diff --git a/db/mysql/maku.sql b/db/mysql/maku.sql index 921bb6c9b2e6f72d986ae2133b1788e2a116da80..0ca0505114254bb0b7524af7aac4b78d49476c67 100644 --- a/db/mysql/maku.sql +++ b/db/mysql/maku.sql @@ -261,6 +261,9 @@ INSERT INTO sys_menu (id, pid, name, url, authority, type, open_style, icon, sor INSERT INTO sys_menu (id, pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (37, 34, '删除', '', 'sys:attachment:delete', 1, 0, '', 1, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_menu (id, pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (38, 0, '日志管理', '', '', 0, 0, 'icon-filedone', 3, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_menu (id, pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (39, 38, '登录日志', 'sys/log/login', 'sys:log:login', 0, 0, 'icon-solution', 0, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_menu (id, pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (40, 39, '导出登录日志', '', 'sys:log:login:export', 1, 0, '', 1, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_menu (id, pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (41, 28, '导入', '', 'sys:user:import', 1, 0, '', 5, 0, 0, 10000, now(), 10000, now()); +INSERT INTO sys_menu (id, pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (42, 28, '导出', '', 'sys:user:export', 1, 0, '', 6, 0, 0, 10000, now(), 10000, now()); INSERT INTO sys_dict_type (id, dict_type, dict_name, remark, sort, version, deleted, creator, create_time, updater, update_time) VALUES (1, 'post_status', '状态', '岗位管理', 0, 0, 0, 10000, now(), 10000, now()); diff --git a/maku-boot-system/src/main/java/net/maku/system/controller/SysLogLoginController.java b/maku-boot-system/src/main/java/net/maku/system/controller/SysLogLoginController.java index 25dc96affe7805e869c8c2858f8fbb787f227342..263e7674ce798d4dc0cc207077e79f668eb533a8 100644 --- a/maku-boot-system/src/main/java/net/maku/system/controller/SysLogLoginController.java +++ b/maku-boot-system/src/main/java/net/maku/system/controller/SysLogLoginController.java @@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; -import java.io.IOException; import java.util.Map; /** @@ -40,7 +39,8 @@ public class SysLogLoginController { @GetMapping("export") @Operation(summary = "导出excel") - public Result> export() throws IOException { + @PreAuthorize("hasAuthority('sys:log:login:export')") + public Result> export() { Map map = sysLogLoginService.export(); return Result.ok(map); diff --git a/maku-boot-system/src/main/java/net/maku/system/controller/SysUserController.java b/maku-boot-system/src/main/java/net/maku/system/controller/SysUserController.java index de1a86ef1618cf7cfcf4fa6fa3c5a801a98e7105..2ba2105d17a2f0134dfa8320a370aed1302813d2 100644 --- a/maku-boot-system/src/main/java/net/maku/system/controller/SysUserController.java +++ b/maku-boot-system/src/main/java/net/maku/system/controller/SysUserController.java @@ -19,9 +19,11 @@ import net.maku.system.vo.SysUserVO; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import java.util.List; +import java.util.Map; /** @@ -137,4 +139,25 @@ public class SysUserController { return Result.ok(); } + + @PostMapping("import") + @Operation(summary = "导入用户") + @PreAuthorize("hasAuthority('sys:user:import')") + public Result importExcel(@RequestParam("file") MultipartFile file) { + if (file.isEmpty()) { + return Result.error("请选择需要上传的文件"); + } + sysUserService.importByExcel(file, passwordEncoder.encode("123456")); + + return Result.ok(); + } + + @GetMapping("export") + @Operation(summary = "导出用户") + @PreAuthorize("hasAuthority('sys:user:export')") + public Result> export() { + Map map = sysUserService.export(); + + return Result.ok(map); + } } diff --git a/maku-boot-system/src/main/java/net/maku/system/convert/SysUserConvert.java b/maku-boot-system/src/main/java/net/maku/system/convert/SysUserConvert.java index 8253cadd52a99813ff44c73f44fd2a74f22a558d..4a0403a2313c9d960bfb01965d64a6965e308d9b 100644 --- a/maku-boot-system/src/main/java/net/maku/system/convert/SysUserConvert.java +++ b/maku-boot-system/src/main/java/net/maku/system/convert/SysUserConvert.java @@ -2,6 +2,7 @@ package net.maku.system.convert; import net.maku.framework.security.user.UserDetail; import net.maku.system.entity.SysUserEntity; +import net.maku.system.vo.SysUserExcelVO; import net.maku.system.vo.SysUserVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -23,4 +24,8 @@ public interface SysUserConvert { List convertList(List list); + List convert2List(List list); + + List convertListEntity(List list); + } diff --git a/maku-boot-system/src/main/java/net/maku/system/enums/SuperAdminEnum.java b/maku-boot-system/src/main/java/net/maku/system/enums/SuperAdminEnum.java index 49ca1a2cbf350d68c6fe1e9442f2184ca0fa32dd..b68ec6ae566c48fa9da5d6cc6175025457b2069b 100644 --- a/maku-boot-system/src/main/java/net/maku/system/enums/SuperAdminEnum.java +++ b/maku-boot-system/src/main/java/net/maku/system/enums/SuperAdminEnum.java @@ -3,14 +3,41 @@ package net.maku.system.enums; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Objects; + /** * 超级管理员枚举 */ @Getter @AllArgsConstructor public enum SuperAdminEnum { - YES(1), - NO(0); + /** + * 是 + */ + YES(1, "是"), + /** + * 否 + */ + NO(0, "否"); private final Integer value; + private final String name; + + public static String getNameByValue(int value) { + for (SuperAdminEnum s : SuperAdminEnum.values()) { + if (s.getValue() == value) { + return s.getName(); + } + } + return ""; + } + + public static Integer getValueByName(String name) { + for (SuperAdminEnum s : SuperAdminEnum.values()) { + if (Objects.equals(s.getName(), name)) { + return s.getValue(); + } + } + return null; + } } \ No newline at end of file diff --git a/maku-boot-system/src/main/java/net/maku/system/enums/UserGenderEnum.java b/maku-boot-system/src/main/java/net/maku/system/enums/UserGenderEnum.java new file mode 100644 index 0000000000000000000000000000000000000000..8ce4ce4a1e8f5a470af00953ca332ea730cea3fd --- /dev/null +++ b/maku-boot-system/src/main/java/net/maku/system/enums/UserGenderEnum.java @@ -0,0 +1,49 @@ +package net.maku.system.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Objects; + +/** + * 用户性别状态 + * + * @author 阿沐 babamu@126.com + */ +@Getter +@AllArgsConstructor +public enum UserGenderEnum { + /** + * 男 + */ + MAN(0, "男"), + /** + * 女 + */ + WOMEN(1, "女"), + /** + * 未知 + */ + UNKNOWN(2,"未知"); + + private final int value; + private final String name; + + public static String getNameByValue(int value) { + for (UserGenderEnum s : UserGenderEnum.values()) { + if (s.getValue() == value) { + return s.getName(); + } + } + return ""; + } + + public static Integer getValueByName(String name) { + for (UserGenderEnum s : UserGenderEnum.values()) { + if (Objects.equals(s.getName(), name)) { + return s.getValue(); + } + } + return null; + } +} diff --git a/maku-boot-system/src/main/java/net/maku/system/enums/UserStatusEnum.java b/maku-boot-system/src/main/java/net/maku/system/enums/UserStatusEnum.java index b80798759cc4c918fc1ff2fde34c62a0335aed24..de654022909cb020581614ba278ec2ce334455c6 100644 --- a/maku-boot-system/src/main/java/net/maku/system/enums/UserStatusEnum.java +++ b/maku-boot-system/src/main/java/net/maku/system/enums/UserStatusEnum.java @@ -3,6 +3,8 @@ package net.maku.system.enums; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Objects; + /** * 用户状态 * @@ -14,11 +16,30 @@ public enum UserStatusEnum { /** * 停用 */ - DISABLE(0), + DISABLE(0, "停用"), /** * 正常 */ - ENABLED(1); + ENABLED(1, "正常"); private final int value; + private final String name; + + public static String getNameByValue(int value) { + for (UserStatusEnum s : UserStatusEnum.values()) { + if (s.getValue() == value) { + return s.getName(); + } + } + return ""; + } + + public static Integer getValueByName(String name) { + for (UserStatusEnum s : UserStatusEnum.values()) { + if (Objects.equals(s.getName(), name)) { + return s.getValue(); + } + } + return null; + } } diff --git a/maku-boot-system/src/main/java/net/maku/system/service/SysLogLoginService.java b/maku-boot-system/src/main/java/net/maku/system/service/SysLogLoginService.java index 8723d4d4c8830ba3bb4c32e636c8b5f80d2d0336..e437850e4c77f342e41173729a2361903315d13f 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/SysLogLoginService.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/SysLogLoginService.java @@ -37,7 +37,6 @@ public interface SysLogLoginService extends BaseService { * 导出登录日志 * * @return the map - * @throws IOException the io exception */ - Map export() throws IOException; + Map export(); } \ No newline at end of file diff --git a/maku-boot-system/src/main/java/net/maku/system/service/SysUserService.java b/maku-boot-system/src/main/java/net/maku/system/service/SysUserService.java index b4dd673bf7a8b426e534d8fb9f9a2699534ef8a5..4905e55f7a33f23fdb2eae99d1e259f215097bd9 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/SysUserService.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/SysUserService.java @@ -6,8 +6,10 @@ import net.maku.system.entity.SysUserEntity; import net.maku.system.query.SysRoleUserQuery; import net.maku.system.query.SysUserQuery; import net.maku.system.vo.SysUserVO; +import org.springframework.web.multipart.MultipartFile; import java.util.List; +import java.util.Map; /** * 用户管理 @@ -39,4 +41,18 @@ public interface SysUserService extends BaseService { */ PageResult roleUserPage(SysRoleUserQuery query); + /** + * 批量导入用户 + * + * @param file excel文件 + * @param password 密码 + */ + void importByExcel(MultipartFile file, String password); + + /** + * 导出用户信息表格 + * + * @return map + */ + Map export(); } diff --git a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysLogLoginServiceImpl.java b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysLogLoginServiceImpl.java index af1adfca4ffa95f2197640fb278d6c77765c77c4..d38589e4270a6ce239e5ea6917eb02b331809203 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysLogLoginServiceImpl.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysLogLoginServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.AllArgsConstructor; +import lombok.SneakyThrows; import net.maku.framework.common.page.PageResult; import net.maku.framework.common.service.impl.BaseServiceImpl; import net.maku.framework.common.utils.AddressUtils; @@ -24,7 +25,6 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import java.io.File; -import java.io.IOException; import java.nio.file.Files; import java.util.HashMap; import java.util.List; @@ -78,18 +78,19 @@ public class SysLogLoginServiceImpl extends BaseServiceImpl export() throws IOException { + @SneakyThrows + public Map export() { List list = list(); List sysLogLoginVOS = SysLogLoginConvert.INSTANCE.convertList(list); - File file = File.createTempFile("log_excel", ".xlsx"); + + File file = File.createTempFile("system_login_log_excel", ".xlsx"); // 写入到文件 ExcelUtils.excelExport(SysLogLoginVO.class, file, sysLogLoginVOS); byte[] data = IoUtil.readBytes(Files.newInputStream(file.toPath())); - String path = storageService.getPath(file.getName()); String url = storageService.upload(data, path); - Map map = new HashMap<>(); + Map map = new HashMap<>(2); map.put("path", url); map.put("filename", file.getName()); return map; diff --git a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysUserServiceImpl.java b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysUserServiceImpl.java index 09e43834b3a8e2ecf6113a3744f21fb55a036a9c..cfe1622aae41808ed39acafe4ba689a87bec5c49 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysUserServiceImpl.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysUserServiceImpl.java @@ -1,11 +1,17 @@ package net.maku.system.service.impl; +import cn.hutool.core.io.IoUtil; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.AllArgsConstructor; +import lombok.SneakyThrows; import net.maku.framework.common.constant.Constant; +import net.maku.framework.common.excel.ExcelFinishCallBack; import net.maku.framework.common.exception.ServerException; import net.maku.framework.common.page.PageResult; import net.maku.framework.common.service.impl.BaseServiceImpl; +import net.maku.framework.common.utils.ExcelUtils; +import net.maku.storage.service.StorageService; import net.maku.system.convert.SysUserConvert; import net.maku.system.dao.SysUserDao; import net.maku.system.entity.SysUserEntity; @@ -15,10 +21,14 @@ import net.maku.system.query.SysUserQuery; import net.maku.system.service.SysUserPostService; import net.maku.system.service.SysUserRoleService; import net.maku.system.service.SysUserService; +import net.maku.system.vo.SysUserExcelVO; import net.maku.system.vo.SysUserVO; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import java.io.File; +import java.nio.file.Files; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,6 +43,7 @@ import java.util.Map; public class SysUserServiceImpl extends BaseServiceImpl implements SysUserService { private final SysUserRoleService sysUserRoleService; private final SysUserPostService sysUserPostService; + private final StorageService storageService; @Override public PageResult page(SysUserQuery query) { @@ -131,7 +142,7 @@ public class SysUserServiceImpl extends BaseServiceImpl(SysUserConvert.INSTANCE.convertList(list), page.getTotal()); } + @Override + @Transactional(rollbackFor = Exception.class) + public void importByExcel(MultipartFile file, String password) { + + ExcelUtils.readAnalysis(file, SysUserExcelVO.class, new ExcelFinishCallBack<>() { + @Override + public void doAfterAllAnalysed(List result) { + saveUser(result); + } + + @Override + public void doSaveBatch(List result) { + saveUser(result); + } + + private void saveUser(List result) { + List sysUserEntities = SysUserConvert.INSTANCE.convertListEntity(result); + sysUserEntities.forEach(user -> user.setPassword(password)); + saveBatch(sysUserEntities); + } + }); + + } + + @Override + @SneakyThrows + public Map export() { + List list = list(Wrappers.lambdaQuery(SysUserEntity.class).eq(SysUserEntity::getSuperAdmin, SuperAdminEnum.NO.getValue())); + List userExcelVOS = SysUserConvert.INSTANCE.convert2List(list); + + File file = File.createTempFile("system_user_excel", ".xlsx"); + // 写入到文件 + ExcelUtils.excelExport(SysUserExcelVO.class, file, userExcelVOS); + + byte[] data = IoUtil.readBytes(Files.newInputStream(file.toPath())); + String path = storageService.getPath(file.getName()); + String url = storageService.upload(data, path); + Map map = new HashMap<>(2); + map.put("path", url); + map.put("filename", file.getName()); + return map; + } + } diff --git a/maku-boot-system/src/main/java/net/maku/system/vo/SysUserExcelVO.java b/maku-boot-system/src/main/java/net/maku/system/vo/SysUserExcelVO.java new file mode 100644 index 0000000000000000000000000000000000000000..f3c298f8047e9f37b1561285f6f5b0f895198401 --- /dev/null +++ b/maku-boot-system/src/main/java/net/maku/system/vo/SysUserExcelVO.java @@ -0,0 +1,96 @@ +package net.maku.system.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; +import lombok.Data; +import net.maku.framework.common.excel.DateConverter; +import net.maku.framework.common.utils.DateUtils; +import net.maku.system.enums.SuperAdminEnum; +import net.maku.system.enums.UserGenderEnum; +import net.maku.system.enums.UserStatusEnum; + +import java.io.Serializable; +import java.util.Date; + +/** + * excel用户表 + * + * @author 阿沐 babamu@126.com + */ +@Data +public class SysUserExcelVO implements Serializable { + private static final long serialVersionUID = 1L; + + @ExcelProperty("用户名") + private String username; + + @ExcelProperty("姓名") + private String realName; + + @ExcelProperty(value = "性别", converter = GenderConverter.class) + private Integer gender; + + @ExcelProperty("邮箱") + private String email; + + @ExcelProperty("手机号") + private String mobile; + + @ExcelProperty("机构ID") + private Long orgId; + + @ExcelProperty(value = "状态", converter = StatusConverter.class) + private Integer status; + + @ExcelProperty(value = "超级管理员", converter = SuperConverter.class) + private Integer superAdmin; + + @ExcelProperty(value = "创建时间", converter = DateConverter.class) + private Date createTime; + + public static class GenderConverter implements Converter { + + @Override + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + String dateString = cellData.getStringValue(); + return UserGenderEnum.getValueByName(dateString); + } + + @Override + public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + return new WriteCellData<>(UserGenderEnum.getNameByValue(value)); + } + } + + public static class StatusConverter implements Converter { + + @Override + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + String dateString = cellData.getStringValue(); + return UserStatusEnum.getValueByName(dateString); + } + + @Override + public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + return new WriteCellData<>(UserStatusEnum.getNameByValue(value)); + } + } + + public static class SuperConverter implements Converter { + + @Override + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + String dateString = cellData.getStringValue(); + return SuperAdminEnum.getValueByName(dateString); + } + + @Override + public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + return new WriteCellData<>(SuperAdminEnum.getNameByValue(value)); + } + } +} diff --git a/maku-framework/src/main/java/net/maku/framework/common/excel/ExcelDataListener.java b/maku-framework/src/main/java/net/maku/framework/common/excel/ExcelDataListener.java index 851f6b36abb2a0676df0ad458d31fd3a2a147e2b..2ec4242d9943b2739251c687ff1b79857d450d98 100644 --- a/maku-framework/src/main/java/net/maku/framework/common/excel/ExcelDataListener.java +++ b/maku-framework/src/main/java/net/maku/framework/common/excel/ExcelDataListener.java @@ -41,9 +41,10 @@ public class ExcelDataListener extends AnalysisEventListener { @Override public void invoke(T data, AnalysisContext context) { list.add(data); - if (list.size() == 1) { - System.out.println("自己逻辑"); - + if (list.size() == 500) { + System.out.println(("自己逻辑...")); + this.callBack.doSaveBatch(list); + list.clear(); } } diff --git a/maku-framework/src/main/java/net/maku/framework/common/utils/ExcelUtils.java b/maku-framework/src/main/java/net/maku/framework/common/utils/ExcelUtils.java index 17293f52b4cf66b04466d47c13af81cbdb867d3c..181ebbab6167ee429cda9a8e0f735d7c0b04beb3 100644 --- a/maku-framework/src/main/java/net/maku/framework/common/utils/ExcelUtils.java +++ b/maku-framework/src/main/java/net/maku/framework/common/utils/ExcelUtils.java @@ -4,6 +4,7 @@ import com.alibaba.excel.EasyExcel; import com.alibaba.excel.support.ExcelTypeEnum; import net.maku.framework.common.excel.ExcelDataListener; import net.maku.framework.common.excel.ExcelFinishCallBack; +import org.apache.commons.lang3.StringUtils; import org.springframework.web.multipart.MultipartFile; import java.io.File; @@ -18,6 +19,31 @@ import java.util.List; */ public class ExcelUtils { + + /** + * 判断excel文件类型 + * + * @param file 源头文件 + * @return type + */ + public static ExcelTypeEnum getExcelFileType(MultipartFile file) { + String filename = file.getOriginalFilename(); + if (StringUtils.isNotBlank(filename)) { + filename = filename.substring(filename.lastIndexOf(".")); + switch (filename) { + case ".csv": + return ExcelTypeEnum.CSV; + case ".xls": + return ExcelTypeEnum.XLS; + case ".xlsx": + return ExcelTypeEnum.XLSX; + default: + throw new IllegalArgumentException("无效的文件"); + } + } + throw new IllegalArgumentException("无效的文件"); + } + /** * 读取excel文件 * diff --git a/maku-server/src/test/java/net/maku/EasyExcelTest.java b/maku-server/src/test/java/net/maku/EasyExcelTest.java index 4a632b96b6b88f9c1d914b873a9e75d1f6037358..7433955a951a0d96fe3a8a10a0f1c9d23daabc80 100644 --- a/maku-server/src/test/java/net/maku/EasyExcelTest.java +++ b/maku-server/src/test/java/net/maku/EasyExcelTest.java @@ -8,7 +8,6 @@ import net.maku.framework.common.utils.ExcelUtils; import org.junit.jupiter.api.Test; import java.io.File; -import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -21,7 +20,7 @@ import java.util.List; public class EasyExcelTest { @Test - public void doImport() throws FileNotFoundException { + public void doImport() { File file = new File("D://upload//test01.xlsx"); ExcelClass excelClass = new ExcelClass(); excelClass.setNumber(1); @@ -29,12 +28,11 @@ public class EasyExcelTest { excelClass.setString("test"); excelClass.setDate(new Date()); List data = Arrays.asList(excelClass, excelClass, excelClass); - if (!file.exists()) { + if (file.exists()) { ExcelUtils.excelExport(ExcelClass.class, file, data); + List list = ExcelUtils.readSync(file, ExcelClass.class); + list.forEach(System.out::println); } - - List list = ExcelUtils.readSync(file, ExcelClass.class); - list.forEach(System.out::println); } @@ -49,10 +47,10 @@ public class EasyExcelTest { List data = Arrays.asList(excelClass, excelClass, excelClass, excelClass, excelClass, excelClass, excelClass); if (!file.exists()) { ExcelUtils.excelExport(ExcelClass.class, file, data); + ExcelUtils.readAnalysis(file, ExcelClass.class, new ServiceA()); } - ExcelUtils.readAnalysis(file, ExcelClass.class, new ServiceA()); - } + } @Data public static class ExcelClass {