|
@@ -0,0 +1,496 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.client.CdssCoreClient;
|
|
|
+import com.diagbot.dto.IndexBatchDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.dto.TcmdiseaseInfoDTO;
|
|
|
+import com.diagbot.entity.TcmdiseaseConfig;
|
|
|
+import com.diagbot.entity.TcmsyndromeConfig;
|
|
|
+import com.diagbot.enums.ConceptTypeEnum;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.TcmdiseaseConfigService;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ExcelUtils;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.util.SysUserUtils;
|
|
|
+import com.diagbot.vo.ConceptVO;
|
|
|
+import com.diagbot.vo.IdListVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.diagbot.vo.RetrievalVO;
|
|
|
+import com.diagbot.vo.TcmdiseaseConfigListVO;
|
|
|
+import com.diagbot.vo.TcmdiseaseConfigPageVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhaops
|
|
|
+ * @time: 2021/5/13 15:07
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class TcmdiseaseConfigFacade {
|
|
|
+ @Autowired
|
|
|
+ private TcmdiseaseConfigService tcmdiseaseConfigService;
|
|
|
+ @Autowired
|
|
|
+ private CdssCoreClient cdssCoreClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否已存在
|
|
|
+ *
|
|
|
+ * @param tcmdiseaseConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isExistRecord(TcmdiseaseConfig tcmdiseaseConfig) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ QueryWrapper<TcmdiseaseConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", Long.valueOf(hospitalId))
|
|
|
+ .eq("his_name", tcmdiseaseConfig.getHisName())
|
|
|
+ .eq("unique_name", tcmdiseaseConfig.getUniqueName());
|
|
|
+ TcmdiseaseConfig oldRecord = tcmdiseaseConfigService.getOne(queryWrapper, false);
|
|
|
+ if (tcmdiseaseConfig.getId() == null
|
|
|
+ && oldRecord != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法添加");
|
|
|
+ }
|
|
|
+ if (tcmdiseaseConfig.getId() != null
|
|
|
+ && oldRecord != null
|
|
|
+ && !tcmdiseaseConfig.getId().equals(oldRecord.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-单条
|
|
|
+ *
|
|
|
+ * @param tcmdiseaseConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecord(TcmdiseaseConfig tcmdiseaseConfig) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ tcmdiseaseConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ tcmdiseaseConfig.setModifier(userId);
|
|
|
+ tcmdiseaseConfig.setGmtModified(now);
|
|
|
+ QueryWrapper<TcmdiseaseConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", Long.valueOf(hospitalId))
|
|
|
+ .eq("his_name", tcmdiseaseConfig.getHisName())
|
|
|
+ .eq("unique_name", tcmdiseaseConfig.getUniqueName());
|
|
|
+ TcmdiseaseConfig oldRecord = tcmdiseaseConfigService.getOne(queryWrapper, false);
|
|
|
+ if (tcmdiseaseConfig.getId() == null
|
|
|
+ && oldRecord != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法添加");
|
|
|
+ }
|
|
|
+ if (tcmdiseaseConfig.getId() != null
|
|
|
+ && oldRecord != null
|
|
|
+ && !tcmdiseaseConfig.getId().equals(oldRecord.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ //新增数据
|
|
|
+ if (tcmdiseaseConfig.getId() == null) {
|
|
|
+ tcmdiseaseConfig.setCreator(userId);
|
|
|
+ tcmdiseaseConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (tcmdiseaseConfig.getIsDeleted() == null) {
|
|
|
+ tcmdiseaseConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ tcmdiseaseConfigService.saveOrUpdate(tcmdiseaseConfig);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-批量
|
|
|
+ *
|
|
|
+ * @param tcmdiseaseConfigListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(TcmdiseaseConfigListVO tcmdiseaseConfigListVO) {
|
|
|
+ if (ListUtil.isEmpty(tcmdiseaseConfigListVO.getTcmdiseaseConfigList())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return saveOrUpdateRecords(tcmdiseaseConfigListVO.getTcmdiseaseConfigList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量保存
|
|
|
+ *
|
|
|
+ * @param tcmdiseaseConfigList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(List<TcmdiseaseConfig> tcmdiseaseConfigList) {
|
|
|
+ if (ListUtil.isEmpty(tcmdiseaseConfigList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ //数据不完整的不保存
|
|
|
+ //过滤外部名称或公表名为空的数据
|
|
|
+ tcmdiseaseConfigList = tcmdiseaseConfigList
|
|
|
+ .stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ Map<String, Map<String, List<Long>>> configMap
|
|
|
+ = getConfigMapWithIds(Long.valueOf(hospitalId), null, null);
|
|
|
+ tcmdiseaseConfigList.forEach(tcmdiseaseConfig -> {
|
|
|
+ tcmdiseaseConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ tcmdiseaseConfig.setModifier(userId);
|
|
|
+ tcmdiseaseConfig.setGmtModified(now);
|
|
|
+ if (tcmdiseaseConfig.getId() == null) {
|
|
|
+ if (configMap.containsKey(tcmdiseaseConfig.getHisName())
|
|
|
+ && ListUtil.isNotEmpty(configMap.get(tcmdiseaseConfig.getHisName()).get(tcmdiseaseConfig.getUniqueName()))) {
|
|
|
+ deleteIds.addAll(configMap.get(tcmdiseaseConfig.getHisName()).get(tcmdiseaseConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ tcmdiseaseConfig.setCreator(userId);
|
|
|
+ tcmdiseaseConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (tcmdiseaseConfig.getIsDeleted() == null) {
|
|
|
+ tcmdiseaseConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //删除已存在映射关系
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ tcmdiseaseConfigService.saveOrUpdateBatch(tcmdiseaseConfigList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-单条
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecord(IdVO idVO) {
|
|
|
+ UpdateWrapper<TcmdiseaseConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", idVO.getId())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ tcmdiseaseConfigService.removeById(idVO.getId());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-批量
|
|
|
+ *
|
|
|
+ * @param idListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
+ if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ UpdateWrapper<TcmdiseaseConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.in("id", idListVO.getIds())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ tcmdiseaseConfigService.removeByIds(idListVO.getIds());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param tcmdiseaseConfigPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<TcmdiseaseConfig> getPage(TcmdiseaseConfigPageVO tcmdiseaseConfigPageVO) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ tcmdiseaseConfigPageVO.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ return tcmdiseaseConfigService.getPage(tcmdiseaseConfigPageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导入
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ */
|
|
|
+ public void importExcel(MultipartFile file) {
|
|
|
+ List<TcmdiseaseConfig> tcmdiseaseConfigList = ExcelUtils.importExcel(file, 0, 1, TcmdiseaseConfig.class);
|
|
|
+ if (ListUtil.isNotEmpty(tcmdiseaseConfigList)) {
|
|
|
+ importExcelRecords(tcmdiseaseConfigList);
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导入
|
|
|
+ *
|
|
|
+ * @param tcmdiseaseConfigList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean importExcelRecords(List<TcmdiseaseConfig> tcmdiseaseConfigList) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+
|
|
|
+ //1、数据完整性校验
|
|
|
+ //2、去除前后空格
|
|
|
+ //过滤空数据,保留重复数据,方便计行
|
|
|
+ tcmdiseaseConfigList = tcmdiseaseConfigList.stream()
|
|
|
+ .filter(TcmdiseaseConfig::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (ListUtil.isEmpty(tcmdiseaseConfigList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
+ }
|
|
|
+ List<String> emptyNumList = Lists.newLinkedList();
|
|
|
+ for (int i = 0; i < tcmdiseaseConfigList.size(); i++) {
|
|
|
+ if (StringUtil.isBlank(tcmdiseaseConfigList.get(i).getHisName())
|
|
|
+ || StringUtil.isBlank(tcmdiseaseConfigList.get(i).getUniqueName())) {
|
|
|
+ emptyNumList.add(String.valueOf(i + 2));
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(tcmdiseaseConfigList.get(i).getHisName())) {
|
|
|
+ tcmdiseaseConfigList.get(i).setHisName(tcmdiseaseConfigList.get(i).getHisName().trim());
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(tcmdiseaseConfigList.get(i).getUniqueName())) {
|
|
|
+ tcmdiseaseConfigList.get(i).setUniqueName(tcmdiseaseConfigList.get(i).getUniqueName().trim());
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(tcmdiseaseConfigList.get(i).getUniqueCode())) {
|
|
|
+ tcmdiseaseConfigList.get(i).setUniqueCode(tcmdiseaseConfigList.get(i).getUniqueCode().trim());
|
|
|
+ } else {
|
|
|
+ tcmdiseaseConfigList.get(i).setUniqueCode(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(emptyNumList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "以下行数(不计入空行)存在不完整数据:"
|
|
|
+ + emptyNumList.stream().collect(Collectors.joining("、"))
|
|
|
+ + "。导入取消,请修改后再试。\n");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
+ synchronized (this) {
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ Map<String, Map<String, List<Long>>> configMap
|
|
|
+ = getConfigMapWithIds(Long.valueOf(hospitalId), null, null);
|
|
|
+ tcmdiseaseConfigList.forEach(tcmdiseaseConfig -> {
|
|
|
+ tcmdiseaseConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ tcmdiseaseConfig.setModifier(userId);
|
|
|
+ tcmdiseaseConfig.setGmtModified(now);
|
|
|
+ if (tcmdiseaseConfig.getId() == null) {
|
|
|
+ if (configMap.containsKey(tcmdiseaseConfig.getHisName())
|
|
|
+ && ListUtil.isNotEmpty(configMap.get(tcmdiseaseConfig.getHisName()).get(tcmdiseaseConfig.getUniqueName()))) {
|
|
|
+ deleteIds.addAll(configMap.get(tcmdiseaseConfig.getHisName()).get(tcmdiseaseConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ tcmdiseaseConfig.setCreator(userId);
|
|
|
+ tcmdiseaseConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (tcmdiseaseConfig.getIsDeleted() == null) {
|
|
|
+ tcmdiseaseConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //标准术语校验
|
|
|
+ List<String> errorNumList = Lists.newLinkedList();
|
|
|
+ List<String> uniqueNames = tcmdiseaseConfigList.stream()
|
|
|
+ .map(i -> i.getUniqueName())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
+ conceptVO.setNames(uniqueNames);
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Tcmdisease.getKey());
|
|
|
+ RespDTO<List<IndexBatchDTO>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respDTO, "标准术语校验失败");
|
|
|
+ List<String> names = respDTO.data.stream().map(IndexBatchDTO::getName).collect(Collectors.toList());
|
|
|
+ for (int i = 0; i < tcmdiseaseConfigList.size(); i++) {
|
|
|
+ if (!names.contains(tcmdiseaseConfigList.get(i).getUniqueName())) {
|
|
|
+ errorNumList.add(String.valueOf(i + 2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(errorNumList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
+ "以下行数(不计空行)标准术语在数据库中不存在:"
|
|
|
+ + errorNumList.stream().collect(Collectors.joining("、"))
|
|
|
+ + "。导入取消,请修改后再试。");
|
|
|
+ }
|
|
|
+
|
|
|
+ //重复数据过滤
|
|
|
+ tcmdiseaseConfigList = tcmdiseaseConfigList
|
|
|
+ .stream()
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //删除已存在映射关系
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ tcmdiseaseConfigService.saveOrUpdateBatch(tcmdiseaseConfigList);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-公表名
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, Long>> getConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, Long>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<TcmdiseaseConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalId);
|
|
|
+ if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
+ queryWrapper.in("his_name", hisNames);
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
+ queryWrapper.in("unique_name", uniqueNames);
|
|
|
+ }
|
|
|
+ List<TcmdiseaseConfig> records = tcmdiseaseConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, List<TcmdiseaseConfig>> configMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<TcmdiseaseConfig>> entry : configMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ retMap.put(entry.getKey(), EntityUtil.makeMapWithKeyValue(entry.getValue(), "uniqueName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-公表名
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, List<Long>>> getConfigMapWithIds(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, List<Long>>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<TcmdiseaseConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalId);
|
|
|
+ if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
+ queryWrapper.in("his_name", hisNames);
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
+ queryWrapper.in("unique_name", uniqueNames);
|
|
|
+ }
|
|
|
+ List<TcmdiseaseConfig> records = tcmdiseaseConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, List<TcmdiseaseConfig>> configMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<TcmdiseaseConfig>> entry : configMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ Map<String, List<TcmdiseaseConfig>> subMap = EntityUtil.makeEntityListMap(entry.getValue(), "uniqueName");
|
|
|
+ Map<String, List<Long>> subIdMap = new HashMap<>();
|
|
|
+ for (Map.Entry<String, List<TcmdiseaseConfig>> subEntry : subMap.entrySet()) {
|
|
|
+ subIdMap.put(subEntry.getKey(), subEntry.getValue().stream().map(i -> i.getId()).distinct().collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ retMap.put(entry.getKey(), subIdMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系
|
|
|
+ * Map<uniqueName,Map<hisName,id>>
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, Long>> getUniqueNameConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, Long>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<TcmdiseaseConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalId);
|
|
|
+ if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
+ queryWrapper.in("his_name", hisNames);
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
+ queryWrapper.in("unique_name", uniqueNames);
|
|
|
+ }
|
|
|
+ List<TcmdiseaseConfig> records = tcmdiseaseConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<TcmdiseaseConfig>> uniqueNameMap = EntityUtil.makeEntityListMap(records, "uniqueName");
|
|
|
+ for (Map.Entry<String, List<TcmdiseaseConfig>> entry : uniqueNameMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ retMap.put(entry.getKey(), EntityUtil.makeMapWithKeyValue(entry.getValue(), "hisName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ public void exportExcel(HttpServletResponse response) {
|
|
|
+ QueryWrapper<TcmdiseaseConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", SysUserUtils.getCurrentHospitalID())
|
|
|
+ .orderByDesc("gmt_modified");
|
|
|
+ List<TcmdiseaseConfig> records = tcmdiseaseConfigService.list(queryWrapper);
|
|
|
+ String fileName = "中医疾病映射.xls";
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", TcmdiseaseConfig.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导入模板导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ public void exportExcelModule(HttpServletResponse response) {
|
|
|
+ String fileName = "中医疾病映射模板.xls";
|
|
|
+ ExcelUtils.exportExcel(new ArrayList<>(), null, "sheet1", TcmdiseaseConfig.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 中医疾病搜索
|
|
|
+ *
|
|
|
+ * @param retrievalVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<TcmdiseaseInfoDTO> getTcmdiseases(RetrievalVO retrievalVO) {
|
|
|
+ List<TcmdiseaseInfoDTO> tcmdiseaseNames = new ArrayList<>();
|
|
|
+ List<TcmdiseaseConfig> tcmdiseaseConfigList = tcmdiseaseConfigService.getTcmdiseasesIndex(retrievalVO);
|
|
|
+ for (TcmdiseaseConfig tcmdiseaseConfig : tcmdiseaseConfigList) {
|
|
|
+ TcmdiseaseInfoDTO tcmdiseaseInfoDTO = new TcmdiseaseInfoDTO();
|
|
|
+ tcmdiseaseInfoDTO.setCode(tcmdiseaseConfig.getUniqueCode());
|
|
|
+ tcmdiseaseInfoDTO.setName(tcmdiseaseConfig.getHisName());
|
|
|
+ tcmdiseaseNames.add(tcmdiseaseInfoDTO);
|
|
|
+ }
|
|
|
+ return tcmdiseaseNames;
|
|
|
+ }
|
|
|
+}
|