瀏覽代碼

加入导入导出逻辑

wangliang 1 年之前
父節點
當前提交
758e791521
共有 16 個文件被更改,包括 369 次插入63 次删除
  1. 12 0
      sop-business/src/main/java/com/qmth/sop/business/bean/dto/UserArchivesImportDto.java
  2. 4 19
      sop-business/src/main/java/com/qmth/sop/business/entity/TBTask.java
  3. 20 0
      sop-business/src/main/java/com/qmth/sop/business/service/BasicAttachmentService.java
  4. 8 0
      sop-business/src/main/java/com/qmth/sop/business/service/TBTaskService.java
  5. 73 0
      sop-business/src/main/java/com/qmth/sop/business/service/impl/BasicAttachmentServiceImpl.java
  6. 30 0
      sop-business/src/main/java/com/qmth/sop/business/service/impl/TBTaskServiceImpl.java
  7. 50 5
      sop-business/src/main/java/com/qmth/sop/business/templete/execute/AsyncUserArchivesExportService.java
  8. 8 6
      sop-business/src/main/java/com/qmth/sop/business/templete/execute/AsyncUserArchivesImportService.java
  9. 44 0
      sop-business/src/main/java/com/qmth/sop/business/templete/export/AsyncExportTaskTemplete.java
  10. 9 0
      sop-business/src/main/java/com/qmth/sop/business/templete/service/TaskLogicService.java
  11. 39 3
      sop-business/src/main/java/com/qmth/sop/business/templete/service/impl/TaskLogicServiceImpl.java
  12. 4 0
      sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java
  13. 3 1
      sop-common/src/main/java/com/qmth/sop/common/enums/TaskTypeEnum.java
  14. 1 29
      sop-server/src/main/java/com/qmth/sop/server/api/SysUserController.java
  15. 64 0
      sop-server/src/main/java/com/qmth/sop/server/api/UserArchivesController.java
  16. 二進制
      sop-server/src/main/resources/static/user_archives.xlsx

+ 12 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/dto/UserArchivesImportDto.java

@@ -41,6 +41,18 @@ public class UserArchivesImportDto extends BasicExcelRow implements Serializable
     @NotBlank(message = "角色不能为空")
     private String roleName;
 
+    public UserArchivesImportDto() {
+
+    }
+
+    public UserArchivesImportDto(String name, String code, String phoneNumber, String orgName, String roleName) {
+        this.name = name;
+        this.code = code;
+        this.phoneNumber = phoneNumber;
+        this.orgName = orgName;
+        this.roleName = roleName;
+    }
+
     public String getName() {
         return name;
     }

+ 4 - 19
sop-business/src/main/java/com/qmth/sop/business/entity/TBTask.java

@@ -85,35 +85,20 @@ public class TBTask extends BaseEntity implements Serializable {
 
     }
 
