|
@@ -53,6 +53,13 @@ public class DrugConfigFacade {
|
|
|
.eq("hospital_id", drugConfig.getHospitalId())
|
|
|
.eq("his_name", drugConfig.getHisName())
|
|
|
.eq("unique_name", drugConfig.getUniqueName());
|
|
|
+ if (StringUtil.isBlank(drugConfig.getForm())) {
|
|
|
+ queryWrapper.and(i -> i.isNull("form")
|
|
|
+ .or()
|
|
|
+ .eq("form", ""));
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq("form", drugConfig.getForm());
|
|
|
+ }
|
|
|
DrugConfig oldRecord = drugConfigService.getOne(queryWrapper, false);
|
|
|
if (oldRecord != null) {
|
|
|
return true;
|
|
@@ -76,6 +83,13 @@ public class DrugConfigFacade {
|
|
|
.eq("hospital_id", drugConfig.getHospitalId())
|
|
|
.eq("his_name", drugConfig.getHisName())
|
|
|
.eq("unique_name", drugConfig.getUniqueName());
|
|
|
+ if (StringUtil.isBlank(drugConfig.getForm())) {
|
|
|
+ queryWrapper.and(i -> i.isNull("form")
|
|
|
+ .or()
|
|
|
+ .eq("form", ""));
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq("form", drugConfig.getForm());
|
|
|
+ }
|
|
|
DrugConfig oldRecord = drugConfigService.getOne(queryWrapper, false);
|
|
|
if (oldRecord != null) {
|
|
|
drugConfig.setId(oldRecord.getId());
|
|
@@ -126,23 +140,37 @@ public class DrugConfigFacade {
|
|
|
.filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
.filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
.collect(Collectors.toList());
|
|
|
+
|
|
|
if (ListUtil.isEmpty(drugConfigList)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
Long hospitalId = drugConfigList.get(0).getHospitalId();
|
|
|
|
|
|
+ List<String> hisNames = drugConfigList
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getHisName())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> uniqueNames = drugConfigList
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getUniqueName())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
// 验证数据是否已存在,已存在的先删除
|
|
|
// 没id的删除重新插入,有id的更新
|
|
|
List<Long> deleteIds = Lists.newLinkedList();
|
|
|
- Map<String, Map<String, Long>> configMap
|
|
|
- = getConfigMap(hospitalId, null, null);
|
|
|
+ Map<String, Map<String, Map<String, Long>>> configMap
|
|
|
+ = getConfigMap(hospitalId, hisNames, uniqueNames);
|
|
|
drugConfigList.forEach(drugConfig -> {
|
|
|
+ drugConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
drugConfig.setModifier(userId);
|
|
|
drugConfig.setGmtModified(now);
|
|
|
+ String form = StringUtil.isBlank(drugConfig.getForm()) ? "" : drugConfig.getForm();
|
|
|
if (drugConfig.getId() == null) {
|
|
|
- if (configMap.containsKey(drugConfig.getHisName())) {
|
|
|
- deleteIds.add(configMap.get(drugConfig.getHisName()).get(drugConfig.getUniqueName()));
|
|
|
+ if (configMap.get(drugConfig.getHisName()) != null
|
|
|
+ && configMap.get(drugConfig.getHisName()).get(form) != null
|
|
|
+ && configMap.get(drugConfig.getHisName()).get(form).get(drugConfig.getUniqueName()) != null) {
|
|
|
+ deleteIds.add(configMap.get(drugConfig.getHisName()).get(form).get(drugConfig.getUniqueName()));
|
|
|
}
|
|
|
drugConfig.setCreator(userId);
|
|
|
drugConfig.setGmtCreate(now);
|
|
@@ -151,6 +179,7 @@ public class DrugConfigFacade {
|
|
|
drugConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
//删除已存在映射关系
|
|
|
IdListVO idListVO = new IdListVO();
|
|
|
idListVO.setIds(deleteIds);
|
|
@@ -216,15 +245,144 @@ public class DrugConfigFacade {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-公表名
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return Map<hisName,Map<form,Map<uniqueName,id>>>
|
|
|
+ */
|
|
|
+ public Map<String, Map<String,Map<String, Long>>> getConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, Map<String, Long>>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<DrugConfig> 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<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, List<DrugConfig>> hisNameMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<DrugConfig>> entry : hisNameMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ Map<String, Map<String, Long>> formMap = new HashMap<>();
|
|
|
+ entry.getValue().forEach(i -> {
|
|
|
+ if (StringUtil.isBlank(i.getForm())) {
|
|
|
+ i.setForm("");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<String, List<DrugConfig>> subMap
|
|
|
+ = EntityUtil.makeEntityListMap(entry.getValue(), "form");
|
|
|
+ for (Map.Entry<String, List<DrugConfig>> subEntry : subMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(subEntry.getValue())) {
|
|
|
+ formMap.put(subEntry.getKey(),
|
|
|
+ EntityUtil.makeMapWithKeyValue(subEntry.getValue(), "uniqueName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ retMap.put(entry.getKey(), formMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系
|
|
|
+ * Map<uniqueName,Map<form,Map<hisName,id>>>
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String,Map<String,Map<String,Long>>> getUniqueNameConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, Map<String, Long>>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<DrugConfig> 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<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ records.forEach(i -> {
|
|
|
+ if (StringUtil.isBlank(i.getForm())) {
|
|
|
+ i.setForm("");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<String, List<DrugConfig>> uniqueNameMap = EntityUtil.makeEntityListMap(records, "uniqueName");
|
|
|
+ for (Map.Entry<String, List<DrugConfig>> entry : uniqueNameMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ Map<String, Map<String, Long>> formMap = new HashMap<>();
|
|
|
+ Map<String, List<DrugConfig>> subMap
|
|
|
+ = EntityUtil.makeEntityListMap(entry.getValue(), "form");
|
|
|
+ for (Map.Entry<String, List<DrugConfig>> subEntry : subMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(subEntry.getValue())) {
|
|
|
+ formMap.put(subEntry.getKey(),
|
|
|
+ EntityUtil.makeMapWithKeyValue(subEntry.getValue(), "hisName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ retMap.put(entry.getKey(), formMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取映射关系-公表名
|
|
|
*
|
|
|
* @param hospitalId
|
|
|
* @param hisNames
|
|
|
* @param uniqueNames
|
|
|
+ * @return Map<hisName,Map<uniqueName,id>>
|
|
|
+ */
|
|
|
+ public Map<String, Map<String,Long>> getConfigMapWithoutForm(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, Long>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<DrugConfig> 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<DrugConfig> records = drugConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, List<DrugConfig>> hisNameMap
|
|
|
+ = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<DrugConfig>> entry : hisNameMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ retMap.put(entry.getKey(),
|
|
|
+ EntityUtil.makeMapWithKeyValue(records, "uniqueName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系
|
|
|
+ * Map<uniqueName,Map<hisName,id>>
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Map<String, Long>> getConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ public Map<String,Map<String,Long>> getUniqueNameConfigMapWithoutForm(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
Map<String, Map<String, Long>> retMap = new HashMap<>();
|
|
|
QueryWrapper<DrugConfig> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
@@ -239,10 +397,17 @@ public class DrugConfigFacade {
|
|
|
if (ListUtil.isEmpty(records)) {
|
|
|
return retMap;
|
|
|
}
|
|
|
- Map<String, List<DrugConfig>> configMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
- for (Map.Entry<String, List<DrugConfig>> entry : configMap.entrySet()) {
|
|
|
+ records.forEach(i -> {
|
|
|
+ if (StringUtil.isBlank(i.getForm())) {
|
|
|
+ i.setForm("");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<String, List<DrugConfig>> uniqueNameMap
|
|
|
+ = EntityUtil.makeEntityListMap(records, "uniqueName");
|
|
|
+ for (Map.Entry<String, List<DrugConfig>> entry : uniqueNameMap.entrySet()) {
|
|
|
if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
- retMap.put(entry.getKey(), EntityUtil.makeMapWithKeyValue(entry.getValue(), "uniqueName", "id"));
|
|
|
+ retMap.put(entry.getKey(),
|
|
|
+ EntityUtil.makeMapWithKeyValue(records, "hisName", "id"));
|
|
|
}
|
|
|
}
|
|
|
return retMap;
|