|
@@ -2,15 +2,21 @@ 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.entity.LisConfig;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
import com.diagbot.service.LisConfigService;
|
|
|
import com.diagbot.service.impl.LisConfigServiceImpl;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
import com.diagbot.util.ExcelUtils;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
import com.diagbot.util.StringUtil;
|
|
|
import com.diagbot.util.SysUserUtils;
|
|
|
+import com.diagbot.vo.IdListVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.diagbot.vo.LisConfigListVO;
|
|
|
+import com.diagbot.vo.LisConfigPageVO;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@@ -18,7 +24,9 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -39,6 +47,7 @@ public class LisConfigFacade extends LisConfigServiceImpl {
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean isExistRecord(LisConfig lisConfig) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
QueryWrapper<LisConfig> queryWrapper = new QueryWrapper<>();
|
|
|
LisConfig oldRecord = new LisConfig();
|
|
|
if (lisConfig.getId() != null) {
|
|
@@ -48,6 +57,7 @@ public class LisConfigFacade extends LisConfigServiceImpl {
|
|
|
}
|
|
|
} else if (StringUtil.isNotBlank(lisConfig.getHisName())) {
|
|
|
queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", Long.valueOf(hospitalId))
|
|
|
.eq("his_name", lisConfig.getHisName());
|
|
|
if (StringUtil.isBlank(lisConfig.getHisDetailName())) {
|
|
|
queryWrapper
|
|
@@ -72,57 +82,83 @@ public class LisConfigFacade extends LisConfigServiceImpl {
|
|
|
* @param lisConfig
|
|
|
* @return
|
|
|
*/
|
|
|
- public LisConfig saveRecord(LisConfig lisConfig) {
|
|
|
+ public Boolean saveOrUpdateRecord(LisConfig lisConfig) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
Date now = DateUtil.now();
|
|
|
- if (lisConfig.getId() != null) {
|
|
|
- deleteRecord(lisConfig.getId());
|
|
|
- lisConfig.setId(null);
|
|
|
- }
|
|
|
- lisConfig.setCreator(userId);
|
|
|
- lisConfig.setGmtCreate(now);
|
|
|
+ lisConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
lisConfig.setModifier(userId);
|
|
|
lisConfig.setGmtModified(now);
|
|
|
+ //新增数据
|
|
|
+ if (lisConfig.getId() == null) {
|
|
|
+ lisConfig.setCreator(userId);
|
|
|
+ lisConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (lisConfig.getIsDeleted() == null) {
|
|
|
+ lisConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
this.saveOrUpdate(lisConfig);
|
|
|
- return lisConfig;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存记录-批量
|
|
|
*
|
|
|
- * @param lisConfigList
|
|
|
+ * @param lisConfigListVO
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean saveRecords(List<LisConfig> lisConfigList) {
|
|
|
+ public Boolean saveOrUpdateRecords(LisConfigListVO lisConfigListVO) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
Date now = DateUtil.now();
|
|
|
+ //id为空且已存在的映射关系先删除
|
|
|
List<Long> deleteIds = Lists.newLinkedList();
|
|
|
- if (ListUtil.isNotEmpty(lisConfigList)) {
|
|
|
- lisConfigList.forEach(lisConfig -> {
|
|
|
- if (lisConfig.getId() != null) {
|
|
|
- deleteIds.add(lisConfig.getId());
|
|
|
- lisConfig.setId(null);
|
|
|
+ Map<String, Map<String, Long>> configMap
|
|
|
+ = getConfigMapWithId(Long.valueOf(hospitalId), null, null);
|
|
|
+ if (ListUtil.isNotEmpty(lisConfigListVO.getLisConfigList())) {
|
|
|
+ lisConfigListVO.getLisConfigList().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("")) {
|
|
|
+ deleteIds.add(configMap.get(lisConfig.getHisName()).get(""));
|
|
|
+ } else if (configMap.get(lisConfig.getHisName()).containsKey(lisConfig.getHisDetailName())) {
|
|
|
+ deleteIds.add(configMap.get(lisConfig.getHisName()).get(lisConfig.getHisDetailName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
lisConfig.setCreator(userId);
|
|
|
lisConfig.setGmtCreate(now);
|
|
|
- lisConfig.setModifier(userId);
|
|
|
- lisConfig.setGmtModified(now);
|
|
|
+ }
|
|
|
+ if (lisConfig.getIsDeleted() == null) {
|
|
|
+ lisConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
}
|
|
|
});
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
}
|
|
|
- deleteRecords(deleteIds);
|
|
|
- lisConfigService.saveBatch(lisConfigList);
|
|
|
+ //数据不完整的不保存
|
|
|
+ List<LisConfig> records = lisConfigListVO.getLisConfigList()
|
|
|
+ .stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ lisConfigService.saveOrUpdateBatch(records);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除记录-单条
|
|
|
*
|
|
|
- * @param id
|
|
|
+ * @param idVO
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean deleteRecord(Long id) {
|
|
|
+ public Boolean deleteRecord(IdVO idVO) {
|
|
|
UpdateWrapper<LisConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.eq("id", id)
|
|
|
+ updateWrapper.eq("id", idVO.getId())
|
|
|
.set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
this.update(updateWrapper);
|
|
|
return true;
|
|
@@ -131,20 +167,32 @@ public class LisConfigFacade extends LisConfigServiceImpl {
|
|
|
/**
|
|
|
* 删除记录-批量
|
|
|
*
|
|
|
- * @param ids
|
|
|
+ * @param idListVO
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean deleteRecords(List<Long> ids) {
|
|
|
- if (ListUtil.isEmpty(ids)) {
|
|
|
+ public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
+ if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
return false;
|
|
|
}
|
|
|
UpdateWrapper<LisConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.in("id", ids)
|
|
|
+ updateWrapper.in("id", idListVO.getIds())
|
|
|
.set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
this.update(updateWrapper);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param lisConfigPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<LisConfig> getPage(LisConfigPageVO lisConfigPageVO) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ lisConfigPageVO.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ return lisConfigService.getPage(lisConfigPageVO);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 化验数据导入
|
|
|
*
|
|
@@ -163,6 +211,24 @@ public class LisConfigFacade extends LisConfigServiceImpl {
|
|
|
.filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
.collect(Collectors.toList());
|
|
|
//验证数据是否已存在
|
|
|
+ List<Long> deleteIds = Lists.newArrayList();
|
|
|
+ Map<String, Map<String, Long>> configMap = getConfigMapWithId(Long.valueOf(hospitalId), null, null);
|
|
|
+ lisConfigList.forEach(lisConfig -> {
|
|
|
+ if (configMap.containsKey(lisConfig.getHisName())) {
|
|
|
+ if (StringUtil.isBlank(lisConfig.getHisDetailName())
|
|
|
+ && configMap.get(lisConfig.getHisName()).containsKey("")) {
|
|
|
+ deleteIds.add(configMap.get(lisConfig.getHisName()).get(""));
|
|
|
+ } else if (configMap.get(lisConfig.getHisName()).containsKey(lisConfig.getHisDetailName())) {
|
|
|
+ deleteIds.add(configMap.get(lisConfig.getHisName()).get(lisConfig.getHisDetailName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除已存在的映射关系
|
|
|
+ if (ListUtil.isNotEmpty(deleteIds)) {
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
//新增数据
|
|
|
lisConfigList.forEach(lisConfig -> {
|
|
@@ -177,4 +243,84 @@ public class LisConfigFacade extends LisConfigServiceImpl {
|
|
|
lisConfigService.saveBatch(lisConfigList);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-id
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, Long>> getConfigMapWithId(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, Long>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<LisConfig> 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<LisConfig> records = this.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ records.forEach(lisConfig -> {
|
|
|
+ if (lisConfig.getHisDetailName() == null) {
|
|
|
+ lisConfig.setHisDetailName("");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<String, List<LisConfig>> hisNameMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<LisConfig>> entry : hisNameMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ retMap.put(entry.getKey(),
|
|
|
+ EntityUtil.makeMapWithKeyValue(entry.getValue(), "hisDetailName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-公表名
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, String>> getConfigMapWithUniqueName(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, String>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<LisConfig> 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<LisConfig> records = this.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ records.forEach(lisConfig -> {
|
|
|
+ if (lisConfig.getHisDetailName() == null) {
|
|
|
+ lisConfig.setHisDetailName("");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<String, List<LisConfig>> hisNameMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<LisConfig>> entry : hisNameMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ retMap.put(entry.getKey(),
|
|
|
+ EntityUtil.makeMapWithKeyValue(entry.getValue(), "hisDetailName", "uniqueName"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
}
|