xiaoyi
10 天以前 9efd8376cb0c444ce6f229b2544e68efa352f674
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package cn.iocoder.yudao.module.mes.controller.admin.safety;
 
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.controller.admin.safety.vo.inspection.*;
import cn.iocoder.yudao.module.mes.service.safety.SafetyInspectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
/**
 * 安全生产 - 巡检点位与巡检记录
 *
 * @author 超级管理员
 */
@Tag(name = "管理后台 - 安全生产-安全巡检")
@RestController
@RequestMapping("/safety/inspection")
@Validated
public class SafetyInspectionController {
 
    @Resource
    private SafetyInspectionService inspectionService;
 
    // ==================== 巡检点位 ====================
 
    @PostMapping("/point/create")
    @Operation(summary = "新增巡检点位")
    @PreAuthorize("@ss.hasPermission('safety:inspection-point:create')")
    public CommonResult<Long> createPoint(@Valid @RequestBody SafetyInspectionPointSaveReqVO reqVO) {
        return success(inspectionService.createPoint(reqVO));
    }
 
    @PutMapping("/point/update")
    @Operation(summary = "修改巡检点位")
    @PreAuthorize("@ss.hasPermission('safety:inspection-point:update')")
    public CommonResult<Boolean> updatePoint(@Valid @RequestBody SafetyInspectionPointSaveReqVO reqVO) {
        inspectionService.updatePoint(reqVO);
        return success(true);
    }
 
    @DeleteMapping("/point/delete")
    @Operation(summary = "删除巡检点位")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('safety:inspection-point:delete')")
    public CommonResult<Boolean> deletePoint(@RequestParam("id") Long id) {
        inspectionService.deletePoint(id);
        return success(true);
    }
 
    @GetMapping("/point/get")
    @Operation(summary = "获得巡检点位")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('safety:inspection-point:query')")
    public CommonResult<SafetyInspectionPointRespVO> getPoint(@RequestParam("id") Long id) {
        var point = inspectionService.getPoint(id);
        // 单条查询也要回填主数据最新值,不能只返回快照
        inspectionService.fillPointRefs(java.util.List.of(point));
        var resp = BeanUtils.toBean(point, SafetyInspectionPointRespVO.class);
        SafetyInspectionService.fillPointDisplay(point, resp);
        resp.setLastInspectTime(inspectionService.getLastInspectTime(id));
        return success(resp);
    }
 
    @GetMapping("/point/page")
    @Operation(summary = "获得巡检点位分页")
    @PreAuthorize("@ss.hasPermission('safety:inspection-point:query')")
    public CommonResult<PageResult<SafetyInspectionPointRespVO>> getPointPage(
            @Valid SafetyInspectionPointPageReqVO reqVO) {
        var page = inspectionService.getPointPage(reqVO);
        inspectionService.fillPointRefs(page.getList());
        var result = BeanUtils.toBean(page, SafetyInspectionPointRespVO.class);
        for (int i = 0; i < page.getList().size(); i++) {
            SafetyInspectionService.fillPointDisplay(page.getList().get(i), result.getList().get(i));
        }
        return success(result);
    }
 
    @GetMapping("/point/simple-list")
    @Operation(summary = "获得启用中的巡检点位精简列表(移动端巡检选择)")
    @PreAuthorize("@ss.hasPermission('safety:inspection-point:query')")
    public CommonResult<List<SafetyInspectionPointRespVO>> getPointSimpleList() {
        var points = inspectionService.getEnabledPointList();
        inspectionService.fillPointRefs(points);
        List<SafetyInspectionPointRespVO> list = points.stream()
                .map(point -> {
                    var resp = BeanUtils.toBean(point, SafetyInspectionPointRespVO.class);
                    SafetyInspectionService.fillPointDisplay(point, resp);
                    return resp;
                }).toList();
        return success(list);
    }
 
    // ==================== 巡检记录 ====================
 
    @PostMapping("/record/create")
    @Operation(summary = "新增巡检记录")
    @PreAuthorize("@ss.hasPermission('safety:inspection:create')")
    public CommonResult<Long> createRecord(@Valid @RequestBody SafetyInspectionSaveReqVO reqVO) {
        return success(inspectionService.createInspection(reqVO));
    }
 
    @PutMapping("/record/update")
    @Operation(summary = "修改巡检记录")
    @PreAuthorize("@ss.hasPermission('safety:inspection:update')")
    public CommonResult<Boolean> updateRecord(@Valid @RequestBody SafetyInspectionSaveReqVO reqVO) {
        inspectionService.updateInspection(reqVO);
        return success(true);
    }
 
    @DeleteMapping("/record/delete")
    @Operation(summary = "删除巡检记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('safety:inspection:delete')")
    public CommonResult<Boolean> deleteRecord(@RequestParam("id") Long id) {
        inspectionService.deleteInspection(id);
        return success(true);
    }
 
    @GetMapping("/record/get")
    @Operation(summary = "获得巡检记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('safety:inspection:query')")
    public CommonResult<SafetyInspectionRespVO> getRecord(@RequestParam("id") Long id) {
        var record = inspectionService.getInspection(id);
        inspectionService.fillInspectorNames(java.util.List.of(record));
        var resp = BeanUtils.toBean(record, SafetyInspectionRespVO.class);
        resp.setPointTypeName(cn.iocoder.yudao.module.mes.enums.safety.SafetyInspectionPointTypeEnum
                .getNameByType(record.getPointType()));
        resp.setResultName("NORMAL".equals(record.getResult()) ? "正常" : "异常");
        return success(resp);
    }
 
    @GetMapping("/record/page")
    @Operation(summary = "获得巡检记录分页")
    @PreAuthorize("@ss.hasPermission('safety:inspection:query')")
    public CommonResult<PageResult<SafetyInspectionRespVO>> getRecordPage(
            @Valid SafetyInspectionPageReqVO reqVO) {
        var page = inspectionService.getInspectionPage(reqVO);
        inspectionService.fillInspectorNames(page.getList());
        var result = BeanUtils.toBean(page, SafetyInspectionRespVO.class);
        for (int i = 0; i < page.getList().size(); i++) {
            var record = page.getList().get(i);
            var resp = result.getList().get(i);
            resp.setPointTypeName(cn.iocoder.yudao.module.mes.enums.safety.SafetyInspectionPointTypeEnum
                    .getNameByType(record.getPointType()));
            resp.setResultName("NORMAL".equals(record.getResult()) ? "正常" : "异常");
        }
        return success(result);
    }
 
}