houzhongjian
2024-08-02 d141aee7ec84d3578a19be8c26f10759c1e557b4
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.controller.admin.logger;
H 2
3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.pojo.PageParam;
6 import com.iailab.framework.common.pojo.PageResult;
7 import com.iailab.framework.common.util.object.BeanUtils;
8 import com.iailab.framework.excel.core.util.ExcelUtils;
9 import com.iailab.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
10 import com.iailab.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogRespVO;
11 import com.iailab.module.infra.dal.dataobject.logger.ApiErrorLogDO;
12 import com.iailab.module.infra.service.logger.ApiErrorLogService;
13 import io.swagger.v3.oas.annotations.Operation;
14 import io.swagger.v3.oas.annotations.Parameter;
15 import io.swagger.v3.oas.annotations.Parameters;
16 import io.swagger.v3.oas.annotations.tags.Tag;
17 import org.springframework.security.access.prepost.PreAuthorize;
18 import org.springframework.validation.annotation.Validated;
19 import org.springframework.web.bind.annotation.*;
20
21 import javax.annotation.Resource;
22 import javax.servlet.http.HttpServletResponse;
23 import javax.validation.Valid;
24 import java.io.IOException;
25 import java.util.List;
26
27 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
28 import static com.iailab.framework.common.pojo.CommonResult.success;
29 import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
30
31 @Tag(name = "管理后台 - API 错误日志")
32 @RestController
33 @RequestMapping("/infra/api-error-log")
34 @Validated
35 public class ApiErrorLogController {
36
37     @Resource
38     private ApiErrorLogService apiErrorLogService;
39
40     @PutMapping("/update-status")
41     @Operation(summary = "更新 API 错误日志的状态")
42     @Parameters({
43             @Parameter(name = "id", description = "编号", required = true, example = "1024"),
44             @Parameter(name = "processStatus", description = "处理状态", required = true, example = "1")
45     })
46     @PreAuthorize("@ss.hasPermission('infra:api-error-log:update-status')")
47     public CommonResult<Boolean> updateApiErrorLogProcess(@RequestParam("id") Long id,
48                                                           @RequestParam("processStatus") Integer processStatus) {
49         apiErrorLogService.updateApiErrorLogProcess(id, processStatus, getLoginUserId());
50         return success(true);
51     }
52
53     @GetMapping("/page")
54     @Operation(summary = "获得 API 错误日志分页")
55     @PreAuthorize("@ss.hasPermission('infra:api-error-log:query')")
56     public CommonResult<PageResult<ApiErrorLogRespVO>> getApiErrorLogPage(@Valid ApiErrorLogPageReqVO pageReqVO) {
57         PageResult<ApiErrorLogDO> pageResult = apiErrorLogService.getApiErrorLogPage(pageReqVO);
58         return success(BeanUtils.toBean(pageResult, ApiErrorLogRespVO.class));
59     }
60
61     @GetMapping("/export-excel")
62     @Operation(summary = "导出 API 错误日志 Excel")
63     @PreAuthorize("@ss.hasPermission('infra:api-error-log:export')")
64     @ApiAccessLog(operateType = EXPORT)
65     public void exportApiErrorLogExcel(@Valid ApiErrorLogPageReqVO exportReqVO,
66               HttpServletResponse response) throws IOException {
67         exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
68         List<ApiErrorLogDO> list = apiErrorLogService.getApiErrorLogPage(exportReqVO).getList();
69         // 导出 Excel
70         ExcelUtils.write(response, "API 错误日志.xls", "数据", ApiErrorLogRespVO.class,
71                 BeanUtils.toBean(list, ApiErrorLogRespVO.class));
72     }
73
74 }