|
@@ -3,16 +3,23 @@ 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.HosRelationNumDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
import com.diagbot.entity.LisConfig;
|
|
|
+import com.diagbot.enums.ConceptTypeEnum;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.LisConfigService;
|
|
|
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;
|
|
@@ -40,6 +47,8 @@ import java.util.stream.Collectors;
|
|
|
public class LisConfigFacade{
|
|
|
@Autowired
|
|
|
private LisConfigService lisConfigService;
|
|
|
+ @Autowired
|
|
|
+ private CdssCoreClient cdssCoreClient;
|
|
|
|
|
|
/**
|
|
|
* 判断是否已存在
|
|
@@ -62,8 +71,14 @@ public class LisConfigFacade{
|
|
|
.eq("his_detail_name", lisConfig.getHisDetailName());
|
|
|
}
|
|
|
LisConfig oldRecord = lisConfigService.getOne(queryWrapper, false);
|
|
|
- if (oldRecord != null) {
|
|
|
- return true;
|
|
|
+ if (lisConfig.getId() == null
|
|
|
+ && oldRecord != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ if (lisConfig.getId() != null
|
|
|
+ && oldRecord != null
|
|
|
+ && !lisConfig.getId().equals(oldRecord.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -93,8 +108,14 @@ public class LisConfigFacade{
|
|
|
.eq("his_detail_name", lisConfig.getHisDetailName());
|
|
|
}
|
|
|
LisConfig oldRecord = lisConfigService.getOne(queryWrapper, false);
|
|
|
- if (oldRecord != null) {
|
|
|
- lisConfig.setId(oldRecord.getId());
|
|
|
+ if (lisConfig.getId() == null
|
|
|
+ && oldRecord != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
+ }
|
|
|
+ if (lisConfig.getId() != null
|
|
|
+ && oldRecord != null
|
|
|
+ && !lisConfig.getId().equals(oldRecord.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
}
|
|
|
//新增数据
|
|
|
if (lisConfig.getId() == null) {
|
|
@@ -241,10 +262,113 @@ public class LisConfigFacade{
|
|
|
lisConfigList.forEach(lisConfig -> {
|
|
|
lisConfig.setHospitalId(hospitalIdVO.getHospitalId());
|
|
|
});
|
|
|
- saveOrUpdateRecords(lisConfigList);
|
|
|
+ importExcelRecords(lisConfigList, hospitalIdVO);
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 数据导入
|
|
|
+ *
|
|
|
+ * @param lisConfigList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean importExcelRecords(List<LisConfig> lisConfigList,HospitalIdVO hospitalIdVO) {
|
|
|
+ Long hospitalId = hospitalIdVO.getHospitalId();
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ //1、数据完整性校验
|
|
|
+ //2、去除前后空格
|
|
|
+ for (int i = 0; i < lisConfigList.size(); i++) {
|
|
|
+ if (StringUtil.isBlank(lisConfigList.get(i).getHisName())
|
|
|
+ || StringUtil.isBlank(lisConfigList.get(i).getUniqueName())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "第" + (i + 2) + "行存在不完整数据,导入失败,请修改后再试");
|
|
|
+ }
|
|
|
+ lisConfigList.get(i).setHisName(lisConfigList.get(i).getHisName().trim());
|
|
|
+ lisConfigList.get(i).setUniqueName(lisConfigList.get(i).getUniqueName().trim());
|
|
|
+ if (StringUtil.isNotBlank(lisConfigList.get(i).getUniqueCode())) {
|
|
|
+ lisConfigList.get(i).setUniqueCode(lisConfigList.get(i).getUniqueCode().trim());
|
|
|
+ } else {
|
|
|
+ lisConfigList.get(i).setUniqueCode(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> hisNames = lisConfigList
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getHisName())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> uniqueNames = lisConfigList
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getUniqueName())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ Map<String, Map<String, Map<String, Long>>> configMap
|
|
|
+ = getConfigMap(Long.valueOf(hospitalId), hisNames, uniqueNames);
|
|
|
+ lisConfigList.forEach(lisConfig -> {
|
|
|
+ lisConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ lisConfig.setModifier(userId);
|
|
|
+ lisConfig.setGmtModified(now);
|
|
|
+ if (lisConfig.getId() == null) {
|
|
|
+ if (configMap.containsKey(lisConfig.getHisName())) {
|
|
|
+ if (lisConfig.getHisDetailName() == null
|
|
|
+ && configMap.get(lisConfig.getHisName()).containsKey("")) {
|
|
|
+ if (configMap.get(lisConfig.getHisName()).get("").containsKey(lisConfig.getUniqueName())) {
|
|
|
+ deleteIds.add(configMap.get(lisConfig.getHisName()).get("").get(lisConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ } else if (configMap.get(lisConfig.getHisName()).containsKey(lisConfig.getHisDetailName())) {
|
|
|
+ if (configMap.get(lisConfig.getHisName()).get(lisConfig.getHisDetailName()).containsKey(lisConfig.getUniqueName())) {
|
|
|
+ deleteIds.add(configMap
|
|
|
+ .get(lisConfig.getHisName())
|
|
|
+ .get(lisConfig.getHisDetailName())
|
|
|
+ .get(lisConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lisConfig.setCreator(userId);
|
|
|
+ lisConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (lisConfig.getIsDeleted() == null) {
|
|
|
+ lisConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //标准术语校验
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
+ conceptVO.setNames(uniqueNames);
|
|
|
+ conceptVO.setType(ConceptTypeEnum.LisPack.getKey());
|
|
|
+ RespDTO<List<String>> respLisPackDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respLisPackDTO, "标准术语校验失败");
|
|
|
+ List<String> lisPackNames = respLisPackDTO.data;
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Lis.getKey());
|
|
|
+ RespDTO<List<String>> respLisDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(respLisDTO, "标准术语校验失败");
|
|
|
+ List<String> lisNames = respLisDTO.data;
|
|
|
+ for (int i = 0; i < lisConfigList.size(); i++) {
|
|
|
+ if (!lisPackNames.contains(lisConfigList.get(i).getUniqueName())
|
|
|
+ && !lisNames.contains(lisConfigList.get(i).getUniqueName())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
+ "【" + lisConfigList.get(i).getUniqueName() + "】不是标准术语,导入失败,请修改后再试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //重复数据过滤
|
|
|
+ lisConfigList = lisConfigList
|
|
|
+ .stream()
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //删除已存在映射关系
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ lisConfigService.saveOrUpdateBatch(lisConfigList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取映射关系-id
|