From 07496adb3a0c61e48c660e0cb4ee95d44782f05d Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期四, 23 七月 2026 10:18:37 +0800
Subject: [PATCH] fix: 修改新增绑定逻辑,避免重复绑定产品
---
src/main/java/com/ruoyi/safe/controller/SafeFacilityLedgerController.java | 30 +++++++++++++++++++++++++++++-
1 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/ruoyi/safe/controller/SafeFacilityLedgerController.java b/src/main/java/com/ruoyi/safe/controller/SafeFacilityLedgerController.java
index 5b59298..a17f0a3 100644
--- a/src/main/java/com/ruoyi/safe/controller/SafeFacilityLedgerController.java
+++ b/src/main/java/com/ruoyi/safe/controller/SafeFacilityLedgerController.java
@@ -4,7 +4,9 @@
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.safe.pojo.SafeFacilityInspection;
import com.ruoyi.safe.pojo.SafeFacilityLedger;
+import com.ruoyi.safe.service.SafeFacilityInspectionService;
import com.ruoyi.safe.service.SafeFacilityLedgerService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
@@ -28,6 +30,7 @@
public class SafeFacilityLedgerController {
private SafeFacilityLedgerService safeFacilityLedgerService;
+ private SafeFacilityInspectionService safeFacilityInspectionService;
@GetMapping("/page")
@Operation(summary = "鍒嗛〉鏌ヨ")
@@ -45,6 +48,9 @@
@Log(title = "瀹夊叏璁炬柦鍙拌处", businessType = BusinessType.INSERT)
@PostMapping()
public R add(@RequestBody SafeFacilityLedger safeFacilityLedger) {
+ if (isCodeExists(safeFacilityLedger.getFacilityCode(), null)) {
+ return R.fail("璁炬柦缂栧彿銆�" + safeFacilityLedger.getFacilityCode() + "銆嶅凡瀛樺湪");
+ }
return R.ok(safeFacilityLedgerService.save(safeFacilityLedger));
}
@@ -52,13 +58,35 @@
@Log(title = "瀹夊叏璁炬柦鍙拌处", businessType = BusinessType.UPDATE)
@PutMapping()
public R update(@RequestBody SafeFacilityLedger safeFacilityLedger) {
+ if (isCodeExists(safeFacilityLedger.getFacilityCode(), safeFacilityLedger.getId())) {
+ return R.fail("璁炬柦缂栧彿銆�" + safeFacilityLedger.getFacilityCode() + "銆嶅凡瀛樺湪");
+ }
return R.ok(safeFacilityLedgerService.updateById(safeFacilityLedger));
+ }
+
+ private boolean isCodeExists(String code, Integer excludeId) {
+ if (code == null || code.isEmpty()) return false;
+ return safeFacilityLedgerService.lambdaQuery()
+ .eq(SafeFacilityLedger::getFacilityCode, code)
+ .ne(excludeId != null, SafeFacilityLedger::getId, excludeId)
+ .count() > 0;
}
@Operation(summary = "鍒犻櫎瀹夊叏璁炬柦鍙拌处")
@Log(title = "瀹夊叏璁炬柦鍙拌处", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
- public R delSafeFacilityLedger(@RequestBody List<Integer> ids) {
+ public R delSafeFacilityLedger(@PathVariable List<Integer> ids) {
+ // 鏍¢獙璁炬柦鏄惁鏈夊叧鑱旂殑宸℃璁板綍
+ for (Integer id : ids) {
+ long count = safeFacilityInspectionService.lambdaQuery()
+ .eq(com.ruoyi.safe.pojo.SafeFacilityInspection::getFacilityId, id)
+ .count();
+ if (count > 0) {
+ SafeFacilityLedger ledger = safeFacilityLedgerService.getById(id);
+ String name = ledger != null ? ledger.getFacilityName() : String.valueOf(id);
+ return R.fail("璁炬柦銆�" + name + "銆嶅瓨鍦ㄥ叧鑱旂殑宸℃璁板綍锛屾棤娉曞垹闄�");
+ }
+ }
return R.ok(safeFacilityLedgerService.removeBatchByIds(ids));
}
}
--
Gitblit v1.9.3