|
@@ -0,0 +1,132 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.client.AiptServiceClient;
|
|
|
+import com.diagbot.dto.ModuleDetailDTO;
|
|
|
+import com.diagbot.dto.ModuleInfoDTO;
|
|
|
+import com.diagbot.dto.QuestionDTO;
|
|
|
+import com.diagbot.entity.ModuleDetail;
|
|
|
+import com.diagbot.entity.ModuleInfo;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.service.impl.ModuleInfoServiceImpl;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.vo.ConceptSearchVO;
|
|
|
+import com.diagbot.vo.ModuleVO;
|
|
|
+import com.diagbot.vo.QuestionVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 模型业务层
|
|
|
+ * @author: zhoutg
|
|
|
+ * @time: 2018/8/6 9:11
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ModuleFacade extends ModuleInfoServiceImpl {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ModuleDetailFacade moduleDetailFacade;
|
|
|
+ @Autowired
|
|
|
+ QuestionFacade questionFacade;
|
|
|
+ @Autowired
|
|
|
+ AiptServiceClient aiptServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回所有的模型结构
|
|
|
+ *
|
|
|
+ * @return 模型结构
|
|
|
+ */
|
|
|
+ public List<ModuleInfoDTO> getAll(ModuleVO moduleVO) {
|
|
|
+ ConceptSearchVO conceptSearchVO = new ConceptSearchVO();
|
|
|
+ List<ModuleInfoDTO> data = new ArrayList<>();
|
|
|
+ //取到所有模板信息
|
|
|
+ List<ModuleInfo> list = new ArrayList<>();
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ Boolean isDefault = false;
|
|
|
+ if (moduleVO.getMouduleType().intValue() == 1) {
|
|
|
+ //根据科室筛选如果没有,返回通用模板
|
|
|
+ list = getModuleInfoByDisType(moduleVO.getMouduleType(), moduleVO.getRelationId());
|
|
|
+ if (ListUtil.isNotEmpty(list)) {
|
|
|
+ ids = list.stream()
|
|
|
+ .map(moduleInfo -> moduleInfo.getId())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ isDefault = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isDefault = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //科室没有内容,或者默认情况下,需要推测出默认模板
|
|
|
+ if (isDefault) {
|
|
|
+ //默认
|
|
|
+ list = getModuleInfoByDisType(0, 0L);
|
|
|
+ ids = list.stream()
|
|
|
+ .map(moduleInfo -> moduleInfo.getId())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ data = BeanUtil.listCopyTo(list, ModuleInfoDTO.class);
|
|
|
+ Map<Long, ModuleInfo> moduleInfoMap
|
|
|
+ = list.stream().collect(Collectors.toMap(ModuleInfo::getId, moduleInfo -> moduleInfo));
|
|
|
+ Map<Long, List<ModuleDetail>> moduleDetailMap = new LinkedHashMap<>();
|
|
|
+ //取到所有模板明细
|
|
|
+ if (ListUtil.isNotEmpty(ids)) {
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
+ paramMap.put("ids", ids);
|
|
|
+ paramMap.put("sexType", moduleVO.getSexType());
|
|
|
+ paramMap.put("age", moduleVO.getAge());
|
|
|
+ List<ModuleDetail> moduleDetailList = moduleDetailFacade.getDetailByModuleFac(paramMap);
|
|
|
+ if (ListUtil.isNotEmpty(moduleDetailList)) {
|
|
|
+ moduleDetailMap = EntityUtil.makeEntityListMap(moduleDetailList, "moduleId");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //循环放入模板明细
|
|
|
+ List<ModuleDetailDTO> moduleDetailDTOList = new ArrayList<>();
|
|
|
+ for (ModuleInfoDTO bean : data) {
|
|
|
+ if (moduleDetailMap.get(bean.getId()) != null) {
|
|
|
+ moduleDetailDTOList = BeanUtil.listCopyTo(moduleDetailMap.get(bean.getId()), ModuleDetailDTO.class);
|
|
|
+ for (ModuleDetailDTO detailDTO : moduleDetailDTOList) {
|
|
|
+ if (null != detailDTO.getQuestionId()) {
|
|
|
+ QuestionVO questionVO = new QuestionVO();
|
|
|
+ questionVO.setId(detailDTO.getQuestionId());
|
|
|
+ questionVO.setSexType(moduleVO.getSexType());
|
|
|
+ questionVO.setAge(moduleVO.getAge());
|
|
|
+ QuestionDTO questionDTO = questionFacade.getById(questionVO);
|
|
|
+ BeanUtil.copyProperties(questionDTO, detailDTO);
|
|
|
+ }
|
|
|
+ if (null != detailDTO.getRelationModule() &&
|
|
|
+ moduleInfoMap.get(detailDTO.getRelationModule()) != null) {
|
|
|
+ detailDTO.setRelationModuleName(moduleInfoMap.get(detailDTO.getRelationModule()).getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bean.setModuleDetailDTOList(moduleDetailDTOList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取相应类型的模板信息
|
|
|
+ *
|
|
|
+ * @param moduleType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<ModuleInfo> getModuleInfoByDisType(Integer moduleType, Long relationId) {
|
|
|
+ QueryWrapper<ModuleInfo> queryWrapper = new QueryWrapper();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("module_type", moduleType)
|
|
|
+ .eq("relation_id", relationId);
|
|
|
+ queryWrapper.orderByAsc("id");
|
|
|
+ return this.list(queryWrapper);
|
|
|
+ }
|
|
|
+}
|