package com.battery.business.web; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.battery.business.domain.TTestWarningException; import com.battery.business.mapper.TTestMapper; import com.battery.business.service.ITTestService; import com.battery.business.service.impl.TestWarningExceptionService; /** 测试预警异常查询与人工关闭接口。 */ @RestController @RequestMapping("/system/test-warning-exceptions") public class TTestWarningExceptionController extends BaseController { @Autowired private TTestMapper mapper; @Autowired private ITTestService testService; @Autowired private TestWarningExceptionService warningExceptionService; /** 按测试和状态查询后端异常事实。 */ @PreAuthorize("@ss.hasPermi('system:exception:query')") @GetMapping("/list") public TableDataInfo list(@RequestParam(required=false) Long testId, @RequestParam(required=false) String status) { startPage(); List rows = mapper.selectWarningExceptions(testId, status); return getDataTable(rows); } /** 校验测试负责人身份并关闭异常,同时追加测试审计事实。 */ @PreAuthorize("@ss.hasPermi('system:exception:handle')") @Log(title = "测试预警异常", businessType = BusinessType.UPDATE) @PutMapping("/{exceptionId}/close") public AjaxResult close(@PathVariable Long exceptionId, @RequestBody CloseRequest request) { if (request == null || request.handlingNote() == null || request.handlingNote().trim().isEmpty()) return error("处理结果不能为空"); TTestWarningException exception = mapper.selectWarningExceptionById(exceptionId); if (exception == null) return error("异常不存在"); var test = testService.selectTestById(exception.getTestId()); if (test == null || !getUserId().equals(test.getPrincipalId())) return error("仅测试负责人可以关闭预警异常"); int rows = warningExceptionService.close(exceptionId, getUserId(), getUsername(), request.handlingNote().trim()); return rows == 1 ? success(mapper.selectWarningExceptionById(exceptionId)) : error("异常已关闭或不存在"); } public record CloseRequest(String handlingNote) {} }