🔧 简化 loginLog 和 operateLog 模块的 VO
parent
8eb04d6805
commit
4225db217d
@ -1,40 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 登录日志 Excel 导出响应 VO
|
||||
*/
|
||||
@Data
|
||||
public class LoginLogExcelVO {
|
||||
|
||||
@ExcelProperty("日志主键")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("用户账号")
|
||||
private String username;
|
||||
|
||||
@ExcelProperty(value = "日志类型", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.LOGIN_TYPE)
|
||||
private Integer logType;
|
||||
|
||||
@ExcelProperty(value = "登录结果", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.LOGIN_RESULT)
|
||||
private Integer result;
|
||||
|
||||
@ExcelProperty("登录 IP")
|
||||
private String userIp;
|
||||
|
||||
@ExcelProperty("浏览器 UA")
|
||||
private String userAgent;
|
||||
|
||||
@ExcelProperty("登录时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@ -1,30 +1,57 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 登录日志 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class LoginLogRespVO extends LoginLogBaseVO {
|
||||
@ExcelIgnoreUnannotated
|
||||
public class LoginLogRespVO {
|
||||
|
||||
@Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@ExcelProperty("日志主键")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "日志类型,参见 LoginLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "日志类型", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.LOGIN_TYPE)
|
||||
private Integer logType;
|
||||
|
||||
@Schema(description = "用户编号", example = "666")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab")
|
||||
private String traceId;
|
||||
|
||||
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
|
||||
@ExcelProperty("用户账号")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "登录结果,参见 LoginResultEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "登录结果", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.LOGIN_RESULT)
|
||||
private Integer result;
|
||||
|
||||
@Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1")
|
||||
@ExcelProperty("登录 IP")
|
||||
private String userIp;
|
||||
|
||||
@Schema(description = "浏览器 UserAgent", example = "Mozilla/5.0")
|
||||
@ExcelProperty("浏览器 UA")
|
||||
private String userAgent;
|
||||
|
||||
@Schema(description = "登录时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("登录时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 操作日志 Excel 导出响应 VO
|
||||
*/
|
||||
@Data
|
||||
public class OperateLogExcelVO {
|
||||
|
||||
@ExcelProperty("日志编号")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("操作模块")
|
||||
private String module;
|
||||
|
||||
@ExcelProperty("操作名")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty(value = "操作类型", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.OPERATE_TYPE)
|
||||
private String type;
|
||||
|
||||
@ExcelProperty("操作人")
|
||||
private String userNickname;
|
||||
|
||||
@ExcelProperty(value = "操作结果") // 成功 or 失败
|
||||
private String successStr;
|
||||
|
||||
@ExcelProperty("操作日志")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@ExcelProperty("执行时长")
|
||||
private Integer duration;
|
||||
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 操作日志分页列表 Request VO")
|
||||
@Data
|
||||
public class OperateLogExportReqVO {
|
||||
|
||||
@Schema(description = "操作模块,模拟匹配", example = "订单")
|
||||
private String module;
|
||||
|
||||
@Schema(description = "用户昵称,模拟匹配", example = "芋道")
|
||||
private String userNickname;
|
||||
|
||||
@Schema(description = "操作分类,参见 OperateLogTypeEnum 枚举类", example = "1")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "操作状态", example = "true")
|
||||
private Boolean success;
|
||||
|
||||
@Schema(description = "开始时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] startTime;
|
||||
|
||||
}
|
||||
@ -1,20 +1,90 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
@Schema(description = "管理后台 - 操作日志 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class OperateLogRespVO extends OperateLogBaseVO {
|
||||
@ExcelIgnoreUnannotated
|
||||
public class OperateLogRespVO {
|
||||
|
||||
@Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@ExcelProperty("日志编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab")
|
||||
private String traceId;
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@ExcelProperty("操作人")
|
||||
private String userNickname;
|
||||
|
||||
@Schema(description = "操作模块", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单")
|
||||
@ExcelProperty("操作模块")
|
||||
private String module;
|
||||
|
||||
@Schema(description = "操作名", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建订单")
|
||||
@ExcelProperty("操作名")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "操作分类,参见 OperateLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "操作类型", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.OPERATE_TYPE)
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "操作明细", example = "修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "拓展字段", example = "{'orderId': 1}")
|
||||
private Map<String, Object> exts;
|
||||
|
||||
@Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET")
|
||||
@NotEmpty(message = "请求方法名不能为空")
|
||||
private String requestMethod;
|
||||
|
||||
@Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xxx/yyy")
|
||||
private String requestUrl;
|
||||
|
||||
@Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1")
|
||||
private String userIp;
|
||||
|
||||
@Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0")
|
||||
private String userAgent;
|
||||
|
||||
@Schema(description = "Java 方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "cn.iocoder.yudao.adminserver.UserController.save(...)")
|
||||
private String javaMethod;
|
||||
|
||||
@Schema(description = "Java 方法的参数")
|
||||
private String javaMethodArgs;
|
||||
|
||||
@Schema(description = "开始时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("操作日志")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "执行时长,单位:毫秒", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("执行时长")
|
||||
private Integer duration;
|
||||
|
||||
@Schema(description = "结果码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty(value = "结果码")
|
||||
private Integer resultCode;
|
||||
|
||||
@Schema(description = "结果提示")
|
||||
private String resultMsg;
|
||||
|
||||
@Schema(description = "结果数据")
|
||||
private String resultData;
|
||||
|
||||
}
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.convert.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExcelVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface LoginLogConvert {
|
||||
|
||||
LoginLogConvert INSTANCE = Mappers.getMapper(LoginLogConvert.class);
|
||||
|
||||
PageResult<LoginLogRespVO> convertPage(PageResult<LoginLogDO> page);
|
||||
|
||||
List<LoginLogExcelVO> convertList(List<LoginLogDO> list);
|
||||
|
||||
LoginLogDO convert(LoginLogCreateReqDTO bean);
|
||||
|
||||
}
|
||||
@ -1,41 +1,28 @@
|
||||
package cn.iocoder.yudao.module.system.convert.logger;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExcelVO;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
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.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.SUCCESS;
|
||||
|
||||
@Mapper
|
||||
public interface OperateLogConvert {
|
||||
|
||||
OperateLogConvert INSTANCE = Mappers.getMapper(OperateLogConvert.class);
|
||||
|
||||
OperateLogDO convert(OperateLogCreateReqDTO bean);
|
||||
|
||||
PageResult<OperateLogRespVO> convertPage(PageResult<OperateLogDO> page);
|
||||
|
||||
OperateLogRespVO convert(OperateLogDO bean);
|
||||
|
||||
default List<OperateLogExcelVO> convertList(List<OperateLogDO> list, Map<Long, AdminUserDO> userMap) {
|
||||
return list.stream().map(operateLog -> {
|
||||
OperateLogExcelVO excelVO = convert02(operateLog);
|
||||
MapUtils.findAndThen(userMap, operateLog.getUserId(), user -> excelVO.setUserNickname(user.getNickname()));
|
||||
excelVO.setSuccessStr(SUCCESS.getCode().equals(operateLog.getResultCode()) ? "成功" : "失败");
|
||||
return excelVO;
|
||||
}).collect(Collectors.toList());
|
||||
default List<OperateLogRespVO> convertList(List<OperateLogDO> list, Map<Long, AdminUserDO> userMap) {
|
||||
return CollectionUtils.convertList(list, log -> {
|
||||
OperateLogRespVO logVO = BeanUtils.toBean(log, OperateLogRespVO.class);
|
||||
MapUtils.findAndThen(userMap, log.getUserId(), user -> logVO.setUserNickname(user.getNickname()));
|
||||
return logVO;
|
||||
});
|
||||
}
|
||||
|
||||
OperateLogExcelVO convert02(OperateLogDO bean);
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue