提交 | 用户 | 时间
|
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.apiaccesslog.ApiAccessLogPageReqVO; |
|
10 |
import com.iailab.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogRespVO; |
|
11 |
import com.iailab.module.infra.dal.dataobject.logger.ApiAccessLogDO; |
|
12 |
import com.iailab.module.infra.service.logger.ApiAccessLogService; |
|
13 |
import io.swagger.v3.oas.annotations.Operation; |
|
14 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
15 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
16 |
import org.springframework.validation.annotation.Validated; |
|
17 |
import org.springframework.web.bind.annotation.GetMapping; |
|
18 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
19 |
import org.springframework.web.bind.annotation.RestController; |
|
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 |
|
|
30 |
@Tag(name = "管理后台 - API 访问日志") |
|
31 |
@RestController |
|
32 |
@RequestMapping("/infra/api-access-log") |
|
33 |
@Validated |
|
34 |
public class ApiAccessLogController { |
|
35 |
|
|
36 |
@Resource |
|
37 |
private ApiAccessLogService apiAccessLogService; |
|
38 |
|
|
39 |
@GetMapping("/page") |
|
40 |
@Operation(summary = "获得API 访问日志分页") |
|
41 |
@PreAuthorize("@ss.hasPermission('infra:api-access-log:query')") |
|
42 |
public CommonResult<PageResult<ApiAccessLogRespVO>> getApiAccessLogPage(@Valid ApiAccessLogPageReqVO pageReqVO) { |
|
43 |
PageResult<ApiAccessLogDO> pageResult = apiAccessLogService.getApiAccessLogPage(pageReqVO); |
|
44 |
return success(BeanUtils.toBean(pageResult, ApiAccessLogRespVO.class)); |
|
45 |
} |
|
46 |
|
|
47 |
@GetMapping("/export-excel") |
|
48 |
@Operation(summary = "导出API 访问日志 Excel") |
|
49 |
@PreAuthorize("@ss.hasPermission('infra:api-access-log:export')") |
|
50 |
@ApiAccessLog(operateType = EXPORT) |
|
51 |
public void exportApiAccessLogExcel(@Valid ApiAccessLogPageReqVO exportReqVO, |
|
52 |
HttpServletResponse response) throws IOException { |
|
53 |
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
|
54 |
List<ApiAccessLogDO> list = apiAccessLogService.getApiAccessLogPage(exportReqVO).getList(); |
|
55 |
// 导出 Excel |
|
56 |
ExcelUtils.write(response, "API 访问日志.xls", "数据", ApiAccessLogRespVO.class, |
|
57 |
BeanUtils.toBean(list, ApiAccessLogRespVO.class)); |
|
58 |
} |
|
59 |
|
|
60 |
} |