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);
|
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);
|
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() {
|
List<SafetyInspectionPointRespVO> list = inspectionService.getEnabledPointList().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);
|
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);
|
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);
|
}
|
|
}
|