diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/constant/DataParam.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/constant/DataParam.java index 9784b03..5209abe 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/constant/DataParam.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/constant/DataParam.java @@ -56,12 +56,20 @@ public interface DataParam { String wlRecordPath = "test/"; - //中断标志 - List intrStr = Arrays.asList(0,26,40,54,68,82); - //暂降标志 - List dipStr = Arrays.asList(1,27,41,55,69,83); - //暂升标志 - List swlStr = Arrays.asList(13,36,50,64,78,92); + //中断标志及ele_epd_pqd表中中断事件ID、NAME + List intrStr = Arrays.asList((short)0,(short)26,(short)40,(short)54,(short)68,(short)82); + String intrStrId = "84aed85e7be48d59fcd59e1c8c8622ed"; + String intrStrName = "Evt_Sys_IntrStr"; + + //暂降标志及ele_epd_pqd表中暂降事件ID + List dipStr = Arrays.asList((short)1,(short)27,(short)41,(short)55,(short)69,(short)83); + String dipStrId = "145c96b0e2d359f7c1c00312eeeacaec"; + String dipStrName = "Evt_Sys_DipStr"; + + //暂升标志及ele_epd_pqd表中暂升事件ID + List swlStr = Arrays.asList((short)13,(short)36,(short)50,(short)64,(short)78,(short)92); + String swlStrId = "f9be85a431084a729748eee786ee1450"; + String swlStrName = "Evt_Sys_SwlStr"; String wlRecordUpload = "Offline_Data_Upload"; diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/PortableOfflLogServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/PortableOfflLogServiceImpl.java index 51479f4..3f5fc61 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/PortableOfflLogServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/PortableOfflLogServiceImpl.java @@ -3,21 +3,34 @@ package com.njcn.csdevice.service.impl; import cn.hutool.core.util.IdUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.csdevice.api.CsLineFeignClient; +import com.njcn.csdevice.api.EquipmentFeignClient; import com.njcn.csdevice.constant.DataParam; +import com.njcn.csdevice.enums.AlgorithmResponseEnum; import com.njcn.csdevice.mapper.PortableOfflLogMapper; +import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO; import com.njcn.csdevice.pojo.po.PortableOfflLog; import com.njcn.csdevice.service.IPortableOfflLogService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.csdevice.param.UploadDataParam; +import com.njcn.csharmonic.api.EventFeignClient; import com.njcn.csharmonic.api.OfflineDataUploadFeignClient; import com.njcn.csharmonic.offline.constant.OfflineConstant; +import com.njcn.csharmonic.offline.log.vo.NewHeadTaglogbuffer; import com.njcn.csharmonic.offline.log.vo.NewTaglogbuffer; import com.njcn.csharmonic.offline.mincfg.tagComtradeCfg; import com.njcn.csharmonic.offline.vo.Response; +import com.njcn.csharmonic.pojo.po.CsEventPO; +import com.njcn.influx.imapper.PqdDataMapper; import com.njcn.influx.pojo.po.cs.PqdData; +import com.njcn.influx.query.InfluxQueryWrapper; +import com.njcn.influx.utils.InfluxDbUtils; import com.njcn.oss.utils.FileStorageUtil; import com.njcn.system.api.DicDataFeignClient; +import com.njcn.system.api.EleEvtFeignClient; +import com.njcn.system.enums.DicDataEnum; import com.njcn.system.pojo.po.DictData; +import com.njcn.system.pojo.po.EleEvtParm; import com.njcn.web.pojo.param.BaseParam; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -28,6 +41,8 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** *

@@ -47,6 +62,16 @@ public class PortableOfflLogServiceImpl extends ServiceImpl queryPage(BaseParam baseParam) { Page returnpage = new Page<> (baseParam.getPageNum(), baseParam.getPageSize ()); @@ -95,6 +120,8 @@ public class PortableOfflLogServiceImpl extends ServiceImpl data1 = equipmentFeignClient.queryDeviceById(Stream.of(uploadDataParam.getDevId()).collect(Collectors.toList())).getData(); + //min文件夹下的文件是否解析过 boolean minFlag = true; //开始上传文件、记录上传日志、解析的文件结果入库 @@ -115,40 +142,90 @@ public class PortableOfflLogServiceImpl extends ServiceImpl pqdData = (List) response.getObj(); + //如果明确返回了state 那么当前文件解析出错 if(response.getState() != null){ portableOfflLog.setState(response.getState()); } if(pqdData != null && !pqdData.isEmpty()){ + //否则正常标记为成功解析 portableOfflLog.setState(1); portableOfflLog.setAllCount(pqdData.size()); + portableOfflLog.setRealCount(pqdData.size()); if(minFlag){ + //高频谐波数据入库 + //pqdDataMapper.insertBatch(pqdData); //min结果集解析入库后就不需要在解析了 minFlag = false; - portableOfflLog.setRealCount(pqdData.size()); } } }else if(file.getOriginalFilename().equals(response.getFilename())){ - //判断当前解析的数据属于哪种结果(目前来说三种:comtrade、log、min) - if(checkPrevsFolder(file.getOriginalFilename(),OfflineConstant.COMTRADE)!=null){ + //判断当前解析的数据属于哪种结果(目前来说三种:comtrade、log、min(除外)) + if(checkPrevsFolder(file.getOriginalFilename(),OfflineConstant.COMTRADE)!=null){ //cfg + //如果明确返回了state 那么当前文件解析出错 if(response.getState() != null){ portableOfflLog.setState(response.getState()); } tagComtradeCfg tagComtradeCfg = (tagComtradeCfg) response.getObj(); if(tagComtradeCfg != null){ + //否则正常标记为成功解析 portableOfflLog.setState(1); portableOfflLog.setAllCount(1); portableOfflLog.setRealCount(1); + //cfg入库 } } - if(checkPrevsFolder(file.getOriginalFilename(),OfflineConstant.LOG)!=null){ + if(checkPrevsFolder(file.getOriginalFilename(),OfflineConstant.LOG)!=null){ //事件 + //如果明确返回了state 那么当前文件解析出错 if(response.getState() != null){ portableOfflLog.setState(response.getState()); } List newTaglogbuffers = (List) response.getObj(); if(newTaglogbuffers != null && !newTaglogbuffers.isEmpty()){ + //否则正常标记为成功解析 portableOfflLog.setState(1); portableOfflLog.setAllCount(newTaglogbuffers.size()); portableOfflLog.setRealCount(newTaglogbuffers.size()); + + List csEventPOS = new ArrayList<>(); + //事件解析入库 + for(NewTaglogbuffer newTaglogbuffer : newTaglogbuffers){ + NewHeadTaglogbuffer newHeadTaglogbuffer = newTaglogbuffer.getNewHeadTaglogbuffer(); + String strId = ""; + String strName = ""; + //中断标志 + if(DataParam.intrStr.contains(newHeadTaglogbuffer.getLogCode())){ + strId = DataParam.intrStrId; + strName = DataParam.intrStrName; + } + //暂降标志 + if(DataParam.dipStr.contains(newHeadTaglogbuffer.getLogCode())){ + strId = DataParam.dipStrId; + strName = DataParam.dipStrName; + } + //暂升标志 + if(DataParam.swlStr.contains(newHeadTaglogbuffer.getLogCode())){ + strId = DataParam.swlStrId; + strName = DataParam.swlStrName; + } + List eleEvtParms = eleEvtFeignClient.queryByPid(strId).getData(); + //插入事件表 + CsEventPO csEventPO = new CsEventPO(); + csEventPO.setId(IdUtil.simpleUUID()); + csEventPO.setLineId(uploadDataParam.getLineId()); + csEventPO.setDeviceId(uploadDataParam.getDevId()); + csEventPO.setStartTime(newTaglogbuffer.getStart()); + csEventPO.setTag(strName); + //默认暂态事件 + csEventPO.setType(0); + csEventPO.setClDid(getClDidByLineId(uploadDataParam.getLineId())); + //默认告警等级2 + csEventPO.setLevel(2); + //默认事件发生位置:电网侧 + csEventPO.setLocation("grid"); + csEventPO.setProcess(data1.get(0).getProcess()); + csEventPOS.add(csEventPO); + } + //eventFeignClient.saveBatchEventList(csEventPOS); } } } @@ -157,6 +234,23 @@ public class PortableOfflLogServiceImpl extends ServiceImpl paths = Arrays.asList(filePath.split("/")); 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 new file mode 100644 index 0000000..7a34b90 --- /dev/null +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/EventFeignClient.java @@ -0,0 +1,21 @@ +package com.njcn.csharmonic.api; + +import com.njcn.common.pojo.constant.ServerInfo; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.csharmonic.api.fallback.EventFeignClientFallbackFactory; +import com.njcn.csharmonic.pojo.po.CsEventPO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import java.util.List; + +/** + * @author gfh + */ +@FeignClient(value = ServerInfo.CS_HARMONIC_BOOT, path = "/event", fallbackFactory = EventFeignClientFallbackFactory.class,contextId = "event") +public interface EventFeignClient { + + @PostMapping("/saveBatchEventList") + HttpResult saveBatchEventList(@RequestBody List csEventPOS); + +} 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 new file mode 100644 index 0000000..021321b --- /dev/null +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/api/fallback/EventFeignClientFallbackFactory.java @@ -0,0 +1,35 @@ +package com.njcn.csharmonic.api.fallback; + +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.csharmonic.api.EventFeignClient; +import com.njcn.csharmonic.pojo.po.CsEventPO; +import feign.hystrix.FallbackFactory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import java.util.List; + +/** + * @author gfh + */ +@Slf4j +@Component +public class EventFeignClientFallbackFactory implements FallbackFactory { + @Override + public EventFeignClient create(Throwable cause) { + //判断抛出异常是否为解码器抛出的业务异常 + Enum exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK; + if (cause.getCause() instanceof BusinessException) { + BusinessException businessException = (BusinessException) cause.getCause(); + } + Enum finalExceptionEnum = exceptionEnum; + return new EventFeignClient() { + @Override + public HttpResult saveBatchEventList(List csEventPOS) { + log.error("{}异常,降级处理,异常为:{}","获取当天事件未读消息未读消息",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + }; + } +} diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/EventController.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/EventController.java index 0ba8d9d..a467457 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/EventController.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/EventController.java @@ -6,6 +6,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; import com.njcn.csharmonic.param.CsEventUserQueryParam; +import com.njcn.csharmonic.pojo.po.CsEventPO; import com.njcn.csharmonic.pojo.vo.CsEventVO; import com.njcn.csharmonic.pojo.vo.EventDetailVO; import com.njcn.csharmonic.service.CsEventPOService; @@ -66,7 +67,13 @@ public class EventController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, eventVO, methodDescribe); } - - - + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @GetMapping("/saveBatchEventList") + @ApiOperation("批量新增事件") + @ApiImplicitParam(name = "csEventPOS", value = "事件集合", required = true) + public HttpResult saveBatchEventList(@RequestBody List csEventPOS) { + String methodDescribe = getMethodDescribe("saveBatchEventList"); + csEventPOService.saveBatchEventList(csEventPOS); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, 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 5cb5bbd..79773e1 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 @@ -39,4 +39,6 @@ public interface CsEventPOService extends IService{ CsEventVO getWavePics(String eventId, int i); List queryEventList(CsEventUserQueryParam csEventUserQueryParam); + + void saveBatchEventList(List csEventPOS); } 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 68100fa..ed64cce 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 @@ -35,6 +35,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.csharmonic.mapper.CsEventPOMapper; import com.njcn.csharmonic.pojo.po.CsEventPO; import com.njcn.csharmonic.service.CsEventPOService; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; @@ -110,6 +111,12 @@ public class CsEventPOServiceImpl extends ServiceImpl csEventPOS) { + this.saveBatch(csEventPOS); + } + /** * @return WaveDataDTO