|
@@ -0,0 +1,295 @@
|
|
|
|
+package com.rongwei.trainingcommon.sys.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
|
+import com.rongwei.training.domain.*;
|
|
|
|
+import com.rongwei.trainingcommon.sys.dao.*;
|
|
|
|
+import com.rongwei.trainingcommon.sys.service.TrainingDemandService;
|
|
|
|
+import com.rongwei.trainingcommon.sys.utils.TrainingUtils;
|
|
|
|
+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;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.DemandState.RELEASE;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * TrainingDemandService class
|
|
|
|
+ *
|
|
|
|
+ * @author XH
|
|
|
|
+ * @date 2023/11/24
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class TrainingDemandServiceImpl implements TrainingDemandService {
|
|
|
|
+ private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandQuestionDao trainingDemandQuestionDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandQuestionOptionDao trainingDemandQuestionOptionDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandSurveyCustomDetailDao trainingDemandSurveyCustomDetailDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandSurveyDao trainingDemandSurveyDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandTempDao trainingDemandTempDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandTempDetailDao trainingDemandTempDetailDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandTempQuestionOptionDao trainingDemandTempQuestionOptionDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandSurveyTempDetailDao trainingDemandSurveyTempDetailDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandQuestionBackupsServiceImpl trainingDemandQuestionBackupsServiceImpl;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandQuestionOptionBackupsServiceImpl trainingDemandQuestionOptionBackupsServiceImpl;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandSurveyBackupsServiceImpl trainingDemandSurveyBackupsServiceImpl;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandSurveyCustomDetailBackupsServiceImpl trainingDemandSurveyCustomDetailBackupsServiceImpl;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainingDemandTempBackupsServiceImpl trainingDemandTempBackupsServiceImpl;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserDemandSurveyServiceImpl userDemandSurveyServiceImpl;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TraningCommonDao traningCommonDao;
|
|
|
|
+
|
|
|
|
+ public static final String ERROR_MSG = "问卷调查发布失败";
|
|
|
|
+ /**
|
|
|
|
+ * 全员参与问卷调查
|
|
|
|
+ */
|
|
|
|
+ public static final String FULL_PARTICIPATION = "y";
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R releaseTrainDemand(Map<String, Object> parameter) {
|
|
|
|
+ String id = parameter.getOrDefault("id", "").toString();
|
|
|
|
+ TrainingDemandSurveyDo trainingDemandSurveyDo = trainingDemandSurveyDao.selectById(id);
|
|
|
|
+ if (trainingDemandSurveyDo == null) {
|
|
|
|
+ log.error("无法通过id:{},获取到培训需求调查信息", trainingDemandSurveyDo);
|
|
|
|
+ return R.error(ERROR_MSG);
|
|
|
|
+ }
|
|
|
|
+ if (RELEASE.equals(trainingDemandSurveyDo.getState())) {
|
|
|
|
+ log.error("调查问卷 :{}已发布无法再次发布", trainingDemandSurveyDo.getName());
|
|
|
|
+ return R.error("调查问卷已发布");
|
|
|
|
+ }
|
|
|
|
+ List<UserDemandSurveyDo> saveUserDemandSurveyDos = new ArrayList<>();
|
|
|
|
+ /******************************获取参与此次问卷的用户信息*********************************************/
|
|
|
|
+ Set<String> participantUserId = getParticipantUser(trainingDemandSurveyDo);
|
|
|
|
+ log.info("参与本次温泉调查的员工数为:{}", participantUserId.size());
|
|
|
|
+ if (participantUserId.size() == 0) {
|
|
|
|
+ log.error("本次问卷调查参与人数为0");
|
|
|
|
+ return R.error(ERROR_MSG);
|
|
|
|
+ }
|
|
|
|
+ /******************************开始复制业务数据*********************************************/
|
|
|
|
+ // 调查问卷自定义信息
|
|
|
|
+ List<TrainingDemandSurveyCustomDetailDo> surveyCustomDetailDos = trainingDemandSurveyCustomDetailDao.selectList(new LambdaQueryWrapper<TrainingDemandSurveyCustomDetailDo>()
|
|
|
|
+ .eq(TrainingDemandSurveyCustomDetailDo::getSurverid, id).orderByAsc(TrainingDemandSurveyCustomDetailDo::getNum));
|
|
|
|
+ // 调查问卷模板信息
|
|
|
|
+ List<TrainingDemandSurveyTempDetailDo> surveyTempDetailDos = trainingDemandSurveyTempDetailDao.selectList(new LambdaQueryWrapper<TrainingDemandSurveyTempDetailDo>()
|
|
|
|
+ .eq(TrainingDemandSurveyTempDetailDo::getSurverid, id).orderByAsc(TrainingDemandSurveyTempDetailDo::getNum));
|
|
|
|
+ // 模板信息
|
|
|
|
+ List<TrainingDemandTempDo> trainingDemandTempDos = trainingDemandTempDao.selectList(new LambdaQueryWrapper<TrainingDemandTempDo>()
|
|
|
|
+ .in(TrainingDemandTempDo::getId, surveyTempDetailDos.stream().map(TrainingDemandSurveyTempDetailDo::getTempid).collect(Collectors.toList())));
|
|
|
|
+ // 模板子表
|
|
|
|
+ List<TrainingDemandTempDetailDo> trainingDemandTempDetailDos = trainingDemandTempDetailDao.selectList(new LambdaQueryWrapper<TrainingDemandTempDetailDo>()
|
|
|
|
+ .in(TrainingDemandTempDetailDo::getDemandtempid, trainingDemandTempDos.stream().map(TrainingDemandTempDo::getId).collect(Collectors.toList())));
|
|
|
|
+ // 模板问题选项记录表
|
|
|
|
+ List<TrainingDemandTempQuestionOptionDo> trainingDemandTempQuestionOptionDos = trainingDemandTempQuestionOptionDao.selectList(new LambdaQueryWrapper<TrainingDemandTempQuestionOptionDo>()
|
|
|
|
+ .in(TrainingDemandTempQuestionOptionDo::getDemandtempdetailid, trainingDemandTempDetailDos.stream().map(TrainingDemandTempDetailDo::getId).collect(Collectors.toList())));
|
|
|
|
+
|
|
|
|
+ String userIds = participantUserId.stream().map(info -> info.split("-;-")[0]).collect(Collectors.joining(","));
|
|
|
|
+ String userNames = participantUserId.stream().map(info -> info.split("-;-")[1]).collect(Collectors.joining(","));
|
|
|
|
+ /************调查主表备份*************/
|
|
|
|
+ TrainingDemandSurveyBackupsDo saveDemandSurveyBackupsDo = generateSurveyBackups(trainingDemandSurveyDo, userIds, userNames);
|
|
|
|
+ /************自定义内容备份*************/
|
|
|
|
+ List<TrainingDemandSurveyCustomDetailBackupsDo> saveDemandSurveyCustomDetailBackupsDos = TrainingUtils.copyListProperties(surveyCustomDetailDos, TrainingDemandSurveyCustomDetailBackupsDo::new);
|
|
|
|
+ saveDemandSurveyCustomDetailBackupsDos.forEach(info -> info.setSurverid(saveDemandSurveyBackupsDo.getId()));
|
|
|
|
+ /************其他数据备份*************/
|
|
|
|
+ // 保存问题数据备份
|
|
|
|
+ List<TrainingDemandQuestionBackupsDo> saveDemandQuestionBackupsDos = new ArrayList<>();
|
|
|
|
+ // 保存问题选项数据备份
|
|
|
|
+ List<TrainingDemandQuestionOptionBackupsDo> saveDemandQuestionOptionBackupsDos = new ArrayList<>();
|
|
|
|
+ // 保存模板数据备份
|
|
|
|
+ List<TrainingDemandTempBackupsDo> saveDemandTempBackupsDo = new ArrayList<>();
|
|
|
|
+ int num = 1;
|
|
|
|
+ int questionNum= 1;
|
|
|
|
+ UserDemandSurveyDo addDemandSurveyDo;
|
|
|
|
+ for (int i = 0; i < surveyTempDetailDos.size(); i++) {
|
|
|
|
+ /************ 问卷调查模板内容备份*************/
|
|
|
|
+ TrainingDemandSurveyTempDetailDo surveyTempDetail = surveyTempDetailDos.get(i);
|
|
|
|
+ /******************模板备份************************/
|
|
|
|
+ TrainingDemandTempDo trainingDemandTempDo = trainingDemandTempDos.stream()
|
|
|
|
+ .filter(info -> info.getId().equals(surveyTempDetail.getTempid()))
|
|
|
|
+ .findFirst()
|
|
|
|
+ .orElse(null);
|
|
|
|
+ TrainingDemandTempBackupsDo trainingDemandTempBackupsDo = new TrainingDemandTempBackupsDo();
|
|
|
|
+ trainingDemandTempBackupsDo.setId(SecurityUtil.getUUID());
|
|
|
|
+ trainingDemandTempBackupsDo.setSurverid(saveDemandSurveyBackupsDo.getId());
|
|
|
|
+ trainingDemandTempBackupsDo.setName(surveyTempDetail.getTempname());
|
|
|
|
+ trainingDemandTempBackupsDo.setYear(trainingDemandTempDo.getYear());
|
|
|
|
+ trainingDemandTempBackupsDo.setNum(i);
|
|
|
|
+ saveDemandTempBackupsDo.add(trainingDemandTempBackupsDo);
|
|
|
|
+ /************ 循环问题明细*************/
|
|
|
|
+ List<TrainingDemandTempDetailDo> demandTempDetail = trainingDemandTempDetailDos.stream()
|
|
|
|
+ .filter(info -> trainingDemandTempDo.getId().equals(info.getDemandtempid()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ for (int j = 0; j < demandTempDetail.size(); j++) {
|
|
|
|
+ TrainingDemandTempDetailDo trainingDemandTempDetailDo = demandTempDetail.get(j);
|
|
|
|
+ /******************问题备份************************/
|
|
|
|
+ TrainingDemandQuestionBackupsDo questionBackupsDo = new TrainingDemandQuestionBackupsDo();
|
|
|
|
+ questionBackupsDo.setId(SecurityUtil.getUUID());
|
|
|
|
+ questionBackupsDo.setName(trainingDemandTempDetailDo.getContent());
|
|
|
|
+ questionBackupsDo.setQuestiontype(trainingDemandTempDetailDo.getQuestiontype());
|
|
|
|
+ questionBackupsDo.setSurveyid(surveyTempDetail.getId());
|
|
|
|
+ questionBackupsDo.setTempid(trainingDemandTempBackupsDo.getId());
|
|
|
|
+ questionBackupsDo.setNum(questionNum);
|
|
|
|
+ questionNum++;
|
|
|
|
+ saveDemandQuestionBackupsDos.add(questionBackupsDo);
|
|
|
|
+ /************ 问题答案备份 *************/
|
|
|
|
+ List<TrainingDemandTempQuestionOptionDo> questionOptions = trainingDemandTempQuestionOptionDos.stream()
|
|
|
|
+ .filter(info -> trainingDemandTempDetailDo.getQuestionid().equals(info.getQuestionid()) &&
|
|
|
|
+ trainingDemandTempDetailDo.getId().equals(info.getDemandtempdetailid())
|
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
+ List<TrainingDemandQuestionOptionBackupsDo> addOptions = TrainingUtils.copyListProperties(questionOptions, TrainingDemandQuestionOptionBackupsDo::new);
|
|
|
|
+ addOptions.forEach(info -> {
|
|
|
|
+ info.setQuestionid(questionBackupsDo.getId());
|
|
|
|
+ });
|
|
|
|
+ saveDemandQuestionOptionBackupsDos.addAll(addOptions);
|
|
|
|
+ // 生成用户问卷
|
|
|
|
+ saveUserDemandSurveyDos.add(generateUserDemandSurvey(num, questionBackupsDo, trainingDemandTempBackupsDo,
|
|
|
|
+ saveDemandSurveyBackupsDo, addOptions));
|
|
|
|
+ num++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (int k = 0; k < saveDemandSurveyCustomDetailBackupsDos.size(); k++) {
|
|
|
|
+ addDemandSurveyDo = new UserDemandSurveyDo();
|
|
|
|
+ addDemandSurveyDo.setId(SecurityUtil.getUUID());
|
|
|
|
+ addDemandSurveyDo.setNum(num);
|
|
|
|
+ addDemandSurveyDo.setSurverid(saveDemandSurveyBackupsDo.getId());
|
|
|
|
+ addDemandSurveyDo.setSurvername(saveDemandSurveyBackupsDo.getName());
|
|
|
|
+ addDemandSurveyDo.setQuestionid(saveDemandSurveyCustomDetailBackupsDos.get(k).getId());
|
|
|
|
+ addDemandSurveyDo.setQuestionname(saveDemandSurveyCustomDetailBackupsDos.get(k).getContent());
|
|
|
|
+ addDemandSurveyDo.setQuestiontype(saveDemandSurveyCustomDetailBackupsDos.get(k).getQuestiontype());
|
|
|
|
+ saveUserDemandSurveyDos.add(addDemandSurveyDo);
|
|
|
|
+ num++;
|
|
|
|
+ }
|
|
|
|
+ // 数据存表
|
|
|
|
+ saveData(saveDemandSurveyBackupsDo, saveDemandSurveyCustomDetailBackupsDos,
|
|
|
|
+ saveDemandQuestionBackupsDos, saveDemandQuestionOptionBackupsDos,
|
|
|
|
+ saveUserDemandSurveyDos, saveDemandTempBackupsDo, trainingDemandSurveyDo);
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 数据保存
|
|
|
|
+ *
|
|
|
|
+ * @param saveDemandSurveyBackupsDo 问卷调查
|
|
|
|
+ * @param saveDemandSurveyCustomDetailBackupsDos 培训内容自定义调查表
|
|
|
|
+ * @param saveDemandQuestionBackupsDos
|
|
|
|
+ * @param saveDemandQuestionOptionBackupsDos
|
|
|
|
+ * @param saveUserDemandSurveyDos
|
|
|
|
+ * @param saveDemandTempBackupsDo
|
|
|
|
+ */
|
|
|
|
+ @Transactional
|
|
|
|
+ public void saveData(TrainingDemandSurveyBackupsDo saveDemandSurveyBackupsDo,
|
|
|
|
+ List<TrainingDemandSurveyCustomDetailBackupsDo> saveDemandSurveyCustomDetailBackupsDos,
|
|
|
|
+ List<TrainingDemandQuestionBackupsDo> saveDemandQuestionBackupsDos,
|
|
|
|
+ List<TrainingDemandQuestionOptionBackupsDo> saveDemandQuestionOptionBackupsDos,
|
|
|
|
+ List<UserDemandSurveyDo> saveUserDemandSurveyDos,
|
|
|
|
+ List<TrainingDemandTempBackupsDo> saveDemandTempBackupsDo,
|
|
|
|
+ TrainingDemandSurveyDo trainingDemandSurveyDo) {
|
|
|
|
+ trainingDemandQuestionBackupsServiceImpl.saveOrUpdateBatch(saveDemandQuestionBackupsDos);
|
|
|
|
+ trainingDemandQuestionOptionBackupsServiceImpl.saveOrUpdateBatch(saveDemandQuestionOptionBackupsDos);
|
|
|
|
+ trainingDemandSurveyBackupsServiceImpl.saveOrUpdate(saveDemandSurveyBackupsDo);
|
|
|
|
+ trainingDemandSurveyCustomDetailBackupsServiceImpl.saveOrUpdateBatch(saveDemandSurveyCustomDetailBackupsDos);
|
|
|
|
+ trainingDemandTempBackupsServiceImpl.saveOrUpdateBatch(saveDemandTempBackupsDo);
|
|
|
|
+ userDemandSurveyServiceImpl.saveOrUpdateBatch(saveUserDemandSurveyDos);
|
|
|
|
+ trainingDemandSurveyDo.setState(RELEASE);
|
|
|
|
+ trainingDemandSurveyDo.setReleasetime(new Date());
|
|
|
|
+ trainingDemandSurveyDao.updateById(trainingDemandSurveyDo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成用户调查问卷
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private UserDemandSurveyDo generateUserDemandSurvey(int num,
|
|
|
|
+ TrainingDemandQuestionBackupsDo questionBackupsDo,
|
|
|
|
+ TrainingDemandTempBackupsDo trainingDemandTempBackupsDo,
|
|
|
|
+ TrainingDemandSurveyBackupsDo trainingDemandSurveyBackupsDo,
|
|
|
|
+ List<TrainingDemandQuestionOptionBackupsDo> addOptions) {
|
|
|
|
+ UserDemandSurveyDo demandSurveyDo = new UserDemandSurveyDo();
|
|
|
|
+ demandSurveyDo.setId(SecurityUtil.getUUID());
|
|
|
|
+ demandSurveyDo.setNum(num);
|
|
|
|
+ demandSurveyDo.setSurverid(trainingDemandSurveyBackupsDo.getId());
|
|
|
|
+ demandSurveyDo.setSurvername(trainingDemandSurveyBackupsDo.getName());
|
|
|
|
+ demandSurveyDo.setTempid(trainingDemandTempBackupsDo.getId());
|
|
|
|
+ demandSurveyDo.setTempname(trainingDemandTempBackupsDo.getName());
|
|
|
|
+ demandSurveyDo.setQuestionid(questionBackupsDo.getId());
|
|
|
|
+ demandSurveyDo.setQuestionname(questionBackupsDo.getName());
|
|
|
|
+ demandSurveyDo.setQuestiontype(questionBackupsDo.getQuestiontype());
|
|
|
|
+ demandSurveyDo.setOptions(addOptions.stream().map(TrainingDemandQuestionOptionBackupsDo::getContent).collect(Collectors.joining(",")));
|
|
|
|
+ return demandSurveyDo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 调查主表备份
|
|
|
|
+ *
|
|
|
|
+ * @param trainingDemandSurveyDo
|
|
|
|
+ * @param userIds
|
|
|
|
+ * @param userNames
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private TrainingDemandSurveyBackupsDo generateSurveyBackups(TrainingDemandSurveyDo trainingDemandSurveyDo, String userIds, String userNames) {
|
|
|
|
+ TrainingDemandSurveyBackupsDo trainingDemandSurveyBackupsDo = new TrainingDemandSurveyBackupsDo();
|
|
|
|
+ BeanUtils.copyProperties(trainingDemandSurveyDo, trainingDemandSurveyBackupsDo);
|
|
|
|
+ trainingDemandSurveyBackupsDo.setId(SecurityUtil.getUUID());
|
|
|
|
+ trainingDemandSurveyBackupsDo.setParticipateuserid(userIds);
|
|
|
|
+ trainingDemandSurveyBackupsDo.setParticipateusername(userNames);
|
|
|
|
+ trainingDemandSurveyBackupsDo.setNoparticipatinguserid(userIds);
|
|
|
|
+ trainingDemandSurveyBackupsDo.setNoparticipatingusername(userNames);
|
|
|
|
+ return trainingDemandSurveyBackupsDo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取参与培训的员工
|
|
|
|
+ *
|
|
|
|
+ * @param trainingDemandSurveyDo
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Set<String> getParticipantUser(TrainingDemandSurveyDo trainingDemandSurveyDo) {
|
|
|
|
+
|
|
|
|
+ if (FULL_PARTICIPATION.equals(trainingDemandSurveyDo.getFullparticipation())) {
|
|
|
|
+ log.debug("全员参与培训");
|
|
|
|
+ String factoryId = trainingDemandSurveyDo.getTenantid();
|
|
|
|
+ return traningCommonDao.getAllUserIdAndNameByOrgId(Arrays.asList(factoryId));
|
|
|
|
+ }
|
|
|
|
+ // 参与培训的员工信息
|
|
|
|
+ Set<String> participantUserIdList = new HashSet<>();
|
|
|
|
+ // 参与培训的部门
|
|
|
|
+ String participatedeptid = trainingDemandSurveyDo.getParticipatedeptid();
|
|
|
|
+ if (StringUtils.isNotBlank(participatedeptid)) {
|
|
|
|
+ participantUserIdList = traningCommonDao.getAllUserIdAndNameByOrgId(Arrays.asList(participatedeptid.split(",")));
|
|
|
|
+ }
|
|
|
|
+ // 参与培训的员工
|
|
|
|
+ String participateuserid = trainingDemandSurveyDo.getParticipateuserid();
|
|
|
|
+ if (StringUtils.isNotBlank(participatedeptid)) {
|
|
|
|
+ participantUserIdList.addAll(Arrays.asList(participateuserid.split(",")));
|
|
|
|
+ }
|
|
|
|
+ // 排除的员工
|
|
|
|
+ String excludeuserid = trainingDemandSurveyDo.getExcludeuserid();
|
|
|
|
+ if (StringUtils.isNotBlank(excludeuserid)) {
|
|
|
|
+ participantUserIdList.removeAll(Arrays.asList(excludeuserid.split(",")));
|
|
|
|
+ }
|
|
|
|
+ return participantUserIdList;
|
|
|
|
+ }
|
|
|
|
+}
|