|
@@ -3,22 +3,29 @@ package com.diagbot.facade;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.diagbot.client.CdssCoreClient;
|
|
import com.diagbot.dto.HosRelationNumDTO;
|
|
import com.diagbot.dto.HosRelationNumDTO;
|
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
import com.diagbot.entity.TransfusionConfig;
|
|
import com.diagbot.entity.TransfusionConfig;
|
|
|
|
+import com.diagbot.enums.ConceptTypeEnum;
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
|
+import com.diagbot.exception.CommonException;
|
|
import com.diagbot.service.TransfusionConfigService;
|
|
import com.diagbot.service.TransfusionConfigService;
|
|
import com.diagbot.util.DateUtil;
|
|
import com.diagbot.util.DateUtil;
|
|
import com.diagbot.util.EntityUtil;
|
|
import com.diagbot.util.EntityUtil;
|
|
import com.diagbot.util.ExcelUtils;
|
|
import com.diagbot.util.ExcelUtils;
|
|
import com.diagbot.util.ListUtil;
|
|
import com.diagbot.util.ListUtil;
|
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
import com.diagbot.util.StringUtil;
|
|
import com.diagbot.util.StringUtil;
|
|
import com.diagbot.util.UserUtils;
|
|
import com.diagbot.util.UserUtils;
|
|
-import com.diagbot.vo.TransfusionConfigListVO;
|
|
|
|
-import com.diagbot.vo.TransfusionConfigPageVO;
|
|
|
|
|
|
+import com.diagbot.vo.ConceptVO;
|
|
import com.diagbot.vo.HosRelationNumPageVO;
|
|
import com.diagbot.vo.HosRelationNumPageVO;
|
|
import com.diagbot.vo.HospitalIdVO;
|
|
import com.diagbot.vo.HospitalIdVO;
|
|
import com.diagbot.vo.IdListVO;
|
|
import com.diagbot.vo.IdListVO;
|
|
import com.diagbot.vo.IdVO;
|
|
import com.diagbot.vo.IdVO;
|
|
|
|
+import com.diagbot.vo.TransfusionConfigListVO;
|
|
|
|
+import com.diagbot.vo.TransfusionConfigPageVO;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -40,6 +47,8 @@ import java.util.stream.Collectors;
|
|
public class TransfusionConfigFacade {
|
|
public class TransfusionConfigFacade {
|
|
@Autowired
|
|
@Autowired
|
|
private TransfusionConfigService transfusionConfigService;
|
|
private TransfusionConfigService transfusionConfigService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CdssCoreClient cdssCoreClient;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 判断是否已存在
|
|
* 判断是否已存在
|
|
@@ -54,8 +63,14 @@ public class TransfusionConfigFacade {
|
|
.eq("his_name", transfusionConfig.getHisName())
|
|
.eq("his_name", transfusionConfig.getHisName())
|
|
.eq("unique_name", transfusionConfig.getUniqueName());
|
|
.eq("unique_name", transfusionConfig.getUniqueName());
|
|
TransfusionConfig oldRecord = transfusionConfigService.getOne(queryWrapper, false);
|
|
TransfusionConfig oldRecord = transfusionConfigService.getOne(queryWrapper, false);
|
|
- if (oldRecord != null) {
|
|
|
|
- return true;
|
|
|
|
|
|
+ if (transfusionConfig.getId() == null
|
|
|
|
+ && oldRecord != null) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
|
+ }
|
|
|
|
+ if (transfusionConfig.getId() != null
|
|
|
|
+ && oldRecord != null
|
|
|
|
+ && !transfusionConfig.getId().equals(oldRecord.getId())) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -77,8 +92,14 @@ public class TransfusionConfigFacade {
|
|
.eq("his_name", transfusionConfig.getHisName())
|
|
.eq("his_name", transfusionConfig.getHisName())
|
|
.eq("unique_name", transfusionConfig.getUniqueName());
|
|
.eq("unique_name", transfusionConfig.getUniqueName());
|
|
TransfusionConfig oldRecord = transfusionConfigService.getOne(queryWrapper, false);
|
|
TransfusionConfig oldRecord = transfusionConfigService.getOne(queryWrapper, false);
|
|
- if (oldRecord != null) {
|
|
|
|
- transfusionConfig.setId(oldRecord.getId());
|
|
|
|
|
|
+ if (transfusionConfig.getId() == null
|
|
|
|
+ && oldRecord != null) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
|
|
+ }
|
|
|
|
+ if (transfusionConfig.getId() != null
|
|
|
|
+ && oldRecord != null
|
|
|
|
+ && !transfusionConfig.getId().equals(oldRecord.getId())) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.IS_EXISTS, "该条关联已存在,无法保存");
|
|
}
|
|
}
|
|
//新增数据
|
|
//新增数据
|
|
if (transfusionConfig.getId() == null) {
|
|
if (transfusionConfig.getId() == null) {
|
|
@@ -212,8 +233,90 @@ public class TransfusionConfigFacade {
|
|
transfusionConfigList.forEach(transfusionConfig -> {
|
|
transfusionConfigList.forEach(transfusionConfig -> {
|
|
transfusionConfig.setHospitalId(hospitalIdVO.getHospitalId());
|
|
transfusionConfig.setHospitalId(hospitalIdVO.getHospitalId());
|
|
});
|
|
});
|
|
- saveOrUpdateRecords(transfusionConfigList);
|
|
|
|
|
|
+ importExcelRecords(transfusionConfigList, hospitalIdVO);
|
|
|
|
+ } else {
|
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "校验失败,导入数据不能为空");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 数据导入
|
|
|
|
+ *
|
|
|
|
+ * @param transfusionConfigList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Boolean importExcelRecords(List<TransfusionConfig> transfusionConfigList, HospitalIdVO hospitalIdVO) {
|
|
|
|
+ Long hospitalId = hospitalIdVO.getHospitalId();
|
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
|
+ Date now = DateUtil.now();
|
|
|
|
+
|
|
|
|
+ //1、数据完整性校验
|
|
|
|
+ //2、去除前后空格
|
|
|
|
+ for (int i = 0; i < transfusionConfigList.size(); i++) {
|
|
|
|
+ if (StringUtil.isBlank(transfusionConfigList.get(i).getHisName())
|
|
|
|
+ || StringUtil.isBlank(transfusionConfigList.get(i).getUniqueName())) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "第" + (i + 2) + "行存在不完整数据,导入失败,请修改后再试");
|
|
|
|
+ }
|
|
|
|
+ transfusionConfigList.get(i).setHisName(transfusionConfigList.get(i).getHisName().trim());
|
|
|
|
+ transfusionConfigList.get(i).setUniqueName(transfusionConfigList.get(i).getUniqueName().trim());
|
|
|
|
+ if (StringUtil.isNotBlank(transfusionConfigList.get(i).getUniqueCode())) {
|
|
|
|
+ transfusionConfigList.get(i).setUniqueCode(transfusionConfigList.get(i).getUniqueCode().trim());
|
|
|
|
+ } else {
|
|
|
|
+ transfusionConfigList.get(i).setUniqueCode(null);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
|
+ Map<String, Map<String, Long>> configMap
|
|
|
|
+ = getConfigMap(Long.valueOf(hospitalId), null, null);
|
|
|
|
+ transfusionConfigList.forEach(transfusionConfig -> {
|
|
|
|
+ transfusionConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
|
+ transfusionConfig.setModifier(userId);
|
|
|
|
+ transfusionConfig.setGmtModified(now);
|
|
|
|
+ if (transfusionConfig.getId() == null) {
|
|
|
|
+ if (configMap.containsKey(transfusionConfig.getHisName())) {
|
|
|
|
+ deleteIds.add(configMap.get(transfusionConfig.getHisName()).get(transfusionConfig.getUniqueName()));
|
|
|
|
+ }
|
|
|
|
+ transfusionConfig.setCreator(userId);
|
|
|
|
+ transfusionConfig.setGmtCreate(now);
|
|
|
|
+ }
|
|
|
|
+ if (transfusionConfig.getIsDeleted() == null) {
|
|
|
|
+ transfusionConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ //标准术语校验
|
|
|
|
+ List<String> uniqueNames = transfusionConfigList.stream()
|
|
|
|
+ .map(i -> i.getUniqueName())
|
|
|
|
+ .distinct()
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ ConceptVO conceptVO = new ConceptVO();
|
|
|
|
+ conceptVO.setNames(uniqueNames);
|
|
|
|
+ conceptVO.setType(ConceptTypeEnum.Transfusion.getKey());
|
|
|
|
+ RespDTO<List<String>> respDTO = cdssCoreClient.getConceptNames(conceptVO);
|
|
|
|
+ RespDTOUtil.respNGDealCover(respDTO, "标准术语校验失败");
|
|
|
|
+ List<String> names = respDTO.data;
|
|
|
|
+ for (int i = 0; i < transfusionConfigList.size(); i++) {
|
|
|
|
+ if (!names.contains(transfusionConfigList.get(i).getUniqueName())) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
|
+ "【" + transfusionConfigList.get(i).getUniqueName() + "】不是标准术语,导入失败,请修改后再试");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //重复数据过滤
|
|
|
|
+ transfusionConfigList = transfusionConfigList
|
|
|
|
+ .stream()
|
|
|
|
+ .distinct()
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //删除已存在映射关系
|
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
|
+ deleteRecords(idListVO);
|
|
|
|
+ transfusionConfigService.saveOrUpdateBatch(transfusionConfigList);
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -272,4 +375,4 @@ public class TransfusionConfigFacade {
|
|
public IPage<HosRelationNumDTO> getRelationNumPage(HosRelationNumPageVO hosRelationNumPageVO) {
|
|
public IPage<HosRelationNumDTO> getRelationNumPage(HosRelationNumPageVO hosRelationNumPageVO) {
|
|
return transfusionConfigService.getRelationNumPage(hosRelationNumPageVO);
|
|
return transfusionConfigService.getRelationNumPage(hosRelationNumPageVO);
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|