|
@@ -0,0 +1,121 @@
|
|
|
+package com.rongwei.bscommon.sys.service.impl;
|
|
|
+
|
|
|
+import com.rongwei.bscommon.sys.dao.StudyFileDao;
|
|
|
+import com.rongwei.bscommon.sys.service.StudyFilePersonRecordService;
|
|
|
+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.rwadmincommon.system.vo.SysUserVo;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class StudyFileServiceImpl implements StudyFileService {
|
|
|
+ @Autowired
|
|
|
+ private StudyFileDao studyFileDao;
|
|
|
+ @Autowired
|
|
|
+ private StudyFileRecordService studyFileRecordService;
|
|
|
+ @Autowired
|
|
|
+ private StudyFilePersonService studyFilePersonService;
|
|
|
+ @Autowired
|
|
|
+ private StudyFilePersonRecordService studyFilePersonRecordService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成历史数据
|
|
|
+ *
|
|
|
+ * @param studyFileDo 学习文件
|
|
|
+ * @param processType 流程类型
|
|
|
+ * @return 生成结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean produceHistory(StudyFileDo studyFileDo, String processType) {
|
|
|
+
|
|
|
+ // 获取最新的学习文件信息
|
|
|
+ StudyFileDo currentFile = studyFileDao.selectById(studyFileDo.getId());
|
|
|
+ if (currentFile == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存历史学习文件信息
|
|
|
+ StudyFileRecordDo historyFile = createHistoryFileRecord(currentFile);
|
|
|
+ studyFileRecordService.save(historyFile);
|
|
|
+
|
|
|
+ // 处理相关人员历史记录
|
|
|
+ processPersonHistoryRecords(currentFile.getId(), historyFile.getId(), processType);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建历史学习文件记录
|
|
|
+ *
|
|
|
+ * @param source 源数据
|
|
|
+ */
|
|
|
+ private StudyFileRecordDo createHistoryFileRecord(StudyFileDo source) {
|
|
|
+ StudyFileRecordDo target = new StudyFileRecordDo();
|
|
|
+ BeanUtils.copyProperties(source, target);
|
|
|
+ target.setId(SecurityUtil.getUUID());
|
|
|
+ target.setMainId(source.getId());
|
|
|
+ return target;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理相关人员历史记录
|
|
|
+ *
|
|
|
+ * @param fileId 文件ID
|
|
|
+ * @param historyFileId 历史文件ID
|
|
|
+ * @param processType 流程类型
|
|
|
+ */
|
|
|
+ private void processPersonHistoryRecords(String fileId, String historyFileId, String processType) {
|
|
|
+ // 获取当前用户信息
|
|
|
+ SysUserVo currentUser = QHSEUtils.getCurrentUser();
|
|
|
+
|
|
|
+ // 查询当前文件的所有人员信息
|
|
|
+ List<StudyFilePersonDo> currentPersons = studyFilePersonService.selectListByStudyFileId(fileId);
|
|
|
+
|
|
|
+ // 转换为历史记录并收集需要删除的ID
|
|
|
+ List<StudyFilePersonRecordDo> historyPersons = currentPersons.stream()
|
|
|
+ .map(person -> convertToHistoryPersonRecord(person, historyFileId, currentUser))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 批量保存历史记录
|
|
|
+ studyFilePersonRecordService.saveBatch(historyPersons);
|
|
|
+
|
|
|
+ // 如果是更新操作,删除原人员记录
|
|
|
+ if ("update".equals(processType)) {
|
|
|
+ List<String> personIdsToDelete = currentPersons.stream()
|
|
|
+ .map(StudyFilePersonDo::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ studyFilePersonService.removeByIds(personIdsToDelete);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将人员记录转换为历史人员记录
|
|
|
+ *
|
|
|
+ * @param source 源数据
|
|
|
+ * @param historyFileId 历史文件ID
|
|
|
+ * @param 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.setCreatedate(new Date());
|
|
|
+ target.setCreateuserid(currentUser.getId());
|
|
|
+ target.setCreateusername(currentUser.getName());
|
|
|
+ return target;
|
|
|
+ }
|
|
|
+}
|