diff --git a/pom.xml b/pom.xml
index ff87fe22..d5c788fa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,7 @@
1.2.9
3.5.1
2.1.7
+ 3.2.1
4.3.0
2.0.24
2.8.9
@@ -318,6 +319,13 @@
${smcrypto.version}
+
+
+ com.alibaba
+ easyexcel
+ ${easyexcel.version}
+
+
cn.dev33
diff --git a/snowy-common/pom.xml b/snowy-common/pom.xml
index 91ade772..86026bcc 100644
--- a/snowy-common/pom.xml
+++ b/snowy-common/pom.xml
@@ -154,5 +154,11 @@
com.antherd
sm-crypto
+
+
+
+ com.alibaba
+ easyexcel
+
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/param/SysUserExportParam.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/param/SysUserExportParam.java
index 459fa311..9400e69b 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/param/SysUserExportParam.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/param/SysUserExportParam.java
@@ -16,6 +16,8 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
+import java.util.List;
+
/**
* 用户导出参数
*
@@ -33,4 +35,8 @@ public class SysUserExportParam {
/** 账号、姓名、手机号关键词 */
@ApiModelProperty(value = "账号、姓名、手机号关键词")
private String searchKey;
+
+ /** 用户id集合 */
+ @ApiModelProperty(value = "用户id集合")
+ private List userIdList;
}
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/result/SysUserExportResult.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/result/SysUserExportResult.java
index 719a9d33..07218bba 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/result/SysUserExportResult.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/result/SysUserExportResult.java
@@ -12,7 +12,11 @@
*/
package vip.xiaonuo.sys.modular.user.result;
-import cn.afterturn.easypoi.excel.annotation.Excel;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.format.DateTimeFormat;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentRowHeight;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Getter;
import lombok.Setter;
@@ -29,169 +33,168 @@ import java.util.Date;
public class SysUserExportResult {
/** 头像 */
- private String avatar;
-
- /** 头像字节数组 */
- @Excel(name = "头像", type = 2, imageType = 2)
- private byte[] avatarByte;
+ @ExcelProperty("头像")
+ private byte[] avatar;
/** 账号 */
- @Excel(name = "账号")
+ @ExcelProperty("账号")
private String account;
/** 姓名 */
- @Excel(name = "姓名")
+ @ExcelProperty("姓名")
private String name;
/** 昵称 */
- @Excel(name = "昵称")
+ @ExcelProperty("昵称")
private String nickname;
/** 性别 */
- @Excel(name = "性别")
+ @ExcelProperty("性别")
private String gender;
/** 年龄 */
- @Excel(name = "年龄")
+ @ExcelProperty("年龄")
private String age;
/** 出生日期 */
- @Excel(name = "出生日期")
+ @ExcelProperty("出生日期")
private String birthday;
/** 民族 */
- @Excel(name = "民族")
+ @ExcelProperty("民族")
private String nation;
/** 籍贯 */
- @Excel(name = "籍贯")
+ @ExcelProperty("籍贯")
private String nativePlace;
/** 家庭住址 */
- @Excel(name = "家庭住址")
+ @ExcelProperty("家庭住址")
private String homeAddress;
/** 通信地址 */
- @Excel(name = "通信地址")
+ @ExcelProperty("通信地址")
private String mailingAddress;
/** 证件类型 */
- @Excel(name = "证件类型")
+ @ExcelProperty("证件类型")
private String idCardType;
/** 证件号码 */
- @Excel(name = "证件号码")
+ @ExcelProperty("证件号码")
private String idCardNumber;
/** 文化程度 */
- @Excel(name = "文化程度")
+ @ExcelProperty("文化程度")
private String cultureLevel;
/** 政治面貌 */
- @Excel(name = "政治面貌")
+ @ExcelProperty("政治面貌")
private String politicalOutlook;
/** 毕业院校 */
- @Excel(name = "毕业院校")
+ @ExcelProperty("毕业院校")
private String college;
/** 学历 */
- @Excel(name = "学历")
+ @ExcelProperty("学历")
private String education;
/** 学制 */
- @Excel(name = "学制")
+ @ExcelProperty("学制")
private String eduLength;
/** 学位 */
- @Excel(name = "学位")
+ @ExcelProperty("学位")
private String degree;
/** 手机 */
- @Excel(name = "手机")
+ @ExcelProperty("手机")
private String phone;
/** 邮箱 */
- @Excel(name = "邮箱")
+ @ExcelProperty("邮箱")
private String email;
/** 家庭电话 */
- @Excel(name = "家庭电话")
+ @ExcelProperty("家庭电话")
private String homeTel;
/** 办公电话 */
- @Excel(name = "办公电话")
+ @ExcelProperty("办公电话")
private String officeTel;
/** 紧急联系人 */
- @Excel(name = "紧急联系人")
+ @ExcelProperty("紧急联系人")
private String emergencyContact;
/** 紧急联系人电话 */
- @Excel(name = "紧急联系人电话")
+ @ExcelProperty("紧急联系人电话")
private String emergencyPhone;
/** 紧急联系人地址 */
- @Excel(name = "紧急联系人地址")
+ @ExcelProperty("紧急联系人地址")
private String emergencyAddress;
/** 员工编号 */
- @Excel(name = "员工编号")
+ @ExcelProperty("员工编号")
private String empNo;
/** 入职日期 */
- @Excel(name = "入职日期")
+ @ExcelProperty("入职日期")
private String entryDate;
/** 组织名称 */
- @Excel(name = "组织名称")
+ @ExcelProperty("组织名称")
private String orgName;
/** 职位名称 */
- @Excel(name = "职位名称")
+ @ExcelProperty("职位名称")
private String positionName;
/** 主管名称 */
- @Excel(name = "主管名称")
+ @ExcelProperty("主管名称")
private String directorName;
/** 职级 */
- @Excel(name = "职级")
+ @ExcelProperty("职级")
private String positionLevel;
/** 上次登录ip */
- @Excel(name = "上次登录ip")
+ @ExcelProperty("上次登录ip")
private String lastLoginIp;
/** 上次登录地点 */
- @Excel(name = "上次登录地点")
+ @ExcelProperty("上次登录地点")
private String lastLoginAddress;
/** 上次登录时间 */
- @Excel(name = "上次登录时间", format = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
+ @ExcelProperty("上次登录时间")
private Date lastLoginTime;
/** 上次登录设备 */
- @Excel(name = "上次登录设备")
+ @ExcelProperty("上次登录设备")
private String lastLoginDevice;
/** 最新登录ip */
- @Excel(name = "最新登录ip")
+ @ExcelProperty("最新登录ip")
private String latestLoginIp;
/** 最新登录地点 */
- @Excel(name = "最新登录地点")
+ @ExcelProperty("最新登录地点")
private String latestLoginAddress;
/** 最新登录时间 */
- @Excel(name = "最新登录时间", format = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
+ @ExcelProperty("最新登录时间")
private Date latestLoginTime;
/** 最新登录设备 */
- @Excel(name = "最新登录设备")
+ @ExcelProperty("最新登录设备")
private String latestLoginDevice;
/** 用户状态 */
- @Excel(name = "用户状态", replace = { "正常_ENABLE", "停用_DISABLED" })
+ @ExcelProperty("用户状态")
private String userStatus;
}
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java
index 3784b299..76716e04 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java
@@ -12,8 +12,6 @@
*/
package vip.xiaonuo.sys.modular.user.service.impl;
-import cn.afterturn.easypoi.excel.ExcelExportUtil;
-import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
@@ -37,6 +35,8 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -44,7 +44,6 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fhs.trans.service.impl.TransService;
-import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -87,7 +86,6 @@ import vip.xiaonuo.sys.modular.user.service.SysUserService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -1014,27 +1012,35 @@ public class SysUserServiceImpl extends ServiceImpl impl
File tempFile = null;
try {
QueryWrapper queryWrapper = new QueryWrapper<>();
- if (ObjectUtil.isNotEmpty(sysUserExportParam.getSearchKey())) {
- queryWrapper.lambda().like(SysUser::getAccount, sysUserExportParam.getSearchKey()).or()
- .like(SysUser::getName, sysUserExportParam.getSearchKey());
- }
- if (ObjectUtil.isNotEmpty(sysUserExportParam.getUserStatus())) {
- queryWrapper.lambda().eq(SysUser::getUserStatus, sysUserExportParam.getUserStatus());
- }
- String fileName = "SNOWY2.0系统B端用户信息清单";
- List sysUserExportResultList = this.list(queryWrapper).stream()
- .map(sysUser -> BeanUtil.copyProperties(sysUser, SysUserExportResult.class)).peek(sysUserExportResult -> {
- if (ObjectUtil.isNotEmpty(sysUserExportResult.getAvatar())) {
- sysUserExportResult.setAvatarByte(ImgUtil.toBytes(ImgUtil.toImage(StrUtil
- .split(sysUserExportResult.getAvatar(), StrUtil.COMMA).get(1)), ImgUtil.IMAGE_TYPE_PNG));
+ if(ObjectUtil.isNotEmpty(sysUserExportParam.getUserIdList())) {
+ queryWrapper.lambda().in(SysUser::getId, sysUserExportParam.getUserIdList());
+ } else {
+ if (ObjectUtil.isNotEmpty(sysUserExportParam.getSearchKey())) {
+ queryWrapper.lambda().like(SysUser::getAccount, sysUserExportParam.getSearchKey())
+ .or().like(SysUser::getName, sysUserExportParam.getSearchKey())
+ .or().like(SysUser::getPhone, sysUserExportParam.getSearchKey());
}
- }).collect(Collectors.toList());
- Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(fileName, "B端用户"),
- SysUserExportResult.class, sysUserExportResultList);
- tempFile = FileUtil.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + fileName + ".xls");
- BufferedOutputStream outputStream = FileUtil.getOutputStream(tempFile);
- workbook.write(outputStream);
- outputStream.close();
+ if (ObjectUtil.isNotEmpty(sysUserExportParam.getUserStatus())) {
+ queryWrapper.lambda().eq(SysUser::getUserStatus, sysUserExportParam.getUserStatus());
+ }
+ }
+ String fileName = "SNOWY2.0系统B端用户信息清单.xlsx";
+ List sysUserExportResultList = this.list(queryWrapper).stream()
+ .map(sysUser -> {
+ SysUserExportResult sysUserExportResult = new SysUserExportResult();
+ BeanUtil.copyProperties(sysUser, sysUserExportResult);
+ // 将base64转为byte数组
+ sysUserExportResult.setAvatar(ImgUtil.toBytes(ImgUtil.toImage(StrUtil
+ .split(sysUser.getAvatar(), StrUtil.COMMA).get(1)), ImgUtil.IMAGE_TYPE_PNG));
+ return sysUserExportResult;
+ }).collect(Collectors.toList());
+ // 创建临时文件
+ tempFile = FileUtil.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + fileName);
+ // 写excel
+ EasyExcel.write(tempFile.getPath(), SysUserExportResult.class)
+ // 自动列宽
+ .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
+ .sheet("用户信息").doWrite(sysUserExportResultList);
CommonDownloadUtil.download(tempFile, response);
} catch (Exception e) {
e.printStackTrace();
diff --git a/snowy-web-app/src/test/java/vip/xiaonuo/Test.java b/snowy-web-app/src/test/java/vip/xiaonuo/Test.java
index d62a47af..a9270e71 100644
--- a/snowy-web-app/src/test/java/vip/xiaonuo/Test.java
+++ b/snowy-web-app/src/test/java/vip/xiaonuo/Test.java
@@ -12,11 +12,6 @@
*/
package vip.xiaonuo;
-import cn.hutool.core.collection.CollectionUtil;
-
-import java.util.Collection;
-import java.util.Set;
-
/**
* TestMain方法
*
@@ -25,7 +20,6 @@ import java.util.Set;
*/
public class Test {
public static void main(String[] args) {
- Set integers = CollectionUtil.unionDistinct(CollectionUtil.newArrayList(), CollectionUtil.newArrayList(1, 2, 4));
- System.out.println(integers);
+
}
}