Parcourir la source

修改医院信息

zhoutg il y a 3 ans
Parent
commit
e9fac5d38a

+ 47 - 31
cdssman-service/src/main/java/com/diagbot/facade/HospitalInfoFacade.java

@@ -104,7 +104,6 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
      * @return
      */
     public HospitalRelationErrorDTO saveOrUpdateRecord(HospitalInfoSaveVO hospitalInfoSaveVO) {
-        HospitalRelationErrorDTO res = new HospitalRelationErrorDTO(); // 返回类
         String userId = UserUtils.getCurrentPrincipleID();
         HospitalInfo hospitalInfo = new HospitalInfo();
         BeanUtil.copyProperties(hospitalInfoSaveVO, hospitalInfo);
@@ -123,6 +122,52 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
 
         // 获取子医院
         List<HospitalRelationVO> hospitalRelationVOList = hospitalInfoSaveVO.getHospitalRelationVOList();
+        // 校验子医院
+        HospitalRelationErrorDTO res = checkRelationHospital(hospitalRelationVOList, hospitalInfo.getId());
+        if (res != null) {
+            return res;
+        }
+
+        // 新增数据
+        if (hospitalInfo.getId() == null) {
+            hospitalInfo.setCreator(userId);
+            hospitalInfo.setGmtCreate(now);
+            hospitalInfo.setConnect(1);
+        }
+        if (StringUtil.isBlank(hospitalInfo.getSpell())) {
+            hospitalInfo.setSpell(Cn2SpellUtil.converterToFirstSpell(hospitalInfo.getName()));
+        }
+        this.saveOrUpdate(hospitalInfo);
+
+        // 先删除子医院关联表
+        tranHospitalRelationService.remove(new QueryWrapper<TranHospitalRelation>().eq("hospital_id", hospitalInfo.getId()));
+        // 插入子医院关联表
+        List<TranHospitalRelation> saveRelationList = Lists.newArrayList();
+        for (HospitalRelationVO hospitalRelationVO : hospitalRelationVOList) {
+            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(saveRelationList)) {
+            tranHospitalRelationService.saveBatch(saveRelationList);
+        }
+        return null;
+    }
+
+    /**
+     * 校验子医院
+     *
+     * @param hospitalRelationVOList
+     * @param curHospitalId
+     * @return
+     */
+    public HospitalRelationErrorDTO checkRelationHospital(List<HospitalRelationVO> hospitalRelationVOList, Long curHospitalId) {
+        HospitalRelationErrorDTO res = new HospitalRelationErrorDTO();
         if (ListUtil.isNotEmpty(hospitalRelationVOList)) {
             // 校验name+code唯一性
             List<TranHospitalRelation> tranHospitalRelationList = tranHospitalRelationService.list(new QueryWrapper<TranHospitalRelation>()
@@ -145,7 +190,7 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
                 }
                 // 判断与其他医院重复
                 Long hospitalId = relationMap.get(unionKey);
-                if (hospitalId != null && !hospitalId.equals(hospitalInfo.getId()) && !keyExist.contains(unionKey)) {
+                if (hospitalId != null && !hospitalId.equals(curHospitalId) && !keyExist.contains(unionKey)) {
                     errorOther.add(hospitalRelationVO);
                     keyExist.add(unionKey);
                 }
@@ -158,35 +203,6 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
                 return res;
             }
         }
-
-        // 新增数据
-        if (hospitalInfo.getId() == null) {
-            hospitalInfo.setCreator(userId);
-            hospitalInfo.setGmtCreate(now);
-            hospitalInfo.setConnect(1);
-        }
-        if (StringUtil.isBlank(hospitalInfo.getSpell())) {
-            hospitalInfo.setSpell(Cn2SpellUtil.converterToFirstSpell(hospitalInfo.getName()));
-        }
-        this.saveOrUpdate(hospitalInfo);
-
-        // 先删除子医院关联表
-        tranHospitalRelationService.remove(new QueryWrapper<TranHospitalRelation>().eq("hospital_id", hospitalInfo.getId()));
-        // 插入子医院关联表
-        List<TranHospitalRelation> saveRelationList = Lists.newArrayList();
-        for (HospitalRelationVO hospitalRelationVO : hospitalRelationVOList) {
-            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(saveRelationList)) {
-            tranHospitalRelationService.saveBatch(saveRelationList);
-        }
         return null;
     }