Browse Source

BUG修复添加区域窗口中添加子区域无重复名称校验

jichaobo 2 years ago
parent
commit
89e856fa27

+ 22 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionAreaServiceImpl.java

@@ -60,6 +60,14 @@ public class PatrolInspectionAreaServiceImpl extends AbstractCrudService<PatrolI
         this.save(patrolInspectionArea);
         Integer areaFid = patrolInspectionArea.getId();
         for (int i = 0; i < patrolInspectionAreaVo.getAreaNameArray().length; i++) {
+            LambdaQueryWrapper<PatrolInspectionArea> queryWrapperOne = Wrappers.lambdaQuery();
+            queryWrapperOne.eq(PatrolInspectionArea::getEnable, 1)
+                    .eq(PatrolInspectionArea::getAreaName, patrolInspectionAreaVo.getAreaNameArray()[i])
+                    .eq(PatrolInspectionArea::getAreaFid, areaFid);
+            List<PatrolInspectionArea> list1 = this.list(queryWrapperOne);
+            if (list1.size() > 0) {
+                throw new BusinessException(patrolInspectionAreaVo.getAreaNameArray()[i] + "重复,子区域不可以重复");
+            }
             PatrolInspectionArea patrolInspectionAreaZ = new PatrolInspectionArea();
             patrolInspectionAreaZ.setAreaName(patrolInspectionAreaVo.getAreaNameArray()[i]);
             patrolInspectionAreaZ.setAreaFid(areaFid);
@@ -105,6 +113,20 @@ public class PatrolInspectionAreaServiceImpl extends AbstractCrudService<PatrolI
     @Override
     @Transactional
     public void updatePatrolInspectionArea(PatrolInspectionArea patrolInspectionArea) {
+        LambdaQueryWrapper<PatrolInspectionArea> queryWrapperOne = Wrappers.lambdaQuery();
+        queryWrapperOne.select(PatrolInspectionArea::getAreaFid)
+                .eq(PatrolInspectionArea::getId, patrolInspectionArea.getId())
+                .eq(PatrolInspectionArea::getEnable, 1);
+        PatrolInspectionArea patrolInspectionAreaMap = this.getOne(queryWrapperOne);
+        LambdaQueryWrapper<PatrolInspectionArea> queryWrapperTwo = Wrappers.lambdaQuery();
+        queryWrapperTwo.select(PatrolInspectionArea::getAreaFid)
+                .eq(PatrolInspectionArea::getAreaFid, patrolInspectionAreaMap.getAreaFid())
+                .eq(PatrolInspectionArea::getAreaName, patrolInspectionArea.getAreaName())
+                .eq(PatrolInspectionArea::getEnable, 1);
+        List<PatrolInspectionArea> list1 = this.list(queryWrapperTwo);
+        if (list1.size() > 0) {
+            throw new BusinessException(patrolInspectionArea.getAreaName() + "重复,区域不可以重复");
+        }
         this.updateById(patrolInspectionArea);
         LambdaQueryWrapper<PatrolInspectionArea> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.eq(PatrolInspectionArea::getAreaFid, patrolInspectionArea.getId())