This commit is contained in:
2025-07-01 21:00:38 +08:00
parent a4edf8b3f6
commit 9c02a7cb8e
5 changed files with 152 additions and 34 deletions

View File

@@ -1,7 +1,11 @@
package com.njcn.gather.event.transientes.controller; package com.njcn.gather.event.transientes.controller;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.pojo.annotation.OperateInfo; import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
@@ -14,10 +18,9 @@ import com.njcn.gather.event.devcie.pojo.po.PqsDeptsline;
import com.njcn.gather.event.devcie.service.PqsDeptslineService; import com.njcn.gather.event.devcie.service.PqsDeptslineService;
import com.njcn.gather.event.transientes.pojo.param.MonitorTerminalParam; import com.njcn.gather.event.transientes.pojo.param.MonitorTerminalParam;
import com.njcn.gather.event.transientes.pojo.param.SimulationMsgParam; import com.njcn.gather.event.transientes.pojo.param.SimulationMsgParam;
import com.njcn.gather.event.transientes.pojo.po.PqsDepts; import com.njcn.gather.event.transientes.pojo.po.*;
import com.njcn.gather.event.transientes.pojo.po.PqsUser;
import com.njcn.gather.event.transientes.pojo.po.PqsUserSet;
import com.njcn.gather.event.transientes.service.*; import com.njcn.gather.event.transientes.service.*;
import com.njcn.gather.event.transientes.service.impl.MsgEventInfoServiceImpl;
import com.njcn.gather.event.transientes.websocket.WebSocketServer; import com.njcn.gather.event.transientes.websocket.WebSocketServer;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil; import com.njcn.web.utils.HttpResultUtil;
@@ -33,9 +36,10 @@ import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.HashSet; import java.time.LocalDate;
import java.util.List; import java.time.LocalDateTime;
import java.util.Set; import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -50,6 +54,7 @@ import java.util.stream.Stream;
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
public class EventGateController extends BaseController { public class EventGateController extends BaseController {
private final MsgEventInfoServiceImpl msgEventInfoServiceImpl;
@Value("${SYS_TYPE_ZT}") @Value("${SYS_TYPE_ZT}")
private String sysTypeZt; private String sysTypeZt;
@@ -69,6 +74,9 @@ public class EventGateController extends BaseController {
private final MsgEventConfigService msgEventConfigService; private final MsgEventConfigService msgEventConfigService;
private final PqsEventdetailService pqsEventdetailService;
private final MsgEventInfoService msgEventInfoService;
@OperateInfo @OperateInfo
@@ -76,27 +84,106 @@ public class EventGateController extends BaseController {
@ApiOperation("接收远程推送的暂态事件") @ApiOperation("接收远程推送的暂态事件")
@ApiImplicitParam(name = "eventMsg", value = "暂态事件json字符", required = true) @ApiImplicitParam(name = "eventMsg", value = "暂态事件json字符", required = true)
public HttpResult<Object> eventMsg(@RequestParam("msg") String msg) { public HttpResult<Object> eventMsg(@RequestParam("msg") String msg) {
System.out.println(msg);
String methodDescribe = getMethodDescribe("eventMsg"); String methodDescribe = getMethodDescribe("eventMsg");
System.out.println(msg);
JSONObject jsonObject; JSONObject jsonObject;
try { try {
jsonObject = new JSONObject(msg); //下面一行代码正式环境需要放开
if(msgEventConfigService.getEventType().contains(jsonObject.get("wavetype").toString()) ){ //jsonObject = new JSONObject(msg);
webSocketServer.sendMessageToAll(msg); //下面一行代码正式环境需要放开
jsonObject = test();
if (msgEventConfigService.getEventType().contains(jsonObject.get("wavetype").toString())) {
webSocketServer.sendMessageToAll(jsonObject.toString());
} }
//开始发送短信 //开始发送短信
// sendMessage(jsonObject); sendMessage(jsonObject);
}catch (Exception e){ } catch (Exception e) {
log.error("暂降json格式异常!{}",e.getMessage()); log.error("暂降json格式异常!{}", e.getMessage());
} }
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
//测试模拟,正式环境删除
private PqsEventdetail createEvent(JSONObject jsonObject, LocalDateTime now) {
PqsEventdetail pqsEventdetail = new PqsEventdetail();
pqsEventdetail.setEventdetailIndex(jsonObject.get("eventdetail_index").toString());
pqsEventdetail.setLineid(Integer.valueOf(jsonObject.get("lineid").toString()));
pqsEventdetail.setTimeid(now);
pqsEventdetail.setMs(new BigDecimal(jsonObject.get("ms").toString()));
pqsEventdetail.setWavetype(Integer.valueOf(jsonObject.get("wavetype").toString()));
pqsEventdetail.setPersisttime(Double.valueOf(jsonObject.get("persisttime").toString()));
pqsEventdetail.setEventvalue(Double.valueOf(jsonObject.get("eventvalue").toString()));
pqsEventdetail.setEventreason(jsonObject.get("eventreason").toString());
pqsEventdetail.setEventtype(jsonObject.get("eventtype").toString());
return pqsEventdetail;
}
//测试模拟,正式环境删除
private JSONObject test() {
/*----------------------------------------------------------------------------------------*/
//以下部分为测试数据后续删除
List<PqLine> pqLineList = pqLineMapper.selectList(new LambdaQueryWrapper<>());
List<Integer> lineList = pqLineList.stream().map(PqLine::getLineIndex).collect(Collectors.toList());
List<LedgerBaseInfoDTO> baseInfoDTOList = pqLineMapper.getBaseLineInfo(lineList);
Map<Integer, LedgerBaseInfoDTO> map = baseInfoDTOList.stream().collect(Collectors.toMap(LedgerBaseInfoDTO::getLineId, Function.identity()));
Random random = new Random();
Integer lineId = lineList.get(random.nextInt(lineList.size()));
LedgerBaseInfoDTO dto = map.get(lineId);
LocalDateTime now = LocalDateTime.now();
String timeStr = DateUtil.format(now, DatePattern.NORM_DATETIME_PATTERN);
Long ms = (long) random.nextInt(999);
Integer[] temArr = new Integer[]{1, 3};
Integer wave = random.nextInt(2);
double min = 0.5;
double max = 10.0;
// 生成 (0.5, 10.0) 范围内的随机小数
Double perTem = min + (max - min) * Math.random();
Double per = new BigDecimal(perTem).setScale(2, RoundingMode.HALF_UP).doubleValue();
double minV = 0.1;
double maxV = 0.9;
Double eventValue = minV + (maxV - minV) * Math.random();
String id = IdUtil.simpleUUID();
JSONObject tem = new JSONObject();
tem.set("eventdetail_index", id);
tem.set("lineid", lineId.toString());
tem.set("timeid", timeStr);
tem.set("ms", ms.toString());
tem.set("wavetype", temArr[wave]);
tem.set("persisttime", per.toString());
tem.set("eventvalue", eventValue);
tem.set("eventreason", "97a56e0f-b546-4c1e-b27c-52463fc1d82f");
tem.set("eventtype", "676683a0-7f80-43e6-8df8-bea8ed235d67");
tem.set("gdname", "测试供电公司");
tem.set("bdname", dto.getStationName());
tem.set("pointname", dto.getLineName());
PqsEventdetail pqsEventdetail = createEvent(tem, now);
if (msgEventConfigService.getEventType().contains(tem.get("wavetype").toString())) {
webSocketServer.sendMessageToAll(tem.toString());
}
pqsEventdetailService.save(pqsEventdetail);
/*----------------------------------------------------------------------------------------*/
return tem;
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON) @OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getTransientAnalyseWave") @PostMapping("/getTransientAnalyseWave")
@ApiOperation("暂态事件波形分析") @ApiOperation("暂态事件波形分析")
public HttpResult<WaveDataDTO> getTransientAnalyseWave(@RequestBody MonitorTerminalParam param){ public HttpResult<WaveDataDTO> getTransientAnalyseWave(@RequestBody MonitorTerminalParam param) {
String methodDescribe = getMethodDescribe("getTransientAnalyseWave"); String methodDescribe = getMethodDescribe("getTransientAnalyseWave");
WaveDataDTO wave = eventGateService.getTransientAnalyseWave(param); WaveDataDTO wave = eventGateService.getTransientAnalyseWave(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, wave, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, wave, methodDescribe);
@@ -106,29 +193,27 @@ public class EventGateController extends BaseController {
@OperateInfo(info = LogEnum.BUSINESS_COMMON) @OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/simulationSend") @PostMapping("/simulationSend")
@ApiOperation("模拟发送短信") @ApiOperation("模拟发送短信")
public HttpResult<WaveDataDTO> simulationSend(@RequestBody @Validated SimulationMsgParam param){ public HttpResult<WaveDataDTO> simulationSend(@RequestBody @Validated SimulationMsgParam param) {
String methodDescribe = getMethodDescribe("simulationSend"); String methodDescribe = getMethodDescribe("simulationSend");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
private void sendMessage(JSONObject jsonObject) {
private void sendMessage(JSONObject jsonObject){
Integer lineId = Integer.valueOf(jsonObject.get("lineid").toString()); Integer lineId = Integer.valueOf(jsonObject.get("lineid").toString());
List<PqsDeptsline> pqLineDept = pqsDeptslineService.lambdaQuery().eq(PqsDeptsline::getLineIndex,lineId).eq(PqsDeptsline::getSystype,sysTypeZt).list(); List<PqsDeptsline> pqLineDept = pqsDeptslineService.lambdaQuery().eq(PqsDeptsline::getLineIndex, lineId).eq(PqsDeptsline::getSystype, sysTypeZt).list();
Set<String> deptIds = pqLineDept.stream().map(PqsDeptsline::getDeptsIndex).collect(Collectors.toSet()); Set<String> deptIds = pqLineDept.stream().map(PqsDeptsline::getDeptsIndex).collect(Collectors.toSet());
Set<String> resultIds = getAllParentDeptIds(deptIds); Set<String> resultIds = getAllParentDeptIds(deptIds);
List<PqsUserSet> pqsUserSetList = pqsUsersetService.lambdaQuery().eq(PqsUserSet::getIsNotice,1).in(PqsUserSet::getDeptsIndex,resultIds).list(); List<PqsUserSet> pqsUserSetList = pqsUsersetService.lambdaQuery().eq(PqsUserSet::getIsNotice, 1).in(PqsUserSet::getDeptsIndex, resultIds).list();
if(CollUtil.isEmpty(pqsUserSetList)){ if (CollUtil.isEmpty(pqsUserSetList)) {
//当前事件未找到用户信息,判断为不需要发送短信用户 //当前事件未找到用户信息,判断为不需要发送短信用户
return; return;
} }
List<PqsUser> pqsUserList = pqsUserService.lambdaQuery().select(PqsUser::getUserIndex).in(PqsUser::getUserIndex,pqsUserSetList.stream().map(PqsUserSet::getUserIndex).collect(Collectors.toList())).list(); List<PqsUser> pqsUserList = pqsUserService.lambdaQuery().select(PqsUser::getUserIndex,PqsUser::getPhone,PqsUser::getName).in(PqsUser::getUserIndex, pqsUserSetList.stream().map(PqsUserSet::getUserIndex).collect(Collectors.toList())).list();
List<String> userIds = pqsUserList.stream().map(PqsUser::getUserIndex).collect(Collectors.toList()); List<String> userIds = pqsUserList.stream().map(PqsUser::getUserIndex).collect(Collectors.toList());
List<PqsUserSet> poList = pqsUserSetList.stream().filter(it->userIds.contains(it.getUserIndex())).collect(Collectors.toList()); List<PqsUserSet> poList = pqsUserSetList.stream().filter(it -> userIds.contains(it.getUserIndex())).collect(Collectors.toList());
if(CollUtil.isNotEmpty(poList)){ if (CollUtil.isNotEmpty(poList)) {
StringBuilder stringBuilder = new StringBuilder(jsonObject.get("timeid").toString()); StringBuilder stringBuilder = new StringBuilder(jsonObject.get("timeid").toString());
List<LedgerBaseInfoDTO> list = pqLineMapper.getBaseLineInfo(Stream.of(lineId).collect(Collectors.toList())); List<LedgerBaseInfoDTO> list = pqLineMapper.getBaseLineInfo(Stream.of(lineId).collect(Collectors.toList()));
LedgerBaseInfoDTO ledgerBaseInfoDTO = list.get(0); LedgerBaseInfoDTO ledgerBaseInfoDTO = list.get(0);
@@ -136,8 +221,36 @@ public class EventGateController extends BaseController {
stringBuilder.append(".").append(jsonObject.get("ms").toString()).append(", ").append(ledgerBaseInfoDTO.getStationName()).append(ledgerBaseInfoDTO.getLineName()) stringBuilder.append(".").append(jsonObject.get("ms").toString()).append(", ").append(ledgerBaseInfoDTO.getStationName()).append(ledgerBaseInfoDTO.getLineName())
.append("发生暂降事件,事件特征幅值").append(bigDecimal).append("%,持续时间:").append(jsonObject.get("persisttime").toString()).append("S"); .append("发生暂降事件,事件特征幅值").append(bigDecimal).append("%,持续时间:").append(jsonObject.get("persisttime").toString()).append("S");
//TODO 发送短信 //TODO 发送短信
System.out.println(stringBuilder); // System.out.println(stringBuilder);
List<MsgEventInfo> resultList = new ArrayList<>();
for (PqsUser user : pqsUserList) {
MsgEventInfo msgEventInfo = new MsgEventInfo();
msgEventInfo.setEventIndex(jsonObject.get("eventdetail_index").toString());
msgEventInfo.setMsgContent(stringBuilder.toString());
msgEventInfo.setMsgIndex(IdUtil.simpleUUID());
msgEventInfo.setPhone(user.getPhone());
msgEventInfo.setSendResult(0);
msgEventInfo.setUserId(user.getUserIndex());
msgEventInfo.setUserName(user.getName());
msgEventInfo.setIsHandle(0);
msgEventInfo.setSendTime(LocalDateTime.now());
resultList.add(msgEventInfo);
} }
msgEventInfoService.saveBatch(resultList);
}
}
/**
* 获取远程短信平台token
*/
private String apiToken() {
return "token";
}
private boolean apiSend(){
return false;
} }
@@ -145,27 +258,28 @@ public class EventGateController extends BaseController {
// 首次获取直接父级 // 首次获取直接父级
List<PqsDepts> allDeptList = pqsDeptsService.lambdaQuery().list(); List<PqsDepts> allDeptList = pqsDeptsService.lambdaQuery().list();
// 递归获取所有父级 // 递归获取所有父级
Set<String> result = recursivelyGetParentIds(deptIds,allDeptList); Set<String> result = recursivelyGetParentIds(deptIds, allDeptList);
return result; return result;
} }
/** /**
* 递归获取所有父级ID * 递归获取所有父级ID
*
* @param currentParentIds 当前层级的父级ID集合 * @param currentParentIds 当前层级的父级ID集合
* @return 所有层级的父级ID集合 * @return 所有层级的父级ID集合
*/ */
private Set<String> recursivelyGetParentIds(Set<String> currentParentIds,List<PqsDepts> allDeptList) { private Set<String> recursivelyGetParentIds(Set<String> currentParentIds, List<PqsDepts> allDeptList) {
Set<String> result = new HashSet<>(currentParentIds); Set<String> result = new HashSet<>(currentParentIds);
Set<String> nextLevelParentIds = new HashSet<>(); Set<String> nextLevelParentIds = new HashSet<>();
List<PqsDepts> parentDeptList = allDeptList.stream().filter(it->currentParentIds.contains(it.getDeptsIndex())).collect(Collectors.toList()); List<PqsDepts> parentDeptList = allDeptList.stream().filter(it -> currentParentIds.contains(it.getDeptsIndex())).collect(Collectors.toList());
for(PqsDepts pqsDepts: parentDeptList){ for (PqsDepts pqsDepts : parentDeptList) {
if(!pqsDepts.getParentnodeid().equals("0")){ if (!pqsDepts.getParentnodeid().equals("0")) {
nextLevelParentIds.add(pqsDepts.getParentnodeid()); nextLevelParentIds.add(pqsDepts.getParentnodeid());
} }
} }
// 如果有更高层级的父级,继续递归 // 如果有更高层级的父级,继续递归
if (!nextLevelParentIds.isEmpty()) { if (!nextLevelParentIds.isEmpty()) {
Set<String> deeperParentIds = recursivelyGetParentIds(nextLevelParentIds,allDeptList); Set<String> deeperParentIds = recursivelyGetParentIds(nextLevelParentIds, allDeptList);
result.addAll(deeperParentIds); result.addAll(deeperParentIds);
} }
return result; return result;

View File

@@ -45,11 +45,11 @@ public class JwtRequestFilter extends OncePerRequestFilter {
try { try {
username = jwtUtil.extractUsername(jwt); username = jwtUtil.extractUsername(jwt);
} catch (ExpiredJwtException e) { } catch (ExpiredJwtException e) {
e.printStackTrace(); // e.printStackTrace();
sendErrorResponse(response,CommonResponseEnum.TOKEN_EXPIRE_JWT); sendErrorResponse(response,CommonResponseEnum.TOKEN_EXPIRE_JWT);
return; return;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
sendErrorResponse(response,CommonResponseEnum.PARSE_TOKEN_ERROR); sendErrorResponse(response,CommonResponseEnum.PARSE_TOKEN_ERROR);
return; return;
} }

View File

@@ -6,6 +6,7 @@ package com.njcn.gather.event.transientes.pojo.po;
* @Description: 暂降远程通知反馈 * @Description: 暂降远程通知反馈
*/ */
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
@@ -23,6 +24,7 @@ public class MessageEventFeedback {
private String influenceFactors; private String influenceFactors;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date dealDate; private Date dealDate;
private String dealScheme; private String dealScheme;

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.event.transientes.pojo.vo; package com.njcn.gather.event.transientes.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.njcn.gather.event.transientes.pojo.po.MsgEventInfo; import com.njcn.gather.event.transientes.pojo.po.MsgEventInfo;
import lombok.Data; import lombok.Data;
@@ -20,6 +21,7 @@ public class EventMsgDetailVO {
private String influenceFactors; private String influenceFactors;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date dealDate; private Date dealDate;
private String dealScheme; private String dealScheme;

View File

@@ -35,7 +35,7 @@ public class AuthController extends BaseController {
@ApiOperation("登录认证") @ApiOperation("登录认证")
public HttpResult<AuthResponse> createAuthenticationToken(@RequestBody AuthRequest authRequest) { public HttpResult<AuthResponse> createAuthenticationToken(@RequestBody AuthRequest authRequest) {
String methodDescribe = getMethodDescribe("createAuthenticationToken"); String methodDescribe = getMethodDescribe("createAuthenticationToken");
log.info("Authentication request - username: {}, password: {}",authRequest.getUsername(),authRequest.getPassword()); //log.info("Authentication request - username: {}, password: {}",authRequest.getUsername(),authRequest.getPassword());
try { try {
// 执行认证,内部会调用 UserDetailsService 加载用户信息 // 执行认证,内部会调用 UserDetailsService 加载用户信息
Authentication authentication = authenticationManager.authenticate( Authentication authentication = authenticationManager.authenticate(