From d2f07163fc4074f335986dd51eedbdc7be9e19ea Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 30 七月 2026 11:52:47 +0800
Subject: [PATCH] fix: 线路巡检调整

---
 src/main/java/com/ruoyi/safe/controller/SafeLineInspectionController.java |   64 +++++++++++++++++++++++++++-----
 1 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/ruoyi/safe/controller/SafeLineInspectionController.java b/src/main/java/com/ruoyi/safe/controller/SafeLineInspectionController.java
index ac4ac33..63f7766 100644
--- a/src/main/java/com/ruoyi/safe/controller/SafeLineInspectionController.java
+++ b/src/main/java/com/ruoyi/safe/controller/SafeLineInspectionController.java
@@ -5,14 +5,18 @@
 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.dto.SafeLineInspectionExecuteDto;
 import com.ruoyi.safe.pojo.SafeLineInspection;
+import com.ruoyi.safe.pojo.SafeLineInspectionHazard;
+import com.ruoyi.safe.pojo.SafeLineInspectionRecord;
+import com.ruoyi.safe.service.SafeLineInspectionHazardService;
+import com.ruoyi.safe.service.SafeLineInspectionRecordService;
 import com.ruoyi.safe.service.SafeLineInspectionService;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.Operation;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
-import java.time.LocalDateTime;
 import java.util.List;
 
 /**
@@ -30,6 +34,8 @@
 public class SafeLineInspectionController {
 
     private SafeLineInspectionService safeLineInspectionService;
+    private SafeLineInspectionHazardService safeLineInspectionHazardService;
+    private SafeLineInspectionRecordService safeLineInspectionRecordService;
 
     @GetMapping("/page")
     @Operation(summary = "鍒嗛〉鏌ヨ")
@@ -47,8 +53,15 @@
     @Log(title = "绾胯矾宸℃", businessType = BusinessType.INSERT)
     @PostMapping()
     public R add(@RequestBody SafeLineInspection safeLineInspection) {
-        // 鏂板鏃堕粯璁ょ姸鎬佷负"寰呭贰妫�"
+        if (isInspectionCodeExists(safeLineInspection.getInspectionCode(), null)) {
+            return R.fail("宸℃缂栧彿銆�" + safeLineInspection.getInspectionCode() + "銆嶅凡瀛樺湪");
+        }
         safeLineInspection.setStatus("寰呭贰妫�");
+        Long currentUserId = SecurityUtils.getUserId();
+        safeLineInspection.setAssignUserId(currentUserId.intValue());
+        if (safeLineInspection.getInspectorId() != null && safeLineInspection.getInspectorId().isEmpty()) {
+            safeLineInspection.setInspectorId(null);
+        }
         return R.ok(safeLineInspectionService.save(safeLineInspection));
     }
 
@@ -56,10 +69,24 @@
     @Log(title = "绾胯矾宸℃", businessType = BusinessType.UPDATE)
     @PutMapping()
     public R update(@RequestBody SafeLineInspection safeLineInspection) {
+        if (isInspectionCodeExists(safeLineInspection.getInspectionCode(), safeLineInspection.getId())) {
+            return R.fail("宸℃缂栧彿銆�" + safeLineInspection.getInspectionCode() + "銆嶅凡瀛樺湪");
+        }
+        if (safeLineInspection.getInspectorId() != null && safeLineInspection.getInspectorId().isEmpty()) {
+            safeLineInspection.setInspectorId(null);
+        }
         return R.ok(safeLineInspectionService.updateById(safeLineInspection));
     }
 
-    @Operation(summary = "瀹屾垚宸℃")
+    private boolean isInspectionCodeExists(String code, Integer excludeId) {
+        if (code == null || code.isEmpty()) return false;
+        return safeLineInspectionService.lambdaQuery()
+                .eq(SafeLineInspection::getInspectionCode, code)
+                .ne(excludeId != null, SafeLineInspection::getId, excludeId)
+                .count() > 0;
+    }
+
+    @Operation(summary = "搴熷純鏃у贰妫�瀹屾垚鎺ュ彛")
     @Log(title = "绾胯矾宸℃", businessType = BusinessType.UPDATE)
     @PutMapping("/complete/{id}")
     public R complete(@PathVariable Integer id) {
@@ -67,19 +94,36 @@
         if (inspection == null) {
             return R.fail("宸℃浠诲姟涓嶅瓨鍦�");
         }
+        if ("宸插畬鎴�".equals(inspection.getStatus())) {
+            return R.fail("宸℃浠诲姟宸插畬鎴愶紝璇峰嬁閲嶅鎿嶄綔");
+        }
+        return R.fail("璇烽�氳繃鎵ц宸℃鎻愪氦姝e父缁撴灉锛涘紓甯歌褰曡鍦ㄦ暣鏀硅窡韪腑鐢辨暣鏀硅矗浠讳汉瀹屾垚鏁存敼");
+    }
 
-        Long currentUserId = SecurityUtils.getUserId();
-        inspection.setStatus("宸插畬鎴�");
-        inspection.setUpdateTime(LocalDateTime.now());
-        inspection.setUpdateUser(currentUserId.intValue());
-
-        return R.ok(safeLineInspectionService.updateById(inspection));
+    @Operation(summary = "鎵ц宸℃")
+    @Log(title = "绾胯矾宸℃", businessType = BusinessType.UPDATE)
+    @PutMapping("/execute")
+    public R execute(@RequestBody SafeLineInspectionExecuteDto executeDto) {
+        try {
+            return R.ok(safeLineInspectionService.executeInspection(executeDto));
+        } catch (IllegalArgumentException e) {
+            return R.fail(e.getMessage());
+        }
     }
 
     @Operation(summary = "鍒犻櫎绾胯矾宸℃浠诲姟")
     @Log(title = "绾胯矾宸℃", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
-    public R delSafeLineInspection(@RequestBody List<Integer> ids) {
+    public R delSafeLineInspection(@PathVariable List<Integer> ids) {
+        for (Integer id : ids) {
+            long recordCount = safeLineInspectionRecordService.lambdaQuery()
+                    .eq(SafeLineInspectionRecord::getInspectionId, id).count();
+            long hazardCount = safeLineInspectionHazardService.lambdaQuery()
+                    .eq(SafeLineInspectionHazard::getInspectionId, id).count();
+            if (recordCount > 0 || hazardCount > 0) {
+                return R.fail("璇ュ贰妫�浠诲姟瀛樺湪鍏宠仈鐨勫贰妫�璁板綍鎴栭殣鎮o紝鏃犳硶鍒犻櫎");
+            }
+        }
         return R.ok(safeLineInspectionService.removeBatchByIds(ids));
     }
 }

--
Gitblit v1.9.3