Jelajahi Sumber

feat(qhse): 添加学习文件取消流程功能

- 在 StudyFileController 中添加取消流程接口
- 在 StudyFileService 中实现取消流程方法
- 新增相关 mapper 和 service 方法以支持取消流程功能
- 优化 StudyFileRecordDao.xml 中的 SQL 查询
lg 1 Minggu lalu
induk
melakukan
31347f2824

+ 10 - 0
qhse-common/src/main/java/com/rongwei/bscommon/system/service/StudyFilePersonRecordService.java

@@ -3,6 +3,8 @@ package com.rongwei.bscommon.system.service;
 import com.rongwei.bsentity.domain.StudyFilePersonRecordDo;
 import com.rongwei.rwcommon.base.BaseService;
 
+import java.util.List;
+
 public interface StudyFilePersonRecordService extends BaseService<StudyFilePersonRecordDo> {
     /**
      * 根据历史ID删除
@@ -11,4 +13,12 @@ public interface StudyFilePersonRecordService extends BaseService<StudyFilePerso
      * @return 删除数量
      */
     boolean deleteByHistoryId(String historyId);
+
+    /**
+     * 根据历史ID查询
+     *
+     * @param id 历史ID
+     * @return 查询结果
+     */
+    List<StudyFilePersonRecordDo> selectListByHistoryId(String id);
 }

+ 7 - 0
qhse-common/src/main/java/com/rongwei/bscommon/system/service/StudyFilePersonService.java

@@ -13,4 +13,11 @@ public interface StudyFilePersonService extends BaseService<StudyFilePersonDo> {
      * @return 学习文件人员
      */
     List<StudyFilePersonDo> selectListByStudyFileId(String studyFileId);
+
+    /**
+     * 根据学习文件id删除学习文件人员
+     *
+     * @param id 学习文件id
+     */
+    boolean deleteByStudyFileId(String id);
 }

+ 10 - 1
qhse-common/src/main/java/com/rongwei/bscommon/system/service/StudyFileService.java

@@ -1,7 +1,8 @@
 package com.rongwei.bscommon.system.service;
 
-import com.rongwei.bsentity.dto.StudyFileProduceHistoryDto;
 import com.rongwei.bsentity.domain.StudyFileDo;
+import com.rongwei.bsentity.dto.StudyFileProduceHistoryDto;
+import com.rongwei.rwcommon.base.R;
 
 public interface StudyFileService {
     /**
@@ -20,4 +21,12 @@ public interface StudyFileService {
      * @return 同步结果
      */
     boolean syncPerson(StudyFileProduceHistoryDto dto);
+
+    /**
+     * 取消流程,恢复历史数据
+     *
+     * @param id 取消流程的文件 ID
+     * @return 结果
+     */
+    R cancelProcess(String id);
 }

+ 15 - 0
qhse-common/src/main/java/com/rongwei/bscommon/system/service/impl/StudyFilePersonRecordServiceImpl.java

@@ -7,6 +7,8 @@ import com.rongwei.rwcommon.base.BaseServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 public class StudyFilePersonRecordServiceImpl extends BaseServiceImpl<StudyFilePersonRecordDao, StudyFilePersonRecordDo>
         implements StudyFilePersonRecordService {
@@ -25,4 +27,17 @@ public class StudyFilePersonRecordServiceImpl extends BaseServiceImpl<StudyFileP
                 .eq(StudyFilePersonRecordDo::getHistoryId, historyId)
                 .remove();
     }
+
+    /**
+     * 根据历史ID查询
+     *
+     * @param id 历史ID
+     * @return 列表
+     */
+    @Override
+    public List<StudyFilePersonRecordDo> selectListByHistoryId(String id) {
+        return lambdaQuery().eq(StudyFilePersonRecordDo::getHistoryId, id)
+                .eq(StudyFilePersonRecordDo::getDeleted, "0")
+                .list();
+    }
 }

+ 13 - 0
qhse-common/src/main/java/com/rongwei/bscommon/system/service/impl/StudyFilePersonServiceImpl.java

@@ -23,4 +23,17 @@ public class StudyFilePersonServiceImpl extends BaseServiceImpl<StudyFilePersonD
                 .eq(StudyFilePersonDo::getDeleted, "0")
                 .list();
     }
+
+    /**
+     * 根据学习文件id删除学习文件人员
+     *
+     * @param id 学习文件id
+     * @return 是否成功
+     */
+    @Override
+    public boolean deleteByStudyFileId(String id) {
+        return lambdaUpdate().eq(StudyFilePersonDo::getStudyFileId, id)
+                .eq(StudyFilePersonDo::getDeleted, "0")
+                .remove();
+    }
 }

+ 65 - 1
qhse-common/src/main/java/com/rongwei/bscommon/system/service/impl/StudyFileServiceImpl.java

@@ -6,13 +6,16 @@ import com.rongwei.bscommon.system.service.StudyFilePersonService;
 import com.rongwei.bscommon.system.service.StudyFileRecordService;
 import com.rongwei.bscommon.system.service.StudyFileService;
 import com.rongwei.bscommon.system.utils.QHSEUtils;
-import com.rongwei.bsentity.dto.StudyFileProduceHistoryDto;
 import com.rongwei.bsentity.domain.StudyFileDo;
 import com.rongwei.bsentity.domain.StudyFilePersonDo;
 import com.rongwei.bsentity.domain.StudyFilePersonRecordDo;
 import com.rongwei.bsentity.domain.StudyFileRecordDo;
