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 createPoint(@Valid @RequestBody SafetyInspectionPointSaveReqVO reqVO) { return success(inspectionService.createPoint(reqVO)); } @PutMapping("/point/update") @Operation(summary = "修改巡检点位") @PreAuthorize("@ss.hasPermission('safety:inspection-point:update')") public CommonResult 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 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 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> 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> getPointSimpleList() { var points = inspectionService.getEnabledPointList(); inspectionService.fillPointRefs(points); List 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 createRecord(@Valid @RequestBody SafetyInspectionSaveReqVO reqVO) { return success(inspectionService.createInspection(reqVO)); } @PutMapping("/record/update") @Operation(summary = "修改巡检记录") @PreAuthorize("@ss.hasPermission('safety:inspection:update')") public CommonResult 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 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 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> 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); } }