diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsTerminalLogs.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsTerminalLogs.java index f0254ef..a08ff39 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsTerminalLogs.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsTerminalLogs.java @@ -37,6 +37,11 @@ public class CsTerminalLogs extends BaseEntity implements Serializable { */ private String deviceName; + /** + * 监测点id + */ + private String lineId; + /** * 前置服务器id */ diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsTerminalReply.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsTerminalReply.java index 8270858..a554281 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsTerminalReply.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsTerminalReply.java @@ -57,6 +57,11 @@ public class CsTerminalReply extends BaseEntity implements Serializable { */ private String deviceName; + /** + * 监测点id + */ + private String lineId; + /** * 是否收到(0:未收到 1:收到) */ diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/icd/IcdController.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/icd/IcdController.java index c68b3c4..7e3103e 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/icd/IcdController.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/icd/IcdController.java @@ -10,10 +10,10 @@ import com.njcn.csdevice.param.IcdParam; import com.njcn.csdevice.pojo.vo.CldLedgerVo; import com.njcn.csdevice.pojo.vo.DeviceInfo; import com.njcn.csdevice.service.IcdService; -import com.njcn.mq.message.CldControlMessage; 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.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -68,10 +68,51 @@ public class IcdController extends BaseController { @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/restartProcess") @ApiOperation("重启前置机进程") - @ApiImplicitParam(name = "message", value = "message", required = true) - public HttpResult restartProcess(@RequestBody CldControlMessage message){ + @ApiImplicitParams({ + @ApiImplicitParam(name = "nodeId", value = "前置服务器id", required = true), + @ApiImplicitParam(name = "processNo", value = "进程号", required = true) + }) + public HttpResult restartProcess(@RequestParam String nodeId,@RequestParam Integer processNo){ String methodDescribe = getMethodDescribe("restartProcess"); - icdService.restartProcess(message); + icdService.restartProcess(nodeId,processNo); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/bzFileByEventId") + @ApiOperation("指定事件补召波形") + @ApiImplicitParam(name = "eventId", value = "事件id", required = true) + public HttpResult bzFileByEventId(@RequestParam String eventId){ + String methodDescribe = getMethodDescribe("bzFileByEventId"); + icdService.bzFileByEventId(eventId); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/bzEvent") + @ApiOperation("补召事件") + @ApiImplicitParams({ + @ApiImplicitParam(name = "lineList", value = "监测点id集合"), + @ApiImplicitParam(name = "startTime", value = "开始时间"), + @ApiImplicitParam(name = "endTime", value = "结束时间") + }) + public HttpResult bzEvent(@RequestParam(required = false) List lineList,@RequestParam String startTime,@RequestParam String endTime){ + String methodDescribe = getMethodDescribe("bzEvent"); + icdService.bzEvent(lineList,startTime,endTime); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/bzFile") + @ApiOperation("补召波形") + @ApiImplicitParams({ + @ApiImplicitParam(name = "lineList", value = "监测点id"), + @ApiImplicitParam(name = "startTime", value = "开始时间"), + @ApiImplicitParam(name = "endTime", value = "结束时间") + }) + public HttpResult bzFile(@RequestParam(required = false) List lineList,@RequestParam String startTime,@RequestParam String endTime){ + String methodDescribe = getMethodDescribe("bzFile"); + icdService.bzFile(lineList,startTime,endTime); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsEquipmentDeliveryService.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsEquipmentDeliveryService.java index 03454b1..8d82722 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsEquipmentDeliveryService.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsEquipmentDeliveryService.java @@ -130,6 +130,12 @@ public interface CsEquipmentDeliveryService extends IService getAll(); + /** + * 获取所有装置信息(投运且在线) + * @return + */ + List getAllOnline(); + /** * 判断设备型号 */ diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/IcdService.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/IcdService.java index f9ba4c1..dfa51d1 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/IcdService.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/IcdService.java @@ -4,7 +4,6 @@ import com.njcn.csdevice.param.IcdLedgerParam; import com.njcn.csdevice.param.IcdParam; import com.njcn.csdevice.pojo.vo.CldLedgerVo; import com.njcn.csdevice.pojo.vo.DeviceInfo; -import com.njcn.mq.message.CldControlMessage; import java.util.List; @@ -16,6 +15,12 @@ public interface IcdService { CldLedgerVo getLedgerById(String id); - void restartProcess(CldControlMessage message); + void restartProcess(String nodeId, Integer processNo); + + void bzFileByEventId(String eventId); + + void bzEvent(List lineList, String startTime, String endTime); + + void bzFile(List lineList,String startTime, String endTime); } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java index ee352e9..f2c1271 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java @@ -706,6 +706,15 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl getAllOnline() { + return this.lambdaQuery() + .ne(CsEquipmentDeliveryPO::getRunStatus,0) + .eq(CsEquipmentDeliveryPO::getUsageStatus,1) + .isNotNull(CsEquipmentDeliveryPO::getNodeId) + .list(); + } + @Override public boolean judgeDevModel(String nDid) { boolean result = false; diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsTerminalLogsServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsTerminalLogsServiceImpl.java index 0e34349..518ad94 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsTerminalLogsServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsTerminalLogsServiceImpl.java @@ -146,8 +146,10 @@ public class CsTerminalLogsServiceImpl extends ServiceImpl{ String key; - String code; + String code = ""; if (Objects.equals(item.getCode(), "add_terminal")) { code = "新增"; } else if (Objects.equals(item.getCode(), "ledger_modify")) { code = "修改"; - } else { + } else if (Objects.equals(item.getCode(), "delete_terminal")){ code = "删除"; } String nodeName = nodeService.getNodeById(item.getNodeId()).getName(); diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/IcdServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/IcdServiceImpl.java index 4b8496b..b21bb06 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/IcdServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/IcdServiceImpl.java @@ -1,6 +1,10 @@ package com.njcn.csdevice.service.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; +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.alibaba.csp.sentinel.util.StringUtil; @@ -16,7 +20,12 @@ import com.njcn.csdevice.pojo.po.*; import com.njcn.csdevice.pojo.vo.CldLedgerVo; import com.njcn.csdevice.pojo.vo.DeviceInfo; import com.njcn.csdevice.service.*; +import com.njcn.csharmonic.api.EventFeignClient; +import com.njcn.csharmonic.pojo.po.CsEventPO; +import com.njcn.mq.message.BZEventMessage; import com.njcn.mq.message.CldControlMessage; +import com.njcn.mq.template.BZEventMessageTemplate; +import com.njcn.mq.template.CldControlMessageTemplate; import com.njcn.redis.pojo.enums.AppRedisKey; import com.njcn.redis.utils.RedisUtil; import com.njcn.system.enums.DicDataEnum; @@ -27,6 +36,8 @@ import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -44,7 +55,12 @@ class IcdServiceImpl implements IcdService { private final CsEquipmentDeliveryService csEquipmentDeliveryService; private final CsLinePOService csLinePOService; private final ICsLedgerService csLedgerService; + private final CldControlMessageTemplate controlMessageTemplate; + private final BZEventMessageTemplate bzEventMessageTemplate; + private final EventFeignClient eventFeignClient; private final ICsTerminalLogsService csTerminalLogsService; + private final ICsTerminalReplyService csTerminalReplyService; + private final DateTimeFormatter microsecondFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"); @Override public List getLedgerInfo(IcdParam param) { @@ -161,8 +177,307 @@ class IcdServiceImpl implements IcdService { } @Override - public void restartProcess(CldControlMessage message) { + public void restartProcess(String nodeId, Integer processNo) { + Node node = nodeService.getNodeById(nodeId); + CldControlMessage cldControlMessage = new CldControlMessage(); + cldControlMessage.setGuid(IdUtil.simpleUUID()); + cldControlMessage.setCode("set_process"); + cldControlMessage.setNodeId(nodeId); + cldControlMessage.setProcessNo(processNo); + cldControlMessage.setFun("delete"); + cldControlMessage.setProcessNum(node.getMaxProcessNum()); + controlMessageTemplate.sendMember(cldControlMessage,nodeId); + } + @Override + @Transactional(rollbackFor = Exception.class) + public void bzFileByEventId(String eventId) { + CsEventPO po = eventFeignClient.queryById(eventId).getData(); + if (ObjectUtil.isNull(po)) { + throw new BusinessException("事件缺失"); + } + //获取设备信息 + CsEquipmentDeliveryPO dev = csEquipmentDeliveryService.getDevByLineId(po.getLineId()); + BZEventMessage.File file = new BZEventMessage.File(); + file.setGuid(po.getId()); + file.setTerminalId(po.getDeviceId()); + file.setMonitorId(po.getLineId()); + file.setTimeList(Collections.singletonList(po.getStartTime().format(microsecondFormatter))); + file.setDataType(2); + //记录发送日志 + CsTerminalLogs csTerminalLogs = new CsTerminalLogs(); + csTerminalLogs.setId(po.getId()); + csTerminalLogs.setDeviceId(dev.getId()); + csTerminalLogs.setLineId(po.getLineId()); + csTerminalLogs.setOperateType(3); + csTerminalLogs.setNodeId(dev.getNodeId()); + csTerminalLogs.setNodeProcess(dev.getNodeProcess()); + csTerminalLogs.setIsPush(1); + csTerminalLogsService.saveOrUpdate(csTerminalLogs); + //记录响应日志 + CsTerminalReply csTerminalReply = new CsTerminalReply(); + csTerminalReply.setId(IdUtil.simpleUUID()); + csTerminalReply.setReplyId(po.getId()); + csTerminalReply.setNodeId(dev.getNodeId()); + csTerminalReply.setProcessNo(dev.getNodeProcess()); + csTerminalReply.setDeviceId(dev.getId()); + csTerminalReply.setLineId(po.getLineId()); + csTerminalReply.setIsReceived(0); + csTerminalReply.setCode("oneFile"); + csTerminalReplyService.saveOrUpdate(csTerminalReply); + //发送消息 + bzEventMessageTemplate.sendMember(file,dev.getNodeId()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void bzEvent(List lineList, String startTime, String endTime) { + // 参数校验 + if (StrUtil.isBlank(startTime) || StrUtil.isBlank(endTime)) { + throw new BusinessException("开始时间和结束时间不能为空"); + } + LocalDateTime startLocalDate; + LocalDateTime endLocalDate; + try { + startLocalDate = LocalDateTimeUtil.parse(startTime, DatePattern.NORM_DATE_PATTERN); + endLocalDate = LocalDateTimeUtil.parse(endTime, DatePattern.NORM_DATE_PATTERN); + } catch (Exception e) { + throw new BusinessException("时间格式不正确,请使用 yyyy-MM-dd 格式"); + } + String beginDay = LocalDateTimeUtil.format( + LocalDateTimeUtil.beginOfDay(startLocalDate), + DatePattern.NORM_DATETIME_PATTERN + ); + String endDay = LocalDateTimeUtil.format( + LocalDateTimeUtil.endOfDay(endLocalDate), + DatePattern.NORM_DATETIME_PATTERN + ); + if (CollectionUtil.isNotEmpty(lineList)) { + processWithLineIds(lineList, beginDay, endDay); + } else { + processWithoutLineIds(beginDay, endDay); + } + } + + private void processWithLineIds(List lineList, String beginDay, String endDay) { + List csLineList = csLinePOService.listByIds(lineList); + List deviceIdList = csLineList.stream() + .map(CsLinePO::getDeviceId) + .distinct() + .collect(Collectors.toList()); + + List equipmentList = csEquipmentDeliveryService.listByIds(deviceIdList); + Map> devMap = equipmentList.stream() + .collect(Collectors.groupingBy(CsEquipmentDeliveryPO::getNodeId)); + + handleEventsAndLogs(devMap, csLineList, beginDay, endDay); + } + + private void processWithoutLineIds(String beginDay, String endDay) { + List devList = csEquipmentDeliveryService.getAllOnline(); + if (CollectionUtil.isEmpty(devList)) return; + + List deviceIds = devList.stream() + .map(CsEquipmentDeliveryPO::getId) + .collect(Collectors.toList()); + + List csLineList = csLinePOService.getLinesByDevList(deviceIds); + Map> devMap = devList.stream() + .collect(Collectors.groupingBy(CsEquipmentDeliveryPO::getNodeId)); + + handleEventsAndLogs(devMap, csLineList, beginDay, endDay); + } + + private void handleEventsAndLogs( + Map> devMap, + List csLineList, + String beginDay, + String endDay + ) { + devMap.forEach((nodeId, devices) -> { + List events = new ArrayList<>(); + List logsToSave = new ArrayList<>(); + List repliesToSave = new ArrayList<>(); + + for (CsEquipmentDeliveryPO device : devices) { + String uuid = IdUtil.simpleUUID(); + + BZEventMessage.Event event = buildEvent(uuid, device, csLineList, beginDay, endDay); + events.add(event); + + CsTerminalLogs log = buildTerminalLog(uuid, device, csLineList); + logsToSave.add(log); + + CsTerminalReply reply = buildTerminalReply(uuid, device, csLineList); + repliesToSave.add(reply); + } + csTerminalLogsService.saveBatch(logsToSave); + csTerminalReplyService.saveBatch(repliesToSave); + bzEventMessageTemplate.sendMember(events, nodeId); + }); + } + + private BZEventMessage.Event buildEvent(String guid, CsEquipmentDeliveryPO device, + List csLineList, String beginDay, String endDay) { + BZEventMessage.Event event = new BZEventMessage.Event(); + event.setGuid(guid); + event.setTerminalId(device.getId()); + + List monitorIds = csLineList.stream() + .filter(line -> Objects.equals(line.getDeviceId(), device.getId())) + .map(CsLinePO::getLineId) + .collect(Collectors.toList()); + + event.setMonitorIdList(monitorIds); + event.setDataType(1); + event.setTimeInterval(Collections.singletonList(beginDay + "~" + endDay)); + return event; + } + + private CsTerminalLogs buildTerminalLog(String id, CsEquipmentDeliveryPO device, + List csLineList) { + List lineIds = csLineList.stream() + .filter(line -> Objects.equals(line.getDeviceId(), device.getId())) + .map(CsLinePO::getLineId) + .collect(Collectors.toList()); + + CsTerminalLogs log = new CsTerminalLogs(); + log.setId(id); + log.setDeviceId(device.getId()); + log.setLineId(String.join(",", lineIds)); + log.setOperateType(3); + log.setNodeId(device.getNodeId()); + log.setNodeProcess(device.getNodeProcess()); + log.setIsPush(1); + return log; + } + + private CsTerminalReply buildTerminalReply(String replyId, CsEquipmentDeliveryPO device, + List csLineList) { + List lineIds = csLineList.stream() + .filter(line -> Objects.equals(line.getDeviceId(), device.getId())) + .map(CsLinePO::getLineId) + .collect(Collectors.toList()); + + CsTerminalReply reply = new CsTerminalReply(); + reply.setId(IdUtil.simpleUUID()); + reply.setReplyId(replyId); + reply.setNodeId(device.getNodeId()); + reply.setProcessNo(device.getNodeProcess()); + reply.setDeviceId(device.getId()); + reply.setLineId(String.join(",", lineIds)); + reply.setIsReceived(0); + reply.setCode("allEvent"); + return reply; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void bzFile(List lineList, String startTime, String endTime) { + String beginDay = LocalDateTimeUtil.format( + LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.parse(startTime, DatePattern.NORM_DATE_PATTERN)), + DatePattern.NORM_DATETIME_PATTERN + ); + String endDay = LocalDateTimeUtil.format( + LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.parse(endTime, DatePattern.NORM_DATE_PATTERN)), + DatePattern.NORM_DATETIME_PATTERN + ); + + // 获取监测点没有波形的事件信息 + List eventList = eventFeignClient.getEventByTime(lineList, beginDay, endDay).getData(); + if (CollUtil.isEmpty(eventList)) { + return; + } + + // 获取装置信息,用于区分不同服务器 + List deviceIds = eventList.stream() + .map(CsEventPO::getDeviceId) + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toList()); + + if (CollUtil.isEmpty(deviceIds)) { + return; + } + + List equipmentList = csEquipmentDeliveryService.listByIds(deviceIds); + if (CollUtil.isEmpty(equipmentList)) { + return; + } + + Map> nodeToDeviceMap = equipmentList.stream() + .collect(Collectors.groupingBy(CsEquipmentDeliveryPO::getNodeId)); + + // 构建 deviceId -> CsEventPO 映射,避免重复 filter + Map> deviceToEventMap = eventList.stream() + .filter(event -> event.getDeviceId() != null) + .collect(Collectors.groupingBy(CsEventPO::getDeviceId)); + + nodeToDeviceMap.forEach((nodeId, deviceList) -> { + List msgList = new ArrayList<>(); + List logList = new ArrayList<>(); + List replyList = new ArrayList<>(); + + for (CsEquipmentDeliveryPO device : deviceList) { + String deviceId = device.getId(); + List eventsForDevice = deviceToEventMap.getOrDefault(deviceId, Collections.emptyList()); + + Map> lineToEventMap = eventsForDevice.stream() + .filter(event -> event.getLineId() != null) + .collect(Collectors.groupingBy(CsEventPO::getLineId)); + + lineToEventMap.forEach((lineId, eventGroup) -> { + BZEventMessage.File event = new BZEventMessage.File(); + String guid = IdUtil.simpleUUID(); + event.setGuid(guid); + event.setTerminalId(deviceId); + event.setMonitorId(lineId); + event.setDataType(2); + + List timeList = eventGroup.stream() + .map(CsEventPO::getStartTime) + .filter(Objects::nonNull) + .map(dt -> dt.format(microsecondFormatter)) + .collect(Collectors.toList()); + + event.setTimeList(timeList); + msgList.add(event); + + // 记录发送日志 + CsTerminalLogs log = new CsTerminalLogs(); + log.setId(guid); + log.setDeviceId(deviceId); + log.setLineId(lineId); + log.setOperateType(3); + log.setNodeId(device.getNodeId()); + log.setNodeProcess(device.getNodeProcess()); + log.setIsPush(1); + logList.add(log); + + // 记录响应日志 + CsTerminalReply reply = new CsTerminalReply(); + reply.setId(IdUtil.simpleUUID()); + reply.setReplyId(guid); + reply.setNodeId(device.getNodeId()); + reply.setProcessNo(device.getNodeProcess()); + reply.setDeviceId(deviceId); + reply.setLineId(lineId); + reply.setIsReceived(0); + reply.setCode("allFile"); + replyList.add(reply); + }); + } + + if (CollUtil.isNotEmpty(logList)) { + csTerminalLogsService.saveBatch(logList); + } + if (CollUtil.isNotEmpty(replyList)) { + csTerminalReplyService.saveBatch(replyList); + } + if (CollUtil.isNotEmpty(msgList)) { + bzEventMessageTemplate.sendMember(msgList, nodeId); + } + }); } /** diff --git a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/EventFeignClient.java b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/EventFeignClient.java index e198f09..5f84903 100644 --- a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/EventFeignClient.java +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/EventFeignClient.java @@ -1,19 +1,24 @@ package com.njcn.csharmonic.api; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.common.pojo.annotation.OperateInfo; import com.njcn.common.pojo.constant.ServerInfo; +import com.njcn.common.pojo.enums.common.LogEnum; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.HttpResultUtil; import com.njcn.csdevice.pojo.vo.DataGroupEventVO; import com.njcn.csharmonic.api.fallback.EventFeignClientFallbackFactory; import com.njcn.csharmonic.param.CsEventUserQueryPage; import com.njcn.csharmonic.pojo.po.CsEventPO; -import com.njcn.csharmonic.pojo.vo.CsEventVO; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; -import java.time.LocalDateTime; import java.util.List; /** @@ -30,5 +35,9 @@ public interface EventFeignClient { @PostMapping("/queryByIndex") HttpResult queryByIndex(@RequestBody CsEventPO csEventPO); + @PostMapping("/queryById") + HttpResult queryById(@RequestParam("eventId") String eventId); - } + @PostMapping("/getEventByTime") + HttpResult> getEventByTime(@RequestParam(name = "lineList", required = false) List lineList,@RequestParam("startTime") String startTime,@RequestParam("endTime") String endTime); +} diff --git a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/fallback/EventFeignClientFallbackFactory.java b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/fallback/EventFeignClientFallbackFactory.java index 73a4159..ef7c9e0 100644 --- a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/fallback/EventFeignClientFallbackFactory.java +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/fallback/EventFeignClientFallbackFactory.java @@ -8,13 +8,10 @@ import com.njcn.csdevice.pojo.vo.DataGroupEventVO; import com.njcn.csharmonic.api.EventFeignClient; import com.njcn.csharmonic.param.CsEventUserQueryPage; import com.njcn.csharmonic.pojo.po.CsEventPO; -import com.njcn.csharmonic.pojo.vo.CsEventVO; import feign.hystrix.FallbackFactory; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.RequestBody; -import java.time.LocalDateTime; import java.util.List; /** @@ -49,6 +46,18 @@ public class EventFeignClientFallbackFactory implements FallbackFactory queryById(String eventId) { + log.error("{}异常,降级处理,异常为:{}","根据事件id查询数据",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + + @Override + public HttpResult> getEventByTime(List lineList, String startTime, String endTime) { + log.error("{}异常,降级处理,异常为:{}","根据时间获取无波形的暂态事件",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } }; } } diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/CsEventController.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/CsEventController.java index dc518ad..cab0502 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/CsEventController.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/CsEventController.java @@ -19,6 +19,7 @@ import com.njcn.event.file.pojo.dto.WaveDataDTO; 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.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -111,6 +112,16 @@ public class CsEventController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe); } + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/queryById") + @ApiOperation("根据事件id查询数据") + public HttpResult queryById(String eventId) { + String methodDescribe = getMethodDescribe("queryById"); + CsEventPO po = csEventPOService.lambdaQuery().eq(CsEventPO::getId,eventId).one(); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/queryByModelId") @ApiOperation("获取各模块事件") @@ -130,4 +141,18 @@ public class CsEventController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/getEventByTime") + @ApiOperation("根据时间获取无波形的暂态事件") + @ApiImplicitParams({ + @ApiImplicitParam(name = "lineList", value = "监测点id"), + @ApiImplicitParam(name = "startTime", value = "开始时间"), + @ApiImplicitParam(name = "endTime", value = "结束时间") + }) + public HttpResult> getEventByTime(@RequestParam(required = false) List lineList,@RequestParam String startTime,@RequestParam String endTime) { + String methodDescribe = getMethodDescribe("getEventByTime"); + List list = csEventPOService.getEventByTime(lineList,startTime,endTime); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + } diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventPOService.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventPOService.java index 7612b19..e7c639e 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventPOService.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventPOService.java @@ -11,6 +11,7 @@ import com.njcn.csharmonic.pojo.po.CsEventPO; import com.njcn.csharmonic.pojo.vo.CsEventVO; import com.njcn.csharmonic.pojo.vo.EventDetailVO; import com.njcn.event.file.pojo.dto.WaveDataDTO; +import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletResponse; import java.time.LocalDateTime; @@ -59,4 +60,6 @@ public interface CsEventPOService extends IService{ void addCldEvent(CldEventParam param); + List getEventByTime(List lineList, String startTime, String endTime); + } diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventPOServiceImpl.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventPOServiceImpl.java index 6cac06f..2b8afa5 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventPOServiceImpl.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventPOServiceImpl.java @@ -42,7 +42,6 @@ import com.njcn.influx.utils.InfluxDbUtils; import com.njcn.minioss.config.MinIossProperties; import com.njcn.minioss.util.MinIoUtils; import com.njcn.oss.constant.GeneralConstant; -import com.njcn.oss.constant.OssPath; import com.njcn.oss.utils.FileStorageUtil; import com.njcn.system.api.EleEvtFeignClient; import com.njcn.system.api.EpdFeignClient; @@ -62,7 +61,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; @@ -306,6 +304,18 @@ public class CsEventPOServiceImpl extends ServiceImpl getEventByTime(List lineList, String startTime, String endTime) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.between(CsEventPO::getStartTime,startTime,endTime) + .eq(CsEventPO::getType,0) + .isNull(CsEventPO::getWavePath); + if (CollUtil.isNotEmpty(lineList)) { + lambdaQueryWrapper.in(CsEventPO::getLineId,lineList); + } + return this.list(lambdaQueryWrapper); + } + public String getTag(Integer type) { String tag; switch (type) {