1.灿能云实时信息,部分接口调整

2.消息推送接口编写,定时推送接口编写
This commit is contained in:
wr
2023-11-17 16:24:43 +08:00
parent ec073555ab
commit 44832df878
5 changed files with 590 additions and 160 deletions

View File

@@ -1,137 +1,92 @@
//package com.njcn.cloud.controller.message; package com.njcn.cloud.controller.message;
//
//import com.njcn.enums.app.ReturnCode; import cn.hutool.core.util.StrUtil;
//import com.njcn.enums.app.UserCodeEnum; import com.njcn.cloud.enums.app.UserCodeEnum;
//import com.njcn.pojo.commons.ResponseData; import com.njcn.cloud.service.user.MsgService;
//import com.njcn.utils.PubUtils; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
//import com.shining.cloud.service.information.EventMsgService; import com.njcn.common.pojo.exception.BusinessException;
//import io.swagger.annotations.Api; import com.njcn.common.pojo.response.HttpResult;
//import io.swagger.annotations.ApiImplicitParam; import com.njcn.common.utils.HttpResultUtil;
//import io.swagger.annotations.ApiImplicitParams; import com.njcn.web.controller.BaseController;
//import io.swagger.annotations.ApiOperation; import io.swagger.annotations.Api;
//import net.sf.json.JSONObject; import io.swagger.annotations.ApiImplicitParam;
//import org.slf4j.Logger; import io.swagger.annotations.ApiImplicitParams;
//import org.slf4j.LoggerFactory; import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired; import lombok.RequiredArgsConstructor;
//import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletRequest;
// /**
// * @author hongawen
///** * @date: 2019/11/11 14:51
// * @author hongawen */
// * @date: 2019/11/11 14:51 @RestController
// */ @RequestMapping("/msg")
//@RestController @Api(tags = "内部消息推送")
//@RequestMapping("/msg") @RequiredArgsConstructor
//@Api(tags = "内部消息推送") public class EventMsgPushController extends BaseController {
//public class EventMsgPushController {
// private final MsgService msgService;
// private static final Logger logger = LoggerFactory.getLogger(EventMsgPushController.class);
// /**
// @Autowired * 暂态消息推送
// private EventMsgService eventMsgService; */
// @PostMapping("/sendEventMsg")
// @ApiImplicitParams({
// /** @ApiImplicitParam(name = "eventDetailIndex", value = "暂降索引", required = true, paramType = "query"),
// * 暂态消息推送 @ApiImplicitParam(name = "lineId", value = "监测点索引", required = true, paramType = "query"),
// */ })
// @PostMapping("sendEventMsg") @ApiOperation(value = "暂态消息推送", notes = "暂态消息推送")
// @ApiImplicitParams({ public HttpResult<Boolean> sendEventMsg(String eventDetailIndex, String lineId) throws Exception {
// @ApiImplicitParam(name = "eventDetailIndex", value = "暂降索引", required = true, paramType = "query"), String methodDescribe = getMethodDescribe("sendEventMsg");
// @ApiImplicitParam(name = "lineId", value = "监测点索引", required = true, paramType = "query"), if (StrUtil.isNotBlank(eventDetailIndex) || StrUtil.isNotBlank(lineId)) {
// }) throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg());
// @ApiOperation(value = "暂态消息推送", notes = "暂态消息推送", response = ResponseData.class) }
// public ResponseData sendEventMsg(String eventDetailIndex, int lineId, HttpServletRequest request) { msgService.sendEventMsg(eventDetailIndex, lineId);
// logger.error("推送暂降事件:事件索引:{},监测点ID为{}",eventDetailIndex,lineId); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
// ResponseData responseData; }
// if (StringUtils.isEmpty(eventDetailIndex) || StringUtils.isEmpty(lineId)) {
// return PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.INVALID_PARAMETER.getCode(), UserCodeEnum.INVALID_PARAMETER.getMsg(), null); /**
// } * 稳态消息推送
// try { */
// eventMsgService.sendEventMsg(eventDetailIndex, lineId,request); @PostMapping("/sendSteadyMsg")
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_SUCCESS, UserCodeEnum.EVENT_MSG_SUCCESS.getCode(), UserCodeEnum.EVENT_MSG_SUCCESS.getMsg(), null); @ApiImplicitParams({
// } catch (Exception e) { @ApiImplicitParam(name = "userIndex", value = "用户索引", required = true, paramType = "query"),
// logger.error("暂降消息推送,异常为:" + e.getMessage()); @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"),
// if (e.getMessage().length() < 10) { @ApiImplicitParam(name = "lineNum", value = "监测点个数", required = true, paramType = "query"),
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.getCodeByMsg(e.getMessage()), e.getMessage(), null); })
// } else { @ApiOperation(value = "稳态消息推送", notes = "稳态消息推送")
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.EVENT_MSG_FAIL.getCode(), UserCodeEnum.EVENT_MSG_FAIL.getMsg(), null); public HttpResult<Boolean> sendSteadyMsg(String userIndex, String timeID, Integer lineNum) {
// } String methodDescribe = getMethodDescribe("sendSteadyMsg");
// } if (StrUtil.isNotBlank(userIndex) || StrUtil.isNotBlank(userIndex)) {
// return responseData; throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg());
// } }
// msgService.sendSteadyMsg(userIndex, timeID, lineNum);
// /** return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
// * 稳态消息推送 }
// */
// @PostMapping("sendSteadyMsg")
// @ApiImplicitParams({ /**
// @ApiImplicitParam(name = "userIndex", value = "用户索引", required = true, paramType = "query"), * 终端消息推送
// @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"), */
// @ApiImplicitParam(name = "lineNum", value = "监测点个数", required = true, paramType = "query"), @PostMapping("/sendTargetMsg")
// }) @ApiImplicitParams({
// @ApiOperation(value = "稳态消息推送", notes = "稳态消息推送", response = ResponseData.class) @ApiImplicitParam(name = "userIndex", value = "用户索引", required = true, paramType = "query"),
// public ResponseData sendSteadyMsg(String userIndex, Long timeID, Integer lineNum) { @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"),
// ResponseData responseData; @ApiImplicitParam(name = "topID", value = "终点消息id", required = true, paramType = "query"),
// logger.error("稳态消息推送:用户索引:{},统计时间:{},监测点个数:{}",userIndex,timeID,lineNum); @ApiImplicitParam(name = "flag", value = "强制推送标志", required = true, paramType = "query"),
// if (StringUtils.isEmpty(userIndex) || StringUtils.isEmpty(timeID) || StringUtils.isEmpty(lineNum)) { })
// return PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.INVALID_PARAMETER.getCode(), UserCodeEnum.INVALID_PARAMETER.getMsg(), null); @ApiOperation(value = "终端消息推送", notes = "终端消息推送")
// } public HttpResult<Boolean> sendTargetMsg(String userIndex, String timeID, String topID, int flag) {
// try { String methodDescribe = getMethodDescribe("sendTargetMsg");
// String msgIndex = eventMsgService.sendSteadyMsg(userIndex, timeID, lineNum); if (StrUtil.isNotBlank(userIndex) || StrUtil.isNotBlank(userIndex)) {
// JSONObject jsonObject = new JSONObject(); throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg());
// jsonObject.put("msgIndex", msgIndex); }
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_SUCCESS, UserCodeEnum.STEADY_MSG_SUCCESS.getCode(), UserCodeEnum.STEADY_MSG_SUCCESS.getMsg(), jsonObject); msgService.sendTargetMsg(userIndex, timeID, topID, flag);
// } catch (Exception e) { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
// logger.error("稳态消息推送,异常为:" + e.getMessage()); }
// if (e.getMessage().length() < 10) {
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.getCodeByMsg(e.getMessage()), e.getMessage(), null); }
// } else {
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.STEADY_MSG_FAIL.getCode(), UserCodeEnum.STEADY_MSG_FAIL.getMsg(), null);
// }
// }
// return responseData;
// }
//
//
// /**
// * 终端消息推送
// */
// @PostMapping("sendTargetMsg")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "userIndex", value = "用户索引", required = true, paramType = "query"),
// @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"),
// @ApiImplicitParam(name = "devNum", value = "终端个数", required = true, paramType = "query"),
// @ApiImplicitParam(name = "alarmNum", value = "终端警告次数", paramType = "query"),
// @ApiImplicitParam(name = "comOutNum", value = "通讯状态", paramType = "query"),
// @ApiImplicitParam(name = "flowNum", value = "流量百分比", paramType = "query"),
// @ApiImplicitParam(name = "flag", value = "强制推送标志",required = true, paramType = "query"),
// })
// @ApiOperation(value = "终端消息推送", notes = "终端消息推送", response = ResponseData.class)
// public ResponseData sendTargetMsg(String userIndex, Long timeID,Integer devNum, Integer alarmNum, Integer comOutNum, Float flowNum, int flag) {
// logger.error("稳态消息推送:用户索引:{},统计时间:{},终端个数:{}",userIndex,timeID,devNum);
// ResponseData responseData;
// if (StringUtils.isEmpty(userIndex) || StringUtils.isEmpty(timeID) || StringUtils.isEmpty(flag)) {
// return PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.INVALID_PARAMETER.getCode(), UserCodeEnum.INVALID_PARAMETER.getMsg(), null);
// }
// try {
// String msgIndex = eventMsgService.sendTargetMsg(userIndex, timeID, devNum,alarmNum,comOutNum,flowNum,flag);
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("msgIndex", msgIndex);
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_SUCCESS, UserCodeEnum.DEVICE_MSG_SUCCESS.getCode(), UserCodeEnum.DEVICE_MSG_SUCCESS.getMsg(), jsonObject);
// } catch (Exception e) {
// logger.error("终端消息推送,异常为:" + e.getMessage());
// if (e.getMessage().length() < 10) {
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.getCodeByMsg(e.getMessage()), e.getMessage(), null);
// } else {
// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_FAIL, UserCodeEnum.DEVICE_MSG_FAIL.getCode(), UserCodeEnum.DEVICE_MSG_FAIL.getMsg(), null);
// }
// }
// return responseData;
// }
//
//}

