Browse Source

组合标签保存

zhoutg 6 years ago
parent
commit
10149589e1

+ 4 - 0
icssman-service/src/main/java/com/diagbot/entity/wrapper/QuestionMappingWrapper.java

@@ -59,7 +59,11 @@ public class QuestionMappingWrapper implements Serializable {
      */
     private Integer symptomType;
 
+    /**
+     * 文字内容
+     */
     private String text;
 
+    private QuestionWrapper questionMappingSon = new QuestionWrapper(); //第二层级的映射关系
 
 }

+ 3 - 1
icssman-service/src/main/java/com/diagbot/enums/TagTypeEnum.java

@@ -16,7 +16,9 @@ public enum TagTypeEnum implements KeyedNamed {
     T5(5, "竖铺组合项"),
     T6(6, "组合项多列"),
     T7(7, "化验类型"),
-    T8(8, "模板专用文字");
+    T8(8, "文字标签"),
+    T9(9, "空标签"),
+    T10(10, "组合项标签");
 
     @Setter
     private Integer key;

+ 104 - 37
icssman-service/src/main/java/com/diagbot/facade/QuestionInfoFacade.java

@@ -95,11 +95,10 @@ public class QuestionInfoFacade extends QuestionInfoServiceImpl {
             case "3":  //组合项,例如:血压
             case "4":  //组合项,例如:咳嗽
             case "5":  //组合项,例如:有无治疗
+            case "6":  // 组合项,例如:既往史
             case "7":  //化验
                 saveQuestionMapping(questionWrapper, param);
                 break;
-            case "6":  // 组合项,例如:既往史
-                break;
             case "8":  //模板专用文字,无单独维护
             case "9":  //空标签,只维护主表信息
             case "10": //疾病组合类型
@@ -137,37 +136,101 @@ public class QuestionInfoFacade extends QuestionInfoServiceImpl {
         Date now = param.getNow();
         String person = param.getPerson();
         //先删除原明细,再插入新明细
-        questionMappingFacade.update(new QuestionMapping(), //删除原映射关系
-                new UpdateWrapper<QuestionMapping>()
-                        .eq("parent_question", questionInfo.getId())
-                        .eq("is_deleted", IsDeleteEnum.N.getKey())
-                        .set("gmt_modified", now)
-                        .set("modifier", person)
-                        .set("is_deleted", IsDeleteEnum.Y.getKey()));
+        deleteMapping(questionInfo.getId(), param);//删除原映射关系
         List<QuestionMappingWrapper> questionMappings = questionWrapper.getQuestionMappings();
+        if (ListUtil.isNotEmpty(questionMappings)) {
+            for (QuestionMappingWrapper bean : questionMappings) {
+                QuestionWrapper sonQues = bean.getQuestionMappingSon();
+                if (ListUtil.isNotEmpty(sonQues.getQuestionMappings())) {
+                    QuestionInfo ques = new QuestionInfo();
+                    BeanUtil.copyProperties(sonQues, ques);
+                    if (ques.getId() != null) {
+                        ques = this.getOne(new QueryWrapper<QuestionInfo>()
+                                .eq("is_deleted", IsDeleteEnum.N.getKey())
+                                .eq("id", ques.getId()));
+                        if (ques == null) {
+                            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标签被修改,请刷新后重新保存");
+                        }
+                    } else {
+                        String name = "组合项_" + DateUtil.format(DateUtil.now(), DateUtil.FORMAT_FULL);
+                        ques.setTagName(name);
+                        ques.setName(name);
+                        ques.setTagType("10");
+                        ques.setGmtCreate(now);
+                        ques.setCreator(person);
+                        ques.setSubType(1);
+                    }
+                    ques.setType(questionInfo.getType());
+                    ques.setGmtModified(now);
+                    ques.setModifier(person);
+                    this.saveOrUpdate(ques);
+
+                    //删除原二级映射关系
+                    deleteMapping(ques.getId(), param);
+
+                    //添加二级映射关系
+                    saveMapping(sonQues.getQuestionMappings(), new HashMap<String, Long>(), person, now, ques.getId());
+
+                    //设置主映射关系
+                    bean.setSonQuestion(ques.getId());
+                    bean.setParentQuestion(questionInfo.getId());
+                }
+            }
+        }
         if (ListUtil.isNotEmpty(questionMappings)) {
             //预处理文字标签,之后统一添加映射关系
             Map<String, Long> map = getNameMap(questionMappings, now, person, questionInfo.getType());
-            List<QuestionMapping> saveMapping = new ArrayList<>();
-            int i = 1;
-            for (QuestionMappingWrapper mapping : questionMappings) {
-                String text = mapping.getText();
-                if (StringUtil.isNotEmpty(text)) {
-                    mapping.setSonQuestion(map.get(text));
-                }
-                QuestionMapping bean = new QuestionMapping();
-                BeanUtil.copyProperties(mapping, bean);
-                bean.setId(null); //防止前端传参,将前端的id置空自动插入
-                bean.setCreator(person);
-                bean.setGmtCreate(now);
-                bean.setModifier(person);
-                bean.setGmtModified(now);
-                bean.setParentQuestion(questionInfo.getId());
-                bean.setOrderNo(i++);
-                saveMapping.add(bean);
+            saveMapping(questionMappings, map, person, now, questionInfo.getId());
+        }
+    }
+
+
+    /**
+     * 删除映射关系
+     *
+     * @param questionId
+     * @param param
+     */
+    public void deleteMapping(Long questionId, CommonParam param) {
+        questionMappingFacade.update(new QuestionMapping(), //删除原映射关系
+                new UpdateWrapper<QuestionMapping>()
+                        .eq("parent_question", questionId)
+                        .eq("is_deleted", IsDeleteEnum.N.getKey())
+                        .set("gmt_modified", param.getNow())
+                        .set("modifier", param.getPerson())
+                        .set("is_deleted", IsDeleteEnum.Y.getKey()));
+    }
+
+
+    /**
+     * 保存映射关系
+     *
+     * @param questionMappings
+     * @param map
+     * @param person
+     * @param now
+     * @param id
+     */
+    public void saveMapping(List<QuestionMappingWrapper> questionMappings, Map<String, Long> map, String person, Date now, Long id) {
+        List<QuestionMapping> saveMapping = new ArrayList<>();
+        int i = 1;
+        for (QuestionMappingWrapper mapping : questionMappings) {
+            String text = mapping.getText();
+            if (StringUtil.isNotEmpty(text)) {
+                mapping.setSonQuestion(map.get(text));
             }
-            questionMappingService.saveBatch(saveMapping);
+            QuestionMapping bean = new QuestionMapping();
+            BeanUtil.copyProperties(mapping, bean);
+            bean.setId(null); //防止前端传参,将前端的id置空自动插入
+            bean.setCreator(person);
+            bean.setGmtCreate(now);
+            bean.setModifier(person);
+            bean.setGmtModified(now);
+            bean.setParentQuestion(id);
+            bean.setOrderNo(i++);
+            saveMapping.add(bean);
         }
+        questionMappingService.saveBatch(saveMapping);
     }
 
 
@@ -327,19 +390,23 @@ public class QuestionInfoFacade extends QuestionInfoServiceImpl {
             return true;
         }
         List<String> idList = Arrays.asList(ids.split(","));
+        StringBuffer errMsg = new StringBuffer();
         for (String id : idList) {
             // 查询映射关系中是否存在父级
-            List<QuestionMapping> questionMappings = questionMappingFacade.list(new QueryWrapper<QuestionMapping>()
-                    .eq("is_deleted", IsDeleteEnum.N.getKey())
-                    .eq("son_question", id));
-            if (ListUtil.isNotEmpty(questionMappings)) {
-                List<Long> questionIds = questionMappings.stream().map(row -> row.getParentQuestion()).collect(Collectors.toList());
-                List<String> tagName = this.list(new QueryWrapper<QuestionInfo>()
-                        .eq("is_deleted", IsDeleteEnum.N.getKey())
-                        .in("id", questionIds))
-                        .stream().map(row -> "【" + row.getTagName() + "】").collect(Collectors.toList());
-                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请先删除标签的关联:" + String.join("、", tagName));
+            List<QuestionInfo> info = this.getParentQuestion(Long.parseLong(id));
+            for(QuestionInfo bean : info) {
+                if(bean.getTagType() != null && Integer.parseInt(bean.getTagType()) == TagTypeEnum.T10.getKey()) {
+                    List<QuestionInfo> info2 = this.getParentQuestion(bean.getId());
+                    List<String> msg = info2.stream().map(row -> "【" + row.getTagName() + "】").collect(Collectors.toList());
+                    errMsg.append(String.join("", msg));
+                } else {
+                    errMsg.append("【").append(bean.getTagName()).append("】");
+                }
+            }
+            if(StringUtil.isNotEmpty(errMsg.toString())) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请先删除标签的关联:" + errMsg);
             }
+
             // 查询模板中是否存在
             List<ModuleDetail> moduleDetails = moduleDetailFacade.list(new QueryWrapper<ModuleDetail>()
                     .eq("is_deleted", IsDeleteEnum.N.getKey())

+ 9 - 0
icssman-service/src/main/java/com/diagbot/mapper/QuestionInfoMapper.java

@@ -51,6 +51,15 @@ public interface QuestionInfoMapper extends BaseMapper<QuestionInfo> {
     public List<QuestionInfo> getSpecial(Map map);
 
 
+    /**
+     * 获取关联的父级标签
+     *
+     * @param id
+     * @return
+     */
+    public List<QuestionInfo> getParent(Long id);
+
+
     /**
      * 获取标签列表
      *

+ 9 - 0
icssman-service/src/main/java/com/diagbot/service/QuestionInfoService.java

@@ -72,6 +72,15 @@ public interface QuestionInfoService extends IService<QuestionInfo> {
      * @return
      */
     public List<QuestionInfo> getSpecial(Map map);
+
+
+    /**
+     * 获取关联的父级标签
+     *
+     * @param id
+     * @return
+     */
+    public List<QuestionInfo> getParentQuestion(Long id);
 }
 
 

+ 5 - 0
icssman-service/src/main/java/com/diagbot/service/impl/QuestionInfoServiceImpl.java

@@ -51,6 +51,11 @@ public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, Que
         return baseMapper.getSpecial(map);
     }
 
+    @Override
+    public List<QuestionInfo> getParentQuestion(Long id) {
+        return baseMapper.getParent(id);
+    }
+
     @Override
     public IPage<QuestionPageDTO> getList(QuestionPageVO questionPageVO) {
         return baseMapper.getList(questionPageVO);

+ 6 - 0
icssman-service/src/main/resources/mapper/QuestionInfoMapper.xml

@@ -148,4 +148,10 @@
     </select>
 
 
+    <select id="getParent"  resultMap="BaseResultMap">
+        SELECT a.* FROM `icss_question_info` a, icss_question_mapping b
+        where a.is_deleted = 'N' and b.is_deleted = 'N' and a.id = b.parent_question
+        and b.son_question = #{id}
+    </select>
+
 </mapper>