UserExcelVO.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.zhentao.vo;
  2. import com.alibaba.excel.annotation.ExcelProperty;
  3. import com.alibaba.excel.annotation.write.style.ColumnWidth;
  4. import lombok.Data;
  5. import java.io.Serializable;
  6. import java.time.LocalDateTime;
  7. import java.time.format.DateTimeFormatter;
  8. /**
  9. * 用户Excel导出VO
  10. */
  11. @Data
  12. @ColumnWidth(20)
  13. public class UserExcelVO implements Serializable {
  14. private static final long serialVersionUID = 1L;
  15. private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  16. @ExcelProperty(value = "用户ID", index = 0)
  17. private Integer userId;
  18. @ExcelProperty(value = "昵称", index = 1)
  19. private String nickname;
  20. @ExcelProperty(value = "手机号", index = 2)
  21. private String phone;
  22. @ExcelProperty(value = "邮箱", index = 3)
  23. private String email;
  24. @ExcelProperty(value = "性别", index = 4)
  25. private String gender;
  26. @ExcelProperty(value = "年龄", index = 5)
  27. private Integer age;
  28. @ExcelProperty(value = "VIP等级", index = 6)
  29. private String vipLevel;
  30. @ExcelProperty(value = "VIP剩余天数", index = 7)
  31. private Integer vipRemainingDays;
  32. @ExcelProperty(value = "资料完整", index = 8)
  33. private String isProfileComplete;
  34. @ExcelProperty(value = "状态", index = 9)
  35. private String status;
  36. @ExcelProperty(value = "注册时间", index = 10)
  37. private String createdAt;
  38. @ExcelProperty(value = "最后登录", index = 11)
  39. private String lastLoginAt;
  40. /**
  41. * 从UserVO转换
  42. */
  43. public static UserExcelVO fromUserVO(UserVO user) {
  44. UserExcelVO vo = new UserExcelVO();
  45. vo.setUserId(user.getUserId());
  46. vo.setNickname(user.getNickname());
  47. vo.setPhone(user.getPhone());
  48. vo.setEmail(user.getEmail());
  49. // 性别
  50. if (user.getGender() != null) {
  51. vo.setGender(user.getGender() == 1 ? "男" : user.getGender() == 2 ? "女" : "未知");
  52. } else {
  53. vo.setGender("未知");
  54. }
  55. vo.setAge(user.getAge());
  56. vo.setVipLevel(user.getVipLevel() != null ? user.getVipLevel() : "普通用户");
  57. vo.setVipRemainingDays(user.getVipRemainingDays());
  58. // 资料完整
  59. vo.setIsProfileComplete(user.getIsProfileComplete() != null && user.getIsProfileComplete() == 1 ? "已完成" : "未完成");
  60. // 状态
  61. if (user.getStatus() != null) {
  62. switch (user.getStatus()) {
  63. case 1:
  64. vo.setStatus("正常");
  65. break;
  66. case 0:
  67. vo.setStatus("禁用");
  68. break;
  69. case 2:
  70. vo.setStatus("注销");
  71. break;
  72. default:
  73. vo.setStatus("未知");
  74. }
  75. }
  76. // 时间格式化
  77. if (user.getCreatedAt() != null) {
  78. vo.setCreatedAt(user.getCreatedAt().format(FORMATTER));
  79. }
  80. if (user.getLastLoginAt() != null) {
  81. vo.setLastLoginAt(user.getLastLoginAt().format(FORMATTER));
  82. }
  83. return vo;
  84. }
  85. }