123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- package com.diagbot.facade;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.diagbot.client.KnowledgemanServiceClient;
- import com.diagbot.client.UserServiceClient;
- import com.diagbot.dto.ConceptBaseDTO;
- import com.diagbot.dto.DeptDTO;
- import com.diagbot.dto.GetAllDeptAndDisInfoDTO;
- import com.diagbot.dto.GetModuleDetailInfoDTO;
- import com.diagbot.dto.GetModuleInfoOneDTO;
- import com.diagbot.dto.GetModuleTypeDTO;
- import com.diagbot.dto.ModuleInfoListDTO;
- import com.diagbot.dto.RespDTO;
- import com.diagbot.entity.DictionaryInfo;
- import com.diagbot.entity.ModuleDetail;
- import com.diagbot.entity.ModuleInfo;
- import com.diagbot.entity.QuestionInfo;
- import com.diagbot.enums.IsDeleteEnum;
- import com.diagbot.enums.ModuleInfoTypeEnum;
- import com.diagbot.service.impl.ModuleInfoServiceImpl;
- import com.diagbot.util.BeanUtil;
- import com.diagbot.util.DateUtil;
- import com.diagbot.util.ListUtil;
- import com.diagbot.util.RespDTOUtil;
- import com.diagbot.util.StringUtil;
- import com.diagbot.util.UserUtils;
- import com.diagbot.vo.AddModuleInfoVO;
- import com.diagbot.vo.ConceptTypeVO;
- import com.diagbot.vo.GetAllDeptAndDisInfoVO;
- import com.diagbot.vo.GetModuleInfoOneVO;
- import com.diagbot.vo.GetModuleInfoVO;
- import com.diagbot.vo.GetModuleTypeVO;
- import com.diagbot.vo.UpdateModuleInfoVO;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * @Description:
- * @Author:zhoutg
- * @time: 2018/11/23 11:37
- */
- @Component
- public class ModuleInfoFacade extends ModuleInfoServiceImpl {
- @Autowired
- ModuleDetailFacade moduleDetailFacade;
- @Autowired
- QuestionFacade questionFacade;
- @Autowired
- UserServiceClient userServiceClient;
- @Autowired
- DictionaryFacade dictionaryFacade;
- @Autowired
- KnowledgemanServiceClient knowledgemanServiceClient;
- /**
- * 根据id删除标签模板
- *
- * @param ids
- * @return
- */
- public Boolean deleteByIdsFac(String ids) {
- //如果是子模板,删除该子模板与其他模板的关联
- QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
- moduleInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
- .eq("id",ids);
- ModuleInfo moduleInfo = this.getOne(moduleInfoQueryWrapper);
- String userId = UserUtils.getCurrentPrincipleID();
- Date date = DateUtil.now();
- if(null != moduleInfo){
- if("31".equals(moduleInfo.getType())
- || "32".equals(moduleInfo.getType())
- || "322".equals(moduleInfo.getType())){
- UpdateWrapper<ModuleDetail> moduleDetailUpdateWrapper = new UpdateWrapper<>();
- moduleDetailUpdateWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("relation_module", moduleInfo.getId())
- .set("is_deleted", IsDeleteEnum.Y.getKey())
- .set("modifier", userId)
- .set("gmt_modified",date );
- moduleDetailFacade.update(new ModuleDetail(),moduleDetailUpdateWrapper);
- }
- }
- if (StringUtil.isEmpty(ids)) {
- return true;
- }
- Map paramMap = new HashMap<>();
- paramMap.put("delete", IsDeleteEnum.Y.getKey());
- paramMap.put("ids", Arrays.asList(ids.split(",")));
- paramMap.put("gmtModified", date);
- paramMap.put("modifier", userId);
- //删除模板
- this.deleteByIds(paramMap);
- //删除明细表
- moduleDetailFacade.deleteByModuleIdFac(paramMap);
- return true;
- }
- /**
- * 添加模板
- *
- * @param addModulInfoVO
- * @return
- */
- public Boolean saveOrUpdateModuleInfo(AddModuleInfoVO addModulInfoVO) {
- Long moduleId = null;
- Boolean bac = false;
- if(addModulInfoVO.getId() == null){
- String userId = UserUtils.getCurrentPrincipleID();
- Date now = DateUtil.now();
- ModuleInfo moduleInfo = new ModuleInfo();
- BeanUtil.copyProperties(addModulInfoVO, moduleInfo);
- moduleInfo.setCreator(userId);
- moduleInfo.setModifier(userId);
- moduleInfo.setGmtCreate(now);
- moduleInfo.setGmtModified(now);
- moduleInfo.setType(addModulInfoVO.getType());
- moduleInfo.setModuleType(addModulInfoVO.getModuleType());
- //当添加为科室专用模板时添加关联id
- if(addModulInfoVO.getModuleType().intValue() == 1){
- moduleInfo.setRelationId(addModulInfoVO.getRelationId());
- }
- this.save(moduleInfo);
- moduleId = moduleInfo.getId();
- bac = moduleDetailFacade.saveOrUpdateInfos(addModulInfoVO, moduleId);
- }else {
- UpdateModuleInfoVO updateModuleInfoVO = new UpdateModuleInfoVO();
- BeanUtil.copyProperties(addModulInfoVO,updateModuleInfoVO);
- bac = this.updateModuleInfo(updateModuleInfoVO);
- }
- return bac;
- }
- /**
- * 修改模板
- *
- * @param updateModuleInfoVO
- * @return
- */
- public Boolean updateModuleInfo(UpdateModuleInfoVO updateModuleInfoVO) {
- String userId = UserUtils.getCurrentPrincipleID();
- UpdateWrapper<ModuleInfo> moduleInfoUpdateWrapper = new UpdateWrapper<>();
- moduleInfoUpdateWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("id", updateModuleInfoVO.getId())
- .set("name", updateModuleInfoVO.getName())
- .set("type", updateModuleInfoVO.getType())
- .set("module_type",updateModuleInfoVO.getModuleType())
- .set("modifier", userId)
- .set("gmt_modified", DateUtil.now())
- .set("remark",updateModuleInfoVO.getRemark());
- if(updateModuleInfoVO.getRelationId() != null){
- moduleInfoUpdateWrapper.set("relation_id", updateModuleInfoVO.getRelationId());
- }
- this.update(new ModuleInfo(), moduleInfoUpdateWrapper);
- AddModuleInfoVO addModuleInfoVO = new AddModuleInfoVO();
- BeanUtil.copyProperties(updateModuleInfoVO, addModuleInfoVO);
- return moduleDetailFacade.saveOrUpdateInfos(addModuleInfoVO, updateModuleInfoVO.getId());
- }
- /**
- * 模板维护页面获取模板列表
- *
- * @param getModuleInfoVO
- * @return
- */
- public IPage<ModuleInfoListDTO> getModuleInfoList(GetModuleInfoVO getModuleInfoVO) {
- //获取模板信息
- IPage<ModuleInfoListDTO> moduleInfoDTOIPage = this.getModuleInfoListByType(getModuleInfoVO);
- List<String> ids = new ArrayList<>();
- List<Long> deptId = new ArrayList<>();
- for (ModuleInfoListDTO moduleInfoListDTO : moduleInfoDTOIPage.getRecords()) {
- ids.add(moduleInfoListDTO.getModifier());
- if(moduleInfoListDTO.getModuleType().intValue() == 1){
- deptId.add(moduleInfoListDTO.getRelationId());
- }
- }
- //获取科室名称
- ConceptTypeVO conceptTypeVO = new ConceptTypeVO();
- conceptTypeVO.setType(1);
- RespDTO<List<ConceptBaseDTO>> deptInfoList = knowledgemanServiceClient.getConceptListByType(conceptTypeVO);
- RespDTOUtil.respNGDeal(deptInfoList,"获取科室信息失败");
- Map<Long, ConceptBaseDTO> deptInfoMap = deptInfoList.data.stream().collect(Collectors.toMap(ConceptBaseDTO::getConceptId,conceptBaseDTO -> conceptBaseDTO));
- //获取模板类型名称
- QueryWrapper<DictionaryInfo> dictionaryInfoQueryWrapper = new QueryWrapper<>();
- dictionaryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("group_type", 1)
- .eq("return_type", 1)
- .orderByDesc("order_no");
- List<DictionaryInfo> dictionaryInfoList = dictionaryFacade.list(dictionaryInfoQueryWrapper);
- Map<String, DictionaryInfo> dictionaryInfoMap = dictionaryInfoList.stream().collect(Collectors.toMap(DictionaryInfo::getVal,dictionaryInfo -> dictionaryInfo));
- if(ListUtil.isNotEmpty(moduleInfoDTOIPage.getRecords())){
- //获取用户信息
- RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(ids);
- RespDTOUtil.respNGDeal(respDTO,"获取用户信息失败");
- //将用户信息放入实体
- for (ModuleInfoListDTO moduleInfoListDTO : moduleInfoDTOIPage.getRecords()) {
- moduleInfoListDTO.setUserName(respDTO.data.get(moduleInfoListDTO.getModifier()));
- if(null != dictionaryInfoMap.get(moduleInfoListDTO.getType())){
- moduleInfoListDTO.setAscriptionName(dictionaryInfoMap.get(moduleInfoListDTO.getType()).getName());
- }
- if(moduleInfoListDTO.getModuleType().intValue() == 1){//根据科室
- if(moduleInfoListDTO.getRelationId().intValue() != -1){//判断是不是科室通用子模板
- if(null != deptInfoMap.get(moduleInfoListDTO.getRelationId())){
- moduleInfoListDTO.setRelationName(deptInfoMap.get(moduleInfoListDTO.getRelationId()).getName());
- }
- }else {
- moduleInfoListDTO.setRelationName(ModuleInfoTypeEnum.Common.getName());
- }
- }
- moduleInfoListDTO.setModuleTypeName(ModuleInfoTypeEnum.getName(moduleInfoListDTO.getModuleType().intValue()));
- }
- }
- return moduleInfoDTOIPage;
- }
- /**
- * 模板维护页面获取模板列表
- *
- * @param getModuleInfoOneVO
- * @return
- */
- public GetModuleInfoOneDTO getModuleInfoOne(GetModuleInfoOneVO getModuleInfoOneVO) {
- GetModuleInfoOneDTO getModuleInfoOneDTO = new GetModuleInfoOneDTO();
- List<Long> deptId = new ArrayList<>();
- //获取模板信息
- QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
- moduleInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("id", getModuleInfoOneVO.getModuleId());
- ModuleInfo moduleInfo = this.getOne(moduleInfoQueryWrapper);
- if(null != moduleInfo){
- //获取模板类型名称
- if(moduleInfo.getModuleType().intValue() == 1){
- deptId.add(moduleInfo.getRelationId());
- }
- //获取科室名称
- ConceptTypeVO conceptTypeVO = new ConceptTypeVO();
- conceptTypeVO.setType(1);
- RespDTO<List<ConceptBaseDTO>> deptInfoList = knowledgemanServiceClient.getConceptListByType(conceptTypeVO);
- RespDTOUtil.respNGDeal(deptInfoList,"获取科室信息失败");
- Map<Long, ConceptBaseDTO> deptInfoMap = deptInfoList.data.stream().collect(Collectors.toMap(ConceptBaseDTO::getConceptId,conceptBaseDTO -> conceptBaseDTO));
- //获取模板类型
- BeanUtil.copyProperties(moduleInfo, getModuleInfoOneDTO);
- //获取模板类型名称
- QueryWrapper<DictionaryInfo> dictionaryInfoQueryWrapper = new QueryWrapper<>();
- dictionaryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("group_type", 1)
- .eq("return_type", 1)
- .orderByDesc("order_no");
- List<DictionaryInfo> dictionaryInfoList = dictionaryFacade.list(dictionaryInfoQueryWrapper);
- Map<String, DictionaryInfo> dictionaryInfoMap = dictionaryInfoList.stream().collect(Collectors.toMap(DictionaryInfo::getVal,dictionaryInfo -> dictionaryInfo));
- if (null != dictionaryInfoMap.get(getModuleInfoOneDTO.getType())) {
- getModuleInfoOneDTO.setAscriptionName(dictionaryInfoMap.get(getModuleInfoOneDTO.getType()).getName());
- }
- getModuleInfoOneDTO.setModuleTypeName(ModuleInfoTypeEnum.getName(getModuleInfoOneDTO.getModuleType().intValue()));
- if(getModuleInfoOneDTO.getModuleType().intValue() == 1){
- if(null != deptInfoMap.get(getModuleInfoOneDTO.getRelationId())){
- getModuleInfoOneDTO.setRelationName(deptInfoMap.get(getModuleInfoOneDTO.getRelationId()).getName());
- }
- }
- //获取模板明细
- List<GetModuleDetailInfoDTO> getModuleDetailInfoDTOList = new ArrayList<>();
- GetModuleDetailInfoDTO getModuleDetailInfoDTO = null;
- QueryWrapper<ModuleDetail> moduleDetailQueryWrapper = new QueryWrapper<>();
- moduleDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("module_id", getModuleInfoOneVO.getModuleId())
- .orderByAsc("order_no");
- List<ModuleDetail> moduleDetailList = moduleDetailFacade.list(moduleDetailQueryWrapper);
- List<Long> questionIdList = moduleDetailList.stream().map(moduleDetail -> moduleDetail.getQuestionId()).collect(Collectors.toList());
- List<Long> moduleIdList = moduleDetailList.stream().map(moduleDetail -> moduleDetail.getRelationModule()).collect(Collectors.toList());
- //获取标签信息
- QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
- questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .in("id", questionIdList);
- List<QuestionInfo> questionInfoList = questionFacade.list(questionInfoQueryWrapper);
- Map<Long, QuestionInfo> questionInfoMap = questionInfoList.stream().collect(Collectors.toMap(QuestionInfo::getId, questionInfo -> questionInfo));
- //获取模板信息
- QueryWrapper<ModuleInfo> getRelationModuleWapper = new QueryWrapper<>();
- questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .in("id", moduleIdList);
- List<ModuleInfo> moduleInfoList = this.list(getRelationModuleWapper);
- Map<Long, ModuleInfo> moduleInfoMap = moduleInfoList.stream().collect(Collectors.toMap(ModuleInfo::getId, m -> moduleInfo));
- //循环给出参赋值
- for (ModuleDetail moduleDetail : moduleDetailList) {
- getModuleDetailInfoDTO = new GetModuleDetailInfoDTO();
- BeanUtil.copyProperties(moduleDetail, getModuleDetailInfoDTO);
- if (moduleDetail.getQuestionId() != null) {
- getModuleDetailInfoDTO.setTagName(questionInfoMap.get(moduleDetail.getQuestionId()).getTagName());
- getModuleDetailInfoDTO.setTagType(questionInfoMap.get(moduleDetail.getQuestionId()).getTagType());
- } else {
- getModuleDetailInfoDTO.setRelationModuleName(moduleInfoMap.get(moduleDetail.getRelationModule()).getName());
- }
- getModuleDetailInfoDTOList.add(getModuleDetailInfoDTO);
- }
- getModuleInfoOneDTO.setModuleDetail(getModuleDetailInfoDTOList);
- }
- return getModuleInfoOneDTO;
- }
- /**
- * 获取模板类型(从症状情况到补充内容)
- *
- * @param getModuleTypeVO
- * @return
- */
- public List<GetModuleTypeDTO> getModuleType(GetModuleTypeVO getModuleTypeVO){
- QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
- moduleInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("module_Type", getModuleTypeVO.getModuleType());
- if(getModuleTypeVO.getRelationId() != null){
- moduleInfoQueryWrapper.eq("relation_id", getModuleTypeVO.getRelationId());
- }
- List<ModuleInfo> moduleInfos = this.list(moduleInfoQueryWrapper);
- List<String> types = moduleInfos.stream().map(moduleInfo -> moduleInfo.getType()).collect(Collectors.toList());
- //获取模板类型
- QueryWrapper<DictionaryInfo> dictionaryInfoQueryWrapper = new QueryWrapper<>();
- dictionaryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("group_type", 1)
- .eq("return_type", 1)
- .orderByAsc("order_no")
- .notIn("val",types);
- List<DictionaryInfo> dictionaryInfoList = dictionaryFacade.list(dictionaryInfoQueryWrapper);
- List<GetModuleTypeDTO> getModuleTypeDTOS = new ArrayList<>();
- for (DictionaryInfo dictionaryInfo : dictionaryInfoList) {
- GetModuleTypeDTO getModuleTypeDTO = new GetModuleTypeDTO();
- getModuleTypeDTO.setName(dictionaryInfo.getName());
- getModuleTypeDTO.setVal(dictionaryInfo.getVal());
- getModuleTypeDTOS.add(getModuleTypeDTO);
- }
- return getModuleTypeDTOS;
- }
- /**
- * 获取所有的科室和疾病信息
- *
- * @return
- */
- public GetAllDeptAndDisInfoDTO getAllDeptAndDisInfo(GetAllDeptAndDisInfoVO getAllDeptAndDisInfoVO){
- //获取所有科室
- ConceptTypeVO deptType = new ConceptTypeVO();
- deptType.setType(1);
- RespDTO<List<ConceptBaseDTO>> deptInfoList = knowledgemanServiceClient.getConceptListByType(deptType);
- RespDTOUtil.respNGDeal(deptInfoList,"获取科室信息失败");
- if(getAllDeptAndDisInfoVO.getModuleType() != null && getAllDeptAndDisInfoVO.getModuleType().intValue() == 1){//过滤添加过得科室
- List<ModuleInfo> moduleInfoList = getModuleInfos(getAllDeptAndDisInfoVO.getModuleType(),getAllDeptAndDisInfoVO.getType());
- List<Long> deptIds = moduleInfoList.stream().map(ModuleInfo::getRelationId).collect(Collectors.toList());
- Iterator<ConceptBaseDTO> deptIterator = deptInfoList.data.iterator();
- for (Long deptId : deptIds) {
- while (deptIterator.hasNext()){
- Long deptConceptId = deptIterator.next().getConceptId();
- if(deptId.intValue() == deptConceptId.intValue()){
- deptIterator.remove();
- }
- }
- }
- }
- List<DeptDTO> deptDTOS = BeanUtil.listCopyTo(deptInfoList.data,DeptDTO.class);
- GetAllDeptAndDisInfoDTO getAllDeptAndDisInfoDTO = new GetAllDeptAndDisInfoDTO();
- getAllDeptAndDisInfoDTO.setDeptDTOS(deptDTOS);
- return getAllDeptAndDisInfoDTO;
- }
- /**
- * 获取模板信息
- *
- * @param moduleType
- * @param type
- * @return
- */
- public List<ModuleInfo> getModuleInfos(Long moduleType,String type){
- QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
- moduleInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
- .eq("module_type",moduleType)
- .eq("type",type);
- return this.list(moduleInfoQueryWrapper);
- }
- }
|