| | |
| | | package com.ruoyi.safe.controller; |
| | | |
| | | 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.SafeLineInspection; |
| | | import com.ruoyi.safe.pojo.SafeLineInspectionRecord; |
| | | import com.ruoyi.safe.service.SafeLineInspectionRecordService; |
| | | import com.ruoyi.safe.service.SafeLineInspectionService; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | public class SafeLineInspectionRecordController { |
| | | |
| | | private SafeLineInspectionRecordService safeLineInspectionRecordService; |
| | | private SafeLineInspectionService safeLineInspectionService; |
| | | |
| | | @GetMapping("/list/{inspectionId}") |
| | | @Operation(summary = "根据巡检任务ID查询记录") |
| | |
| | | @Log(title = "线路巡检记录", businessType = BusinessType.INSERT) |
| | | @PostMapping() |
| | | public R add(@RequestBody SafeLineInspectionRecord safeLineInspectionRecord) { |
| | | return R.ok(safeLineInspectionRecordService.save(safeLineInspectionRecord)); |
| | | boolean saved = safeLineInspectionRecordService.save(safeLineInspectionRecord); |
| | | if (saved && safeLineInspectionRecord.getInspectionId() != null) { |
| | | updateInspectionStatus(safeLineInspectionRecord.getInspectionId()); |
| | | } |
| | | return R.ok(saved); |
| | | } |
| | | |
| | | private void updateInspectionStatus(Integer inspectionId) { |
| | | SafeLineInspection inspection = safeLineInspectionService.getById(inspectionId); |
| | | if (inspection != null && "待巡检".equals(inspection.getStatus())) { |
| | | Long currentUserId = SecurityUtils.getUserId(); |
| | | String currentUserIdStr = String.valueOf(currentUserId); |
| | | |
| | | String inspectorId = inspection.getInspectorId(); |
| | | if (inspectorId == null || inspectorId.isEmpty()) { |
| | | inspectorId = currentUserIdStr; |
| | | } else { |
| | | String[] ids = inspectorId.split(","); |
| | | boolean exists = Arrays.stream(ids).anyMatch(id -> id.trim().equals(currentUserIdStr)); |
| | | if (!exists) { |
| | | inspectorId = inspectorId + "," + currentUserIdStr; |
| | | } |
| | | } |
| | | |
| | | inspection.setStatus("巡检中"); |
| | | inspection.setInspectorId(inspectorId); |
| | | inspection.setUpdateTime(LocalDateTime.now()); |
| | | inspection.setUpdateUser(currentUserId.intValue()); |
| | | safeLineInspectionService.updateById(inspection); |
| | | } |
| | | } |
| | | |
| | | @Operation(summary = "批量新增线路巡检记录") |
| | |
| | | @Operation(summary = "删除线路巡检记录") |
| | | @Log(title = "线路巡检记录", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public R delSafeLineInspectionRecord(@RequestBody List<Integer> ids) { |
| | | public R delSafeLineInspectionRecord(@PathVariable List<Integer> ids) { |
| | | return R.ok(safeLineInspectionRecordService.removeBatchByIds(ids)); |
| | | } |
| | | } |