From d4a3ddfeac6aea951c51bee91d9cf4eb57c4f4c4 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 30 六月 2026 14:31:07 +0800
Subject: [PATCH] feat(safe): 完善安全巡检系统功能

---
 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