1.审计用户消息和邮件推送

2.国网上送母线,变电站,主配网监测点统计,典型源荷统计等算法调整
3.国网上送定时任务调整
This commit is contained in:
wr
2024-03-12 14:52:35 +08:00
parent 93f86feb33
commit df07c79ac8
38 changed files with 571 additions and 73 deletions

View File

@@ -1,16 +1,27 @@
package com.njcn.system.handler;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
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.system.service.IUserLogService;
import com.njcn.user.api.UserFeignClient;
import com.njcn.user.pojo.po.User;
import com.njcn.web.utils.EmailUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* @author hongawen
@@ -23,6 +34,8 @@ import java.nio.charset.StandardCharsets;
public class MqttMessageHandler {
private final IUserLogService userLogService;
private final UserFeignClient userFeignClient;
private final EmailUtil emailUtil;
/**
* 订阅审计日志的记录,并进行入库操作
@@ -32,4 +45,35 @@ public class MqttMessageHandler {
LogInfoDTO logInfoDTO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),LogInfoDTO.class);
userLogService.addUserLog(logInfoDTO);
}
/**
* 订阅审计日志的记录,并进行入库操作
*/
@MqttSubscribe(value = "/userLogEmailPush")
public void subUserLogEmail(String topic, MqttMessage message, @Payload String payload) {
LogInfoDTO auditLogVO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),LogInfoDTO.class);
List<User> data = userFeignClient.getUserListByRoleCode("audit_manager").getData();
List<String> emails = data.stream()
.filter(x -> Pattern.matches(PatternRegex.EMAIL_REGEX,x.getEmail()))
.filter(x -> StrUtil.isNotBlank(x.getEmail()) && x.getEmailNotice() == 1)
.map(User::getEmail).collect(Collectors.toList());
if(CollUtil.isNotEmpty(emails)){
StringBuilder describe = new StringBuilder();
describe.append(auditLogVO.getType() == 0 ? "业务事件 -> " : "系统事件 -> ");
describe.append(auditLogVO.getUserName()).append("")
.append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(auditLogVO.getCreateTime()))
.append("")
.append(auditLogVO.getIp())
.append("执行了")
.append(auditLogVO.getOperate())
.append(",结果为");
if (auditLogVO.getResult() == 1) {
describe.append("成功");
}
if (auditLogVO.getResult() == 0) {
describe.append("失败").append(",失败原因为").append(auditLogVO.getFailReason());
}
emailUtil.sendMultiple(emails,"告警消息",describe.toString(),false);
}
}
}

View File

@@ -112,7 +112,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
auditLogVO.setUserName(userLog.getLoginName());
auditLogVO.setOperate(userLog.getOperate());
StringBuilder describe = new StringBuilder();
describe.append(auditLogVO.getUserName()).append("").append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(userLog.getUpdateTime())).append("").append(userLog.getIp()).append("执行了").append(userLog.getOperate()).append(",结果为");
describe.append(auditLogVO.getUserName()).append("").append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(userLog.getUpdateTime())).append("").append(userLog.getIp()).append("执行了").append(userLog.getOperate()).append(",结果为");
if (userLog.getResult() == 1) {
describe.append("成功");
}

View File

@@ -22,11 +22,18 @@ public class PqTypicalSourceTaskMRunner implements TimerTaskRunner {
@Override
public void action(String date) {
//月
UploadParam param=new UploadParam();
param.setTime(DateUtil.yesterday().toString(DatePattern.NORM_MONTH_PATTERN));
String code = pqTypicalSourceFeignClient.send(param).getCode();
if(code.equals("A0002")){
throw new BusinessException("失败");
}
//年
param.setTime(DateUtil.yesterday().toString(DatePattern.NORM_YEAR_PATTERN));
String code2 = pqTypicalSourceFeignClient.send(param).getCode();
if(code2.equals("A0002")){
throw new BusinessException("失败");
}
}
}

View File

@@ -24,11 +24,18 @@ public class UploadGwTaskEvaluationMRunner implements TimerTaskRunner {
@Override
public void action(String date) {
//月
UploadParam param = new UploadParam();
param.setTime(DateUtil.yesterday().toString(DatePattern.NORM_MONTH_PATTERN));
String code = uploadGwDataFeignClient.uploadEvaluationData(param).getCode();
if(code.equals("A0002")){
throw new BusinessException("失败");
}
//年
param.setTime(DateUtil.yesterday().toString(DatePattern.NORM_YEAR_PATTERN));
String code2 = uploadGwDataFeignClient.uploadEvaluationData(param).getCode();
if(code2.equals("A0002")){
throw new BusinessException("失败");
}
}
}

View File

@@ -30,5 +30,11 @@ public class UploadGwTaskMRunner implements TimerTaskRunner {
if(code.equals("A0002")){
throw new BusinessException("失败");
}
//年
param.setTime(DateUtil.yesterday().toString(DatePattern.NORM_YEAR_PATTERN));
String code2 = uploadGwDataFeignClient.uploadPointStatisticalData(param).getCode();
if(code2.equals("A0002")){
throw new BusinessException("失败");
}
}
}

View File

@@ -30,5 +30,11 @@ public class UploadGwTaskSubstationMRunner implements TimerTaskRunner {
if(code.equals("A0002")){
throw new BusinessException("失败");
}
//年
param.setTime(DateUtil.yesterday().toString(DatePattern.NORM_YEAR_PATTERN));
String code2 = uploadGwDataFeignClient.uploadSubstationStatisticalData(param).getCode();
if(code2.equals("A0002")){
throw new BusinessException("失败");
}
}
}