清除不必要的代码

This commit is contained in:
2026-03-24 19:57:03 +08:00
parent 37c5e9cbf8
commit fcddc064f6
2 changed files with 114 additions and 114 deletions

View File

@@ -256,8 +256,8 @@ whitelist:
#结束 #结束
- /user-boot/user/listAllUserByDeptId - /user-boot/user/listAllUserByDeptId
- /IndexAnalysis/** - /IndexAnalysis/**
mqtt: #mqtt:
client-id: @artifactId@${random.value} # client-id: @artifactId@${random.value}

View File

@@ -1,112 +1,112 @@
package com.njcn.system.handler; //package com.njcn.system.handler;
//
import cn.hutool.core.collection.CollUtil; //import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; //import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject; //import cn.hutool.json.JSONObject;
import com.github.tocrhz.mqtt.annotation.Payload; //import com.github.tocrhz.mqtt.annotation.Payload;
import com.njcn.common.pojo.constant.LogInfo; //import com.njcn.common.pojo.constant.LogInfo;
import com.njcn.common.pojo.constant.PatternRegex; //import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.common.pojo.dto.LogInfoDTO; //import com.njcn.common.pojo.dto.LogInfoDTO;
import com.njcn.common.utils.PubUtils; //import com.njcn.common.utils.PubUtils;
import com.njcn.redis.pojo.enums.RedisKeyEnum; //import com.njcn.redis.pojo.enums.RedisKeyEnum;
import com.njcn.redis.utils.RedisUtil; //import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.service.IUserLogService; //import com.njcn.system.service.IUserLogService;
import com.njcn.user.api.UserFeignClient; //import com.njcn.user.api.UserFeignClient;
import com.njcn.user.pojo.po.User; //import com.njcn.user.pojo.po.User;
import com.njcn.web.utils.EmailUtil; //import com.njcn.web.utils.EmailUtil;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage; //import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.nio.charset.StandardCharsets; //import java.nio.charset.StandardCharsets;
import java.time.format.DateTimeFormatter; //import java.time.format.DateTimeFormatter;
import java.util.List; //import java.util.List;
import java.util.Objects; //import java.util.Objects;
import java.util.regex.Pattern; //import java.util.regex.Pattern;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* @author hongawen // * @author hongawen
* @version 1.0.0 // * @version 1.0.0
* @date 2022年07月13日 13:35 // * @date 2022年07月13日 13:35
*/ // */
@Slf4j //@Slf4j
@Component //@Component
@RequiredArgsConstructor //@RequiredArgsConstructor
public class MqttMessageHandler { //public class MqttMessageHandler {
//
private final IUserLogService userLogService; // private final IUserLogService userLogService;
private final UserFeignClient userFeignClient; // private final UserFeignClient userFeignClient;
private final EmailUtil emailUtil; // private final EmailUtil emailUtil;
//
private final RedisUtil redisUtil; // private final RedisUtil redisUtil;
//
//
//
//
private JSONObject jsonObject = null; // private JSONObject jsonObject = null;
/** // /**
* 订阅审计日志的记录,并进行入库操作 // * 订阅审计日志的记录,并进行入库操作
*/ // */
// @MqttSubscribe(value = "/userLog") //// @MqttSubscribe(value = "/userLog")
public void subUserLog(String topic, MqttMessage message, @Payload String payload) { // public void subUserLog(String topic, MqttMessage message, @Payload String payload) {
if(Objects.isNull(jsonObject)){ // if(Objects.isNull(jsonObject)){
jsonObject = (JSONObject) redisUtil.getObjectByKey(RedisKeyEnum.USER_ROLE_TYPE_KEY.getKey()); // jsonObject = (JSONObject) redisUtil.getObjectByKey(RedisKeyEnum.USER_ROLE_TYPE_KEY.getKey());
if(Objects.isNull(jsonObject)){ // if(Objects.isNull(jsonObject)){
userFeignClient.userRoleList(); // userFeignClient.userRoleList();
jsonObject = (JSONObject) redisUtil.getObjectByKey(RedisKeyEnum.USER_ROLE_TYPE_KEY.getKey()); // jsonObject = (JSONObject) redisUtil.getObjectByKey(RedisKeyEnum.USER_ROLE_TYPE_KEY.getKey());
} // }
} // }
//
LogInfoDTO logInfoDTO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),LogInfoDTO.class); // LogInfoDTO logInfoDTO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),LogInfoDTO.class);
if(!logInfoDTO.getLoginName().equals(LogInfo.UNKNOWN_USER) && !logInfoDTO.getOperate().equals(LogInfo.UNKNOWN_OPERATE) && !logInfoDTO.getIp().equals(LogInfo.UNKNOWN_IP)){ // if(!logInfoDTO.getLoginName().equals(LogInfo.UNKNOWN_USER) && !logInfoDTO.getOperate().equals(LogInfo.UNKNOWN_OPERATE) && !logInfoDTO.getIp().equals(LogInfo.UNKNOWN_IP)){
if("注销".equals(logInfoDTO.getOperateType()) || "认证".equals(logInfoDTO.getOperateType())){ // if("注销".equals(logInfoDTO.getOperateType()) || "认证".equals(logInfoDTO.getOperateType())){
logInfoDTO.setType(1); // logInfoDTO.setType(1);
}else { // }else {
String loginName = logInfoDTO.getLoginName(); // String loginName = logInfoDTO.getLoginName();
if(StrUtil.isNotBlank(loginName) && jsonObject.containsKey(loginName)){ // if(StrUtil.isNotBlank(loginName) && jsonObject.containsKey(loginName)){
if((Integer) jsonObject.get(loginName)==2){ // if((Integer) jsonObject.get(loginName)==2){
logInfoDTO.setType(0); // logInfoDTO.setType(0);
}else { // }else {
logInfoDTO.setType(1); // logInfoDTO.setType(1);
}; // };
}else { // }else {
logInfoDTO.setType(1); // logInfoDTO.setType(1);
} // }
} // }
userLogService.addUserLog(logInfoDTO); // userLogService.addUserLog(logInfoDTO);
} // }
} // }
//
/** // /**
* 订阅审计日志的记录,并进行入库操作 // * 订阅审计日志的记录,并进行入库操作
*/ // */
// @MqttSubscribe(value = "/userLogEmailPush") //// @MqttSubscribe(value = "/userLogEmailPush")
public void subUserLogEmail(String topic, MqttMessage message, @Payload String payload) { // public void subUserLogEmail(String topic, MqttMessage message, @Payload String payload) {
LogInfoDTO auditLogVO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),LogInfoDTO.class); // LogInfoDTO auditLogVO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),LogInfoDTO.class);
List<User> data = userFeignClient.getUserListByRoleCode("audit_manager").getData(); // List<User> data = userFeignClient.getUserListByRoleCode("audit_manager").getData();
List<String> emails = data.stream() // List<String> emails = data.stream()
.filter(x -> Pattern.matches(PatternRegex.EMAIL_REGEX,x.getEmail())) // .filter(x -> Pattern.matches(PatternRegex.EMAIL_REGEX,x.getEmail()))
.filter(x -> StrUtil.isNotBlank(x.getEmail()) && x.getEmailNotice() == 1) // .filter(x -> StrUtil.isNotBlank(x.getEmail()) && x.getEmailNotice() == 1)
.map(User::getEmail).collect(Collectors.toList()); // .map(User::getEmail).collect(Collectors.toList());
if(CollUtil.isNotEmpty(emails)){ // if(CollUtil.isNotEmpty(emails)){
StringBuilder describe = new StringBuilder(); // StringBuilder describe = new StringBuilder();
describe.append(auditLogVO.getType() == 0 ? "业务事件 -> " : "系统事件 -> "); // describe.append(auditLogVO.getType() == 0 ? "业务事件 -> " : "系统事件 -> ");
describe.append(auditLogVO.getUserName()).append("") // describe.append(auditLogVO.getUserName()).append("在")
.append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(auditLogVO.getCreateTime())) // .append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(auditLogVO.getCreateTime()))
.append("") // .append("在")
.append(auditLogVO.getIp()) // .append(auditLogVO.getIp())
.append("执行了") // .append("执行了")
.append(auditLogVO.getOperate()) // .append(auditLogVO.getOperate())
.append(",结果为"); // .append(",结果为");
if (auditLogVO.getResult() == 1) { // if (auditLogVO.getResult() == 1) {
describe.append("成功"); // describe.append("成功");
} // }
if (auditLogVO.getResult() == 0) { // if (auditLogVO.getResult() == 0) {
describe.append("失败").append(",失败原因为").append(auditLogVO.getFailReason()); // describe.append("失败").append(",失败原因为").append(auditLogVO.getFailReason());
} // }
emailUtil.sendMultiple(emails,"告警消息",describe.toString(),false); // emailUtil.sendMultiple(emails,"告警消息",describe.toString(),false);
} // }
} // }
} //}