Commit 1b3e665be6bd62160a4205e6249f9ff3a4fa723e
1 parent
19a461b3
初始化 API 错误日志的后端 API
Showing
15 changed files
with
543 additions
and
8 deletions
src/main/java/cn/iocoder/dashboard/modules/infra/controller/logger/InfApiErrorLogController.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.logger; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils; | |
| 6 | +import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExcelVO; | |
| 8 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; | |
| 9 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | |
| 10 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO; | |
| 11 | +import cn.iocoder.dashboard.modules.infra.convert.logger.InfApiErrorLogConvert; | |
| 12 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | |
| 13 | +import cn.iocoder.dashboard.modules.infra.service.logger.InfApiErrorLogService; | |
| 14 | +import io.swagger.annotations.Api; | |
| 15 | +import io.swagger.annotations.ApiImplicitParam; | |
| 16 | +import io.swagger.annotations.ApiImplicitParams; | |
| 17 | +import io.swagger.annotations.ApiOperation; | |
| 18 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 19 | +import org.springframework.validation.annotation.Validated; | |
| 20 | +import org.springframework.web.bind.annotation.*; | |
| 21 | + | |
| 22 | +import javax.annotation.Resource; | |
| 23 | +import javax.servlet.http.HttpServletResponse; | |
| 24 | +import javax.validation.Valid; | |
| 25 | +import java.io.IOException; | |
| 26 | +import java.util.List; | |
| 27 | + | |
| 28 | +import static cn.iocoder.dashboard.common.pojo.CommonResult.success; | |
| 29 | +import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT; | |
| 30 | +import static cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 31 | + | |
| 32 | +@Api(tags = "API 错误日志") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/infra/api-error-log") | |
| 35 | +@Validated | |
| 36 | +public class InfApiErrorLogController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private InfApiErrorLogService apiErrorLogService; | |
| 40 | + | |
| 41 | + @PutMapping("/update-status") | |
| 42 | + @ApiOperation("更新 API 错误日志的状态") | |
| 43 | + @ApiImplicitParams({ | |
| 44 | + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class), | |
| 45 | + @ApiImplicitParam(name = "processStatus", value = "处理状态", required = true, example = "1", dataTypeClass = Integer.class) | |
| 46 | + }) | |
| 47 | + @PreAuthorize("@ss.hasPermission('infra:api-error-log:update-status')") | |
| 48 | + public CommonResult<Boolean> updateApiErrorLogProcess(@RequestParam("id") Long id, | |
| 49 | + @RequestParam("processStatus") Integer processStatus) { | |
| 50 | + apiErrorLogService.updateApiErrorLogProcess(id, processStatus, getLoginUserId()); | |
| 51 | + return success(true); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @GetMapping("/page") | |
| 55 | + @ApiOperation("获得 API 错误日志分页") | |
| 56 | + @PreAuthorize("@ss.hasPermission('infra:api-error-log:query')") | |
| 57 | + public CommonResult<PageResult<InfApiErrorLogRespVO>> getApiErrorLogPage(@Valid InfApiErrorLogPageReqVO pageVO) { | |
| 58 | + PageResult<InfApiErrorLogDO> pageResult = apiErrorLogService.getApiErrorLogPage(pageVO); | |
| 59 | + return success(InfApiErrorLogConvert.INSTANCE.convertPage(pageResult)); | |
| 60 | + } | |
| 61 | + | |
| 62 | + @GetMapping("/export-excel") | |
| 63 | + @ApiOperation("导出 API 错误日志 Excel") | |
| 64 | + @PreAuthorize("@ss.hasPermission('infra:api-error-log:export')") | |
| 65 | + @OperateLog(type = EXPORT) | |
| 66 | + public void exportApiErrorLogExcel(@Valid InfApiErrorLogExportReqVO exportReqVO, | |
| 67 | + HttpServletResponse response) throws IOException { | |
| 68 | + List<InfApiErrorLogDO> list = apiErrorLogService.getApiErrorLogList(exportReqVO); | |
| 69 | + // 导出 Excel | |
| 70 | + List<InfApiErrorLogExcelVO> datas = InfApiErrorLogConvert.INSTANCE.convertList02(list); | |
| 71 | + ExcelUtils.write(response, "API 错误日志.xls", "数据", InfApiErrorLogExcelVO.class, datas); | |
| 72 | + } | |
| 73 | + | |
| 74 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/logger/vo/apierrorlog/InfApiErrorLogBaseVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModelProperty; | |
| 4 | +import lombok.Data; | |
| 5 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | + | |
| 7 | +import javax.validation.constraints.NotNull; | |
| 8 | +import java.util.Date; | |
| 9 | + | |
| 10 | +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +/** | |
| 13 | +* API 错误日志 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 14 | +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 15 | +*/ | |
| 16 | +@Data | |
| 17 | +public class InfApiErrorLogBaseVO { | |
| 18 | + | |
| 19 | + @ApiModelProperty(value = "链路追踪编号", required = true, example = "66600cb6-7852-11eb-9439-0242ac130002") | |
| 20 | + @NotNull(message = "链路追踪编号不能为空") | |
| 21 | + private String traceId; | |
| 22 | + | |
| 23 | + @ApiModelProperty(value = "用户编号", required = true, example = "666") | |
| 24 | + @NotNull(message = "用户编号不能为空") | |
| 25 | + private Integer userId; | |
| 26 | + | |
| 27 | + @ApiModelProperty(value = "用户类型", required = true, example = "1") | |
| 28 | + @NotNull(message = "用户类型不能为空") | |
| 29 | + private Integer userType; | |
| 30 | + | |
| 31 | + @ApiModelProperty(value = "应用名", required = true, example = "dashboard") | |
| 32 | + @NotNull(message = "应用名不能为空") | |
| 33 | + private String applicationName; | |
| 34 | + | |
| 35 | + @ApiModelProperty(value = "请求方法名", required = true, example = "GET") | |
| 36 | + @NotNull(message = "请求方法名不能为空") | |
| 37 | + private String requestMethod; | |
| 38 | + | |
| 39 | + @ApiModelProperty(value = "请求地址", required = true, example = "/xx/yy") | |
| 40 | + @NotNull(message = "请求地址不能为空") | |
| 41 | + private String requestUrl; | |
| 42 | + | |
| 43 | + @ApiModelProperty(value = "请求参数", required = true) | |
| 44 | + @NotNull(message = "请求参数不能为空") | |
| 45 | + private String requestParams; | |
| 46 | + | |
| 47 | + @ApiModelProperty(value = "用户 IP", required = true, example = "127.0.0.1") | |
| 48 | + @NotNull(message = "用户 IP不能为空") | |
| 49 | + private String userIp; | |
| 50 | + | |
| 51 | + @ApiModelProperty(value = "浏览器 UA", required = true, example = "Mozilla/5.0") | |
| 52 | + @NotNull(message = "浏览器 UA不能为空") | |
| 53 | + private String userAgent; | |
| 54 | + | |
| 55 | + @ApiModelProperty(value = "异常发生时间", required = true) | |
| 56 | + @NotNull(message = "异常发生时间不能为空") | |
| 57 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 58 | + private Date exceptionTime; | |
| 59 | + | |
| 60 | + @ApiModelProperty(value = "异常名", required = true) | |
| 61 | + @NotNull(message = "异常名不能为空") | |
| 62 | + private String exceptionName; | |
| 63 | + | |
| 64 | + @ApiModelProperty(value = "异常导致的消息", required = true) | |
| 65 | + @NotNull(message = "异常导致的消息不能为空") | |
| 66 | + private String exceptionMessage; | |
| 67 | + | |
| 68 | + @ApiModelProperty(value = "异常导致的根消息", required = true) | |
| 69 | + @NotNull(message = "异常导致的根消息不能为空") | |
| 70 | + private String exceptionRootCauseMessage; | |
| 71 | + | |
| 72 | + @ApiModelProperty(value = "异常的栈轨迹", required = true) | |
| 73 | + @NotNull(message = "异常的栈轨迹不能为空") | |
| 74 | + private String exceptionStackTrace; | |
| 75 | + | |
| 76 | + @ApiModelProperty(value = "异常发生的类全名", required = true) | |
| 77 | + @NotNull(message = "异常发生的类全名不能为空") | |
| 78 | + private String exceptionClassName; | |
| 79 | + | |
| 80 | + @ApiModelProperty(value = "异常发生的类文件", required = true) | |
| 81 | + @NotNull(message = "异常发生的类文件不能为空") | |
| 82 | + private String exceptionFileName; | |
| 83 | + | |
| 84 | + @ApiModelProperty(value = "异常发生的方法名", required = true) | |
| 85 | + @NotNull(message = "异常发生的方法名不能为空") | |
| 86 | + private String exceptionMethodName; | |
| 87 | + | |
| 88 | + @ApiModelProperty(value = "异常发生的方法所在行", required = true) | |
| 89 | + @NotNull(message = "异常发生的方法所在行不能为空") | |
| 90 | + private Integer exceptionLineNumber; | |
| 91 | + | |
| 92 | + @ApiModelProperty(value = "处理状态", required = true, example = "0") | |
| 93 | + @NotNull(message = "处理状态不能为空") | |
| 94 | + private Integer processStatus; | |
| 95 | + | |
| 96 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/logger/vo/apierrorlog/InfApiErrorLogExcelVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.util.Date; | |
| 9 | + | |
| 10 | +import static cn.iocoder.dashboard.modules.system.enums.dict.SysDictTypeEnum.INF_API_ERROR_LOG_PROCESS_STATUS; | |
| 11 | +import static cn.iocoder.dashboard.modules.system.enums.dict.SysDictTypeEnum.USER_TYPE; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * API 错误日志 Excel VO | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +@Data | |
| 19 | +public class InfApiErrorLogExcelVO { | |
| 20 | + | |
| 21 | + @ExcelProperty("编号") | |
| 22 | + private Integer id; | |
| 23 | + | |
| 24 | + @ExcelProperty("链路追踪编号") | |
| 25 | + private String traceId; | |
| 26 | + | |
| 27 | + @ExcelProperty("用户编号") | |
| 28 | + private Integer userId; | |
| 29 | + | |
| 30 | + @ExcelProperty(value = "用户类型", converter = DictConvert.class) | |
| 31 | + @DictFormat(USER_TYPE) | |
| 32 | + private Integer userType; | |
| 33 | + | |
| 34 | + @ExcelProperty("应用名") | |
| 35 | + private String applicationName; | |
| 36 | + | |
| 37 | + @ExcelProperty("请求方法名") | |
| 38 | + private String requestMethod; | |
| 39 | + | |
| 40 | + @ExcelProperty("请求地址") | |
| 41 | + private String requestUrl; | |
| 42 | + | |
| 43 | + @ExcelProperty("请求参数") | |
| 44 | + private String requestParams; | |
| 45 | + | |
| 46 | + @ExcelProperty("用户 IP") | |
| 47 | + private String userIp; | |
| 48 | + | |
| 49 | + @ExcelProperty("浏览器 UA") | |
| 50 | + private String userAgent; | |
| 51 | + | |
| 52 | + @ExcelProperty("异常发生时间") | |
| 53 | + private Date exceptionTime; | |
| 54 | + | |
| 55 | + @ExcelProperty("异常名") | |
| 56 | + private String exceptionName; | |
| 57 | + | |
| 58 | + @ExcelProperty("异常导致的消息") | |
| 59 | + private String exceptionMessage; | |
| 60 | + | |
| 61 | + @ExcelProperty("异常导致的根消息") | |
| 62 | + private String exceptionRootCauseMessage; | |
| 63 | + | |
| 64 | + @ExcelProperty("异常的栈轨迹") | |
| 65 | + private String exceptionStackTrace; | |
| 66 | + | |
| 67 | + @ExcelProperty("异常发生的类全名") | |
| 68 | + private String exceptionClassName; | |
| 69 | + | |
| 70 | + @ExcelProperty("异常发生的类文件") | |
| 71 | + private String exceptionFileName; | |
| 72 | + | |
| 73 | + @ExcelProperty("异常发生的方法名") | |
| 74 | + private String exceptionMethodName; | |
| 75 | + | |
| 76 | + @ExcelProperty("异常发生的方法所在行") | |
| 77 | + private Integer exceptionLineNumber; | |
| 78 | + | |
| 79 | + @ExcelProperty("创建时间") | |
| 80 | + private Date createTime; | |
| 81 | + | |
| 82 | + @ExcelProperty(value = "处理状态", converter = DictConvert.class) | |
| 83 | + @DictFormat(INF_API_ERROR_LOG_PROCESS_STATUS) | |
| 84 | + private Integer processStatus; | |
| 85 | + | |
| 86 | + @ExcelProperty("处理时间") | |
| 87 | + private Date processTime; | |
| 88 | + | |
| 89 | + @ExcelProperty("处理用户编号") | |
| 90 | + private Integer processUserId; | |
| 91 | + | |
| 92 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/logger/vo/apierrorlog/InfApiErrorLogExportReqVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 7 | + | |
| 8 | +import java.util.Date; | |
| 9 | + | |
| 10 | +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@ApiModel(value = "API 错误日志 Excel 导出 Request VO", description = "参数和 InfApiErrorLogPageReqVO 是一致的") | |
| 13 | +@Data | |
| 14 | +public class InfApiErrorLogExportReqVO { | |
| 15 | + | |
| 16 | + @ApiModelProperty(value = "用户编号", example = "666") | |
| 17 | + private Integer userId; | |
| 18 | + | |
| 19 | + @ApiModelProperty(value = "用户类型", example = "1") | |
| 20 | + private Integer userType; | |
| 21 | + | |
| 22 | + @ApiModelProperty(value = "应用名", example = "dashboard") | |
| 23 | + private String applicationName; | |
| 24 | + | |
| 25 | + @ApiModelProperty(value = "请求地址", example = "/xx/yy") | |
| 26 | + private String requestUrl; | |
| 27 | + | |
| 28 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 29 | + @ApiModelProperty(value = "开始异常发生时间") | |
| 30 | + private Date beginExceptionTime; | |
| 31 | + | |
| 32 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 33 | + @ApiModelProperty(value = "结束异常发生时间") | |
| 34 | + private Date endExceptionTime; | |
| 35 | + | |
| 36 | + @ApiModelProperty(value = "处理状态", example = "0") | |
| 37 | + private Integer processStatus; | |
| 38 | + | |
| 39 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/logger/vo/apierrorlog/InfApiErrorLogPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageParam; | |
| 4 | +import io.swagger.annotations.ApiModel; | |
| 5 | +import io.swagger.annotations.ApiModelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | +import lombok.EqualsAndHashCode; | |
| 8 | +import lombok.ToString; | |
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 10 | + | |
| 11 | +import java.util.Date; | |
| 12 | + | |
| 13 | +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 14 | + | |
| 15 | +@ApiModel("API 错误日志分页 Request VO") | |
| 16 | +@Data | |
| 17 | +@EqualsAndHashCode(callSuper = true) | |
| 18 | +@ToString(callSuper = true) | |
| 19 | +public class InfApiErrorLogPageReqVO extends PageParam { | |
| 20 | + | |
| 21 | + @ApiModelProperty(value = "用户编号", example = "666") | |
| 22 | + private Integer userId; | |
| 23 | + | |
| 24 | + @ApiModelProperty(value = "用户类型", example = "1") | |
| 25 | + private Integer userType; | |
| 26 | + | |
| 27 | + @ApiModelProperty(value = "应用名", example = "dashboard") | |
| 28 | + private String applicationName; | |
| 29 | + | |
| 30 | + @ApiModelProperty(value = "请求地址", example = "/xx/yy") | |
| 31 | + private String requestUrl; | |
| 32 | + | |
| 33 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 34 | + @ApiModelProperty(value = "开始异常发生时间") | |
| 35 | + private Date beginExceptionTime; | |
| 36 | + | |
| 37 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 38 | + @ApiModelProperty(value = "结束异常发生时间") | |
| 39 | + private Date endExceptionTime; | |
| 40 | + | |
| 41 | + @ApiModelProperty(value = "处理状态", example = "0") | |
| 42 | + private Integer processStatus; | |
| 43 | + | |
| 44 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/logger/vo/apierrorlog/InfApiErrorLogRespVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +import java.util.Date; | |
| 10 | + | |
| 11 | +@ApiModel("API 错误日志 Response VO") | |
| 12 | +@Data | |
| 13 | +@EqualsAndHashCode(callSuper = true) | |
| 14 | +@ToString(callSuper = true) | |
| 15 | +public class InfApiErrorLogRespVO extends InfApiErrorLogBaseVO { | |
| 16 | + | |
| 17 | + @ApiModelProperty(value = "编号", required = true, example = "1024") | |
| 18 | + private Integer id; | |
| 19 | + | |
| 20 | + @ApiModelProperty(value = "创建时间", required = true) | |
| 21 | + private Date createTime; | |
| 22 | + | |
| 23 | + @ApiModelProperty(value = "处理时间", required = true) | |
| 24 | + private Date processTime; | |
| 25 | + | |
| 26 | + @ApiModelProperty(value = "处理用户编号", example = "233") | |
| 27 | + private Integer processUserId; | |
| 28 | + | |
| 29 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/convert/logger/InfApiErrorLogConvert.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.convert.logger; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiErrorLogCreateDTO; | |
| 5 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExcelVO; | |
| 6 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | |
| 8 | +import org.mapstruct.Mapper; | |
| 9 | +import org.mapstruct.factory.Mappers; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * API 错误日志 Convert | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +@Mapper | |
| 19 | +public interface InfApiErrorLogConvert { | |
| 20 | + | |
| 21 | + InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class); | |
| 22 | + | |
| 23 | + InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean); | |
| 24 | + | |
| 25 | + InfApiErrorLogRespVO convert(InfApiErrorLogDO bean); | |
| 26 | + | |
| 27 | + PageResult<InfApiErrorLogRespVO> convertPage(PageResult<InfApiErrorLogDO> page); | |
| 28 | + | |
| 29 | + List<InfApiErrorLogExcelVO> convertList02(List<InfApiErrorLogDO> list); | |
| 30 | + | |
| 31 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.dashboard.modules.infra.dal.dataobject.logger; |
| 3 | 3 | import cn.iocoder.dashboard.common.enums.UserTypeEnum; |
| 4 | 4 | import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; |
| 5 | 5 | import cn.iocoder.dashboard.modules.infra.enums.logger.ApiErrorLogProcessStatusEnum; |
| 6 | +import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; | |
| 6 | 7 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | 8 | import lombok.*; |
| 8 | 9 | |
| ... | ... | @@ -25,7 +26,7 @@ public class InfApiErrorLogDO extends BaseDO { |
| 25 | 26 | /** |
| 26 | 27 | * 编号 |
| 27 | 28 | */ |
| 28 | - private Integer id; | |
| 29 | + private Long id; | |
| 29 | 30 | /** |
| 30 | 31 | * 用户编号 |
| 31 | 32 | */ |
| ... | ... | @@ -143,9 +144,9 @@ public class InfApiErrorLogDO extends BaseDO { |
| 143 | 144 | */ |
| 144 | 145 | private Date processTime; |
| 145 | 146 | /** |
| 146 | - * 处理管理员编号 | |
| 147 | + * 处理用户编号 | |
| 147 | 148 | * |
| 148 | - * 关联 {@link} | |
| 149 | + * 关联 {@link SysUserDO#getId()} | |
| 149 | 150 | */ |
| 150 | 151 | private Integer processUserId; |
| 151 | 152 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.infra.dal.mysql.logger; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; | |
| 6 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | |
| 8 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * API 错误日志 Mapper | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +@Mapper | |
| 19 | +public interface InfApiErrorLogMapper extends BaseMapperX<InfApiErrorLogDO> { | |
| 20 | + | |
| 21 | + default PageResult<InfApiErrorLogDO> selectPage(InfApiErrorLogPageReqVO reqVO) { | |
| 22 | + return selectPage(reqVO, new QueryWrapperX<InfApiErrorLogDO>() | |
| 23 | + .eqIfPresent("user_id", reqVO.getUserId()) | |
| 24 | + .eqIfPresent("user_type", reqVO.getUserType()) | |
| 25 | + .eqIfPresent("application_name", reqVO.getApplicationName()) | |
| 26 | + .likeIfPresent("request_url", reqVO.getRequestUrl()) | |
| 27 | + .betweenIfPresent("exception_time", reqVO.getBeginExceptionTime(), reqVO.getEndExceptionTime()) | |
| 28 | + .eqIfPresent("process_status", reqVO.getProcessStatus()) | |
| 29 | + .orderByDesc("id") | |
| 30 | + ); | |
| 31 | + } | |
| 32 | + | |
| 33 | + default List<InfApiErrorLogDO> selectList(InfApiErrorLogExportReqVO reqVO) { | |
| 34 | + return selectList(new QueryWrapperX<InfApiErrorLogDO>() | |
| 35 | + .eqIfPresent("user_id", reqVO.getUserId()) | |
| 36 | + .eqIfPresent("user_type", reqVO.getUserType()) | |
| 37 | + .eqIfPresent("application_name", reqVO.getApplicationName()) | |
| 38 | + .likeIfPresent("request_url", reqVO.getRequestUrl()) | |
| 39 | + .betweenIfPresent("exception_time", reqVO.getBeginExceptionTime(), reqVO.getEndExceptionTime()) | |
| 40 | + .eqIfPresent("process_status", reqVO.getProcessStatus()) | |
| 41 | + .orderByDesc("id") | |
| 42 | + ); | |
| 43 | + } | |
| 44 | + | |
| 45 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/enums/InfErrorCodeConstants.java
| ... | ... | @@ -23,4 +23,8 @@ public interface InfErrorCodeConstants { |
| 23 | 23 | ErrorCode JOB_UPDATE_ONLY_NORMAL_STATUS = new ErrorCode(1001001004, "只有开启状态的任务,才可以修改"); |
| 24 | 24 | ErrorCode JOB_CRON_EXPRESSION_VALID = new ErrorCode(1001001005, "CRON 表达式不正确"); |
| 25 | 25 | |
| 26 | + // ========== API 错误日志 1001002000 ========== | |
| 27 | + ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1001002000, "API 错误日志不存在"); | |
| 28 | + ErrorCode API_ERROR_LOG_PROCESSED = new ErrorCode(1001002001, "API 错误日志已处理"); | |
| 29 | + | |
| 26 | 30 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/service/logger/InfApiErrorLogService.java
| 1 | 1 | package cn.iocoder.dashboard.modules.infra.service.logger; |
| 2 | 2 | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 3 | 4 | import cn.iocoder.dashboard.framework.logger.apilog.core.service.ApiErrorLogFrameworkService; |
| 5 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; | |
| 6 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | |
| 8 | + | |
| 9 | +import java.util.List; | |
| 4 | 10 | |
| 5 | 11 | /** |
| 6 | 12 | * API 错误日志 Service 接口 |
| ... | ... | @@ -9,4 +15,29 @@ import cn.iocoder.dashboard.framework.logger.apilog.core.service.ApiErrorLogFram |
| 9 | 15 | */ |
| 10 | 16 | public interface InfApiErrorLogService extends ApiErrorLogFrameworkService { |
| 11 | 17 | |
| 18 | + /** | |
| 19 | + * 获得 API 错误日志分页 | |
| 20 | + * | |
| 21 | + * @param pageReqVO 分页查询 | |
| 22 | + * @return API 错误日志分页 | |
| 23 | + */ | |
| 24 | + PageResult<InfApiErrorLogDO> getApiErrorLogPage(InfApiErrorLogPageReqVO pageReqVO); | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 获得 API 错误日志列表, 用于 Excel 导出 | |
| 28 | + * | |
| 29 | + * @param exportReqVO 查询条件 | |
| 30 | + * @return API 错误日志分页 | |
| 31 | + */ | |
| 32 | + List<InfApiErrorLogDO> getApiErrorLogList(InfApiErrorLogExportReqVO exportReqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 更新 API 错误日志已处理 | |
| 36 | + * | |
| 37 | + * @param id API 日志编号 | |
| 38 | + * @param processStatus 处理结果 | |
| 39 | + * @param processUserId 处理人 | |
| 40 | + */ | |
| 41 | + void updateApiErrorLogProcess(Long id, Integer processStatus, Long processUserId); | |
| 42 | + | |
| 12 | 43 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java
| 1 | 1 | package cn.iocoder.dashboard.modules.infra.service.logger.impl; |
| 2 | 2 | |
| 3 | +import cn.iocoder.dashboard.common.pojo.PageResult; | |
| 3 | 4 | import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiErrorLogCreateDTO; |
| 5 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; | |
| 6 | +import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | |
| 7 | +import cn.iocoder.dashboard.modules.infra.convert.logger.InfApiErrorLogConvert; | |
| 8 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | |
| 9 | +import cn.iocoder.dashboard.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; | |
| 10 | +import cn.iocoder.dashboard.modules.infra.enums.logger.ApiErrorLogProcessStatusEnum; | |
| 4 | 11 | import cn.iocoder.dashboard.modules.infra.service.logger.InfApiErrorLogService; |
| 5 | 12 | import org.springframework.scheduling.annotation.Async; |
| 6 | 13 | import org.springframework.stereotype.Service; |
| 7 | 14 | import org.springframework.validation.annotation.Validated; |
| 8 | 15 | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import java.util.List; | |
| 18 | + | |
| 19 | +import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception; | |
| 20 | +import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND; | |
| 21 | +import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_PROCESSED; | |
| 22 | + | |
| 9 | 23 | /** |
| 10 | 24 | * API 错误日志 Service 实现类 |
| 11 | 25 | * |
| ... | ... | @@ -15,10 +29,39 @@ import org.springframework.validation.annotation.Validated; |
| 15 | 29 | @Validated |
| 16 | 30 | public class InfApiErrorLogServiceImpl implements InfApiErrorLogService { |
| 17 | 31 | |
| 32 | + @Resource | |
| 33 | + private InfApiErrorLogMapper apiErrorLogMapper; | |
| 34 | + | |
| 18 | 35 | @Override |
| 19 | 36 | @Async |
| 20 | 37 | public void createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) { |
| 38 | + InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO); | |
| 39 | + apiErrorLog.setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus()); | |
| 40 | + apiErrorLogMapper.insert(apiErrorLog); | |
| 41 | + } | |
| 21 | 42 | |
| 43 | + @Override | |
| 44 | + public PageResult<InfApiErrorLogDO> getApiErrorLogPage(InfApiErrorLogPageReqVO pageReqVO) { | |
| 45 | + return apiErrorLogMapper.selectPage(pageReqVO); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public List<InfApiErrorLogDO> getApiErrorLogList(InfApiErrorLogExportReqVO exportReqVO) { | |
| 50 | + return apiErrorLogMapper.selectList(exportReqVO); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public void updateApiErrorLogProcess(Long id, Integer processStatus, Long processUserId) { | |
| 55 | + InfApiErrorLogDO errorLog = apiErrorLogMapper.selectById(id); | |
| 56 | + if (errorLog == null) { | |
| 57 | + throw exception(API_ERROR_LOG_NOT_FOUND); | |
| 58 | + } | |
| 59 | + if (!ApiErrorLogProcessStatusEnum.INIT.getStatus().equals(errorLog.getProcessStatus())) { | |
| 60 | + throw exception(API_ERROR_LOG_PROCESSED); | |
| 61 | + } | |
| 62 | + // 标记处理 | |
| 63 | + apiErrorLogMapper.updateById(InfApiErrorLogDO.builder().id(id).processStatus(processStatus) | |
| 64 | + .processUserId(processStatus).build()); | |
| 22 | 65 | } |
| 23 | 66 | |
| 24 | 67 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/SysDictTypeEnum.java
| ... | ... | @@ -21,8 +21,10 @@ public enum SysDictTypeEnum { |
| 21 | 21 | |
| 22 | 22 | INF_REDIS_TIMEOUT_TYPE("inf_redis_timeout_type"), // Redis 超时类型 |
| 23 | 23 | INF_JOB_STATUS("inf_job_status"), // 定时任务状态的枚举 |
| 24 | - INF_JOB_LOG_STATUS("inf_job_log_status") // 定时任务日志状态的枚举 | |
| 25 | - ,; | |
| 24 | + INF_JOB_LOG_STATUS("inf_job_log_status"), // 定时任务日志状态的枚举 | |
| 25 | + INF_API_ERROR_LOG_PROCESS_STATUS("inf_api_error_log_process_status"), // API 错误日志的处理状态的枚举 | |
| 26 | + | |
| 27 | + ; | |
| 26 | 28 | |
| 27 | 29 | |
| 28 | 30 | /** | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java
| ... | ... | @@ -252,7 +252,10 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { |
| 252 | 252 | |
| 253 | 253 | @Override |
| 254 | 254 | public List<ToolSchemaTableDO> getSchemaTableList(String tableName, String tableComment) { |
| 255 | - return schemaTableMapper.selectList(codegenProperties.getDbSchemas(), tableName, tableComment); | |
| 255 | + List<ToolSchemaTableDO> tables = schemaTableMapper.selectList(codegenProperties.getDbSchemas(), tableName, tableComment); | |
| 256 | + // TODO 强制移除 Quartz 的表,未来做成可配置 | |
| 257 | + tables.removeIf(table -> table.getTableName().startsWith("QRTZ_")); | |
| 258 | + return tables; | |
| 256 | 259 | } |
| 257 | 260 | |
| 258 | 261 | // /** | ... | ... |
src/main/resources/codegen/java/dal/mapper.vm
| ... | ... | @@ -52,13 +52,14 @@ public interface ${table.className}Mapper extends BaseMapperX<${table.className} |
| 52 | 52 | default PageResult<${table.className}DO> selectPage(${table.className}PageReqVO reqVO) { |
| 53 | 53 | return selectPage(reqVO, new QueryWrapperX<${table.className}DO>() |
| 54 | 54 | #listCondition() |
| 55 | - .orderByDesc("id")# 大多数情况下,id 倒序 | |
| 55 | + .orderByDesc("id")## 大多数情况下,id 倒序 | |
| 56 | 56 | ); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | default List<${table.className}DO> selectList(${table.className}ExportReqVO reqVO) { |
| 60 | 60 | return selectList(new QueryWrapperX<${table.className}DO>() |
| 61 | - #listCondition()# 大多数情况下,id 倒序 | |
| 61 | + #listCondition() | |
| 62 | + .orderByDesc("id")## 大多数情况下,id 倒序 | |
| 62 | 63 | ); |
| 63 | 64 | } |
| 64 | 65 | ... | ... |