| | |
| | | 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.SafeFacilityLedger; |
| | | import com.ruoyi.safe.service.SafeFacilityInspectionService; |
| | | import com.ruoyi.safe.service.SafeFacilityLedgerService; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | |
| | | public class SafeFacilityLedgerController { |
| | | |
| | | private SafeFacilityLedgerService safeFacilityLedgerService; |
| | | private SafeFacilityInspectionService safeFacilityInspectionService; |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "分页查询") |
| | |
| | | @Log(title = "安全设施台账", businessType = BusinessType.INSERT) |
| | | @PostMapping() |
| | | public R add(@RequestBody SafeFacilityLedger safeFacilityLedger) { |
| | | if (isCodeExists(safeFacilityLedger.getFacilityCode(), null)) { |
| | | return R.fail("设施编号「" + safeFacilityLedger.getFacilityCode() + "」已存在"); |
| | | } |
| | | return R.ok(safeFacilityLedgerService.save(safeFacilityLedger)); |
| | | } |
| | | |
| | |
| | | @Log(title = "安全设施台账", businessType = BusinessType.UPDATE) |
| | | @PutMapping() |
| | | public R update(@RequestBody SafeFacilityLedger safeFacilityLedger) { |
| | | if (isCodeExists(safeFacilityLedger.getFacilityCode(), safeFacilityLedger.getId())) { |
| | | return R.fail("设施编号「" + safeFacilityLedger.getFacilityCode() + "」已存在"); |
| | | } |
| | | return R.ok(safeFacilityLedgerService.updateById(safeFacilityLedger)); |
| | | } |
| | | |
| | | private boolean isCodeExists(String code, Integer excludeId) { |
| | | if (code == null || code.isEmpty()) return false; |
| | | return safeFacilityLedgerService.lambdaQuery() |
| | | .eq(SafeFacilityLedger::getFacilityCode, code) |
| | | .ne(excludeId != null, SafeFacilityLedger::getId, excludeId) |
| | | .count() > 0; |
| | | } |
| | | |
| | | @Operation(summary = "删除安全设施台账") |
| | | @Log(title = "安全设施台账", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public R delSafeFacilityLedger(@RequestBody List<Integer> ids) { |
| | | public R delSafeFacilityLedger(@PathVariable List<Integer> ids) { |
| | | // 校验设施是否有关联的巡检记录 |
| | | for (Integer id : ids) { |
| | | long count = safeFacilityInspectionService.lambdaQuery() |
| | | .eq(com.ruoyi.safe.pojo.SafeFacilityInspection::getFacilityId, id) |
| | | .count(); |
| | | if (count > 0) { |
| | | SafeFacilityLedger ledger = safeFacilityLedgerService.getById(id); |
| | | String name = ledger != null ? ledger.getFacilityName() : String.valueOf(id); |
| | | return R.fail("设施「" + name + "」存在关联的巡检记录,无法删除"); |
| | | } |
| | | } |
| | | return R.ok(safeFacilityLedgerService.removeBatchByIds(ids)); |
| | | } |
| | | } |