ModuleInfoFacade.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. package com.diagbot.facade;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.diagbot.client.KnowledgemanServiceClient;
  6. import com.diagbot.client.UserServiceClient;
  7. import com.diagbot.dto.ConceptBaseDTO;
  8. import com.diagbot.dto.DeptDTO;
  9. import com.diagbot.dto.GetAllDeptAndDisInfoDTO;
  10. import com.diagbot.dto.GetModuleDetailInfoDTO;
  11. import com.diagbot.dto.GetModuleInfoOneDTO;
  12. import com.diagbot.dto.GetModuleTypeDTO;
  13. import com.diagbot.dto.ModuleInfoListDTO;
  14. import com.diagbot.dto.RespDTO;
  15. import com.diagbot.entity.DictionaryInfo;
  16. import com.diagbot.entity.ModuleDetail;
  17. import com.diagbot.entity.ModuleInfo;
  18. import com.diagbot.entity.QuestionInfo;
  19. import com.diagbot.enums.IsDeleteEnum;
  20. import com.diagbot.enums.ModuleInfoTypeEnum;
  21. import com.diagbot.service.impl.ModuleInfoServiceImpl;
  22. import com.diagbot.util.BeanUtil;
  23. import com.diagbot.util.DateUtil;
  24. import com.diagbot.util.ListUtil;
  25. import com.diagbot.util.RespDTOUtil;
  26. import com.diagbot.util.StringUtil;
  27. import com.diagbot.util.UserUtils;
  28. import com.diagbot.vo.AddModuleInfoVO;
  29. import com.diagbot.vo.ConceptTypeVO;
  30. import com.diagbot.vo.GetAllDeptAndDisInfoVO;
  31. import com.diagbot.vo.GetModuleInfoOneVO;
  32. import com.diagbot.vo.GetModuleInfoVO;
  33. import com.diagbot.vo.GetModuleTypeVO;
  34. import com.diagbot.vo.UpdateModuleInfoVO;
  35. import org.springframework.beans.factory.annotation.Autowired;
  36. import org.springframework.stereotype.Component;
  37. import java.util.ArrayList;
  38. import java.util.Arrays;
  39. import java.util.Date;
  40. import java.util.HashMap;
  41. import java.util.Iterator;
  42. import java.util.List;
  43. import java.util.Map;
  44. import java.util.stream.Collectors;
  45. /**
  46. * @Description:
  47. * @Author:zhoutg
  48. * @time: 2018/11/23 11:37
  49. */
  50. @Component
  51. public class ModuleInfoFacade extends ModuleInfoServiceImpl {
  52. @Autowired
  53. ModuleDetailFacade moduleDetailFacade;
  54. @Autowired
  55. QuestionFacade questionFacade;
  56. @Autowired
  57. UserServiceClient userServiceClient;
  58. @Autowired
  59. DictionaryFacade dictionaryFacade;
  60. @Autowired
  61. KnowledgemanServiceClient knowledgemanServiceClient;
  62. /**
  63. * 根据id删除标签模板
  64. *
  65. * @param ids
  66. * @return
  67. */
  68. public Boolean deleteByIdsFac(String ids) {
  69. //如果是子模板,删除该子模板与其他模板的关联
  70. QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
  71. moduleInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
  72. .eq("id",ids);
  73. ModuleInfo moduleInfo = this.getOne(moduleInfoQueryWrapper);
  74. String userId = UserUtils.getCurrentPrincipleID();
  75. Date date = DateUtil.now();
  76. if(null != moduleInfo){
  77. if("31".equals(moduleInfo.getType())
  78. || "32".equals(moduleInfo.getType())
  79. || "322".equals(moduleInfo.getType())){
  80. UpdateWrapper<ModuleDetail> moduleDetailUpdateWrapper = new UpdateWrapper<>();
  81. moduleDetailUpdateWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  82. .eq("relation_module", moduleInfo.getId())
  83. .set("is_deleted", IsDeleteEnum.Y.getKey())
  84. .set("modifier", userId)
  85. .set("gmt_modified",date );
  86. moduleDetailFacade.update(new ModuleDetail(),moduleDetailUpdateWrapper);
  87. }
  88. }
  89. if (StringUtil.isEmpty(ids)) {
  90. return true;
  91. }
  92. Map paramMap = new HashMap<>();
  93. paramMap.put("delete", IsDeleteEnum.Y.getKey());
  94. paramMap.put("ids", Arrays.asList(ids.split(",")));
  95. paramMap.put("gmtModified", date);
  96. paramMap.put("modifier", userId);
  97. //删除模板
  98. this.deleteByIds(paramMap);
  99. //删除明细表
  100. moduleDetailFacade.deleteByModuleIdFac(paramMap);
  101. return true;
  102. }
  103. /**
  104. * 添加模板
  105. *
  106. * @param addModulInfoVO
  107. * @return
  108. */
  109. public Boolean saveOrUpdateModuleInfo(AddModuleInfoVO addModulInfoVO) {
  110. Long moduleId = null;
  111. Boolean bac = false;
  112. if(addModulInfoVO.getId() == null){
  113. String userId = UserUtils.getCurrentPrincipleID();
  114. Date now = DateUtil.now();
  115. ModuleInfo moduleInfo = new ModuleInfo();
  116. BeanUtil.copyProperties(addModulInfoVO, moduleInfo);
  117. moduleInfo.setCreator(userId);
  118. moduleInfo.setModifier(userId);
  119. moduleInfo.setGmtCreate(now);
  120. moduleInfo.setGmtModified(now);
  121. moduleInfo.setType(addModulInfoVO.getType());
  122. moduleInfo.setModuleType(addModulInfoVO.getModuleType());
  123. //当添加为科室专用模板时添加关联id
  124. if(addModulInfoVO.getModuleType().intValue() == 1){
  125. moduleInfo.setRelationId(addModulInfoVO.getRelationId());
  126. }
  127. this.save(moduleInfo);
  128. moduleId = moduleInfo.getId();
  129. bac = moduleDetailFacade.saveOrUpdateInfos(addModulInfoVO, moduleId);
  130. }else {
  131. UpdateModuleInfoVO updateModuleInfoVO = new UpdateModuleInfoVO();
  132. BeanUtil.copyProperties(addModulInfoVO,updateModuleInfoVO);
  133. bac = this.updateModuleInfo(updateModuleInfoVO);
  134. }
  135. return bac;
  136. }
  137. /**
  138. * 修改模板
  139. *
  140. * @param updateModuleInfoVO
  141. * @return
  142. */
  143. public Boolean updateModuleInfo(UpdateModuleInfoVO updateModuleInfoVO) {
  144. String userId = UserUtils.getCurrentPrincipleID();
  145. UpdateWrapper<ModuleInfo> moduleInfoUpdateWrapper = new UpdateWrapper<>();
  146. moduleInfoUpdateWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  147. .eq("id", updateModuleInfoVO.getId())
  148. .set("name", updateModuleInfoVO.getName())
  149. .set("type", updateModuleInfoVO.getType())
  150. .set("module_type",updateModuleInfoVO.getModuleType())
  151. .set("modifier", userId)
  152. .set("gmt_modified", DateUtil.now())
  153. .set("remark",updateModuleInfoVO.getRemark());
  154. if(updateModuleInfoVO.getRelationId() != null){
  155. moduleInfoUpdateWrapper.set("relation_id", updateModuleInfoVO.getRelationId());
  156. }
  157. this.update(new ModuleInfo(), moduleInfoUpdateWrapper);
  158. AddModuleInfoVO addModuleInfoVO = new AddModuleInfoVO();
  159. BeanUtil.copyProperties(updateModuleInfoVO, addModuleInfoVO);
  160. return moduleDetailFacade.saveOrUpdateInfos(addModuleInfoVO, updateModuleInfoVO.getId());
  161. }
  162. /**
  163. * 模板维护页面获取模板列表
  164. *
  165. * @param getModuleInfoVO
  166. * @return
  167. */
  168. public IPage<ModuleInfoListDTO> getModuleInfoList(GetModuleInfoVO getModuleInfoVO) {
  169. //获取模板信息
  170. IPage<ModuleInfoListDTO> moduleInfoDTOIPage = this.getModuleInfoListByType(getModuleInfoVO);
  171. List<String> ids = new ArrayList<>();
  172. List<Long> deptId = new ArrayList<>();
  173. for (ModuleInfoListDTO moduleInfoListDTO : moduleInfoDTOIPage.getRecords()) {
  174. ids.add(moduleInfoListDTO.getModifier());
  175. if(moduleInfoListDTO.getModuleType().intValue() == 1){
  176. deptId.add(moduleInfoListDTO.getRelationId());
  177. }
  178. }
  179. //获取科室名称
  180. ConceptTypeVO conceptTypeVO = new ConceptTypeVO();
  181. conceptTypeVO.setType(1);
  182. RespDTO<List<ConceptBaseDTO>> deptInfoList = knowledgemanServiceClient.getConceptListByType(conceptTypeVO);
  183. RespDTOUtil.respNGDeal(deptInfoList,"获取科室信息失败");
  184. Map<Long, ConceptBaseDTO> deptInfoMap = deptInfoList.data.stream().collect(Collectors.toMap(ConceptBaseDTO::getConceptId,conceptBaseDTO -> conceptBaseDTO));
  185. //获取模板类型名称
  186. QueryWrapper<DictionaryInfo> dictionaryInfoQueryWrapper = new QueryWrapper<>();
  187. dictionaryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  188. .eq("group_type", 1)
  189. .eq("return_type", 1)
  190. .orderByDesc("order_no");
  191. List<DictionaryInfo> dictionaryInfoList = dictionaryFacade.list(dictionaryInfoQueryWrapper);
  192. Map<String, DictionaryInfo> dictionaryInfoMap = dictionaryInfoList.stream().collect(Collectors.toMap(DictionaryInfo::getVal,dictionaryInfo -> dictionaryInfo));
  193. if(ListUtil.isNotEmpty(moduleInfoDTOIPage.getRecords())){
  194. //获取用户信息
  195. RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(ids);
  196. RespDTOUtil.respNGDeal(respDTO,"获取用户信息失败");
  197. //将用户信息放入实体
  198. for (ModuleInfoListDTO moduleInfoListDTO : moduleInfoDTOIPage.getRecords()) {
  199. moduleInfoListDTO.setUserName(respDTO.data.get(moduleInfoListDTO.getModifier()));
  200. if(null != dictionaryInfoMap.get(moduleInfoListDTO.getType())){
  201. moduleInfoListDTO.setAscriptionName(dictionaryInfoMap.get(moduleInfoListDTO.getType()).getName());
  202. }
  203. if(moduleInfoListDTO.getModuleType().intValue() == 1){//根据科室
  204. if(moduleInfoListDTO.getRelationId().intValue() != -1){//判断是不是科室通用子模板
  205. if(null != deptInfoMap.get(moduleInfoListDTO.getRelationId())){
  206. moduleInfoListDTO.setRelationName(deptInfoMap.get(moduleInfoListDTO.getRelationId()).getName());
  207. }
  208. }else {
  209. moduleInfoListDTO.setRelationName(ModuleInfoTypeEnum.Common.getName());
  210. }
  211. }
  212. moduleInfoListDTO.setModuleTypeName(ModuleInfoTypeEnum.getName(moduleInfoListDTO.getModuleType().intValue()));
  213. }
  214. }
  215. return moduleInfoDTOIPage;
  216. }
  217. /**
  218. * 模板维护页面获取模板列表
  219. *
  220. * @param getModuleInfoOneVO
  221. * @return
  222. */
  223. public GetModuleInfoOneDTO getModuleInfoOne(GetModuleInfoOneVO getModuleInfoOneVO) {
  224. GetModuleInfoOneDTO getModuleInfoOneDTO = new GetModuleInfoOneDTO();
  225. List<Long> deptId = new ArrayList<>();
  226. //获取模板信息
  227. QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
  228. moduleInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  229. .eq("id", getModuleInfoOneVO.getModuleId());
  230. ModuleInfo moduleInfo = this.getOne(moduleInfoQueryWrapper);
  231. if(null != moduleInfo){
  232. //获取模板类型名称
  233. if(moduleInfo.getModuleType().intValue() == 1){
  234. deptId.add(moduleInfo.getRelationId());
  235. }
  236. //获取科室名称
  237. ConceptTypeVO conceptTypeVO = new ConceptTypeVO();
  238. conceptTypeVO.setType(1);
  239. RespDTO<List<ConceptBaseDTO>> deptInfoList = knowledgemanServiceClient.getConceptListByType(conceptTypeVO);
  240. RespDTOUtil.respNGDeal(deptInfoList,"获取科室信息失败");
  241. Map<Long, ConceptBaseDTO> deptInfoMap = deptInfoList.data.stream().collect(Collectors.toMap(ConceptBaseDTO::getConceptId,conceptBaseDTO -> conceptBaseDTO));
  242. //获取模板类型
  243. BeanUtil.copyProperties(moduleInfo, getModuleInfoOneDTO);
  244. //获取模板类型名称
  245. QueryWrapper<DictionaryInfo> dictionaryInfoQueryWrapper = new QueryWrapper<>();
  246. dictionaryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  247. .eq("group_type", 1)
  248. .eq("return_type", 1)
  249. .orderByDesc("order_no");
  250. List<DictionaryInfo> dictionaryInfoList = dictionaryFacade.list(dictionaryInfoQueryWrapper);
  251. Map<String, DictionaryInfo> dictionaryInfoMap = dictionaryInfoList.stream().collect(Collectors.toMap(DictionaryInfo::getVal,dictionaryInfo -> dictionaryInfo));
  252. if (null != dictionaryInfoMap.get(getModuleInfoOneDTO.getType())) {
  253. getModuleInfoOneDTO.setAscriptionName(dictionaryInfoMap.get(getModuleInfoOneDTO.getType()).getName());
  254. }
  255. getModuleInfoOneDTO.setModuleTypeName(ModuleInfoTypeEnum.getName(getModuleInfoOneDTO.getModuleType().intValue()));
  256. if(getModuleInfoOneDTO.getModuleType().intValue() == 1){
  257. if(null != deptInfoMap.get(getModuleInfoOneDTO.getRelationId())){
  258. getModuleInfoOneDTO.setRelationName(deptInfoMap.get(getModuleInfoOneDTO.getRelationId()).getName());
  259. }
  260. }
  261. //获取模板明细
  262. List<GetModuleDetailInfoDTO> getModuleDetailInfoDTOList = new ArrayList<>();
  263. GetModuleDetailInfoDTO getModuleDetailInfoDTO = null;
  264. QueryWrapper<ModuleDetail> moduleDetailQueryWrapper = new QueryWrapper<>();
  265. moduleDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  266. .eq("module_id", getModuleInfoOneVO.getModuleId())
  267. .orderByAsc("order_no");
  268. List<ModuleDetail> moduleDetailList = moduleDetailFacade.list(moduleDetailQueryWrapper);
  269. List<Long> questionIdList = moduleDetailList.stream().map(moduleDetail -> moduleDetail.getQuestionId()).collect(Collectors.toList());
  270. List<Long> moduleIdList = moduleDetailList.stream().map(moduleDetail -> moduleDetail.getRelationModule()).collect(Collectors.toList());
  271. //获取标签信息
  272. QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
  273. questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  274. .in("id", questionIdList);
  275. List<QuestionInfo> questionInfoList = questionFacade.list(questionInfoQueryWrapper);
  276. Map<Long, QuestionInfo> questionInfoMap = questionInfoList.stream().collect(Collectors.toMap(QuestionInfo::getId, questionInfo -> questionInfo));
  277. //获取模板信息
  278. QueryWrapper<ModuleInfo> getRelationModuleWapper = new QueryWrapper<>();
  279. questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  280. .in("id", moduleIdList);
  281. List<ModuleInfo> moduleInfoList = this.list(getRelationModuleWapper);
  282. Map<Long, ModuleInfo> moduleInfoMap = moduleInfoList.stream().collect(Collectors.toMap(ModuleInfo::getId, m -> moduleInfo));
  283. //循环给出参赋值
  284. for (ModuleDetail moduleDetail : moduleDetailList) {
  285. getModuleDetailInfoDTO = new GetModuleDetailInfoDTO();
  286. BeanUtil.copyProperties(moduleDetail, getModuleDetailInfoDTO);
  287. if (moduleDetail.getQuestionId() != null) {
  288. getModuleDetailInfoDTO.setTagName(questionInfoMap.get(moduleDetail.getQuestionId()).getTagName());
  289. getModuleDetailInfoDTO.setTagType(questionInfoMap.get(moduleDetail.getQuestionId()).getTagType());
  290. } else {
  291. getModuleDetailInfoDTO.setRelationModuleName(moduleInfoMap.get(moduleDetail.getRelationModule()).getName());
  292. }
  293. getModuleDetailInfoDTOList.add(getModuleDetailInfoDTO);
  294. }
  295. getModuleInfoOneDTO.setModuleDetail(getModuleDetailInfoDTOList);
  296. }
  297. return getModuleInfoOneDTO;
  298. }
  299. /**
  300. * 获取模板类型(从症状情况到补充内容)
  301. *
  302. * @param getModuleTypeVO
  303. * @return
  304. */
  305. public List<GetModuleTypeDTO> getModuleType(GetModuleTypeVO getModuleTypeVO){
  306. QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
  307. moduleInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  308. .eq("module_Type", getModuleTypeVO.getModuleType());
  309. if(getModuleTypeVO.getRelationId() != null){
  310. moduleInfoQueryWrapper.eq("relation_id", getModuleTypeVO.getRelationId());
  311. }
  312. List<ModuleInfo> moduleInfos = this.list(moduleInfoQueryWrapper);
  313. List<String> types = moduleInfos.stream().map(moduleInfo -> moduleInfo.getType()).collect(Collectors.toList());
  314. //获取模板类型
  315. QueryWrapper<DictionaryInfo> dictionaryInfoQueryWrapper = new QueryWrapper<>();
  316. dictionaryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  317. .eq("group_type", 1)
  318. .eq("return_type", 1)
  319. .orderByAsc("order_no")
  320. .notIn("val",types);
  321. List<DictionaryInfo> dictionaryInfoList = dictionaryFacade.list(dictionaryInfoQueryWrapper);
  322. List<GetModuleTypeDTO> getModuleTypeDTOS = new ArrayList<>();
  323. for (DictionaryInfo dictionaryInfo : dictionaryInfoList) {
  324. GetModuleTypeDTO getModuleTypeDTO = new GetModuleTypeDTO();
  325. getModuleTypeDTO.setName(dictionaryInfo.getName());
  326. getModuleTypeDTO.setVal(dictionaryInfo.getVal());
  327. getModuleTypeDTOS.add(getModuleTypeDTO);
  328. }
  329. return getModuleTypeDTOS;
  330. }
  331. /**
  332. * 获取所有的科室和疾病信息
  333. *
  334. * @return
  335. */
  336. public GetAllDeptAndDisInfoDTO getAllDeptAndDisInfo(GetAllDeptAndDisInfoVO getAllDeptAndDisInfoVO){
  337. //获取所有科室
  338. ConceptTypeVO deptType = new ConceptTypeVO();
  339. deptType.setType(1);
  340. RespDTO<List<ConceptBaseDTO>> deptInfoList = knowledgemanServiceClient.getConceptListByType(deptType);
  341. RespDTOUtil.respNGDeal(deptInfoList,"获取科室信息失败");
  342. if(getAllDeptAndDisInfoVO.getModuleType() != null && getAllDeptAndDisInfoVO.getModuleType().intValue() == 1){//过滤添加过得科室
  343. List<ModuleInfo> moduleInfoList = getModuleInfos(getAllDeptAndDisInfoVO.getModuleType(),getAllDeptAndDisInfoVO.getType());
  344. List<Long> deptIds = moduleInfoList.stream().map(ModuleInfo::getRelationId).collect(Collectors.toList());
  345. Iterator<ConceptBaseDTO> deptIterator = deptInfoList.data.iterator();
  346. for (Long deptId : deptIds) {
  347. while (deptIterator.hasNext()){
  348. Long deptConceptId = deptIterator.next().getConceptId();
  349. if(deptId.intValue() == deptConceptId.intValue()){
  350. deptIterator.remove();
  351. }
  352. }
  353. }
  354. }
  355. List<DeptDTO> deptDTOS = BeanUtil.listCopyTo(deptInfoList.data,DeptDTO.class);
  356. GetAllDeptAndDisInfoDTO getAllDeptAndDisInfoDTO = new GetAllDeptAndDisInfoDTO();
  357. getAllDeptAndDisInfoDTO.setDeptDTOS(deptDTOS);
  358. return getAllDeptAndDisInfoDTO;
  359. }
  360. /**
  361. * 获取模板信息
  362. *
  363. * @param moduleType
  364. * @param type
  365. * @return
  366. */
  367. public List<ModuleInfo> getModuleInfos(Long moduleType,String type){
  368. QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
  369. moduleInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
  370. .eq("module_type",moduleType)
  371. .eq("type",type);
  372. return this.list(moduleInfoQueryWrapper);
  373. }
  374. }