【更新】导出功能(待完善)
This commit is contained in:
parent
029c4cfba8
commit
1cf1e1765e
8
pom.xml
8
pom.xml
@ -30,6 +30,7 @@
|
|||||||
<druid.version>1.2.9</druid.version>
|
<druid.version>1.2.9</druid.version>
|
||||||
<dynamic.datasource.version>3.5.1</dynamic.datasource.version>
|
<dynamic.datasource.version>3.5.1</dynamic.datasource.version>
|
||||||
<easy.trans.version>2.1.7</easy.trans.version>
|
<easy.trans.version>2.1.7</easy.trans.version>
|
||||||
|
<easyexcel.version>3.2.1</easyexcel.version>
|
||||||
<easypoi.version>4.3.0</easypoi.version>
|
<easypoi.version>4.3.0</easypoi.version>
|
||||||
<fastjson.version>2.0.24</fastjson.version>
|
<fastjson.version>2.0.24</fastjson.version>
|
||||||
<gson.version>2.8.9</gson.version>
|
<gson.version>2.8.9</gson.version>
|
||||||
@ -318,6 +319,13 @@
|
|||||||
<version>${smcrypto.version}</version>
|
<version>${smcrypto.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- easyexcel -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>easyexcel</artifactId>
|
||||||
|
<version>${easyexcel.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- sa-token-core -->
|
<!-- sa-token-core -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
|
@ -154,5 +154,11 @@
|
|||||||
<groupId>com.antherd</groupId>
|
<groupId>com.antherd</groupId>
|
||||||
<artifactId>sm-crypto</artifactId>
|
<artifactId>sm-crypto</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- easyexcel -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>easyexcel</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -16,6 +16,8 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户导出参数
|
* 用户导出参数
|
||||||
*
|
*
|
||||||
@ -33,4 +35,8 @@ public class SysUserExportParam {
|
|||||||
/** 账号、姓名、手机号关键词 */
|
/** 账号、姓名、手机号关键词 */
|
||||||
@ApiModelProperty(value = "账号、姓名、手机号关键词")
|
@ApiModelProperty(value = "账号、姓名、手机号关键词")
|
||||||
private String searchKey;
|
private String searchKey;
|
||||||
|
|
||||||
|
/** 用户id集合 */
|
||||||
|
@ApiModelProperty(value = "用户id集合")
|
||||||
|
private List<String> userIdList;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,11 @@
|
|||||||
*/
|
*/
|
||||||
package vip.xiaonuo.sys.modular.user.result;
|
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.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@ -29,169 +33,168 @@ import java.util.Date;
|
|||||||
public class SysUserExportResult {
|
public class SysUserExportResult {
|
||||||
|
|
||||||
/** 头像 */
|
/** 头像 */
|
||||||
private String avatar;
|
@ExcelProperty("头像")
|
||||||
|
private byte[] avatar;
|
||||||
/** 头像字节数组 */
|
|
||||||
@Excel(name = "头像", type = 2, imageType = 2)
|
|
||||||
private byte[] avatarByte;
|
|
||||||
|
|
||||||
/** 账号 */
|
/** 账号 */
|
||||||
@Excel(name = "账号")
|
@ExcelProperty("账号")
|
||||||
private String account;
|
private String account;
|
||||||
|
|
||||||
/** 姓名 */
|
/** 姓名 */
|
||||||
@Excel(name = "姓名")
|
@ExcelProperty("姓名")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/** 昵称 */
|
/** 昵称 */
|
||||||
@Excel(name = "昵称")
|
@ExcelProperty("昵称")
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
/** 性别 */
|
/** 性别 */
|
||||||
@Excel(name = "性别")
|
@ExcelProperty("性别")
|
||||||
private String gender;
|
private String gender;
|
||||||
|
|
||||||
/** 年龄 */
|
/** 年龄 */
|
||||||
@Excel(name = "年龄")
|
@ExcelProperty("年龄")
|
||||||
private String age;
|
private String age;
|
||||||
|
|
||||||
/** 出生日期 */
|
/** 出生日期 */
|
||||||
@Excel(name = "出生日期")
|
@ExcelProperty("出生日期")
|
||||||
private String birthday;
|
private String birthday;
|
||||||
|
|
||||||
/** 民族 */
|
/** 民族 */
|
||||||
@Excel(name = "民族")
|
@ExcelProperty("民族")
|
||||||
private String nation;
|
private String nation;
|
||||||
|
|
||||||
/** 籍贯 */
|
/** 籍贯 */
|
||||||
@Excel(name = "籍贯")
|
@ExcelProperty("籍贯")
|
||||||
private String nativePlace;
|
private String nativePlace;
|
||||||
|
|
||||||
/** 家庭住址 */
|
/** 家庭住址 */
|
||||||
@Excel(name = "家庭住址")
|
@ExcelProperty("家庭住址")
|
||||||
private String homeAddress;
|
private String homeAddress;
|
||||||
|
|
||||||
/** 通信地址 */
|
/** 通信地址 */
|
||||||
@Excel(name = "通信地址")
|
@ExcelProperty("通信地址")
|
||||||
private String mailingAddress;
|
private String mailingAddress;
|
||||||
|
|
||||||
/** 证件类型 */
|
/** 证件类型 */
|
||||||
@Excel(name = "证件类型")
|
@ExcelProperty("证件类型")
|
||||||
private String idCardType;
|
private String idCardType;
|
||||||
|
|
||||||
/** 证件号码 */
|
/** 证件号码 */
|
||||||
@Excel(name = "证件号码")
|
@ExcelProperty("证件号码")
|
||||||
private String idCardNumber;
|
private String idCardNumber;
|
||||||
|
|
||||||
/** 文化程度 */
|
/** 文化程度 */
|
||||||
@Excel(name = "文化程度")
|
@ExcelProperty("文化程度")
|
||||||
private String cultureLevel;
|
private String cultureLevel;
|
||||||
|
|
||||||
/** 政治面貌 */
|
/** 政治面貌 */
|
||||||
@Excel(name = "政治面貌")
|
@ExcelProperty("政治面貌")
|
||||||
private String politicalOutlook;
|
private String politicalOutlook;
|
||||||
|
|
||||||
/** 毕业院校 */
|
/** 毕业院校 */
|
||||||
@Excel(name = "毕业院校")
|
@ExcelProperty("毕业院校")
|
||||||
private String college;
|
private String college;
|
||||||
|
|
||||||
/** 学历 */
|
/** 学历 */
|
||||||
@Excel(name = "学历")
|
@ExcelProperty("学历")
|
||||||
private String education;
|
private String education;
|
||||||
|
|
||||||
/** 学制 */
|
/** 学制 */
|
||||||
@Excel(name = "学制")
|
@ExcelProperty("学制")
|
||||||
private String eduLength;
|
private String eduLength;
|
||||||
|
|
||||||
/** 学位 */
|
/** 学位 */
|
||||||
@Excel(name = "学位")
|
@ExcelProperty("学位")
|
||||||
private String degree;
|
private String degree;
|
||||||
|
|
||||||
/** 手机 */
|
/** 手机 */
|
||||||
@Excel(name = "手机")
|
@ExcelProperty("手机")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
/** 邮箱 */
|
/** 邮箱 */
|
||||||
@Excel(name = "邮箱")
|
@ExcelProperty("邮箱")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
/** 家庭电话 */
|
/** 家庭电话 */
|
||||||
@Excel(name = "家庭电话")
|
@ExcelProperty("家庭电话")
|
||||||
private String homeTel;
|
private String homeTel;
|
||||||
|
|
||||||
/** 办公电话 */
|
/** 办公电话 */
|
||||||
@Excel(name = "办公电话")
|
@ExcelProperty("办公电话")
|
||||||
private String officeTel;
|
private String officeTel;
|
||||||
|
|
||||||
/** 紧急联系人 */
|
/** 紧急联系人 */
|
||||||
@Excel(name = "紧急联系人")
|
@ExcelProperty("紧急联系人")
|
||||||
private String emergencyContact;
|
private String emergencyContact;
|
||||||
|
|
||||||
/** 紧急联系人电话 */
|
/** 紧急联系人电话 */
|
||||||
@Excel(name = "紧急联系人电话")
|
@ExcelProperty("紧急联系人电话")
|
||||||
private String emergencyPhone;
|
private String emergencyPhone;
|
||||||
|
|
||||||
/** 紧急联系人地址 */
|
/** 紧急联系人地址 */
|
||||||
@Excel(name = "紧急联系人地址")
|
@ExcelProperty("紧急联系人地址")
|
||||||
private String emergencyAddress;
|
private String emergencyAddress;
|
||||||
|
|
||||||
/** 员工编号 */
|
/** 员工编号 */
|
||||||
@Excel(name = "员工编号")
|
@ExcelProperty("员工编号")
|
||||||
private String empNo;
|
private String empNo;
|
||||||
|
|
||||||
/** 入职日期 */
|
/** 入职日期 */
|
||||||
@Excel(name = "入职日期")
|
@ExcelProperty("入职日期")
|
||||||
private String entryDate;
|
private String entryDate;
|
||||||
|
|
||||||
/** 组织名称 */
|
/** 组织名称 */
|
||||||
@Excel(name = "组织名称")
|
@ExcelProperty("组织名称")
|
||||||
private String orgName;
|
private String orgName;
|
||||||
|
|
||||||
/** 职位名称 */
|
/** 职位名称 */
|
||||||
@Excel(name = "职位名称")
|
@ExcelProperty("职位名称")
|
||||||
private String positionName;
|
private String positionName;
|
||||||
|
|
||||||
/** 主管名称 */
|
/** 主管名称 */
|
||||||
@Excel(name = "主管名称")
|
@ExcelProperty("主管名称")
|
||||||
private String directorName;
|
private String directorName;
|
||||||
|
|
||||||
/** 职级 */
|
/** 职级 */
|
||||||
@Excel(name = "职级")
|
@ExcelProperty("职级")
|
||||||
private String positionLevel;
|
private String positionLevel;
|
||||||
|
|
||||||
/** 上次登录ip */
|
/** 上次登录ip */
|
||||||
@Excel(name = "上次登录ip")
|
@ExcelProperty("上次登录ip")
|
||||||
private String lastLoginIp;
|
private String lastLoginIp;
|
||||||
|
|
||||||
/** 上次登录地点 */
|
/** 上次登录地点 */
|
||||||
@Excel(name = "上次登录地点")
|
@ExcelProperty("上次登录地点")
|
||||||
private String lastLoginAddress;
|
private String lastLoginAddress;
|
||||||
|
|
||||||
/** 上次登录时间 */
|
/** 上次登录时间 */
|
||||||
@Excel(name = "上次登录时间", format = "yyyy-MM-dd HH:mm:ss")
|
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ExcelProperty("上次登录时间")
|
||||||
private Date lastLoginTime;
|
private Date lastLoginTime;
|
||||||
|
|
||||||
/** 上次登录设备 */
|
/** 上次登录设备 */
|
||||||
@Excel(name = "上次登录设备")
|
@ExcelProperty("上次登录设备")
|
||||||
private String lastLoginDevice;
|
private String lastLoginDevice;
|
||||||
|
|
||||||
/** 最新登录ip */
|
/** 最新登录ip */
|
||||||
@Excel(name = "最新登录ip")
|
@ExcelProperty("最新登录ip")
|
||||||
private String latestLoginIp;
|
private String latestLoginIp;
|
||||||
|
|
||||||
/** 最新登录地点 */
|
/** 最新登录地点 */
|
||||||
@Excel(name = "最新登录地点")
|
@ExcelProperty("最新登录地点")
|
||||||
private String latestLoginAddress;
|
private String latestLoginAddress;
|
||||||
|
|
||||||
/** 最新登录时间 */
|
/** 最新登录时间 */
|
||||||
@Excel(name = "最新登录时间", format = "yyyy-MM-dd HH:mm:ss")
|
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ExcelProperty("最新登录时间")
|
||||||
private Date latestLoginTime;
|
private Date latestLoginTime;
|
||||||
|
|
||||||
/** 最新登录设备 */
|
/** 最新登录设备 */
|
||||||
@Excel(name = "最新登录设备")
|
@ExcelProperty("最新登录设备")
|
||||||
private String latestLoginDevice;
|
private String latestLoginDevice;
|
||||||
|
|
||||||
/** 用户状态 */
|
/** 用户状态 */
|
||||||
@Excel(name = "用户状态", replace = { "正常_ENABLE", "停用_DISABLED" })
|
@ExcelProperty("用户状态")
|
||||||
private String userStatus;
|
private String userStatus;
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
package vip.xiaonuo.sys.modular.user.service.impl;
|
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.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.captcha.CaptchaUtil;
|
import cn.hutool.captcha.CaptchaUtil;
|
||||||
import cn.hutool.captcha.CircleCaptcha;
|
import cn.hutool.captcha.CircleCaptcha;
|
||||||
@ -37,6 +35,8 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.json.JSONArray;
|
import cn.hutool.json.JSONArray;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
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.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
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.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.fhs.trans.service.impl.TransService;
|
import com.fhs.trans.service.impl.TransService;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@ -87,7 +86,6 @@ import vip.xiaonuo.sys.modular.user.service.SysUserService;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -1014,27 +1012,35 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
File tempFile = null;
|
File tempFile = null;
|
||||||
try {
|
try {
|
||||||
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
|
||||||
|
if(ObjectUtil.isNotEmpty(sysUserExportParam.getUserIdList())) {
|
||||||
|
queryWrapper.lambda().in(SysUser::getId, sysUserExportParam.getUserIdList());
|
||||||
|
} else {
|
||||||
if (ObjectUtil.isNotEmpty(sysUserExportParam.getSearchKey())) {
|
if (ObjectUtil.isNotEmpty(sysUserExportParam.getSearchKey())) {
|
||||||
queryWrapper.lambda().like(SysUser::getAccount, sysUserExportParam.getSearchKey()).or()
|
queryWrapper.lambda().like(SysUser::getAccount, sysUserExportParam.getSearchKey())
|
||||||
.like(SysUser::getName, sysUserExportParam.getSearchKey());
|
.or().like(SysUser::getName, sysUserExportParam.getSearchKey())
|
||||||
|
.or().like(SysUser::getPhone, sysUserExportParam.getSearchKey());
|
||||||
}
|
}
|
||||||
if (ObjectUtil.isNotEmpty(sysUserExportParam.getUserStatus())) {
|
if (ObjectUtil.isNotEmpty(sysUserExportParam.getUserStatus())) {
|
||||||
queryWrapper.lambda().eq(SysUser::getUserStatus, sysUserExportParam.getUserStatus());
|
queryWrapper.lambda().eq(SysUser::getUserStatus, sysUserExportParam.getUserStatus());
|
||||||
}
|
}
|
||||||
String fileName = "SNOWY2.0系统B端用户信息清单";
|
|
||||||
List<SysUserExportResult> 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));
|
|
||||||
}
|
}
|
||||||
|
String fileName = "SNOWY2.0系统B端用户信息清单.xlsx";
|
||||||
|
List<SysUserExportResult> 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());
|
}).collect(Collectors.toList());
|
||||||
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(fileName, "B端用户"),
|
// 创建临时文件
|
||||||
SysUserExportResult.class, sysUserExportResultList);
|
tempFile = FileUtil.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + fileName);
|
||||||
tempFile = FileUtil.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + fileName + ".xls");
|
// 写excel
|
||||||
BufferedOutputStream outputStream = FileUtil.getOutputStream(tempFile);
|
EasyExcel.write(tempFile.getPath(), SysUserExportResult.class)
|
||||||
workbook.write(outputStream);
|
// 自动列宽
|
||||||
outputStream.close();
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||||
|
.sheet("用户信息").doWrite(sysUserExportResultList);
|
||||||
CommonDownloadUtil.download(tempFile, response);
|
CommonDownloadUtil.download(tempFile, response);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -12,11 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
package vip.xiaonuo;
|
package vip.xiaonuo;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestMain方法
|
* TestMain方法
|
||||||
*
|
*
|
||||||
@ -25,7 +20,6 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class Test {
|
public class Test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Set<Integer> integers = CollectionUtil.unionDistinct(CollectionUtil.newArrayList(), CollectionUtil.newArrayList(1, 2, 4));
|
|
||||||
System.out.println(integers);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user