审计日志相关代码提交
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.njcn.system.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||
import com.njcn.system.api.fallback.UserLogFeignClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年07月12日 15:20
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SYSTEM,path = "/userLog",fallbackFactory = UserLogFeignClientFallbackFactory.class)
|
||||
public interface UserLogFeignClient {
|
||||
|
||||
/**
|
||||
* 插入审计日志
|
||||
* @param logInfoDTO 日志详细信息
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
void addUserLog(@RequestBody LogInfoDTO logInfoDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.njcn.system.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.AreaFeignClient;
|
||||
import com.njcn.system.api.UserLogFeignClient;
|
||||
import com.njcn.system.pojo.dto.AreaTreeDTO;
|
||||
import com.njcn.system.pojo.po.Area;
|
||||
import com.njcn.system.utils.SystemEnumUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年07月12日 15:21
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class UserLogFeignClientFallbackFactory implements FallbackFactory<UserLogFeignClient> {
|
||||
|
||||
/**
|
||||
* 输出远程请求接口异常日志
|
||||
* @param cause RPC请求异常
|
||||
*/
|
||||
@Override
|
||||
public UserLogFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new UserLogFeignClient() {
|
||||
@Override
|
||||
public void addUserLog(LogInfoDTO logInfoDTO) {
|
||||
log.error("{}异常,降级处理,异常为:{}","插入审计日志",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.njcn.system.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年07月12日 14:45
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_user_log")
|
||||
public class UserLog extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 事件日志Id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 用户已登录:用户名
|
||||
* 用户未登录:登录名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 操作Ip
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 操作内容
|
||||
*/
|
||||
private String operate;
|
||||
|
||||
/**
|
||||
* 操作类型 比如:查询、新增、删除等等
|
||||
*/
|
||||
private String operateType;
|
||||
|
||||
/**
|
||||
* 操作结果 0.失败 1.成功
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 严重度 0.普通 1.中等 2.严重
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 事件类型 0.业务事件 1.系统事件
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 模块名
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.njcn.system.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.system.pojo.po.Area;
|
||||
import com.njcn.system.service.IUserLogService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器(行政区域)
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/userLog")
|
||||
@Api(tags = "行政区域管理")
|
||||
@AllArgsConstructor
|
||||
public class UserLogController extends BaseController {
|
||||
|
||||
private final IUserLogService userLogService;
|
||||
|
||||
|
||||
/**
|
||||
* 插入审计日志
|
||||
*/
|
||||
@ApiIgnore
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("插入审计日志")
|
||||
public void addUserLog(@RequestBody LogInfoDTO logInfoDTO) {
|
||||
|
||||
System.out.println(logInfoDTO.toString());
|
||||
|
||||
// userLogService.addUserLog(logInfoDTO);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.system.pojo.dto.AreaTreeDTO;
|
||||
import com.njcn.system.pojo.po.Area;
|
||||
import com.njcn.system.pojo.po.UserLog;
|
||||
import com.njcn.system.pojo.vo.AreaTreeVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
public interface UserLogMapper extends BaseMapper<UserLog> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?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.njcn.system.mapper.UserLogMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||
import com.njcn.system.pojo.po.UserLog;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
public interface IUserLogService extends IService<UserLog> {
|
||||
|
||||
/**
|
||||
* 插入审计日志
|
||||
* @param logInfoDTO .
|
||||
*/
|
||||
void addUserLog(LogInfoDTO logInfoDTO);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||
import com.njcn.system.mapper.UserLogMapper;
|
||||
import com.njcn.system.pojo.po.UserLog;
|
||||
import com.njcn.system.service.IUserLogService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2021-12-13
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class UserLogServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements IUserLogService {
|
||||
|
||||
|
||||
@Override
|
||||
public void addUserLog(LogInfoDTO logInfoDTO) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user