1.审计日志处理2
This commit is contained in:
@@ -61,6 +61,8 @@ public class LogInfoDTO implements Serializable {
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
private Integer roleType;
|
||||
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
@@ -75,4 +77,19 @@ public class LogInfoDTO implements Serializable {
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
public LogInfoDTO(String loginName, String userName, String ip, String operate, String operateType, Integer result, String failReason, Integer level, Integer type, String serviceName, String userIndex, LocalDateTime createTime) {
|
||||
this.loginName = loginName;
|
||||
this.userName = userName;
|
||||
this.ip = ip;
|
||||
this.operate = operate;
|
||||
this.operateType = operateType;
|
||||
this.result = result;
|
||||
this.failReason = failReason;
|
||||
this.level = level;
|
||||
this.type = type;
|
||||
this.serviceName = serviceName;
|
||||
this.userIndex = userIndex;
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,31 @@ public class FileUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件是否为excel格式
|
||||
*
|
||||
* @param fileName 文件名
|
||||
*/
|
||||
public static boolean judgeFileIsZip(String fileName) {
|
||||
// 检查文件名是否为空
|
||||
if (StrUtil.isBlank(fileName)) {
|
||||
return false;
|
||||
}
|
||||
// 获取文件扩展名
|
||||
String fileExtension = getFileExtension(fileName);
|
||||
// 定义支持的文件类型
|
||||
String[] allowedExtensions = {"zip", "rar"};
|
||||
|
||||
// 检查扩展名是否在允许的列表中
|
||||
for (String ext : allowedExtensions) {
|
||||
if (ext.equalsIgnoreCase(fileExtension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从文件名中提取扩展名
|
||||
*
|
||||
|
||||
@@ -34,7 +34,13 @@ public enum RedisKeyEnum {
|
||||
/***
|
||||
* MQ消息key缓存时间,默认72小时 * 60 * 60
|
||||
*/
|
||||
ROCKET_MQ_KEY("ROCKET_MQ", 259200L);
|
||||
ROCKET_MQ_KEY("ROCKET_MQ", 259200L),
|
||||
|
||||
|
||||
/***
|
||||
* 存放用户的角色关系
|
||||
*/
|
||||
USER_ROLE_TYPE_KEY("USER_ROLE_TYPE_KEY", -1L);
|
||||
|
||||
|
||||
private final String key;
|
||||
|
||||
@@ -49,6 +49,7 @@ public class LogServiceImpl implements ILogService {
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
|
||||
/**
|
||||
* 异步记录controller中返回的信息内容
|
||||
*
|
||||
|
||||
@@ -84,6 +84,9 @@ public class UserLog {
|
||||
@ExcelProperty(value = "事件类型")
|
||||
private Integer type;
|
||||
|
||||
@ExcelProperty(value = "日志类型")
|
||||
private Integer roleType;
|
||||
|
||||
/**
|
||||
* 模块名
|
||||
*/
|
||||
|
||||
@@ -3,23 +3,30 @@ package com.njcn.system.handler;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
|
||||
import com.github.tocrhz.mqtt.annotation.Payload;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.common.pojo.dto.LogInfoDTO;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.redis.pojo.enums.RedisKeyEnum;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.service.IUserLogService;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import com.njcn.web.utils.EmailUtil;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.data.redis.core.BoundHashOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -37,12 +44,33 @@ public class MqttMessageHandler {
|
||||
private final UserFeignClient userFeignClient;
|
||||
private final EmailUtil emailUtil;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
|
||||
|
||||
private JSONObject jsonObject = null;
|
||||
/**
|
||||
* 订阅审计日志的记录,并进行入库操作
|
||||
*/
|
||||
@MqttSubscribe(value = "/userLog")
|
||||
public void subUserLog(String topic, MqttMessage message, @Payload String payload) {
|
||||
if(Objects.isNull(jsonObject)){
|
||||
jsonObject = (JSONObject) redisUtil.getObjectByKey(RedisKeyEnum.USER_ROLE_TYPE_KEY.getKey());
|
||||
if(Objects.isNull(jsonObject)){
|
||||
userFeignClient.userRoleList();
|
||||
}
|
||||
}
|
||||
LogInfoDTO logInfoDTO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),LogInfoDTO.class);
|
||||
String loginName = logInfoDTO.getLoginName();
|
||||
if(StrUtil.isNotBlank(loginName) && jsonObject.containsKey(loginName)){
|
||||
if((Integer) jsonObject.get(loginName)==2){
|
||||
logInfoDTO.setRoleType(0);
|
||||
}else {
|
||||
logInfoDTO.setRoleType(1);
|
||||
};
|
||||
}else {
|
||||
logInfoDTO.setRoleType(1);
|
||||
}
|
||||
userLogService.addUserLog(logInfoDTO);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user