Преглед на файлове

feat(qhse): 添加学习文件人员同步功能

- 新增同步人员接口和相关服务方法
- 实现学习文件历史记录创建和人员历史记录处理逻辑
- 添加根据历史ID删除人员历史记录的功能
- 优化数据库查询,增加根据原主键查询最新记录的方法
lg преди 1 месец
родител
ревизия
d22e981f3b

+ 7 - 0
qhse-common/src/main/java/com/rongwei/bscommon/sys/dao/StudyFileRecordDao.java

@@ -4,4 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.rongwei.bsentity.domain.StudyFileRecordDo;
 
 public interface StudyFileRecordDao extends BaseMapper<StudyFileRecordDo> {
+    /**
+     * 根据原主键查询最新一条记录
+     *
+     * @param mainId 原主键
+     * @return 最新记录
+     */
+    StudyFileRecordDo selectLatestRecordByMainId(String mainId);
 }

+ 7 - 0
qhse-common/src/main/java/com/rongwei/bscommon/sys/service/StudyFilePersonRecordService.java

@@ -4,4 +4,11 @@ import com.rongwei.bsentity.domain.StudyFilePersonRecordDo;
 import com.rongwei.rwcommon.base.BaseService;
 
 public interface StudyFilePersonRecordService extends BaseService<StudyFilePersonRecordDo> {
+    /**
+     * 根据历史ID删除
+     *
+     * @param historyId 历史ID
+     * @return 删除数量
+     */
+    boolean deleteByHistoryId(String historyId);
 }

+ 8 - 1
qhse-common/src/main/java/com/rongwei/bscommon/sys/service/StudyFileRecordService.java

@@ -3,5 +3,12 @@ package com.rongwei.bscommon.sys.service;
 import com.rongwei.bsentity.domain.StudyFileRecordDo;
 import com.rongwei.rwcommon.base.BaseService;
 
