Commit 4225db217d180467f05912c02a058cac5efe1602
1 parent
8eb04d68
🔧 简化 loginLog 和 operateLog 模块的 VO
Showing
21 changed files
with
176 additions
and
558 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java
| ... | ... | @@ -26,17 +26,14 @@ public class ErrorCodeRespVO { |
| 26 | 26 | private Integer type; |
| 27 | 27 | |
| 28 | 28 | @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") |
| 29 | - @NotNull(message = "应用名不能为空") | |
| 30 | 29 | @ExcelProperty("应用名") |
| 31 | 30 | private String applicationName; |
| 32 | 31 | |
| 33 | 32 | @Schema(description = "错误码编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1234") |
| 34 | - @NotNull(message = "错误码编码不能为空") | |
| 35 | 33 | @ExcelProperty("错误码编码") |
| 36 | 34 | private Integer code; |
| 37 | 35 | |
| 38 | 36 | @Schema(description = "错误码错误提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "帅气") |
| 39 | - @NotNull(message = "错误码错误提示不能为空") | |
| 40 | 37 | @ExcelProperty("错误码错误提示") |
| 41 | 38 | private String message; |
| 42 | 39 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/LoginLogController.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.logger; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 7 | 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExcelVO; | |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; | |
| 10 | 9 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; |
| 11 | 10 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogRespVO; |
| 12 | -import cn.iocoder.yudao.module.system.convert.logger.LoginLogConvert; | |
| 11 | +import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; | |
| 13 | 12 | import cn.iocoder.yudao.module.system.service.logger.LoginLogService; |
| 14 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 14 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 16 | 15 | import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | 16 | import org.springframework.validation.annotation.Validated; |
| 18 | 17 | import org.springframework.web.bind.annotation.GetMapping; |
| ... | ... | @@ -25,6 +24,7 @@ import javax.validation.Valid; |
| 25 | 24 | import java.io.IOException; |
| 26 | 25 | import java.util.List; |
| 27 | 26 | |
| 27 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 28 | 28 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 29 | 29 | |
| 30 | 30 | @Tag(name = "管理后台 - 登录日志") |
| ... | ... | @@ -39,21 +39,21 @@ public class LoginLogController { |
| 39 | 39 | @GetMapping("/page") |
| 40 | 40 | @Operation(summary = "获得登录日志分页列表") |
| 41 | 41 | @PreAuthorize("@ss.hasPermission('system:login-log:query')") |
| 42 | - public CommonResult<PageResult<LoginLogRespVO>> getLoginLogPage(@Valid LoginLogPageReqVO reqVO) { | |
| 43 | - PageResult<LoginLogDO> page = loginLogService.getLoginLogPage(reqVO); | |
| 44 | - return CommonResult.success(LoginLogConvert.INSTANCE.convertPage(page)); | |
| 42 | + public CommonResult<PageResult<LoginLogRespVO>> getLoginLogPage(@Valid LoginLogPageReqVO pageReqVO) { | |
| 43 | + PageResult<LoginLogDO> pageResult = loginLogService.getLoginLogPage(pageReqVO); | |
| 44 | + return success(BeanUtils.toBean(pageResult, LoginLogRespVO.class)); | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | @GetMapping("/export") |
| 48 | 48 | @Operation(summary = "导出登录日志 Excel") |
| 49 | 49 | @PreAuthorize("@ss.hasPermission('system:login-log:export')") |
| 50 | 50 | @OperateLog(type = EXPORT) |
| 51 | - public void exportLoginLog(HttpServletResponse response, @Valid LoginLogExportReqVO reqVO) throws IOException { | |
| 52 | - List<LoginLogDO> list = loginLogService.getLoginLogList(reqVO); | |
| 53 | - // 拼接数据 | |
| 54 | - List<LoginLogExcelVO> data = LoginLogConvert.INSTANCE.convertList(list); | |
| 51 | + public void exportLoginLog(HttpServletResponse response, @Valid LoginLogPageReqVO exportReqVO) throws IOException { | |
| 52 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 53 | + List<LoginLogDO> list = loginLogService.getLoginLogPage(exportReqVO).getList(); | |
| 55 | 54 | // 输出 |
| 56 | - ExcelUtils.write(response, "登录日志.xls", "数据列表", LoginLogExcelVO.class, data); | |
| 55 | + ExcelUtils.write(response, "登录日志.xls", "数据列表", LoginLogRespVO.class, | |
| 56 | + BeanUtils.toBean(list, LoginLogRespVO.class)); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.logger; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExcelVO; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 7 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 5 | 8 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; |
| 6 | 9 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO; |
| 7 | 10 | import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert; |
| 8 | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; |
| 9 | 12 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 10 | 13 | import cn.iocoder.yudao.module.system.service.logger.OperateLogService; |
| 11 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 12 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 13 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 14 | -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 15 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 16 | -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 17 | 14 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 18 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 19 | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 20 | 17 | import org.springframework.security.access.prepost.PreAuthorize; |
| 21 | 18 | import org.springframework.validation.annotation.Validated; |
| 22 | 19 | import org.springframework.web.bind.annotation.GetMapping; |
| ... | ... | @@ -27,12 +24,11 @@ import javax.annotation.Resource; |
| 27 | 24 | import javax.servlet.http.HttpServletResponse; |
| 28 | 25 | import javax.validation.Valid; |
| 29 | 26 | import java.io.IOException; |
| 30 | -import java.util.ArrayList; | |
| 31 | -import java.util.Collection; | |
| 32 | 27 | import java.util.List; |
| 33 | 28 | import java.util.Map; |
| 34 | 29 | |
| 35 | 30 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 31 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 36 | 32 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 37 | 33 | |
| 38 | 34 | @Tag(name = "管理后台 - 操作日志") |
| ... | ... | @@ -49,37 +45,27 @@ public class OperateLogController { |
| 49 | 45 | @GetMapping("/page") |
| 50 | 46 | @Operation(summary = "查看操作日志分页列表") |
| 51 | 47 | @PreAuthorize("@ss.hasPermission('system:operate-log:query')") |
| 52 | - public CommonResult<PageResult<OperateLogRespVO>> pageOperateLog(@Valid OperateLogPageReqVO reqVO) { | |
| 53 | - PageResult<OperateLogDO> pageResult = operateLogService.getOperateLogPage(reqVO); | |
| 54 | - | |
| 48 | + public CommonResult<PageResult<OperateLogRespVO>> pageOperateLog(@Valid OperateLogPageReqVO pageReqVO) { | |
| 49 | + PageResult<OperateLogDO> pageResult = operateLogService.getOperateLogPage(pageReqVO); | |
| 55 | 50 | // 获得拼接需要的数据 |
| 56 | - Collection<Long> userIds = CollectionUtils.convertList(pageResult.getList(), OperateLogDO::getUserId); | |
| 57 | - Map<Long, AdminUserDO> userMap = userService.getUserMap(userIds); | |
| 58 | - // 拼接数据 | |
| 59 | - List<OperateLogRespVO> list = new ArrayList<>(pageResult.getList().size()); | |
| 60 | - pageResult.getList().forEach(operateLog -> { | |
| 61 | - OperateLogRespVO respVO = OperateLogConvert.INSTANCE.convert(operateLog); | |
| 62 | - list.add(respVO); | |
| 63 | - // 拼接用户信息 | |
| 64 | - MapUtils.findAndThen(userMap, operateLog.getUserId(), user -> respVO.setUserNickname(user.getNickname())); | |
| 65 | - }); | |
| 66 | - return success(new PageResult<>(list, pageResult.getTotal())); | |
| 51 | + Map<Long, AdminUserDO> userMap = userService.getUserMap( | |
| 52 | + convertList(pageResult.getList(), OperateLogDO::getUserId)); | |
| 53 | + return success(new PageResult<>(OperateLogConvert.INSTANCE.convertList(pageResult.getList(), userMap), | |
| 54 | + pageResult.getTotal())); | |
| 67 | 55 | } |
| 68 | 56 | |
| 69 | 57 | @Operation(summary = "导出操作日志") |
| 70 | 58 | @GetMapping("/export") |
| 71 | 59 | @PreAuthorize("@ss.hasPermission('system:operate-log:export')") |
| 72 | 60 | @OperateLog(type = EXPORT) |
| 73 | - public void exportOperateLog(HttpServletResponse response, @Valid OperateLogExportReqVO reqVO) throws IOException { | |
| 74 | - List<OperateLogDO> list = operateLogService.getOperateLogList(reqVO); | |
| 75 | - | |
| 76 | - // 获得拼接需要的数据 | |
| 77 | - Collection<Long> userIds = CollectionUtils.convertList(list, OperateLogDO::getUserId); | |
| 78 | - Map<Long, AdminUserDO> userMap = userService.getUserMap(userIds); | |
| 79 | - // 拼接数据 | |
| 80 | - List<OperateLogExcelVO> excelDataList = OperateLogConvert.INSTANCE.convertList(list, userMap); | |
| 61 | + public void exportOperateLog(HttpServletResponse response, @Valid OperateLogPageReqVO exportReqVO) throws IOException { | |
| 62 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 63 | + List<OperateLogDO> list = operateLogService.getOperateLogPage(exportReqVO).getList(); | |
| 81 | 64 | // 输出 |
| 82 | - ExcelUtils.write(response, "操作日志.xls", "数据列表", OperateLogExcelVO.class, excelDataList); | |
| 65 | + Map<Long, AdminUserDO> userMap = userService.getUserMap( | |
| 66 | + convertList(list, OperateLogDO::getUserId)); | |
| 67 | + ExcelUtils.write(response, "操作日志.xls", "数据列表", OperateLogRespVO.class, | |
| 68 | + OperateLogConvert.INSTANCE.convertList(list, userMap)); | |
| 83 | 69 | } |
| 84 | 70 | |
| 85 | 71 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogBaseVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | - | |
| 6 | -import javax.validation.constraints.NotBlank; | |
| 7 | -import javax.validation.constraints.NotEmpty; | |
| 8 | -import javax.validation.constraints.NotNull; | |
| 9 | -import javax.validation.constraints.Size; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 登录日志 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 13 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 14 | - */ | |
| 15 | -@Data | |
| 16 | -public class LoginLogBaseVO { | |
| 17 | - | |
| 18 | - @Schema(description = "日志类型,参见 LoginLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 19 | - @NotNull(message = "日志类型不能为空") | |
| 20 | - private Integer logType; | |
| 21 | - | |
| 22 | - @Schema(description = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab") | |
| 23 | - @NotEmpty(message = "链路追踪编号不能为空") | |
| 24 | - private String traceId; | |
| 25 | - | |
| 26 | - @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") | |
| 27 | - @NotBlank(message = "用户账号不能为空") | |
| 28 | - @Size(max = 30, message = "用户账号长度不能超过30个字符") | |
| 29 | - private String username; | |
| 30 | - | |
| 31 | - @Schema(description = "登录结果,参见 LoginResultEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 32 | - @NotNull(message = "登录结果不能为空") | |
| 33 | - private Integer result; | |
| 34 | - | |
| 35 | - @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") | |
| 36 | - @NotEmpty(message = "用户 IP 不能为空") | |
| 37 | - private String userIp; | |
| 38 | - | |
| 39 | - @Schema(description = "浏览器 UserAgent", example = "Mozilla/5.0") | |
| 40 | - private String userAgent; | |
| 41 | - | |
| 42 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 6 | -import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | -import lombok.Data; | |
| 8 | - | |
| 9 | -import java.time.LocalDateTime; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 登录日志 Excel 导出响应 VO | |
| 13 | - */ | |
| 14 | -@Data | |
| 15 | -public class LoginLogExcelVO { | |
| 16 | - | |
| 17 | - @ExcelProperty("日志主键") | |
| 18 | - private Long id; | |
| 19 | - | |
| 20 | - @ExcelProperty("用户账号") | |
| 21 | - private String username; | |
| 22 | - | |
| 23 | - @ExcelProperty(value = "日志类型", converter = DictConvert.class) | |
| 24 | - @DictFormat(DictTypeConstants.LOGIN_TYPE) | |
| 25 | - private Integer logType; | |
| 26 | - | |
| 27 | - @ExcelProperty(value = "登录结果", converter = DictConvert.class) | |
| 28 | - @DictFormat(DictTypeConstants.LOGIN_RESULT) | |
| 29 | - private Integer result; | |
| 30 | - | |
| 31 | - @ExcelProperty("登录 IP") | |
| 32 | - private String userIp; | |
| 33 | - | |
| 34 | - @ExcelProperty("浏览器 UA") | |
| 35 | - private String userAgent; | |
| 36 | - | |
| 37 | - @ExcelProperty("登录时间") | |
| 38 | - private LocalDateTime createTime; | |
| 39 | - | |
| 40 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExportReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | - | |
| 7 | -import java.time.LocalDateTime; | |
| 8 | - | |
| 9 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | - | |
| 11 | -@Schema(description = "管理后台 - 登录日志分页列表 Request VO") | |
| 12 | -@Data | |
| 13 | -public class LoginLogExportReqVO { | |
| 14 | - | |
| 15 | - @Schema(description = "用户 IP,模拟匹配", example = "127.0.0.1") | |
| 16 | - private String userIp; | |
| 17 | - | |
| 18 | - @Schema(description = "用户账号,模拟匹配", example = "芋道") | |
| 19 | - private String username; | |
| 20 | - | |
| 21 | - @Schema(description = "操作状态", example = "true") | |
| 22 | - private Boolean status; | |
| 23 | - | |
| 24 | - @Schema(description = "登录时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") | |
| 25 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 26 | - private LocalDateTime[] createTime; | |
| 27 | - | |
| 28 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 6 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 7 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 3 | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 9 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | 10 | |
| 8 | -import javax.validation.constraints.NotNull; | |
| 9 | 11 | import java.time.LocalDateTime; |
| 10 | 12 | |
| 11 | 13 | @Schema(description = "管理后台 - 登录日志 Response VO") |
| 12 | 14 | @Data |
| 13 | -@EqualsAndHashCode(callSuper = true) | |
| 14 | -@ToString(callSuper = true) | |
| 15 | -public class LoginLogRespVO extends LoginLogBaseVO { | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class LoginLogRespVO { | |
| 16 | 17 | |
| 17 | 18 | @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 19 | + @ExcelProperty("日志主键") | |
| 18 | 20 | private Long id; |
| 19 | 21 | |
| 22 | + @Schema(description = "日志类型,参见 LoginLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 23 | + @ExcelProperty(value = "日志类型", converter = DictConvert.class) | |
| 24 | + @DictFormat(DictTypeConstants.LOGIN_TYPE) | |
| 25 | + private Integer logType; | |
| 26 | + | |
| 20 | 27 | @Schema(description = "用户编号", example = "666") |
| 21 | 28 | private Long userId; |
| 22 | 29 | |
| 23 | 30 | @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 24 | - @NotNull(message = "用户类型不能为空") | |
| 25 | 31 | private Integer userType; |
| 26 | 32 | |
| 33 | + @Schema(description = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab") | |
| 34 | + private String traceId; | |
| 35 | + | |
| 36 | + @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") | |
| 37 | + @ExcelProperty("用户账号") | |
| 38 | + private String username; | |
| 39 | + | |
| 40 | + @Schema(description = "登录结果,参见 LoginResultEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 41 | + @ExcelProperty(value = "登录结果", converter = DictConvert.class) | |
| 42 | + @DictFormat(DictTypeConstants.LOGIN_RESULT) | |
| 43 | + private Integer result; | |
| 44 | + | |
| 45 | + @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") | |
| 46 | + @ExcelProperty("登录 IP") | |
| 47 | + private String userIp; | |
| 48 | + | |
| 49 | + @Schema(description = "浏览器 UserAgent", example = "Mozilla/5.0") | |
| 50 | + @ExcelProperty("浏览器 UA") | |
| 51 | + private String userAgent; | |
| 52 | + | |
| 27 | 53 | @Schema(description = "登录时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 54 | + @ExcelProperty("登录时间") | |
| 28 | 55 | private LocalDateTime createTime; |
| 29 | 56 | |
| 30 | 57 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogBaseVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | - | |
| 6 | -import javax.validation.constraints.NotEmpty; | |
| 7 | -import javax.validation.constraints.NotNull; | |
| 8 | -import java.time.LocalDateTime; | |
| 9 | -import java.util.Map; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 操作日志 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 13 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 14 | - */ | |
| 15 | -@Data | |
| 16 | -public class OperateLogBaseVO { | |
| 17 | - | |
| 18 | - @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab") | |
| 19 | - @NotEmpty(message = "链路追踪编号不能为空") | |
| 20 | - private String traceId; | |
| 21 | - | |
| 22 | - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 23 | - @NotNull(message = "用户编号不能为空") | |
| 24 | - private Long userId; | |
| 25 | - | |
| 26 | - @Schema(description = "操作模块", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单") | |
| 27 | - @NotEmpty(message = "操作模块不能为空") | |
| 28 | - private String module; | |
| 29 | - | |
| 30 | - @Schema(description = "操作名", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建订单") | |
| 31 | - @NotEmpty(message = "操作名") | |
| 32 | - private String name; | |
| 33 | - | |
| 34 | - @Schema(description = "操作分类,参见 OperateLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | - @NotNull(message = "操作分类不能为空") | |
| 36 | - private Integer type; | |
| 37 | - | |
| 38 | - @Schema(description = "操作明细", example = "修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。") | |
| 39 | - private String content; | |
| 40 | - | |
| 41 | - @Schema(description = "拓展字段", example = "{'orderId': 1}") | |
| 42 | - private Map<String, Object> exts; | |
| 43 | - | |
| 44 | - @Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET") | |
| 45 | - @NotEmpty(message = "请求方法名不能为空") | |
| 46 | - private String requestMethod; | |
| 47 | - | |
| 48 | - @Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xxx/yyy") | |
| 49 | - @NotEmpty(message = "请求地址不能为空") | |
| 50 | - private String requestUrl; | |
| 51 | - | |
| 52 | - @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") | |
| 53 | - @NotEmpty(message = "用户 IP 不能为空") | |
| 54 | - private String userIp; | |
| 55 | - | |
| 56 | - @Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0") | |
| 57 | - @NotEmpty(message = "浏览器 UserAgent 不能为空") | |
| 58 | - private String userAgent; | |
| 59 | - | |
| 60 | - @Schema(description = "Java 方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "cn.iocoder.yudao.adminserver.UserController.save(...)") | |
| 61 | - @NotEmpty(message = "Java 方法名不能为空") | |
| 62 | - private String javaMethod; | |
| 63 | - | |
| 64 | - @Schema(description = "Java 方法的参数") | |
| 65 | - private String javaMethodArgs; | |
| 66 | - | |
| 67 | - @Schema(description = "开始时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 68 | - @NotNull(message = "开始时间不能为空") | |
| 69 | - private LocalDateTime startTime; | |
| 70 | - | |
| 71 | - @Schema(description = "执行时长,单位:毫秒", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 72 | - @NotNull(message = "执行时长不能为空") | |
| 73 | - private Integer duration; | |
| 74 | - | |
| 75 | - @Schema(description = "结果码", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 76 | - @NotNull(message = "结果码不能为空") | |
| 77 | - private Integer resultCode; | |
| 78 | - | |
| 79 | - @Schema(description = "结果提示") | |
| 80 | - private String resultMsg; | |
| 81 | - | |
| 82 | - @Schema(description = "结果数据") | |
| 83 | - private String resultData; | |
| 84 | - | |
| 85 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 6 | -import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | -import lombok.Data; | |
| 8 | - | |
| 9 | -import java.time.LocalDateTime; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 操作日志 Excel 导出响应 VO | |
| 13 | - */ | |
| 14 | -@Data | |
| 15 | -public class OperateLogExcelVO { | |
| 16 | - | |
| 17 | - @ExcelProperty("日志编号") | |
| 18 | - private Long id; | |
| 19 | - | |
| 20 | - @ExcelProperty("操作模块") | |
| 21 | - private String module; | |
| 22 | - | |
| 23 | - @ExcelProperty("操作名") | |
| 24 | - private String name; | |
| 25 | - | |
| 26 | - @ExcelProperty(value = "操作类型", converter = DictConvert.class) | |
| 27 | - @DictFormat(DictTypeConstants.OPERATE_TYPE) | |
| 28 | - private String type; | |
| 29 | - | |
| 30 | - @ExcelProperty("操作人") | |
| 31 | - private String userNickname; | |
| 32 | - | |
| 33 | - @ExcelProperty(value = "操作结果") // 成功 or 失败 | |
| 34 | - private String successStr; | |
| 35 | - | |
| 36 | - @ExcelProperty("操作日志") | |
| 37 | - private LocalDateTime startTime; | |
| 38 | - | |
| 39 | - @ExcelProperty("执行时长") | |
| 40 | - private Integer duration; | |
| 41 | - | |
| 42 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExportReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | - | |
| 7 | -import java.time.LocalDateTime; | |
| 8 | - | |
| 9 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | - | |
| 11 | -@Schema(description = "管理后台 - 操作日志分页列表 Request VO") | |
| 12 | -@Data | |
| 13 | -public class OperateLogExportReqVO { | |
| 14 | - | |
| 15 | - @Schema(description = "操作模块,模拟匹配", example = "订单") | |
| 16 | - private String module; | |
| 17 | - | |
| 18 | - @Schema(description = "用户昵称,模拟匹配", example = "芋道") | |
| 19 | - private String userNickname; | |
| 20 | - | |
| 21 | - @Schema(description = "操作分类,参见 OperateLogTypeEnum 枚举类", example = "1") | |
| 22 | - private Integer type; | |
| 23 | - | |
| 24 | - @Schema(description = "操作状态", example = "true") | |
| 25 | - private Boolean success; | |
| 26 | - | |
| 27 | - @Schema(description = "开始时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") | |
| 28 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 29 | - private LocalDateTime[] startTime; | |
| 30 | - | |
| 31 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 6 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 7 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 3 | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 9 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.NotEmpty; | |
| 12 | +import java.time.LocalDateTime; | |
| 13 | +import java.util.Map; | |
| 7 | 14 | |
| 8 | 15 | @Schema(description = "管理后台 - 操作日志 Response VO") |
| 9 | 16 | @Data |
| 10 | -@EqualsAndHashCode(callSuper = true) | |
| 11 | -@ToString(callSuper = true) | |
| 12 | -public class OperateLogRespVO extends OperateLogBaseVO { | |
| 17 | +@ExcelIgnoreUnannotated | |
| 18 | +public class OperateLogRespVO { | |
| 13 | 19 | |
| 14 | 20 | @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 21 | + @ExcelProperty("日志编号") | |
| 15 | 22 | private Long id; |
| 16 | 23 | |
| 24 | + @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab") | |
| 25 | + private String traceId; | |
| 26 | + | |
| 27 | + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 28 | + private Long userId; | |
| 29 | + | |
| 17 | 30 | @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") |
| 31 | + @ExcelProperty("操作人") | |
| 18 | 32 | private String userNickname; |
| 19 | 33 | |
| 34 | + @Schema(description = "操作模块", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单") | |
| 35 | + @ExcelProperty("操作模块") | |
| 36 | + private String module; | |
| 37 | + | |
| 38 | + @Schema(description = "操作名", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建订单") | |
| 39 | + @ExcelProperty("操作名") | |
| 40 | + private String name; | |
| 41 | + | |
| 42 | + @Schema(description = "操作分类,参见 OperateLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 43 | + @ExcelProperty(value = "操作类型", converter = DictConvert.class) | |
| 44 | + @DictFormat(DictTypeConstants.OPERATE_TYPE) | |
| 45 | + private Integer type; | |
| 46 | + | |
| 47 | + @Schema(description = "操作明细", example = "修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。") | |
| 48 | + private String content; | |
| 49 | + | |
| 50 | + @Schema(description = "拓展字段", example = "{'orderId': 1}") | |
| 51 | + private Map<String, Object> exts; | |
| 52 | + | |
| 53 | + @Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET") | |
| 54 | + @NotEmpty(message = "请求方法名不能为空") | |
| 55 | + private String requestMethod; | |
| 56 | + | |
| 57 | + @Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xxx/yyy") | |
| 58 | + private String requestUrl; | |
| 59 | + | |
| 60 | + @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") | |
| 61 | + private String userIp; | |
| 62 | + | |
| 63 | + @Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0") | |
| 64 | + private String userAgent; | |
| 65 | + | |
| 66 | + @Schema(description = "Java 方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "cn.iocoder.yudao.adminserver.UserController.save(...)") | |
| 67 | + private String javaMethod; | |
| 68 | + | |
| 69 | + @Schema(description = "Java 方法的参数") | |
| 70 | + private String javaMethodArgs; | |
| 71 | + | |
| 72 | + @Schema(description = "开始时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 73 | + @ExcelProperty("操作日志") | |
| 74 | + private LocalDateTime startTime; | |
| 75 | + | |
| 76 | + @Schema(description = "执行时长,单位:毫秒", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 77 | + @ExcelProperty("执行时长") | |
| 78 | + private Integer duration; | |
| 79 | + | |
| 80 | + @Schema(description = "结果码", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 81 | + @ExcelProperty(value = "结果码") | |
| 82 | + private Integer resultCode; | |
| 83 | + | |
| 84 | + @Schema(description = "结果提示") | |
| 85 | + private String resultMsg; | |
| 86 | + | |
| 87 | + @Schema(description = "结果数据") | |
| 88 | + private String resultData; | |
| 89 | + | |
| 20 | 90 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/LoginLogConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.logger; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; | |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExcelVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogRespVO; | |
| 7 | -import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; | |
| 8 | -import org.mapstruct.Mapper; | |
| 9 | -import org.mapstruct.factory.Mappers; | |
| 10 | - | |
| 11 | -import java.util.List; | |
| 12 | - | |
| 13 | -@Mapper | |
| 14 | -public interface LoginLogConvert { | |
| 15 | - | |
| 16 | - LoginLogConvert INSTANCE = Mappers.getMapper(LoginLogConvert.class); | |
| 17 | - | |
| 18 | - PageResult<LoginLogRespVO> convertPage(PageResult<LoginLogDO> page); | |
| 19 | - | |
| 20 | - List<LoginLogExcelVO> convertList(List<LoginLogDO> list); | |
| 21 | - | |
| 22 | - LoginLogDO convert(LoginLogCreateReqDTO bean); | |
| 23 | - | |
| 24 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.system.convert.logger; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExcelVO; | |
| 3 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 4 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 4 | 6 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO; |
| 5 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; |
| 6 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 7 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 9 | -import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; | |
| 10 | 9 | import org.mapstruct.Mapper; |
| 11 | 10 | import org.mapstruct.factory.Mappers; |
| 12 | 11 | |
| 13 | 12 | import java.util.List; |
| 14 | 13 | import java.util.Map; |
| 15 | -import java.util.stream.Collectors; | |
| 16 | - | |
| 17 | -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.SUCCESS; | |
| 18 | 14 | |
| 19 | 15 | @Mapper |
| 20 | 16 | public interface OperateLogConvert { |
| 21 | 17 | |
| 22 | 18 | OperateLogConvert INSTANCE = Mappers.getMapper(OperateLogConvert.class); |
| 23 | 19 | |
| 24 | - OperateLogDO convert(OperateLogCreateReqDTO bean); | |
| 25 | - | |
| 26 | - PageResult<OperateLogRespVO> convertPage(PageResult<OperateLogDO> page); | |
| 27 | - | |
| 28 | - OperateLogRespVO convert(OperateLogDO bean); | |
| 29 | - | |
| 30 | - default List<OperateLogExcelVO> convertList(List<OperateLogDO> list, Map<Long, AdminUserDO> userMap) { | |
| 31 | - return list.stream().map(operateLog -> { | |
| 32 | - OperateLogExcelVO excelVO = convert02(operateLog); | |
| 33 | - MapUtils.findAndThen(userMap, operateLog.getUserId(), user -> excelVO.setUserNickname(user.getNickname())); | |
| 34 | - excelVO.setSuccessStr(SUCCESS.getCode().equals(operateLog.getResultCode()) ? "成功" : "失败"); | |
| 35 | - return excelVO; | |
| 36 | - }).collect(Collectors.toList()); | |
| 20 | + default List<OperateLogRespVO> convertList(List<OperateLogDO> list, Map<Long, AdminUserDO> userMap) { | |
| 21 | + return CollectionUtils.convertList(list, log -> { | |
| 22 | + OperateLogRespVO logVO = BeanUtils.toBean(log, OperateLogRespVO.class); | |
| 23 | + MapUtils.findAndThen(userMap, log.getUserId(), user -> logVO.setUserNickname(user.getNickname())); | |
| 24 | + return logVO; | |
| 25 | + }); | |
| 37 | 26 | } |
| 38 | 27 | |
| 39 | - OperateLogExcelVO convert02(OperateLogDO bean); | |
| 40 | - | |
| 41 | 28 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/LoginLogMapper.java
| ... | ... | @@ -3,14 +3,11 @@ package cn.iocoder.yudao.module.system.dal.mysql.logger; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; |
| 9 | 8 | import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum; |
| 10 | 9 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 10 | |
| 12 | -import java.util.List; | |
| 13 | - | |
| 14 | 11 | @Mapper |
| 15 | 12 | public interface LoginLogMapper extends BaseMapperX<LoginLogDO> { |
| 16 | 13 | |
| ... | ... | @@ -28,18 +25,4 @@ public interface LoginLogMapper extends BaseMapperX<LoginLogDO> { |
| 28 | 25 | return selectPage(reqVO, query); |
| 29 | 26 | } |
| 30 | 27 | |
| 31 | - default List<LoginLogDO> selectList(LoginLogExportReqVO reqVO) { | |
| 32 | - LambdaQueryWrapperX<LoginLogDO> query = new LambdaQueryWrapperX<LoginLogDO>() | |
| 33 | - .likeIfPresent(LoginLogDO::getUserIp, reqVO.getUserIp()) | |
| 34 | - .likeIfPresent(LoginLogDO::getUsername, reqVO.getUsername()) | |
| 35 | - .betweenIfPresent(LoginLogDO::getCreateTime, reqVO.getCreateTime()); | |
| 36 | - if (Boolean.TRUE.equals(reqVO.getStatus())) { | |
| 37 | - query.eq(LoginLogDO::getResult, LoginResultEnum.SUCCESS.getResult()); | |
| 38 | - } else if (Boolean.FALSE.equals(reqVO.getStatus())) { | |
| 39 | - query.gt(LoginLogDO::getResult, LoginResultEnum.SUCCESS.getResult()); | |
| 40 | - } | |
| 41 | - query.orderByDesc(LoginLogDO::getId); // 降序 | |
| 42 | - return selectList(query); | |
| 43 | - } | |
| 44 | - | |
| 45 | 28 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/OperateLogMapper.java
| ... | ... | @@ -4,13 +4,11 @@ import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstant |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; | |
| 8 | 7 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; |
| 10 | 9 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 10 | |
| 12 | 11 | import java.util.Collection; |
| 13 | -import java.util.List; | |
| 14 | 12 | |
| 15 | 13 | @Mapper |
| 16 | 14 | public interface OperateLogMapper extends BaseMapperX<OperateLogDO> { |
| ... | ... | @@ -30,19 +28,4 @@ public interface OperateLogMapper extends BaseMapperX<OperateLogDO> { |
| 30 | 28 | return selectPage(reqVO, query); |
| 31 | 29 | } |
| 32 | 30 | |
| 33 | - default List<OperateLogDO> selectList(OperateLogExportReqVO reqVO, Collection<Long> userIds) { | |
| 34 | - LambdaQueryWrapperX<OperateLogDO> query = new LambdaQueryWrapperX<OperateLogDO>() | |
| 35 | - .likeIfPresent(OperateLogDO::getModule, reqVO.getModule()) | |
| 36 | - .inIfPresent(OperateLogDO::getUserId, userIds) | |
| 37 | - .eqIfPresent(OperateLogDO::getType, reqVO.getType()) | |
| 38 | - .betweenIfPresent(OperateLogDO::getStartTime, reqVO.getStartTime()); | |
| 39 | - if (Boolean.TRUE.equals(reqVO.getSuccess())) { | |
| 40 | - query.eq(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode()); | |
| 41 | - } else if (Boolean.FALSE.equals(reqVO.getSuccess())) { | |
| 42 | - query.gt(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode()); | |
| 43 | - } | |
| 44 | - query.orderByDesc(OperateLogDO::getId); // 降序 | |
| 45 | - return selectList(query); | |
| 46 | - } | |
| 47 | - | |
| 48 | 31 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogService.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.logger; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; | |
| 5 | -import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; | |
| 6 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 4 | import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; | |
| 6 | +import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; | |
| 8 | 7 | |
| 9 | 8 | import javax.validation.Valid; |
| 10 | -import java.util.List; | |
| 11 | 9 | |
| 12 | 10 | /** |
| 13 | 11 | * 登录日志 Service 接口 |
| ... | ... | @@ -17,18 +15,10 @@ public interface LoginLogService { |
| 17 | 15 | /** |
| 18 | 16 | * 获得登录日志分页 |
| 19 | 17 | * |
| 20 | - * @param reqVO 分页条件 | |
| 18 | + * @param pageReqVO 分页条件 | |
| 21 | 19 | * @return 登录日志分页 |
| 22 | 20 | */ |
| 23 | - PageResult<LoginLogDO> getLoginLogPage(LoginLogPageReqVO reqVO); | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * 获得登录日志列表 | |
| 27 | - * | |
| 28 | - * @param reqVO 列表条件 | |
| 29 | - * @return 登录日志列表 | |
| 30 | - */ | |
| 31 | - List<LoginLogDO> getLoginLogList(LoginLogExportReqVO reqVO); | |
| 21 | + PageResult<LoginLogDO> getLoginLogPage(LoginLogPageReqVO pageReqVO); | |
| 32 | 22 | |
| 33 | 23 | /** |
| 34 | 24 | * 创建登录日志 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.logger; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 4 | 5 | import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; | |
| 6 | 6 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; |
| 7 | -import cn.iocoder.yudao.module.system.convert.logger.LoginLogConvert; | |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper; |
| 10 | 9 | import org.springframework.stereotype.Service; |
| 11 | 10 | import org.springframework.validation.annotation.Validated; |
| 12 | 11 | |
| 13 | 12 | import javax.annotation.Resource; |
| 14 | -import java.util.List; | |
| 15 | 13 | |
| 16 | 14 | /** |
| 17 | 15 | * 登录日志 Service 实现 |
| ... | ... | @@ -24,18 +22,13 @@ public class LoginLogServiceImpl implements LoginLogService { |
| 24 | 22 | private LoginLogMapper loginLogMapper; |
| 25 | 23 | |
| 26 | 24 | @Override |
| 27 | - public PageResult<LoginLogDO> getLoginLogPage(LoginLogPageReqVO reqVO) { | |
| 28 | - return loginLogMapper.selectPage(reqVO); | |
| 29 | - } | |
| 30 | - | |
| 31 | - @Override | |
| 32 | - public List<LoginLogDO> getLoginLogList(LoginLogExportReqVO reqVO) { | |
| 33 | - return loginLogMapper.selectList(reqVO); | |
| 25 | + public PageResult<LoginLogDO> getLoginLogPage(LoginLogPageReqVO pageReqVO) { | |
| 26 | + return loginLogMapper.selectPage(pageReqVO); | |
| 34 | 27 | } |
| 35 | 28 | |
| 36 | 29 | @Override |
| 37 | 30 | public void createLoginLog(LoginLogCreateReqDTO reqDTO) { |
| 38 | - LoginLogDO loginLog = LoginLogConvert.INSTANCE.convert(reqDTO); | |
| 31 | + LoginLogDO loginLog = BeanUtils.toBean(reqDTO, LoginLogDO.class); | |
| 39 | 32 | loginLogMapper.insert(loginLog); |
| 40 | 33 | } |
| 41 | 34 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogService.java
| ... | ... | @@ -2,12 +2,9 @@ package cn.iocoder.yudao.module.system.service.logger; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; | |
| 6 | 5 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; |
| 7 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; |
| 8 | 7 | |
| 9 | -import java.util.List; | |
| 10 | - | |
| 11 | 8 | /** |
| 12 | 9 | * 操作日志 Service 接口 |
| 13 | 10 | * |
| ... | ... | @@ -25,17 +22,9 @@ public interface OperateLogService { |
| 25 | 22 | /** |
| 26 | 23 | * 获得操作日志分页列表 |
| 27 | 24 | * |
| 28 | - * @param reqVO 分页条件 | |
| 25 | + * @param pageReqVO 分页条件 | |
| 29 | 26 | * @return 操作日志分页列表 |
| 30 | 27 | */ |
| 31 | - PageResult<OperateLogDO> getOperateLogPage(OperateLogPageReqVO reqVO); | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * 获得操作日志列表 | |
| 35 | - * | |
| 36 | - * @param reqVO 列表条件 | |
| 37 | - * @return 日志列表 | |
| 38 | - */ | |
| 39 | - List<OperateLogDO> getOperateLogList(OperateLogExportReqVO reqVO); | |
| 28 | + PageResult<OperateLogDO> getOperateLogPage(OperateLogPageReqVO pageReqVO); | |
| 40 | 29 | |
| 41 | 30 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImpl.java
| ... | ... | @@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.system.service.logger; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.string.StrUtils; |
| 7 | 8 | import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; | |
| 9 | 9 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; |
| 10 | -import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert; | |
| 11 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; |
| 12 | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 13 | 12 | import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogMapper; |
| ... | ... | @@ -18,13 +17,16 @@ import org.springframework.validation.annotation.Validated; |
| 18 | 17 | |
| 19 | 18 | import javax.annotation.Resource; |
| 20 | 19 | import java.util.Collection; |
| 21 | -import java.util.Collections; | |
| 22 | -import java.util.List; | |
| 23 | 20 | |
| 24 | 21 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 25 | 22 | import static cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO.JAVA_METHOD_ARGS_MAX_LENGTH; |
| 26 | 23 | import static cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO.RESULT_MAX_LENGTH; |
| 27 | 24 | |
| 25 | +/** | |
| 26 | + * 操作日志 Service 实现类 | |
| 27 | + * | |
| 28 | + * @author 芋道源码 | |
| 29 | + */ | |
| 28 | 30 | @Service |
| 29 | 31 | @Validated |
| 30 | 32 | @Slf4j |
| ... | ... | @@ -38,38 +40,24 @@ public class OperateLogServiceImpl implements OperateLogService { |
| 38 | 40 | |
| 39 | 41 | @Override |
| 40 | 42 | public void createOperateLog(OperateLogCreateReqDTO createReqDTO) { |
| 41 | - OperateLogDO logDO = OperateLogConvert.INSTANCE.convert(createReqDTO); | |
| 42 | - logDO.setJavaMethodArgs(StrUtils.maxLength(logDO.getJavaMethodArgs(), JAVA_METHOD_ARGS_MAX_LENGTH)); | |
| 43 | - logDO.setResultData(StrUtils.maxLength(logDO.getResultData(), RESULT_MAX_LENGTH)); | |
| 44 | - operateLogMapper.insert(logDO); | |
| 43 | + OperateLogDO log = BeanUtils.toBean(createReqDTO, OperateLogDO.class); | |
| 44 | + log.setJavaMethodArgs(StrUtils.maxLength(log.getJavaMethodArgs(), JAVA_METHOD_ARGS_MAX_LENGTH)); | |
| 45 | + log.setResultData(StrUtils.maxLength(log.getResultData(), RESULT_MAX_LENGTH)); | |
| 46 | + operateLogMapper.insert(log); | |
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | @Override |
| 48 | - public PageResult<OperateLogDO> getOperateLogPage(OperateLogPageReqVO reqVO) { | |
| 50 | + public PageResult<OperateLogDO> getOperateLogPage(OperateLogPageReqVO pageReqVO) { | |
| 49 | 51 | // 处理基于用户昵称的查询 |
| 50 | 52 | Collection<Long> userIds = null; |
| 51 | - if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { | |
| 52 | - userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId); | |
| 53 | + if (StrUtil.isNotEmpty(pageReqVO.getUserNickname())) { | |
| 54 | + userIds = convertSet(userService.getUserListByNickname(pageReqVO.getUserNickname()), AdminUserDO::getId); | |
| 53 | 55 | if (CollUtil.isEmpty(userIds)) { |
| 54 | 56 | return PageResult.empty(); |
| 55 | 57 | } |
| 56 | 58 | } |
| 57 | 59 | // 查询分页 |
| 58 | - return operateLogMapper.selectPage(reqVO, userIds); | |
| 59 | - } | |
| 60 | - | |
| 61 | - @Override | |
| 62 | - public List<OperateLogDO> getOperateLogList(OperateLogExportReqVO reqVO) { | |
| 63 | - // 处理基于用户昵称的查询 | |
| 64 | - Collection<Long> userIds = null; | |
| 65 | - if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { | |
| 66 | - userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId); | |
| 67 | - if (CollUtil.isEmpty(userIds)) { | |
| 68 | - return Collections.emptyList(); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - // 查询列表 | |
| 72 | - return operateLogMapper.selectList(reqVO, userIds); | |
| 60 | + return operateLogMapper.selectPage(pageReqVO, userIds); | |
| 73 | 61 | } |
| 74 | 62 | |
| 75 | 63 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImplTest.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.service.logger; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 5 | 5 | import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper; |
| ... | ... | @@ -11,7 +10,6 @@ import org.junit.jupiter.api.Test; |
| 11 | 10 | import org.springframework.context.annotation.Import; |
| 12 | 11 | |
| 13 | 12 | import javax.annotation.Resource; |
| 14 | -import java.util.List; | |
| 15 | 13 | |
| 16 | 14 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
| 17 | 15 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| ... | ... | @@ -65,38 +63,6 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest { |
| 65 | 63 | } |
| 66 | 64 | |
| 67 | 65 | @Test |
| 68 | - public void testGetLoginLogList() { | |
| 69 | - // mock 数据 | |
| 70 | - LoginLogDO loginLogDO = randomPojo(LoginLogDO.class, o -> { | |
| 71 | - o.setUserIp("192.168.199.16"); | |
| 72 | - o.setUsername("wang"); | |
| 73 | - o.setResult(SUCCESS.getResult()); | |
| 74 | - o.setCreateTime(buildTime(2021, 3, 6)); | |
| 75 | - }); | |
| 76 | - loginLogMapper.insert(loginLogDO); | |
| 77 | - // 测试 status 不匹配 | |
| 78 | - loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setResult(CAPTCHA_CODE_ERROR.getResult()))); | |
| 79 | - // 测试 ip 不匹配 | |
| 80 | - loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setUserIp("192.168.128.18"))); | |
| 81 | - // 测试 username 不匹配 | |
| 82 | - loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setUsername("yunai"))); | |
| 83 | - // 测试 createTime 不匹配 | |
| 84 | - loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setCreateTime(buildTime(2021, 2, 6)))); | |
| 85 | - // 构造调用参数 | |
| 86 | - LoginLogExportReqVO reqVO = new LoginLogExportReqVO(); | |
| 87 | - reqVO.setUsername("wang"); | |
| 88 | - reqVO.setUserIp("192.168.199"); | |
| 89 | - reqVO.setStatus(true); | |
| 90 | - reqVO.setCreateTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); | |
| 91 | - | |
| 92 | - // 调用service方法 | |
| 93 | - List<LoginLogDO> list = loginLogService.getLoginLogList(reqVO); | |
| 94 | - // 断言 | |
| 95 | - assertEquals(1, list.size()); | |
| 96 | - assertPojoEquals(loginLogDO, list.get(0)); | |
| 97 | - } | |
| 98 | - | |
| 99 | - @Test | |
| 100 | 66 | public void testCreateLoginLog() { |
| 101 | 67 | LoginLogCreateReqDTO reqDTO = randomPojo(LoginLogCreateReqDTO.class); |
| 102 | 68 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImplTest.java
| ... | ... | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; |
| 9 | 9 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 10 | 10 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; |
| 11 | 11 | import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; |
| 12 | -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; | |
| 13 | 12 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; |
| 14 | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; |
| 15 | 14 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| ... | ... | @@ -21,7 +20,6 @@ import org.springframework.context.annotation.Import; |
| 21 | 20 | |
| 22 | 21 | import javax.annotation.Resource; |
| 23 | 22 | import java.util.Collections; |
| 24 | -import java.util.List; | |
| 25 | 23 | |
| 26 | 24 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 27 | 25 | import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; |
| ... | ... | @@ -46,7 +44,7 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { |
| 46 | 44 | private AdminUserService userService; |
| 47 | 45 | |
| 48 | 46 | @Test |
| 49 | - public void testCreateOperateLogAsync() { | |
| 47 | + public void testCreateOperateLog() { | |
| 50 | 48 | OperateLogCreateReqDTO reqVO = RandomUtils.randomPojo(OperateLogCreateReqDTO.class, |
| 51 | 49 | o -> o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build())); |
| 52 | 50 | |
| ... | ... | @@ -105,51 +103,4 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { |
| 105 | 103 | assertPojoEquals(operateLogDO, pageResult.getList().get(0)); |
| 106 | 104 | } |
| 107 | 105 | |
| 108 | - @Test | |
| 109 | - public void testGetOperateLogs() { | |
| 110 | - // mock(用户信息) | |
| 111 | - AdminUserDO user = RandomUtils.randomPojo(AdminUserDO.class, o -> { | |
| 112 | - o.setNickname("wang"); | |
| 113 | - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 114 | - }); | |
| 115 | - when(userService.getUserListByNickname("wang")).thenReturn(Collections.singletonList(user)); | |
| 116 | - Long userId = user.getId(); | |
| 117 | - | |
| 118 | - // 构造操作日志 | |
| 119 | - OperateLogDO operateLogDO = RandomUtils.randomPojo(OperateLogDO.class, o -> { | |
| 120 | - o.setUserId(userId); | |
| 121 | - o.setUserType(randomEle(UserTypeEnum.values()).getValue()); | |
| 122 | - o.setModule("order"); | |
| 123 | - o.setType(OperateTypeEnum.CREATE.getType()); | |
| 124 | - o.setStartTime(buildTime(2021, 3, 6)); | |
| 125 | - o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); | |
| 126 | - o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build()); | |
| 127 | - }); | |
| 128 | - operateLogMapper.insert(operateLogDO); | |
| 129 | - // 测试 userId 不匹配 | |
| 130 | - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setUserId(userId + 1))); | |
| 131 | - // 测试 module 不匹配 | |
| 132 | - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setModule("user"))); | |
| 133 | - // 测试 type 不匹配 | |
| 134 | - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setType(OperateTypeEnum.IMPORT.getType()))); | |
| 135 | - // 测试 createTime 不匹配 | |
| 136 | - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setStartTime(buildTime(2021, 2, 6)))); | |
| 137 | - // 测试 resultCode 不匹配 | |
| 138 | - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setResultCode(BAD_REQUEST.getCode()))); | |
| 139 | - | |
| 140 | - // 构造调用参数 | |
| 141 | - OperateLogExportReqVO reqVO = new OperateLogExportReqVO(); | |
| 142 | - reqVO.setUserNickname("wang"); | |
| 143 | - reqVO.setModule("order"); | |
| 144 | - reqVO.setType(OperateTypeEnum.CREATE.getType()); | |
| 145 | - reqVO.setStartTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); | |
| 146 | - reqVO.setSuccess(true); | |
| 147 | - | |
| 148 | - // 调用 service 方法 | |
| 149 | - List<OperateLogDO> list = operateLogServiceImpl.getOperateLogList(reqVO); | |
| 150 | - // 断言,只查到了一条符合条件的 | |
| 151 | - assertEquals(1, list.size()); | |
| 152 | - assertPojoEquals(operateLogDO, list.get(0)); | |
| 153 | - } | |
| 154 | - | |
| 155 | 106 | } | ... | ... |