-    public TBTask(TaskTypeEnum type, Long entityId, TaskStatusEnum status, String summary, String importFileName, String importFilePath, Long createId) {
-        setId(SystemConstant.getDbUuid());
-        this.type = type;
-        this.entityId = entityId;
-        this.status = status;
-        this.summary = summary;
-        this.importFileName = importFileName;
-        this.importFilePath = importFilePath;
-        setCreateId(createId);
-        setCreateTime(System.currentTimeMillis());
-    }
-
-    public TBTask(TaskTypeEnum type, TaskStatusEnum status, String summary, String importFileName, String importFilePath, Long createId) {
+    public TBTask(TaskTypeEnum type, TaskStatusEnum status, BasicAttachment basicAttachment, Long createId) {
         setId(SystemConstant.getDbUuid());
         this.type = type;
         this.status = status;
-        this.summary = summary;
-        this.importFileName = importFileName;
-        this.importFilePath = importFilePath;
+        this.importFileName = basicAttachment.getName();
+        this.importFilePath = basicAttachment.getPath();
         setCreateId(createId);
         setCreateTime(System.currentTimeMillis());
     }
 
-    public TBTask(TaskTypeEnum type, TaskStatusEnum status, BasicAttachment basicAttachment, Long createId) {
+    public TBTask(TaskTypeEnum type, TaskStatusEnum status, Long createId) {
         setId(SystemConstant.getDbUuid());
         this.type = type;
         this.status = status;
-        this.importFileName = basicAttachment.getName();
-        this.importFilePath = basicAttachment.getPath();
         setCreateId(createId);
         setCreateTime(System.currentTimeMillis());
     }

+ 20 - 0
sop-business/src/main/java/com/qmth/sop/business/service/BasicAttachmentService.java

@@ -6,6 +6,7 @@ import com.qmth.sop.business.entity.BasicAttachment;
 import com.qmth.sop.common.enums.UploadFileEnum;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.io.IOException;
 
 /**
@@ -18,6 +19,15 @@ import java.io.IOException;
  */
 public interface BasicAttachmentService extends IService<BasicAttachment> {
 
+    /**
+     * 验证附件
+     *
+     * @param file
+     * @return
+     * @throws IOException
+     */
+    public AttachmentInfoDto validateAttachment(File file) throws IOException;
+
     /**
      * 验证附件
      *
@@ -27,6 +37,16 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      */
     public AttachmentInfoDto validateAttachment(MultipartFile file) throws IOException;
 
+    /**
+     * 上传文件接口
+     *
+     * @param file
+     * @param type
+     * @return
+     * @throws IOException
+     */
+    public BasicAttachment saveAttachment(File file, UploadFileEnum type) throws Exception;
+
     /**
      * 上传文件接口
      *

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBTaskService.java

@@ -25,4 +25,12 @@ public interface TBTaskService extends IService<TBTask> {
      * @return
      */
     Map<String, Object> saveTask(MultipartFile file, TaskTypeEnum taskTypeEnum) throws Exception;
+
+    /**
+     * 保存任务
+     *
+     * @param taskTypeEnum
+     * @return
+     */
+    Map<String, Object> saveTask(TaskTypeEnum taskTypeEnum) throws Exception;
 }

+ 73 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/BasicAttachmentServiceImpl.java

@@ -21,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
@@ -42,6 +44,49 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
     @Resource
     FileStoreUtil fileStoreUtil;
 
+    /**
+     * 验证附件
+     *
+     * @param file
+     * @return
+     * @throws IOException
+     */
+    @Override
+    public AttachmentInfoDto validateAttachment(File file) throws IOException {
+        String fileName = FilenameUtils.getBaseName(file.getName());
+        String format = "." + FilenameUtils.getExtension(file.getName());
+
+        SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.ATTACHMENT_TYPE);
+        Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置附件类型"));
+        List<String> attachmentTypeList = Arrays.asList(sysConfig.getConfigValue().replaceAll("\\[", "").replaceAll("\\]", "").split(","));
+        if (Objects.nonNull(format)) {
+            long count = attachmentTypeList.stream().filter(s -> format.equalsIgnoreCase(s)).count();
+            if (count == 0) {
+                throw ExceptionResultEnum.ERROR.exception("文件格式只能为" + attachmentTypeList.toString());
+            }
+        }
+
+        SysConfig sysConfigLength = commonCacheService.addSysConfigCache(SystemConstant.ATTACHMENT_LENGTH);
+        Optional.ofNullable(sysConfigLength).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置附件名称长度"));
+        int attachmentLength = Integer.parseInt(sysConfigLength.getConfigValue());
+        if (Objects.nonNull(fileName) && fileName.length() > attachmentLength) {
+            throw ExceptionResultEnum.ERROR.exception("文件名长度不能超过" + attachmentLength + "个字符");
+        }
+        long size = file.length();
+        BigDecimal b = new BigDecimal(size);
+        BigDecimal num = new BigDecimal(1024);
+        b = b.divide(num, 2, BigDecimal.ROUND_HALF_UP).divide(num, 2, BigDecimal.ROUND_HALF_UP)
+                .setScale(2, BigDecimal.ROUND_HALF_UP);
+
+        SysConfig sysConfigSize = commonCacheService.addSysConfigCache(SystemConstant.ATTACHMENT_SIZE);
+        Optional.ofNullable(sysConfigSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置附件大小"));
+        double attachmentSize = Double.valueOf(sysConfigSize.getConfigValue());
+        if (b.doubleValue() > attachmentSize) {
+            throw ExceptionResultEnum.ERROR.exception("文件大小不能超过" + attachmentSize + "MB");
+        }
+        return new AttachmentInfoDto(fileName, format, b, DigestUtils.md5Hex(new FileInputStream(file)));
+    }
+
     /**
      * 验证附件
      *
@@ -90,6 +135,34 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
         return new AttachmentInfoDto(fileName, format, b, fileMd5);
     }
 
+    /**
+     * 上传文件接口
+     *
+     * @param file
+     * @param type
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public BasicAttachment saveAttachment(File file, UploadFileEnum type) throws Exception {
+        BasicAttachment basicAttachment = null;
+        AttachmentInfoDto attachmentInfoDto = this.validateAttachment(file);
+        if (Objects.nonNull(attachmentInfoDto)) {
+            String fileName = SystemConstant.getNanoId();
+            StringJoiner stringJoiner = SystemConstant.getDirName(type, true).add(fileName).add(attachmentInfoDto.getFormat());
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put(SystemConstant.TYPE, fileStoreUtil.uploadFileEnumIsOss(type) ? SystemConstant.OSS : SystemConstant.LOCAL);
+            fileStoreUtil.ossUpload(stringJoiner.toString(), new FileInputStream(file), attachmentInfoDto.getMd5(), type.getFssType());
+            jsonObject.put(SystemConstant.UPLOAD_TYPE, type);
+            jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
+            attachmentInfoDto.setFileName(fileName);
+            basicAttachment = new BasicAttachment(jsonObject.toJSONString(), attachmentInfoDto, null);
+            this.save(basicAttachment);
+        }
+        Optional.ofNullable(basicAttachment).orElseThrow(() -> ExceptionResultEnum.ATTACHMENT_ERROR.exception());
+        return basicAttachment;
+    }
+
     /**
      * 上传文件接口
      *

+ 30 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBTaskServiceImpl.java

@@ -70,4 +70,34 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
         }
         return map;
     }
+
+    /**
+     * 保存任务
+     *
+     * @param taskTypeEnum
+     * @return
+     * @throws Exception
+     */
+    @Override
+    @Transactional
+    public Map<String, Object> saveTask(TaskTypeEnum taskTypeEnum) throws Exception {
+        Map<String, Object> map = new HashMap<>();
+        try {
+            SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+            TBTask tbTask = new TBTask(taskTypeEnum,
+                    TaskStatusEnum.INIT,
+                    Objects.nonNull(sysUser) ? sysUser.getId() : null);
+            this.save(tbTask);
+            map.computeIfAbsent(SystemConstant.USER, v -> sysUser);
+            map.computeIfAbsent(SystemConstant.TASK, v -> tbTask);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return map;
+    }
 }

+ 50 - 5
sop-business/src/main/java/com/qmth/sop/business/templete/execute/AsyncUserArchivesExportService.java

@@ -1,25 +1,42 @@
 package com.qmth.sop.business.templete.execute;
 
+import cn.hutool.core.date.DateUtil;
+import com.qmth.boot.api.exception.ApiException;
+import com.qmth.sop.business.bean.dto.UserArchivesImportDto;
+import com.qmth.sop.business.entity.BasicAttachment;
+import com.qmth.sop.business.entity.TBTask;
 import com.qmth.sop.business.service.TBTaskService;
 import com.qmth.sop.business.templete.export.AsyncExportTaskTemplete;
 import com.qmth.sop.business.templete.service.TaskLogicService;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.TaskResultEnum;
+import com.qmth.sop.common.enums.TaskStatusEnum;
+import com.qmth.sop.common.enums.TaskTypeEnum;
 import com.qmth.sop.common.util.Result;
+import com.qmth.sop.common.util.ResultUtil;
+import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
 import java.util.Map;
+import java.util.StringJoiner;
 
 /**
- * @Description: 用户档案批量导出
- * @Author: CaoZixuan
- * @Date: 2021-08-12
+ * @Description: 人员档案导出
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2023/8/1
  */
 @Service
 public class AsyncUserArchivesExportService extends AsyncExportTaskTemplete {
     private final static Logger log = LoggerFactory.getLogger(AsyncUserArchivesExportService.class);
-    public static final String OBJ_TITLE = "用户基本信息";
+    public static final String OBJ_TITLE = "人员档案信息";
 
     @Resource
     TaskLogicService taskLogicService;
@@ -29,6 +46,34 @@ public class AsyncUserArchivesExportService extends AsyncExportTaskTemplete {
 
     @Override
     public Result exportTask(Map<String, Object> map) throws Exception {
-        return null;
+        TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
+        StringJoiner stringJoinerSummary = new StringJoiner("\n")
+                .add(MessageFormat.format("{0}{1}{2}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), BEGIN_TITLE, OBJ_TITLE));
+        tbTask.setStatus(TaskStatusEnum.RUNNING);
+        tbTask.setSummary(stringJoinerSummary.toString());
+        tbTaskService.updateById(tbTask);
+        try {
+            Map<String, Object> result = taskLogicService.executeExportUserArchivesLogic(map);
+            List<UserArchivesImportDto> archivesImportDtoList = (List<UserArchivesImportDto>) result.get(SystemConstant.EXCEL_DATA);
+            BasicAttachment basicAttachment = (BasicAttachment) result.get(SystemConstant.EXCEL_ATTACHMENT);
+            stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), FINISH_TITLE, !CollectionUtils.isEmpty(archivesImportDtoList) ? archivesImportDtoList.size() : 0, FINISH_SIZE));
+
+            tbTask.setImportFileName(TaskTypeEnum.USER_ARCHIVES_EXPORT.getTitle());
+            tbTask.setResultFilePath(basicAttachment.getPath());
+            tbTask.setResult(TaskResultEnum.SUCCESS);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), EXCEPTION_TITLE, EXCEPTION_DATA, e.getMessage()));
+            tbTask.setResult(TaskResultEnum.ERROR);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {//生成txt文件
+            tbTask.setSummary(stringJoinerSummary.toString());
+            super.createTxt(tbTask);
+        }
+        return ResultUtil.ok();
     }
 }