-public interface StudyFileRecordService  extends BaseService<StudyFileRecordDo> {
+public interface StudyFileRecordService extends BaseService<StudyFileRecordDo> {
+    /**
+     * 根据原表 id 查询最新一条历史记录
+     *
+     * @param mainId 原表 id
+     * @return 最新一条历史记录
+     */
+    StudyFileRecordDo selectLatestRecordByMainId(String mainId);
 }

+ 9 - 0
qhse-common/src/main/java/com/rongwei/bscommon/sys/service/StudyFileService.java

@@ -1,5 +1,6 @@
 package com.rongwei.bscommon.sys.service;
 
+import com.rongwei.bsentity.Dto.StudyFileProduceHistoryDto;
 import com.rongwei.bsentity.domain.StudyFileDo;
 
 public interface StudyFileService {
@@ -11,4 +12,12 @@ public interface StudyFileService {
      * @return 生成结果
      */
     boolean produceHistory(StudyFileDo studyFileDo, String processType);
+
+    /**
+     * 同步人员信息
+     *
+     * @param dto 同步参数
+     * @return 同步结果
+     */
+    boolean syncPerson(StudyFileProduceHistoryDto dto);
 }

+ 18 - 1
qhse-common/src/main/java/com/rongwei/bscommon/sys/service/impl/StudyFilePersonRecordServiceImpl.java

@@ -4,8 +4,25 @@ import com.rongwei.bscommon.sys.dao.StudyFilePersonRecordDao;
 import com.rongwei.bscommon.sys.service.StudyFilePersonRecordService;
 import com.rongwei.bsentity.domain.StudyFilePersonRecordDo;
 import com.rongwei.rwcommon.base.BaseServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 @Service
-public class StudyFilePersonRecordServiceImpl extends BaseServiceImpl<StudyFilePersonRecordDao,StudyFilePersonRecordDo> implements StudyFilePersonRecordService {
+public class StudyFilePersonRecordServiceImpl extends BaseServiceImpl<StudyFilePersonRecordDao, StudyFilePersonRecordDo>
+        implements StudyFilePersonRecordService {
+    @Autowired
+    private StudyFilePersonRecordDao studyFilePersonRecordDao;
+
+    /**
+     * 根据历史ID删除
+     *
+     * @param historyId 历史ID
+     * @return 删除数量
+     */
+    @Override
+    public boolean deleteByHistoryId(String historyId) {
+        return lambdaUpdate()
+                .eq(StudyFilePersonRecordDo::getHistoryId, historyId)
+                .remove();
+    }
 }

+ 11 - 0
qhse-common/src/main/java/com/rongwei/bscommon/sys/service/impl/StudyFileRecordServiceImpl.java

@@ -11,4 +11,15 @@ import org.springframework.stereotype.Service;
 public class StudyFileRecordServiceImpl extends BaseServiceImpl<StudyFileRecordDao, StudyFileRecordDo> implements StudyFileRecordService {
     @Autowired
     private StudyFileRecordDao studyFileRecordDao;
+
+    /**
+     * 根据原表 id 查询最新一条历史记录
+     *
+     * @param mainId 原表 id
+     * @return 最新一条历史记录
+     */
+    @Override
+    public StudyFileRecordDo selectLatestRecordByMainId(String mainId) {
+        return studyFileRecordDao.selectLatestRecordByMainId(mainId);
+    }
 }

+ 55 - 12
qhse-common/src/main/java/com/rongwei/bscommon/sys/service/impl/StudyFileServiceImpl.java

@@ -6,7 +6,11 @@ import com.rongwei.bscommon.sys.service.StudyFilePersonService;
 import com.rongwei.bscommon.sys.service.StudyFileRecordService;
 import com.rongwei.bscommon.sys.service.StudyFileService;
 import com.rongwei.bscommon.sys.utils.QHSEUtils;
-import com.rongwei.bsentity.domain.*;
+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.rwadmincommon.system.vo.SysUserVo;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import org.springframework.beans.BeanUtils;
@@ -39,6 +43,8 @@ public class StudyFileServiceImpl implements StudyFileService {
     @Override
     @Transactional
     public boolean produceHistory(StudyFileDo studyFileDo, String processType) {
+        // 获取当前用户信息
+        SysUserVo currentUser = QHSEUtils.getCurrentUser();
 
         // 获取最新的学习文件信息
         StudyFileDo currentFile = studyFileDao.selectById(studyFileDo.getId());
@@ -53,11 +59,38 @@ public class StudyFileServiceImpl implements StudyFileService {
         }
 
         // 保存历史学习文件信息
-        StudyFileRecordDo historyFile = createHistoryFileRecord(currentFile);
+        StudyFileRecordDo historyFile = createHistoryFileRecord(currentFile, currentUser);
         studyFileRecordService.save(historyFile);
 
         // 处理相关人员历史记录
-        processPersonHistoryRecords(currentFile.getId(), historyFile.getId(), processType);
+        processPersonHistoryRecords(currentFile.getId(), historyFile.getId(), processType, currentUser);
+
+        return true;
+    }
+
+    /**
+     * 同步人员信息
+     *
+     * @param dto 同步数据
+     * @return 同步结果
+     */
+    @Override
+    @Transactional
+    public boolean syncPerson(StudyFileProduceHistoryDto dto) {
+        SysUserVo currentUser = QHSEUtils.getCurrentUser();
+        // 查询当前文件的所有人员信息
+        List<StudyFilePersonDo> currentPersons = studyFilePersonService.selectListByStudyFileId(dto.getId());
+        // 获取最新历史文件
+        StudyFileRecordDo historyFile = studyFileRecordService.selectLatestRecordByMainId(dto.getId());
+        // 删除人员历史记录
+        studyFilePersonRecordService.deleteByHistoryId(historyFile.getId());
+        // 转换为历史记录并收集需要删除的ID
+        List<StudyFilePersonRecordDo> historyPersons = currentPersons.stream()
+                .map(person -> convertToHistoryPersonRecord(person, historyFile.getId(), currentUser))
+                .collect(Collectors.toList());
+
+        // 批量保存历史记录
+        studyFilePersonRecordService.saveBatch(historyPersons);
 
         return true;
     }
@@ -65,13 +98,20 @@ public class StudyFileServiceImpl implements StudyFileService {
     /**
      * 创建历史学习文件记录
      *
-     * @param source 源数据
+     * @param source      源数据
+     * @param currentUser
      */
-    private StudyFileRecordDo createHistoryFileRecord(StudyFileDo source) {
+    private StudyFileRecordDo createHistoryFileRecord(StudyFileDo source, SysUserVo currentUser) {
         StudyFileRecordDo target = new StudyFileRecordDo();
         BeanUtils.copyProperties(source, target);
         target.setId(SecurityUtil.getUUID());
         target.setMainId(source.getId());
+        target.setCreatedate(new Date());
+        target.setCreateuserid(currentUser.getId());
+        target.setCreateusername(currentUser.getName());
+        target.setModifydate(new Date());
+        target.setModifyuserid(currentUser.getId());
+        target.setModifyusername(currentUser.getName());
         return target;
     }
 
@@ -81,15 +121,14 @@ public class StudyFileServiceImpl implements StudyFileService {
      * @param fileId        文件ID
      * @param historyFileId 历史文件ID
      * @param processType   流程类型
+     * @param currentUser   当前用户
      */
-    private void processPersonHistoryRecords(String fileId, String historyFileId, String processType) {
-        // 获取当前用户信息
-        SysUserVo currentUser = QHSEUtils.getCurrentUser();
-
+    private void processPersonHistoryRecords(String fileId,
+                                             String historyFileId, String processType, SysUserVo currentUser) {
         // 查询当前文件的所有人员信息
         List<StudyFilePersonDo> currentPersons = studyFilePersonService.selectListByStudyFileId(fileId);
 
-        // 转换为历史记录并收集需要删除的ID
+        // 转换为历史记录
         List<StudyFilePersonRecordDo> historyPersons = currentPersons.stream()
                 .map(person -> convertToHistoryPersonRecord(person, historyFileId, currentUser))
                 .collect(Collectors.toList());
@@ -115,15 +154,19 @@ public class StudyFileServiceImpl implements StudyFileService {
      * @param historyFileId 历史文件ID
      * @param currentUser
      */
-    private StudyFilePersonRecordDo convertToHistoryPersonRecord(StudyFilePersonDo source, String historyFileId, SysUserVo currentUser) {
+    private StudyFilePersonRecordDo convertToHistoryPersonRecord(StudyFilePersonDo source,
+                                                                 String historyFileId, SysUserVo currentUser) {
         StudyFilePersonRecordDo target = new StudyFilePersonRecordDo();
         BeanUtils.copyProperties(source, target);
         target.setId(SecurityUtil.getUUID());
         target.setMainId(source.getId());
-        target.setStudyFileId(historyFileId);
+        target.setHistoryId(historyFileId);
         target.setCreatedate(new Date());
         target.setCreateuserid(currentUser.getId());
         target.setCreateusername(currentUser.getName());
+        target.setModifydate(new Date());
+        target.setModifyuserid(currentUser.getId());
+        target.setModifyusername(currentUser.getName());
         return target;
     }
 }

+ 7 - 0
qhse-common/src/main/resources/mybatis/StudyFileRecordDao.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.rongwei.bscommon.sys.dao.StudyFileRecordDao">
+    <select id="selectLatestRecordByMainId" resultType="com.rongwei.bsentity.domain.StudyFileRecordDo">
+        SELECT * FROM qhse_study_file_record ORDER BY CREATEDATE LIMIT 1
+    </select>
+</mapper>

+ 6 - 4
qhse-entity/src/main/java/com/rongwei/bsentity/domain/StudyFilePersonRecordDo.java

@@ -1,6 +1,8 @@
 package com.rongwei.bsentity.domain;
 
-import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
 import com.rongwei.rwcommon.base.BaseDo;
 import lombok.Data;
@@ -29,10 +31,10 @@ public class StudyFilePersonRecordDo extends BaseDo {
     private String mainId;
 
     /**
-     * 学习文件ID
+     * 历史文件ID
      */
-    @TableField("STUDYFILEID")
-    private String studyFileId;
+    @TableField("HISTORYID")
+    private String historyId;
 
     /**
      * 部门id

+ 14 - 0
qhse-server/src/main/java/com/rongwei/controller/StudyFileController.java

@@ -29,4 +29,18 @@ public class StudyFileController {
         }
         return studyFileService.produceHistory(dto, dto.getProcessType()) ? R.ok() : R.error("生成历史记录失败!");
     }
+
+    /**
+     * 同步人员
+     *
+     * @param dto 同步参数
+     * @return 同步结果
+     */
+    @PostMapping("/sync/person")
+    public R syncPerson(@RequestBody StudyFileProduceHistoryDto dto) {
+        if (StringUtils.isBlank(dto.getId())) {
+            return R.error("请选择要同步的学习文件!");
+        }
+        return studyFileService.syncPerson(dto) ? R.ok() : R.error("同步人员失败!");
+    }
 }