gongchunyi
4 天以前 d2f07163fc4074f335986dd51eedbdc7be9e19ea
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("请通过执行巡检提交正常结果;异常记录请在整改跟踪中由整改责任人完成整改");
    }
        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("该巡检任务存在关联的巡检记录或隐患,无法删除");
            }
        }
        return R.ok(safeLineInspectionService.removeBatchByIds(ids));
    }
}