123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281 |
- package com.diagbot.facade;
- 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;
- 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 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.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.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.IndexLexiconVO;
- import com.diagbot.vo.IndexVO;
- import com.diagbot.vo.RemoveConceptInfoVO;
- import com.google.common.collect.Lists;
- /**
- * @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;
- /**
- * 获取所有化验公表项
- *
- * @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) {
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<LibraryInfo>();
- libraryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
- libraryInfoQe.eq(getAllConceptVO.getIsConcept() != null, "is_concept", getAllConceptVO.getIsConcept());
- libraryInfoQe.like(StringUtil.isNotBlank(getAllConceptVO.getName()), "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());
- }*/
- List<GetAllConceptDTO> 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 = new ArrayList<>();
- QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
- conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
- conceptQe.like(StringUtil.isNotEmpty(getAllForRelationVO.getName()), "lib_name", getAllForRelationVO.getName());
- conceptQe.eq(getAllForRelationVO.getTypeId() != null, "lib_type", getAllForRelationVO.getTypeId());
- List<Concept> conceptList = list(conceptQe);
- 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());
- if (getAllForRelationVO.getRelationPosition() == 1) {
- relationQe.eq(getAllForRelationVO.getRelationConceptId() != null, "end_id", getAllForRelationVO.getRelationConceptId());
- relationQe.and(wrapper->wrapper.in("start_id", conceptIdList).or(getAllForRelationVO.getRelationConceptId() == null).in("end_id", conceptIdList));
- reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getStartId, Collectors.counting()));
- } else if(getAllForRelationVO.getRelationConceptId() != null) {
- relationQe.in("end_id", conceptIdList);
- relationQe.eq("start_id", getAllForRelationVO.getRelationConceptId());
- 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<>();
-
- List<Long> conceptIdList = null;
- if(StringUtil.isBlank(getAllInformationVO.getLibName())&&StringUtil.isNotBlank(getAllInformationVO.getName())){
- getAllInformationVO.setLibName(getAllInformationVO.getName());
- }
- 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()));
- conceptIdList = libraryinfoFacade.list(libraryInfoQe).stream().map(i->i.getConceptId()).distinct().collect(Collectors.toList());
- }
-
- Page<Concept> conceptPage = new Page<>(getAllInformationVO.getCurrent(),getAllInformationVO.getSize());
- QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
- conceptQe.in(ListUtil.isNotEmpty(conceptIdList), "id", conceptIdList);
- 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.orderByAsc("is_deleted");
- conceptQe.orderByDesc("gmt_modified");
- 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, "该数据已恢复!");
- }
- }
- 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.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(libraryInfoMain.getSpell());
- libraryInfoMain.setConceptId(conceptId);
- libraryInfoMain.setGmtModified(now);
- libraryInfoMain.setModifier(currentUser);
- saveOrUpdateLibraryInfoList.add(libraryInfoMain);
- libraryInfoService.saveOrUpdateBatch(saveOrUpdateLibraryInfoList);
- 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));
-
- addConceptInfoVOList.forEach(i -> {
- i = checkImConceptInfo(i,libraryInfoListMap);
- });
-
- saveAddConceptInfoVOList(addConceptInfoVOList);
- return true;
- }
-
- /**
- * 导入数据插入更新前校验
- * @param addConceptInfoVO
- * @param libraryInfoListAllMap
- * @return
- */
- public AddConceptInfoVO checkImConceptInfo(AddConceptInfoVO addConceptInfoVO,Map<String,List<LibraryInfo>> libraryInfoListAllMap) {
- String currentUser = UserUtils.getCurrentPrincipleID();
- Date now = DateUtil.now();
-
- Concept concept = new Concept();
- ConceptCommon conceptCommon = new ConceptCommon();
- conceptCommon.setSexType(addConceptInfoVO.getSexType());
- conceptCommon.setMinAge(addConceptInfoVO.getMinAge());
- conceptCommon.setMaxAge(addConceptInfoVO.getMaxAge());
- conceptCommon.setGmtModified(now);
- conceptCommon.setModifier(currentUser);
- List<LibraryInfo> libraryInfoList = Lists.newArrayList();
-
- String lineNumStr = "第" + addConceptInfoVO.getLineNum() + "行";
- 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 + "标准术语只能有一个!");
- }
-
- Integer typeId_ = LexiconTypeEnum.getKey(addConceptInfoVO.getType());
- if (typeId_ == null) {
- throw new CommonException(CommonErrorCode.NOT_EXISTS, lineNumStr + "数据有误,该类型信息在数据库中不存在!");
- }
- Long typeId = typeId_.longValue();
- concept.setLibType(typeId);
- concept.setGmtModified(now);
- concept.setModifier(currentUser);
- List<LibraryInfo> extLibraryInfoList = Lists.newArrayList();
- addConceptInfoVO.getDetailList().forEach(a->{
- List<LibraryInfo> libraryInfoListAll = libraryInfoListAllMap.get(a.getName());
- if(libraryInfoListAll!=null){
- libraryInfoListAll = libraryInfoListAll.stream().filter(b->b.getTypeId().intValue()==typeId.intValue()).collect(Collectors.toList());
- if(libraryInfoListAll!=null){
- 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);
- 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) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "标准术语已作为同义词被占用!");
- }
- }
- 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("已被占用");
- throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
- }
-
- addConceptInfoVO.setConcept(concept);
- addConceptInfoVO.setConceptCommon(conceptCommon);
- addConceptInfoVO.setLibraryInfoList(libraryInfoList);
- return addConceptInfoVO;
- }
-
- /**
- * 导入数据插入更新
- * @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());
- });
- 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();
- QueryWrapper<ConceptCommon> conceptCommonQe = new QueryWrapper<>();
- conceptCommonQe.in("concept_id", conceptIds);
- Map<Long,ConceptCommon> conceptCommonMap = conceptCommonFacade.list(conceptCommonQe).stream().collect(Collectors.toMap(ConceptCommon::getConceptId, i->i));
- addConceptInfoVOList.forEach(i->{
- if(i.getConceptId()!=null){
- i.getConceptCommon().setId(conceptCommonMap.get(i.getConceptId()).getId());
- }
- i.getConceptCommon().setConceptId(i.getConcept().getId());
- saveOrUpdateConceptCommonList.add(i.getConceptCommon());
- });
- 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;
- }
- }
|