Ver Fonte

优化信息采集接口

cgp há 6 dias atrás
pai
commit
cedb3b0cbd

+ 33 - 27
fs-service/src/main/java/com/fs/hisStore/service/impl/FsUserInformationCollectionServiceImpl.java

@@ -796,7 +796,9 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
                 //插入医生消息
                 doctorMsgMapper.insertDoctorMsg(msg);
             }
-            //第一次确认
+            //第一次确认也需要校验用户填写的问题必填项
+            //validateRequiredRemarks();
+            map.setCompleteStatus(0);
             map.setStatus(2);
             //设置用户信息采集进度节点
             if (schedule != null) {
@@ -1373,41 +1375,40 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
     @Transactional(rollbackFor = Exception.class)
     public int submitCollectionAnswerParam(SubmitCollectionAnswerParam param) {
         FsUserInformationCollection informationCollection = fsUserInformationCollectionMapper.selectFsUserInformationCollectionById(param.getCollectionId());
-        if (informationCollection== null){
+        if (informationCollection == null) {
             throw new CustomException("用户采集信息不存在");
         }
         //校验填写用户与信息采集信息用户是否一致
-        if (!param.getUserId().equals(informationCollection.getUserId())){
-            log.error("信息采集用户信息不一致,当前用户userId:{},信息采集表实际userId:{}",param.getUserId(),informationCollection.getUserId());
+        if (!param.getUserId().equals(informationCollection.getUserId())) {
+            log.error("信息采集用户信息不一致,当前用户userId:{},信息采集表实际userId:{}", param.getUserId(), informationCollection.getUserId());
             throw new CustomException("用户信息不一致,请检查");
         }
-        int result=0;
+        int result = 0;
         //根据前端传递的填写结果判断是否更新标识符
-        if (informationCollection.getFillFlag()==0 &&!CollectionUtils.isEmpty(param.getAnswers())) {
+        if (informationCollection.getFillFlag() == 0 && !CollectionUtils.isEmpty(param.getAnswers())) {
             param.getAnswers().forEach(answer -> {
                 if (answer.getFlag() == null) {
                     answer.setFlag(false);
                 }
             });
-            // 只要有一个 answer 的 value 有值,就设置为已填
-            boolean hasValue = param.getAnswers().stream()
-                    .anyMatch(answer -> !CollectionUtils.isEmpty(answer.getValue()));
-            if (hasValue) {
-                informationCollection.setJsonInfo(JSON.toJSONString(param.getAnswers()));
-                //设置填写标识
+            informationCollection.setJsonInfo(JSON.toJSONString(param.getAnswers()));
+            //设置填写标识
+            if (validateRequiredRemarks(param.getAnswers(), informationCollection.getQuestionId())) {
                 informationCollection.setFillFlag(1);
-                fsUserInformationCollectionMapper.updateFsUserInformationCollection(informationCollection);
+                informationCollection.setCompleteStatus(1);
+            } else {
+                informationCollection.setFillFlag(1);//TODO 这里需要配合前端优化一下改成0
+                informationCollection.setCompleteStatus(0);
+            }
+            fsUserInformationCollectionMapper.updateFsUserInformationCollection(informationCollection);
 
-                FsUserInformationCollectionSchedule schedule = scheduleMapper.selectCollectionScheduleRunningByCollectionId(informationCollection.getId());
-                if (schedule == null) {
-                    throw new CustomException("用户采集信息已更新,请扫描最新二维码确认");
-                }
-                //设置填写时间
-                schedule.setFillTime(DateUtils.getNowDate());
-                result=scheduleMapper.updateFsUserInformationCollectionSchedule(schedule);
-            }else {
-                throw new CustomException("请提交采集信息后再操作");
+            FsUserInformationCollectionSchedule schedule = scheduleMapper.selectCollectionScheduleRunningByCollectionId(informationCollection.getId());
+            if (schedule == null) {
+                throw new CustomException("用户采集信息已更新,请扫描最新二维码确认");
             }
+            //设置填写时间
+            schedule.setFillTime(DateUtils.getNowDate());
+            result = scheduleMapper.updateFsUserInformationCollectionSchedule(schedule);
         }
         return result;
     }
@@ -1485,16 +1486,13 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
         if (CollectionUtils.isEmpty(answers)) {
             return true;
         }
-
         // 查询模板数据,获取选项的 open 配置
         FsQuestionAndAnswerVO template = questionAndAnswerService.selectFsQuestionAndAnswerById(questionId);
         if (template == null || CollectionUtils.isEmpty(template.getAnswers())) {
-            log.warn("未找到问题模板,无法校验备注,questionId={}", questionId);
             return true;
         }
 
         // 构建模板中每个问题下选项的 open 映射:title -> (optionValue -> open)
-        // 合并函数 (existing, replacement) -> replacement 保留最新的值
         Map<String, Map<Integer, Boolean>> openConfigMap = template.getAnswers().stream()
                 .collect(Collectors.toMap(
                         AnswerVO::getTitle,
@@ -1502,21 +1500,24 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
                                 .collect(Collectors.toMap(
                                         AnswerVO.Options::getValue,
                                         AnswerVO.Options::isOpen,
-                                        (existing, replacement) -> replacement // 保留最新
+                                        (existing, replacement) -> replacement
                                 )),
-                        (existing, replacement) -> replacement // 外层也保留最新(可选,防止title重复)
+                        (existing, replacement) -> replacement
                 ));
 
         // 遍历提交的答案进行校验
         for (AnswerVO answer : answers) {
             String title = answer.getTitle();
+
             Map<Integer, Boolean> optionOpenMap = openConfigMap.get(title);
             if (optionOpenMap == null) {
+                log.error("模板中未找到该问题:{}", title);
                 continue;
             }
 
             List<Integer> selectedValues = answer.getValue();
             if (CollectionUtils.isEmpty(selectedValues)) {
+                log.error("该问题未选择任何选项:{}", title);
                 continue;
             }
 
@@ -1526,6 +1527,9 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
                 for (AnswerVO.Remarks remark : answer.getRemarksList()) {
                     if (StringUtils.isNotBlank(remark.getText())) {
                         remarkMap.put(remark.getValue(), remark.getText().trim());
+                        log.error("添加备注映射:{} -> {}", remark.getValue(), remark.getText());
+                    } else {
+                        log.error("备注文本为空白,跳过添加:{} -> '{}'", remark.getValue(), remark.getText());
                     }
                 }
             }
@@ -1534,6 +1538,8 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
             for (Integer val : selectedValues) {
                 if (Boolean.TRUE.equals(optionOpenMap.get(val))) {
                     String text = remarkMap.get(val);
+                    log.error("检查选项 {} (open=true),备注文本:'{}'", val, text);
+
                     if (StringUtils.isBlank(text)) {
                         log.warn("必填备注缺失:title={}, optionValue={}", title, val);
                         return false;

+ 1 - 0
fs-service/src/main/resources/mapper/hisStore/FsUserInformationCollectionMapper.xml

@@ -138,6 +138,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN company_user cu ON infocollect.company_user_id = cu.user_id
         LEFT JOIN fs_doctor fd ON infocollect.doctor_id = fd.doctor_id
         <where>
+            infocollect.user_id is NOT NULL
             <if test="questionId != null">
                 AND infocollect.question_id = #{questionId}
             </if>