|
@@ -1,13 +1,18 @@
|
|
|
package com.rongwei.trainingcommon.sys.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
+import com.rongwei.rwcommon.base.BaseDo;
|
|
|
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.training.vo.PreviewTrainDemandVo;
|
|
|
+import com.rongwei.training.vo.TrainingDemandVo;
|
|
|
import com.rongwei.trainingcommon.sys.dao.*;
|
|
|
import com.rongwei.trainingcommon.sys.service.TrainingDemandService;
|
|
|
import com.rongwei.trainingcommon.sys.utils.TrainingListCopyUtils;
|
|
|
+import com.rongwei.trainingcommon.sys.utils.TrainingUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -58,9 +63,14 @@ public class TrainingDemandServiceImpl implements TrainingDemandService {
|
|
|
private TrainingDemandTempBackupsServiceImpl trainingDemandTempBackupsServiceImpl;
|
|
|
@Autowired
|
|
|
private DemandSurveyContentContentServiceImpl demandSurveyContentServiceImpl;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private TrainingDemandSurveyBackupsDao trainingDemandSurveyBackupsDao;
|
|
|
@Autowired
|
|
|
private TraningCommonDao traningCommonDao;
|
|
|
+ @Autowired
|
|
|
+ private DemandSurveyContentDao demandSurveyContentDao;
|
|
|
+ @Autowired
|
|
|
+ private DemandSurveyUserAnswerServiceImpl demandSurveyUserAnswerService;
|
|
|
|
|
|
public static final String ERROR_MSG = "问卷调查发布失败";
|
|
|
/**
|
|
@@ -188,6 +198,173 @@ public class TrainingDemandServiceImpl implements TrainingDemandService {
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 预览培训需求调查
|
|
|
+ *
|
|
|
+ * @param previewTrainDemandVo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R previewTrainDemand(PreviewTrainDemandVo previewTrainDemandVo) {
|
|
|
+ List<String> tempIdList = previewTrainDemandVo.getTempIdList();
|
|
|
+ if (tempIdList == null || previewTrainDemandVo.getTempIdList().isEmpty()) {
|
|
|
+ return R.error("培训模板信息为空");
|
|
|
+ }
|
|
|
+ // 问题模板信息
|
|
|
+ List<TrainingDemandTempDo> trainingDemandTempDos = trainingDemandTempDao.selectList(new LambdaQueryWrapper<TrainingDemandTempDo>()
|
|
|
+ .in(TrainingDemandTempDo::getId, tempIdList).eq(BaseDo::getDeleted, "0"));
|
|
|
+ // 问题模板问题
|
|
|
+ List<TrainingDemandTempDetailDo> trainingDemandTempDetailDos = trainingDemandTempDetailDao.selectList(new LambdaQueryWrapper<TrainingDemandTempDetailDo>()
|
|
|
+ .in(TrainingDemandTempDetailDo::getDemandtempid, tempIdList).eq(BaseDo::getDeleted, "0"));
|
|
|
+ List<String> questionIdList = trainingDemandTempDetailDos.stream().map(TrainingDemandTempDetailDo::getQuestionid).collect(Collectors.toList());
|
|
|
+ // 问题答案
|
|
|
+ List<TrainingDemandQuestionOptionDo> trainingDemandQuestionDos = trainingDemandQuestionOptionDao.selectList(new LambdaQueryWrapper<TrainingDemandQuestionOptionDo>()
|
|
|
+ .in(TrainingDemandQuestionOptionDo::getQuestionid, questionIdList).eq(BaseDo::getDeleted, "0"));
|
|
|
+
|
|
|
+ List<TrainingDemandVo> trainingDemandVoList = new ArrayList<>();
|
|
|
+ int num = 1;
|
|
|
+ // 问题模板
|
|
|
+ for (int i = 0; i < trainingDemandTempDos.size(); i++) {
|
|
|
+ TrainingDemandTempDo trainingDemandTempDo = trainingDemandTempDos.get(i);
|
|
|
+ // 当前模板拥有的问题
|
|
|
+ List<TrainingDemandTempDetailDo> currentTempQuestion = trainingDemandTempDetailDos.stream()
|
|
|
+ .filter(info -> info.getDemandtempid().equals(trainingDemandTempDo.getId())).collect(Collectors.toList());
|
|
|
+ for (int j = 0; j < currentTempQuestion.size(); j++) {
|
|
|
+ TrainingDemandTempDetailDo currentQuestion = currentTempQuestion.get(j);
|
|
|
+ // 问题答案
|
|
|
+ List<String> collect = trainingDemandQuestionDos.stream().filter(info -> currentQuestion.getQuestionid().equals(info.getQuestionid()))
|
|
|
+ .map(TrainingDemandQuestionOptionDo::getContent)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ TrainingDemandVo trainingDemandVo = new TrainingDemandVo();
|
|
|
+ trainingDemandVo.setModelName(trainingDemandTempDo.getName());
|
|
|
+ trainingDemandVo.setNum(num);
|
|
|
+ trainingDemandVo.setQuestionContent(currentQuestion.getContent());
|
|
|
+ trainingDemandVo.setQuestionType(currentQuestion.getQuestiontype());
|
|
|
+ trainingDemandVo.setQuestionOptions(collect);
|
|
|
+ num++;
|
|
|
+ trainingDemandVoList.add(trainingDemandVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LinkedHashMap<String, List<TrainingDemandVo>> collect = trainingDemandVoList.stream().collect(Collectors.groupingBy(TrainingDemandVo::getModelName, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ List<TrainingDemandVo> customerDataList = previewTrainDemandVo.getCustomerDataList();
|
|
|
+ if (customerDataList != null || !customerDataList.isEmpty()) {
|
|
|
+ collect.put("customQuestion", customerDataList);
|
|
|
+ }
|
|
|
+ return R.ok(collect);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前登录用的调查问卷信息
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R getInfoByUser(String userId) {
|
|
|
+ if (StringUtils.isBlank(userId)) {
|
|
|
+ SysUserVo currentUser = TrainingUtils.getCurrentUser();
|
|
|
+ userId = currentUser.getId();
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(userId)) {
|
|
|
+ log.debug("用户ID 为空");
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ List<TrainingDemandSurveyBackupsDo> list = trainingDemandSurveyBackupsDao.getValidListData(userId);
|
|
|
+ return R.ok(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 问卷
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R showQuestionnaire(String id) {
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
+ log.debug("参数异常");
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ TrainingDemandSurveyBackupsDo trainingDemandSurveyBackupsDo = trainingDemandSurveyBackupsServiceImpl.getById(id);
|
|
|
+ String oldSurveyId = trainingDemandSurveyBackupsDo.getOldSurveyId();
|
|
|
+ TrainingDemandSurveyDo trainingDemandSurveyDo = trainingDemandSurveyDao.selectById(oldSurveyId);
|
|
|
+ if (StringUtils.isBlank(trainingDemandSurveyDo.getState()) || !"1".equals(trainingDemandSurveyDo.getState())) {
|
|
|
+ log.debug("问卷调查发布状态异常");
|
|
|
+ return R.error("问卷调查已关闭");
|
|
|
+ }
|
|
|
+ if (trainingDemandSurveyDo.getDeadline() != null && new Date().compareTo(trainingDemandSurveyDo.getDeadline()) > 0) {
|
|
|
+ log.debug("问卷调查发布状态异常");
|
|
|
+ return R.error("问卷调查已结束");
|
|
|
+ }
|
|
|
+ List<TrainingDemandVo> surveyContent = demandSurveyContentDao.getSurveyContent(id);
|
|
|
+
|
|
|
+ LinkedHashMap<String, List<TrainingDemandVo>> collect = surveyContent.stream()
|
|
|
+ .collect(Collectors.groupingBy(TrainingDemandVo::getModelName, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ return R.ok(collect);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R submit(List<TrainingDemandVo> trainingDemandVoList) {
|
|
|
+ // 当前登录用户
|
|
|
+ SysUserVo currentUser = TrainingUtils.getCurrentUser();
|
|
|
+ if (currentUser == null) {
|
|
|
+ log.error("无法获取到当前登录人信息");
|
|
|
+ return R.error("请重新登录");
|
|
|
+ }
|
|
|
+ if (trainingDemandVoList == null || trainingDemandVoList.isEmpty()) {
|
|
|
+ log.error("问卷答案为空");
|
|
|
+ return R.error("请填写问卷调查信息");
|
|
|
+ }
|
|
|
+ boolean hasEmptySurverId = trainingDemandVoList.stream().anyMatch(info -> StringUtils.isBlank(info.getSurverid()));
|
|
|
+ if (hasEmptySurverId) {
|
|
|
+ log.error("存在问卷ID为空的数据");
|
|
|
+ return R.error("数据异常");
|
|
|
+ }
|
|
|
+ boolean hasEmptycontentId = trainingDemandVoList.stream().anyMatch(info -> StringUtils.isBlank(info.getContentid()));
|
|
|
+ if (hasEmptycontentId) {
|
|
|
+ log.error("存在问卷内容ID为空的数据");
|
|
|
+ return R.error("数据异常");
|
|
|
+ }
|
|
|
+ // 获取培训计划ID
|
|
|
+ String surverid = trainingDemandVoList.get(0).getSurverid();
|
|
|
+ Date currentDate = new Date();
|
|
|
+ TrainingDemandSurveyBackupsDo trainingDemandSurveyBackupsDo = trainingDemandSurveyBackupsDao.selectById(surverid);
|
|
|
+ // 判断是否以参与过该问卷
|
|
|
+ String participatingUserList = trainingDemandSurveyBackupsDo.getParticipatinguserid();
|
|
|
+ if(StringUtils.isNotBlank(participatingUserList) && participatingUserList.contains(currentUser.getId())){
|
|
|
+ log.error("当前用户以参与过问卷");
|
|
|
+ return R.error("您已提交过问卷!无法再次提交");
|
|
|
+ }
|
|
|
+ List<DemandSurveyUserAnswerDo> saveData = trainingDemandVoList.stream().map(info -> {
|
|
|
+ DemandSurveyUserAnswerDo demandSurveyUserAnswerDo = new DemandSurveyUserAnswerDo();
|
|
|
+ demandSurveyUserAnswerDo.setId(SecurityUtil.getUUID());
|
|
|
+ demandSurveyUserAnswerDo.setNum(info.getNum());
|
|
|
+ demandSurveyUserAnswerDo.setAnswer(info.getUserAnswer());
|
|
|
+ demandSurveyUserAnswerDo.setSurverid(info.getSurverid());
|
|
|
+ demandSurveyUserAnswerDo.setSurvercontentid(info.getContentid());
|
|
|
+ demandSurveyUserAnswerDo.setQuestiontype(info.getQuestionType());
|
|
|
+ if (info.getQuestionOptions() != null && !info.getQuestionOptions().isEmpty()) {
|
|
|
+ demandSurveyUserAnswerDo.setOptions(String.join("-;-", info.getQuestionOptions()));
|
|
|
+ }
|
|
|
+ demandSurveyUserAnswerDo.setCreateuserid(currentUser.getCreateuserid());
|
|
|
+ demandSurveyUserAnswerDo.setCreateusername(currentUser.getCreateusername());
|
|
|
+ demandSurveyUserAnswerDo.setCreatedate(currentDate);
|
|
|
+ demandSurveyUserAnswerDo.setModifyuserid(currentUser.getCreateuserid());
|
|
|
+ demandSurveyUserAnswerDo.setModifyusername(currentUser.getCreateusername());
|
|
|
+ demandSurveyUserAnswerDo.setModifydate(currentDate);
|
|
|
+ demandSurveyUserAnswerDo.setDeleted("0");
|
|
|
+ demandSurveyUserAnswerDo.setTenantid(trainingDemandSurveyBackupsDo.getTenantid());
|
|
|
+ return demandSurveyUserAnswerDo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 保存用户问卷结果
|
|
|
+ demandSurveyUserAnswerService.saveBatch(saveData);
|
|
|
+ // 更新问卷调查已参与用户和未参与用户
|
|
|
+ trainingDemandSurveyBackupsDao.updateParticipant(currentUser.getCreateuserid(), currentUser.getCreateusername(), surverid);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 数据保存
|
|
|
*
|
|
@@ -237,7 +414,7 @@ public class TrainingDemandServiceImpl implements TrainingDemandService {
|
|
|
demandSurveyDo.setQuestionid(questionBackupsDo.getId());
|
|
|
demandSurveyDo.setQuestionname(questionBackupsDo.getName());
|
|
|
demandSurveyDo.setQuestiontype(questionBackupsDo.getQuestiontype());
|
|
|
- demandSurveyDo.setOptions(addOptions.stream().map(TrainingDemandQuestionOptionBackupsDo::getContent).collect(Collectors.joining(",")));
|
|
|
+ demandSurveyDo.setOptions(addOptions.stream().map(TrainingDemandQuestionOptionBackupsDo::getContent).collect(Collectors.joining("-;-")));
|
|
|
return demandSurveyDo;
|
|
|
}
|
|
|
|
|
@@ -253,6 +430,7 @@ public class TrainingDemandServiceImpl implements TrainingDemandService {
|
|
|
TrainingDemandSurveyBackupsDo trainingDemandSurveyBackupsDo = new TrainingDemandSurveyBackupsDo();
|
|
|
BeanUtils.copyProperties(trainingDemandSurveyDo, trainingDemandSurveyBackupsDo);
|
|
|
trainingDemandSurveyBackupsDo.setId(SecurityUtil.getUUID());
|
|
|
+ trainingDemandSurveyBackupsDo.setOldSurveyId(trainingDemandSurveyDo.getId());
|
|
|
trainingDemandSurveyBackupsDo.setParticipateuserid(userIds);
|
|
|
trainingDemandSurveyBackupsDo.setParticipateusername(userNames);
|
|
|
trainingDemandSurveyBackupsDo.setNoparticipatinguserid(userIds);
|