+ 8 - 6
sop-business/src/main/java/com/qmth/sop/business/templete/execute/AsyncUserArchivesImportService.java

@@ -25,11 +25,13 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.StringJoiner;
 
-/**
- * @Description: 系统用户批量导入
- * @Author: CaoZixuan
- * @Date: 2021-08-12
- */
+/** 
+* @Description: 人员档案导入
+* @Param:  
+* @return:  
+* @Author: wangliang
+* @Date: 2023/8/1 
+*/ 
 @Service
 public class AsyncUserArchivesImportService extends AsyncImportTaskTemplete {
     private final static Logger log = LoggerFactory.getLogger(AsyncUserArchivesImportService.class);
@@ -46,9 +48,9 @@ public class AsyncUserArchivesImportService extends AsyncImportTaskTemplete {
         TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
         StringJoiner stringJoinerSummary = new StringJoiner("\n").add(MessageFormat.format("{0}{1}{2}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), BEGIN_TITLE, OBJ_TITLE));
         tbTask.setStatus(TaskStatusEnum.RUNNING);
+        tbTask.setSummary(stringJoinerSummary.toString());
         tbTaskService.updateById(tbTask);
         try {
-            tbTask.setSummary(stringJoinerSummary.toString());
             // 执行导入基础用户数据
             Map<String, Object> result = taskLogicService.executeImportUserArchivesLogic(map);
             LinkedMultiValueMap<String, UserArchivesImportDto> userArchivesImportDtoLinkedMultiValueMap = (LinkedMultiValueMap<String, UserArchivesImportDto>) result.get(SystemConstant.EXCEL_DATA);

+ 44 - 0
sop-business/src/main/java/com/qmth/sop/business/templete/export/AsyncExportTaskTemplete.java

@@ -1,12 +1,27 @@
 package com.qmth.sop.business.templete.export;
 
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.boot.api.exception.ApiException;
+import com.qmth.sop.business.entity.TBTask;
+import com.qmth.sop.business.service.TBTaskService;
 import com.qmth.sop.business.templete.importData.AsyncImportTaskTemplete;
+import com.qmth.sop.business.util.ImportExportUtil;
+import com.qmth.sop.common.contant.SpringContextHolder;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.TaskResultEnum;
+import com.qmth.sop.common.enums.TaskStatusEnum;
 import com.qmth.sop.common.util.Result;
+import com.qmth.sop.common.util.ResultUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.scheduling.annotation.Async;
 
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Date;
 import java.util.Map;
+import java.util.StringJoiner;
 
 /**
  * @Description: 异步导出模版
@@ -32,4 +47,33 @@ public abstract class AsyncExportTaskTemplete {
      */
     @Async
     public abstract Result exportTask(Map<String, Object> map) throws Exception;
+
+    /**
+     * 创建txt文件
+     *
+     * @param tbTask
+     */
+    public void createTxt(TBTask tbTask) throws IOException {
+        try {
+            ImportExportUtil importExportUtil = SpringContextHolder.getBean(ImportExportUtil.class);
+            JSONObject json = importExportUtil.createTxt(tbTask.getSummary());
+            tbTask.setReportFilePath(json.toJSONString());
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            StringJoiner stringJoinerSummary = new StringJoiner("").add(tbTask.getSummary()).add("\n");
+            stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), EXCEPTION_CREATE_TXT_TITLE, EXCEPTION_DATA, e.getMessage()));
+
+            tbTask.setSummary(stringJoinerSummary.toString());
+            tbTask.setResult(TaskResultEnum.ERROR);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {
+            TBTaskService tbTaskService = SpringContextHolder.getBean(TBTaskService.class);
+            tbTask.setStatus(TaskStatusEnum.FINISH);
+            tbTaskService.updateById(tbTask);
+        }
+    }
 }

+ 9 - 0
sop-business/src/main/java/com/qmth/sop/business/templete/service/TaskLogicService.java

@@ -19,4 +19,13 @@ public interface TaskLogicService {
      * @throws Exception 异常
      */
     Map<String, Object> executeImportUserArchivesLogic(Map<String, Object> map) throws Exception;
+
+    /**
+     * 处理导出人员档案数据
+     *
+     * @param map 数据源
+     * @return 结果
+     * @throws Exception 异常
+     */
+    Map<String, Object> executeExportUserArchivesLogic(Map<String, Object> map) throws Exception;
 }

+ 39 - 3
sop-business/src/main/java/com/qmth/sop/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -2,11 +2,14 @@ package com.qmth.sop.business.templete.service.impl;
 
 import com.alibaba.excel.EasyExcel;
 import com.qmth.sop.business.bean.dto.UserArchivesImportDto;
+import com.qmth.sop.business.entity.BasicAttachment;
 import com.qmth.sop.business.entity.TBTask;
+import com.qmth.sop.business.service.BasicAttachmentService;
 import com.qmth.sop.business.templete.service.TaskLogicService;
 import com.qmth.sop.business.util.ImportExportUtil;
 import com.qmth.sop.business.util.excel.BasicExcelListener;
 import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.UploadFileEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -14,10 +17,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.LinkedMultiValueMap;
 
 import javax.annotation.Resource;
+import java.io.File;
 import java.io.InputStream;
-import java.util.Map;
-import java.util.Objects;
-import java.util.StringJoiner;
+import java.util.*;
 
 /**
  * @Description: 任务处理逻辑impl
@@ -33,6 +35,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     ImportExportUtil importExportUtil;
 
+    @Resource
+    BasicAttachmentService basicAttachmentService;
+
     /**
      * 处理导入人员档案数据
      *
@@ -69,4 +74,35 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         }
         return map;
     }
+
+    /**
+     * 处理导出人员档案数据
+     *
+     * @param map 数据源
+     * @return
+     * @throws Exception
+     */
+    @Override
+    @Transactional
+    public Map<String, Object> executeExportUserArchivesLogic(Map<String, Object> map) throws Exception {
+        File fileTemp = null;
+        try {
+            fileTemp = SystemConstant.getFileTempVar(SystemConstant.XLSX_PREFIX);
+            //数据读取逻辑start
+            List<UserArchivesImportDto> archivesImportDtoList = new ArrayList<>();
+            archivesImportDtoList.add(new UserArchivesImportDto("1", "2", "123", "aaa", "bbb"));
+            archivesImportDtoList.add(new UserArchivesImportDto("4", "5", "789", "ccc", "ddd"));
+            //数据读取逻辑end
+            EasyExcel.write(fileTemp, UserArchivesImportDto.class).sheet("人员档案导出").doWrite(archivesImportDtoList);
+
+            BasicAttachment basicAttachment = basicAttachmentService.saveAttachment(fileTemp, UploadFileEnum.FILE);
+            map.computeIfAbsent(SystemConstant.EXCEL_DATA, v -> archivesImportDtoList);
+            map.computeIfAbsent(SystemConstant.EXCEL_ATTACHMENT, v -> basicAttachment);
+        } finally {
+            if (Objects.nonNull(fileTemp)) {
+                fileTemp.delete();
+            }
+        }
+        return map;
+    }
 }

+ 4 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -70,8 +70,11 @@ public class SystemConstant {
     public static final String TEMP = "temp";
     public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
     public static final String TXT_PREFIX = ".txt";
+    public static final String XLSX_PREFIX = ".xlsx";
+    public static final String XLS_PREFIX = "xls";
     public static final String EXCEL_DATA = "excelData";
     public static final String EXCEL_DATA_ERROR = "excelDataError";
+    public static final String EXCEL_ATTACHMENT = "excelAttachment";
 
     /**
      * 系统配置
@@ -99,6 +102,7 @@ public class SystemConstant {
     public static final String PREFIX_TEST_FLOW = "/test/flow";
     public static final String PREFIX_URL_COMMON = "/admin/common";
     public static final String PREFIX_URL_USER = "/admin/user";
+    public static final String PREFIX_URL_USER_ARCHIVES = "/admin/user/archives";
 
     /**
      * 缓存配置

+ 3 - 1
sop-common/src/main/java/com/qmth/sop/common/enums/TaskTypeEnum.java

@@ -11,7 +11,9 @@ import java.util.Objects;
  */
 public enum TaskTypeEnum {
 
-    USER_IMPORT("用户导入");
+    USER_ARCHIVES_IMPORT("人员档案导入"),
+
+    USER_ARCHIVES_EXPORT("人员档案导出");
 
     private String title;
 

+ 1 - 29
sop-server/src/main/java/com/qmth/sop/server/api/SysUserController.java

@@ -1,23 +1,10 @@
 package com.qmth.sop.server.api;
 
 import com.qmth.boot.api.constant.ApiConstant;
-import com.qmth.sop.business.bean.result.EditResult;
-import com.qmth.sop.business.entity.TBTask;
-import com.qmth.sop.business.service.TBTaskService;
-import com.qmth.sop.business.templete.execute.AsyncUserArchivesImportService;
 import com.qmth.sop.common.contant.SystemConstant;
-import com.qmth.sop.common.enums.TaskTypeEnum;
-import com.qmth.sop.common.util.Result;
-import com.qmth.sop.common.util.ResultUtil;
-import io.swagger.annotations.*;
+import io.swagger.annotations.Api;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.annotation.Resource;
-import java.util.Map;
 
 /**
  * <p>
@@ -32,19 +19,4 @@ import java.util.Map;
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_USER)
 public class SysUserController {
 
-    @Resource
-    TBTaskService tbTaskService;
-
-    @Resource
-    AsyncUserArchivesImportService asyncSysUserDataImportService;
-
-    @ApiOperation(value = "用户导入")
-    @RequestMapping(value = "/import", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
-    public Result importUser(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) throws Exception {
-        Map<String, Object> map = tbTaskService.saveTask(file, TaskTypeEnum.USER_IMPORT);
-        asyncSysUserDataImportService.importTask(map);
-        TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
-        return ResultUtil.ok(tbTask.getId());
-    }
 }

+ 64 - 0
sop-server/src/main/java/com/qmth/sop/server/api/UserArchivesController.java

@@ -0,0 +1,64 @@
+package com.qmth.sop.server.api;
+
+import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.sop.business.bean.result.EditResult;
+import com.qmth.sop.business.entity.TBTask;
+import com.qmth.sop.business.service.TBTaskService;
+import com.qmth.sop.business.templete.execute.AsyncUserArchivesExportService;
+import com.qmth.sop.business.templete.execute.AsyncUserArchivesImportService;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.TaskTypeEnum;
+import com.qmth.sop.common.util.Result;
+import com.qmth.sop.common.util.ResultUtil;
+import io.swagger.annotations.*;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.util.Map;
+
+/**
+ * <p>
+ * 人员档案表 前端控制器
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-07-17
+ */
+@Api(tags = "人员档案Controller")
+@RestController
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_USER_ARCHIVES)
+public class UserArchivesController {
+
+    @Resource
+    TBTaskService tbTaskService;
+
+    @Resource
+    AsyncUserArchivesImportService asyncUserArchivesImportService;
+
+    @Resource
+    AsyncUserArchivesExportService asyncUserArchivesExportService;
+
+    @ApiOperation(value = "人员档案导入")
+    @RequestMapping(value = "/import", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
+    public Result importUserArchives(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) throws Exception {
+        Map<String, Object> map = tbTaskService.saveTask(file, TaskTypeEnum.USER_ARCHIVES_IMPORT);
+        asyncUserArchivesImportService.importTask(map);
+        TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
+        return ResultUtil.ok(tbTask.getId());
+    }
+
+    @ApiOperation(value = "人员档案导出")
+    @RequestMapping(value = "/export", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
+    public Result exportUserArchives() throws Exception {
+        Map<String, Object> map = tbTaskService.saveTask(TaskTypeEnum.USER_ARCHIVES_EXPORT);
+        asyncUserArchivesExportService.exportTask(map);
+        TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
+        return ResultUtil.ok(tbTask.getId());
+    }
+}

二進制
sop-server/src/main/resources/static/user.xlsx → sop-server/src/main/resources/static/user_archives.xlsx