+import com.rongwei.bsentity.dto.StudyFileProduceHistoryDto;
 import com.rongwei.rwadmincommon.system.vo.SysUserVo;
+import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.utils.SecurityUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -20,10 +23,14 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Service
 public class StudyFileServiceImpl implements StudyFileService {
+
+    private static final Logger logger = LoggerFactory.getLogger(StudyFileServiceImpl.class);
+
     @Autowired
     private StudyFileDao studyFileDao;
     @Autowired
@@ -95,6 +102,63 @@ public class StudyFileServiceImpl implements StudyFileService {
         return true;
     }
 
+    /**
+     * 取消流程,恢复历史数据
+     *
+     * @param id 取消流程的文件 ID
+     * @return 结果
+     */
+    @Override
+    public R cancelProcess(String id) {
+        // 获取最新的学习文件信息
+        StudyFileDo currentFile = studyFileDao.selectById(id);
+        // 获取最新历史文件
+        StudyFileRecordDo historyFile = studyFileRecordService.selectLatestRecordByMainId(id);
+        if (historyFile == null) {
+            logger.info("文件:{},没有找到对应的历史文件", id);
+            return R.ok("没有找到对应的历史文件");
+        }
+        // 恢复文件历史数据
+        BeanUtils.copyProperties(historyFile, currentFile);
+        currentFile.setId(historyFile.getMainId());
+        if (Objects.isNull(historyFile.getRemark())) {
+            currentFile.setRemark("");
+        }
+        studyFileDao.updateById(currentFile);
+
+        // 删除人员信息
+        studyFilePersonService.deleteByStudyFileId(id);
+        List<StudyFilePersonRecordDo> personRecords =
+                studyFilePersonRecordService.selectListByHistoryId(historyFile.getId());
+
+        if (personRecords == null || personRecords.isEmpty()) {
+            logger.info("文件:{},没有找到对应人员历史数据", id);
+            return R.ok();
+        }
+
+        // 恢复人员
+        List<StudyFilePersonDo> persons = personRecords.stream()
+                .map(record -> convertToPerson(record, currentFile))
+                .collect(Collectors.toList());
+        studyFilePersonService.saveBatch(persons);
+        return R.ok();
+    }
+
+    /**
+     * 转换人员信息
+     *
+     * @param record      历史记录
+     * @param currentFile 最新文件
+     * @return 人员信息
+     */
+    private StudyFilePersonDo convertToPerson(StudyFilePersonRecordDo record, StudyFileDo currentFile) {
+        StudyFilePersonDo studyFilePersonDo = new StudyFilePersonDo();
+        BeanUtils.copyProperties(record, studyFilePersonDo);
+        studyFilePersonDo.setId(SecurityUtil.getUUID());
+        studyFilePersonDo.setStudyFileId(currentFile.getId());
+        return studyFilePersonDo;
+    }
+
     /**
      * 创建历史学习文件记录
      *

+ 1 - 1
qhse-common/src/main/resources/mybatis/system/StudyFileRecordDao.xml

@@ -2,6 +2,6 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.rongwei.bscommon.system.dao.StudyFileRecordDao">
     <select id="selectLatestRecordByMainId" resultType="com.rongwei.bsentity.domain.StudyFileRecordDo">
-        SELECT*FROM qhse_study_file_record WHERE MAINID= #{ mainId } ORDER BY CREATEDATE LIMIT 1
+        SELECT * FROM qhse_study_file_record WHERE MAINID= #{ mainId } ORDER BY CREATEDATE DESC LIMIT 1
     </select>
 </mapper>

qhse-entity/src/main/java/com/rongwei/bsentity/Dto/PunishmentExcelDto.java → qhse-entity/src/main/java/com/rongwei/bsentity/dto/PunishmentExcelDto.java


qhse-entity/src/main/java/com/rongwei/bsentity/Dto/QhseVisitorManagementDto.java → qhse-entity/src/main/java/com/rongwei/bsentity/dto/QhseVisitorManagementDto.java


qhse-entity/src/main/java/com/rongwei/bsentity/Dto/SendMessageDto.java → qhse-entity/src/main/java/com/rongwei/bsentity/dto/SendMessageDto.java


qhse-entity/src/main/java/com/rongwei/bsentity/Dto/StudyFileProduceHistoryDto.java → qhse-entity/src/main/java/com/rongwei/bsentity/dto/StudyFileProduceHistoryDto.java


+ 20 - 4
qhse-server/src/main/java/com/rongwei/controller/StudyFileController.java

@@ -4,15 +4,16 @@ import com.rongwei.bscommon.system.service.StudyFileService;
 import com.rongwei.bsentity.dto.StudyFileProduceHistoryDto;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 @RestController
 @RequestMapping("/study/file")
 public class StudyFileController {
+    private static final Logger logger = LoggerFactory.getLogger(StudyFileController.class);
+
     @Autowired
     private StudyFileService studyFileService;
 
@@ -43,4 +44,19 @@ public class StudyFileController {
         }
         return studyFileService.syncPerson(dto) ? R.ok() : R.error("同步人员失败!");
     }
+
+    /**
+     * 取消流程,恢复历史数据
+     *
+     * @param id 取消流程的文件 ID
+     * @return 结果
+     */
+    @GetMapping("/cancel/process/{id}")
+    public R cancelProcess(@PathVariable String id) {
+        logger.info("取消流程,恢复历史数据,入参:{}", id);
+        if (StringUtils.isBlank(id)) {
+            return R.error("主健不能为空!");
+        }
+        return studyFileService.cancelProcess(id);
+    }
 }