View File

@@ -0,0 +1,309 @@
package com.njcn.cloud.controller.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.cloud.pojo.dto.AppDevMsg;
import com.njcn.cloud.pojo.dto.AppSteadyAss;
import com.njcn.cloud.pojo.dto.AppSteadyUrl;
import com.njcn.cloud.service.user.*;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.pojo.param.OnlineRateParam;
import com.njcn.device.pq.pojo.po.TopMsgPO;
import com.njcn.harmonic.api.HarmDataFeignClient;
import com.njcn.harmonic.pojo.param.StatSubstationBizBaseParam;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.user.api.UserFeignClient;
import com.njcn.user.pojo.po.User;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.*;
@Component
@RequiredArgsConstructor
public class SteadyMsgTask {
private final UserFeignClient userFeignClient;
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final HarmDataFeignClient harmDataFeignClient;
private final MsgService msgService;
private final IAppSteadyUrlService appSteadyUrlService;
private final IAppSteadyAssService appSteadyAssService;
private final IAppDevMsgService appDevMsgService;
@Scheduled(cron = "* * 10 * * ?")
public void timer() throws Exception {
System.out.println("开始执行++++++++++++++++++++++++"+new Date());
Date date = DateUtil.offsetDay(new Date(), -1);
String time = DateUtil.format(date, DatePattern.NORM_DATE_PATTERN);
//开始时间
String startTime = DateUtil.beginOfDay(date).toString();
//结束时间
String endTime = DateUtil.endOfDay(date).toString();
//执行稳态消息推送
steadyMsg(time,startTime,endTime);
//终端消息推送
devDegree(time,startTime,endTime);
}
/**
* @Description: 稳态消息
* @Date: 2023/11/17 15:07
*/
public void steadyMsg(String time,String startTime,String endTime) {
List<User> users = userFeignClient.getUserByIdList(null).getData();
if(CollUtil.isNotEmpty(users)){
StatSubstationBizBaseParam param;
for (User user : users) {
//根据单位获取投运监测点
List<String> lineIds = generalDeviceInfoClient.deptGetRunLine(user.getDeptId()).getData();
param=new StatSubstationBizBaseParam();
param.setIds(lineIds);
param.setStartTime(startTime);
param.setEndTime(endTime);
List<String> linesTargets = harmDataFeignClient.getLinesTarget(param).getData();
if(CollUtil.isNotEmpty(linesTargets)){
param.setIds(linesTargets);
List<RStatLimitRateDPO> limitRates = harmDataFeignClient.getLinesRate(param).getData();
//获取稳态消息guid
String msgIndex = msgService.sendSteadyMsg(user.getId(), time, linesTargets.size());
LocalDateTime date = LocalDateTimeUtil.parse(time,DatePattern.NORM_DATE_PATTERN);
AppSteadyAss steadyAss;
for (RStatLimitRateDPO line : limitRates) {
steadyAss=new AppSteadyAss();
steadyAss.setSteadyIndex(msgIndex);
steadyAss.setLineIndex(line.getLineId());
steadyAss.setTimeId(date);
appSteadyAssService.save(steadyAss);
saveSteadyUrl(line,date);
}
}
}
}
}
/**
* @Description: 新增终端异常通告
* @Date: 2023/11/17 15:08
*/
public void devDegree(String time,String startTime,String endTime){
LocalDateTime date = LocalDateTimeUtil.parse(time,DatePattern.NORM_DATE_PATTERN);
List<User> users = userFeignClient.getUserByIdList(null).getData();
if(CollUtil.isNotEmpty(users)){
for (User user : users) {
List<String> devIds = generalDeviceInfoClient.deptGetRunDev(user.getDeptId()).getData();
//获取消息信息
OnlineRateParam top=new OnlineRateParam();
top.setIds(devIds);
top.setType(1);
top.setStartTime(startTime);
top.setEndTime(endTime);
List<TopMsgPO> topMsgList = generalDeviceInfoClient.getTopMsgInfoByIds(top).getData();
AppDevMsg appDevMsg;
for (TopMsgPO topMsgPO : topMsgList) {
appDevMsg=new AppDevMsg();
appDevMsg.setDevmsgIndex(IdUtil.simpleUUID());
appDevMsg.setTopId(topMsgPO.getTopId());
appDevMsg.setUserIndex(user.getId());
appDevMsg.setTimeId(date);
appDevMsg.setState(0);
appDevMsgService.save(appDevMsg);
msgService.sendTerminalMsg(user.getId(),user.getDevCode(),time,
topMsgPO.getDeviceAbnormalNum(),
topMsgPO.getAlarmCount(),
topMsgPO.getComOutCount()
);
}
}
}
}
public void saveSteadyUrl(RStatLimitRateDPO limit, LocalDateTime timeId) {
String lineIndex=limit.getLineId();
if (limit.getFreqDevOvertime() > 0) {
insertUrlDate(lineIndex, timeId, 2, limit.getFreqDevOvertime());
}
if (limit.getVoltageDevOvertime() > 0) {
insertUrlDate(lineIndex, timeId, 3, limit.getVoltageDevOvertime());
}
if (limit.getUbalanceOvertime() > 0) {
insertUrlDate(lineIndex, timeId, 4, limit.getUbalanceOvertime());
}
if (limit.getFlickerOvertime() > 0) {
insertUrlDate(lineIndex, timeId, 5, limit.getFlickerOvertime());
}
if (limit.getUaberranceOvertime() > 0) {
insertUrlDate(lineIndex, timeId, 6, limit.getUaberranceOvertime());
}
if (limit.getUharm2Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 7, limit.getUharm2Overtime());
}
if (limit.getUharm3Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 8, limit.getUharm3Overtime());
}
if (limit.getUharm4Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 9, limit.getUharm4Overtime());
}
if (limit.getUharm5Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 10, limit.getUharm5Overtime());
}
if (limit.getUharm6Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 11, limit.getUharm6Overtime());
}
if (limit.getUharm7Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 12, limit.getUharm7Overtime());
}
if (limit.getUharm8Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 13, limit.getUharm8Overtime());
}
if (limit.getUharm9Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 14, limit.getUharm9Overtime());
}
if (limit.getUharm10Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 15, limit.getUharm10Overtime());
}
if (limit.getUharm11Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 16, limit.getUharm11Overtime());
}
if (limit.getUharm12Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 17, limit.getUharm12Overtime());
}
if (limit.getUharm13Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 18, limit.getUharm13Overtime());
}
if (limit.getUharm14Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 19, limit.getUharm14Overtime());
}
if (limit.getUharm15Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 20, limit.getUharm15Overtime());
}
if (limit.getUharm16Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 21, limit.getUharm16Overtime());
}
if (limit.getUharm17Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 22, limit.getUharm17Overtime());
}
if (limit.getUharm18Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 23, limit.getUharm18Overtime());
}
if (limit.getUharm19Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 24, limit.getUharm19Overtime());
}
if (limit.getUharm20Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 25, limit.getUharm20Overtime());
}
if (limit.getUharm21Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 26, limit.getUharm21Overtime());
}
if (limit.getUharm22Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 27, limit.getUharm22Overtime());
}
if (limit.getUharm23Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 28, limit.getUharm23Overtime());
}
if (limit.getUharm24Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 29, limit.getUharm24Overtime());
}
if (limit.getUharm25Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 30, limit.getUharm25Overtime());
}
if (limit.getIharm2Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 31, limit.getIharm2Overtime());
}
if (limit.getIharm3Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 32, limit.getIharm3Overtime());
}
if (limit.getIharm4Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 33, limit.getIharm4Overtime());
}
if (limit.getIharm5Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 34, limit.getIharm5Overtime());
}
if (limit.getIharm6Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 35, limit.getIharm6Overtime());
}
if (limit.getIharm7Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 36, limit.getIharm7Overtime());
}
if (limit.getIharm8Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 37, limit.getIharm8Overtime());
}
if (limit.getIharm9Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 38, limit.getIharm9Overtime());
}
if (limit.getIharm10Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 39, limit.getIharm10Overtime());
}
if (limit.getIharm11Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 40, limit.getIharm11Overtime());
}
if (limit.getIharm12Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 41, limit.getIharm12Overtime());
}
if (limit.getIharm13Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 42, limit.getIharm13Overtime());
}
if (limit.getIharm14Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 43, limit.getIharm14Overtime());
}
if (limit.getIharm15Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 44, limit.getIharm15Overtime());
}
if (limit.getIharm16Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 45, limit.getIharm16Overtime());
}
if (limit.getIharm17Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 46, limit.getIharm17Overtime());
}
if (limit.getIharm18Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 47, limit.getIharm18Overtime());
}
if (limit.getIharm19Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 48, limit.getIharm19Overtime());
}
if (limit.getIharm20Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 49, limit.getIharm20Overtime());
}
if (limit.getIharm21Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 50, limit.getIharm21Overtime());
}
if (limit.getIharm22Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 51, limit.getIharm22Overtime());
}
if (limit.getIharm23Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 52, limit.getIharm23Overtime());
}
if (limit.getIharm24Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 53, limit.getIharm24Overtime());
}
if (limit.getIharm25Overtime() > 0) {
insertUrlDate(lineIndex, timeId, 54, limit.getIharm25Overtime());
}
}
public void insertUrlDate(String lineIndex, LocalDateTime timeId, Integer typeCode, Integer limitNum) {
AppSteadyUrl url = new AppSteadyUrl();
url.setLineIndex(lineIndex);
url.setTimeId(timeId);
url.setTypeCode(typeCode);
url.setLimitNum(limitNum);
AppSteadyUrl one = appSteadyUrlService.getOne(new LambdaQueryWrapper<AppSteadyUrl>()
.eq(AppSteadyUrl::getLineIndex, lineIndex)
.eq(AppSteadyUrl::getTimeId, timeId)
.eq(AppSteadyUrl::getTypeCode, typeCode)
.eq(AppSteadyUrl::getLimitNum, limitNum)
);
if (ObjectUtil.isNull(one)) {
appSteadyUrlService.save(url);
}
}
}

