Ver código fonte

完善用户信息采集查询逻辑

cgp 1 semana atrás
pai
commit
98463a10fa

+ 5 - 1
fs-service/src/main/java/com/fs/his/vo/AnswerVO.java

@@ -17,6 +17,8 @@ public class AnswerVO implements Serializable {
 
 
     //已选择数据(多选)
     //已选择数据(多选)
     private List<Integer> value;
     private List<Integer> value;
+
+    //每个问题下的选项的备注根据options的open 属性来判断 true 显示, false 不显示
     private List<Remarks> remarksList;
     private List<Remarks> remarksList;
 
 
     //排序
     //排序
@@ -36,7 +38,9 @@ public class AnswerVO implements Serializable {
 
 
     @Data
     @Data
     public static class Remarks implements Serializable{
     public static class Remarks implements Serializable{
-        private String text;
+        //问题的选项值
         private Integer value;
         private Integer value;
+        //选项的备注
+        private String text;
     }
     }
 }
 }

+ 40 - 1
fs-service/src/main/java/com/fs/hisStore/service/impl/FsUserInformationCollectionServiceImpl.java

@@ -3,6 +3,7 @@ package com.fs.hisStore.service.impl;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.api.WxMaService;
@@ -1415,7 +1416,36 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
         return false; // 默认返回 false
         return false; // 默认返回 false
     }
     }
 
 
-    private List<AnswerVO> getAnswerVOs(List<AnswerVO> target,List<AnswerVO> source) {
+    private List<AnswerVO> getAnswerVOs(List<AnswerVO> target, List<AnswerVO> source) {
+        // 1. 先对 target 中的每个 AnswerVO,从 source 中按 title 找到对应的模板,补充 options 的 open 字段
+        if (target != null && source != null) {
+            // 构建 source 的 title -> AnswerVO 映射
+            Map<String, AnswerVO> sourceMap = source.stream()
+                    .collect(Collectors.toMap(AnswerVO::getTitle, Function.identity(), (a, b) -> a));
+
+            for (AnswerVO targetAnswer : target) {
+                AnswerVO sourceAnswer = sourceMap.get(targetAnswer.getTitle());
+                if (sourceAnswer != null) {
+                    // 构建 source 中 options 的 value -> open 映射
+                    Map<Integer, Boolean> openMap = sourceAnswer.getOptions().stream()
+                            .collect(Collectors.toMap(AnswerVO.Options::getValue, AnswerVO.Options::isOpen, (a, b) -> a));
+
+                    // 遍历 target 的 options,设置 open 字段
+                    if (targetAnswer.getOptions() != null) {
+                        for (AnswerVO.Options opt : targetAnswer.getOptions()) {
+                            Boolean open = openMap.get(opt.getValue());
+                            if (open != null) {
+                                opt.setOpen(open);
+                            } else {
+                                opt.setOpen(false); // 默认 false
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        // 2. 合并列表并去重(保留第一个出现的,即 target 中补全后的数据优先)
         target.addAll(source);
         target.addAll(source);
         return target.stream()
         return target.stream()
                 .collect(Collectors.groupingBy(AnswerVO::getTitle))
                 .collect(Collectors.groupingBy(AnswerVO::getTitle))
@@ -1423,6 +1453,15 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
                 .map(group -> group.stream().reduce((a, b) -> a).orElse(null))
                 .map(group -> group.stream().reduce((a, b) -> a).orElse(null))
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
     }
     }
+    //这个是备份方法
+//    private List<AnswerVO> getAnswerVOs(List<AnswerVO> target,List<AnswerVO> source) {
+//        target.addAll(source);
+//        return target.stream()
+//                .collect(Collectors.groupingBy(AnswerVO::getTitle))
+//                .values().stream()
+//                .map(group -> group.stream().reduce((a, b) -> a).orElse(null))
+//                .collect(Collectors.toList());
+//    }
 
 
     /**
     /**
      * 辅助方法:组装信息采集对象
      * 辅助方法:组装信息采集对象