yuan
5 天以前 a13dc56f0ba6760a448ef19d72ee6db84bc84c6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.ruoyi.safe.controller;
 
import com.ruoyi.common.utils.SecurityUtils;
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.SafeLineInspection;
import com.ruoyi.safe.pojo.SafeLineInspectionRecord;
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.Arrays;
import java.util.List;
 
/**
 * <p>
 * 安全生产--线路巡检记录 前端控制器
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2026-06-29
 */
@RestController
@RequestMapping("/safeLineInspectionRecord")
@AllArgsConstructor
@Tag(name = "安全生产--线路巡检记录")
public class SafeLineInspectionRecordController {
 
    private SafeLineInspectionRecordService safeLineInspectionRecordService;
    private SafeLineInspectionService safeLineInspectionService;
 
    @GetMapping("/list/{inspectionId}")
    @Operation(summary = "根据巡检任务ID查询记录")
    public R listByInspectionId(@PathVariable Integer inspectionId) {
        return R.ok(safeLineInspectionRecordService.listByInspectionId(inspectionId));
    }
 
    @Operation(summary = "新增线路巡检记录")
    @Log(title = "线路巡检记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public R add(@RequestBody SafeLineInspectionRecord safeLineInspectionRecord) {
        boolean saved = safeLineInspectionRecordService.save(safeLineInspectionRecord);
        if (saved && safeLineInspectionRecord.getInspectionId() != null) {
            updateInspectionStatus(safeLineInspectionRecord.getInspectionId());
        }
        return R.ok(saved);
    }
 
    private void updateInspectionStatus(Integer inspectionId) {
        SafeLineInspection inspection = safeLineInspectionService.getById(inspectionId);
        if (inspection != null && "待巡检".equals(inspection.getStatus())) {
            Long currentUserId = SecurityUtils.getUserId();
            String currentUserIdStr = String.valueOf(currentUserId);
 
            String inspectorId = inspection.getInspectorId();
            if (inspectorId == null || inspectorId.isEmpty()) {
                inspectorId = currentUserIdStr;
            } else {
                String[] ids = inspectorId.split(",");
                boolean exists = Arrays.stream(ids).anyMatch(id -> id.trim().equals(currentUserIdStr));
                if (!exists) {
                    inspectorId = inspectorId + "," + currentUserIdStr;
                }
            }
 
            inspection.setStatus("巡检中");
            inspection.setInspectorId(inspectorId);
            inspection.setUpdateTime(LocalDateTime.now());
            inspection.setUpdateUser(currentUserId.intValue());
            safeLineInspectionService.updateById(inspection);
        }
    }
 
    @Operation(summary = "批量新增线路巡检记录")
    @Log(title = "线路巡检记录", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public R addBatch(@RequestBody List<SafeLineInspectionRecord> records) {
        return R.ok(safeLineInspectionRecordService.saveBatch(records));
    }
 
    @Operation(summary = "修改线路巡检记录")
    @Log(title = "线路巡检记录", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R update(@RequestBody SafeLineInspectionRecord safeLineInspectionRecord) {
        return R.ok(safeLineInspectionRecordService.updateById(safeLineInspectionRecord));
    }
 
    @Operation(summary = "删除线路巡检记录")
    @Log(title = "线路巡检记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R delSafeLineInspectionRecord(@PathVariable List<Integer> ids) {
        return R.ok(safeLineInspectionRecordService.removeBatchByIds(ids));
    }
}