diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/DevCapacityFeignClient.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/DevCapacityFeignClient.java index c2767d9..11f261d 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/DevCapacityFeignClient.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/DevCapacityFeignClient.java @@ -4,9 +4,12 @@ import com.njcn.common.pojo.constant.ServerInfo; import com.njcn.common.pojo.response.HttpResult; import com.njcn.csdevice.api.fallback.DevCapacityClientFallbackFactory; import com.njcn.csdevice.pojo.po.CsDevCapacityPO; +import io.swagger.annotations.ApiImplicitParam; +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.util.List; @@ -19,4 +22,7 @@ public interface DevCapacityFeignClient { @PostMapping("/addList") HttpResult> addList(@RequestBody List list); + @PostMapping("/getDevCapacity") + + HttpResult getDevCapacity(@RequestParam("id") String id); } diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/DevCapacityClientFallbackFactory.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/DevCapacityClientFallbackFactory.java index aecd916..9908f2d 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/DevCapacityClientFallbackFactory.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/DevCapacityClientFallbackFactory.java @@ -33,6 +33,12 @@ public class DevCapacityClientFallbackFactory implements FallbackFactory getDevCapacity(String id) { + log.error("{}异常,降级处理,异常为:{}","获取设备模块容量",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + }; } } diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java index da3d751..239d350 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java @@ -6,6 +6,7 @@ import com.github.tocrhz.mqtt.annotation.MqttSubscribe; import com.github.tocrhz.mqtt.annotation.NamedValue; import com.github.tocrhz.mqtt.annotation.Payload; import com.github.tocrhz.mqtt.publisher.MqttPublisher; +import com.njcn.csdevice.api.DevCapacityFeignClient; import com.njcn.csharmonic.param.CommonStatisticalQueryParam; import com.njcn.csharmonic.param.FrequencyStatisticalQueryParam; import com.njcn.csharmonic.pojo.vo.CsRtDataVO; @@ -52,6 +53,8 @@ public class MqttMessageHandler { private final RedisUtil redisUtil; private final TemperatureService temperatureService; + + private final DevCapacityFeignClient devCapacityFeignClient; private final DecimalFormat df = new DecimalFormat("#0.000"); /** * 实时数据应答 @@ -208,6 +211,24 @@ public class MqttMessageHandler { } }); + Double capacity = devCapacityFeignClient.getDevCapacity(devId).getData(); + //获取输出电流计算负载率 + List iTolOut = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_RmsI_TolOut(A)")).collect(Collectors.toList()); + iTolOut.forEach(temp->{ + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(temp,thdDataVO); + temp.setUnit("%"); + temp.setStatisticalName("load_Rate"); + if (capacity<=0){ + temp.setStatisticalData(3.1415926); + }else { + double v = temp.getStatisticalData() / capacity; + thdDataVO.setStatisticalData(Double.valueOf(df.format(v))); + + } + + }); + List notM = tempList.stream().filter(temp -> !Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); @@ -224,23 +245,150 @@ public class MqttMessageHandler { publisher.send("/zl/devData/"+devId,topoDataJson,1,false); } + +// @MqttSubscribe(value = "/zl/askDvrData/{devId}",qos = 1) +// public void responseDvrData(String topic, @NamedValue("devId") String devId, MqttMessage message, @Payload String payload) { +// String topoDataJson =redisUtil.getStringByKey (devId+"DVR"); +// if(StringUtils.isEmpty(topoDataJson)){ +// List result = new ArrayList<>(); +// List tempList = new ArrayList<>(); +// +// +// //1.查询DVR配置的指标:DVR配置:9fc1de386b623a1339977e168a23ad97 +// List data = csStatisticalSetFeignClient.queryStatisticalSelect("9fc1de386b623a1339977e168a23ad97").getData(); +// data.forEach(temp->{ +// if(Objects.nonNull(temp.getHarmStart())&&Objects.nonNull(temp.getHarmEnd())){ +// +// FrequencyStatisticalQueryParam frequencyStatisticalQueryParam = new FrequencyStatisticalQueryParam(); +// frequencyStatisticalQueryParam.setDevId(devId); +// frequencyStatisticalQueryParam.setStatisticalId(temp.getId()); +// frequencyStatisticalQueryParam.setValueType("avg"); +// frequencyStatisticalQueryParam.setFrequencyStart(temp.getHarmStart()); +// frequencyStatisticalQueryParam.setFrequencyEnd(temp.getHarmEnd()); +// List thdDataVOList = stableDataService.QuerySqlData(frequencyStatisticalQueryParam); +// tempList.addAll(thdDataVOList); +// +// }else { +// CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam(); +// commonStatisticalQueryParam.setDevId(devId); +// commonStatisticalQueryParam.setStatisticalId(temp.getId()); +// commonStatisticalQueryParam.setValueType("avg"); +// List listFuture= stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam); +// tempList.addAll(listFuture); +// } +// +// }); +// +// //过滤M相 +//// List m = tempList.stream().filter(temp -> Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); +//// m.stream().forEach(temp->{ +//// Stream.of("A","B","C").forEach(phase->{ +//// ThdDataVO thdDataVO = new ThdDataVO(); +//// BeanUtils.copyProperties(temp,thdDataVO); +//// thdDataVO.setPhase(phase); +//// result.add(thdDataVO); +//// }); +//// }); +//// //过滤谐波电流,谐波电压畸变率求平均值 +//// List thdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Pq_ThdU(%)")).collect(Collectors.toList()); +//// Map> collect = thdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); +//// collect.forEach((k,v)->{ +//// if(!CollectionUtil.isEmpty(v)){ +//// double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); +//// ThdDataVO thdDataVO = new ThdDataVO(); +//// BeanUtils.copyProperties(v.get(0),thdDataVO); +//// thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); +//// thdDataVO.setPhase("avg"); +//// result.add(thdDataVO); +//// +//// } +//// }); +//// +//// List thdV = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Pq_ThdI(%)")).collect(Collectors.toList()); +//// Map> collect1 = thdV.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); +//// collect1.forEach((k,v)->{ +//// if(!CollectionUtil.isEmpty(v)){ +//// double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); +//// ThdDataVO thdDataVO = new ThdDataVO(); +//// BeanUtils.copyProperties(v.get(0),thdDataVO); +//// thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); +//// thdDataVO.setPhase("avg"); +//// result.add(thdDataVO); +//// +//// } +//// }); +//// List apfThdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Load(%)")).collect(Collectors.toList()); +//// Map> collect3 = apfThdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); +//// collect3.forEach((k,v)->{ +//// if(!CollectionUtil.isEmpty(v)){ +//// double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); +//// ThdDataVO thdDataVO = new ThdDataVO(); +//// BeanUtils.copyProperties(v.get(0),thdDataVO); +//// thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); +//// thdDataVO.setPhase("avg"); +//// result.add(thdDataVO); +//// +//// } +//// }); +//// List apfRmsI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_RmsI_TolOut(A)")).collect(Collectors.toList()); +//// Map> collect2 = apfRmsI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); +//// collect2.forEach((k,v)->{ +//// if(!CollectionUtil.isEmpty(v)){ +//// double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); +//// ThdDataVO thdDataVO = new ThdDataVO(); +//// BeanUtils.copyProperties(v.get(0),thdDataVO); +//// thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); +//// thdDataVO.setPhase("avg"); +//// result.add(thdDataVO); +//// +//// } +//// }); +//// List apfThdISys = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Sys(%)")).collect(Collectors.toList()); +//// Map> collect4 = apfThdISys.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); +//// collect4.forEach((k,v)->{ +//// if(!CollectionUtil.isEmpty(v)){ +//// double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); +//// ThdDataVO thdDataVO = new ThdDataVO(); +//// BeanUtils.copyProperties(v.get(0),thdDataVO); +//// thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); +//// thdDataVO.setPhase("avg"); +//// result.add(thdDataVO); +//// +//// } +//// }); +//// +//// List notM = tempList.stream().filter(temp -> !Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); +// +// result.addAll(tempList); +// +// +// +// Gson gson = new Gson(); +// topoDataJson = gson.toJson(result); +// redisUtil.saveByKeyWithExpire(devId+"DVR", (Object) topoDataJson,Long.valueOf(10*60)); +// } +// +// +// publisher.send("/zl/DvrData/"+devId,topoDataJson,1,false); +// } + public String getCldidName( String cldid) { switch (cldid) { case "0": return "主模块"; case "1": - return "模块1"; + return "APF模块 1"; case "2": - return "模块2"; + return "APF模块 2"; case "3": - return "模块3"; + return "APF模块 3"; case "4": - return "模块4"; + return "APF模块 4"; case "5": - return "模块5"; + return "APF模块 5"; case "6": - return "模块6"; + return "APF模块 6"; default: break; }