生成操作日志代码.
This commit is contained in:
@@ -93,26 +93,30 @@ public class OperatorLogAspect {
|
||||
* @param exception exception
|
||||
*/
|
||||
private void saveLog(long start, OperatorLog o, Object ret, Throwable exception) {
|
||||
// 请求信息
|
||||
Map<String, Object> extra = OperatorLogs.get();
|
||||
if (!OperatorLogs.isSave(extra)) {
|
||||
return;
|
||||
try {
|
||||
// 请求信息
|
||||
Map<String, Object> extra = OperatorLogs.get();
|
||||
if (!OperatorLogs.isSave(extra)) {
|
||||
return;
|
||||
}
|
||||
OperatorLogModel model = new OperatorLogModel();
|
||||
// 填充使用时间
|
||||
this.fillUseTime(model, start);
|
||||
// 填充用户信息
|
||||
this.fillUserInfo(model);
|
||||
// 填充请求信息
|
||||
this.fillRequest(model);
|
||||
// 填充结果信息
|
||||
this.fillResult(model, o, ret, exception);
|
||||
// 填充拓展信息
|
||||
this.fillExtra(model, extra);
|
||||
// 填充日志
|
||||
this.fillLogInfo(model, extra, o);
|
||||
// 插入日志
|
||||
this.asyncSaveLog(model);
|
||||
} catch (Exception e) {
|
||||
log.error("操作日志保存失败", e);
|
||||
}
|
||||
OperatorLogModel model = new OperatorLogModel();
|
||||
// 填充使用时间
|
||||
this.fillUseTime(model, start);
|
||||
// 填充用户信息
|
||||
this.fillUserInfo(model);
|
||||
// 填充请求信息
|
||||
this.fillRequest(model);
|
||||
// 填充结果信息
|
||||
this.fillResult(model, o, ret, exception);
|
||||
// 填充拓展信息
|
||||
this.fillExtra(model, extra);
|
||||
// 填充日志
|
||||
this.fillLogInfo(model, extra, o);
|
||||
// 插入日志
|
||||
this.asyncSaveLog(model);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +155,7 @@ public class OperatorLogAspect {
|
||||
String address = Servlets.getRemoteAddr(request);
|
||||
model.setAddress(address);
|
||||
model.setLocation(IpUtils.getLocation(address));
|
||||
model.setUserAgent(Servlets.getUserAgent(request));
|
||||
model.setUserAgent(Strings.retain(Servlets.getUserAgent(request), operatorLogConfig.getUserAgentLength()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -189,7 +193,9 @@ public class OperatorLogAspect {
|
||||
*/
|
||||
private void fillExtra(OperatorLogModel model, Map<String, Object> extra) {
|
||||
// 脱敏
|
||||
model.setExtra(JSON.toJSONString(extra, desensitizeValueFilter));
|
||||
if (extra != null) {
|
||||
model.setExtra(JSON.toJSONString(extra, desensitizeValueFilter));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,13 @@ public class OperatorLogConfig {
|
||||
*/
|
||||
private Integer errorMessageLength;
|
||||
|
||||
/**
|
||||
* userAgent 长度
|
||||
*/
|
||||
private Integer userAgentLength;
|
||||
|
||||
public OperatorLogConfig() {
|
||||
this.errorMessageLength = 255;
|
||||
this.userAgentLength = 128;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,10 @@ public class OperatorTypeHolder {
|
||||
/**
|
||||
* 设置类型
|
||||
*
|
||||
* @param key key
|
||||
* @param type type
|
||||
*/
|
||||
public static void set(String key, OperatorType type) {
|
||||
TYPES.put(key, type);
|
||||
public static void set(OperatorType type) {
|
||||
TYPES.put(type.getType(), type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,14 @@
|
||||
{
|
||||
"name": "orion.operator-log.error-message-length",
|
||||
"type": "java.lang.Integer",
|
||||
"description": "日志打印模型.",
|
||||
"description": "错误信息长度.",
|
||||
"defaultValue": "255"
|
||||
},
|
||||
{
|
||||
"name": "orion.operator-log.user-agent-length",
|
||||
"type": "java.lang.Integer",
|
||||
"description": "userAgent 长度.",
|
||||
"defaultValue": "128"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -20,28 +20,28 @@ import java.util.Date;
|
||||
@Data
|
||||
public class BaseDO implements Serializable {
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
|
||||
@Schema(description = "创建人")
|
||||
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
|
||||
private String creator;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.VARCHAR)
|
||||
@Schema(description = "修改人")
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.VARCHAR)
|
||||
private String updater;
|
||||
|
||||
/**
|
||||
* @see com.orion.ops.framework.common.constant.Const#NOT_DELETE
|
||||
* @see com.orion.ops.framework.common.constant.Const#IS_DELETED
|
||||
*/
|
||||
@TableLogic
|
||||
@Schema(description = "是否删除 0未删除 1已删除")
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.TINYINT)
|
||||
private Boolean deleted;
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
||||
* @return 是否为后端缓存文件
|
||||
*/
|
||||
private boolean isServerCacheFile(String templatePath) {
|
||||
return templatePath.contains("orion-server-cache");
|
||||
return templatePath.contains("orion-server-module-cache");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -197,4 +197,5 @@ orion:
|
||||
queue-capacity: 30
|
||||
keep-alive-seconds: 180
|
||||
operator-log:
|
||||
error-message-length: 255
|
||||
error-message-length: 255
|
||||
user-agent-length: 128
|
||||
@@ -15,14 +15,14 @@
|
||||
<id column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#end
|
||||
#foreach($field in ${table.commonFields})##生成公共字段
|
||||
<result column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#foreach($field in ${table.fields})
|
||||
#if(!${field.keyFlag})##生成普通字段
|
||||
<result column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#end
|
||||
#foreach($field in ${table.commonFields})##生成公共字段
|
||||
<result column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
</resultMap>
|
||||
|
||||
#end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.module.asset.define;
|
||||
package com.orion.ops.module.asset.define.cache;
|
||||
|
||||
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
@@ -15,7 +15,7 @@ import com.orion.ops.module.asset.convert.HostIdentityConvert;
|
||||
import com.orion.ops.module.asset.dao.HostConfigDAO;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
import com.orion.ops.module.asset.define.HostCacheKeyDefine;
|
||||
import com.orion.ops.module.asset.define.cache.HostCacheKeyDefine;
|
||||
import com.orion.ops.module.asset.entity.domain.HostIdentityDO;
|
||||
import com.orion.ops.module.asset.entity.domain.HostKeyDO;
|
||||
import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO;
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.orion.ops.module.asset.convert.HostKeyConvert;
|
||||
import com.orion.ops.module.asset.dao.HostConfigDAO;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
import com.orion.ops.module.asset.define.HostCacheKeyDefine;
|
||||
import com.orion.ops.module.asset.define.cache.HostCacheKeyDefine;
|
||||
import com.orion.ops.module.asset.entity.domain.HostKeyDO;
|
||||
import com.orion.ops.module.asset.entity.dto.HostKeyCacheDTO;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostKeyCreateRequest;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
### 分页查询操作日志
|
||||
POST {{baseUrl}}/infra/operator-log/query
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"page": 1,
|
||||
"limit": 10,
|
||||
"userId": "",
|
||||
"module": "",
|
||||
"type": "",
|
||||
"result": "",
|
||||
"startTime": "",
|
||||
"endTime": ""
|
||||
}
|
||||
|
||||
###
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.orion.ops.module.infra.controller;
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.framework.common.validator.group.Page;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.infra.entity.request.operator.log.OperatorLogQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.OperatorLogVO;
|
||||
import com.orion.ops.module.infra.service.OperatorLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 操作日志 api
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
@Tag(name = "infra - 操作日志服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/infra/operator-log")
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class OperatorLogController {
|
||||
|
||||
@Resource
|
||||
private OperatorLogService operatorLogService;
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "分页查询操作日志")
|
||||
@PreAuthorize("@ss.hasPermission('infra:operator-log:query')")
|
||||
public DataGrid<OperatorLogVO> getOperatorLogPage(@Validated(Page.class) @RequestBody OperatorLogQueryRequest request) {
|
||||
return operatorLogService.getOperatorLogPage(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.orion.ops.module.infra.controller;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.define.wrapper.HttpWrapper;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.common.validator.group.Page;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.infra.define.operator.UserOperatorType;
|
||||
import com.orion.ops.module.infra.entity.request.user.*;
|
||||
import com.orion.ops.module.infra.entity.vo.SystemUserVO;
|
||||
import com.orion.ops.module.infra.service.SystemUserRoleService;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.orion.ops.module.infra.convert;
|
||||
|
||||
import com.orion.ops.framework.biz.operator.log.core.model.OperatorLogModel;
|
||||
import com.orion.ops.module.infra.entity.domain.OperatorLogDO;
|
||||
import com.orion.ops.module.infra.entity.request.operator.log.OperatorLogQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.OperatorLogVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 操作日志 内部对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
@Mapper
|
||||
public interface OperatorLogConvert {
|
||||
|
||||
OperatorLogConvert MAPPER = Mappers.getMapper(OperatorLogConvert.class);
|
||||
|
||||
OperatorLogDO to(OperatorLogModel model);
|
||||
|
||||
OperatorLogDO to(OperatorLogQueryRequest request);
|
||||
|
||||
OperatorLogVO to(OperatorLogDO domain);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.orion.ops.module.infra.dao;
|
||||
|
||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.ops.module.infra.entity.domain.OperatorLogDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 操作日志 Mapper 接口
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
@Mapper
|
||||
public interface OperatorLogDAO extends IMapper<OperatorLogDO> {
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.module.infra.define;
|
||||
package com.orion.ops.module.infra.define.cache;
|
||||
|
||||
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.module.infra.define;
|
||||
package com.orion.ops.module.infra.define.cache;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.module.infra.define;
|
||||
package com.orion.ops.module.infra.define.cache;
|
||||
|
||||
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.module.infra.define;
|
||||
package com.orion.ops.module.infra.define.cache;
|
||||
|
||||
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.module.infra.define;
|
||||
package com.orion.ops.module.infra.define.cache;
|
||||
|
||||
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.orion.ops.module.infra.entity.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 操作日志 实体对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "operator_log", autoResultMap = true)
|
||||
@Schema(name = "OperatorLogDO", description = "操作日志 实体对象")
|
||||
public class OperatorLogDO extends BaseDO {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "traceId")
|
||||
@TableField("trace_id")
|
||||
private String traceId;
|
||||
|
||||
@Schema(description = "请求ip")
|
||||
@TableField("address")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "请求地址")
|
||||
@TableField("location")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "userAgent")
|
||||
@TableField("user_agent")
|
||||
private String userAgent;
|
||||
|
||||
@Schema(description = "模块")
|
||||
@TableField("module")
|
||||
private String module;
|
||||
|
||||
@Schema(description = "操作类型")
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "日志")
|
||||
@TableField("log_info")
|
||||
private String logInfo;
|
||||
|
||||
@Schema(description = "参数")
|
||||
@TableField("extra")
|
||||
private String extra;
|
||||
|
||||
@Schema(description = "操作结果 0失败 1成功")
|
||||
@TableField("result")
|
||||
private Integer result;
|
||||
|
||||
@Schema(description = "错误信息")
|
||||
@TableField("error_message")
|
||||
private String errorMessage;
|
||||
|
||||
@Schema(description = "返回值")
|
||||
@TableField("return_value")
|
||||
private String returnValue;
|
||||
|
||||
@Schema(description = "操作时间")
|
||||
@TableField("duration")
|
||||
private Integer duration;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
@TableField("start_time")
|
||||
private Date startTime;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
@TableField("end_time")
|
||||
private Date endTime;
|
||||
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(exist = false)
|
||||
private Date updateTime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
@TableField(exist = false)
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "修改人")
|
||||
@TableField(exist = false)
|
||||
private String updater;
|
||||
|
||||
@Schema(description = "是否删除 0未删除 1已删除")
|
||||
@TableField(exist = false)
|
||||
private Boolean deleted;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.orion.ops.module.infra.entity.request.operator.log;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.orion.ops.framework.common.entity.PageRequest;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 操作日志 查询请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(name = "OperatorLogQueryRequest", description = "操作日志 查询请求对象")
|
||||
public class OperatorLogQueryRequest extends PageRequest {
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "模块")
|
||||
private String module;
|
||||
|
||||
@Size(max = 64)
|
||||
@Schema(description = "操作类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "操作结果 0失败 1成功")
|
||||
private Integer result;
|
||||
|
||||
@Schema(description = "开始时间-开区间")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date startTimeStart;
|
||||
|
||||
@Schema(description = "开始时间-闭区间")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date startTimeEnd;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.orion.ops.module.infra.entity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 操作日志 视图响应对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "OperatorLogVO", description = "操作日志 视图响应对象")
|
||||
public class OperatorLogVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "traceId")
|
||||
private String traceId;
|
||||
|
||||
@Schema(description = "请求ip")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "请求地址")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "userAgent")
|
||||
private String userAgent;
|
||||
|
||||
@Schema(description = "模块")
|
||||
private String module;
|
||||
|
||||
@Schema(description = "操作类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "日志")
|
||||
private String logInfo;
|
||||
|
||||
@Schema(description = "参数")
|
||||
private String extra;
|
||||
|
||||
@Schema(description = "操作结果 0失败 1成功")
|
||||
private Integer result;
|
||||
|
||||
@Schema(description = "错误信息")
|
||||
private String errorMessage;
|
||||
|
||||
@Schema(description = "返回值")
|
||||
private String returnValue;
|
||||
|
||||
@Schema(description = "操作时间")
|
||||
private Integer duration;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
private Date startTime;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
private Date endTime;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -2,8 +2,11 @@ package com.orion.ops.module.infra.framework.service.impl;
|
||||
|
||||
import com.orion.ops.framework.biz.operator.log.core.model.OperatorLogModel;
|
||||
import com.orion.ops.framework.biz.operator.log.core.service.OperatorLogFrameworkService;
|
||||
import com.orion.ops.module.infra.service.OperatorLogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 操作日志包 实现类
|
||||
*
|
||||
@@ -14,9 +17,12 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class OperatorLogFrameworkServiceImpl implements OperatorLogFrameworkService {
|
||||
|
||||
@Resource
|
||||
private OperatorLogService operatorLogService;
|
||||
|
||||
@Override
|
||||
public void insert(OperatorLogModel log) {
|
||||
System.out.println(log);
|
||||
operatorLogService.addOperatorLog(log);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.orion.ops.module.infra.service;
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.framework.biz.operator.log.core.model.OperatorLogModel;
|
||||
import com.orion.ops.module.infra.entity.request.operator.log.OperatorLogQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.OperatorLogVO;
|
||||
|
||||
/**
|
||||
* 操作日志 服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
public interface OperatorLogService {
|
||||
|
||||
/**
|
||||
* 添加操作日志
|
||||
*
|
||||
* @param model model
|
||||
*/
|
||||
void addOperatorLog(OperatorLogModel model);
|
||||
|
||||
/**
|
||||
* 分页查询操作日志
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
*/
|
||||
DataGrid<OperatorLogVO> getOperatorLogPage(OperatorLogQueryRequest request);
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.infra.convert.SystemUserConvert;
|
||||
import com.orion.ops.module.infra.dao.SystemUserDAO;
|
||||
import com.orion.ops.module.infra.dao.SystemUserRoleDAO;
|
||||
import com.orion.ops.module.infra.define.UserCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.define.cache.UserCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemRoleDO;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
||||
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.orion.ops.framework.redis.core.utils.RedisLists;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.infra.convert.FavoriteConvert;
|
||||
import com.orion.ops.module.infra.dao.FavoriteDAO;
|
||||
import com.orion.ops.module.infra.define.FavoriteCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.define.cache.FavoriteCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.FavoriteDO;
|
||||
import com.orion.ops.module.infra.entity.request.favorite.FavoriteOperatorRequest;
|
||||
import com.orion.ops.module.infra.entity.request.favorite.FavoriteQueryRequest;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.framework.biz.operator.log.core.model.OperatorLogModel;
|
||||
import com.orion.ops.module.infra.convert.OperatorLogConvert;
|
||||
import com.orion.ops.module.infra.dao.OperatorLogDAO;
|
||||
import com.orion.ops.module.infra.entity.domain.OperatorLogDO;
|
||||
import com.orion.ops.module.infra.entity.request.operator.log.OperatorLogQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.OperatorLogVO;
|
||||
import com.orion.ops.module.infra.service.OperatorLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 操作日志 服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class OperatorLogServiceImpl implements OperatorLogService {
|
||||
|
||||
@Resource
|
||||
private OperatorLogDAO operatorLogDAO;
|
||||
|
||||
@Override
|
||||
public void addOperatorLog(OperatorLogModel model) {
|
||||
// 转换
|
||||
OperatorLogDO record = OperatorLogConvert.MAPPER.to(model);
|
||||
// 插入
|
||||
operatorLogDAO.insert(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataGrid<OperatorLogVO> getOperatorLogPage(OperatorLogQueryRequest request) {
|
||||
// 条件
|
||||
LambdaQueryWrapper<OperatorLogDO> wrapper = this.buildQueryWrapper(request);
|
||||
// 查询
|
||||
return operatorLogDAO.of(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(OperatorLogConvert.MAPPER::to);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询 wrapper
|
||||
*
|
||||
* @param request request
|
||||
* @return wrapper
|
||||
*/
|
||||
private LambdaQueryWrapper<OperatorLogDO> buildQueryWrapper(OperatorLogQueryRequest request) {
|
||||
return operatorLogDAO.wrapper()
|
||||
.eq(OperatorLogDO::getUserId, request.getUserId())
|
||||
.eq(OperatorLogDO::getModule, request.getModule())
|
||||
.eq(OperatorLogDO::getType, request.getType())
|
||||
.eq(OperatorLogDO::getResult, request.getResult())
|
||||
.ge(OperatorLogDO::getStartTime, request.getStartTimeStart())
|
||||
.le(OperatorLogDO::getStartTime, request.getStartTimeEnd());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.infra.dao.PreferenceDAO;
|
||||
import com.orion.ops.module.infra.define.PreferenceCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.define.cache.PreferenceCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.PreferenceDO;
|
||||
import com.orion.ops.module.infra.entity.request.preference.PreferenceUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.PreferenceVO;
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.module.infra.dao.SystemRoleDAO;
|
||||
import com.orion.ops.module.infra.dao.SystemUserDAO;
|
||||
import com.orion.ops.module.infra.dao.SystemUserRoleDAO;
|
||||
import com.orion.ops.module.infra.define.UserCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.define.cache.UserCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemRoleDO;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemUserRoleDO;
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.infra.convert.SystemUserConvert;
|
||||
import com.orion.ops.module.infra.dao.SystemUserDAO;
|
||||
import com.orion.ops.module.infra.dao.SystemUserRoleDAO;
|
||||
import com.orion.ops.module.infra.define.UserCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.define.cache.UserCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
||||
import com.orion.ops.module.infra.entity.request.user.*;
|
||||
import com.orion.ops.module.infra.entity.vo.SystemUserVO;
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.module.infra.convert.TagRelConvert;
|
||||
import com.orion.ops.module.infra.dao.TagDAO;
|
||||
import com.orion.ops.module.infra.dao.TagRelDAO;
|
||||
import com.orion.ops.module.infra.define.TagCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.define.cache.TagCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.TagDO;
|
||||
import com.orion.ops.module.infra.entity.domain.TagRelDO;
|
||||
import com.orion.ops.module.infra.entity.dto.TagCacheDTO;
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.orion.ops.framework.mybatis.core.query.Conditions;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisLists;
|
||||
import com.orion.ops.module.infra.convert.TagConvert;
|
||||
import com.orion.ops.module.infra.dao.TagDAO;
|
||||
import com.orion.ops.module.infra.define.TagCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.define.cache.TagCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.TagDO;
|
||||
import com.orion.ops.module.infra.entity.dto.TagCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.tag.TagCreateRequest;
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.orion.ops.module.infra.service.impl;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisLists;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.infra.define.TipsCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.define.cache.TipsCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.service.TipsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.orion.ops.module.infra.dao.OperatorLogDAO">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.OperatorLogDO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="trace_id" property="traceId"/>
|
||||
<result column="address" property="address"/>
|
||||
<result column="location" property="location"/>
|
||||
<result column="user_agent" property="userAgent"/>
|
||||
<result column="module" property="module"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="log_info" property="logInfo"/>
|
||||
<result column="extra" property="extra"/>
|
||||
<result column="result" property="result"/>
|
||||
<result column="error_message" property="errorMessage"/>
|
||||
<result column="return_value" property="returnValue"/>
|
||||
<result column="duration" property="duration"/>
|
||||
<result column="start_time" property="startTime"/>
|
||||
<result column="end_time" property="endTime"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, trace_id, address, location, user_agent, module, type, log_info, extra, result, error_message, return_value, duration, start_time, end_time, create_time
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user