|
@@ -0,0 +1,175 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.diagbot.dto.ConceptWithOrderRes;
|
|
|
+import com.diagbot.dto.PartDTO;
|
|
|
+import com.diagbot.dto.PartSymptomDTO;
|
|
|
+import com.diagbot.entity.Symptom;
|
|
|
+import com.diagbot.entity.wrapper.ConceptWrapper;
|
|
|
+import com.diagbot.enums.LexiconRSTypeEnum;
|
|
|
+import com.diagbot.enums.LexiconTypeEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.vo.PartSymptomVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 部位facade
|
|
|
+ * @Author: ztg
|
|
|
+ * @Date: 2018/10/23 16:33
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class PartFacade {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ConceptFacade conceptFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据已选部位返回对应的症状
|
|
|
+ *
|
|
|
+ * @param partSymptomVO 参数
|
|
|
+ * @return 部位症状关联信息
|
|
|
+ */
|
|
|
+ public List<PartSymptomDTO> getSymptomByPartName(PartSymptomVO partSymptomVO) {
|
|
|
+ List<String> partList = partSymptomVO.getPartList();
|
|
|
+ if (ListUtil.isEmpty(partList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
+ "请选择部位");
|
|
|
+ }
|
|
|
+ if (partSymptomVO.getSexType() == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
+ "请选择性别");
|
|
|
+ }
|
|
|
+ if (partSymptomVO.getAge() == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
+ "请选择年龄");
|
|
|
+ }
|
|
|
+ if (partSymptomVO.getAge().intValue() < 0 || partSymptomVO.getAge().intValue() > 200) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
|
|
|
+ "超出年龄范围【0 — 200】");
|
|
|
+ }
|
|
|
+ List<PartSymptomDTO> res = new ArrayList<>();
|
|
|
+
|
|
|
+ // 获取顶级部位信息
|
|
|
+ ConceptWrapper conceptWrapper = new ConceptWrapper();
|
|
|
+ conceptWrapper.setStartNameList(partList);
|
|
|
+ conceptWrapper.setStartType(LexiconTypeEnum.BODYPART.getKey());
|
|
|
+// conceptWrapper.setEndNameList(partList);
|
|
|
+ conceptWrapper.setEndType(LexiconTypeEnum.BODYPART.getKey());
|
|
|
+ conceptWrapper.setEndSex(partSymptomVO.getSexType());
|
|
|
+ conceptWrapper.setEndAge(partSymptomVO.getAge());
|
|
|
+ List<ConceptWithOrderRes> list = conceptFacade.getConceptWithOrder(conceptWrapper);
|
|
|
+ for (String s : partList) {
|
|
|
+ PartSymptomDTO dto = new PartSymptomDTO();
|
|
|
+ dto.setName(s);
|
|
|
+ res.add(dto);
|
|
|
+ }
|
|
|
+ // 设置一级部位
|
|
|
+ for (PartSymptomDTO dto : res) {
|
|
|
+ for (ConceptWithOrderRes concept : list) {
|
|
|
+ if(dto.getName().equals(concept.getStartName()) && dto.getName().equals(concept.getEndName())) {
|
|
|
+ dto.setConceptId(concept.getStartId());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> secPart = new ArrayList<>();
|
|
|
+ // 设置二级部位
|
|
|
+ for (PartSymptomDTO dto : res) {
|
|
|
+ List<PartDTO> partDTO = new ArrayList<>();
|
|
|
+ for (ConceptWithOrderRes concept : list) {
|
|
|
+ if (dto.getName().equals(concept.getStartName())
|
|
|
+ && !concept.getStartName().equals(concept.getEndName())) {
|
|
|
+ PartDTO dto1 = new PartDTO();
|
|
|
+ dto1.setName(concept.getEndName());
|
|
|
+ dto1.setConceptId(concept.getEndId());
|
|
|
+ secPart.add(concept.getEndName());
|
|
|
+ partDTO.add(dto1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dto.setPartDTO(partDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取二级部位信息
|
|
|
+ ConceptWrapper wrapper = new ConceptWrapper();
|
|
|
+ wrapper.setStartNameList(secPart);
|
|
|
+ wrapper.setStartType(LexiconTypeEnum.BODYPART.getKey());
|
|
|
+ wrapper.setRelationType(LexiconRSTypeEnum.ORDER_BY.getKey());
|
|
|
+ wrapper.setEndType(LexiconTypeEnum.SYMPTOM.getKey());
|
|
|
+ wrapper.setEndSex(partSymptomVO.getSexType());
|
|
|
+ wrapper.setEndAge(partSymptomVO.getAge());
|
|
|
+ List<ConceptWithOrderRes> sympton = conceptFacade.getConceptWithOrder(wrapper);
|
|
|
+
|
|
|
+ List<Symptom> symptomList = new ArrayList<>();
|
|
|
+ for(ConceptWithOrderRes conceptWithOrderRes : sympton) {
|
|
|
+ Symptom bean = new Symptom();
|
|
|
+ bean.setName(conceptWithOrderRes.getEndName());
|
|
|
+ bean.setConceptId(conceptWithOrderRes.getEndId());
|
|
|
+ bean.setPartConceptId(conceptWithOrderRes.getStartId());
|
|
|
+ symptomList.add(bean);
|
|
|
+ }
|
|
|
+ Map<Long, List<Symptom>> keyMap = EntityUtil.makeEntityListMap(symptomList, "partConceptId");
|
|
|
+
|
|
|
+ // 设置部位对应的症状
|
|
|
+ for (PartSymptomDTO dto : res) {
|
|
|
+ for (PartDTO partDTO : dto.getPartDTO()) {
|
|
|
+ if(keyMap.get(partDTO.getConceptId()) != null) {
|
|
|
+ partDTO.setSymptomList(keyMap.get(partDTO.getConceptId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如二级部位无关联的症状,则删除二级部位
|
|
|
+
|
|
|
+ //添加默认部位-全身
|
|
|
+// QueryWrapper wrapper = new QueryWrapper();
|
|
|
+// wrapper.eq("name", "全身");
|
|
|
+// Part part = this.getOne(wrapper);
|
|
|
+// partIds.add(part.getId());
|
|
|
+// Map paramMap = new HashMap<>();
|
|
|
+// paramMap.put("ids", partIds);
|
|
|
+// List<PartSymptomDTO> res = this.getByPartId(paramMap);
|
|
|
+// List<PartDTO> partList = this.getByParentId(paramMap);
|
|
|
+//
|
|
|
+// //添加二级部位信息
|
|
|
+// Map<Long, List<PartDTO>> keyMap = EntityUtil.makeEntityListMap(partList, "parentId");
|
|
|
+// for(PartSymptomDTO bean : res) {
|
|
|
+// bean.setPartDTO(keyMap.get(bean.getId()));
|
|
|
+// }
|
|
|
+//
|
|
|
+// //添加部位和症状的关联信息
|
|
|
+// List<Long> idList = new ArrayList<>();
|
|
|
+// for(PartDTO bean : partList) {
|
|
|
+// idList.add(bean.getId());
|
|
|
+// }
|
|
|
+// Map paramMap1 = new HashMap<>();
|
|
|
+// paramMap1.put("ids", idList);
|
|
|
+// paramMap1.put("sexType", partSymptomVO.getSexType());
|
|
|
+// paramMap1.put("age", partSymptomVO.getAge());
|
|
|
+// List<SymptomWrapper> symptomList = symptomFacade.getByPartIdsFac(paramMap1);
|
|
|
+// Map<Long, List<SymptomWrapper>> partSymptomMap = EntityUtil.makeEntityListMap(symptomList, "partId");
|
|
|
+// for(PartDTO bean : partList) {
|
|
|
+// bean.setSymptomList(partSymptomMap.get(bean.getId()));
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 如二级部位无关联的症状,删除二级部位
|
|
|
+// for(int i = 0; i < res.size(); i++) {
|
|
|
+// List<PartDTO> partDTO = res.get(i).getPartDTO();
|
|
|
+// for(int j = 0; j < partDTO.size(); j++) {
|
|
|
+// if(ListUtil.isEmpty(partDTO.get(j).getSymptomList())) {
|
|
|
+// partDTO.remove(j--);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return res;
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|