From e330bf0f39d41124000fd1b43d701d88fe1e35c4 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 17 Jan 2021 22:18:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=93=8D=E4=BD=9C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/api/system/operatelog.js | 3 +- .../src/views/system/operatelog/index.vue | 52 +++++++++++-------- .../core/annotations/OperateLog.java | 4 +- .../operatelog/core/aop/OperateLogAspect.java | 28 ++++++---- ...eLogTypeEnum.java => OperateTypeEnum.java} | 2 +- .../logger/SysOperateLogController.java | 33 ++++++++---- .../logger/vo/SysOperateLogExcelVO.java | 42 +++++++++++++++ .../logger/vo/SysOperateLogExportReqVO.java | 36 +++++++++++++ .../convert/logger/SysOperateLogConvert.java | 20 +++++++ .../mysql/dao/logger/SysOperateLogMapper.java | 18 +++++++ .../dataobject/logger/SysOperateLogDO.java | 6 +-- .../system/enums/dict/DictTypeEnum.java | 1 + .../service/logger/SysOperateLogService.java | 11 ++++ .../logger/impl/SysOperateLogServiceImpl.java | 17 ++++++ 14 files changed, 224 insertions(+), 49 deletions(-) rename src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/enums/{OperateLogTypeEnum.java => OperateTypeEnum.java} (96%) create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/SysOperateLogExcelVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/SysOperateLogExportReqVO.java diff --git a/ruoyi-ui/src/api/system/operatelog.js b/ruoyi-ui/src/api/system/operatelog.js index c089975d4..895bf718f 100644 --- a/ruoyi-ui/src/api/system/operatelog.js +++ b/ruoyi-ui/src/api/system/operatelog.js @@ -14,6 +14,7 @@ export function exportOperateLog(query) { return request({ url: '/system/operate-log/export', method: 'get', - params: query + params: query, + responseType: 'blob' }) } diff --git a/ruoyi-ui/src/views/system/operatelog/index.vue b/ruoyi-ui/src/views/system/operatelog/index.vue index f038dc51f..1f1bc1571 100644 --- a/ruoyi-ui/src/views/system/operatelog/index.vue +++ b/ruoyi-ui/src/views/system/operatelog/index.vue @@ -138,36 +138,41 @@ - - {{ form.title }} / {{ typeFormat(form) }} - {{ form.operName }} / {{ form.operIp }} / {{ form.operLocation }} - - - {{ form.operUrl }} - {{ form.requestMethod }} + + {{ form.id }} - {{ form.method }} + {{ form.traceId }} - {{ form.operParam }} + {{ form.userId }} | {{ form.userNickname }} | {{ form.userIp }} | {{ form.userAgent}} - {{ form.jsonResult }} + + {{ form.module }} | {{ form.name }} | {{ getDictDataLabel(DICT_TYPE.SYS_OPERATE_TYPE, form.type) }} +
{{ form.content }} +
{{ form.exts }} +
- - -
正常
-
失败
+ + {{ form.requestMethod }} | {{ form.requestUrl }} + + + {{ form.javaMethod }} + + + {{ form.javaMethodArgs }} + + + + {{ parseTime(form.startTime) }} | {{ form.duration }} ms - {{ parseTime(form.operTime) }} - - - {{ form.errorMsg }} + +
正常 | {{ form.resultData}}
+
失败 | {{ form.resultCode }} || {{ form.resultMsg}}
+
@@ -258,7 +263,10 @@ export default { }, /** 导出按钮操作 */ handleExport() { - const queryParams = this.queryParams; + const queryParams = this.addDateRange(this.queryParams, [ + this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined, + this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined, + ]) this.$confirm('是否确认导出所有操作日志数据项?', "警告", { confirmButtonText: "确定", cancelButtonText: "取消", @@ -266,7 +274,7 @@ export default { }).then(function() { return exportOperateLog(queryParams); }).then(response => { - this.download(response.msg); + this.downloadExcel(response, '操作日志.xls'); }) } } diff --git a/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/annotations/OperateLog.java b/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/annotations/OperateLog.java index 494f04158..e5e941034 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/annotations/OperateLog.java +++ b/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/annotations/OperateLog.java @@ -1,6 +1,6 @@ package cn.iocoder.dashboard.framework.logger.operatelog.core.annotations; -import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateLogTypeEnum; +import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -32,7 +32,7 @@ public @interface OperateLog { * * 实际并不是数组,因为枚举不能设置 null 作为默认值 */ - OperateLogTypeEnum[] type() default {}; + OperateTypeEnum[] type() default {}; // ========== 开关字段 ========== diff --git a/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/aop/OperateLogAspect.java b/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/aop/OperateLogAspect.java index a5afe95e1..3c3b72ea2 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/aop/OperateLogAspect.java +++ b/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/aop/OperateLogAspect.java @@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; import cn.iocoder.dashboard.common.pojo.CommonResult; import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; -import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateLogTypeEnum; +import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum; import cn.iocoder.dashboard.framework.logger.operatelog.core.service.OperateLogFrameworkService; import cn.iocoder.dashboard.framework.security.core.util.SecurityUtils; import cn.iocoder.dashboard.framework.tracer.core.util.TracerUtils; @@ -163,8 +163,14 @@ public class OperateLogAspect { if (StrUtil.isEmpty(operateLogVO.getModule())) { Api api = getClassAnnotation(joinPoint, Api.class); if (api != null) { - operateLogVO.setModule(Optional.of(api.value()) - .orElse(ArrayUtil.isEmpty(api.tags()) ? api.tags()[0] : null)); + // 优先读取 @API 的 name 属性 + if (StrUtil.isNotEmpty(api.value())) { + operateLogVO.setModule(api.value()); + } + // 没有的话,读取 @API 的 tags 属性 + if (StrUtil.isEmpty(operateLogVO.getModule()) && ArrayUtil.isNotEmpty(api.tags())) { + operateLogVO.setModule(api.tags()[0]); + } } } // name 属性 @@ -180,7 +186,7 @@ public class OperateLogAspect { } if (operateLogVO.getType() == null) { RequestMethod requestMethod = obtainFirstMatchRequestMethod(obtainRequestMethod(joinPoint)); - OperateLogTypeEnum operateLogType = convertOperateLogType(requestMethod); + OperateTypeEnum operateLogType = convertOperateLogType(requestMethod); operateLogVO.setType(operateLogType != null ? operateLogType.getType() : null); } // content 和 exts 属性 @@ -275,21 +281,21 @@ public class OperateLogAspect { return requestMethods[0]; } - private static OperateLogTypeEnum convertOperateLogType(RequestMethod requestMethod) { + private static OperateTypeEnum convertOperateLogType(RequestMethod requestMethod) { if (requestMethod == null) { return null; } switch (requestMethod) { case GET: - return OperateLogTypeEnum.GET; + return OperateTypeEnum.GET; case POST: - return OperateLogTypeEnum.CREATE; + return OperateTypeEnum.CREATE; case PUT: - return OperateLogTypeEnum.UPDATE; + return OperateTypeEnum.UPDATE; case DELETE: - return OperateLogTypeEnum.DELETE; + return OperateTypeEnum.DELETE; default: - return OperateLogTypeEnum.OTHER; + return OperateTypeEnum.OTHER; } } @@ -322,7 +328,7 @@ public class OperateLogAspect { // 被忽略时,标记为 ignore 字符串,避免和 null 混在一起 args.put(argName, !isIgnoreArgs(argValue) ? argValue : "[ignore]"); } - return JSON.toJSONString(argValues); + return JSON.toJSONString(args); } private static String obtainResultData(Object result) { diff --git a/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/enums/OperateLogTypeEnum.java b/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/enums/OperateTypeEnum.java similarity index 96% rename from src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/enums/OperateLogTypeEnum.java rename to src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/enums/OperateTypeEnum.java index 5e3552455..8ce1c406b 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/enums/OperateLogTypeEnum.java +++ b/src/main/java/cn/iocoder/dashboard/framework/logger/operatelog/core/enums/OperateTypeEnum.java @@ -11,7 +11,7 @@ import lombok.Getter; */ @Getter @AllArgsConstructor -public enum OperateLogTypeEnum { +public enum OperateTypeEnum { /** * 查询 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/SysOperateLogController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/SysOperateLogController.java index 2b569e193..b71519f98 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/SysOperateLogController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/SysOperateLogController.java @@ -2,9 +2,12 @@ package cn.iocoder.dashboard.modules.system.controller.logger; import cn.iocoder.dashboard.common.pojo.CommonResult; import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils; import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; -import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateLogTypeEnum; +import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum; import cn.iocoder.dashboard.framework.logger.operatelog.core.util.OperateLogUtils; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogExcelVO; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogExportReqVO; import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogPageReqVO; import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogRespVO; import cn.iocoder.dashboard.modules.system.convert.logger.SysOperateLogConvert; @@ -22,12 +25,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import static cn.iocoder.dashboard.common.pojo.CommonResult.success; +import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT; @Api(tags = "操作日志 API") @RestController @@ -41,7 +47,7 @@ public class SysOperateLogController { private SysUserService userService; @ApiOperation("示例") - @OperateLog(type = OperateLogTypeEnum.OTHER) + @OperateLog(type = OperateTypeEnum.OTHER) @GetMapping("/demo") public CommonResult demo() { // 这里可以调用业务逻辑 @@ -74,13 +80,22 @@ public class SysOperateLogController { return success(new PageResult<>(list, pageResult.getTotal())); } -// @Log(title = "操作日志", businessType = BusinessType.EXPORT) + @ApiOperation("导出操作日志") + @GetMapping("/export") + @OperateLog(type = EXPORT) // @PreAuthorize("@ss.hasPermi('system:operate-log:export')") -// @GetMapping("/export") -// public AjaxResult export(SysOperLog operLog) { -// List list = operLogService.selectOperLogList(operLog); -// ExcelUtil util = new ExcelUtil(SysOperLog.class); -// return util.exportExcel(list, "操作日志"); -// } + public void exportOperateLog(HttpServletResponse response, @Validated SysOperateLogExportReqVO reqVO) + throws IOException { + List list = operateLogService.listOperateLogs(reqVO); + + // 获得拼接需要的数据 + Collection userIds = CollectionUtils.convertList(list, SysOperateLogDO::getUserId); + Map userMap = userService.getUserMap(userIds); + // 拼接数据 + List excelDataList = SysOperateLogConvert.INSTANCE.convertList(list, userMap); + // 输出 + ExcelUtils.write(response, "操作日志.xls", "数据列表", + SysOperateLogExcelVO.class, excelDataList); + } } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/SysOperateLogExcelVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/SysOperateLogExcelVO.java new file mode 100644 index 000000000..814607837 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/SysOperateLogExcelVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.dashboard.modules.system.controller.logger.vo; + +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat; +import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert; +import cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * 操作日志 Excel 导出响应 VO + */ +@Data +public class SysOperateLogExcelVO { + + @ExcelProperty("日志编号") + private Long id; + + @ExcelProperty("操作模块") + private String module; + + @ExcelProperty("操作名") + private String name; + + @ExcelProperty(value = "操作类型", converter = DictConvert.class) + @DictFormat(DictTypeEnum.SYS_OPERATE_TYPE) + private String type; + + @ExcelProperty("操作人") + private String userNickname; + + @ExcelProperty(value = "操作结果") // 成功 or 失败 + private String successStr; + + @ExcelProperty("操作日志") + private Date startTime; + + @ExcelProperty("执行时长") + private Integer duration; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/SysOperateLogExportReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/SysOperateLogExportReqVO.java new file mode 100644 index 000000000..53f3dae9e --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/SysOperateLogExportReqVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.dashboard.modules.system.controller.logger.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("操作日志分页列表 Request VO") +@Data +public class SysOperateLogExportReqVO { + + @ApiModelProperty(value = "操作模块", example = "订单", notes = "模拟匹配") + private String module; + + @ApiModelProperty(value = "用户昵称", example = "芋道", notes = "模拟匹配") + private String userNickname; + + @ApiModelProperty(value = "操作分类", example = "1", notes = "参见 SysOperateLogTypeEnum 枚举类") + private Integer type; + + @ApiModelProperty(value = "操作状态", example = "true") + private Boolean success; + + @ApiModelProperty(value = "开始时间", example = "2020-10-24") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date beginTime; + + @ApiModelProperty(value = "结束时间", example = "2020-10-24") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date endTime; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/logger/SysOperateLogConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/logger/SysOperateLogConvert.java index 2f46788e4..53dd381ca 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/convert/logger/SysOperateLogConvert.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/convert/logger/SysOperateLogConvert.java @@ -2,11 +2,20 @@ package cn.iocoder.dashboard.modules.system.convert.logger; import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogExcelVO; import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogRespVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysOperateLogDO; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; +import cn.iocoder.dashboard.util.collection.MapUtils; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants.SUCCESS; + @Mapper public interface SysOperateLogConvert { @@ -18,4 +27,15 @@ public interface SysOperateLogConvert { SysOperateLogRespVO convert(SysOperateLogDO bean); + default List convertList(List list, Map userMap) { + return list.stream().map(operateLog -> { + SysOperateLogExcelVO excelVO = convert02(operateLog); + MapUtils.findAndThen(userMap, operateLog.getId(), user -> excelVO.setUserNickname(user.getNickname())); + excelVO.setSuccessStr(SUCCESS.getCode().equals(operateLog.getResultCode()) ? "成功" : "失败"); + return excelVO; + }).collect(Collectors.toList()); + } + + SysOperateLogExcelVO convert02(SysOperateLogDO bean); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/logger/SysOperateLogMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/logger/SysOperateLogMapper.java index 99667ec78..d52524483 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/logger/SysOperateLogMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/logger/SysOperateLogMapper.java @@ -4,11 +4,13 @@ import cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants; import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogExportReqVO; import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogPageReqVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysOperateLogDO; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; +import java.util.List; @Mapper public interface SysOperateLogMapper extends BaseMapperX { @@ -24,7 +26,23 @@ public interface SysOperateLogMapper extends BaseMapperX { } else if (Boolean.FALSE.equals(reqVO.getSuccess())) { query.gt("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); } + query.orderByDesc("id"); // 降序 return selectPage(reqVO, query); } + default List selectList(SysOperateLogExportReqVO reqVO, Collection userIds) { + QueryWrapperX query = new QueryWrapperX() + .likeIfPresent("module", reqVO.getModule()) + .inIfPresent("user_id", userIds) + .eqIfPresent("operate_type", reqVO.getType()) + .betweenIfPresent("start_time", reqVO.getBeginTime(), reqVO.getEndTime()); + if (Boolean.TRUE.equals(reqVO.getSuccess())) { + query.eq("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); + } else if (Boolean.FALSE.equals(reqVO.getSuccess())) { + query.gt("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); + } + query.orderByDesc("id"); // 降序 + return selectList(query); + } + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java index 709b486ab..14a0654d3 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java @@ -3,7 +3,7 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger; import cn.iocoder.dashboard.common.pojo.CommonResult; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; -import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateLogTypeEnum; +import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -19,7 +19,7 @@ import java.util.Map; * * @author 芋道源码 */ -@TableName("sys_operate_log") +@TableName(value = "sys_operate_log", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) public class SysOperateLogDO extends BaseDO { @@ -62,7 +62,7 @@ public class SysOperateLogDO extends BaseDO { /** * 操作分类 * - * 枚举 {@link OperateLogTypeEnum} + * 枚举 {@link OperateTypeEnum} */ @TableField("operate_type") private Integer type; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java b/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java index c4147f032..4b8b96738 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java @@ -12,6 +12,7 @@ public enum DictTypeEnum { SYS_USER_SEX("sys_user_sex"), // 用户性别 SYS_COMMON_STATUS("sys_common_status"), // 系统状态 + SYS_OPERATE_TYPE("sys_operate_type"), // 操作类型 ; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/SysOperateLogService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/SysOperateLogService.java index 89d87720a..ed66ad4c6 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/SysOperateLogService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/SysOperateLogService.java @@ -2,9 +2,12 @@ package cn.iocoder.dashboard.modules.system.service.logger; import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.framework.logger.operatelog.core.service.OperateLogFrameworkService; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogExportReqVO; import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogPageReqVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysOperateLogDO; +import java.util.List; + /** * 操作日志 Service 接口 */ @@ -18,4 +21,12 @@ public interface SysOperateLogService extends OperateLogFrameworkService { */ PageResult pageOperateLog(SysOperateLogPageReqVO reqVO); + /** + * 获得操作日志列表 + * + * @param reqVO 列表条件 + * @return 日志列表 + */ + List listOperateLogs(SysOperateLogExportReqVO reqVO); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/impl/SysOperateLogServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/impl/SysOperateLogServiceImpl.java index 0e8953c70..0193d5dc0 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/impl/SysOperateLogServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/impl/SysOperateLogServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogExportReqVO; import cn.iocoder.dashboard.modules.system.controller.logger.vo.SysOperateLogPageReqVO; import cn.iocoder.dashboard.modules.system.convert.logger.SysOperateLogConvert; import cn.iocoder.dashboard.modules.system.dal.mysql.dao.logger.SysOperateLogMapper; @@ -18,6 +19,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; +import java.util.Collections; +import java.util.List; import static cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysOperateLogDO.JAVA_METHOD_ARGS_MAX_LENGTH; import static cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysOperateLogDO.RESULT_MAX_LENGTH; @@ -61,4 +64,18 @@ public class SysOperateLogServiceImpl implements SysOperateLogService { return operateLogMapper.selectPage(reqVO, userIds); } + @Override + public List listOperateLogs(SysOperateLogExportReqVO reqVO) { + // 处理基于用户昵称的查询 + Collection userIds = null; + if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { + userIds = convertSet(userService.listUsersByNickname(reqVO.getUserNickname()), SysUserDO::getId); + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } + } + // 查询列表 + return operateLogMapper.selectList(reqVO, userIds); + } + }