|
@@ -0,0 +1,597 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.client.CdssCoreClient;
|
|
|
+import com.diagbot.dto.HosRelationNumDTO;
|
|
|
+import com.diagbot.dto.IndexBatchDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+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.TcmsyndromeConfigService;
|
|
|
+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.UserUtils;
|
|
|
+import com.diagbot.vo.ConceptVO;
|
|
|
+import com.diagbot.vo.HosRelationNumPageVO;
|
|
|
+import com.diagbot.vo.HospitalIdVO;
|
|
|
+import com.diagbot.vo.IdListVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.diagbot.vo.TcmsyndromeConfigListVO;
|
|
|
+import com.diagbot.vo.TcmsyndromeConfigPageVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+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/14 11:04
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class TcmsyndromeConfigFacade {
|
|
|
+ @Autowired
|
|
|
+ private TcmsyndromeConfigService tcmsyndromeConfigService;
|
|
|
+ @Autowired
|
|
|
+ private CdssCoreClient cdssCoreClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否已存在
|
|
|
+ *
|
|
|
+ * @param tcmsyndromeConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isExistRecord(TcmsyndromeConfig tcmsyndromeConfig) {
|
|
|
+ QueryWrapper<TcmsyndromeConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", tcmsyndromeConfig.getHospitalId())
|
|
|
+ .eq("his_name", tcmsyndromeConfig.getHisName())
|
|
|
+ .eq("unique_name", tcmsyndromeConfig.getUniqueName());
|
|
|
+ TcmsyndromeConfig oldRecord = tcmsyndromeConfigService.getOne(queryWrapper, false);
|
|
|
+ if (tcmsyndromeConfig.getId() == null
|
|
|
+ && oldRecord != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ if (tcmsyndromeConfig.getId() != null
|
|
|
+ && oldRecord != null
|
|
|
+ && !tcmsyndromeConfig.getId().equals(oldRecord.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-单条
|
|
|
+ *
|
|
|
+ * @param tcmsyndromeConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecord(TcmsyndromeConfig tcmsyndromeConfig) {
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ tcmsyndromeConfig.setModifier(userId);
|
|
|
+ tcmsyndromeConfig.setGmtModified(now);
|
|
|
+ QueryWrapper<TcmsyndromeConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", tcmsyndromeConfig.getHospitalId())
|
|
|
+ .eq("his_name", tcmsyndromeConfig.getHisName())
|
|
|
+ .eq("unique_name", tcmsyndromeConfig.getUniqueName());
|
|
|
+ TcmsyndromeConfig oldRecord = tcmsyndromeConfigService.getOne(queryWrapper, false);
|
|
|
+ if (tcmsyndromeConfig.getId() == null
|
|
|
+ && oldRecord != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ if (tcmsyndromeConfig.getId() != null
|
|
|
+ && oldRecord != null
|
|
|
+ && !tcmsyndromeConfig.getId().equals(oldRecord.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ //新增数据
|
|
|
+ if (tcmsyndromeConfig.getId() == null) {
|
|
|
+ tcmsyndromeConfig.setCreator(userId);
|
|
|
+ tcmsyndromeConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (tcmsyndromeConfig.getIsDeleted() == null) {
|
|
|
+ tcmsyndromeConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ tcmsyndromeConfigService.saveOrUpdate(tcmsyndromeConfig);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-批量
|
|
|
+ *
|
|
|
+ * @param tcmsyndromeConfigListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(TcmsyndromeConfigListVO tcmsyndromeConfigListVO) {
|
|
|
+ if (ListUtil.isEmpty(tcmsyndromeConfigListVO.getTcmsyndromeConfigList())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return saveOrUpdateRecords(tcmsyndromeConfigListVO.getTcmsyndromeConfigList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量保存
|
|
|
+ *
|
|
|
+ * @param tcmsyndromeConfigList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(List<TcmsyndromeConfig> tcmsyndromeConfigList) {
|
|
|
+ if (ListUtil.isEmpty(tcmsyndromeConfigList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ //数据不完整的不保存
|
|
|
+ //过滤外部名称或公表名为空的数据
|
|
|
+ tcmsyndromeConfigList = tcmsyndromeConfigList
|
|
|
+ .stream()
|
|
|
+ .filter(i -> i.getHospitalId() != null)
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (ListUtil.isEmpty(tcmsyndromeConfigList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Long hospitalId = tcmsyndromeConfigList.get(0).getHospitalId();
|
|
|
+
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ Map<String, Map<String, List<Long>>> configMap
|
|
|
+ = getConfigMap(hospitalId, null, null);
|
|
|
+ tcmsyndromeConfigList.forEach(tcmsyndromeConfig -> {
|
|
|
+ tcmsyndromeConfig.setModifier(userId);
|
|
|
+ tcmsyndromeConfig.setGmtModified(now);
|
|
|
+ if (tcmsyndromeConfig.getId() == null) {
|
|
|
+ if (configMap.containsKey(tcmsyndromeConfig.getHisName())
|
|
|
+ && ListUtil.isNotEmpty(configMap.get(tcmsyndromeConfig.getHisName()).get(tcmsyndromeConfig.getUniqueName()))) {
|
|
|
+ deleteIds.addAll(configMap.get(tcmsyndromeConfig.getHisName()).get(tcmsyndromeConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ tcmsyndromeConfig.setCreator(userId);
|
|
|
+ tcmsyndromeConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (tcmsyndromeConfig.getIsDeleted() == null) {
|
|
|
+ tcmsyndromeConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //删除已存在映射关系
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ tcmsyndromeConfigService.saveOrUpdateBatch(tcmsyndromeConfigList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-单条
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecord(IdVO idVO) {
|
|
|
+ tcmsyndromeConfigService.removeById(idVO.getId());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-批量
|
|
|
+ *
|
|
|
+ * @param idListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
+ if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ tcmsyndromeConfigService.removeByIds(idListVO.getIds());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param tcmsyndromeConfigPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<TcmsyndromeConfig> getPage(TcmsyndromeConfigPageVO tcmsyndromeConfigPageVO) {
|
|
|
+ return tcmsyndromeConfigService.getPage(tcmsyndromeConfigPageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导入
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param hospitalIdVO
|
|
|
+ */
|
|
|
+ public void importExcel(MultipartFile file, HospitalIdVO hospitalIdVO) {
|
|
|
+ List<TcmsyndromeConfig> tcmsyndromeConfigList = ExcelUtils.importExcel(file, 0, 1, TcmsyndromeConfig.class);
|
|
|
+ if (ListUtil.isNotEmpty(tcmsyndromeConfigList)) {
|
|
|
+ importExcelRecords(tcmsyndromeConfigList, hospitalIdVO);
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导入
|
|
|
+ *
|
|
|
+ * @param tcmsyndromeConfigList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean importExcelRecords(List<TcmsyndromeConfig> tcmsyndromeConfigList, HospitalIdVO hospitalIdVO) {
|
|
|
+ Long hospitalId = hospitalIdVO.getHospitalId();
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ //1、数据完整性校验
|
|
|
+ //2、去除前后空格
|
|
|
+ //过滤空数据,保留重复数据,方便计行
|
|
|
+ tcmsyndromeConfigList = tcmsyndromeConfigList.stream()
|
|
|
+ .filter(TcmsyndromeConfig::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (ListUtil.isEmpty(tcmsyndromeConfigList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
+ }
|
|
|
+ tcmsyndromeConfigList.forEach(tcmsyndromeConfig -> {
|
|
|
+ tcmsyndromeConfig.setHospitalId(hospitalIdVO.getHospitalId());
|
|
|
+ });
|
|
|
+ List<String> emptyNumList = Lists.newLinkedList();
|
|
|
+ for (int i = 0; i < tcmsyndromeConfigList.size(); i++) {
|
|
|
+ if (StringUtil.isBlank(tcmsyndromeConfigList.get(i).getHisName())
|
|
|
+ || StringUtil.isBlank(tcmsyndromeConfigList.get(i).getUniqueName())) {
|
|
|
+ emptyNumList.add(String.valueOf(i + 2));
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(tcmsyndromeConfigList.get(i).getHisName())) {
|
|
|
+ tcmsyndromeConfigList.get(i).setHisName(tcmsyndromeConfigList.get(i).getHisName().trim());
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(tcmsyndromeConfigList.get(i).getUniqueName())) {
|
|
|
+ tcmsyndromeConfigList.get(i).setUniqueName(tcmsyndromeConfigList.get(i).getUniqueName().trim());
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(tcmsyndromeConfigList.get(i).getUniqueCode())) {
|
|
|
+ tcmsyndromeConfigList.get(i).setUniqueCode(tcmsyndromeConfigList.get(i).getUniqueCode().trim());
|
|
|
+ } else {
|
|
|
+ tcmsyndromeConfigList.get(i).setUniqueCode(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(emptyNumList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "以下行数(不计入空行)存在不完整数据:"
|
|
|
+ + emptyNumList.stream().collect(Collectors.joining("、"))
|
|
|
+ + "。导入取消,请修改后再试。\n");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ Map<String, Map<String, List<Long>>> configMap
|
|
|
+ = getConfigMap(Long.valueOf(hospitalId), null, null);
|
|
|
+ tcmsyndromeConfigList.forEach(tcmsyndromeConfig -> {
|
|
|
+ tcmsyndromeConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ tcmsyndromeConfig.setModifier(userId);
|
|
|
+ tcmsyndromeConfig.setGmtModified(now);
|
|
|
+ if (tcmsyndromeConfig.getId() == null) {
|
|
|
+ if (configMap.containsKey(tcmsyndromeConfig.getHisName())
|
|
|
+ && ListUtil.isNotEmpty(configMap.get(tcmsyndromeConfig.getHisName()).get(tcmsyndromeConfig.getUniqueName()))) {
|
|
|
+ deleteIds.addAll(configMap.get(tcmsyndromeConfig.getHisName()).get(tcmsyndromeConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ tcmsyndromeConfig.setCreator(userId);
|
|
|
+ tcmsyndromeConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (tcmsyndromeConfig.getIsDeleted() == null) {
|
|
|
+ tcmsyndromeConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //标准术语校验
|
|
|
+ List<String> errorNumList = Lists.newLinkedList();
|
|
|
+ List<String> uniqueNames = tcmsyndromeConfigList.stream()
|
|
|
+ .map(i -> i.getUniqueName())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
+ conceptVO.setNames(uniqueNames);
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Tcmsyndrome.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 < tcmsyndromeConfigList.size(); i++) {
|
|
|
+ if (!names.contains(tcmsyndromeConfigList.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("、"))
|
|
|
+ + "。导入取消,请修改后再试。");
|
|
|
+ }
|
|
|
+
|
|
|
+ //重复数据过滤
|
|
|
+ tcmsyndromeConfigList = tcmsyndromeConfigList
|
|
|
+ .stream()
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //删除已存在映射关系
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ tcmsyndromeConfigService.saveOrUpdateBatch(tcmsyndromeConfigList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-公表名
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, List<Long>>> getConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, List<Long>>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<TcmsyndromeConfig> 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<TcmsyndromeConfig> records = tcmsyndromeConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, List<TcmsyndromeConfig>> configMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<TcmsyndromeConfig>> entry : configMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ Map<String, List<TcmsyndromeConfig>> subMap = EntityUtil.makeEntityListMap(entry.getValue(), "uniqueName");
|
|
|
+ Map<String, List<Long>> subIdMap = new HashMap<>();
|
|
|
+ for (Map.Entry<String, List<TcmsyndromeConfig>> 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-公表名
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, List<Long>>> getUniqueConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, List<Long>>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<TcmsyndromeConfig> 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<TcmsyndromeConfig> records = tcmsyndromeConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, List<TcmsyndromeConfig>> configMap = EntityUtil.makeEntityListMap(records, "uniqueName");
|
|
|
+ for (Map.Entry<String, List<TcmsyndromeConfig>> entry : configMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ Map<String, List<TcmsyndromeConfig>> subMap = EntityUtil.makeEntityListMap(entry.getValue(), "hisName");
|
|
|
+ Map<String, List<Long>> subIdMap = new HashMap<>();
|
|
|
+ for (Map.Entry<String, List<TcmsyndromeConfig>> 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param hospitalIdVO
|
|
|
+ */
|
|
|
+ public void exportExcel(HttpServletResponse response, HospitalIdVO hospitalIdVO) {
|
|
|
+ QueryWrapper<TcmsyndromeConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalIdVO.getHospitalId())
|
|
|
+ .orderByDesc("gmt_modified");
|
|
|
+ List<TcmsyndromeConfig> records = tcmsyndromeConfigService.list(queryWrapper);
|
|
|
+ String fileName = "中医证候映射.xls";
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", TcmsyndromeConfig.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 各医院映射关系数列表
|
|
|
+ *
|
|
|
+ * @param hosRelationNumPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<HosRelationNumDTO> getRelationNumPage(HosRelationNumPageVO hosRelationNumPageVO) {
|
|
|
+ return tcmsyndromeConfigService.getRelationNumPage(hosRelationNumPageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导入模板导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ public void exportExcelModule(HttpServletResponse response) {
|
|
|
+ String fileName = "中医证候映射模板.xls";
|
|
|
+ ExcelUtils.exportExcel(new ArrayList<>(), null, "sheet1", TcmsyndromeConfig.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入数据预匹配
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ public void precDataMatch(MultipartFile file, HttpServletResponse response) {
|
|
|
+ List<TcmsyndromeConfig> originList = ExcelUtils.importExcel(file, 0, 1, TcmsyndromeConfig.class);
|
|
|
+ List<TcmsyndromeConfig> retList = dataProcess(originList);
|
|
|
+
|
|
|
+ String fileName = "中医证候关联数据(预匹配).xls";
|
|
|
+ ExcelUtils.exportExcel(retList, null, "sheet1", TcmsyndromeConfig.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入数据验证
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean dataVerify(MultipartFile file) {
|
|
|
+ List<TcmsyndromeConfig> originList = ExcelUtils.importExcel(file, 0, 1, TcmsyndromeConfig.class);
|
|
|
+ List<TcmsyndromeConfig> retList = dataProcess(originList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据处理
|
|
|
+ *
|
|
|
+ * @param originList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<TcmsyndromeConfig> dataProcess(List<TcmsyndromeConfig> originList) {
|
|
|
+ List<TcmsyndromeConfig> retList = Lists.newLinkedList();
|
|
|
+ List<String> hisNameList = originList.stream().map(i -> i.getHisName()).distinct().collect(Collectors.toList());
|
|
|
+ Map<String, List<TcmsyndromeConfig>> allMap = getAll(hisNameList);
|
|
|
+
|
|
|
+ if (ListUtil.isEmpty(originList)) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+ //去除空行
|
|
|
+ originList = originList.stream().filter(TcmsyndromeConfig::nonNull).collect(Collectors.toList());
|
|
|
+ if (ListUtil.isEmpty(originList)) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+ //去除空格
|
|
|
+ originList.forEach(item -> {
|
|
|
+ item.setHisName(item.getHisName().trim());
|
|
|
+ });
|
|
|
+
|
|
|
+ //获取标准术语
|
|
|
+ List<String> precUniqueName = Lists.newArrayList();
|
|
|
+ if (allMap != null) {
|
|
|
+ for (Map.Entry<String, List<TcmsyndromeConfig>> entry : allMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ precUniqueName.addAll(entry.getValue().stream().map(i -> i.getUniqueName()).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ precUniqueName = precUniqueName.stream().distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
+ conceptVO.setNames(precUniqueName);
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Tcmsyndrome.getKey());
|
|
|
+ RespDTO<List<IndexBatchDTO>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respDTO, "标准术语校验失败");
|
|
|
+ List<IndexBatchDTO> uniqueNameList = respDTO.data;
|
|
|
+ Map<String, IndexBatchDTO> uniqueMap = uniqueNameList.stream().collect(Collectors.toMap(IndexBatchDTO::getName, v -> v));
|
|
|
+ if (ListUtil.isNotEmpty(originList)) {
|
|
|
+ for (TcmsyndromeConfig originItem : originList) {
|
|
|
+ if (allMap.containsKey(originItem.getHisName())) {
|
|
|
+ List<TcmsyndromeConfig> items = allMap.get(originItem.getHisName());
|
|
|
+ boolean flag = false;
|
|
|
+ for (TcmsyndromeConfig item : items) {
|
|
|
+ if (uniqueMap.containsKey(item.getUniqueName())) {
|
|
|
+ item.setUniqueCode(uniqueMap.get(item.getUniqueName()).getCode());
|
|
|
+ retList.add(item);
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!flag) {
|
|
|
+ retList.add(originItem);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ retList.add(originItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ retList = retList.stream()
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有医院映射数据
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, List<TcmsyndromeConfig>> getAll(List<String> hisNameList) {
|
|
|
+ Map<String, List<TcmsyndromeConfig>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<TcmsyndromeConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ if (ListUtil.isNotEmpty(hisNameList)) {
|
|
|
+ queryWrapper.in("his_name", hisNameList);
|
|
|
+ }
|
|
|
+ List<TcmsyndromeConfig> records = tcmsyndromeConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ records.forEach(record -> {
|
|
|
+ record.setHospitalId(null);
|
|
|
+ record.setId(null);
|
|
|
+ record.setUniqueCode(StringUtils.isBlank(record.getUniqueCode()) ? null : record.getUniqueName());
|
|
|
+ });
|
|
|
+
|
|
|
+ records = records
|
|
|
+ .stream()
|
|
|
+ .filter(record -> record.getIsDeleted().equals(IsDeleteEnum.N.getKey()))
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ retMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查找指定医院映射关系
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<TcmsyndromeConfig> getListByHospitalId(Long hospitalId) {
|
|
|
+ QueryWrapper<TcmsyndromeConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalId);
|
|
|
+ return tcmsyndromeConfigService.list(queryWrapper);
|
|
|
+ }
|
|
|
+}
|