Przeglądaj źródła

【CHG】修改地感器验证方法

zhaomn 3 lat temu
rodzic
commit
959c6cee03

+ 51 - 8
railway-business/src/main/java/com/railway/business/baseinfo/service/impl/BusDmcgyqServiceImpl.java

@@ -39,7 +39,7 @@ public class BusDmcgyqServiceImpl implements IBusDmcgyqService {
   @Transactional(rollbackFor = Exception.class)
   public int create(BusDmcgyq busDmcgyq) {
     // 校验设备是否已经存在
-    checkDmcgyq(busDmcgyq);
+    checkNewDmcgyq(busDmcgyq);
     // 设置默认字段值
     BaseDeptStation deptStation = stationService.getInfo(busDmcgyq.getDeptId(),
         busDmcgyq.getLineId(), busDmcgyq.getStationId());
@@ -70,7 +70,7 @@ public class BusDmcgyqServiceImpl implements IBusDmcgyqService {
   @Transactional(rollbackFor = Exception.class)
   public int update(BusDmcgyq busDmcgyq) {
     // 校验设备是否已经存在
-    checkDmcgyq(busDmcgyq);
+    checkUpdateDmcgyq(busDmcgyq);
     // 设置默认字段值
     BaseDeptStation deptStation = stationService.getInfo(busDmcgyq.getDeptId(),
         busDmcgyq.getLineId(), busDmcgyq.getStationId());
@@ -101,17 +101,60 @@ public class BusDmcgyqServiceImpl implements IBusDmcgyqService {
     return busDmcgyqMapper.listTeam(query);
   }
 
-  private void checkDmcgyq(BusDmcgyq busDmcgyq){
-    BusDmcgyq query = new BusDmcgyq();
-    query.setTeam(busDmcgyq.getTeam());
-    query.setSbbh(busDmcgyq.getSbbh());
-    List<BusDmcgyq> dmcgyqList = this.getList(query);
+  private void checkUpdateDmcgyq(BusDmcgyq busDmcgyq) {
+    // 组号重复
+    List<BusDmcgyq> dmcgyqList = getDmcgyqByTeam(busDmcgyq);
     if (CollectionUtils.isNotEmpty(dmcgyqList)) {
       // 如果按照组号和设备编号查询的结果大于1,或者仅1条时,主键字段是新的,表示已经存在
-      if(dmcgyqList.size() > 1 || !dmcgyqList.get(0).getId().equals(busDmcgyq.getId())) {
+      if (dmcgyqList.size() > 1 || !dmcgyqList.get(0).getId().equals(busDmcgyq.getId())) {
         throw new ServiceException("地面磁感应器设备组“" + busDmcgyq.getTeam() + "”已经存在编号为"
             + busDmcgyq.getSbbh() + "的设备,请检查!");
       }
     }
+
+    // 设备是否在其他分组中
+    dmcgyqList = this.getDmcgyqByStation(busDmcgyq);
+    if (CollectionUtils.isNotEmpty(dmcgyqList)) {
+      // 如果按照组号和设备编号查询的结果大于1,或者仅1条时,主键字段是新的,表示已经存在
+      if (dmcgyqList.size() > 1 || !dmcgyqList.get(0).getId().equals(busDmcgyq.getId())) {
+        throw new ServiceException("该设备支柱号:" + busDmcgyq.getPillarArea()
+            + ",已经在地面磁感应器设备组“" + dmcgyqList.get(0).getTeam() + "”中,请检查!");
+      }
+    }
   }
+
+  private void checkNewDmcgyq(BusDmcgyq busDmcgyq) {
+    // 组号重复
+    List<BusDmcgyq> dmcgyqList = getDmcgyqByTeam(busDmcgyq);
+    if (CollectionUtils.isNotEmpty(dmcgyqList)) {
+      // 如果按照组号和设备编号查询的结果大于1,表示已经存在
+      throw new ServiceException("地面磁感应器设备组“" + busDmcgyq.getTeam() + "”已经存在编号为"
+          + busDmcgyq.getSbbh() + "的设备,请检查!");
+    }
+
+    // 设备是否在其他分组中
+    dmcgyqList = this.getDmcgyqByStation(busDmcgyq);
+    if (CollectionUtils.isNotEmpty(dmcgyqList)) {
+      // 如果按照组号和设备编号查询的结果大于1,表示已经存在
+      throw new ServiceException("该设备支柱号:" + busDmcgyq.getPillarArea()
+          + ",已经在地面磁感应器设备组“" + dmcgyqList.get(0).getTeam() + "”中,请检查!");
+    }
+  }
+
+  private List<BusDmcgyq> getDmcgyqByTeam(BusDmcgyq busDmcgyq) {
+    BusDmcgyq query = new BusDmcgyq();
+    query.setTeam(busDmcgyq.getTeam());
+    query.setSbbh(busDmcgyq.getSbbh());
+    return getList(query);
+  }
+
+  private List<BusDmcgyq> getDmcgyqByStation(BusDmcgyq busDmcgyq) {
+    BusDmcgyq query = new BusDmcgyq();
+    query.setStationId(busDmcgyq.getStationId());
+    query.setLineId(busDmcgyq.getLineId());
+    query.setPillarArea(busDmcgyq.getPillarArea());
+    query.setSbbh(busDmcgyq.getSbbh());
+    return getList(query);
+  }
+
 }