ConceptFacade.java 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. package com.diagbot.facade;
  2. import java.io.InputStream;
  3. import java.text.DecimalFormat;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.stream.Collectors;
  10. import org.apache.commons.lang.time.DateFormatUtils;
  11. import org.apache.poi.hssf.usermodel.HSSFDateUtil;
  12. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  13. import org.apache.poi.ss.usermodel.Cell;
  14. import org.apache.poi.ss.usermodel.Row;
  15. import org.apache.poi.ss.usermodel.Sheet;
  16. import org.apache.poi.ss.usermodel.Workbook;
  17. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Qualifier;
  20. import org.springframework.stereotype.Component;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  23. import com.baomidou.mybatisplus.core.metadata.IPage;
  24. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  25. import com.diagbot.client.UserServiceClient;
  26. import com.diagbot.dto.ConceptBaseDTO;
  27. import com.diagbot.dto.ConceptRes;
  28. import com.diagbot.dto.GetAllConceptDTO;
  29. import com.diagbot.dto.GetAllForRelationDTO;
  30. import com.diagbot.dto.GetAllInformationDTO;
  31. import com.diagbot.dto.GetAllLisConceptDTO;
  32. import com.diagbot.dto.GetConceptInfoDTO;
  33. import com.diagbot.dto.GetConceptInfoDetailDTO;
  34. import com.diagbot.dto.RespDTO;
  35. import com.diagbot.entity.Concept;
  36. import com.diagbot.entity.ConceptCommon;
  37. import com.diagbot.entity.Lexicon;
  38. import com.diagbot.entity.LibraryInfo;
  39. import com.diagbot.entity.Relation;
  40. import com.diagbot.entity.wrapper.ConceptWrapper;
  41. import com.diagbot.enums.IsDeleteEnum;
  42. import com.diagbot.enums.LexiconRSTypeEnum;
  43. import com.diagbot.enums.LexiconTypeEnum;
  44. import com.diagbot.exception.CommonErrorCode;
  45. import com.diagbot.exception.CommonException;
  46. import com.diagbot.service.ConceptCommonService;
  47. import com.diagbot.service.ConceptService;
  48. import com.diagbot.service.LibraryInfoService;
  49. import com.diagbot.service.impl.ConceptServiceImpl;
  50. import com.diagbot.util.BeanUtil;
  51. import com.diagbot.util.Cn2SpellUtil;
  52. import com.diagbot.util.DateUtil;
  53. import com.diagbot.util.EntityUtil;
  54. import com.diagbot.util.IntegerUtil;
  55. import com.diagbot.util.ListUtil;
  56. import com.diagbot.util.ParamConvertUtil;
  57. import com.diagbot.util.RespDTOUtil;
  58. import com.diagbot.util.SqlExecuteUtil;
  59. import com.diagbot.util.StringUtil;
  60. import com.diagbot.util.UserUtils;
  61. import com.diagbot.vo.AddConceptInfoDetailVO;
  62. import com.diagbot.vo.AddConceptInfoVO;
  63. import com.diagbot.vo.ConceptExistVO;
  64. import com.diagbot.vo.ConceptSearchVO;
  65. import com.diagbot.vo.ConceptTypeVO;
  66. import com.diagbot.vo.GetAllConceptVO;
  67. import com.diagbot.vo.GetAllForRelationVO;
  68. import com.diagbot.vo.GetAllInformationVO;
  69. import com.diagbot.vo.GetAllLisConceptVO;
  70. import com.diagbot.vo.GetConceptInfoDetailVO;
  71. import com.diagbot.vo.GetConceptPacInfosVO;
  72. import com.diagbot.vo.IndexLexiconVO;
  73. import com.diagbot.vo.IndexVO;
  74. import com.diagbot.vo.RemoveConceptInfoVO;
  75. import com.google.common.collect.Lists;
  76. /**
  77. * @Description: 术语查询业务层
  78. * @author: Weixuan Huang
  79. * @time: 2019/1/14 16:17
  80. */
  81. @Component
  82. public class ConceptFacade extends ConceptServiceImpl {
  83. @Autowired
  84. private LibraryInfoFacade libraryinfoFacade;
  85. @Autowired
  86. private RelationFacade relationFacade;
  87. @Autowired
  88. @Qualifier("libraryInfoServiceImpl")
  89. private LibraryInfoService libraryInfoService;
  90. @Autowired
  91. @Qualifier("conceptServiceImpl")
  92. private ConceptService conceptService;
  93. @Autowired
  94. @Qualifier("conceptCommonServiceImpl")
  95. private ConceptCommonService conceptCommonService;
  96. @Autowired
  97. private UserServiceClient userServiceClient;
  98. @Autowired
  99. private LexiconFacade lexiconFacade;
  100. @Autowired
  101. private ConceptCommonFacade conceptCommonFacade;
  102. /**
  103. * 获取所有化验公表项
  104. *
  105. * @param getAllLisConceptVO
  106. * @return
  107. */
  108. public List<GetAllLisConceptDTO> getAllLisConcept(GetAllLisConceptVO getAllLisConceptVO) {
  109. List<GetAllLisConceptDTO> getAllLisConceptDTOList = new ArrayList<>();
  110. QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
  111. conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
  112. conceptQe.eq("lib_type", LexiconTypeEnum.LIS_TABLES.getKey());
  113. conceptQe.like(StringUtil.isNotEmpty(getAllLisConceptVO.getConceptName()), "lib_name", getAllLisConceptVO.getConceptName());
  114. List<Concept> conceptList = list(conceptQe);
  115. conceptList.forEach(i -> {
  116. if (getAllLisConceptVO.getExcludedConceptNames() != null
  117. && getAllLisConceptVO.getExcludedConceptNames().contains(i.getLibName())) {
  118. return;
  119. }
  120. GetAllLisConceptDTO getAllLisConceptDTO = new GetAllLisConceptDTO();
  121. getAllLisConceptDTO.setConceptId(i.getId());
  122. getAllLisConceptDTO.setConceptName(i.getLibName());
  123. getAllLisConceptDTOList.add(getAllLisConceptDTO);
  124. });
  125. //return this.baseMapper.getAllLisConcept(getAllLisConceptVO);
  126. return getAllLisConceptDTOList;
  127. }
  128. /**
  129. * 获取所有医学术语命名
  130. *
  131. * @param getAllConceptVO
  132. * @return
  133. */
  134. public List<GetAllConceptDTO> getAllConcept(GetAllConceptVO getAllConceptVO) {
  135. QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<LibraryInfo>();
  136. libraryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
  137. libraryInfoQe.eq(getAllConceptVO.getIsConcept() != null, "is_concept", getAllConceptVO.getIsConcept());
  138. libraryInfoQe.like(StringUtil.isNotBlank(getAllConceptVO.getName()), "name", getAllConceptVO.getName());
  139. List<LibraryInfo> libraryInfoList = libraryinfoFacade.list(libraryInfoQe);
  140. //过滤掉非概念术语
  141. if (getAllConceptVO.getIsConcept() != null && getAllConceptVO.getIsConcept() == 1) {
  142. QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
  143. conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
  144. conceptQe.in("id", libraryInfoList.stream().map(i -> i.getConceptId()).distinct().collect(Collectors.toList()));
  145. Map<Long, Concept> conceptMap = list(conceptQe).stream().collect(Collectors.toMap(Concept::getId, i -> i));
  146. libraryInfoList.forEach(i -> {
  147. if (conceptMap.get(i.getConceptId()) == null || conceptMap.get(i.getConceptId()).getLibId().intValue() != i.getId().intValue()
  148. ||(getAllConceptVO.getExcludedConceptIds() != null && getAllConceptVO.getExcludedConceptIds().contains(i.getConceptId()))) {
  149. i.setIsDeleted(IsDeleteEnum.Y.getKey());
  150. }
  151. });
  152. libraryInfoList = libraryInfoList.stream().filter(i -> i.getIsDeleted().equals(IsDeleteEnum.N.getKey())).collect(Collectors.toList());
  153. }
  154. /*//添加过术语医学属性的过滤掉
  155. if (getAllConceptVO.getIsMedical() != null && getAllConceptVO.getIsMedical() == 1) {
  156. QueryWrapper<Medical> medicalQe = new QueryWrapper<>();
  157. medicalQe.eq("is_deleted", "N");
  158. medicalQe.in("concept_id", libraryInfoList.stream().map(i -> i.getConceptId()).collect(Collectors.toList()));
  159. Map<Long, Medical> medicalMap = medicalFacade.list(medicalQe).stream().collect(Collectors.toMap(Medical::getConceptId, i -> i));
  160. libraryInfoList = libraryInfoList.stream().filter(i -> {
  161. if (medicalMap.get(i.getConceptId()) == null) {
  162. return true;
  163. } else {
  164. return false;
  165. }
  166. }).collect(Collectors.toList());
  167. }*/
  168. List<GetAllConceptDTO> getAllConceptDTOList = BeanUtil.listCopyTo(libraryInfoList, GetAllConceptDTO.class);
  169. getAllConceptDTOList.forEach(i -> {
  170. i.setType(LexiconTypeEnum.getName(i.getTypeId().intValue()));
  171. i.setNameAndType(i.getName() + "(" + i.getType() + ")");
  172. });
  173. return getAllConceptDTOList;
  174. }
  175. /**
  176. * 获取所有概念(术语关系维护时筛选使用)
  177. *
  178. * @param getAllForRelationVO
  179. * @return
  180. */
  181. public List<GetAllForRelationDTO> getAllForRelation(GetAllForRelationVO getAllForRelationVO) {
  182. List<GetAllForRelationDTO> retList = new ArrayList<>();
  183. QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
  184. conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
  185. conceptQe.like(StringUtil.isNotEmpty(getAllForRelationVO.getName()), "lib_name", getAllForRelationVO.getName());
  186. conceptQe.eq(getAllForRelationVO.getTypeId() != null, "lib_type", getAllForRelationVO.getTypeId());
  187. List<Concept> conceptList = list(conceptQe);
  188. Map<Long, Long> reCouMap = new HashMap<>();
  189. if (getAllForRelationVO.getRelationPosition() != 3) {
  190. if (getAllForRelationVO.getRelationId() == null) {
  191. throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "关系类型id必传!");
  192. }
  193. List<Long> conceptIdList = conceptList.stream().map(i -> i.getId()).collect(Collectors.toList());
  194. QueryWrapper<Relation> relationQe = new QueryWrapper<>();
  195. relationQe.eq("relation_id", getAllForRelationVO.getRelationId());
  196. if (getAllForRelationVO.getRelationPosition() == 1) {
  197. relationQe.eq(getAllForRelationVO.getRelationConceptId() != null, "end_id", getAllForRelationVO.getRelationConceptId());
  198. relationQe.and(wrapper->wrapper.in("start_id", conceptIdList).or(getAllForRelationVO.getRelationConceptId() == null).in("end_id", conceptIdList));
  199. reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getStartId, Collectors.counting()));
  200. } else if(getAllForRelationVO.getRelationConceptId() != null) {
  201. relationQe.in("end_id", conceptIdList);
  202. relationQe.eq("start_id", getAllForRelationVO.getRelationConceptId());
  203. reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getEndId, Collectors.counting()));
  204. }
  205. }
  206. for (Concept i : conceptList) {
  207. if (reCouMap.get(i.getId()) != null
  208. || (getAllForRelationVO.getExcludedConceptIds() != null && getAllForRelationVO.getExcludedConceptIds().contains(i.getId()))
  209. || (getAllForRelationVO.getRelationConceptId() != null && getAllForRelationVO.getRelationConceptId() == i.getId())) {
  210. continue;
  211. }
  212. GetAllForRelationDTO getAllForRelationDTO = new GetAllForRelationDTO();
  213. getAllForRelationDTO.setConceptId(i.getId());
  214. getAllForRelationDTO.setConceptName(i.getLibName());
  215. getAllForRelationDTO.setConceptNameType(i.getLibName()+"("+LexiconTypeEnum.getName(i.getLibType().intValue())+")");
  216. retList.add(getAllForRelationDTO);
  217. }
  218. return retList;
  219. }
  220. /**
  221. * 获取医学术语命名列表
  222. *
  223. * @param getAllInformationVO
  224. * @return
  225. */
  226. public IPage<GetAllInformationDTO> getAllInformation(GetAllInformationVO getAllInformationVO) {
  227. Page<GetAllInformationDTO> getAllInformationDTOPage = new Page<>();
  228. List<Long> conceptIdList = null;
  229. if(StringUtil.isBlank(getAllInformationVO.getLibName())&&StringUtil.isNotBlank(getAllInformationVO.getName())){
  230. getAllInformationVO.setLibName(getAllInformationVO.getName());
  231. }
  232. if(StringUtil.isNotBlank(getAllInformationVO.getLibName())){
  233. QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
  234. libraryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
  235. libraryInfoQe.like("name", getAllInformationVO.getLibName());
  236. libraryInfoQe.eq(StringUtil.isNotBlank(getAllInformationVO.getType()),"type_id", LexiconTypeEnum.getKey(getAllInformationVO.getType()));
  237. conceptIdList = libraryinfoFacade.list(libraryInfoQe).stream().map(i->i.getConceptId()).distinct().collect(Collectors.toList());
  238. }
  239. Page<Concept> conceptPage = new Page<>(getAllInformationVO.getCurrent(),getAllInformationVO.getSize());
  240. QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
  241. conceptQe.in(ListUtil.isNotEmpty(conceptIdList), "id", conceptIdList);
  242. conceptQe.like(StringUtil.isNotBlank(getAllInformationVO.getName()),"lib_name", getAllInformationVO.getName());
  243. conceptQe.eq(StringUtil.isNotBlank(getAllInformationVO.getType()),"lib_type", LexiconTypeEnum.getKey(getAllInformationVO.getType()));
  244. conceptQe.eq(StringUtil.isNotBlank(getAllInformationVO.getIsDeleted()),"is_deleted", getAllInformationVO.getIsDeleted());
  245. conceptQe.orderByAsc("is_deleted");
  246. conceptQe.orderByDesc("gmt_modified");
  247. IPage<Concept> iPage = this.page(conceptPage, conceptQe);
  248. BeanUtil.copyProperties(iPage, getAllInformationDTOPage);
  249. if(ListUtil.isNotEmpty(iPage.getRecords())){
  250. List<GetAllInformationDTO> getAllInformationDTOList = Lists.newArrayList();
  251. List<Long> conceptIds = iPage.getRecords().stream().map(i->i.getId()).collect(Collectors.toList());
  252. QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
  253. libraryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
  254. libraryInfoQe.in("concept_id", conceptIds);
  255. Map<Long,List<LibraryInfo>> libraryInfoListMap = libraryinfoFacade.list(libraryInfoQe).stream().collect(Collectors.groupingBy(LibraryInfo::getConceptId));
  256. List<String> userIds = iPage.getRecords().stream().map(i ->i.getModifier()).distinct().collect(Collectors.toList());
  257. RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(userIds);
  258. RespDTOUtil.respNGDealCover(respDTO, "获取用户信息失败");
  259. iPage.getRecords().forEach(i -> {
  260. GetAllInformationDTO getAllInformationDTO = new GetAllInformationDTO();
  261. getAllInformationDTO.setConceptId(i.getId());
  262. getAllInformationDTO.setLibName(i.getLibName());
  263. getAllInformationDTO.setLibType(LexiconTypeEnum.getName(i.getLibType().intValue()));
  264. getAllInformationDTO.setIsDeleted(i.getIsDeleted());
  265. getAllInformationDTO.setOperName(respDTO.data.get(i.getModifier()));
  266. getAllInformationDTO.setOperTime(i.getGmtModified());
  267. if(libraryInfoListMap.get(i.getId())!=null){
  268. getAllInformationDTO.setOtherNames(libraryInfoListMap.get(i.getId()).stream().sorted((a,b)->b.getIsConcept()-a.getIsConcept()).map(k->k.getName()).collect(Collectors.joining("、")));
  269. }
  270. getAllInformationDTOList.add(getAllInformationDTO);
  271. });
  272. getAllInformationDTOPage.setRecords(getAllInformationDTOList);
  273. }
  274. return getAllInformationDTOPage;
  275. }
  276. /**
  277. * 医学术语命名删除或者恢复
  278. *
  279. * @param removeConceptInfoVO
  280. * @return
  281. */
  282. public Boolean removeConceptInfo(RemoveConceptInfoVO removeConceptInfoVO) {
  283. /*StringBuffer sbf = new StringBuffer();
  284. QueryWrapper<Medical> medicalQe = new QueryWrapper<Medical>();
  285. medicalQe.eq("is_deleted", "N");
  286. medicalQe.eq("concept_id", removeConceptInfoVO.getConceptId());
  287. if(medicalFacade.list(medicalQe).size()>0){
  288. sbf.append("请先解除医学属性关联 ");
  289. }
  290. QueryWrapper<Relation> relationQe = new QueryWrapper<Relation>();
  291. relationQe.eq("is_deleted", "N");
  292. relationQe.and(i->i.eq("start_id", removeConceptInfoVO.getConceptId()).or().eq("end_id", removeConceptInfoVO.getConceptId()));
  293. if(relationFacade.list(relationQe).size()>0){
  294. sbf.append("请先解除术语关系关联 ");
  295. }
  296. QueryWrapper<ConceptDetail> libraryDetailQe = new QueryWrapper<ConceptDetail>();
  297. libraryDetailQe.eq("is_deleted", "N");
  298. libraryDetailQe.eq("concept_id", removeConceptInfoVO.getConceptId());
  299. if(libraryDetailFacade.list(libraryDetailQe).size()>0){
  300. sbf.append("请先解除医学静态知识关联 ");
  301. }
  302. if(sbf.length()>0){
  303. throw new CommonException(CommonErrorCode.RPC_ERROR,sbf.toString());
  304. }*/
  305. String currentUser = UserUtils.getCurrentPrincipleID();
  306. Date now = DateUtil.now();
  307. /*QueryWrapper<LibraryInfo> libraryInfoQe1 = new QueryWrapper<>();
  308. libraryInfoQe1.eq("concept_id", removeConceptInfoVO.getConceptId());
  309. libraryInfoQe1.eq("is_concept", 0);
  310. libraryinfoFacade.remove(libraryInfoQe1);
  311. QueryWrapper<LibraryInfo> libraryInfoQe2 = new QueryWrapper<>();
  312. libraryInfoQe2.eq("concept_id", removeConceptInfoVO.getConceptId());
  313. LibraryInfo libraryInfo = new LibraryInfo();
  314. libraryInfo.setIsDeleted("Y");
  315. libraryInfo.setGmtModified(now);
  316. libraryInfo.setModifier(currentUser);
  317. libraryinfoFacade.update(libraryInfo, libraryInfoQe2);*/
  318. /*Concept concept = new Concept();
  319. concept.setId(removeConceptInfoVO.getConceptId());
  320. concept.setIsDeleted("Y");
  321. concept.setModifier(currentUser);
  322. concept.setGmtModified(now);
  323. this.updateById(concept);*/
  324. Concept concept = this.getById(removeConceptInfoVO.getConceptId());
  325. if (concept == null) {
  326. throw new CommonException(CommonErrorCode.NOT_EXISTS);
  327. }
  328. if (concept.getIsDeleted().equals(removeConceptInfoVO.getIsDeleted())) {
  329. if (removeConceptInfoVO.getIsDeleted().equals(IsDeleteEnum.Y.getKey())) {
  330. throw new CommonException(CommonErrorCode.NOT_EXISTS, "该数据已删除!");
  331. }
  332. if (removeConceptInfoVO.getIsDeleted().equals(IsDeleteEnum.N.getKey())) {
  333. throw new CommonException(CommonErrorCode.IS_EXISTS, "该数据已恢复!");
  334. }
  335. }
  336. concept.setIsDeleted(removeConceptInfoVO.getIsDeleted());
  337. concept.setModifier(currentUser);
  338. concept.setGmtModified(now);
  339. this.updateById(concept);
  340. return true;
  341. }
  342. /**
  343. * 获取医学术语命名详情
  344. *
  345. * @param getConceptInfoDetailVO
  346. * @return libName-标准术语,otherNames-同义词
  347. */
  348. public GetConceptInfoDTO getConceptInfoDetail(GetConceptInfoDetailVO getConceptInfoDetailVO) {
  349. GetConceptInfoDTO getConceptInfoDTO = new GetConceptInfoDTO();
  350. Concept concept = this.getById(getConceptInfoDetailVO.getConceptId());
  351. if (concept == null) {
  352. throw new CommonException(CommonErrorCode.NOT_EXISTS);
  353. }
  354. QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<LibraryInfo>();
  355. libraryInfoQe.eq("concept_id", getConceptInfoDetailVO.getConceptId());
  356. List<GetConceptInfoDetailDTO> getConceptInfoDetailDTOList = BeanUtil.listCopyTo(libraryinfoFacade.list(libraryInfoQe), GetConceptInfoDetailDTO.class);
  357. getConceptInfoDetailDTOList.forEach(i -> {
  358. i.setType(LexiconTypeEnum.getName(i.getTypeId().intValue()));
  359. });
  360. getConceptInfoDTO.setLibName(getConceptInfoDetailDTOList.stream().filter(i -> i.getIsConcept() != null && i.getIsConcept() == 1).collect(Collectors.toList()));
  361. getConceptInfoDTO.setOtherNames(getConceptInfoDetailDTOList.stream().filter(i -> i.getIsConcept() == null || i.getIsConcept() == 0).collect(Collectors.toList()));
  362. Integer isHasCommon = lexiconFacade.getById(concept.getLibType()).getIsHasCommon();
  363. getConceptInfoDTO.setIsHasCommon(isHasCommon);
  364. if (isHasCommon == 1) {
  365. QueryWrapper<ConceptCommon> conceptCommonQe = new QueryWrapper<>();
  366. conceptCommonQe.eq("concept_id", getConceptInfoDetailVO.getConceptId());
  367. ConceptCommon conceptCommon = conceptCommonFacade.getOne(conceptCommonQe);
  368. if (conceptCommon != null) {
  369. getConceptInfoDTO.setSexType(conceptCommon.getSexType());
  370. getConceptInfoDTO.setMinAge(conceptCommon.getMinAge());
  371. getConceptInfoDTO.setMaxAge(conceptCommon.getMaxAge());
  372. }
  373. }
  374. return getConceptInfoDTO;
  375. }
  376. /**
  377. * 医学术语命名添加或者编辑
  378. *
  379. * @param addConceptInfoVO
  380. * @return
  381. */
  382. public Boolean addConceptInfo(AddConceptInfoVO addConceptInfoVO) {
  383. String lineNumStr = "";
  384. if (addConceptInfoVO.getLineNum() != null) {
  385. lineNumStr = "第" + addConceptInfoVO.getLineNum() + "行";
  386. }
  387. //String regEx = "[0-9]+|[`~·!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]+";
  388. String regEx = "[0-9]+";
  389. for (AddConceptInfoDetailVO i : addConceptInfoVO.getDetailList()) {
  390. if (i.getName().matches(regEx)) {
  391. //throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "无法输入纯数字或者纯字符,请输入正确数据!");
  392. throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "无法输入纯数字,请输入正确数据!");
  393. }
  394. }
  395. if (addConceptInfoVO.getMaxAge() < addConceptInfoVO.getMinAge()) {
  396. throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "症状发生的最小年龄大于症状发生的最大年龄!");
  397. }
  398. if (addConceptInfoVO.getDetailList().stream().distinct().count() != addConceptInfoVO.getDetailList().size()) {
  399. throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "存在重复数据!");
  400. }
  401. List<AddConceptInfoDetailVO> addConceptInfoDetailVOMainList = addConceptInfoVO.getDetailList().stream().filter(i -> i.getIsConcept() == 1).collect(Collectors.toList());
  402. if (addConceptInfoDetailVOMainList.size() == 0) {
  403. throw new CommonException(CommonErrorCode.PARAM_IS_NULL, lineNumStr + "无标准术语!");
  404. }
  405. if (addConceptInfoDetailVOMainList.size() > 1) {
  406. throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, lineNumStr + "标准术语只能有一个!");
  407. }
  408. QueryWrapper<Lexicon> lexiconQe = new QueryWrapper<>();
  409. lexiconQe.eq("name", addConceptInfoVO.getType());
  410. Lexicon lexicon = lexiconFacade.getOne(lexiconQe);
  411. if (lexicon == null) {
  412. throw new CommonException(CommonErrorCode.NOT_EXISTS, lineNumStr + "数据有误,该类型信息在数据库中不存在!");
  413. }
  414. List<LibraryInfo> saveOrUpdateLibraryInfoList = new ArrayList<>();
  415. AddConceptInfoDetailVO addConceptInfoDetailVOMain = addConceptInfoDetailVOMainList.get(0);//提交过来的标准术语
  416. //查询当前添加的术语是否已经在数据库中
  417. QueryWrapper<LibraryInfo> libraryInfoQe1 = new QueryWrapper<>();
  418. libraryInfoQe1.eq("type_id", lexicon.getId());
  419. libraryInfoQe1.in("name", addConceptInfoVO.getDetailList().stream().map(i -> i.getName()).collect(Collectors.toList()));
  420. List<LibraryInfo> libraryInfoList = libraryinfoFacade.list(libraryInfoQe1);
  421. String currentUser = UserUtils.getCurrentPrincipleID();
  422. Date now = DateUtil.now();
  423. Map<String, LibraryInfo> libraryInfoMap = libraryInfoList.stream().collect(Collectors.toMap(LibraryInfo::getName, i -> i));
  424. LibraryInfo libraryInfoMain = libraryInfoMap.get(addConceptInfoDetailVOMain.getName());
  425. Concept concept = new Concept();
  426. Long conceptId = null;
  427. if (libraryInfoMain == null) {
  428. libraryInfoMain = new LibraryInfo();
  429. BeanUtil.copyProperties(addConceptInfoDetailVOMain, libraryInfoMain);
  430. libraryInfoMain.setGmtCreate(now);
  431. libraryInfoMain.setCreator(currentUser);
  432. libraryInfoMain.setTypeId(lexicon.getId());
  433. libraryinfoFacade.save(libraryInfoMain);
  434. concept.setLibId(libraryInfoMain.getId());
  435. concept.setLibName(addConceptInfoDetailVOMain.getName());
  436. concept.setLibType(lexicon.getId());
  437. concept.setGmtCreate(now);
  438. concept.setCreator(currentUser);
  439. concept.setId(addConceptInfoVO.getConceptId());
  440. saveOrUpdate(concept);
  441. conceptId = concept.getId();
  442. } else {
  443. conceptId = libraryInfoMain.getConceptId();
  444. int ckConceptId = conceptId.intValue();
  445. concept = getById(conceptId);
  446. //如果标准词之前作为同义词被其他占用的情况
  447. if (libraryInfoMain.getIsConcept() == 1) {
  448. //新增操作时,已经建立的标准词提示
  449. if (addConceptInfoVO.getLineNum() == null && addConceptInfoVO.getConceptId() == null) {
  450. if (concept.getIsDeleted().equals("N")) {
  451. throw new CommonException(CommonErrorCode.RPC_ERROR, "该数据已经建立!");
  452. } else {
  453. throw new CommonException(CommonErrorCode.RPC_ERROR, "该数据已经建立且处于已删除状态,可前往列表中恢复该条数据!");
  454. }
  455. }
  456. } else if (addConceptInfoVO.getLineNum() == null && addConceptInfoVO.getConceptId() == null && concept != null
  457. || libraryInfoList.stream().filter(i -> i.getConceptId().intValue() == ckConceptId).count() == 1) {
  458. throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "标准术语已作为同义词被占用!");
  459. }
  460. }
  461. //先删除概念下的同义词,后续再插入
  462. QueryWrapper<LibraryInfo> libraryInfoQe2 = new QueryWrapper<>();
  463. libraryInfoQe2.eq("concept_id", conceptId);
  464. libraryInfoQe2.ne("id", libraryInfoMain.getId());
  465. libraryinfoFacade.remove(libraryInfoQe2);
  466. StringBuffer sbf = new StringBuffer();
  467. for (AddConceptInfoDetailVO i : addConceptInfoVO.getDetailList()) {
  468. if (i.getIsConcept() == 1) {
  469. continue;
  470. }
  471. LibraryInfo libraryInfo = libraryInfoMap.get(i.getName());
  472. if (libraryInfo == null) {
  473. libraryInfo = new LibraryInfo();
  474. libraryInfo.setGmtCreate(now);
  475. libraryInfo.setCreator(currentUser);
  476. } else if (libraryInfo.getConceptId().intValue() != conceptId.intValue()) {
  477. sbf.append(i.getName()).append(" ");
  478. continue;
  479. }
  480. libraryInfo.setName(i.getName());
  481. libraryInfo.setSpell(i.getSpell());
  482. libraryInfo.setRemark(i.getRemark());
  483. saveOrUpdateLibraryInfoList.add(libraryInfo);
  484. }
  485. if (sbf.length() > 0) {
  486. sbf.append("已被占用");
  487. throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
  488. }
  489. for (LibraryInfo i : saveOrUpdateLibraryInfoList) {
  490. i.setId(null);
  491. i.setConceptId(conceptId);
  492. i.setTypeId(lexicon.getId());
  493. i.setIsConcept(0);
  494. i.setGmtModified(now);
  495. i.setModifier(currentUser);
  496. }
  497. libraryInfoMain.setIsConcept(1);
  498. libraryInfoMain.setRemark(addConceptInfoDetailVOMain.getRemark());
  499. libraryInfoMain.setSpell(libraryInfoMain.getSpell());
  500. libraryInfoMain.setConceptId(conceptId);
  501. libraryInfoMain.setGmtModified(now);
  502. libraryInfoMain.setModifier(currentUser);
  503. saveOrUpdateLibraryInfoList.add(libraryInfoMain);
  504. libraryInfoService.saveOrUpdateBatch(saveOrUpdateLibraryInfoList);
  505. concept.setId(conceptId);
  506. concept.setLibId(libraryInfoMain.getId());
  507. concept.setLibName(libraryInfoMain.getName());
  508. concept.setLibType(libraryInfoMain.getTypeId());
  509. concept.setGmtModified(now);
  510. concept.setModifier(currentUser);
  511. updateById(concept);
  512. if (lexicon.getIsHasCommon() == 1) {
  513. QueryWrapper<ConceptCommon> conceptCommonQe = new QueryWrapper<>();
  514. conceptCommonQe.eq("concept_id", conceptId);
  515. ConceptCommon conceptCommon = conceptCommonFacade.getOne(conceptCommonQe);
  516. if (conceptCommon == null) {
  517. conceptCommon = new ConceptCommon();
  518. conceptCommon.setGmtCreate(now);
  519. conceptCommon.setCreator(currentUser);
  520. }
  521. BeanUtil.copyProperties(addConceptInfoVO, conceptCommon);
  522. conceptCommon.setConceptId(conceptId);
  523. conceptCommon.setGmtModified(now);
  524. conceptCommon.setModifier(currentUser);
  525. conceptCommonFacade.saveOrUpdate(conceptCommon);
  526. }
  527. return true;
  528. }
  529. /**
  530. * 医学术语命名excel文件导入
  531. *
  532. * @param file
  533. * @return
  534. */
  535. public Boolean conceptInfoExcelIm(MultipartFile file) {
  536. List<AddConceptInfoVO> addConceptInfoVOList = new ArrayList<>();
  537. StringBuffer sbf = new StringBuffer();
  538. InputStream inputStream = null;
  539. Workbook wb = null;
  540. try {
  541. if (!file.isEmpty()) {
  542. inputStream = file.getInputStream();
  543. if (inputStream.available() > 512000) {
  544. sbf.append("文件最大支持500KB!").append("<br/>");
  545. } else {
  546. String fileName = file.getOriginalFilename();
  547. if (fileName.lastIndexOf(".") != -1) {
  548. String type = fileName.substring(fileName.lastIndexOf("."));
  549. if (type.equals(".xls")) {
  550. wb = new HSSFWorkbook(inputStream);
  551. } else if (type.equals(".xlsx")) {
  552. wb = new XSSFWorkbook(inputStream);
  553. }
  554. if (wb != null) {
  555. Sheet sheet = wb.getSheetAt(0);
  556. int count = 0;
  557. String libName, libType, otherNames, remark, sexType, minAge, maxAge;
  558. //String regEx = "[0-9]+|[`~·!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]+";
  559. String regEx = "[0-9]+";
  560. String regExAge = "[0-9]|[1-9][0-9]|1[0-9]{2}|200";
  561. for (Row row : sheet) {
  562. count++;
  563. if (row == null) {
  564. continue;
  565. }
  566. // if (count == 1) {
  567. // title_1 = getValue(row.getCell(0)).trim().replace(" ", "");
  568. // title_2 = getValue(row.getCell(1)).trim().replace(" ", "");
  569. // title_3 = getValue(row.getCell(2)).trim().replace(" ", "");
  570. // title_4 = getValue(row.getCell(3)).trim().replace(" ", "");
  571. // continue;
  572. // }
  573. libName = getValue(row.getCell(0)).trim().replace(" ", "");
  574. libType = getValue(row.getCell(1)).trim().replace(" ", "");
  575. otherNames = getValue(row.getCell(2)).trim().replace(" ", "");
  576. remark = getValue(row.getCell(3)).trim().replace(" ", "");
  577. sexType = getValue(row.getCell(4)).trim().replace(" ", "");
  578. minAge = getValue(row.getCell(5)).trim().replace(" ", "");
  579. maxAge = getValue(row.getCell(6)).trim().replace(" ", "");
  580. if(count == 1){
  581. //当前行是第一行时,libName、libType、otherNames、remark、sexType、minAge、maxAge是标题
  582. if (libName.indexOf("标准术语") == -1
  583. || libType.indexOf("类型") == -1
  584. || otherNames.indexOf("术语同义词") == -1
  585. || remark.indexOf("标准术语说明") == -1
  586. || sexType.indexOf("性别") == -1
  587. || minAge.indexOf("最小年龄") == -1
  588. || maxAge.indexOf("最大年龄") == -1) {
  589. sbf.append("导入数据不正确,请选择正确数据导入!").append("<br/>");
  590. break;
  591. }else{
  592. continue;
  593. }
  594. }
  595. if (StringUtil.isEmpty(libName) && StringUtil.isEmpty(libType)
  596. && StringUtil.isEmpty(otherNames) && StringUtil.isEmpty(remark)) {
  597. continue;
  598. }
  599. if (StringUtil.isEmpty(libName) || StringUtil.isEmpty(libType) || StringUtil.isEmpty(otherNames)) {
  600. sbf.append("第" + count + "行数据不完整;").append("<br/>");
  601. continue;
  602. }
  603. if (StringUtil.isNotEmpty(remark) && remark.length() > 120) {
  604. sbf.append("第" + count + "行导入错误,说明最大可输入120个字;").append("<br/>");
  605. continue;
  606. }
  607. if (StringUtil.isNotEmpty(sexType) && !sexType.matches("男|女|通用")) {
  608. sbf.append("第" + count + "行导入错误,性别须是男、女或者通用;").append("<br/>");
  609. }
  610. if ((StringUtil.isNotEmpty(minAge) && !minAge.matches(regExAge))
  611. || (StringUtil.isNotEmpty(maxAge) && !maxAge.matches(regExAge))) {
  612. sbf.append("第" + count + "行导入错误,年龄须是0-200;").append("<br/>");
  613. continue;
  614. }
  615. if (StringUtil.isNotEmpty(minAge)
  616. && StringUtil.isNotEmpty(maxAge)
  617. && Integer.parseInt(minAge) > Integer.parseInt(maxAge)) {
  618. sbf.append("第" + count + "行导入错误,症状发生的最小年龄大于症状发生的最大年龄;").append("<br/>");
  619. continue;
  620. }
  621. AddConceptInfoVO addConceptInfoVO = new AddConceptInfoVO();
  622. addConceptInfoVO.setLineNum(count);
  623. addConceptInfoVO.setName(libName);
  624. addConceptInfoVO.setType(libType);
  625. addConceptInfoVO.setMinAge(StringUtil.isEmpty(minAge)?0:Integer.parseInt(minAge));
  626. addConceptInfoVO.setMaxAge(StringUtil.isEmpty(minAge)?200:Integer.parseInt(maxAge));
  627. if (sexType.equals("男")) {
  628. addConceptInfoVO.setSexType(1);
  629. } else if (sexType.equals("女")) {
  630. addConceptInfoVO.setSexType(2);
  631. } else {
  632. addConceptInfoVO.setSexType(3);
  633. }
  634. List<AddConceptInfoDetailVO> detailList = new ArrayList<>();
  635. for (String nm : otherNames.split(",")) {
  636. if (StringUtil.isBlank(nm)) {
  637. continue;
  638. }
  639. if (nm.matches(regEx)) {
  640. sbf.append("第" + count + "行无法导入,导入数据无法为纯数字;").append("<br/>");
  641. break;
  642. }
  643. if (nm.length() > 30) {
  644. sbf.append("第" + count + "行导入错误,标准词和同义词最大字数不可超过30个字;").append("<br/>");
  645. break;
  646. }
  647. AddConceptInfoDetailVO addConceptInfoDetailVO = new AddConceptInfoDetailVO();
  648. addConceptInfoDetailVO.setName(nm);
  649. addConceptInfoDetailVO.setType(libType);
  650. addConceptInfoDetailVO.setSpell(Cn2SpellUtil.converterToFirstSpell(nm));
  651. if (libName.equals(nm)) {
  652. addConceptInfoDetailVO.setIsConcept(1);
  653. addConceptInfoDetailVO.setRemark(remark);
  654. } else {
  655. addConceptInfoDetailVO.setIsConcept(0);
  656. }
  657. detailList.add(addConceptInfoDetailVO);
  658. }
  659. addConceptInfoVO.setDetailList(detailList);
  660. addConceptInfoVOList.add(addConceptInfoVO);
  661. }
  662. } else {
  663. sbf.append("非excel文件无法解析!").append("<br/>");
  664. }
  665. } else {
  666. sbf.append("未知文件无法解析!").append("<br/>");
  667. }
  668. }
  669. } else {
  670. sbf.append("无文件上传!").append("<br/>");
  671. }
  672. } catch (Exception e) {
  673. sbf.append("解析失败!").append("<br/>");
  674. } finally {
  675. try {
  676. if (wb != null) {
  677. wb.close();
  678. }
  679. if (inputStream != null) {
  680. inputStream.close();
  681. }
  682. } catch (Exception e) {
  683. }
  684. }
  685. /*****************excel文件本身问题提醒************************/
  686. if (sbf.length() > 0) {
  687. throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
  688. }
  689. // /**********************非规范的excel导入提醒*****************************************/
  690. // if (title_1.indexOf("标准术语") == -1
  691. // || title_2.indexOf("类型") == -1
  692. // || title_3.indexOf("术语同义词") == -1
  693. // || title_4.indexOf("标准术语说明") == -1) {
  694. // throw new CommonException(CommonErrorCode.RPC_ERROR, "导入数据不正确,请选择正确数据导入!");
  695. // }
  696. /****************************导入空文件************************/
  697. if (addConceptInfoVOList.size() == 0) {
  698. throw new CommonException(CommonErrorCode.RPC_ERROR, "导入数据不能为空!");
  699. }
  700. if(addConceptInfoVOList.size() > 5000){
  701. throw new CommonException(CommonErrorCode.RPC_ERROR, "当前数据导入失败,单次导入最多可支持5千条数据导入");
  702. }
  703. /****************excel文件中所有术语存在重复提示---名字和类型一样即重复***********************/
  704. List<AddConceptInfoDetailVO> addConceptInfoDetailVOList = new ArrayList<>();
  705. addConceptInfoVOList.forEach(i -> {
  706. addConceptInfoDetailVOList.addAll(i.getDetailList());
  707. });
  708. Map<String, List<AddConceptInfoDetailVO>> addConceptInfoDetailVOListMap = addConceptInfoDetailVOList.stream().collect(Collectors.groupingBy(AddConceptInfoDetailVO::getName));
  709. for (String key : addConceptInfoDetailVOListMap.keySet()) {
  710. if (addConceptInfoDetailVOListMap.get(key).size() > 1 && addConceptInfoDetailVOListMap.get(key).stream().map(i -> i.getType()).distinct().count() == 1) {
  711. sbf.append(key).append(" ");
  712. }
  713. }
  714. if (sbf.length() > 0) {
  715. sbf.append("数据重复,请修改导入数据!");
  716. throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
  717. }
  718. /*
  719. * 原来的
  720. * addConceptInfoVOList.forEach(i -> {
  721. addConceptInfo(i);
  722. });*/
  723. ////优化后
  724. QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
  725. libraryInfoQe.in("name", addConceptInfoDetailVOList.stream().map(i->i.getName()).distinct().collect(Collectors.toList()));
  726. Map<String,List<LibraryInfo>> libraryInfoListMap = libraryinfoFacade.list(libraryInfoQe).stream().collect(Collectors.groupingBy(LibraryInfo::getName));
  727. addConceptInfoVOList.forEach(i -> {
  728. i = checkImConceptInfo(i,libraryInfoListMap);
  729. });
  730. saveAddConceptInfoVOList(addConceptInfoVOList);
  731. return true;
  732. }
  733. /**
  734. * 导入数据插入更新前校验
  735. * @param addConceptInfoVO
  736. * @param libraryInfoListAllMap
  737. * @return
  738. */
  739. public AddConceptInfoVO checkImConceptInfo(AddConceptInfoVO addConceptInfoVO,Map<String,List<LibraryInfo>> libraryInfoListAllMap) {
  740. String currentUser = UserUtils.getCurrentPrincipleID();
  741. Date now = DateUtil.now();
  742. Concept concept = new Concept();
  743. ConceptCommon conceptCommon = new ConceptCommon();
  744. conceptCommon.setSexType(addConceptInfoVO.getSexType());
  745. conceptCommon.setMinAge(addConceptInfoVO.getMinAge());
  746. conceptCommon.setMaxAge(addConceptInfoVO.getMaxAge());
  747. conceptCommon.setGmtModified(now);
  748. conceptCommon.setModifier(currentUser);
  749. List<LibraryInfo> libraryInfoList = Lists.newArrayList();
  750. String lineNumStr = "第" + addConceptInfoVO.getLineNum() + "行";
  751. List<AddConceptInfoDetailVO> addConceptInfoDetailVOMainList = addConceptInfoVO.getDetailList().stream().filter(i -> i.getIsConcept() == 1).collect(Collectors.toList());
  752. if (addConceptInfoDetailVOMainList.size() == 0) {
  753. throw new CommonException(CommonErrorCode.PARAM_IS_NULL, lineNumStr + "无标准术语!");
  754. }
  755. if (addConceptInfoDetailVOMainList.size() > 1) {
  756. throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, lineNumStr + "标准术语只能有一个!");
  757. }
  758. Integer typeId_ = LexiconTypeEnum.getKey(addConceptInfoVO.getType());
  759. if (typeId_ == null) {
  760. throw new CommonException(CommonErrorCode.NOT_EXISTS, lineNumStr + "数据有误,该类型信息在数据库中不存在!");
  761. }
  762. Long typeId = typeId_.longValue();
  763. concept.setLibType(typeId);
  764. concept.setGmtModified(now);
  765. concept.setModifier(currentUser);
  766. List<LibraryInfo> extLibraryInfoList = Lists.newArrayList();
  767. addConceptInfoVO.getDetailList().forEach(a->{
  768. List<LibraryInfo> libraryInfoListAll = libraryInfoListAllMap.get(a.getName());
  769. if(libraryInfoListAll!=null){
  770. libraryInfoListAll = libraryInfoListAll.stream().filter(b->b.getTypeId().intValue()==typeId.intValue()).collect(Collectors.toList());
  771. if(libraryInfoListAll!=null){
  772. extLibraryInfoList.add(libraryInfoListAll.get(0));
  773. }
  774. }
  775. });
  776. Map<String, LibraryInfo> extLibraryInfoMap = extLibraryInfoList.stream().collect(Collectors.toMap(LibraryInfo::getName, i -> i));
  777. LibraryInfo libraryInfoMain = extLibraryInfoMap.get(addConceptInfoDetailVOMainList.get(0).getName());
  778. Long conceptId = null;
  779. if (libraryInfoMain == null) {
  780. conceptId = -9999l;
  781. concept.setGmtCreate(now);
  782. concept.setCreator(currentUser);
  783. conceptCommon.setGmtCreate(now);
  784. conceptCommon.setCreator(currentUser);
  785. } else {
  786. conceptId = libraryInfoMain.getConceptId();
  787. concept.setId(conceptId);
  788. addConceptInfoVO.setConceptId(conceptId);
  789. if (libraryInfoMain.getIsConcept()!=1&&extLibraryInfoList.stream().filter(i -> i.getConceptId().intValue() == libraryInfoMain.getConceptId().intValue()).count() == 1) {
  790. throw new CommonException(CommonErrorCode.RPC_ERROR, lineNumStr + "标准术语已作为同义词被占用!");
  791. }
  792. }
  793. StringBuffer sbf = new StringBuffer();
  794. for (AddConceptInfoDetailVO i : addConceptInfoVO.getDetailList()) {
  795. LibraryInfo libraryInfo = extLibraryInfoMap.get(i.getName());
  796. if (libraryInfo == null) {
  797. libraryInfo = new LibraryInfo();
  798. libraryInfo.setTypeId(typeId);
  799. libraryInfo.setGmtCreate(now);
  800. libraryInfo.setCreator(currentUser);
  801. } else if (libraryInfo.getConceptId().intValue() != conceptId.intValue()) {
  802. sbf.append(i.getName()).append(" ");
  803. continue;
  804. }
  805. BeanUtil.copyProperties(i, libraryInfo);
  806. libraryInfo.setId(null);
  807. libraryInfo.setConceptId(conceptId);
  808. libraryInfo.setGmtModified(now);
  809. libraryInfo.setModifier(currentUser);
  810. if(i.getIsConcept()==1){
  811. libraryInfoList.add(0,libraryInfo);
  812. }else{
  813. libraryInfoList.add(libraryInfo);
  814. }
  815. }
  816. if (sbf.length() > 0) {
  817. sbf.append("已被占用");
  818. throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
  819. }
  820. addConceptInfoVO.setConcept(concept);
  821. addConceptInfoVO.setConceptCommon(conceptCommon);
  822. addConceptInfoVO.setLibraryInfoList(libraryInfoList);
  823. return addConceptInfoVO;
  824. }
  825. /**
  826. * 导入数据插入更新
  827. * @param addConceptInfoVOList
  828. */
  829. private void saveAddConceptInfoVOList(List<AddConceptInfoVO> addConceptInfoVOList){
  830. List<Long> conceptIds = addConceptInfoVOList.stream().filter(i->i.getConceptId()!=null).map(i->i.getConceptId()).collect(Collectors.toList());
  831. if(ListUtil.isNotEmpty(conceptIds)){
  832. QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<>();
  833. libraryInfoQe.in("concept_id", conceptIds);
  834. libraryinfoFacade.remove(libraryInfoQe);
  835. }
  836. List<LibraryInfo> saveLibraryInfoList = Lists.newArrayList();
  837. addConceptInfoVOList.forEach(i->{
  838. saveLibraryInfoList.addAll(i.getLibraryInfoList());
  839. });
  840. libraryInfoService.saveBatch(saveLibraryInfoList);
  841. List<Concept> saveOrUpdateConceptList = Lists.newArrayList();
  842. addConceptInfoVOList.forEach(i->{
  843. i.getConcept().setLibId(i.getLibraryInfoList().get(0).getId());
  844. i.getConcept().setLibName(i.getLibraryInfoList().get(0).getName());
  845. saveOrUpdateConceptList.add(i.getConcept());
  846. });
  847. conceptService.saveOrUpdateBatch(saveOrUpdateConceptList);
  848. List<LibraryInfo> updateLibraryInfoList = Lists.newArrayList();
  849. addConceptInfoVOList.forEach(i->{
  850. if(i.getConceptId()==null){
  851. i.getLibraryInfoList().forEach(j->{
  852. j.setConceptId(i.getConcept().getId());
  853. });
  854. updateLibraryInfoList.addAll(i.getLibraryInfoList());
  855. }
  856. });
  857. if(ListUtil.isNotEmpty(updateLibraryInfoList)){
  858. libraryInfoService.updateBatchById(updateLibraryInfoList);
  859. }
  860. List<ConceptCommon> saveOrUpdateConceptCommonList = Lists.newArrayList();
  861. QueryWrapper<ConceptCommon> conceptCommonQe = new QueryWrapper<>();
  862. conceptCommonQe.in("concept_id", conceptIds);
  863. Map<Long,ConceptCommon> conceptCommonMap = conceptCommonFacade.list(conceptCommonQe).stream().collect(Collectors.toMap(ConceptCommon::getConceptId, i->i));
  864. addConceptInfoVOList.forEach(i->{
  865. if(i.getConceptId()!=null){
  866. i.getConceptCommon().setId(conceptCommonMap.get(i.getConceptId()).getId());
  867. }
  868. i.getConceptCommon().setConceptId(i.getConcept().getId());
  869. saveOrUpdateConceptCommonList.add(i.getConceptCommon());
  870. });
  871. conceptCommonService.saveOrUpdateBatch(saveOrUpdateConceptCommonList);
  872. }
  873. @SuppressWarnings("deprecation")
  874. private String getValue(Cell cell) {
  875. try {
  876. Object obj = null;
  877. switch (cell.getCellTypeEnum()) {
  878. case BOOLEAN:
  879. obj = cell.getBooleanCellValue();
  880. break;
  881. case ERROR:
  882. obj = cell.getErrorCellValue();
  883. break;
  884. case NUMERIC:
  885. if (HSSFDateUtil.isCellDateFormatted(cell)) {
  886. Date date = cell.getDateCellValue();
  887. obj = DateFormatUtils.format(date, "yyyy-MM-dd");
  888. } else {
  889. obj = cell.getNumericCellValue();
  890. DecimalFormat df = new DecimalFormat("0");
  891. obj = df.format(obj);
  892. }
  893. break;
  894. case STRING:
  895. obj = cell.getStringCellValue();
  896. break;
  897. default:
  898. break;
  899. }
  900. return obj.toString();
  901. } catch (Exception e) {
  902. return "";
  903. }
  904. }
  905. /**
  906. * 根据概念Id列表获取概念列表Map
  907. *
  908. * @param conceptSearchVO 搜索参数
  909. * @return 术语id和术语 Map
  910. */
  911. public Map<Long, String> getConceptMap(ConceptSearchVO conceptSearchVO) {
  912. //入参验证
  913. if (ListUtil.isEmpty(conceptSearchVO.getConceptIds())) {
  914. throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "术语列表不能为空");
  915. }
  916. //获取结构
  917. List<Concept> concepts
  918. = this.getListByIds(conceptSearchVO.getConceptIds());
  919. //出参封装
  920. Map<Long, String> map = new HashMap<>();
  921. if (ListUtil.isNotEmpty(concepts)) {
  922. map = concepts.stream().collect(Collectors.toMap(r -> r.getId(), r -> r.getLibName()));
  923. }
  924. return map;
  925. }
  926. /**
  927. * 根据概念Id列表获取概念列表
  928. *
  929. * @param ids
  930. * @return
  931. */
  932. public List<Concept> getListByIds(List<Long> ids) {
  933. QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
  934. conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
  935. if (ids.size() == 1) {
  936. conceptQueryWrapper.eq("id", ids.get(0));
  937. } else {
  938. conceptQueryWrapper.in("id", ids);
  939. }
  940. List<Concept> list = this.list(conceptQueryWrapper);
  941. return list;
  942. }
  943. /**
  944. * 根据类型获取术语列表(科室、辅检、慢病)
  945. *
  946. * @param conceptTypeVO 类型
  947. * @return 术语列表
  948. */
  949. public List<ConceptBaseDTO> getConceptListByType(ConceptTypeVO conceptTypeVO) {
  950. if (null == conceptTypeVO
  951. || IntegerUtil.isNull(conceptTypeVO.getType())) {
  952. throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "类型不能为空");
  953. }
  954. List<ConceptBaseDTO> res = ListUtil.newArrayList();
  955. switch (conceptTypeVO.getType()) {
  956. case 1:
  957. res = getConceptByType(LexiconTypeEnum.DEPARTMENT.getKey());
  958. break;
  959. case 2:
  960. res = getConceptByType(LexiconTypeEnum.PACS_ITEMS.getKey());
  961. break;
  962. case 3:
  963. res = getConceptChronic();
  964. break;
  965. default:
  966. throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "类型超出范围以外");
  967. }
  968. return res;
  969. }
  970. /**
  971. * 获取慢病列表
  972. *
  973. * @return 慢病列表
  974. */
  975. private List<ConceptBaseDTO> getConceptChronic() {
  976. ConceptWrapper conceptWrapper = new ConceptWrapper();
  977. conceptWrapper.setStartType(LexiconTypeEnum.DIAGNOSIS.getKey());
  978. conceptWrapper.setRelationType(LexiconRSTypeEnum.INCLUDE_OF.getKey());
  979. conceptWrapper.setEndName("慢病");
  980. List<ConceptRes> list = this.getConcept(conceptWrapper);
  981. List<ConceptBaseDTO> res = ListUtil.newArrayList();
  982. if (ListUtil.isNotEmpty(list)) {
  983. for (ConceptRes concept : list) {
  984. ConceptBaseDTO conceptBaseDTO = new ConceptBaseDTO();
  985. conceptBaseDTO.setConceptId(concept.getStartId());
  986. conceptBaseDTO.setName(concept.getStartName());
  987. res.add(conceptBaseDTO);
  988. }
  989. }
  990. return res;
  991. }
  992. /**
  993. * 根据类型获取术语列表(科室、辅检)
  994. *
  995. * @param libType
  996. * @return
  997. */
  998. private List<ConceptBaseDTO> getConceptByType(Integer libType) {
  999. QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
  1000. conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  1001. .in("lib_Type", libType);
  1002. List<Concept> list = this.list(conceptQueryWrapper);
  1003. List<ConceptBaseDTO> res = ListUtil.newArrayList();
  1004. if (ListUtil.isNotEmpty(list)) {
  1005. for (Concept concept : list) {
  1006. ConceptBaseDTO conceptBaseDTO = new ConceptBaseDTO();
  1007. conceptBaseDTO.setConceptId(concept.getId());
  1008. conceptBaseDTO.setName(concept.getLibName());
  1009. res.add(conceptBaseDTO);
  1010. }
  1011. }
  1012. return res;
  1013. }
  1014. /**
  1015. * 根据名称和类型获取概念列表Map
  1016. *
  1017. * @param conceptExistVO 搜索参数
  1018. * @return 术语id和术语 Map
  1019. */
  1020. public Map<String, List<Integer>> getConceptMap(ConceptExistVO conceptExistVO) {
  1021. // 入参验证
  1022. if (ListUtil.isEmpty(conceptExistVO.getNameList())) {
  1023. throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "名称列表不能为空");
  1024. }
  1025. if (conceptExistVO.getType() != null) {
  1026. // 如果是化验明细项,直接赋值
  1027. if (conceptExistVO.getIsLisDetail() == true) {
  1028. conceptExistVO.setLibType(LexiconTypeEnum.LIS_DETAILS.getKey());
  1029. } else {
  1030. Integer libType = ParamConvertUtil.conceptConvert2Lib(conceptExistVO.getType());
  1031. if (libType == null) {
  1032. throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "类型不匹配");
  1033. }
  1034. conceptExistVO.setLibType(libType);
  1035. }
  1036. }
  1037. //获取结构
  1038. List<Concept> concepts
  1039. = this.getListByNamesAndType(conceptExistVO.getNameList(), conceptExistVO.getLibType());
  1040. Map<String, List<Concept>> map1 = EntityUtil.makeEntityListMap(concepts, "libName");
  1041. Map<String, List<Integer>> typeMap = new HashMap<>();
  1042. for (String key : map1.keySet()) {
  1043. List<Concept> list = map1.get(key);
  1044. List<Integer> typeList = new ArrayList<>();
  1045. if (ListUtil.isNotEmpty(list)) {
  1046. for (Concept c : list) {
  1047. Integer type = ParamConvertUtil.libConvert2Concept(c.getLibType().intValue());
  1048. if (type != null) {
  1049. typeList.add(type);
  1050. }
  1051. }
  1052. typeMap.put(key, typeList);
  1053. }
  1054. }
  1055. return typeMap;
  1056. }
  1057. /**
  1058. * 根据名称和词性获取概念列表
  1059. *
  1060. * @param nameList
  1061. * @param libType
  1062. * @return
  1063. */
  1064. public List<Concept> getListByNamesAndType(List<String> nameList, Integer libType) {
  1065. QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
  1066. conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  1067. .in("lib_name", nameList);
  1068. if (libType != null) {
  1069. conceptQueryWrapper.eq("lib_type", libType);
  1070. }
  1071. List<Concept> list = this.list(conceptQueryWrapper);
  1072. return list;
  1073. }
  1074. public List<ConceptBaseDTO> indexFac(IndexVO indexVO) {
  1075. // 类型转换
  1076. Integer libType = ParamConvertUtil.conceptConvert2Lib(indexVO.getType());
  1077. if (libType == null) {
  1078. throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "类型不匹配");
  1079. }
  1080. indexVO.setLibType(libType);
  1081. return this.index(indexVO);
  1082. }
  1083. public List<ConceptBaseDTO> indexByLexiconFac(IndexLexiconVO indexLexiconVO) {
  1084. return this.indexByLexicon(indexLexiconVO);
  1085. }
  1086. /**
  1087. * 根据概念Id列表获取概念列表Map
  1088. *
  1089. * @param conceptSearchVO 搜索参数
  1090. * @return 术语id和术语 Map
  1091. */
  1092. public Map<Long, String> getConceptNameMap(ConceptSearchVO conceptSearchVO) {
  1093. //入参验证
  1094. if (ListUtil.isEmpty(conceptSearchVO.getConceptIds())) {
  1095. throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "术语列表不能为空");
  1096. }
  1097. //获取结构
  1098. List<Concept> concepts
  1099. = this.getListByIds(conceptSearchVO.getConceptIds());
  1100. //出参封装
  1101. Map<Long, String> map = new HashMap<>();
  1102. if (ListUtil.isNotEmpty(concepts)) {
  1103. map = concepts.stream().collect(Collectors.toMap(r -> r.getId(), r -> r.getLibName()));
  1104. }
  1105. return map;
  1106. }
  1107. public Boolean piyinUp() {
  1108. Boolean res = false;
  1109. QueryWrapper<LibraryInfo> libraryInfoQueryWrapper = new QueryWrapper<>();
  1110. libraryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  1111. .isNull("spell");
  1112. List<LibraryInfo> list = libraryInfoService.list(libraryInfoQueryWrapper);
  1113. if (ListUtil.isNotEmpty(list)) {
  1114. Date now = DateUtil.now();
  1115. for (LibraryInfo libraryInfo : list) {
  1116. libraryInfo.setSpell(Cn2SpellUtil.converterToFirstSpell(libraryInfo.getName()));
  1117. libraryInfo.setGmtModified(now);
  1118. }
  1119. List<List<LibraryInfo>> listList = SqlExecuteUtil.divideList(list, 200);
  1120. int i = 0;
  1121. for (List<LibraryInfo> libraryInfoList : listList){
  1122. res = libraryInfoService.updateBatchById(libraryInfoList);
  1123. i++;
  1124. }
  1125. System.out.println("批量更新拼音"+ i +"次!");
  1126. }
  1127. return res;
  1128. }
  1129. /**
  1130. * 模板维护辅检检索
  1131. *
  1132. * @param getConceptPacInfosVO
  1133. * @return
  1134. */
  1135. public List<ConceptBaseDTO> getConceptPacInfos(GetConceptPacInfosVO getConceptPacInfosVO){
  1136. QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
  1137. conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  1138. .eq("lib_type", LexiconTypeEnum.PACS_ITEMS.getKey())
  1139. .like("lib_name", getConceptPacInfosVO.getInputStr());
  1140. List<Concept> list = this.list(conceptQueryWrapper);
  1141. List<ConceptBaseDTO> res = ListUtil.newArrayList();
  1142. if (ListUtil.isNotEmpty(list)) {
  1143. for (Concept concept : list) {
  1144. ConceptBaseDTO conceptBaseDTO = new ConceptBaseDTO();
  1145. conceptBaseDTO.setConceptId(concept.getId());
  1146. conceptBaseDTO.setName(concept.getLibName());
  1147. res.add(conceptBaseDTO);
  1148. }
  1149. }
  1150. return res;
  1151. }
  1152. }