巡检点配置校验

master
张乾翔 3 days ago
parent a7b70df43d
commit b11d6f94b4
  1. 36
      blade-service/blade-desk/src/main/java/org/springblade/desk/energy/controller/BsEpciuInspectionPointController.java
  2. 36
      blade-service/blade-desk/src/main/java/org/springblade/desk/energy/controller/BsSafeInspectionPointController.java
  3. 8
      blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/IBsEpciuInspectionPointService.java
  4. 8
      blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/IBsSafeInspectionPointService.java
  5. 13
      blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/impl/BsEpciuInspectionPointServiceImpl.java
  6. 16
      blade-service/blade-desk/src/main/java/org/springblade/desk/energy/service/impl/BsSafeInspectionPointServiceImpl.java

@ -117,6 +117,12 @@ 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() + "】已存在,不能重复添加");
}
}
return R.status(bsEpciuInspectionPointService.save(bsEpciuInspectionPoint));
}
@ -127,6 +133,12 @@ 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() + "】已存在,不能重复");
}
}
return R.status(bsEpciuInspectionPointService.updateById(bsEpciuInspectionPoint));
}
@ -137,6 +149,12 @@ 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() + "】已存在,不能重复");
}
}
return R.status(bsEpciuInspectionPointService.saveOrUpdate(bsEpciuInspectionPoint));
}
@ -207,6 +225,15 @@ 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() + "】已存在,不能重复导入");
}
}
}
// R checkR = ExcelExtUtil.importExcelCheck(file);
// if (checkR != null) {
// return checkR;
@ -223,6 +250,15 @@ public class BsEpciuInspectionPointController extends BladeController {
@ApiOperationSupport(order = 12)
@Operation(summary = "批量新增", description = "传入bsEpciuInspectionPointList")
public R saveList(@Valid @RequestBody List<BsEpciuInspectionPointEntity> bsEpciuInspectionPointList) {
// 校验批量数据中是否有重复的巡检点编号
for (BsEpciuInspectionPointEntity entity : bsEpciuInspectionPointList) {
if (entity.getInsNum() != null) {
if (bsEpciuInspectionPointService.checkDuplicate(entity.getInsNum(), entity.getId())) {
return R.fail("巡检点编号【" + entity.getInsNum() + "】已存在,不能重复添加");
}
}
}
return R.status(bsEpciuInspectionPointService.saveOrUpdateBatch(bsEpciuInspectionPointList));
}

@ -118,6 +118,12 @@ public class BsSafeInspectionPointController {
@ApiOperationSupport(order = 4)
@Operation(summary = "新增", description = "传入bsSafeInspectionPoint")
public R save(@Valid @RequestBody BsSafeInspectionPointEntity bsSafeInspectionPoint) {
// 校验巡检点编号是否重复
if (bsSafeInspectionPoint.getInsNum() != null) {
if (bsSafeInspectionPointService.checkDuplicate(bsSafeInspectionPoint.getInsNum(), null)) {
throw new RuntimeException("巡检点编号【" + bsSafeInspectionPoint.getInsNum() + "】已存在,不能重复添加");
}
}
return R.status(bsSafeInspectionPointService.save(bsSafeInspectionPoint));
}
@ -128,6 +134,12 @@ public class BsSafeInspectionPointController {
@ApiOperationSupport(order = 5)
@Operation(summary = "修改", description = "传入bsSafeInspectionPoint")
public R update(@Valid @RequestBody BsSafeInspectionPointEntity bsSafeInspectionPoint) {
// 校验巡检点编号是否重复(排除当前记录)
if (bsSafeInspectionPoint.getInsNum() != null) {
if (bsSafeInspectionPointService.checkDuplicate(bsSafeInspectionPoint.getInsNum(), bsSafeInspectionPoint.getId())) {
return R.fail("巡检点编号【" + bsSafeInspectionPoint.getInsNum() + "】已存在,不能重复");
}
}
return R.status(bsSafeInspectionPointService.updateById(bsSafeInspectionPoint));
}
@ -138,6 +150,12 @@ public class BsSafeInspectionPointController {
@ApiOperationSupport(order = 6)
@Operation(summary = "新增或修改", description = "传入bsSafeInspectionPoint")
public R submit(@Valid @RequestBody BsSafeInspectionPointEntity bsSafeInspectionPoint) {
// 校验巡检点编号是否重复
if (bsSafeInspectionPoint.getInsNum() != null) {
if (bsSafeInspectionPointService.checkDuplicate(bsSafeInspectionPoint.getInsNum(), bsSafeInspectionPoint.getId())) {
return R.fail("巡检点编号【" + bsSafeInspectionPoint.getInsNum() + "】已存在,不能重复");
}
}
return R.status(bsSafeInspectionPointService.saveOrUpdate(bsSafeInspectionPoint));
}
@ -212,6 +230,15 @@ public class BsSafeInspectionPointController {
&& !item.getInsNum().contains("注"))
.toList();
// 校验导入数据中是否有重复的巡检点编号
for (BsSafeInspectionPointEntity entity : importList) {
if (entity.getInsNum() != null) {
if (bsSafeInspectionPointService.checkDuplicate(entity.getInsNum(), null)) {
return R.fail("巡检点编号【" + entity.getInsNum() + "】已存在,不能重复导入");
}
}
}
return R.status(bsSafeInspectionPointService.saveBatch(importList));
}
/**
@ -221,6 +248,15 @@ public class BsSafeInspectionPointController {
@ApiOperationSupport(order = 12)
@Operation(summary = "批量新增", description = "传入bsSafeInspectionPointList")
public R saveList(@Valid @RequestBody List<BsSafeInspectionPointEntity> bsSafeInspectionPointList) {
// 校验批量数据中是否有重复的巡检点编号
for (BsSafeInspectionPointEntity entity : bsSafeInspectionPointList) {
if (entity.getInsNum() != null) {
if (bsSafeInspectionPointService.checkDuplicate(entity.getInsNum(), entity.getId())) {
return R.fail("巡检点编号【" + entity.getInsNum() + "】已存在,不能重复添加");
}
}
}
return R.status(bsSafeInspectionPointService.saveOrUpdateBatch(bsSafeInspectionPointList));
}
@PostMapping(value = "/print")

@ -62,4 +62,12 @@ public interface IBsEpciuInspectionPointService extends BaseService<BsEpciuInspe
List<BsEpciuInspectionPointEntity> getByCode(String code);
List<BsEpciuInspectionPointEntity> listByCode(String code);
/**
* 校验巡检点是否重复根据巡检点编号
* @param insNum 巡检点编号
* @param excludeId 排除的ID修改时使用新增时传null
* @return 是否存在重复
*/
boolean checkDuplicate(String insNum, Long excludeId);
}

@ -64,6 +64,14 @@ public interface IBsSafeInspectionPointService extends BaseService<BsSafeInspect
BsSafeInspectionPointEntity getByKey(Long ipId);
/**
* 校验巡检点是否重复根据巡检点编号
* @param insNum 巡检点编号
* @param excludeId 排除的ID修改时使用新增时传null
* @return 是否存在重复
*/
boolean checkDuplicate(String insNum, Long excludeId);
/**
* 导出pdf
* @param list

@ -26,6 +26,8 @@
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;
import org.springblade.desk.energy.mapper.BsEpciuInspectionPointMapper;
@ -74,4 +76,15 @@ public class BsEpciuInspectionPointServiceImpl extends BaseServiceImpl<BsEpciuIn
return getByCode(code);
}
@Override
public boolean checkDuplicate(String insNum, Long excludeId) {
if (StrUtil.isEmpty(insNum)) {
return false;
}
return count(
Wrappers.lambdaQuery(BsEpciuInspectionPointEntity.class)
.eq(BsEpciuInspectionPointEntity::getInsNum, insNum)
.ne(excludeId != null, BsEpciuInspectionPointEntity::getId, excludeId)
) > 0;
}
}

@ -26,6 +26,7 @@
package org.springblade.desk.energy.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -178,4 +179,19 @@ public class BsSafeInspectionPointServiceImpl extends BaseServiceImpl<BsSafeInsp
public BsSafeInspectionPointEntity getByKey(Long ipId) {
return getById(ipId);
}
@Override
public boolean checkDuplicate(String insNum, Long excludeId) {
if (StrUtil.isEmpty(insNum)) {
return false;
}
long count = count(
Wrappers.lambdaQuery(BsSafeInspectionPointEntity.class)
.eq(BsSafeInspectionPointEntity::getInsNum, insNum)
.ne(excludeId != null, BsSafeInspectionPointEntity::getId, excludeId)
);
return count > 0;
}
}

Loading…
Cancel
Save