mirror of https://gitee.com/stylefeng/roses
【8.1.9】新增安全日志模块
parent
6691258d52
commit
ff75cc50fd
|
@ -0,0 +1 @@
|
|||
安全日志记录
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.javaguns.roses</groupId>
|
||||
<artifactId>kernel-d-log</artifactId>
|
||||
<version>8.1.9</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>log-business-security</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--日志api模块-->
|
||||
<dependency>
|
||||
<groupId>com.javaguns.roses</groupId>
|
||||
<artifactId>log-api</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--资源api模块-->
|
||||
<!--aop获取注解属性-->
|
||||
<dependency>
|
||||
<groupId>com.javaguns.roses</groupId>
|
||||
<artifactId>scanner-api</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--auth模块-->
|
||||
<!--获取当前登录用户-->
|
||||
<dependency>
|
||||
<groupId>com.javaguns.roses</groupId>
|
||||
<artifactId>auth-api</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- web -->
|
||||
<!-- 用于本模块中对controller的拦截器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- aop -->
|
||||
<!-- 用于本模块中对controller的拦截器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,114 @@
|
|||
package cn.stylefeng.roses.kernel.log.security.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.log.security.entity.LogSecurity;
|
||||
import cn.stylefeng.roses.kernel.log.security.pojo.request.LogSecurityRequest;
|
||||
import cn.stylefeng.roses.kernel.log.security.service.LogSecurityService;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全日志控制器
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "安全日志")
|
||||
public class LogSecurityController {
|
||||
|
||||
@Resource
|
||||
private LogSecurityService logSecurityService;
|
||||
|
||||
/**
|
||||
* 添加安全日志
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@PostResource(name = "添加安全日志", path = "/logSecurity/add")
|
||||
public ResponseData<LogSecurity> add(@RequestBody @Validated(LogSecurityRequest.add.class) LogSecurityRequest logSecurityRequest) {
|
||||
logSecurityService.add(logSecurityRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除安全日志
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@PostResource(name = "删除安全日志", path = "/logSecurity/delete")
|
||||
public ResponseData<?> delete(@RequestBody @Validated(LogSecurityRequest.delete.class) LogSecurityRequest logSecurityRequest) {
|
||||
logSecurityService.del(logSecurityRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除安全日志
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@PostResource(name = "批量删除安全日志", path = "/logSecurity/batchDelete")
|
||||
public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) LogSecurityRequest logSecurityRequest) {
|
||||
logSecurityService.batchDelete(logSecurityRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑安全日志
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@PostResource(name = "编辑安全日志", path = "/logSecurity/edit")
|
||||
public ResponseData<?> edit(@RequestBody @Validated(LogSecurityRequest.edit.class) LogSecurityRequest logSecurityRequest) {
|
||||
logSecurityService.edit(logSecurityRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看安全日志详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@GetResource(name = "查看安全日志详情", path = "/logSecurity/detail")
|
||||
public ResponseData<LogSecurity> detail(@Validated(LogSecurityRequest.detail.class) LogSecurityRequest logSecurityRequest) {
|
||||
return new SuccessResponseData<>(logSecurityService.detail(logSecurityRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取安全日志列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@GetResource(name = "获取安全日志列表", path = "/logSecurity/list")
|
||||
public ResponseData<List<LogSecurity>> list(LogSecurityRequest logSecurityRequest) {
|
||||
return new SuccessResponseData<>(logSecurityService.findList(logSecurityRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取安全日志列表(带分页)
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@GetResource(name = "获取安全日志列表(带分页)", path = "/logSecurity/page")
|
||||
public ResponseData<PageResult<LogSecurity>> page(LogSecurityRequest logSecurityRequest) {
|
||||
return new SuccessResponseData<>(logSecurityService.findPage(logSecurityRequest));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package cn.stylefeng.roses.kernel.log.security.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
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 lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 安全日志实例类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@TableName("sys_log_security")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LogSecurity extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "security_log_id", type = IdType.ASSIGN_ID)
|
||||
@ChineseDescription("主键")
|
||||
private Long securityLogId;
|
||||
|
||||
/**
|
||||
* 当前用户请求的url
|
||||
*/
|
||||
@TableField("request_url")
|
||||
@ChineseDescription("当前用户请求的url")
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* http或方法的请求参数体
|
||||
*/
|
||||
@TableField("request_params")
|
||||
@ChineseDescription("http或方法的请求参数体")
|
||||
private String requestParams;
|
||||
|
||||
/**
|
||||
* 当前服务器的ip
|
||||
*/
|
||||
@TableField("server_ip")
|
||||
@ChineseDescription("当前服务器的ip")
|
||||
private String serverIp;
|
||||
|
||||
/**
|
||||
* 客户端的ip
|
||||
*/
|
||||
@TableField("client_ip")
|
||||
@ChineseDescription("客户端的ip")
|
||||
private String clientIp;
|
||||
|
||||
/**
|
||||
* 请求http方法
|
||||
*/
|
||||
@TableField("http_method")
|
||||
@ChineseDescription("请求http方法")
|
||||
private String httpMethod;
|
||||
|
||||
/**
|
||||
* 客户浏览器标识
|
||||
*/
|
||||
@TableField("client_browser")
|
||||
@ChineseDescription("客户浏览器标识")
|
||||
private String clientBrowser;
|
||||
|
||||
/**
|
||||
* 客户操作系统
|
||||
*/
|
||||
@TableField("client_os")
|
||||
@ChineseDescription("客户操作系统")
|
||||
private String clientOs;
|
||||
|
||||
/**
|
||||
* 安全日志内容
|
||||
*/
|
||||
@TableField("log_content")
|
||||
@ChineseDescription("安全日志内容")
|
||||
private String logContent;
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package cn.stylefeng.roses.kernel.log.security.enums;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 安全日志异常相关枚举
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@Getter
|
||||
public enum LogSecurityExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 查询结果不存在
|
||||
*/
|
||||
LOG_SECURITY_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
LogSecurityExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package cn.stylefeng.roses.kernel.log.security.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.log.security.entity.LogSecurity;
|
||||
import cn.stylefeng.roses.kernel.log.security.pojo.request.LogSecurityRequest;
|
||||
import cn.stylefeng.roses.kernel.log.security.pojo.response.LogSecurityVo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全日志 Mapper 接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
public interface LogSecurityMapper extends BaseMapper<LogSecurity> {
|
||||
|
||||
/**
|
||||
* 获取自定义查询列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
List<LogSecurityVo> customFindList(@Param("page") Page page, @Param("param")LogSecurityRequest request);
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
<?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="cn.stylefeng.roses.kernel.log.security.mapper.LogSecurityMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.stylefeng.roses.kernel.log.security.entity.LogSecurity">
|
||||
<id column="security_log_id" property="securityLogId" />
|
||||
<result column="request_url" property="requestUrl" />
|
||||
<result column="request_params" property="requestParams" />
|
||||
<result column="server_ip" property="serverIp" />
|
||||
<result column="client_ip" property="clientIp" />
|
||||
<result column="http_method" property="httpMethod" />
|
||||
<result column="client_browser" property="clientBrowser" />
|
||||
<result column="client_os" property="clientOs" />
|
||||
<result column="log_content" property="logContent" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="create_user" property="createUser" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="update_user" property="updateUser" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
security_log_id,request_url,request_params,server_ip,client_ip,http_method,client_browser,client_os,log_content,create_time,create_user,update_time,update_user
|
||||
</sql>
|
||||
|
||||
<resultMap id="customResultMap" type="cn.stylefeng.roses.kernel.log.security.pojo.response.LogSecurityVo" extends="BaseResultMap">
|
||||
</resultMap>
|
||||
|
||||
<select id="customFindList" resultMap="customResultMap">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_log_security tbl
|
||||
WHERE
|
||||
<where>
|
||||
<if test="param.securityLogId != null and param.securityLogId != ''">
|
||||
and tbl.security_log_id like concat('%',#{param.securityLogId},'%')
|
||||
</if>
|
||||
<if test="param.requestUrl != null and param.requestUrl != ''">
|
||||
and tbl.request_url like concat('%',#{param.requestUrl},'%')
|
||||
</if>
|
||||
<if test="param.requestParams != null and param.requestParams != ''">
|
||||
and tbl.request_params like concat('%',#{param.requestParams},'%')
|
||||
</if>
|
||||
<if test="param.serverIp != null and param.serverIp != ''">
|
||||
and tbl.server_ip like concat('%',#{param.serverIp},'%')
|
||||
</if>
|
||||
<if test="param.clientIp != null and param.clientIp != ''">
|
||||
and tbl.client_ip like concat('%',#{param.clientIp},'%')
|
||||
</if>
|
||||
<if test="param.httpMethod != null and param.httpMethod != ''">
|
||||
and tbl.http_method like concat('%',#{param.httpMethod},'%')
|
||||
</if>
|
||||
<if test="param.clientBrowser != null and param.clientBrowser != ''">
|
||||
and tbl.client_browser like concat('%',#{param.clientBrowser},'%')
|
||||
</if>
|
||||
<if test="param.clientOs != null and param.clientOs != ''">
|
||||
and tbl.client_os like concat('%',#{param.clientOs},'%')
|
||||
</if>
|
||||
<if test="param.logContent != null and param.logContent != ''">
|
||||
and tbl.log_content like concat('%',#{param.logContent},'%')
|
||||
</if>
|
||||
<if test="param.createTime != null and param.createTime != ''">
|
||||
and tbl.create_time like concat('%',#{param.createTime},'%')
|
||||
</if>
|
||||
<if test="param.createUser != null and param.createUser != ''">
|
||||
and tbl.create_user like concat('%',#{param.createUser},'%')
|
||||
</if>
|
||||
<if test="param.updateTime != null and param.updateTime != ''">
|
||||
and tbl.update_time like concat('%',#{param.updateTime},'%')
|
||||
</if>
|
||||
<if test="param.updateUser != null and param.updateUser != ''">
|
||||
and tbl.update_user like concat('%',#{param.updateUser},'%')
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,83 @@
|
|||
package cn.stylefeng.roses.kernel.log.security.pojo.request;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全日志封装类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class LogSecurityRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "主键不能为空", groups = {edit.class, delete.class})
|
||||
@ChineseDescription("主键")
|
||||
private Long securityLogId;
|
||||
|
||||
/**
|
||||
* 当前用户请求的url
|
||||
*/
|
||||
@ChineseDescription("当前用户请求的url")
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* http或方法的请求参数体
|
||||
*/
|
||||
@ChineseDescription("http或方法的请求参数体")
|
||||
private String requestParams;
|
||||
|
||||
/**
|
||||
* 当前服务器的ip
|
||||
*/
|
||||
@ChineseDescription("当前服务器的ip")
|
||||
private String serverIp;
|
||||
|
||||
/**
|
||||
* 客户端的ip
|
||||
*/
|
||||
@ChineseDescription("客户端的ip")
|
||||
private String clientIp;
|
||||
|
||||
/**
|
||||
* 请求http方法
|
||||
*/
|
||||
@ChineseDescription("请求http方法")
|
||||
private String httpMethod;
|
||||
|
||||
/**
|
||||
* 客户浏览器标识
|
||||
*/
|
||||
@ChineseDescription("客户浏览器标识")
|
||||
private String clientBrowser;
|
||||
|
||||
/**
|
||||
* 客户操作系统
|
||||
*/
|
||||
@ChineseDescription("客户操作系统")
|
||||
private String clientOs;
|
||||
|
||||
/**
|
||||
* 安全日志内容
|
||||
*/
|
||||
@ChineseDescription("安全日志内容")
|
||||
private String logContent;
|
||||
|
||||
/**
|
||||
* 批量删除用的id集合
|
||||
*/
|
||||
@NotNull(message = "批量删除id集合不能为空", groups = batchDelete.class)
|
||||
@ChineseDescription("批量删除用的id集合")
|
||||
private List<Long> batchDeleteIdList;
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package cn.stylefeng.roses.kernel.log.security.pojo.response;
|
||||
|
||||
import cn.stylefeng.roses.kernel.log.security.entity.LogSecurity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 安全日志返回值封装
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class LogSecurityVo extends LogSecurity {
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package cn.stylefeng.roses.kernel.log.security.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.log.security.entity.LogSecurity;
|
||||
import cn.stylefeng.roses.kernel.log.security.pojo.request.LogSecurityRequest;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全日志服务类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
public interface LogSecurityService extends IService<LogSecurity> {
|
||||
|
||||
/**
|
||||
* 新增安全日志
|
||||
*
|
||||
* @param logSecurityRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
void add(LogSecurityRequest logSecurityRequest);
|
||||
|
||||
/**
|
||||
* 删除安全日志
|
||||
*
|
||||
* @param logSecurityRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
void del(LogSecurityRequest logSecurityRequest);
|
||||
|
||||
/**
|
||||
* 批量删除安全日志
|
||||
*
|
||||
* @param logSecurityRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
void batchDelete(LogSecurityRequest logSecurityRequest);
|
||||
|
||||
/**
|
||||
* 编辑安全日志
|
||||
*
|
||||
* @param logSecurityRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
void edit(LogSecurityRequest logSecurityRequest);
|
||||
|
||||
/**
|
||||
* 查询详情安全日志
|
||||
*
|
||||
* @param logSecurityRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
LogSecurity detail(LogSecurityRequest logSecurityRequest);
|
||||
|
||||
/**
|
||||
* 获取安全日志列表
|
||||
*
|
||||
* @param logSecurityRequest 请求参数
|
||||
* @return List<LogSecurity> 返回结果
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
List<LogSecurity> findList(LogSecurityRequest logSecurityRequest);
|
||||
|
||||
/**
|
||||
* 获取安全日志分页列表
|
||||
*
|
||||
* @param logSecurityRequest 请求参数
|
||||
* @return PageResult<LogSecurity> 返回结果
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
PageResult<LogSecurity> findPage(LogSecurityRequest logSecurityRequest);
|
||||
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
package cn.stylefeng.roses.kernel.log.security.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.log.security.entity.LogSecurity;
|
||||
import cn.stylefeng.roses.kernel.log.security.enums.LogSecurityExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.log.security.mapper.LogSecurityMapper;
|
||||
import cn.stylefeng.roses.kernel.log.security.pojo.request.LogSecurityRequest;
|
||||
import cn.stylefeng.roses.kernel.log.security.service.LogSecurityService;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全日志业务实现层
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
@Service
|
||||
public class LogSecurityServiceImpl extends ServiceImpl<LogSecurityMapper, LogSecurity> implements LogSecurityService {
|
||||
|
||||
@Override
|
||||
public void add(LogSecurityRequest logSecurityRequest) {
|
||||
LogSecurity logSecurity = new LogSecurity();
|
||||
BeanUtil.copyProperties(logSecurityRequest, logSecurity);
|
||||
this.save(logSecurity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void del(LogSecurityRequest logSecurityRequest) {
|
||||
LogSecurity logSecurity = this.queryLogSecurity(logSecurityRequest);
|
||||
this.removeById(logSecurity.getSecurityLogId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchDelete(LogSecurityRequest logSecurityRequest) {
|
||||
this.removeByIds(logSecurityRequest.getBatchDeleteIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(LogSecurityRequest logSecurityRequest) {
|
||||
LogSecurity logSecurity = this.queryLogSecurity(logSecurityRequest);
|
||||
BeanUtil.copyProperties(logSecurityRequest, logSecurity);
|
||||
this.updateById(logSecurity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogSecurity detail(LogSecurityRequest logSecurityRequest) {
|
||||
return this.queryLogSecurity(logSecurityRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<LogSecurity> findPage(LogSecurityRequest logSecurityRequest) {
|
||||
LambdaQueryWrapper<LogSecurity> wrapper = createWrapper(logSecurityRequest);
|
||||
Page<LogSecurity> pageList = this.page(PageFactory.defaultPage(), wrapper);
|
||||
return PageResultFactory.createPageResult(pageList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LogSecurity> findList(LogSecurityRequest logSecurityRequest) {
|
||||
LambdaQueryWrapper<LogSecurity> wrapper = this.createWrapper(logSecurityRequest);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
private LogSecurity queryLogSecurity(LogSecurityRequest logSecurityRequest) {
|
||||
LogSecurity logSecurity = this.getById(logSecurityRequest.getSecurityLogId());
|
||||
if (ObjectUtil.isEmpty(logSecurity)) {
|
||||
throw new ServiceException(LogSecurityExceptionEnum.LOG_SECURITY_NOT_EXISTED);
|
||||
}
|
||||
return logSecurity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建查询wrapper
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/07/11 15:56
|
||||
*/
|
||||
private LambdaQueryWrapper<LogSecurity> createWrapper(LogSecurityRequest logSecurityRequest) {
|
||||
LambdaQueryWrapper<LogSecurity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
Long securityLogId = logSecurityRequest.getSecurityLogId();
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(securityLogId), LogSecurity::getSecurityLogId, securityLogId);
|
||||
|
||||
String requestUrl = logSecurityRequest.getRequestUrl();
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(requestUrl), LogSecurity::getRequestUrl, requestUrl);
|
||||
|
||||
String requestParams = logSecurityRequest.getRequestParams();
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(requestParams), LogSecurity::getRequestParams, requestParams);
|
||||
|
||||
String serverIp = logSecurityRequest.getServerIp();
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(serverIp), LogSecurity::getServerIp, serverIp);
|
||||
|
||||
String clientIp = logSecurityRequest.getClientIp();
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(clientIp), LogSecurity::getClientIp, clientIp);
|
||||
|
||||
String httpMethod = logSecurityRequest.getHttpMethod();
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(httpMethod), LogSecurity::getHttpMethod, httpMethod);
|
||||
|
||||
String clientBrowser = logSecurityRequest.getClientBrowser();
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(clientBrowser), LogSecurity::getClientBrowser, clientBrowser);
|
||||
|
||||
String clientOs = logSecurityRequest.getClientOs();
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(clientOs), LogSecurity::getClientOs, clientOs);
|
||||
|
||||
String logContent = logSecurityRequest.getLogContent();
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(logContent), LogSecurity::getLogContent, logContent);
|
||||
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE `sys_login_log` ADD COLUMN `account` varchar(255) NULL COMMENT '账号' AFTER `user_id`;
|
|
@ -0,0 +1,18 @@
|
|||
ALTER TABLE `sys_login_log` ADD COLUMN `account` varchar(255) NULL COMMENT '账号' AFTER `user_id`;
|
||||
|
||||
CREATE TABLE `sys_log_security` (
|
||||
`security_log_id` bigint NOT NULL COMMENT '主键',
|
||||
`request_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '当前用户请求的url',
|
||||
`request_params` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'http或方法的请求参数体',
|
||||
`server_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '当前服务器的ip',
|
||||
`client_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '客户端的ip',
|
||||
`http_method` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '请求http方法',
|
||||
`client_browser` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '客户浏览器标识',
|
||||
`client_os` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '客户操作系统',
|
||||
`log_content` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '安全日志内容',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
`create_user` bigint DEFAULT NULL COMMENT '创建人',
|
||||
`update_time` datetime DEFAULT NULL COMMENT '修改时间',
|
||||
`update_user` bigint DEFAULT NULL COMMENT '修改人',
|
||||
PRIMARY KEY (`security_log_id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='安全日志';
|
|
@ -20,6 +20,7 @@
|
|||
<module>log-business</module>
|
||||
<module>log-business-login-log</module>
|
||||
<module>log-business-requestapi</module>
|
||||
<module>log-business-security</module>
|
||||
<module>log-spring-boot-starter</module>
|
||||
</modules>
|
||||
|
||||
|
|
Loading…
Reference in New Issue