diff --git a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/controller/message/EventMsgPushController.java b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/controller/message/EventMsgPushController.java index e1381c5..2d62692 100644 --- a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/controller/message/EventMsgPushController.java +++ b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/controller/message/EventMsgPushController.java @@ -1,137 +1,92 @@ -//package com.njcn.cloud.controller.message; -// -//import com.njcn.enums.app.ReturnCode; -//import com.njcn.enums.app.UserCodeEnum; -//import com.njcn.pojo.commons.ResponseData; -//import com.njcn.utils.PubUtils; -//import com.shining.cloud.service.information.EventMsgService; -//import io.swagger.annotations.Api; -//import io.swagger.annotations.ApiImplicitParam; -//import io.swagger.annotations.ApiImplicitParams; -//import io.swagger.annotations.ApiOperation; -//import net.sf.json.JSONObject; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.util.StringUtils; -//import org.springframework.web.bind.annotation.PostMapping; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RestController; -// -//import javax.servlet.http.HttpServletRequest; -// -// -///** -// * @author hongawen -// * @date: 2019/11/11 14:51 -// */ -//@RestController -//@RequestMapping("/msg") -//@Api(tags = "内部消息推送") -//public class EventMsgPushController { -// -// 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"), -// }) -// @ApiOperation(value = "暂态消息推送", notes = "暂态消息推送", response = ResponseData.class) -// public ResponseData sendEventMsg(String eventDetailIndex, int lineId, HttpServletRequest request) { -// logger.error("推送暂降事件:事件索引:{},监测点ID为:{}",eventDetailIndex,lineId); -// 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); -// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_SUCCESS, UserCodeEnum.EVENT_MSG_SUCCESS.getCode(), UserCodeEnum.EVENT_MSG_SUCCESS.getMsg(), null); -// } 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.EVENT_MSG_FAIL.getCode(), UserCodeEnum.EVENT_MSG_FAIL.getMsg(), null); -// } -// } -// return responseData; -// } -// -// /** -// * 稳态消息推送 -// */ -// @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"), -// }) -// @ApiOperation(value = "稳态消息推送", notes = "稳态消息推送", response = ResponseData.class) -// public ResponseData sendSteadyMsg(String userIndex, Long timeID, Integer lineNum) { -// ResponseData responseData; -// logger.error("稳态消息推送:用户索引:{},统计时间:{},监测点个数:{}",userIndex,timeID,lineNum); -// 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); -// } -// try { -// String msgIndex = eventMsgService.sendSteadyMsg(userIndex, timeID, lineNum); -// JSONObject jsonObject = new JSONObject(); -// jsonObject.put("msgIndex", msgIndex); -// responseData = PubUtils.assignmentAppResponse(ReturnCode.RETURN_SUCCESS, UserCodeEnum.STEADY_MSG_SUCCESS.getCode(), UserCodeEnum.STEADY_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.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; -// } -// -//} +package com.njcn.cloud.controller.message; + +import cn.hutool.core.util.StrUtil; +import com.njcn.cloud.enums.app.UserCodeEnum; +import com.njcn.cloud.service.user.MsgService; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.HttpResultUtil; +import com.njcn.web.controller.BaseController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + + +/** + * @author hongawen + * @date: 2019/11/11 14:51 + */ +@RestController +@RequestMapping("/msg") +@Api(tags = "内部消息推送") +@RequiredArgsConstructor +public class EventMsgPushController extends BaseController { + + private final MsgService msgService; + + /** + * 暂态消息推送 + */ + @PostMapping("/sendEventMsg") + @ApiImplicitParams({ + @ApiImplicitParam(name = "eventDetailIndex", value = "暂降索引", required = true, paramType = "query"), + @ApiImplicitParam(name = "lineId", value = "监测点索引", required = true, paramType = "query"), + }) + @ApiOperation(value = "暂态消息推送", notes = "暂态消息推送") + public HttpResult sendEventMsg(String eventDetailIndex, String lineId) throws Exception { + String methodDescribe = getMethodDescribe("sendEventMsg"); + if (StrUtil.isNotBlank(eventDetailIndex) || StrUtil.isNotBlank(lineId)) { + throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg()); + } + msgService.sendEventMsg(eventDetailIndex, lineId); + 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"), + }) + @ApiOperation(value = "稳态消息推送", notes = "稳态消息推送") + public HttpResult sendSteadyMsg(String userIndex, String timeID, Integer lineNum) { + String methodDescribe = getMethodDescribe("sendSteadyMsg"); + if (StrUtil.isNotBlank(userIndex) || StrUtil.isNotBlank(userIndex)) { + throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg()); + } + msgService.sendSteadyMsg(userIndex, timeID, lineNum); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); + } + + + /** + * 终端消息推送 + */ + @PostMapping("/sendTargetMsg") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userIndex", value = "用户索引", required = true, paramType = "query"), + @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"), + @ApiImplicitParam(name = "topID", value = "终点消息id", required = true, paramType = "query"), + @ApiImplicitParam(name = "flag", value = "强制推送标志", required = true, paramType = "query"), + }) + @ApiOperation(value = "终端消息推送", notes = "终端消息推送") + public HttpResult sendTargetMsg(String userIndex, String timeID, String topID, int flag) { + String methodDescribe = getMethodDescribe("sendTargetMsg"); + if (StrUtil.isNotBlank(userIndex) || StrUtil.isNotBlank(userIndex)) { + throw new BusinessException(UserCodeEnum.INVALID_PARAMETER.getMsg()); + } + msgService.sendTargetMsg(userIndex, timeID, topID, flag); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); + } + +} diff --git a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/controller/task/SteadyMsgTask.java b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/controller/task/SteadyMsgTask.java new file mode 100644 index 0000000..3fcdaaa --- /dev/null +++ b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/controller/task/SteadyMsgTask.java @@ -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 users = userFeignClient.getUserByIdList(null).getData(); + if(CollUtil.isNotEmpty(users)){ + StatSubstationBizBaseParam param; + for (User user : users) { + //根据单位获取投运监测点 + List lineIds = generalDeviceInfoClient.deptGetRunLine(user.getDeptId()).getData(); + param=new StatSubstationBizBaseParam(); + param.setIds(lineIds); + param.setStartTime(startTime); + param.setEndTime(endTime); + List linesTargets = harmDataFeignClient.getLinesTarget(param).getData(); + if(CollUtil.isNotEmpty(linesTargets)){ + param.setIds(linesTargets); + List 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 users = userFeignClient.getUserByIdList(null).getData(); + if(CollUtil.isNotEmpty(users)){ + for (User user : users) { + List devIds = generalDeviceInfoClient.deptGetRunDev(user.getDeptId()).getData(); + //获取消息信息 + OnlineRateParam top=new OnlineRateParam(); + top.setIds(devIds); + top.setType(1); + top.setStartTime(startTime); + top.setEndTime(endTime); + List 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() + .eq(AppSteadyUrl::getLineIndex, lineIndex) + .eq(AppSteadyUrl::getTimeId, timeId) + .eq(AppSteadyUrl::getTypeCode, typeCode) + .eq(AppSteadyUrl::getLimitNum, limitNum) + ); + if (ObjectUtil.isNull(one)) { + appSteadyUrlService.save(url); + } + } +} diff --git a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/impl/user/AppDevMsgServiceImpl.java b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/impl/user/AppDevMsgServiceImpl.java index 99c4d92..023018a 100644 --- a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/impl/user/AppDevMsgServiceImpl.java +++ b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/impl/user/AppDevMsgServiceImpl.java @@ -15,6 +15,7 @@ import com.njcn.cloud.pojo.vo.DevMsgDetailInfo; import com.njcn.cloud.service.user.IAppDevMsgService; import com.njcn.device.pq.api.GeneralDeviceInfoClient; 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.vo.DevDetail; import com.njcn.web.pojo.param.BaseParam; @@ -39,7 +40,6 @@ import java.util.stream.Collectors; public class AppDevMsgServiceImpl extends ServiceImpl implements IAppDevMsgService { private final GeneralDeviceInfoClient generalDeviceInfoClient; - private final LineFeignClient lineFeignClient; @Override public Page deviceMsgList(BaseParam param) { @@ -61,7 +61,10 @@ public class AppDevMsgServiceImpl extends ServiceImpl info=new ArrayList<>(); if(CollUtil.isNotEmpty(records)){ List topIds = records.stream().map(AppDevMsg::getTopId).collect(Collectors.toList()); - List data = generalDeviceInfoClient.getTopMsgInfoByIds(topIds).getData(); + OnlineRateParam top=new OnlineRateParam(); + top.setIds(topIds); + top.setType(0); + List data = generalDeviceInfoClient.getTopMsgInfoByIds(top).getData(); Map topMap = data.stream().collect(Collectors.toMap(TopMsgPO::getTopId, Function.identity())); DevMsgDetailInfo msg; for (AppDevMsg record : records) { diff --git a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/impl/user/MsgServiceImpl.java b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/impl/user/MsgServiceImpl.java index e4c338c..d7ed2a3 100644 --- a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/impl/user/MsgServiceImpl.java +++ b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/impl/user/MsgServiceImpl.java @@ -3,32 +3,24 @@ package com.njcn.cloud.service.impl.user; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; 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.njcn.cloud.enums.app.UserCodeEnum; -import com.njcn.cloud.pojo.dto.AppEventInfo; -import com.njcn.cloud.pojo.dto.AppEventMsg; -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.pojo.dto.*; +import com.njcn.cloud.service.user.*; import com.njcn.cloud.utils.RedisDB; import com.njcn.cloud.utils.SmsUtil; import com.njcn.common.pojo.dto.LogInfoDTO; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.utils.PubUtils; 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.pojo.param.OnlineRateParam; 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.event.api.EventDetailFeignClient; 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.web.utils.RequestUtil; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import net.sf.json.JSONObject; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import javax.security.auth.login.AccountException; +import java.time.LocalDateTime; import java.util.*; /** @@ -58,6 +52,7 @@ import java.util.*; */ @Service @RequiredArgsConstructor +@Slf4j public class MsgServiceImpl implements MsgService { private final EventDetailFeignClient eventDetailFeignClient; @@ -66,10 +61,13 @@ public class MsgServiceImpl implements MsgService { private final UserLogFeignClient userLogFeignClient; private final DeptFeignClient deptFeignClient; private final UserFeignClient userFeignClient; + private final GeneralDeviceInfoClient generalDeviceInfoClient; private final IAppEventInfoService appEventInfoService; private final WavePicComponent wavePicComponent; private final IAppInfoSetService appInfoSetService; private final IAppEventMsgService appEventMsgService; + private final IAppSteadyMsgService appSteadyMsgService; + private final IAppDevMsgService appDevMsgService; private final RedisUtil redisUtil; 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 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 steadyMsgs = appSteadyMsgService.list(new LambdaQueryWrapper() + .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 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() + .eq(AppDevMsg::getUserIndex, userIndex) + .eq(AppDevMsg::getTimeId, time) + ); + OnlineRateParam top=new OnlineRateParam(); + top.setIds(Arrays.asList(topID)); + top.setType(0); + List 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 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 lines = lineFeignClient.getLineDetailByIds(Arrays.asList(eventDetail.getLineId())).getData(); if (CollUtil.isNotEmpty(lines)) { LineDetailVO.Detail line = lines.get(0); -// String url = getPushUrl(); - String url = ""; String time = LocalDateTimeUtil.format(eventDetail.getStartTime(), DatePattern.NORM_DATETIME_MS_PATTERN); //暂降幅值 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()); content = content + time + ",暂降幅值:" + amplitude + "%," + "持续时间:" + duration + "s。"; //todo 推送消息地址 -// sendMsg(url, devCode, line.getName() + "监测点发生暂态事件", content, "1"); + sendMsg(devCode, line.getLineName() + "监测点发生暂态事件", content, "1"); //查询主账户是否开启短信通知 根据监测点ID找到部门找到用户 if (phonePushFlag == 0) { //添加策略,判断当前该事件是否需要短信推送 @@ -268,5 +383,32 @@ public class MsgServiceImpl implements MsgService { 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()); + } + } } diff --git a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/user/MsgService.java b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/user/MsgService.java index ebdb38f..8fc61e4 100644 --- a/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/user/MsgService.java +++ b/app-cloud/app-cloud-boot/src/main/java/com/njcn/cloud/service/user/MsgService.java @@ -25,5 +25,26 @@ public interface MsgService { * @Author: wr * @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); }