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 33bc825b..ba7a7944 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 @@ -1003,13 +1003,17 @@ public class SysUserServiceImpl extends ServiceImpl impl } String fileName = "SNOWY2.0系统B端用户信息清单.xlsx"; List sysUserList = this.list(queryWrapper); + if(ObjectUtil.isEmpty(sysUserList)) { + throw new CommonException("无数据可导出"); + } transService.transBatch(sysUserList); sysUserList = CollectionUtil.sort(sysUserList, Comparator.comparing(SysUser::getOrgId)); List sysUserExportResultList = sysUserList.stream() .map(sysUser -> { SysUserExportResult sysUserExportResult = new SysUserExportResult(); BeanUtil.copyProperties(sysUser, sysUserExportResult); - sysUserExportResult.setGroupName(sysUserExportResult.getOrgName()); + sysUserExportResult.setGroupName(ObjectUtil.isNotEmpty(sysUserExportResult.getOrgName())? + sysUserExportResult.getOrgName():"无组织"); // 状态枚举转为文字 sysUserExportResult.setUserStatus(sysUserExportResult.getUserStatus() .equalsIgnoreCase(SysUserStatusEnum.ENABLE.getValue())?"正常":"停用"); @@ -1124,13 +1128,20 @@ public class SysUserServiceImpl extends ServiceImpl impl File.separator + "userExportTemplate.docx")); // 构造填充的参数 Map map = BeanUtil.beanToMap(sysUser); - map.put("avatar", new ImageEntity(ImgUtil.toBytes(ImgUtil.toImage(StrUtil.split(sysUser.getAvatar(), - StrUtil.COMMA).get(1)), ImgUtil.IMAGE_TYPE_PNG), 120, 160)); + String avatarBase64; + if(ObjectUtil.isNotEmpty(sysUser.getAvatar())) { + avatarBase64 = sysUser.getAvatar(); + } else { + avatarBase64 = CommonAvatarUtil.generateImg(sysUser.getAvatar()); + } + ImageEntity imageEntity = new ImageEntity(ImgUtil.toBytes(ImgUtil.toImage(StrUtil + .split(avatarBase64, StrUtil.COMMA).get(1)), ImgUtil.IMAGE_TYPE_PNG), 120, 160); + map.put("avatar", imageEntity); map.put("exportDateTime", DateUtil.format(DateTime.now(), DatePattern.CHINESE_DATE_PATTERN)); // 生成doc XWPFDocument doc = WordExportUtil.exportWord07(destTemplateFile.getAbsolutePath(), map); // 生成临时导出文件 - resultFile = FileUtil.file(FileUtil.getTmpDir() + File.separator + sysUser.getName() + "个人信息.docx"); + resultFile = FileUtil.file(FileUtil.getTmpDir() + File.separator + "SNOWY2.0系统B端用户信息_" + sysUser.getName() + ".docx"); // 写入 BufferedOutputStream outputStream = FileUtil.getOutputStream(resultFile); doc.write(outputStream); diff --git a/snowy-plugin/snowy-plugin-sys/src/main/resources/userExportTemplate.docx b/snowy-plugin/snowy-plugin-sys/src/main/resources/userExportTemplate.docx index acd44575..983604a3 100644 Binary files a/snowy-plugin/snowy-plugin-sys/src/main/resources/userExportTemplate.docx and b/snowy-plugin/snowy-plugin-sys/src/main/resources/userExportTemplate.docx differ 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 b59a9b55..d84ca2e6 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 com.alibaba.excel.EasyExcel; -import com.alibaba.excel.read.listener.PageReadListener; -import vip.xiaonuo.common.exception.CommonException; -import vip.xiaonuo.sys.modular.user.param.SysUserImportParam; - /** * TestMain方法 * @@ -24,16 +19,7 @@ import vip.xiaonuo.sys.modular.user.param.SysUserImportParam; * @date 2022/9/17 17:10 */ public class Test { - public static void main(String[] args) { - try { - EasyExcel.read("D://import.xlsx", SysUserImportParam.class, new PageReadListener(dataList -> { - for (SysUserImportParam sysUserImportParam : dataList) { - System.out.println(sysUserImportParam); - } - })).sheet().headRowNumber(2).doRead(); - } catch (Exception e) { - e.printStackTrace(); - throw new CommonException("文件导入失败"); - } + public static void main(String[] args) throws Exception { + } }