| | |
| | | package com.ruoyi.safe.controller; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.SafeFacilityInspection; |
| | | import com.ruoyi.safe.pojo.SafeFacilityRectification; |
| | | import com.ruoyi.safe.service.SafeFacilityInspectionService; |
| | | import com.ruoyi.safe.service.SafeFacilityRectificationService; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | public class SafeFacilityInspectionController { |
| | | |
| | | private SafeFacilityInspectionService safeFacilityInspectionService; |
| | | private SafeFacilityRectificationService safeFacilityRectificationService; |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "分页查询") |
| | |
| | | @Log(title = "安全设施巡检", businessType = BusinessType.INSERT) |
| | | @PostMapping() |
| | | public R add(@RequestBody SafeFacilityInspection safeFacilityInspection) { |
| | | if (isInspectionCodeExists(safeFacilityInspection.getInspectionCode(), null)) { |
| | | return R.fail("巡检编号「" + safeFacilityInspection.getInspectionCode() + "」已存在"); |
| | | } |
| | | if (safeFacilityInspection.getInspectorId() == null) { |
| | | Long currentUserId = SecurityUtils.getUserId(); |
| | | safeFacilityInspection.setInspectorId(currentUserId.intValue()); |
| | | } |
| | | safeFacilityInspection.setStatus("待巡检"); |
| | | return R.ok(safeFacilityInspectionService.save(safeFacilityInspection)); |
| | | } |
| | | |
| | | private boolean isInspectionCodeExists(String code, Integer excludeId) { |
| | | if (code == null || code.isEmpty()) return false; |
| | | return safeFacilityInspectionService.lambdaQuery() |
| | | .eq(SafeFacilityInspection::getInspectionCode, code) |
| | | .ne(excludeId != null, SafeFacilityInspection::getId, excludeId) |
| | | .count() > 0; |
| | | } |
| | | |
| | | @Operation(summary = "修改安全设施巡检") |
| | |
| | | @Operation(summary = "删除安全设施巡检") |
| | | @Log(title = "安全设施巡检", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public R delSafeFacilityInspection(@RequestBody List<Integer> ids) { |
| | | public R delSafeFacilityInspection(@PathVariable List<Integer> ids) { |
| | | for (Integer id : ids) { |
| | | long count = safeFacilityRectificationService.lambdaQuery() |
| | | .eq(SafeFacilityRectification::getInspectionId, id).count(); |
| | | if (count > 0) { |
| | | return R.fail("该巡检记录存在关联的整改记录,无法删除"); |
| | | } |
| | | } |
| | | return R.ok(safeFacilityInspectionService.removeBatchByIds(ids)); |
| | | } |
| | | } |