|
@@ -121,6 +121,55 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 校验子医院
|
|
|
+ List<TranHospitalRelation> saveRelationList = Lists.newArrayList();
|
|
|
+ // 获取子医院
|
|
|
+ List<HospitalRelationVO> hospitalRelationVOList = hospitalInfoSaveVO.getHospitalRelationVOList();
|
|
|
+ if (ListUtil.isNotEmpty(hospitalRelationVOList)) {
|
|
|
+ // 校验name+code唯一性
|
|
|
+ List<TranHospitalRelation> tranHospitalRelationList = tranHospitalRelationService.list(new QueryWrapper<TranHospitalRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ );
|
|
|
+ Map<String, Long> relationMap = tranHospitalRelationList.stream().collect(Collectors.toMap(k -> k.getName() + "_" + k.getCode(), v -> v.getHospitalId(), (v1, v2) -> (v2), LinkedHashMap::new));
|
|
|
+ List<String> keyExist = Lists.newArrayList(); // 避免重复数据返回
|
|
|
+ List<String> keyAll = Lists.newArrayList(); // 当前医院所有key
|
|
|
+ List<HospitalRelationVO> errorOther = Lists.newArrayList(); // 与其他医院重复
|
|
|
+ List<HospitalRelationVO> errorCurrent = Lists.newArrayList(); // 当前医院重复
|
|
|
+
|
|
|
+ for (HospitalRelationVO hospitalRelationVO : hospitalRelationVOList) {
|
|
|
+ // 联合key
|
|
|
+ String unionKey = hospitalRelationVO.getName() + "_" + hospitalRelationVO.getCode();
|
|
|
+ // 判断当前医院重复
|
|
|
+ if (keyAll.contains(unionKey)) {
|
|
|
+ errorCurrent.add(hospitalRelationVO);
|
|
|
+ } else {
|
|
|
+ keyAll.add(unionKey);
|
|
|
+ }
|
|
|
+ // 判断与其他医院重复
|
|
|
+ Long hospitalId = relationMap.get(unionKey);
|
|
|
+ if (hospitalId != null && !hospitalId.equals(hospitalInfo.getId()) && !keyExist.contains(unionKey)) {
|
|
|
+ errorOther.add(hospitalRelationVO);
|
|
|
+ keyExist.add(unionKey);
|
|
|
+ } else {
|
|
|
+ TranHospitalRelation tranHospitalRelation = new TranHospitalRelation();
|
|
|
+ BeanUtil.copyProperties(hospitalRelationVO, tranHospitalRelation);
|
|
|
+ tranHospitalRelation.setHospitalId(hospitalInfo.getId());
|
|
|
+ tranHospitalRelation.setCreator(userId);
|
|
|
+ tranHospitalRelation.setModifier(userId);
|
|
|
+ tranHospitalRelation.setGmtCreate(now);
|
|
|
+ tranHospitalRelation.setGmtModified(now);
|
|
|
+ saveRelationList.add(tranHospitalRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 有错误,直接返回
|
|
|
+ if (ListUtil.isNotEmpty(errorOther) || ListUtil.isNotEmpty(errorCurrent)) {
|
|
|
+ res.setErrorOther(errorOther);
|
|
|
+ res.setErrorCurrent(errorCurrent);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//新增数据
|
|
|
if (hospitalInfo.getId() == null) {
|
|
|
hospitalInfo.setCreator(userId);
|
|
@@ -132,50 +181,6 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
|
|
|
}
|
|
|
this.saveOrUpdate(hospitalInfo);
|
|
|
|
|
|
- List<TranHospitalRelation> saveRelationList = Lists.newArrayList();
|
|
|
- // 获取子医院
|
|
|
- List<HospitalRelationVO> hospitalRelationVOList = hospitalInfoSaveVO.getHospitalRelationVOList();
|
|
|
- // 校验name+code唯一性
|
|
|
- List<TranHospitalRelation> tranHospitalRelationList = tranHospitalRelationService.list(new QueryWrapper<TranHospitalRelation>()
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- );
|
|
|
- Map<String, Long> relationMap = tranHospitalRelationList.stream().collect(Collectors.toMap(k -> k.getName() + "_" + k.getCode(), v -> v.getHospitalId(), (v1, v2) -> (v2), LinkedHashMap::new));
|
|
|
- List<String> keyExist = Lists.newArrayList(); // 避免重复数据返回
|
|
|
- List<String> keyAll = Lists.newArrayList(); // 当前医院所有key
|
|
|
- List<HospitalRelationVO> errorOther = Lists.newArrayList(); // 与其他医院重复
|
|
|
- List<HospitalRelationVO> errorCurrent = Lists.newArrayList(); // 当前医院重复
|
|
|
-
|
|
|
- for (HospitalRelationVO hospitalRelationVO : hospitalRelationVOList) {
|
|
|
- // 联合key
|
|
|
- String unionKey = hospitalRelationVO.getName() + "_" + hospitalRelationVO.getCode();
|
|
|
- // 判断当前医院重复
|
|
|
- if (keyAll.contains(unionKey)) {
|
|
|
- errorCurrent.add(hospitalRelationVO);
|
|
|
- }
|
|
|
- // 判断与其他医院重复
|
|
|
- Long hospitalId = relationMap.get(unionKey);
|
|
|
- if (hospitalId != null && !hospitalId.equals(hospitalInfo.getId()) && !keyExist.contains(unionKey)) {
|
|
|
- errorOther.add(hospitalRelationVO);
|
|
|
- keyExist.add(unionKey);
|
|
|
- } else {
|
|
|
- TranHospitalRelation tranHospitalRelation = new TranHospitalRelation();
|
|
|
- BeanUtil.copyProperties(hospitalRelationVO, tranHospitalRelation);
|
|
|
- tranHospitalRelation.setHospitalId(hospitalInfo.getId());
|
|
|
- tranHospitalRelation.setCreator(userId);
|
|
|
- tranHospitalRelation.setModifier(userId);
|
|
|
- tranHospitalRelation.setGmtCreate(now);
|
|
|
- tranHospitalRelation.setGmtModified(now);
|
|
|
- saveRelationList.add(tranHospitalRelation);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 有错误,直接返回
|
|
|
- if (ListUtil.isNotEmpty(errorOther) || ListUtil.isNotEmpty(errorCurrent)) {
|
|
|
- res.setErrorOther(errorOther);
|
|
|
- res.setErrorCurrent(errorCurrent);
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
// 先删除子医院关联表
|
|
|
tranHospitalRelationService.remove(new QueryWrapper<TranHospitalRelation>().eq("hospital_id", hospitalInfo.getId()));
|
|
|
// 插入子医院关联表
|