View File

@@ -15,6 +15,7 @@ import com.njcn.cloud.pojo.vo.DevMsgDetailInfo;
import com.njcn.cloud.service.user.IAppDevMsgService; import com.njcn.cloud.service.user.IAppDevMsgService;
import com.njcn.device.pq.api.GeneralDeviceInfoClient; import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.api.LineFeignClient; import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.param.OnlineRateParam;
import com.njcn.device.pq.pojo.po.TopMsgPO; import com.njcn.device.pq.pojo.po.TopMsgPO;
import com.njcn.device.pq.pojo.vo.DevDetail; import com.njcn.device.pq.pojo.vo.DevDetail;
import com.njcn.web.pojo.param.BaseParam; import com.njcn.web.pojo.param.BaseParam;
@@ -39,7 +40,6 @@ import java.util.stream.Collectors;
public class AppDevMsgServiceImpl extends ServiceImpl<AppDevMsgMapper, AppDevMsg> implements IAppDevMsgService { public class AppDevMsgServiceImpl extends ServiceImpl<AppDevMsgMapper, AppDevMsg> implements IAppDevMsgService {
private final GeneralDeviceInfoClient generalDeviceInfoClient; private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final LineFeignClient lineFeignClient;
@Override @Override
public Page<AppDevMsg> deviceMsgList(BaseParam param) { public Page<AppDevMsg> deviceMsgList(BaseParam param) {
@@ -61,7 +61,10 @@ public class AppDevMsgServiceImpl extends ServiceImpl<AppDevMsgMapper, AppDevMsg
List<DevMsgDetailInfo> info=new ArrayList<>(); List<DevMsgDetailInfo> info=new ArrayList<>();
if(CollUtil.isNotEmpty(records)){ if(CollUtil.isNotEmpty(records)){
List<String> topIds = records.stream().map(AppDevMsg::getTopId).collect(Collectors.toList()); List<String> topIds = records.stream().map(AppDevMsg::getTopId).collect(Collectors.toList());
List<TopMsgPO> data = generalDeviceInfoClient.getTopMsgInfoByIds(topIds).getData(); OnlineRateParam top=new OnlineRateParam();
top.setIds(topIds);
top.setType(0);
List<TopMsgPO> data = generalDeviceInfoClient.getTopMsgInfoByIds(top).getData();
Map<String, TopMsgPO> topMap = data.stream().collect(Collectors.toMap(TopMsgPO::getTopId, Function.identity())); Map<String, TopMsgPO> topMap = data.stream().collect(Collectors.toMap(TopMsgPO::getTopId, Function.identity()));
DevMsgDetailInfo msg; DevMsgDetailInfo msg;
for (AppDevMsg record : records) { for (AppDevMsg record : records) {

View File

@@ -3,32 +3,24 @@ package com.njcn.cloud.service.impl.user;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.cloud.enums.app.UserCodeEnum; import com.njcn.cloud.enums.app.UserCodeEnum;
import com.njcn.cloud.pojo.dto.AppEventInfo; import com.njcn.cloud.pojo.dto.*;
import com.njcn.cloud.pojo.dto.AppEventMsg; import com.njcn.cloud.service.user.*;
import com.njcn.cloud.pojo.dto.AppInfoSet;
import com.njcn.cloud.service.user.IAppEventInfoService;
import com.njcn.cloud.service.user.IAppEventMsgService;
import com.njcn.cloud.service.user.IAppInfoSetService;
import com.njcn.cloud.service.user.MsgService;
import com.njcn.cloud.utils.RedisDB; import com.njcn.cloud.utils.RedisDB;
import com.njcn.cloud.utils.SmsUtil; import com.njcn.cloud.utils.SmsUtil;
import com.njcn.common.pojo.dto.LogInfoDTO; import com.njcn.common.pojo.dto.LogInfoDTO;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils; import com.njcn.common.utils.PubUtils;
import com.njcn.device.pq.api.DeptLineFeignClient; import com.njcn.device.pq.api.DeptLineFeignClient;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.api.LineFeignClient; import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.param.OnlineRateParam;
import com.njcn.device.pq.pojo.po.DeptLine; import com.njcn.device.pq.pojo.po.DeptLine;
import com.njcn.device.pq.pojo.po.TopMsgPO;
import com.njcn.device.pq.pojo.vo.LineDetailVO; import com.njcn.device.pq.pojo.vo.LineDetailVO;
import com.njcn.event.api.EventDetailFeignClient; import com.njcn.event.api.EventDetailFeignClient;
import com.njcn.event.file.component.WavePicComponent; import com.njcn.event.file.component.WavePicComponent;
@@ -43,12 +35,14 @@ 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.RequestUtil; import com.njcn.web.utils.RequestUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.security.auth.login.AccountException; import javax.security.auth.login.AccountException;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
/** /**
@@ -58,6 +52,7 @@ import java.util.*;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class MsgServiceImpl implements MsgService { public class MsgServiceImpl implements MsgService {
private final EventDetailFeignClient eventDetailFeignClient; private final EventDetailFeignClient eventDetailFeignClient;
@@ -66,10 +61,13 @@ public class MsgServiceImpl implements MsgService {
private final UserLogFeignClient userLogFeignClient; private final UserLogFeignClient userLogFeignClient;
private final DeptFeignClient deptFeignClient; private final DeptFeignClient deptFeignClient;
private final UserFeignClient userFeignClient; private final UserFeignClient userFeignClient;
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final IAppEventInfoService appEventInfoService; private final IAppEventInfoService appEventInfoService;
private final WavePicComponent wavePicComponent; private final WavePicComponent wavePicComponent;
private final IAppInfoSetService appInfoSetService; private final IAppInfoSetService appInfoSetService;
private final IAppEventMsgService appEventMsgService; private final IAppEventMsgService appEventMsgService;
private final IAppSteadyMsgService appSteadyMsgService;
private final IAppDevMsgService appDevMsgService;
private final RedisUtil redisUtil; private final RedisUtil redisUtil;
private final SmsUtil smsUtil; private final SmsUtil smsUtil;
@@ -135,9 +133,128 @@ public class MsgServiceImpl implements MsgService {
} }
} }
@Override
public void sendSteadyMsg(String userIndex, String timeID, Integer lineNum) {
/**
* 稳态消息推送
*
* @param userIndex 用户索引
* @param timeID 统计时间
* @param lineNum 监测点数
*/
@Override
public String sendSteadyMsg(String userIndex, String timeID, Integer lineNum) {
List<User> users = userFeignClient.getUserByIdList(Arrays.asList(userIndex)).getData();
AppInfoSet appInfoSet = appInfoSetService.getById(userIndex);
if (CollUtil.isEmpty(users) || ObjectUtil.isNotNull(appInfoSet)) {
throw new BusinessException(UserCodeEnum.NO_USER.getMsg());
}
LocalDateTime time = LocalDateTimeUtil.parse(timeID,DatePattern.NORM_DATE_PATTERN);
//插入之前需要判断是否重复时间
List<AppSteadyMsg> steadyMsgs = appSteadyMsgService.list(new LambdaQueryWrapper<AppSteadyMsg>()
.eq(AppSteadyMsg::getTimeId, time)
.eq(AppSteadyMsg::getLineNum, lineNum)
.eq(AppSteadyMsg::getUserIndex, userIndex)
);
if (CollUtil.isNotEmpty(steadyMsgs)) {
return steadyMsgs.get(0).getSteadyIndex();
}
AppSteadyMsg steadyMsg = new AppSteadyMsg();
steadyMsg.setLineNum(lineNum);
steadyMsg.setSteadyIndex(IdUtil.simpleUUID());
steadyMsg.setState(0);
steadyMsg.setTimeId(time);
steadyMsg.setUserIndex(userIndex);
appSteadyMsgService.save(steadyMsg);
if (appInfoSet.getTargetInfo() == 1 && StrUtil.isNotBlank(users.get(0).getDevCode())) {
//发送稳态消息
String date = LocalDateTimeUtil.format(time, DatePattern.NORM_DATE_PATTERN);
String title = "稳态越限消息";
String content = date + " 发生稳态越限监测点" + lineNum + "";
sendMsg( users.get(0).getDevCode(), title, content, "2");
}
return steadyMsg.getSteadyIndex();
}
/**
* 终端消息推送
*
* @param userIndex 用户索引
* @param timeID 统计时间
* @param topID 异常消息id (pqs_top_msg)
* @param flag 是否强制推送
*/
@Override
public String sendTargetMsg(String userIndex, String timeID, String topID, Integer flag) {
List<User> users = userFeignClient.getUserByIdList(Arrays.asList(userIndex)).getData();
AppInfoSet appInfoSet = appInfoSetService.getById(userIndex);
if (CollUtil.isEmpty(users) || ObjectUtil.isNotNull(appInfoSet)) {
throw new BusinessException(UserCodeEnum.NO_USER.getMsg());
}
LocalDateTime time = LocalDateTimeUtil.parse(timeID,DatePattern.NORM_DATE_PATTERN);
AppDevMsg devMsg = appDevMsgService.getOne(new LambdaQueryWrapper<AppDevMsg>()
.eq(AppDevMsg::getUserIndex, userIndex)
.eq(AppDevMsg::getTimeId, time)
);
OnlineRateParam top=new OnlineRateParam();
top.setIds(Arrays.asList(topID));
top.setType(0);
List<TopMsgPO> topMsgPOS = generalDeviceInfoClient.getTopMsgInfoByIds(top).getData();
if (ObjectUtil.isNotNull(devMsg)) {
if (appInfoSet.getDeviceInfo() == 1 && flag == 1) {
sendDevMsg(timeID, topMsgPOS,users.get(0));
}
} else {
devMsg = new AppDevMsg();
devMsg.setDevmsgIndex(IdUtil.simpleUUID());
devMsg.setTopId(topID);
devMsg.setUserIndex(userIndex);
devMsg.setTimeId(time);
devMsg.setState(0);
appDevMsgService.save(devMsg);
if (appInfoSet.getDeviceInfo() == 1) {
sendDevMsg(timeID, topMsgPOS,users.get(0));
}
}
return devMsg.getDevmsgIndex();
}
@Override
public void sendTerminalMsg(String userIndex,String devCode, String timeID,Integer devNum,Integer alarmNum,Integer comOutNum) {
AppInfoSet appInfoSet = appInfoSetService.getById(userIndex);
if (ObjectUtil.isNotNull(appInfoSet)) {
if (appInfoSet.getDeviceInfo() == 1) {
String title = timeID + "终端异常共" + devNum + "";
String content = "异常情况:" + (StringUtils.isEmpty(alarmNum) ? "" : "终端告警:" + alarmNum + "") + (StringUtils.isEmpty(comOutNum) ? "" : "通讯中断:" + Integer.valueOf(comOutNum) + "");
sendMsg(devCode, title, content, "3");
}
} else {
throw new BusinessException(UserCodeEnum.NO_USER_SETTING.getMsg());
}
}
/**
* 终端消息推送
*
* @param time
* @param topMsgPOS
*/
private void sendDevMsg(String time, List<TopMsgPO> topMsgPOS,User user) {
if (CollUtil.isNotEmpty(topMsgPOS)) {
TopMsgPO topMsgPO = topMsgPOS.get(0);
Integer alarmNum = topMsgPO.getAlarmCount();
Integer comOutNum = topMsgPO.getComOutCount();
float flowNum = topMsgPO.getFlowValue();
if (alarmNum > 0 || comOutNum > 0 || flowNum > 94) {
//推送
String title = time + "终端异常共" + topMsgPO.getDeviceAbnormalNum() + "";
String content = "异常情况:" + (StringUtils.isEmpty(alarmNum) ? "" : "终端告警:" + alarmNum + "") + (StringUtils.isEmpty(comOutNum) ? "" : "通讯中断:" + Integer.valueOf(comOutNum) + "") + (StringUtils.isEmpty(flowNum) ? "" : "终端流量:" + Float.valueOf(flowNum) + "%");
sendMsg(user.getDevCode(), title, content, "3");
}
}
} }
/** /**
@@ -164,8 +281,6 @@ public class MsgServiceImpl implements MsgService {
List<LineDetailVO.Detail> lines = lineFeignClient.getLineDetailByIds(Arrays.asList(eventDetail.getLineId())).getData(); List<LineDetailVO.Detail> lines = lineFeignClient.getLineDetailByIds(Arrays.asList(eventDetail.getLineId())).getData();
if (CollUtil.isNotEmpty(lines)) { if (CollUtil.isNotEmpty(lines)) {
LineDetailVO.Detail line = lines.get(0); LineDetailVO.Detail line = lines.get(0);
// String url = getPushUrl();
String url = "";
String time = LocalDateTimeUtil.format(eventDetail.getStartTime(), DatePattern.NORM_DATETIME_MS_PATTERN); String time = LocalDateTimeUtil.format(eventDetail.getStartTime(), DatePattern.NORM_DATETIME_MS_PATTERN);
//暂降幅值 //暂降幅值
Float amplitude = PubUtils.floatRound(2, eventDetail.getFeatureAmplitude().floatValue() * 100); Float amplitude = PubUtils.floatRound(2, eventDetail.getFeatureAmplitude().floatValue() * 100);
@@ -173,7 +288,7 @@ public class MsgServiceImpl implements MsgService {
Float duration = PubUtils.floatRound(2, eventDetail.getDuration().floatValue()); Float duration = PubUtils.floatRound(2, eventDetail.getDuration().floatValue());
content = content + time + ",暂降幅值:" + amplitude + "%," + "持续时间:" + duration + "s。"; content = content + time + ",暂降幅值:" + amplitude + "%," + "持续时间:" + duration + "s。";
//todo 推送消息地址 //todo 推送消息地址
// sendMsg(url, devCode, line.getName() + "监测点发生暂态事件", content, "1"); sendMsg(devCode, line.getLineName() + "监测点发生暂态事件", content, "1");
//查询主账户是否开启短信通知 根据监测点ID找到部门找到用户 //查询主账户是否开启短信通知 根据监测点ID找到部门找到用户
if (phonePushFlag == 0) { if (phonePushFlag == 0) {
//添加策略,判断当前该事件是否需要短信推送 //添加策略,判断当前该事件是否需要短信推送
@@ -268,5 +383,32 @@ public class MsgServiceImpl implements MsgService {
throw new BusinessException(UserCodeEnum.NO_USER_FOCUS.getMsg()); throw new BusinessException(UserCodeEnum.NO_USER_FOCUS.getMsg());
} }
/**
* 推送消息
*
* @param cid 手机唯一标识
* @param title 消息头
* @param content 消息内容
* @param transmissionContent 消息类别
*/
private static void sendMsg(String cid, String title, String content, String transmissionContent) {
String result;
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("cid", cid);
jsonObject.put("title", title);
jsonObject.put("content", content);
jsonObject.put("transmissionContent", transmissionContent);
result = null;
JSONObject resultJson = JSONObject.fromObject(result);
int resultCode = resultJson.getInt("returnCode");
if (resultCode != 0) {
log.error("推送消息的标题:{},失败,返回体为:{}", title, result);
throw new AccountException(UserCodeEnum.STEADY_MSG_FAIL.getMsg());
}
log.error("推送消息的标题:{},结果:{}", title, result);
} catch (Exception e) {
log.error("推送消息发生异常,异常是" + e.getMessage());
}
}
} }

View File

@@ -25,5 +25,26 @@ public interface MsgService {
* @Author: wr * @Author: wr
* @Date: 2023/11/10 15:35 * @Date: 2023/11/10 15:35
*/ */
void sendSteadyMsg(String userIndex, String timeID, Integer lineNum); String sendSteadyMsg(String userIndex, String timeID, Integer lineNum);
/**
* 终端消息推送
* @param userIndex
* @param timeID
* @param topID
* @param flag
* @return
*/
String sendTargetMsg(String userIndex, String timeID, String topID, Integer flag);
/**
* 批量推送终端消息
* @param userIndex
* @param devCode
* @param timeID
* @param devNum
* @param alarmNum
* @param comOutNum
*/
void sendTerminalMsg(String userIndex,String devCode, String timeID,Integer devNum,Integer alarmNum,Integer comOutNum);
} }