| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package com.zhentao.vo;
- import com.alibaba.excel.annotation.ExcelProperty;
- import com.alibaba.excel.annotation.write.style.ColumnWidth;
- import lombok.Data;
- import java.io.Serializable;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- /**
- * 用户Excel导出VO
- */
- @Data
- @ColumnWidth(20)
- public class UserExcelVO implements Serializable {
-
- private static final long serialVersionUID = 1L;
- private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-
- @ExcelProperty(value = "用户ID", index = 0)
- private Integer userId;
-
- @ExcelProperty(value = "昵称", index = 1)
- private String nickname;
-
- @ExcelProperty(value = "手机号", index = 2)
- private String phone;
-
- @ExcelProperty(value = "邮箱", index = 3)
- private String email;
-
- @ExcelProperty(value = "性别", index = 4)
- private String gender;
-
- @ExcelProperty(value = "年龄", index = 5)
- private Integer age;
-
- @ExcelProperty(value = "VIP等级", index = 6)
- private String vipLevel;
-
- @ExcelProperty(value = "VIP剩余天数", index = 7)
- private Integer vipRemainingDays;
-
- @ExcelProperty(value = "资料完整", index = 8)
- private String isProfileComplete;
-
- @ExcelProperty(value = "状态", index = 9)
- private String status;
-
- @ExcelProperty(value = "注册时间", index = 10)
- private String createdAt;
-
- @ExcelProperty(value = "最后登录", index = 11)
- private String lastLoginAt;
-
- /**
- * 从UserVO转换
- */
- public static UserExcelVO fromUserVO(UserVO user) {
- UserExcelVO vo = new UserExcelVO();
- vo.setUserId(user.getUserId());
- vo.setNickname(user.getNickname());
- vo.setPhone(user.getPhone());
- vo.setEmail(user.getEmail());
-
- // 性别
- if (user.getGender() != null) {
- vo.setGender(user.getGender() == 1 ? "男" : user.getGender() == 2 ? "女" : "未知");
- } else {
- vo.setGender("未知");
- }
-
- vo.setAge(user.getAge());
- vo.setVipLevel(user.getVipLevel() != null ? user.getVipLevel() : "普通用户");
- vo.setVipRemainingDays(user.getVipRemainingDays());
-
- // 资料完整
- vo.setIsProfileComplete(user.getIsProfileComplete() != null && user.getIsProfileComplete() == 1 ? "已完成" : "未完成");
-
- // 状态
- if (user.getStatus() != null) {
- switch (user.getStatus()) {
- case 1:
- vo.setStatus("正常");
- break;
- case 0:
- vo.setStatus("禁用");
- break;
- case 2:
- vo.setStatus("注销");
- break;
- default:
- vo.setStatus("未知");
- }
- }
-
- // 时间格式化
- if (user.getCreatedAt() != null) {
- vo.setCreatedAt(user.getCreatedAt().format(FORMATTER));
- }
- if (user.getLastLoginAt() != null) {
- vo.setLastLoginAt(user.getLastLoginAt().format(FORMATTER));
- }
-
- return vo;
- }
- }
|