1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444 |
- package com.diagbot.facade;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.diagbot.client.ICSSManServiceClient;
- import com.diagbot.client.UserServiceClient;
- import com.diagbot.dto.ConceptBaseDTO;
- import com.diagbot.dto.ConceptRes;
- import com.diagbot.dto.GetAllConceptDTO;
- import com.diagbot.dto.GetAllForRelationDTO;
- import com.diagbot.dto.GetAllInformationDTO;
- import com.diagbot.dto.GetAllLisConceptDTO;
- import com.diagbot.dto.GetConceptInfoDTO;
- import com.diagbot.dto.GetConceptInfoDetailDTO;
- import com.diagbot.dto.RespDTO;
- import com.diagbot.entity.Concept;
- import com.diagbot.entity.ConceptCommon;
- import com.diagbot.entity.Lexicon;
- import com.diagbot.entity.LibraryInfo;
- import com.diagbot.entity.QuestionInfo;
- import com.diagbot.entity.Relation;
- import com.diagbot.entity.wrapper.ConceptWrapper;
- import com.diagbot.enums.IsDeleteEnum;
- import com.diagbot.enums.LexiconRSTypeEnum;
- import com.diagbot.enums.LexiconTypeEnum;
- import com.diagbot.exception.CommonErrorCode;
- import com.diagbot.exception.CommonException;
- import com.diagbot.service.ConceptCommonService;
- import com.diagbot.service.ConceptService;
- import com.diagbot.service.LibraryInfoService;
- import com.diagbot.service.impl.ConceptServiceImpl;
- import com.diagbot.util.BeanUtil;
- import com.diagbot.util.Cn2SpellUtil;
- import com.diagbot.util.DateUtil;
- import com.diagbot.util.EntityUtil;
- import com.diagbot.util.IntegerUtil;
- import com.diagbot.util.ListUtil;
- import com.diagbot.util.ParamConvertUtil;
- import com.diagbot.util.RespDTOUtil;
- import com.diagbot.util.SqlExecuteUtil;
- import com.diagbot.util.StringUtil;
- import com.diagbot.util.UserUtils;
- import com.diagbot.vo.AddConceptInfoDetailVO;
- import com.diagbot.vo.AddConceptInfoVO;
- import com.diagbot.vo.ConceptExistVO;
- import com.diagbot.vo.ConceptSearchVO;
- import com.diagbot.vo.ConceptTypeVO;
- import com.diagbot.vo.GetAllConceptVO;
- import com.diagbot.vo.GetAllForRelationVO;
- import com.diagbot.vo.GetAllInformationVO;
- import com.diagbot.vo.GetAllLisConceptVO;
- import com.diagbot.vo.GetConceptInfoDetailVO;
- import com.diagbot.vo.GetConceptPacInfosVO;
- import com.diagbot.vo.IdListVO;
- import com.diagbot.vo.IndexLexiconVO;
- import com.diagbot.vo.IndexVO;
- import com.diagbot.vo.KLQuestionVO;
- import com.diagbot.vo.RemoveConceptInfoVO;
- import com.google.common.collect.Lists;
- import org.apache.commons.lang.time.DateFormatUtils;
- import org.apache.poi.hssf.usermodel.HSSFDateUtil;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Component;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.InputStream;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * @Description: 术语查询业务层
- * @author: Weixuan Huang
- * @time: 2019/1/14 16:17
- */
- @Component
- public class ConceptFacade extends ConceptServiceImpl {
- @Autowired
- private LibraryInfoFacade libraryinfoFacade;
- @Autowired
- private RelationFacade relationFacade;
- @Autowired
- @Qualifier("libraryInfoServiceImpl")
- private LibraryInfoService libraryInfoService;
- @Autowired
- @Qualifier("conceptServiceImpl")
- private ConceptService conceptService;
- @Autowired
- @Qualifier("conceptCommonServiceImpl")
- private ConceptCommonService conceptCommonService;
- @Autowired
- private UserServiceClient userServiceClient;
- @Autowired
- private LexiconFacade lexiconFacade;
- @Autowired
- private ConceptCommonFacade conceptCommonFacade;
- @Autowired
- private LisMappingFacade lisMappingFacade;
- @Autowired
- private ICSSManServiceClient icssManServiceClient;
- /**
- * 获取所有化验公表项
- *
- * @param getAllLisConceptVO
- * @return
- */
- public List<GetAllLisConceptDTO> getAllLisConcept(GetAllLisConceptVO getAllLisConceptVO) {
- List<GetAllLisConceptDTO> getAllLisConceptDTOList = new ArrayList<>();
- QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
- conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
- conceptQe.eq("lib_type", LexiconTypeEnum.LIS_TABLES.getKey());
- conceptQe.like(StringUtil.isNotEmpty(getAllLisConceptVO.getConceptName()), "lib_name", getAllLisConceptVO.getConceptName());
- List<Concept> conceptList = list(conceptQe);
- conceptList.forEach(i -> {
- if (getAllLisConceptVO.getExcludedConceptNames() != null
- && getAllLisConceptVO.getExcludedConceptNames().contains(i.getLibName())) {
- return;
- }
- GetAllLisConceptDTO getAllLisConceptDTO = new GetAllLisConceptDTO();
- getAllLisConceptDTO.setConceptId(i.getId());
- getAllLisConceptDTO.setConceptName(i.getLibName());
- getAllLisConceptDTOList.add(getAllLisConceptDTO);
- });
- //return this.baseMapper.getAllLisConcept(getAllLisConceptVO);
- return getAllLisConceptDTOList;
- }
- /**
- * 获取所有医学术语命名
- *
- * @param getAllConceptVO
- * @return
- */
- public List<GetAllConceptDTO> getAllConcept(GetAllConceptVO getAllConceptVO) {
- List<GetAllConceptDTO> getAllConceptDTOList = Lists.newArrayList();
- if (StringUtil.isBlank(getAllConceptVO.getName())) {
- return getAllConceptDTOList;
- }
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<LibraryInfo>();
- libraryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
- libraryInfoQe.eq(getAllConceptVO.getIsConcept() != null, "is_concept", getAllConceptVO.getIsConcept());
- libraryInfoQe.like("name", getAllConceptVO.getName());
- List<LibraryInfo> libraryInfoList = libraryinfoFacade.list(libraryInfoQe);
- //过滤掉非概念术语
- if (getAllConceptVO.getIsConcept() != null && getAllConceptVO.getIsConcept() == 1) {
- QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
- conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
- conceptQe.in("id", libraryInfoList.stream().map(i -> i.getConceptId()).distinct().collect(Collectors.toList()));
- Map<Long, Concept> conceptMap = list(conceptQe).stream().collect(Collectors.toMap(Concept::getId, i -> i));
- libraryInfoList.forEach(i -> {
- if (conceptMap.get(i.getConceptId()) == null || conceptMap.get(i.getConceptId()).getLibId().intValue() != i.getId().intValue()
- || (getAllConceptVO.getExcludedConceptIds() != null && getAllConceptVO.getExcludedConceptIds().contains(i.getConceptId()))) {
- i.setIsDeleted(IsDeleteEnum.Y.getKey());
- }
- });
- libraryInfoList = libraryInfoList.stream().filter(i -> i.getIsDeleted().equals(IsDeleteEnum.N.getKey())).collect(Collectors.toList());
- }
-
- /*//添加过术语医学属性的过滤掉
- if (getAllConceptVO.getIsMedical() != null && getAllConceptVO.getIsMedical() == 1) {
- QueryWrapper<Medical> medicalQe = new QueryWrapper<>();
- medicalQe.eq("is_deleted", "N");
- medicalQe.in("concept_id", libraryInfoList.stream().map(i -> i.getConceptId()).collect(Collectors.toList()));
- Map<Long, Medical> medicalMap = medicalFacade.list(medicalQe).stream().collect(Collectors.toMap(Medical::getConceptId, i -> i));
- libraryInfoList = libraryInfoList.stream().filter(i -> {
- if (medicalMap.get(i.getConceptId()) == null) {
- return true;
- } else {
- return false;
- }
- }).collect(Collectors.toList());
- }*/
- getAllConceptDTOList = BeanUtil.listCopyTo(libraryInfoList, GetAllConceptDTO.class);
- getAllConceptDTOList.forEach(i -> {
- i.setType(LexiconTypeEnum.getName(i.getTypeId().intValue()));
- i.setNameAndType(i.getName() + "(" + i.getType() + ")");
- });
- return getAllConceptDTOList;
- }
- /**
- * 获取所有概念(术语关系维护时筛选使用)
- *
- * @param getAllForRelationVO
- * @return
- */
- public List<GetAllForRelationDTO> getAllForRelation(GetAllForRelationVO getAllForRelationVO) {
- List<GetAllForRelationDTO> retList = Lists.newArrayList();
- if(StringUtil.isNotBlank(getAllForRelationVO.getName())||getAllForRelationVO.getTypeId()!=null){
- QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
- conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
- conceptQe.like(StringUtil.isNotBlank(getAllForRelationVO.getName()),"lib_name", getAllForRelationVO.getName());
- conceptQe.eq(getAllForRelationVO.getTypeId()!=null,"lib_type", getAllForRelationVO.getTypeId());
- List<Concept> conceptList = list(conceptQe);
- if(ListUtil.isNotEmpty(conceptList)){
- Map<Long, Long> reCouMap = new HashMap<>();
- if (getAllForRelationVO.getRelationPosition() != 3) {
- if (getAllForRelationVO.getRelationId() == null) {
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "关系类型id必传!");
- }
- List<Long> conceptIdList = conceptList.stream().map(i -> i.getId()).collect(Collectors.toList());
- QueryWrapper<Relation> relationQe = new QueryWrapper<>();
- relationQe.eq("relation_id", getAllForRelationVO.getRelationId());
- List<Long> relationConceptIdList = Lists.newArrayList();
- if(getAllForRelationVO.getRelationTypeId() != null){
- QueryWrapper<Concept> conceptQe1 = new QueryWrapper<>();
- conceptQe1.eq("lib_type", getAllForRelationVO.getRelationTypeId());
- relationConceptIdList = list(conceptQe1).stream().map(i->i.getId()).collect(Collectors.toList());
- }
- if(getAllForRelationVO.getRelationConceptId() != null){
- relationConceptIdList.add(getAllForRelationVO.getRelationConceptId());
- }
- if(ListUtil.isNotEmpty(relationConceptIdList)){
- if (getAllForRelationVO.getRelationPosition() == 1) {
- relationQe.in("start_id", conceptIdList);
- relationQe.in("end_id", relationConceptIdList);
- reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getStartId, Collectors.counting()));
- }else{
- relationQe.in("end_id", conceptIdList);
- relationQe.in("start_id", relationConceptIdList);
- reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getEndId, Collectors.counting()));
- }
- }
- }
- for (Concept i : conceptList) {
- if (reCouMap.get(i.getId()) != null
- || (getAllForRelationVO.getExcludedConceptIds() != null && getAllForRelationVO.getExcludedConceptIds().contains(i.getId()))
- || (getAllForRelationVO.getRelationConceptId() != null && getAllForRelationVO.getRelationConceptId() == i.getId())) {
- continue;
- }
- GetAllForRelationDTO getAllForRelationDTO = new GetAllForRelationDTO();
- getAllForRelationDTO.setConceptId(i.getId());
- getAllForRelationDTO.setConceptName(i.getLibName());
- getAllForRelationDTO.setConceptNameType(i.getLibName()+"("+LexiconTypeEnum.getName(i.getLibType().intValue())+")");
- retList.add(getAllForRelationDTO);
- }
- }
- }
- return retList;
- }
- /**
- * 获取医学术语命名列表
- *
- * @param getAllInformationVO
- * @return
- */
- public IPage<GetAllInformationDTO> getAllInformation(GetAllInformationVO getAllInformationVO) {
- Page<GetAllInformationDTO> getAllInformationDTOPage = new Page<>();
- Page<Concept> conceptPage = new Page<>(getAllInformationVO.getCurrent(), getAllInformationVO.getSize());
- QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
- if (StringUtil.isNotBlank(getAllInformationVO.getLibName())) {
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
- libraryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
- libraryInfoQe.like("name", getAllInformationVO.getLibName());
- libraryInfoQe.eq(StringUtil.isNotBlank(getAllInformationVO.getType()), "type_id", LexiconTypeEnum.getKey(getAllInformationVO.getType()));
- List<Long> conceptIdList = libraryinfoFacade.list(libraryInfoQe).stream().map(i -> i.getConceptId()).distinct().collect(Collectors.toList());
- if (ListUtil.isNotEmpty(conceptIdList)) {
- conceptQe.in("id", conceptIdList);
- } else {
- conceptQe.eq("id", -999999999);
- }
- }
- conceptQe.like(StringUtil.isNotBlank(getAllInformationVO.getName()), "lib_name", getAllInformationVO.getName());
- conceptQe.eq(StringUtil.isNotBlank(getAllInformationVO.getType()), "lib_type", LexiconTypeEnum.getKey(getAllInformationVO.getType()));
- conceptQe.eq(StringUtil.isNotBlank(getAllInformationVO.getIsDeleted()), "is_deleted", getAllInformationVO.getIsDeleted());
- conceptQe.orderByDesc("sort_deleted");
- conceptQe.orderByDesc("gmt_modified");
- conceptQe.orderByDesc("id");
- IPage<Concept> iPage = this.page(conceptPage, conceptQe);
- BeanUtil.copyProperties(iPage, getAllInformationDTOPage);
- if (ListUtil.isNotEmpty(iPage.getRecords())) {
- List<GetAllInformationDTO> getAllInformationDTOList = Lists.newArrayList();
- List<Long> conceptIds = iPage.getRecords().stream().map(i -> i.getId()).collect(Collectors.toList());
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
- libraryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
- libraryInfoQe.in("concept_id", conceptIds);
- Map<Long, List<LibraryInfo>> libraryInfoListMap = libraryinfoFacade.list(libraryInfoQe).stream().collect(Collectors.groupingBy(LibraryInfo::getConceptId));
- List<String> userIds = iPage.getRecords().stream().map(i -> i.getModifier()).distinct().collect(Collectors.toList());
- RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(userIds);
- RespDTOUtil.respNGDealCover(respDTO, "获取用户信息失败");
- iPage.getRecords().forEach(i -> {
- GetAllInformationDTO getAllInformationDTO = new GetAllInformationDTO();
- getAllInformationDTO.setConceptId(i.getId());
- getAllInformationDTO.setLibName(i.getLibName());
- getAllInformationDTO.setLibType(LexiconTypeEnum.getName(i.getLibType().intValue()));
- getAllInformationDTO.setIsDeleted(i.getIsDeleted());
- getAllInformationDTO.setOperName(respDTO.data.get(i.getModifier()));
- getAllInformationDTO.setOperTime(i.getGmtModified());
- if (libraryInfoListMap.get(i.getId()) != null) {
- getAllInformationDTO.setOtherNames(libraryInfoListMap.get(i.getId()).stream().sorted((a, b) -> b.getIsConcept() - a.getIsConcept()).map(k -> k.getName()).collect(Collectors.joining("、")));
- }
- getAllInformationDTOList.add(getAllInformationDTO);
- });
- getAllInformationDTOPage.setRecords(getAllInformationDTOList);
- }
- return getAllInformationDTOPage;
- }
- /**
- * 医学术语命名删除或者恢复
- *
- * @param removeConceptInfoVO
- * @return
- */
- public Boolean removeConceptInfo(RemoveConceptInfoVO removeConceptInfoVO) {
- /*StringBuffer sbf = new StringBuffer();
-
- QueryWrapper<Medical> medicalQe = new QueryWrapper<Medical>();
- medicalQe.eq("is_deleted", "N");
- medicalQe.eq("concept_id", removeConceptInfoVO.getConceptId());
- if(medicalFacade.list(medicalQe).size()>0){
- sbf.append("请先解除医学属性关联 ");
- }
-
- QueryWrapper<Relation> relationQe = new QueryWrapper<Relation>();
- relationQe.eq("is_deleted", "N");
- relationQe.and(i->i.eq("start_id", removeConceptInfoVO.getConceptId()).or().eq("end_id", removeConceptInfoVO.getConceptId()));
- if(relationFacade.list(relationQe).size()>0){
- sbf.append("请先解除术语关系关联 ");
- }
-
- QueryWrapper<ConceptDetail> libraryDetailQe = new QueryWrapper<ConceptDetail>();
- libraryDetailQe.eq("is_deleted", "N");
- libraryDetailQe.eq("concept_id", removeConceptInfoVO.getConceptId());
- if(libraryDetailFacade.list(libraryDetailQe).size()>0){
- sbf.append("请先解除医学静态知识关联 ");
- }
-
- if(sbf.length()>0){
- throw new CommonException(CommonErrorCode.RPC_ERROR,sbf.toString());
- }*/
- String currentUser = UserUtils.getCurrentPrincipleID();
- Date now = DateUtil.now();
-
- /*QueryWrapper<LibraryInfo> libraryInfoQe1 = new QueryWrapper<>();
- libraryInfoQe1.eq("concept_id", removeConceptInfoVO.getConceptId());
- libraryInfoQe1.eq("is_concept", 0);
- libraryinfoFacade.remove(libraryInfoQe1);
-
- QueryWrapper<LibraryInfo> libraryInfoQe2 = new QueryWrapper<>();
- libraryInfoQe2.eq("concept_id", removeConceptInfoVO.getConceptId());
- LibraryInfo libraryInfo = new LibraryInfo();
- libraryInfo.setIsDeleted("Y");
- libraryInfo.setGmtModified(now);
- libraryInfo.setModifier(currentUser);
- libraryinfoFacade.update(libraryInfo, libraryInfoQe2);*/
-
- /*Concept concept = new Concept();
- concept.setId(removeConceptInfoVO.getConceptId());
- concept.setIsDeleted("Y");
- concept.setModifier(currentUser);
- concept.setGmtModified(now);
- this.updateById(concept);*/
- Concept concept = this.getById(removeConceptInfoVO.getConceptId());
- if (concept == null) {
- throw new CommonException(CommonErrorCode.NOT_EXISTS);
- }
- if (concept.getIsDeleted().equals(removeConceptInfoVO.getIsDeleted())) {
- if (removeConceptInfoVO.getIsDeleted().equals(IsDeleteEnum.Y.getKey())) {
- throw new CommonException(CommonErrorCode.NOT_EXISTS, "该数据已删除!");
- }
- if (removeConceptInfoVO.getIsDeleted().equals(IsDeleteEnum.N.getKey())) {
- throw new CommonException(CommonErrorCode.IS_EXISTS, "该数据已恢复!");
- }
- }
- //清理缓存
- this.cacheClearByConceptId(concept.getId());
- concept.setIsDeleted(removeConceptInfoVO.getIsDeleted());
- concept.setModifier(currentUser);
- concept.setGmtModified(now);
- this.updateById(concept);
- return true;
- }
- /**
- * 获取医学术语命名详情
- *
- * @param getConceptInfoDetailVO
- * @return libName-标准术语,otherNames-同义词
- */
- public GetConceptInfoDTO getConceptInfoDetail(GetConceptInfoDetailVO getConceptInfoDetailVO) {
- GetConceptInfoDTO getConceptInfoDTO = new GetConceptInfoDTO();
- Concept concept = this.getById(getConceptInfoDetailVO.getConceptId());
- if (concept == null) {
- throw new CommonException(CommonErrorCode.NOT_EXISTS);
- }
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<LibraryInfo>();
- libraryInfoQe.eq("concept_id", getConceptInfoDetailVO.getConceptId());
- List<GetConceptInfoDetailDTO> getConceptInfoDetailDTOList = BeanUtil.listCopyTo(libraryinfoFacade.list(libraryInfoQe), GetConceptInfoDetailDTO.class);
- getConceptInfoDetailDTOList.forEach(i -> {
- i.setType(LexiconTypeEnum.getName(i.getTypeId().intValue()));
- });
- getConceptInfoDTO.setLibName(getConceptInfoDetailDTOList.stream().filter(i -> i.getIsConcept() != null && i.getIsConcept() == 1).collect(Collectors.toList()));
- getConceptInfoDTO.setOtherNames(getConceptInfoDetailDTOList.stream().filter(i -> i.getIsConcept() == null || i.getIsConcept() == 0).collect(Collectors.toList()));
- Integer isHasCommon = lexiconFacade.getById(concept.getLibType()).getIsHasCommon();
- getConceptInfoDTO.setIsHasCommon(isHasCommon);
- if (isHasCommon == 1) {
- QueryWrapper<ConceptCommon> conceptCommonQe = new QueryWrapper<>();
- conceptCommonQe.eq("concept_id", getConceptInfoDetailVO.getConceptId());
- ConceptCommon conceptCommon = conceptCommonFacade.getOne(conceptCommonQe);
- if (conceptCommon != null) {
- getConceptInfoDTO.setSexType(conceptCommon.getSexType());
- getConceptInfoDTO.setMinAge(conceptCommon.getMinAge());
- getConceptInfoDTO.setMaxAge(conceptCommon.getMaxAge());
- }
- }
- return getConceptInfoDTO;
- }
- /**
- * 医学术语命名添加或者编辑
- *
- * @param addConceptInfoVO
- * @return
- */
- public Boolean addConceptInfo(AddConceptInfoVO addConceptInfoVO) {
- String lineNumStr = "";
- if (addConceptInfoVO.getLineNum() != null) {
- lineNumStr = "第" + addConceptInfoVO.getLineNum() + "行";
- }
- //String regEx = "[0-9]+|[`~·!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]+";
- String regEx = "[0-9]+";
- for (AddConceptInfoDetailVO i : addConceptInfoVO.getDetailList()) {
- if (i.getName().matches(regEx)) {
- //throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "无法输入纯数字或者纯字符,请输入正确数据!");
- throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "无法输入纯数字,请输入正确数据!");
- }
- }
- if (addConceptInfoVO.getMaxAge() < addConceptInfoVO.getMinAge()) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "症状发生的最小年龄大于症状发生的最大年龄!");
- }
- if (addConceptInfoVO.getDetailList().stream().distinct().count() != addConceptInfoVO.getDetailList().size()) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "存在重复数据!");
- }
- List<AddConceptInfoDetailVO> addConceptInfoDetailVOMainList = addConceptInfoVO.getDetailList().stream().filter(i -> i.getIsConcept() == 1).collect(Collectors.toList());
- if (addConceptInfoDetailVOMainList.size() == 0) {
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, lineNumStr + "无标准术语!");
- }
- if (addConceptInfoDetailVOMainList.size() > 1) {
- throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, lineNumStr + "标准术语只能有一个!");
- }
- QueryWrapper<Lexicon> lexiconQe = new QueryWrapper<>();
- lexiconQe.eq("name", addConceptInfoVO.getType());
- Lexicon lexicon = lexiconFacade.getOne(lexiconQe);
- if (lexicon == null) {
- throw new CommonException(CommonErrorCode.NOT_EXISTS, lineNumStr + "数据有误,该类型信息在数据库中不存在!");
- }
- List<LibraryInfo> saveOrUpdateLibraryInfoList = new ArrayList<>();
- AddConceptInfoDetailVO addConceptInfoDetailVOMain = addConceptInfoDetailVOMainList.get(0);//提交过来的标准术语
- //查询当前添加的术语是否已经在数据库中
- QueryWrapper<LibraryInfo> libraryInfoQe1 = new QueryWrapper<>();
- libraryInfoQe1.eq("type_id", lexicon.getId());
- libraryInfoQe1.in("name", addConceptInfoVO.getDetailList().stream().map(i -> i.getName()).collect(Collectors.toList()));
- List<LibraryInfo> libraryInfoList = libraryinfoFacade.list(libraryInfoQe1);
- String currentUser = UserUtils.getCurrentPrincipleID();
- Date now = DateUtil.now();
- Map<String, LibraryInfo> libraryInfoMap = libraryInfoList.stream().collect(Collectors.toMap(LibraryInfo::getName, i -> i));
- LibraryInfo libraryInfoMain = libraryInfoMap.get(addConceptInfoDetailVOMain.getName());
- Concept concept = new Concept();
- Long conceptId = null;
- if (libraryInfoMain == null) {
- libraryInfoMain = new LibraryInfo();
- BeanUtil.copyProperties(addConceptInfoDetailVOMain, libraryInfoMain);
- libraryInfoMain.setGmtCreate(now);
- libraryInfoMain.setCreator(currentUser);
- libraryInfoMain.setTypeId(lexicon.getId());
- libraryinfoFacade.save(libraryInfoMain);
- concept.setLibId(libraryInfoMain.getId());
- concept.setLibName(addConceptInfoDetailVOMain.getName());
- concept.setLibType(lexicon.getId());
- concept.setGmtCreate(now);
- concept.setCreator(currentUser);
- concept.setId(addConceptInfoVO.getConceptId());
- saveOrUpdate(concept);
- conceptId = concept.getId();
- } else {
- conceptId = libraryInfoMain.getConceptId();
- int ckConceptId = conceptId.intValue();
- concept = getById(conceptId);
- //如果标准词之前作为同义词被其他占用的情况
- if (libraryInfoMain.getIsConcept() == 1) {
- //新增操作时,已经建立的标准词提示
- if (addConceptInfoVO.getLineNum() == null && addConceptInfoVO.getConceptId() == null) {
- if (concept.getIsDeleted().equals("N")) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, "该数据已经建立!");
- } else {
- throw new CommonException(CommonErrorCode.RPC_ERROR, "该数据已经建立且处于已删除状态,可前往列表中恢复该条数据!");
- }
- } else if (addConceptInfoVO.getConceptId().intValue() != ckConceptId) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "标准术语已被占用!");
- }
- } else if (addConceptInfoVO.getLineNum() == null && addConceptInfoVO.getConceptId() == null && concept != null
- || libraryInfoList.stream().filter(i -> i.getConceptId().intValue() == ckConceptId).count() == 1) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "标准术语已作为同义词被占用!");
- }
- }
- //先删除概念下的同义词,后续再插入
- QueryWrapper<LibraryInfo> libraryInfoQe2 = new QueryWrapper<>();
- libraryInfoQe2.eq("concept_id", conceptId);
- libraryInfoQe2.ne("id", libraryInfoMain.getId());
- libraryinfoFacade.remove(libraryInfoQe2);
- StringBuffer sbf = new StringBuffer();
- for (AddConceptInfoDetailVO i : addConceptInfoVO.getDetailList()) {
- if (i.getIsConcept() == 1) {
- continue;
- }
- LibraryInfo libraryInfo = libraryInfoMap.get(i.getName());
- if (libraryInfo == null) {
- libraryInfo = new LibraryInfo();
- libraryInfo.setGmtCreate(now);
- libraryInfo.setCreator(currentUser);
- } else if (libraryInfo.getConceptId().intValue() != conceptId.intValue()) {
- sbf.append(i.getName()).append(" ");
- continue;
- }
- libraryInfo.setName(i.getName());
- libraryInfo.setSpell(i.getSpell());
- libraryInfo.setRemark(i.getRemark());
- saveOrUpdateLibraryInfoList.add(libraryInfo);
- }
- if (sbf.length() > 0) {
- sbf.append("已被占用");
- throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
- }
- for (LibraryInfo i : saveOrUpdateLibraryInfoList) {
- i.setId(null);
- i.setConceptId(conceptId);
- i.setTypeId(lexicon.getId());
- i.setIsConcept(0);
- i.setGmtModified(now);
- i.setModifier(currentUser);
- }
- libraryInfoMain.setIsConcept(1);
- libraryInfoMain.setRemark(addConceptInfoDetailVOMain.getRemark());
- libraryInfoMain.setSpell(addConceptInfoDetailVOMain.getSpell());
- libraryInfoMain.setConceptId(conceptId);
- libraryInfoMain.setGmtModified(now);
- libraryInfoMain.setModifier(currentUser);
- saveOrUpdateLibraryInfoList.add(libraryInfoMain);
- libraryInfoService.saveOrUpdateBatch(saveOrUpdateLibraryInfoList);
- //清理原名称对应标签缓存
- this.cacheClearByConceptId(conceptId);
- concept.setId(conceptId);
- concept.setLibId(libraryInfoMain.getId());
- concept.setLibName(libraryInfoMain.getName());
- concept.setLibType(libraryInfoMain.getTypeId());
- concept.setGmtModified(now);
- concept.setModifier(currentUser);
- updateById(concept);
- if (lexicon.getIsHasCommon() == 1) {
- QueryWrapper<ConceptCommon> conceptCommonQe = new QueryWrapper<>();
- conceptCommonQe.eq("concept_id", conceptId);
- ConceptCommon conceptCommon = conceptCommonFacade.getOne(conceptCommonQe);
- if (conceptCommon == null) {
- conceptCommon = new ConceptCommon();
- conceptCommon.setGmtCreate(now);
- conceptCommon.setCreator(currentUser);
- }
- BeanUtil.copyProperties(addConceptInfoVO, conceptCommon);
- conceptCommon.setConceptId(conceptId);
- conceptCommon.setGmtModified(now);
- conceptCommon.setModifier(currentUser);
- conceptCommonFacade.saveOrUpdate(conceptCommon);
- }
- return true;
- }
- /**
- * 医学术语命名excel文件导入
- *
- * @param file
- * @return
- */
- public Boolean conceptInfoExcelIm(MultipartFile file) {
- List<AddConceptInfoVO> addConceptInfoVOList = new ArrayList<>();
- StringBuffer sbf = new StringBuffer();
- InputStream inputStream = null;
- Workbook wb = null;
- try {
- if (!file.isEmpty()) {
- inputStream = file.getInputStream();
- if (inputStream.available() > 512000) {
- sbf.append("文件最大支持500KB!").append("<br/>");
- } else {
- String fileName = file.getOriginalFilename();
- if (fileName.lastIndexOf(".") != -1) {
- String type = fileName.substring(fileName.lastIndexOf("."));
- if (type.equals(".xls")) {
- wb = new HSSFWorkbook(inputStream);
- } else if (type.equals(".xlsx")) {
- wb = new XSSFWorkbook(inputStream);
- }
- if (wb != null) {
- Sheet sheet = wb.getSheetAt(0);
- int count = 0;
- String libName, libType, otherNames, remark, sexType, minAge, maxAge;
- //String regEx = "[0-9]+|[`~·!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]+";
- String regEx = "[0-9]+";
- String regExAge = "[0-9]|[1-9][0-9]|1[0-9]{2}|200";
- for (Row row : sheet) {
- count++;
- if (row == null) {
- continue;
- }
- // if (count == 1) {
- // title_1 = getValue(row.getCell(0)).trim().replace(" ", "");
- // title_2 = getValue(row.getCell(1)).trim().replace(" ", "");
- // title_3 = getValue(row.getCell(2)).trim().replace(" ", "");
- // title_4 = getValue(row.getCell(3)).trim().replace(" ", "");
- // continue;
- // }
- libName = getValue(row.getCell(0)).trim().replace(" ", "");
- libType = getValue(row.getCell(1)).trim().replace(" ", "");
- otherNames = getValue(row.getCell(2)).trim().replace(" ", "");
- remark = getValue(row.getCell(3)).trim().replace(" ", "");
- sexType = getValue(row.getCell(4)).trim().replace(" ", "");
- minAge = getValue(row.getCell(5)).trim().replace(" ", "");
- maxAge = getValue(row.getCell(6)).trim().replace(" ", "");
- if (count == 1) {
- //当前行是第一行时,libName、libType、otherNames、remark、sexType、minAge、maxAge是标题
- if (libName.indexOf("标准术语") == -1
- || libType.indexOf("类型") == -1
- || otherNames.indexOf("术语同义词") == -1
- || remark.indexOf("标准术语说明") == -1
- || sexType.indexOf("性别") == -1
- || minAge.indexOf("最小年龄") == -1
- || maxAge.indexOf("最大年龄") == -1) {
- sbf.append("导入数据不正确,请选择正确数据导入!").append("<br/>");
- break;
- } else {
- continue;
- }
- }
- if (StringUtil.isEmpty(libName) && StringUtil.isEmpty(libType)
- && StringUtil.isEmpty(otherNames) && StringUtil.isEmpty(remark)) {
- continue;
- }
- if (StringUtil.isEmpty(libName) || StringUtil.isEmpty(libType) || StringUtil.isEmpty(otherNames)) {
- sbf.append("第" + count + "行数据不完整;").append("<br/>");
- continue;
- }
- if (StringUtil.isNotEmpty(remark) && remark.length() > 120) {
- sbf.append("第" + count + "行导入错误,说明最大可输入120个字;").append("<br/>");
- continue;
- }
- if (StringUtil.isNotEmpty(sexType) && !sexType.matches("男|女|通用")) {
- sbf.append("第" + count + "行导入错误,性别须是男、女或者通用;").append("<br/>");
- }
- if ((StringUtil.isNotEmpty(minAge) && !minAge.matches(regExAge))
- || (StringUtil.isNotEmpty(maxAge) && !maxAge.matches(regExAge))) {
- sbf.append("第" + count + "行导入错误,年龄须是0-200;").append("<br/>");
- continue;
- }
- if (StringUtil.isNotEmpty(minAge)
- && StringUtil.isNotEmpty(maxAge)
- && Integer.parseInt(minAge) > Integer.parseInt(maxAge)) {
- sbf.append("第" + count + "行导入错误,症状发生的最小年龄大于症状发生的最大年龄;").append("<br/>");
- continue;
- }
- AddConceptInfoVO addConceptInfoVO = new AddConceptInfoVO();
- addConceptInfoVO.setLineNum(count);
- addConceptInfoVO.setName(libName);
- addConceptInfoVO.setType(libType);
- addConceptInfoVO.setMinAge(StringUtil.isEmpty(minAge) ? 0 : Integer.parseInt(minAge));
- addConceptInfoVO.setMaxAge(StringUtil.isEmpty(minAge) ? 200 : Integer.parseInt(maxAge));
- if (sexType.equals("男")) {
- addConceptInfoVO.setSexType(1);
- } else if (sexType.equals("女")) {
- addConceptInfoVO.setSexType(2);
- } else {
- addConceptInfoVO.setSexType(3);
- }
- List<AddConceptInfoDetailVO> detailList = new ArrayList<>();
- for (String nm : otherNames.split(",")) {
- if (StringUtil.isBlank(nm)) {
- continue;
- }
- if (nm.matches(regEx)) {
- sbf.append("第" + count + "行无法导入,导入数据无法为纯数字;").append("<br/>");
- break;
- }
- if (nm.length() > 30) {
- sbf.append("第" + count + "行导入错误,标准词和同义词最大字数不可超过30个字;").append("<br/>");
- break;
- }
- AddConceptInfoDetailVO addConceptInfoDetailVO = new AddConceptInfoDetailVO();
- addConceptInfoDetailVO.setName(nm);
- addConceptInfoDetailVO.setType(libType);
- addConceptInfoDetailVO.setSpell(Cn2SpellUtil.converterToFirstSpell(nm));
- if (libName.equals(nm)) {
- addConceptInfoDetailVO.setIsConcept(1);
- addConceptInfoDetailVO.setRemark(remark);
- } else {
- addConceptInfoDetailVO.setIsConcept(0);
- }
- detailList.add(addConceptInfoDetailVO);
- }
- addConceptInfoVO.setDetailList(detailList);
- addConceptInfoVOList.add(addConceptInfoVO);
- }
- } else {
- sbf.append("非excel文件无法解析!").append("<br/>");
- }
- } else {
- sbf.append("未知文件无法解析!").append("<br/>");
- }
- }
- } else {
- sbf.append("无文件上传!").append("<br/>");
- }
- } catch (Exception e) {
- sbf.append("解析失败!").append("<br/>");
- } finally {
- try {
- if (wb != null) {
- wb.close();
- }
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (Exception e) {
- }
- }
- /*****************excel文件本身问题提醒************************/
- if (sbf.length() > 0) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
- }
- // /**********************非规范的excel导入提醒*****************************************/
- // if (title_1.indexOf("标准术语") == -1
- // || title_2.indexOf("类型") == -1
- // || title_3.indexOf("术语同义词") == -1
- // || title_4.indexOf("标准术语说明") == -1) {
- // throw new CommonException(CommonErrorCode.RPC_ERROR, "导入数据不正确,请选择正确数据导入!");
- // }
- /****************************导入空文件************************/
- if (addConceptInfoVOList.size() == 0) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, "导入数据不能为空!");
- }
- if (addConceptInfoVOList.size() > 5000) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, "当前数据导入失败,单次导入最多可支持5千条数据导入");
- }
- /****************excel文件中所有术语存在重复提示---名字和类型一样即重复***********************/
- List<AddConceptInfoDetailVO> addConceptInfoDetailVOList = new ArrayList<>();
- addConceptInfoVOList.forEach(i -> {
- addConceptInfoDetailVOList.addAll(i.getDetailList());
- });
- Map<String, List<AddConceptInfoDetailVO>> addConceptInfoDetailVOListMap = addConceptInfoDetailVOList.stream().collect(Collectors.groupingBy(AddConceptInfoDetailVO::getName));
- for (String key : addConceptInfoDetailVOListMap.keySet()) {
- if (addConceptInfoDetailVOListMap.get(key).size() > 1 && addConceptInfoDetailVOListMap.get(key).stream().map(i -> i.getType()).distinct().count() == 1) {
- sbf.append(key).append(" ");
- }
- }
- if (sbf.length() > 0) {
- sbf.append("数据重复,请修改导入数据!");
- throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
- }
-
- /*
- * 原来的
- * addConceptInfoVOList.forEach(i -> {
- addConceptInfo(i);
- });*/
- ////优化后
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
- libraryInfoQe.in("name", addConceptInfoDetailVOList.stream().map(i -> i.getName()).distinct().collect(Collectors.toList()));
- Map<String, List<LibraryInfo>> libraryInfoListMap = libraryinfoFacade.list(libraryInfoQe).stream().collect(Collectors.groupingBy(LibraryInfo::getName));
- Map<String, Lexicon> lexiconMap = lexiconFacade.list().stream().collect(Collectors.toMap(Lexicon::getName, i -> i));
- String ckmsg = null;
- for (AddConceptInfoVO addConceptInfoVO : addConceptInfoVOList) {
- ckmsg = checkImConceptInfo(addConceptInfoVO, libraryInfoListMap, lexiconMap);
- if (StringUtil.isNotBlank(ckmsg)) {
- sbf.append("第").append(addConceptInfoVO.getLineNum()).append("行").append(ckmsg).append("<br/>");
- }
- }
- if (sbf.length() > 0) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
- }
- saveAddConceptInfoVOList(addConceptInfoVOList);
- return true;
- }
- /**
- * 导入数据插入更新前校验
- *
- * @param addConceptInfoVO
- * @param libraryInfoListAllMap
- * @param lexiconMap
- * @return
- */
- public String checkImConceptInfo(AddConceptInfoVO addConceptInfoVO, Map<String, List<LibraryInfo>> libraryInfoListAllMap, Map<String, Lexicon> lexiconMap) {
- String currentUser = UserUtils.getCurrentPrincipleID();
- Date now = DateUtil.now();
- Concept concept = new Concept();
- ConceptCommon conceptCommon = null;
- List<LibraryInfo> libraryInfoList = Lists.newArrayList();
- List<AddConceptInfoDetailVO> addConceptInfoDetailVOMainList = addConceptInfoVO.getDetailList().stream().filter(i -> i.getIsConcept() == 1).collect(Collectors.toList());
- if (addConceptInfoDetailVOMainList.size() == 0) {
- return "同义词中缺少标准词本体!";
- }
- if (addConceptInfoDetailVOMainList.size() > 1) {
- return "标准术语只能有一个!";
- }
- Lexicon lexicon = lexiconMap.get(addConceptInfoVO.getType());
- if (lexicon == null) {
- return "数据有误,该类型信息在数据库中不存在!";
- }
- Long typeId = lexicon.getId();
- concept.setLibType(typeId);
- concept.setGmtModified(now);
- concept.setModifier(currentUser);
- if (lexicon.getIsHasCommon() == 1) {
- conceptCommon = new ConceptCommon();
- conceptCommon.setSexType(addConceptInfoVO.getSexType());
- conceptCommon.setMinAge(addConceptInfoVO.getMinAge());
- conceptCommon.setMaxAge(addConceptInfoVO.getMaxAge());
- conceptCommon.setGmtModified(now);
- conceptCommon.setModifier(currentUser);
- }
- List<LibraryInfo> extLibraryInfoList = Lists.newArrayList();
- addConceptInfoVO.getDetailList().forEach(a -> {
- List<LibraryInfo> libraryInfoListAll = libraryInfoListAllMap.get(a.getName());
- if (ListUtil.isNotEmpty(libraryInfoListAll)) {
- libraryInfoListAll = libraryInfoListAll.stream().filter(b -> b.getTypeId().intValue() == typeId.intValue()).collect(Collectors.toList());
- if (ListUtil.isNotEmpty(libraryInfoListAll)) {
- extLibraryInfoList.add(libraryInfoListAll.get(0));
- }
- }
- });
- Map<String, LibraryInfo> extLibraryInfoMap = extLibraryInfoList.stream().collect(Collectors.toMap(LibraryInfo::getName, i -> i));
- LibraryInfo libraryInfoMain = extLibraryInfoMap.get(addConceptInfoDetailVOMainList.get(0).getName());
- Long conceptId = null;
- if (libraryInfoMain == null) {
- conceptId = -9999l;
- concept.setGmtCreate(now);
- concept.setCreator(currentUser);
- if (conceptCommon != null) {
- conceptCommon.setGmtCreate(now);
- conceptCommon.setCreator(currentUser);
- }
- } else {
- conceptId = libraryInfoMain.getConceptId();
- concept.setId(conceptId);
- addConceptInfoVO.setConceptId(conceptId);
- if (libraryInfoMain.getIsConcept() != 1 && extLibraryInfoList.stream().filter(i -> i.getConceptId().intValue() == libraryInfoMain.getConceptId().intValue()).count() == 1) {
- return "标准术语已作为同义词被占用!";
- }
- }
- StringBuffer sbf = new StringBuffer();
- for (AddConceptInfoDetailVO i : addConceptInfoVO.getDetailList()) {
- LibraryInfo libraryInfo = extLibraryInfoMap.get(i.getName());
- if (libraryInfo == null) {
- libraryInfo = new LibraryInfo();
- libraryInfo.setTypeId(typeId);
- libraryInfo.setGmtCreate(now);
- libraryInfo.setCreator(currentUser);
- } else if (libraryInfo.getConceptId().intValue() != conceptId.intValue()) {
- sbf.append(i.getName()).append(" ");
- continue;
- }
- BeanUtil.copyProperties(i, libraryInfo);
- libraryInfo.setId(null);
- libraryInfo.setConceptId(conceptId);
- libraryInfo.setGmtModified(now);
- libraryInfo.setModifier(currentUser);
- if (i.getIsConcept() == 1) {
- libraryInfoList.add(0, libraryInfo);
- } else {
- libraryInfoList.add(libraryInfo);
- }
- }
- if (sbf.length() > 0) {
- sbf.append("已被占用");
- return sbf.toString();
- }
- addConceptInfoVO.setConcept(concept);
- addConceptInfoVO.setConceptCommon(conceptCommon);
- addConceptInfoVO.setLibraryInfoList(libraryInfoList);
- return null;
- }
- /**
- * 导入数据插入更新
- *
- * @param addConceptInfoVOList
- */
- private void saveAddConceptInfoVOList(List<AddConceptInfoVO> addConceptInfoVOList) {
- List<Long> conceptIds = addConceptInfoVOList.stream().filter(i -> i.getConceptId() != null).map(i -> i.getConceptId()).collect(Collectors.toList());
- if (ListUtil.isNotEmpty(conceptIds)) {
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
- libraryInfoQe.in("concept_id", conceptIds);
- libraryinfoFacade.remove(libraryInfoQe);
- }
- List<LibraryInfo> saveLibraryInfoList = Lists.newArrayList();
- addConceptInfoVOList.forEach(i -> {
- saveLibraryInfoList.addAll(i.getLibraryInfoList());
- });
- libraryInfoService.saveBatch(saveLibraryInfoList);
- List<Concept> saveOrUpdateConceptList = Lists.newArrayList();
- addConceptInfoVOList.forEach(i -> {
- i.getConcept().setLibId(i.getLibraryInfoList().get(0).getId());
- i.getConcept().setLibName(i.getLibraryInfoList().get(0).getName());
- saveOrUpdateConceptList.add(i.getConcept());
- });
- //删除标签缓存
- List<Long> saveConceptIds = saveOrUpdateConceptList.stream().map(i -> i.getId()).filter(j -> j != null).distinct().collect(Collectors.toList());
- this.cacheClearByConceptIds(saveConceptIds);
- conceptService.saveOrUpdateBatch(saveOrUpdateConceptList);
- List<LibraryInfo> updateLibraryInfoList = Lists.newArrayList();
- addConceptInfoVOList.forEach(i -> {
- if (i.getConceptId() == null) {
- i.getLibraryInfoList().forEach(j -> {
- j.setConceptId(i.getConcept().getId());
- });
- updateLibraryInfoList.addAll(i.getLibraryInfoList());
- }
- });
- if (ListUtil.isNotEmpty(updateLibraryInfoList)) {
- libraryInfoService.updateBatchById(updateLibraryInfoList);
- }
- List<ConceptCommon> saveOrUpdateConceptCommonList = Lists.newArrayList();
- Map<Long, ConceptCommon> conceptCommonMap = null;
- if (ListUtil.isNotEmpty(conceptIds)) {
- QueryWrapper<ConceptCommon> conceptCommonQe = new QueryWrapper<>();
- conceptCommonQe.in("concept_id", conceptIds);
- conceptCommonMap = conceptCommonFacade.list(conceptCommonQe).stream().collect(Collectors.toMap(ConceptCommon::getConceptId, i -> i));
- }
- for (AddConceptInfoVO i : addConceptInfoVOList) {
- if (i.getConceptCommon() != null) {
- if (i.getConceptId() != null && conceptCommonMap != null && conceptCommonMap.containsKey(i.getConceptId())) {
- i.getConceptCommon().setId(conceptCommonMap.get(i.getConceptId()).getId());
- }
- i.getConceptCommon().setConceptId(i.getConcept().getId());
- saveOrUpdateConceptCommonList.add(i.getConceptCommon());
- }
- }
- if (ListUtil.isNotEmpty(saveOrUpdateConceptCommonList)) {
- conceptCommonService.saveOrUpdateBatch(saveOrUpdateConceptCommonList);
- }
- }
- @SuppressWarnings("deprecation")
- private String getValue(Cell cell) {
- try {
- Object obj = null;
- switch (cell.getCellTypeEnum()) {
- case BOOLEAN:
- obj = cell.getBooleanCellValue();
- break;
- case ERROR:
- obj = cell.getErrorCellValue();
- break;
- case NUMERIC:
- if (HSSFDateUtil.isCellDateFormatted(cell)) {
- Date date = cell.getDateCellValue();
- obj = DateFormatUtils.format(date, "yyyy-MM-dd");
- } else {
- obj = cell.getNumericCellValue();
- DecimalFormat df = new DecimalFormat("0");
- obj = df.format(obj);
- }
- break;
- case STRING:
- obj = cell.getStringCellValue();
- break;
- default:
- break;
- }
- return obj.toString();
- } catch (Exception e) {
- return "";
- }
- }
- /**
- * 根据概念Id列表获取概念列表Map
- *
- * @param conceptSearchVO 搜索参数
- * @return 术语id和术语 Map
- */
- public Map<Long, String> getConceptMap(ConceptSearchVO conceptSearchVO) {
- //入参验证
- if (ListUtil.isEmpty(conceptSearchVO.getConceptIds())) {
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "术语列表不能为空");
- }
- //获取结构
- List<Concept> concepts
- = this.getListByIds(conceptSearchVO.getConceptIds());
- //出参封装
- Map<Long, String> map = new HashMap<>();
- if (ListUtil.isNotEmpty(concepts)) {
- map = concepts.stream().collect(Collectors.toMap(r -> r.getId(), r -> r.getLibName()));
- }
- return map;
- }
- /**
- * 根据概念Id列表获取概念列表
- *
- * @param ids
- * @return
- */
- public List<Concept> getListByIds(List<Long> ids) {
- QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
- conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
- if (ids.size() == 1) {
- conceptQueryWrapper.eq("id", ids.get(0));
- } else {
- conceptQueryWrapper.in("id", ids);
- }
- List<Concept> list = this.list(conceptQueryWrapper);
- return list;
- }
- /**
- * 根据类型获取术语列表(科室、辅检、慢病)
- *
- * @param conceptTypeVO 类型
- * @return 术语列表
- */
- public List<ConceptBaseDTO> getConceptListByType(ConceptTypeVO conceptTypeVO) {
- if (null == conceptTypeVO
- || IntegerUtil.isNull(conceptTypeVO.getType())) {
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "类型不能为空");
- }
- List<ConceptBaseDTO> res = ListUtil.newArrayList();
- switch (conceptTypeVO.getType()) {
- case 1:
- res = getConceptByType(LexiconTypeEnum.DEPARTMENT.getKey());
- break;
- case 2:
- res = getConceptByType(LexiconTypeEnum.PACS_ITEMS.getKey());
- break;
- case 3:
- res = getConceptChronic();
- break;
- default:
- throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "类型超出范围以外");
- }
- return res;
- }
- /**
- * 获取慢病列表
- *
- * @return 慢病列表
- */
- private List<ConceptBaseDTO> getConceptChronic() {
- ConceptWrapper conceptWrapper = new ConceptWrapper();
- conceptWrapper.setStartType(LexiconTypeEnum.DIAGNOSIS.getKey());
- conceptWrapper.setRelationType(LexiconRSTypeEnum.INCLUDE_OF.getKey());
- conceptWrapper.setEndName("慢病");
- List<ConceptRes> list = this.getConcept(conceptWrapper);
- List<ConceptBaseDTO> res = ListUtil.newArrayList();
- if (ListUtil.isNotEmpty(list)) {
- for (ConceptRes concept : list) {
- ConceptBaseDTO conceptBaseDTO = new ConceptBaseDTO();
- conceptBaseDTO.setConceptId(concept.getStartId());
- conceptBaseDTO.setName(concept.getStartName());
- res.add(conceptBaseDTO);
- }
- }
- return res;
- }
- /**
- * 根据类型获取术语列表(科室、辅检)
- *
- * @param libType
- * @return
- */
- private List<ConceptBaseDTO> getConceptByType(Integer libType) {
- QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
- conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .in("lib_Type", libType);
- List<Concept> list = this.list(conceptQueryWrapper);
- List<ConceptBaseDTO> res = ListUtil.newArrayList();
- if (ListUtil.isNotEmpty(list)) {
- for (Concept concept : list) {
- ConceptBaseDTO conceptBaseDTO = new ConceptBaseDTO();
- conceptBaseDTO.setConceptId(concept.getId());
- conceptBaseDTO.setName(concept.getLibName());
- res.add(conceptBaseDTO);
- }
- }
- return res;
- }
- /**
- * 根据名称和类型获取概念列表Map
- *
- * @param conceptExistVO 搜索参数
- * @return 术语id和术语 Map
- */
- public Map<String, List<Integer>> getConceptMap(ConceptExistVO conceptExistVO) {
- // 入参验证
- if (ListUtil.isEmpty(conceptExistVO.getNameList())) {
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "名称列表不能为空");
- }
- if (conceptExistVO.getType() != null) {
- // 如果是化验明细项,直接赋值
- if (conceptExistVO.getIsLisDetail() == true) {
- conceptExistVO.setLibType(LexiconTypeEnum.LIS_DETAILS.getKey());
- } else {
- Integer libType = ParamConvertUtil.conceptConvert2Lib(conceptExistVO.getType());
- if (libType == null) {
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "类型不匹配");
- }
- conceptExistVO.setLibType(libType);
- }
- }
- //获取结构
- List<Concept> concepts
- = this.getListByNamesAndType(conceptExistVO.getNameList(), conceptExistVO.getLibType());
- Map<String, List<Concept>> map1 = EntityUtil.makeEntityListMap(concepts, "libName");
- Map<String, List<Integer>> typeMap = new HashMap<>();
- for (String key : map1.keySet()) {
- List<Concept> list = map1.get(key);
- List<Integer> typeList = new ArrayList<>();
- if (ListUtil.isNotEmpty(list)) {
- for (Concept c : list) {
- Integer type = ParamConvertUtil.libConvert2Concept(c.getLibType().intValue());
- if (type != null) {
- typeList.add(type);
- }
- }
- typeMap.put(key, typeList);
- }
- }
- return typeMap;
- }
- /**
- * 根据名称和词性获取概念列表
- *
- * @param nameList
- * @param libType
- * @return
- */
- public List<Concept> getListByNamesAndType(List<String> nameList, Integer libType) {
- QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
- conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .in("lib_name", nameList);
- if (libType != null) {
- conceptQueryWrapper.eq("lib_type", libType);
- }
- List<Concept> list = this.list(conceptQueryWrapper);
- return list;
- }
- public List<ConceptBaseDTO> indexFac(IndexVO indexVO) {
- // 类型转换
- Integer libType = ParamConvertUtil.conceptConvert2Lib(indexVO.getType());
- if (libType == null) {
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "类型不匹配");
- }
- indexVO.setLibType(libType);
- return this.index(indexVO);
- }
- public List<ConceptBaseDTO> indexByLexiconFac(IndexLexiconVO indexLexiconVO) {
- return this.indexByLexicon(indexLexiconVO);
- }
- /**
- * 根据概念Id列表获取概念列表Map
- *
- * @param conceptSearchVO 搜索参数
- * @return 术语id和术语 Map
- */
- public Map<Long, String> getConceptNameMap(ConceptSearchVO conceptSearchVO) {
- //入参验证
- if (ListUtil.isEmpty(conceptSearchVO.getConceptIds())) {
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "术语列表不能为空");
- }
- //获取结构
- List<Concept> concepts
- = this.getListByIds(conceptSearchVO.getConceptIds());
- //出参封装
- Map<Long, String> map = new HashMap<>();
- if (ListUtil.isNotEmpty(concepts)) {
- map = concepts.stream().collect(Collectors.toMap(r -> r.getId(), r -> r.getLibName()));
- }
- return map;
- }
- public Boolean piyinUp() {
- Boolean res = false;
- QueryWrapper<LibraryInfo> libraryInfoQueryWrapper = new QueryWrapper<>();
- libraryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .isNull("spell");
- List<LibraryInfo> list = libraryInfoService.list(libraryInfoQueryWrapper);
- if (ListUtil.isNotEmpty(list)) {
- Date now = DateUtil.now();
- for (LibraryInfo libraryInfo : list) {
- libraryInfo.setSpell(Cn2SpellUtil.converterToFirstSpell(libraryInfo.getName()));
- libraryInfo.setGmtModified(now);
- }
- List<List<LibraryInfo>> listList = SqlExecuteUtil.divideList(list, 200);
- int i = 0;
- for (List<LibraryInfo> libraryInfoList : listList) {
- res = libraryInfoService.updateBatchById(libraryInfoList);
- i++;
- }
- System.out.println("批量更新拼音" + i + "次!");
- }
- return res;
- }
- /**
- * 模板维护辅检检索
- *
- * @param getConceptPacInfosVO
- * @return
- */
- public List<ConceptBaseDTO> getConceptPacInfos(GetConceptPacInfosVO getConceptPacInfosVO) {
- QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
- conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("lib_type", LexiconTypeEnum.PACS_ITEMS.getKey())
- .like("lib_name", getConceptPacInfosVO.getInputStr());
- List<Concept> list = this.list(conceptQueryWrapper);
- List<ConceptBaseDTO> res = ListUtil.newArrayList();
- if (ListUtil.isNotEmpty(list)) {
- for (Concept concept : list) {
- ConceptBaseDTO conceptBaseDTO = new ConceptBaseDTO();
- conceptBaseDTO.setConceptId(concept.getId());
- conceptBaseDTO.setName(concept.getLibName());
- res.add(conceptBaseDTO);
- }
- }
- return res;
- }
- /**
- * 筛选符合类型的概念id
- * @param libTypeId
- * @param sourceConceptIds
- * @return
- */
- public List<Long> getCompatibleTypeConceptIds(Long libTypeId,List<Long> sourceConceptIds){
- if(libTypeId==null||ListUtil.isEmpty(sourceConceptIds)){
- return null;
- }
- QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
- conceptQe.in("id", sourceConceptIds);
- conceptQe.eq("lib_type", libTypeId);
- return list(conceptQe).stream().map(i->i.getId()).collect(Collectors.toList());
- }
- }
- /**
- * 删除缓存(化验相关)
- *
- * @param conceptId
- * @return
- */
- public Boolean cacheClearByConceptId(Long conceptId) {
- Concept concept = this.getById(conceptId);
- List<String> names = Lists.newArrayList();
- names.add(concept.getLibName());
- List<String> mealNames = Lists.newArrayList();
- if (concept.getLibType().equals(Long.valueOf(LexiconTypeEnum.LIS_TABLES.getKey()))) {
- mealNames = lisMappingFacade.getMealNameByUniqueNames(names);
- } else if (concept.getLibType().equals(Long.valueOf(LexiconTypeEnum.LIS_PACKAGE.getKey()))) {
- mealNames.add(concept.getLibName());
- } else if (concept.getLibType().equals(Long.valueOf(LexiconTypeEnum.LIS_DETAILS.getKey()))) {
- mealNames = lisMappingFacade.getMealNameByItemNames(names);
- } else {
- return true;
- }
- if (ListUtil.isNotEmpty(mealNames)) {
- KLQuestionVO klQuestionVO = new KLQuestionVO();
- klQuestionVO.setTagNames(mealNames);
- klQuestionVO.setNames(mealNames);
- klQuestionVO.setType(5);
- List<Integer> tagTypes = Lists.newArrayList();
- tagTypes.add(7);
- klQuestionVO.setTagType(tagTypes);
- RespDTO<List<QuestionInfo>> respDTO = icssManServiceClient.indexForkl(klQuestionVO);
- if (RespDTOUtil.respIsOK(respDTO)) {
- List<QuestionInfo> questionInfoList = respDTO.data;
- if (ListUtil.isNotEmpty(questionInfoList)) {
- IdListVO idListVO = new IdListVO();
- List<Long> idList = questionInfoList.stream().map(i -> i.getId()).collect(Collectors.toList());
- idListVO.setIdList(idList);
- RespDTO<Boolean> cacheRespDTO = icssManServiceClient.clearCache(idListVO);
- }
- }
- }
- return true;
- }
- /**
- * 批量删除化验相关标签缓存
- *
- * @param conceptIds
- * @return
- */
- public Boolean cacheClearByConceptIds(List<Long> conceptIds) {
- List<Concept> concepts = this.getListByIds(conceptIds);
- List<String> mealNames = Lists.newArrayList();
- List<Concept> mealConcepts = concepts.stream().filter(i -> i.getLibType().equals(Long.valueOf(LexiconTypeEnum.LIS_PACKAGE.getKey()))).collect(Collectors.toList());
- mealNames.addAll(mealConcepts.stream().map(i -> i.getLibName()).filter(j -> j != null).distinct().collect(Collectors.toList()));
- List<Concept> itemConcepts = concepts.stream().filter(i -> i.getLibType().equals(Long.valueOf(LexiconTypeEnum.LIS_DETAILS.getKey()))).collect(Collectors.toList());
- List<String> itemNames = itemConcepts.stream().map(i -> i.getLibName()).filter(j -> j != null).distinct().collect(Collectors.toList());
- mealNames.addAll(lisMappingFacade.getMealNameByItemNames(itemNames));
- List<Concept> uniqueConcepts = concepts.stream().filter(i -> i.getLibType().equals(Long.valueOf(LexiconTypeEnum.LIS_TABLES.getKey()))).collect(Collectors.toList());
- List<String> uniqueNames = uniqueConcepts.stream().map(i -> i.getLibName()).filter(j -> j != null).distinct().collect(Collectors.toList());
- mealNames.addAll(lisMappingFacade.getMealNameByUniqueNames(uniqueNames));
- mealNames = mealNames.stream().filter(i -> StringUtil.isNotBlank(i)).distinct().collect(Collectors.toList());
- if (ListUtil.isNotEmpty(mealNames)) {
- KLQuestionVO klQuestionVO = new KLQuestionVO();
- klQuestionVO.setTagNames(mealNames);
- klQuestionVO.setNames(mealNames);
- klQuestionVO.setType(5);
- List<Integer> tagTypes = Lists.newArrayList();
- tagTypes.add(7);
- klQuestionVO.setTagType(tagTypes);
- RespDTO<List<QuestionInfo>> respDTO = icssManServiceClient.indexForkl(klQuestionVO);
- if (RespDTOUtil.respIsOK(respDTO)) {
- List<QuestionInfo> questionInfoList = respDTO.data;
- if (ListUtil.isNotEmpty(questionInfoList)) {
- IdListVO idListVO = new IdListVO();
- List<Long> idList = questionInfoList.stream().map(i -> i.getId()).collect(Collectors.toList());
- idListVO.setIdList(idList);
- RespDTO<Boolean> cacheRespDTO = icssManServiceClient.clearCache(idListVO);
- }
- }
- }
- return true;
- }
- }
|