| | |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.RSAPublicKeyExample; |
| | |
| | | |
| | | @Autowired |
| | | private ISvyLibTemplateScriptService svyLibTemplateScriptService; |
| | | |
| | | @Autowired |
| | | private ISvyTaskTemplateTargetoptionService svyTaskTemplateTargetoptionService; |
| | | |
| | | @Autowired |
| | | private IIvrTaskTemplateService ivrTaskTemplateService; |
| | |
| | | List<SvyTaskTemplateScriptVO> cacheList = redisCache.getCacheList(key); |
| | | cacheList.sort(Comparator.comparingLong(SvyTaskTemplateScriptVO::getSort)); |
| | | log.info("问卷回答结果:{}", CollectionUtils.isEmpty(cacheList) ? null : cacheList.size()); |
| | | |
| | | //校验一下题的序号是否有问题 (如果根据选项无序跳转,就会导致错误) |
| | | cacheList = checkQuestionSort(cacheList); |
| | | |
| | | for (int i = 0; i < cacheList.size(); i++) { |
| | | if (i == 0) { |
| | | //这个时间要找到第一题 |
| | |
| | | String isabnormalFlag = "0"; |
| | | if (serviceSubTaskCacheReq.getType() == 2) { |
| | | List<SvyTaskTemplateScriptVO> cacheList = serviceSubTaskCacheReq.getSvyTaskTemplateScriptVOS(); |
| | | //检查并修正问卷题目排序 |
| | | cacheList = checkQuestionSort(cacheList); |
| | | cacheList.sort(Comparator.comparingLong(SvyTaskTemplateScriptVO::getSort)); |
| | | log.info("问卷回答结果:{}", CollectionUtils.isEmpty(cacheList) ? null : cacheList.size()); |
| | | // 预查询循环中不变的数据,避免每题重复查数据库 |
| | |
| | | ServiceTask preServiceTask = serviceTaskService.selectServiceTaskByTaskid(tid); |
| | | Map<Long, Long> preDetailIdMap = getExistingDetailIdMap(subid); |
| | | Map<Long, Long> preTraceIdMap = getExistingTraceIdMap(subid); |
| | | |
| | | // 提前定位第一题的索引,避免后续嵌套循环 |
| | | Integer firstSortIndex = -1; |
| | | if (CollectionUtils.isNotEmpty(cacheList)) { |
| | | for (int j = 0; j < cacheList.size(); j++) { |
| | | if (cacheList.get(j).getSort() != null && cacheList.get(j).getSort() == 1L) { |
| | | firstSortIndex = j; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | for (int i = 0; i < cacheList.size(); i++) { |
| | | if (i == 0) { |
| | | //这个时间要找到第一题 |
| | | for (SvyTaskTemplateScriptVO svyTaskTemplateScriptVO : cacheList) { |
| | | if (svyTaskTemplateScriptVO.getSort() == 1L) { |
| | | //说明是第一题 |
| | | List<SvyTaskTemplateTargetoption> svyTaskTemplateTargetoptions = svyTaskTemplateScriptVO.getSvyTaskTemplateTargetoptions(); |
| | | svyTaskTemplateScriptVO.setSvyTaskTemplateTargetoptions(svyTaskTemplateTargetoptions); |
| | | Map<String, String> map = setWJInfo(svyTaskTemplateScriptVO, tid, pid, subid, preServiceSubtaskList, preServiceTask, preDetailIdMap, preTraceIdMap); |
| | | if (map == null) continue; |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | isabnormalFlag = map.get("isabnormal"); |
| | | } |
| | | } |
| | | SvyTaskTemplateScriptVO svyTaskTemplateScriptVO = cacheList.get(i); |
| | | log.info("svyTaskTemplateScriptVO 的信息为:{},i 的值为:{}", svyTaskTemplateScriptVO.getScriptno(), i); |
| | | List<SvyTaskTemplateTargetoption> svyTaskTemplateTargetoptions = svyTaskTemplateScriptVO.getSvyTaskTemplateTargetoptions(); |
| | | svyTaskTemplateScriptVO.setSvyTaskTemplateTargetoptions(svyTaskTemplateTargetoptions); |
| | | |
| | | } else { |
| | | SvyTaskTemplateScriptVO svyTaskTemplateScriptVO = cacheList.get(i); |
| | | log.info("svyTaskTemplateScriptVO的信息为:{},i的值为:{}", svyTaskTemplateScriptVO.getScriptno(), i); |
| | | List<SvyTaskTemplateTargetoption> svyTaskTemplateTargetoptions = cacheList.get(i).getSvyTaskTemplateTargetoptions(); |
| | | svyTaskTemplateScriptVO.setSvyTaskTemplateTargetoptions(svyTaskTemplateTargetoptions); |
| | | // 如果是第一题或者匹配 nextScriptno 的题目 |
| | | boolean shouldProcess = false; |
| | | if (i == firstSortIndex) { |
| | | shouldProcess = true; |
| | | } else if (nextScriptno != null && svyTaskTemplateScriptVO.getSort() != null && svyTaskTemplateScriptVO.getSort().equals(nextScriptno)) { |
| | | shouldProcess = true; |
| | | } |
| | | |
| | | if (svyTaskTemplateScriptVO.getSort() != null && svyTaskTemplateScriptVO.getSort().equals(nextScriptno)) { |
| | | Map<String, String> map = setWJInfo(svyTaskTemplateScriptVO, tid, pid, subid, preServiceSubtaskList, preServiceTask, preDetailIdMap, preTraceIdMap); |
| | | log.error("nextScriptNo的信息为:{}", map.get("nextScriptNo")); |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | isabnormalFlag = map.get("isabnormal"); |
| | | if (shouldProcess) { |
| | | Map<String, String> map = setWJInfo(svyTaskTemplateScriptVO, tid, pid, subid, preServiceSubtaskList, preServiceTask, preDetailIdMap, preTraceIdMap); |
| | | log.error("nextScriptNo 的信息为:{}", map.get("nextScriptNo")); |
| | | if (map == null) continue; |
| | | |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | isabnormalFlag = map.get("isabnormal"); |
| | | } |
| | | } |
| | | } else if (serviceSubTaskCacheReq.getType() == 1) { |
| | | List<IvrTaskTemplateScriptVO> cacheList = serviceSubTaskCacheReq.getIvrTaskTemplateScriptVOList(); |
| | | cacheList.sort(Comparator.comparingLong(vo -> Optional.ofNullable(vo.getSort()).orElse(0))); |
| | | log.error("电话随访问卷回答结果:{}", CollectionUtils.isEmpty(cacheList) ? null : cacheList.size()); |
| | | |
| | | // 提前定位第一题的索引 |
| | | Integer firstIvrSortIndex = -1; |
| | | if (CollectionUtils.isNotEmpty(cacheList)) { |
| | | for (int j = 0; j < cacheList.size(); j++) { |
| | | if (cacheList.get(j).getSort() != null && cacheList.get(j).getSort() == 1L) { |
| | | firstIvrSortIndex = j; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | for (int i = 0; i < cacheList.size(); i++) { |
| | | if (i == 0) { |
| | | //这个时间要找到第一题 |
| | | for (IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO : cacheList) { |
| | | if (ivrTaskTemplateScriptVO.getSort() != null && ivrTaskTemplateScriptVO.getSort() == 1L) { |
| | | //说明是第一题 |
| | | List<IvrTaskTemplateTargetoption> ivrTaskTemplateTargetoptions = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList(); |
| | | ivrTaskTemplateScriptVO.setIvrTaskScriptTargetoptionList(ivrTaskTemplateTargetoptions); |
| | | //它俩都是ivr_task_templatescript_id,所以这里需要设置一下 |
| | | ivrTaskTemplateScriptVO.setId(ivrTaskTemplateScriptVO.getScriptID()); |
| | | Map<String, String> map = setSFInfo(ivrTaskTemplateScriptVO, tid, pid, subid); |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | isabnormalFlag = map.get("isabnormal"); |
| | | } |
| | | } |
| | | IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO = DtoConversionUtils.sourceToTarget(cacheList.get(i), IvrTaskTemplateScriptVO.class); |
| | | List<IvrTaskTemplateTargetoption> ivrTaskTemplateTargetoptions = DtoConversionUtils.sourceToTarget(cacheList.get(i).getIvrTaskScriptTargetoptionList(), IvrTaskTemplateTargetoption.class); |
| | | ivrTaskTemplateScriptVO.setIvrTaskScriptTargetoptionList(ivrTaskTemplateTargetoptions); |
| | | //它俩都是 ivr_task_templatescript_id,所以这里需要设置一下 |
| | | ivrTaskTemplateScriptVO.setId(ivrTaskTemplateScriptVO.getScriptID()); |
| | | |
| | | } else { |
| | | IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO = DtoConversionUtils.sourceToTarget(cacheList.get(i), IvrTaskTemplateScriptVO.class); |
| | | List<IvrTaskTemplateTargetoption> ivrTaskTemplateTargetoptions = DtoConversionUtils.sourceToTarget(cacheList.get(i).getIvrTaskScriptTargetoptionList(), IvrTaskTemplateTargetoption.class); |
| | | ivrTaskTemplateScriptVO.setIvrTaskScriptTargetoptionList(ivrTaskTemplateTargetoptions); |
| | | boolean shouldProcess = false; |
| | | if (i == firstIvrSortIndex) { |
| | | shouldProcess = true; |
| | | } else if (nextScriptno != null && ivrTaskTemplateScriptVO.getSort() != null && Long.valueOf(ivrTaskTemplateScriptVO.getSort()).equals(nextScriptno)) { |
| | | shouldProcess = true; |
| | | } |
| | | |
| | | if (ivrTaskTemplateScriptVO.getSort() != null && Long.valueOf(ivrTaskTemplateScriptVO.getSort()).equals(nextScriptno)) { |
| | | Map<String, String> map = setSFInfo(ivrTaskTemplateScriptVO, tid, pid, subid); |
| | | log.error("----nextScriptNo2的信息为:{}", map.get("nextScriptNo")); |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | isabnormalFlag = map.get("isabnormal"); |
| | | if (shouldProcess) { |
| | | Map<String, String> map = setSFInfo(ivrTaskTemplateScriptVO, tid, pid, subid); |
| | | log.error("----nextScriptNo2 的信息为:{}", map.get("nextScriptNo")); |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | isabnormalFlag = map.get("isabnormal"); |
| | | } |
| | | } |
| | | } |
| | |
| | | Double score = null; |
| | | List<SvyTaskTemplateScriptVO> svyTaskTemplateScriptVOS = serviceSubTaskMYDAnswerReq.getSvyTaskTemplateScriptVOS(); |
| | | Long nextScriptno = null; |
| | | |
| | | // 提前定位第一题的索引 |
| | | Integer firstMydSortIndex = -1; |
| | | if (CollectionUtils.isNotEmpty(svyTaskTemplateScriptVOS)) { |
| | | for (int j = 0; j < svyTaskTemplateScriptVOS.size(); j++) { |
| | | if (svyTaskTemplateScriptVOS.get(j).getSort() != null && svyTaskTemplateScriptVOS.get(j).getSort() == 1L) { |
| | | firstMydSortIndex = j; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | for (int i = 0; i < svyTaskTemplateScriptVOS.size(); i++) { |
| | | if (i == 0) { |
| | | //这个时间要找到第一题 |
| | | for (SvyTaskTemplateScriptVO svyTaskTemplateScriptVO : svyTaskTemplateScriptVOS) { |
| | | if (svyTaskTemplateScriptVO.getSort() == 1L) { |
| | | //说明是第一题 |
| | | // SvyTaskTemplateScriptVO svyTaskTemplateScriptVO = DtoConversionUtils.sourceToTarget(svyLibTemplateScriptVOS.get(0), SvyTaskTemplateScriptVO.class); |
| | | List<SvyTaskTemplateTargetoption> svyTaskTemplateTargetoptions = svyTaskTemplateScriptVOS.get(0).getSvyTaskTemplateTargetoptions(); |
| | | // List<SvyTaskTemplateTargetoption> svyTaskTemplateTargetoptions = DtoConversionUtils.sourceToTarget(svyTaskTemplateTargetoptions, SvyTaskTemplateTargetoption.class); |
| | | svyTaskTemplateScriptVO.setSvyTaskTemplateTargetoptions(svyTaskTemplateTargetoptions); |
| | | Map<String, String> map = setWJInfo(svyTaskTemplateScriptVO, Long.valueOf(serviceSubTaskMYDAnswerReq.getTaskId()), patid, serviceSubTaskMYDAnswerReq.getSubId()); |
| | | if (map == null) continue; |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | if (!Objects.isNull(map.get("id"))) { |
| | | idList.add(Long.valueOf(map.get("id"))); |
| | | } |
| | | } |
| | | SvyTaskTemplateScriptVO svyTaskTemplateScriptVO = svyTaskTemplateScriptVOS.get(i); |
| | | List<SvyTaskTemplateTargetoption> svyTaskTemplateTargetoptions = svyTaskTemplateScriptVOS.get(i).getSvyTaskTemplateTargetoptions(); |
| | | svyTaskTemplateScriptVO.setSvyTaskTemplateTargetoptions(svyTaskTemplateTargetoptions); |
| | | |
| | | boolean shouldProcess = false; |
| | | if (i == firstMydSortIndex) { |
| | | shouldProcess = true; |
| | | } else if (nextScriptno != null && svyTaskTemplateScriptVO.getSort() != null && svyTaskTemplateScriptVO.getSort().equals(nextScriptno)) { |
| | | shouldProcess = true; |
| | | } |
| | | |
| | | if (shouldProcess) { |
| | | Map<String, String> map = setWJInfo(svyTaskTemplateScriptVO, Long.valueOf(serviceSubTaskMYDAnswerReq.getTaskId()), patid, serviceSubTaskMYDAnswerReq.getSubId()); |
| | | if (map == null) continue; |
| | | |
| | | log.error("nextScriptNo 的信息为:{}", map.get("nextScriptNo")); |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | |
| | | } else { |
| | | SvyTaskTemplateScriptVO svyTaskTemplateScriptVO = svyTaskTemplateScriptVOS.get(i); |
| | | // SvyTaskTemplateScriptVO svyTaskTemplateScriptVO = DtoConversionUtils.sourceToTarget(svyLibTemplateScriptVOS.get(i), SvyTaskTemplateScriptVO.class); |
| | | List<SvyTaskTemplateTargetoption> svyTaskTemplateTargetoptions = svyTaskTemplateScriptVOS.get(i).getSvyTaskTemplateTargetoptions(); |
| | | // List<SvyTaskTemplateTargetoption> svyTaskTemplateTargetoptions = DtoConversionUtils.sourceToTarget(svyLibTemplateScriptVOS.get(i).getSvyLibTemplateTargetoptions(), SvyTaskTemplateTargetoption.class); |
| | | svyTaskTemplateScriptVO.setSvyTaskTemplateTargetoptions(svyTaskTemplateTargetoptions); |
| | | |
| | | if (svyTaskTemplateScriptVO.getSort() != null && svyTaskTemplateScriptVO.getSort().equals(nextScriptno)) { |
| | | log.error("svyTaskTemplateScriptVO的值为:{}", svyTaskTemplateScriptVO); |
| | | Map<String, String> map = setWJInfo(svyTaskTemplateScriptVO, Long.valueOf(serviceSubTaskMYDAnswerReq.getTaskId()), patid, serviceSubTaskMYDAnswerReq.getSubId()); |
| | | log.error("map的信息为:{}", map); |
| | | if (!Objects.isNull(map.get("nextScriptNo"))) |
| | | nextScriptno = Long.valueOf(map.get("nextScriptNo")); |
| | | if (score == null) { |
| | | score = Double.valueOf(map.get("score")); |
| | | } else { |
| | | score = score + Double.valueOf(map.get("score")); |
| | | } |
| | | if (!Objects.isNull(map.get("id"))) { |
| | | idList.add(Long.valueOf(map.get("id"))); |
| | | } |
| | | if (!Objects.isNull(map.get("id"))) { |
| | | idList.add(Long.valueOf(map.get("id"))); |
| | | } |
| | | } |
| | | } |
| | |
| | | public Map<String, Object> selectPatQuestionResult(ServiceSubTaskQueryReq serviceSubTaskQueryReq) { |
| | | log.info("selectPatQuesTionResult的入参为:{}", serviceSubTaskQueryReq); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if (serviceSubTaskQueryReq.getSubId() != null) { |
| | | ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(serviceSubTaskQueryReq.getSubId()); |
| | | if (serviceSubtask.getSendstate() == 4L) { |
| | | log.info("患者子任务ID为:{},状态为:{}", serviceSubTaskQueryReq.getSubId(), serviceSubtask.getSendstate()); |
| | | throw new BaseException("该任务不执行"); |
| | | } |
| | | } |
| | | |
| | | //获取本次的问答结果 |
| | | Map<String, Object> scriptInfoByCondition = serviceTaskService.getScriptInfoByCondition(serviceSubTaskQueryReq.getTaskid(), serviceSubTaskQueryReq.getPatid(), serviceSubTaskQueryReq.getIsFinish(), serviceSubTaskQueryReq.getPatfrom(), serviceSubTaskQueryReq.getSubId()); |
| | |
| | | map.put("isabnormal", isabnormalFlag); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 检查并修正问卷题目排序(如果根据选项无序跳转,就会导致错误) |
| | | * |
| | | * @param svyTaskTemplateScriptVOList 问卷题目 VO 列表 |
| | | * @return 修正后的问卷题目列表 |
| | | */ |
| | | public List<SvyTaskTemplateScriptVO> checkQuestionSort(List<SvyTaskTemplateScriptVO> svyTaskTemplateScriptVOList) { |
| | | if (CollectionUtils.isEmpty(svyTaskTemplateScriptVOList)) { |
| | | return svyTaskTemplateScriptVOList; |
| | | } |
| | | |
| | | // 按当前 sort 排序 |
| | | svyTaskTemplateScriptVOList.sort(Comparator.comparingLong(SvyTaskTemplateScriptVO::getSort)); |
| | | |
| | | // 先检查一下是否已经是正确的顺序:连续的序号 1,2,3... 且最后一个问题的 nextScriptno 为 "0" |
| | | boolean isCorrect = true; |
| | | int expectedValue = 1; |
| | | |
| | | for (int i = 0; i < svyTaskTemplateScriptVOList.size(); i++) { |
| | | SvyTaskTemplateScriptVO vo = svyTaskTemplateScriptVOList.get(i); |
| | | |
| | | // 检查 sort 是否连续 |
| | | if (!Objects.equals(expectedValue, vo.getSort())) { |
| | | isCorrect = false; |
| | | break; |
| | | } |
| | | |
| | | // 如果不是最后一个问题,检查 nextScriptno 是否是下一题的序号 |
| | | if (i < svyTaskTemplateScriptVOList.size() - 1) { |
| | | String expectedNextScriptNo = String.valueOf(expectedValue + 1); |
| | | if (!expectedNextScriptNo.equals(vo.getNextScriptno())) { |
| | | isCorrect = false; |
| | | break; |
| | | } |
| | | } else { |
| | | // 最后一个问题的 nextScriptno 必须是 "0" |
| | | if (!"0".equals(vo.getNextScriptno())) { |
| | | isCorrect = false; |
| | | break; |
| | | } |
| | | |
| | | // 检查最后一个问题的所有选项的 nextQuestion 是否为 0 |
| | | if (CollectionUtils.isNotEmpty(vo.getSvyTaskTemplateTargetoptions())) { |
| | | for (SvyTaskTemplateTargetoption option : vo.getSvyTaskTemplateTargetoptions()) { |
| | | if (option.getNextQuestion() == null || !option.getNextQuestion().equals(0)) { |
| | | isCorrect = false; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | expectedValue++; |
| | | } |
| | | |
| | | // 如果已经是正确的,直接返回,不再进行数据库更新 |
| | | if (isCorrect) { |
| | | log.debug("问卷题目排序正确,无需修正,共 {} 个题目", svyTaskTemplateScriptVOList.size()); |
| | | return svyTaskTemplateScriptVOList; |
| | | } |
| | | |
| | | log.info("检测到问卷题目需要修正,开始处理..."); |
| | | |
| | | // 重新分配连续的 sort 值:1, 2, 3... |
| | | int newSortValue = 1; |
| | | List<SvyTaskTemplateScriptVO> updatedList = new ArrayList<>(); |
| | | |
| | | for (int i = 0; i < svyTaskTemplateScriptVOList.size(); i++) { |
| | | SvyTaskTemplateScriptVO vo = svyTaskTemplateScriptVOList.get(i); |
| | | Long oldSort = vo.getSort(); |
| | | |
| | | // 如果 sort 不是预期的连续值,则需要更新 |
| | | if (!Objects.equals(newSortValue, oldSort)) { |
| | | log.warn("检测到题目序号不连续,题目 ID: {},原 sort: {}, 新 sort: {}", vo.getId(), oldSort, newSortValue); |
| | | vo.setSort((long) newSortValue); |
| | | } |
| | | |
| | | // 处理下一个问题的 nextScriptno:除最后一个外,nextScriptno = 当前 sort + 1 |
| | | if (i < svyTaskTemplateScriptVOList.size() - 1) { |
| | | String expectedNextScriptNo = String.valueOf(newSortValue + 1); |
| | | String currentNextScriptNo = vo.getNextScriptno(); |
| | | if (!Objects.equals(expectedNextScriptNo, currentNextScriptNo)) { |
| | | log.warn("检测到 nextScriptno 不正确,题目 ID: {},原 nextScriptno: {}, 新 nextScriptno: {}", vo.getId(), currentNextScriptNo, expectedNextScriptNo); |
| | | vo.setNextScriptno(expectedNextScriptNo); |
| | | } |
| | | } else { |
| | | // 最后一个问题的 nextScriptno 必须是 "0" |
| | | String currentNextScriptNo = vo.getNextScriptno(); |
| | | if (!"0".equals(currentNextScriptNo)) { |
| | | log.warn("检测到最后一个题目的 nextScriptno 应为 0,题目 ID: {},原 nextScriptno: {}", vo.getId(), currentNextScriptNo); |
| | | vo.setNextScriptno("0"); |
| | | } |
| | | } |
| | | |
| | | // 处理每个选项的 nextQuestion |
| | | if (CollectionUtils.isNotEmpty(vo.getSvyTaskTemplateTargetoptions())) { |
| | | // 判断是否是最后一个问题 |
| | | boolean isLastQuestion = (i == svyTaskTemplateScriptVOList.size() - 1); |
| | | int expectedNextQuestion = isLastQuestion ? 0 : newSortValue; |
| | | |
| | | for (SvyTaskTemplateTargetoption option : vo.getSvyTaskTemplateTargetoptions()) { |
| | | Integer optionNextQuestion = option.getNextQuestion(); |
| | | int finalNextQuestion = expectedNextQuestion; |
| | | |
| | | if (!isLastQuestion && (optionNextQuestion == null || !optionNextQuestion.equals(newSortValue))) { |
| | | log.info("检测到选项的 nextQuestion 不正确,选项 ID: {},题目 ID: {},原 nextQuestion: {}, 新 nextQuestion: {}", option.getId(), vo.getId(), optionNextQuestion, newSortValue); |
| | | finalNextQuestion = newSortValue; |
| | | } else if (isLastQuestion && (optionNextQuestion == null || !optionNextQuestion.equals(0))) { |
| | | log.info("检测到最后一个问题的选项 nextQuestion 应为 0,选项 ID: {},题目 ID: {},原 nextQuestion: {}, 新 nextQuestion: {}", option.getId(), vo.getId(), optionNextQuestion, 0); |
| | | } |
| | | |
| | | option.setNextQuestion(finalNextQuestion); |
| | | } |
| | | } |
| | | |
| | | updatedList.add(vo); |
| | | newSortValue++; |
| | | } |
| | | |
| | | return updatedList; |
| | | } |
| | | |
| | | } |