diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/controller/BsEpciuInspectionPointController.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/controller/BsEpciuInspectionPointController.java index 83671f98..1548f1af 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/controller/BsEpciuInspectionPointController.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/controller/BsEpciuInspectionPointController.java @@ -117,10 +117,10 @@ public class BsEpciuInspectionPointController extends BladeController { @ApiOperationSupport(order = 4) @Operation(summary = "新增", description = "传入bsEpciuInspectionPoint") public R save(@Valid @RequestBody BsEpciuInspectionPointEntity bsEpciuInspectionPoint) { - // 校验巡检点编号是否重复 + // 校验巡检点编号和类型是否重复 if (bsEpciuInspectionPoint.getInsNum() != null) { - if (bsEpciuInspectionPointService.checkDuplicate(bsEpciuInspectionPoint.getInsNum(), null)) { - throw new RuntimeException("巡检点编号【" + bsEpciuInspectionPoint.getInsNum() + "】已存在,不能重复添加"); + if (bsEpciuInspectionPointService.checkDuplicate(bsEpciuInspectionPoint.getInsNum(), bsEpciuInspectionPoint.getInsType(), null)) { + throw new RuntimeException("巡检点编号【" + bsEpciuInspectionPoint.getInsNum() + "】和巡检点类型的组合已存在,不能重复添加"); } } return R.status(bsEpciuInspectionPointService.save(bsEpciuInspectionPoint)); @@ -133,10 +133,10 @@ public class BsEpciuInspectionPointController extends BladeController { @ApiOperationSupport(order = 5) @Operation(summary = "修改", description = "传入bsEpciuInspectionPoint") public R update(@Valid @RequestBody BsEpciuInspectionPointEntity bsEpciuInspectionPoint) { - // 校验巡检点编号是否重复(排除当前记录) + // 校验巡检点编号和类型是否重复(排除当前记录) if (bsEpciuInspectionPoint.getInsNum() != null) { - if (bsEpciuInspectionPointService.checkDuplicate(bsEpciuInspectionPoint.getInsNum(), bsEpciuInspectionPoint.getId())) { - return R.fail("巡检点编号【" + bsEpciuInspectionPoint.getInsNum() + "】已存在,不能重复"); + if (bsEpciuInspectionPointService.checkDuplicate(bsEpciuInspectionPoint.getInsNum(), bsEpciuInspectionPoint.getInsType(), bsEpciuInspectionPoint.getId())) { + return R.fail("巡检点编号【" + bsEpciuInspectionPoint.getInsNum() + "】和巡检点类型的组合已存在,不能重复"); } } return R.status(bsEpciuInspectionPointService.updateById(bsEpciuInspectionPoint)); @@ -149,10 +149,10 @@ public class BsEpciuInspectionPointController extends BladeController { @ApiOperationSupport(order = 6) @Operation(summary = "新增或修改", description = "传入bsEpciuInspectionPoint") public R submit(@Valid @RequestBody BsEpciuInspectionPointEntity bsEpciuInspectionPoint) { - // 校验巡检点编号是否重复 + // 校验巡检点编号和类型是否重复 if (bsEpciuInspectionPoint.getInsNum() != null) { - if (bsEpciuInspectionPointService.checkDuplicate(bsEpciuInspectionPoint.getInsNum(), bsEpciuInspectionPoint.getId())) { - return R.fail("巡检点编号【" + bsEpciuInspectionPoint.getInsNum() + "】已存在,不能重复"); + if (bsEpciuInspectionPointService.checkDuplicate(bsEpciuInspectionPoint.getInsNum(), bsEpciuInspectionPoint.getInsType(), bsEpciuInspectionPoint.getId())) { + return R.fail("巡检点编号【" + bsEpciuInspectionPoint.getInsNum() + "】和巡检点类型的组合已存在,不能重复"); } } return R.status(bsEpciuInspectionPointService.saveOrUpdate(bsEpciuInspectionPoint)); @@ -225,11 +225,11 @@ public class BsEpciuInspectionPointController extends BladeController { noticeList.add(notice); }); - // 校验导入数据中是否有重复的巡检点编号 + // 校验导入数据中是否有重复的巡检点编号和类型组合 for (BsEpciuInspectionPointEntity entity : noticeList) { if (entity.getInsNum() != null) { - if (bsEpciuInspectionPointService.checkDuplicate(entity.getInsNum(), null)) { - return R.fail("巡检点编号【" + entity.getInsNum() + "】已存在,不能重复导入"); + if (bsEpciuInspectionPointService.checkDuplicate(entity.getInsNum(), entity.getInsType(), null)) { + return R.fail("巡检点编号【" + entity.getInsNum() + "】和巡检点类型【" + entity.getInsType() + "】的组合已存在,不能重复导入"); } } } @@ -250,11 +250,11 @@ public class BsEpciuInspectionPointController extends BladeController { @ApiOperationSupport(order = 12) @Operation(summary = "批量新增", description = "传入bsEpciuInspectionPointList") public R saveList(@Valid @RequestBody List bsEpciuInspectionPointList) { - // 校验批量数据中是否有重复的巡检点编号 + // 校验批量数据中是否有重复的巡检点编号和类型组合 for (BsEpciuInspectionPointEntity entity : bsEpciuInspectionPointList) { if (entity.getInsNum() != null) { - if (bsEpciuInspectionPointService.checkDuplicate(entity.getInsNum(), entity.getId())) { - return R.fail("巡检点编号【" + entity.getInsNum() + "】已存在,不能重复添加"); + if (bsEpciuInspectionPointService.checkDuplicate(entity.getInsNum(), entity.getInsType(), entity.getId())) { + return R.fail("巡检点编号【" + entity.getInsNum() + "】和巡检点类型【" + entity.getInsType() + "】的组合已存在,不能重复添加"); } } } diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/IBsEpciuInspectionPointService.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/IBsEpciuInspectionPointService.java index af370188..21636259 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/IBsEpciuInspectionPointService.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/IBsEpciuInspectionPointService.java @@ -64,10 +64,11 @@ public interface IBsEpciuInspectionPointService extends BaseService listByCode(String code); /** - * 校验巡检点是否重复(根据巡检点编号) + * 校验巡检点是否重复(根据巡检点编号和巡检点类型) * @param insNum 巡检点编号 + * @param insType 巡检点类型 * @param excludeId 排除的ID(修改时使用,新增时传null) * @return 是否存在重复 */ - boolean checkDuplicate(String insNum, Long excludeId); + boolean checkDuplicate(String insNum, String insType, Long excludeId); } diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/impl/BsEpciuInspectionPointServiceImpl.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/impl/BsEpciuInspectionPointServiceImpl.java index e394bb29..f56f1bfe 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/impl/BsEpciuInspectionPointServiceImpl.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/impl/BsEpciuInspectionPointServiceImpl.java @@ -26,7 +26,6 @@ package org.springblade.desk.energy.service.impl; -import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springblade.desk.energy.excel.BsEpciuInspectionPointExcel; @@ -77,14 +76,18 @@ public class BsEpciuInspectionPointServiceImpl extends BaseServiceImpl 0; + + long count = count( + Wrappers.lambdaQuery(BsEpciuInspectionPointEntity.class) + .eq(BsEpciuInspectionPointEntity::getInsNum, insNum) + .eq(StrUtil.isNotEmpty(insType), BsEpciuInspectionPointEntity::getInsType, insType) + .ne(excludeId != null, BsEpciuInspectionPointEntity::getId, excludeId) + ); + + return count > 0; } }