From 2662d3a139f8be54ad56d9996420c3969e02eff7 Mon Sep 17 00:00:00 2001 From: xuyang <748613696@qq.com> Date: Mon, 11 Jul 2022 20:36:37 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=94=B5=E8=83=BD=E8=B4=A8=E9=87=8F=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B0=83=E6=95=B4=202.=E5=BE=AE=E6=9C=8D=E5=8A=A1-?= =?UTF-8?q?=E7=9B=91=E6=B5=8B=E7=82=B9=E6=95=B0=E6=8D=AE=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E6=80=A7=E8=B0=83=E7=94=A8=E4=B8=AD=E5=BF=83=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=203.=E5=88=86=E5=B8=83=E5=BC=8F=E5=85=89=E4=BC=8F=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=8E=A5=E5=8F=A3=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../influxdb/param/InfluxDBPublicParam.java | 7 + .../com/njcn/web/constant/ValidMessage.java | 2 + .../com/njcn/device/api/LineFeignClient.java | 12 + .../LineFeignClientFallbackFactory.java | 8 +- .../device/controller/LineController.java | 22 + .../njcn/device/mapper/LineDetailMapper.java | 8 + .../mapper/mapping/LineDetailMapper.xml | 22 + .../harmonic/enums/HarmonicResponseEnum.java | 3 +- .../harmonic/pojo/photoVO/WarningAreaVO.java | 68 +++ .../pojo/photoVO/WarningMonitorVO.java | 64 +++ .../controller/PhotovoltaicController.java | 150 ++++++ .../harmonic/service/PhotovoltaicService.java | 32 ++ .../service/impl/AnalyzeServiceImpl.java | 2 - .../service/impl/PhotovoltaicServiceImpl.java | 443 ++++++++++++++++++ .../njcn/executor/handler/PollutionJob.java | 30 +- .../executor/handler/PqsIntegrityJob.java | 178 +++++++ .../executor/handler/PqsOnlineRateJob.java | 29 ++ .../njcn/executor/pojo/vo/PqsIntegrity.java | 31 ++ .../src/main/resources/bootstrap.yml | 4 +- pqs-job/job-executor/src/test/java/Test1.java | 56 +++ .../quality/enums/EnergyResponseEnum.java | 4 +- .../quality/param/UpdateDeviceVersion.java | 32 ++ .../quality/pojo/dto/AskDataParamDTO.java | 2 + pqs-quality/quality-boot/Dockerfile | 6 + .../quality/controller/ModelController.java | 19 +- .../quality/handler/MqttMessageHandler.java | 39 +- .../njcn/quality/service/IModelService.java | 12 + .../service/impl/ModelServiceImpl.java | 88 +++- 28 files changed, 1333 insertions(+), 40 deletions(-) create mode 100644 pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/photoVO/WarningAreaVO.java create mode 100644 pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/photoVO/WarningMonitorVO.java create mode 100644 pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/PhotovoltaicController.java create mode 100644 pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/PhotovoltaicService.java create mode 100644 pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/PhotovoltaicServiceImpl.java create mode 100644 pqs-job/job-executor/src/main/java/com/njcn/executor/handler/PqsIntegrityJob.java create mode 100644 pqs-job/job-executor/src/main/java/com/njcn/executor/handler/PqsOnlineRateJob.java create mode 100644 pqs-job/job-executor/src/main/java/com/njcn/executor/pojo/vo/PqsIntegrity.java create mode 100644 pqs-job/job-executor/src/test/java/Test1.java create mode 100644 pqs-quality/quality-api/src/main/java/com/njcn/quality/param/UpdateDeviceVersion.java create mode 100644 pqs-quality/quality-boot/Dockerfile diff --git a/pqs-common/common-influxdb/src/main/java/com/njcn/influxdb/param/InfluxDBPublicParam.java b/pqs-common/common-influxdb/src/main/java/com/njcn/influxdb/param/InfluxDBPublicParam.java index 2f4b6db3e..d052bef1f 100644 --- a/pqs-common/common-influxdb/src/main/java/com/njcn/influxdb/param/InfluxDBPublicParam.java +++ b/pqs-common/common-influxdb/src/main/java/com/njcn/influxdb/param/InfluxDBPublicParam.java @@ -163,6 +163,8 @@ public interface InfluxDBPublicParam { * 时区 */ String TIME_ZONE = " tz('Asia/Shanghai')"; + String TZ = "Asia/Shanghai"; + /** * 日起始时间 @@ -261,4 +263,9 @@ public interface InfluxDBPublicParam { */ String PHASIC_TYPET = "T"; + /** + * 每天固定时间分钟 + */ + Integer DAY_MINUTE = 1440; + } diff --git a/pqs-common/common-web/src/main/java/com/njcn/web/constant/ValidMessage.java b/pqs-common/common-web/src/main/java/com/njcn/web/constant/ValidMessage.java index 857d62e4a..b38182196 100644 --- a/pqs-common/common-web/src/main/java/com/njcn/web/constant/ValidMessage.java +++ b/pqs-common/common-web/src/main/java/com/njcn/web/constant/ValidMessage.java @@ -60,4 +60,6 @@ public interface ValidMessage { String IP_FORMAT_ERROR = "IP格式非法"; + String DEVICE_VERSION_NOT_BLANK = "装置版本json文件不能为空,请检查deviceVersionFile参数"; + } diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/api/LineFeignClient.java b/pqs-device/device-api/src/main/java/com/njcn/device/api/LineFeignClient.java index 64162fb92..6508ad899 100644 --- a/pqs-device/device-api/src/main/java/com/njcn/device/api/LineFeignClient.java +++ b/pqs-device/device-api/src/main/java/com/njcn/device/api/LineFeignClient.java @@ -5,6 +5,7 @@ import com.njcn.common.pojo.response.HttpResult; import com.njcn.device.api.fallback.LineFeignClientFallbackFactory; import com.njcn.device.pojo.dto.*; import com.njcn.device.pojo.po.Line; +import com.njcn.device.pojo.po.LineDetail; import com.njcn.device.pojo.po.Overlimit; import com.njcn.device.pojo.vo.*; import org.apache.commons.collections.map.MultiValueMap; @@ -189,4 +190,15 @@ public interface LineFeignClient { */ @PostMapping("getBaseLineList") HttpResult> getBaseLineList(@RequestBody List list); + + /** + * 功能描述: 获取指定条件的监测点信息 + * @param list 监测点id集合 + * @author xy + * @date 2022/7/8 14:24 + * @return 监测点详情集合 + */ + @PostMapping("getLineDetail") + HttpResult> getLineDetail(@RequestParam(required = false,value = "list") List list); + } diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/api/fallback/LineFeignClientFallbackFactory.java b/pqs-device/device-api/src/main/java/com/njcn/device/api/fallback/LineFeignClientFallbackFactory.java index ad99572ba..fc88ba0c5 100644 --- a/pqs-device/device-api/src/main/java/com/njcn/device/api/fallback/LineFeignClientFallbackFactory.java +++ b/pqs-device/device-api/src/main/java/com/njcn/device/api/fallback/LineFeignClientFallbackFactory.java @@ -6,12 +6,14 @@ import com.njcn.common.pojo.response.HttpResult; import com.njcn.device.api.LineFeignClient; import com.njcn.device.pojo.dto.*; import com.njcn.device.pojo.po.Line; +import com.njcn.device.pojo.po.LineDetail; import com.njcn.device.pojo.po.Overlimit; import com.njcn.device.pojo.vo.*; import com.njcn.device.utils.DeviceEnumUtil; import feign.hystrix.FallbackFactory; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -147,7 +149,11 @@ public class LineFeignClientFallbackFactory implements FallbackFactory> getLineDetail(List list) { + log.error("{}异常,降级处理,异常为:{}", "获取监测点详情 ", throwable.toString()); + throw new BusinessException(finalExceptionEnum); + } }; diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/controller/LineController.java b/pqs-device/device-boot/src/main/java/com/njcn/device/controller/LineController.java index 8763cb028..5a11894c7 100644 --- a/pqs-device/device-boot/src/main/java/com/njcn/device/controller/LineController.java +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/controller/LineController.java @@ -7,10 +7,12 @@ import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; import com.njcn.common.utils.LogUtil; import com.njcn.device.mapper.DeviceMapper; +import com.njcn.device.mapper.LineDetailMapper; import com.njcn.device.mapper.LineMapper; import com.njcn.device.pojo.dto.*; import com.njcn.device.pojo.po.Device; import com.njcn.device.pojo.po.Line; +import com.njcn.device.pojo.po.LineDetail; import com.njcn.device.pojo.po.Overlimit; import com.njcn.device.pojo.vo.*; import com.njcn.device.service.LineService; @@ -42,6 +44,9 @@ public class LineController extends BaseController { private final LineMapper lineMapper; + private final LineDetailMapper lineDetailMapper; + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/getLineDetailData") @ApiOperation("根据监测点id获取监测点详情") @@ -256,4 +261,21 @@ public class LineController extends BaseController { String methodDescribe = getMethodDescribe("getBaseLineList"); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineService.getBaseLineList(lineIndex), methodDescribe); } + + /** + * 功能描述: 获取指定条件的监测点信息 + * @author xy + * @date 2022/7/8 14:24 + * @return 监测点详情集合 + */ + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/getLineDetail") + @ApiOperation("根据监测点集合获取监测点详情") + @ApiImplicitParam(name = "list", value = "监测点集合") + public HttpResult> getLineDetail(@RequestParam(required = false) List list) { + String methodDescribe = getMethodDescribe("getLineDetail"); + LogUtil.njcnDebug(log, "{},监测点集合:{}", methodDescribe, list); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineDetailMapper.getSpecifyLineDetail(list), methodDescribe); + } + } diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/LineDetailMapper.java b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/LineDetailMapper.java index 77b8efdbe..b2695ba85 100644 --- a/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/LineDetailMapper.java +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/LineDetailMapper.java @@ -25,4 +25,12 @@ public interface LineDetailMapper extends BaseMapper { */ List getLineDetail(@Param("devIndex") String devIndex, @Param("num") List num); + /** + * 实际设备下的监测点&&稳态系统和两个系统的监测点&&投运终端下的监测点 + * 获取指定条件的监测点信息 + * @param list 监测点集合 + * @return 结果 + */ + List getSpecifyLineDetail(@Param("list") List list); + } diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/LineDetailMapper.xml b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/LineDetailMapper.xml index ae1998e74..b52729183 100644 --- a/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/LineDetailMapper.xml +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/LineDetailMapper.xml @@ -14,4 +14,26 @@ + diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/enums/HarmonicResponseEnum.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/enums/HarmonicResponseEnum.java index 2196780cc..63715cfa6 100644 --- a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/enums/HarmonicResponseEnum.java +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/enums/HarmonicResponseEnum.java @@ -15,7 +15,8 @@ public enum HarmonicResponseEnum { * A00550 ~ A00649 */ HARMONIC_COMMON_ERROR("A00550","谐波模块异常"), - LIMIT_RATE_ERROR("A00551","稳态监测点数据异常") + + LIMIT_MISSING_ERROR("A00551","limit_rate表缺失限值数据") ; private final String code; diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/photoVO/WarningAreaVO.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/photoVO/WarningAreaVO.java new file mode 100644 index 000000000..2f5571c57 --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/photoVO/WarningAreaVO.java @@ -0,0 +1,68 @@ +package com.njcn.harmonic.pojo.photoVO; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/7/7 9:32 + */ +@Data +public class WarningAreaVO implements Serializable { + + @ApiModelProperty("区域id") + private String id; + + @ApiModelProperty("区域名称") + private String name; + + @ApiModelProperty("在线监测点数量(个)") + private Integer onlineMonitorCounts = 0; + + @ApiModelProperty("告警监测点数量(个)") + private Integer alertMonitorCounts = 0; + + @ApiModelProperty("告警次数") + private Integer alertCounts = 0; + + @ApiModelProperty("告警频次(次/点)") + private Double alertAlarmFrequency = -1.0; + + @ApiModelProperty("频率偏差") + private Double frequencyDeviation = -1.0; + + @ApiModelProperty("电压偏差") + private Double voltageDeviation = -1.0; + + @ApiModelProperty("谐波电压") + private Double harmonicVoltage = -1.0; + + @ApiModelProperty("谐波电流") + private Double harmonicCurrent = -1.0; + + @ApiModelProperty("三相电压不平衡") + private Double threePhaseVoltageUnbalance = -1.0; + + @ApiModelProperty("闪变") + private Double flicker = -1.0; + + @ApiModelProperty("间谐波电压") + private Double interHarmonic = -1.0; + + @ApiModelProperty("负序电流") + private Double negative = -1.0; + + @ApiModelProperty("短时中断") + private Double shortInterruption = -1.0; + + @ApiModelProperty("电压暂降") + private Double voltageDip = -1.0; + + @ApiModelProperty("电压暂升") + private Double voltageSwell = -1.0; +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/photoVO/WarningMonitorVO.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/photoVO/WarningMonitorVO.java new file mode 100644 index 000000000..172137aaa --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/photoVO/WarningMonitorVO.java @@ -0,0 +1,64 @@ +package com.njcn.harmonic.pojo.photoVO; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/7/7 14:24 + */ +@Data +public class WarningMonitorVO implements Serializable { + + @ApiModelProperty("监测点id") + private String id; + + @ApiModelProperty("监测点名称") + private String name; + + @ApiModelProperty("告警次数") + private Integer alertCounts = 0; + + @ApiModelProperty("告警频次(次/点)") + private Double alertAlarmFrequency = -1.0; + + @ApiModelProperty("频率偏差") + private Double frequencyDeviation = -1.0; + + @ApiModelProperty("电压偏差") + private Double voltageDeviation = -1.0; + + @ApiModelProperty("谐波电压") + private Double harmonicVoltage = -1.0; + + @ApiModelProperty("谐波电流") + private Double harmonicCurrent = -1.0; + + @ApiModelProperty("三相电压不平衡") + private Double threePhaseVoltageUnbalance = -1.0; + + @ApiModelProperty("闪变") + private Double flicker = -1.0; + + @ApiModelProperty("间谐波电压") + private Double interHarmonic = -1.0; + + @ApiModelProperty("负序电流") + private Double negative = -1.0; + + @ApiModelProperty("短时中断") + private Double shortInterruption = -1.0; + + @ApiModelProperty("电压暂降") + private Double voltageDip = -1.0; + + @ApiModelProperty("电压暂升") + private Double voltageSwell = -1.0; + + +} diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/PhotovoltaicController.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/PhotovoltaicController.java new file mode 100644 index 000000000..0e8d3a9a7 --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/PhotovoltaicController.java @@ -0,0 +1,150 @@ +package com.njcn.harmonic.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.common.pojo.annotation.OperateInfo; +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.common.utils.LogUtil; +import com.njcn.device.pojo.param.DeviceInfoParam; +import com.njcn.harmonic.pojo.param.HistoryParam; +import com.njcn.harmonic.pojo.photoVO.WarningAreaVO; +import com.njcn.harmonic.pojo.photoVO.WarningMonitorVO; +import com.njcn.harmonic.pojo.vo.*; +import com.njcn.harmonic.service.HistoryResultService; +import com.njcn.harmonic.service.IAnalyzeService; +import com.njcn.harmonic.service.PhotovoltaicService; +import com.njcn.harmonic.service.SteadyQualifyService; +import com.njcn.web.controller.BaseController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/7/5 10:37 + */ +@Validated +@Slf4j +@RestController +@RequestMapping("/photovoltaicHarmonic") +@Api(tags = "分布式光伏-稳态") +@AllArgsConstructor +public class PhotovoltaicController extends BaseController { + + private final IAnalyzeService IAnalyzeService; + + private final SteadyQualifyService steadyQualifyService; + + private final HistoryResultService historyResultService; + + private final PhotovoltaicService photovoltaicService; + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/overAreaStatistics") + @ApiOperation("稳态指标超标统计") + @ApiImplicitParam(name = "param", value = "实体参数", required = true) + public HttpResult> overAreaStatistics(@Validated @RequestBody OverAreaVO param) { + String methodDescribe = getMethodDescribe("overAreaStatistics"); + LogUtil.njcnDebug(log, "{},实体参数:{}", methodDescribe, param); + Page list = IAnalyzeService.getAreaData(param); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/test") + @ApiOperation("有问题-稳态指标超标分类统计") + @ApiImplicitParam(name = "param", value = "实体参数", required = true) + public HttpResult> test(@Validated @RequestBody OverAreaVO param) { + String methodDescribe = getMethodDescribe("overAreaStatistics"); + LogUtil.njcnDebug(log, "{},实体参数:{}", methodDescribe, param); + Page list = IAnalyzeService.getAreaData(param); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/lineOverLimit") + @ApiOperation("稳态指标超标明细") + @ApiImplicitParam(name = "param", value = "实体参数", required = true) + public HttpResult> lineOverLimit(@Validated @RequestBody OverAreaVO param) { + String methodDescribe = getMethodDescribe("lineOverLimit"); + LogUtil.njcnDebug(log, "{},实体参数:{}", methodDescribe, param); + Page list = IAnalyzeService.monitorOverLimitVO(param); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/getSteadyQualifyData") + @ApiOperation("稳态合格率统计") + @ApiImplicitParam(name = "steadyParam", value = "稳态列表参数", required = true) + public HttpResult> getSteadyQualifyData(@RequestBody @Validated DeviceInfoParam.BusinessParam steadyParam){ + String methodDescribe = getMethodDescribe("getSteadyQualifyData"); + List list = steadyQualifyService.getSteadyQualifyData(steadyParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/getHistoryResult") + @ApiOperation("稳态指标历史趋势") + @ApiImplicitParam(name = "historyParam", value = "稳态数据分析参数", required = true) + public HttpResult> getHistoryResult(@RequestBody @Validated HistoryParam historyParam) { + String methodDescribe = getMethodDescribe("getHistoryResult"); + List list = historyResultService.getHistoryResult(historyParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/wholeEvaluation") + @ApiOperation("有问题-全网水平评价") + @ApiImplicitParam(name = "param", value = "实体参数", required = true) + public HttpResult> wholeEvaluation(@Validated @RequestBody OverAreaVO param) { + String methodDescribe = getMethodDescribe("wholeEvaluation"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/areaWithEvaluation") + @ApiOperation("有问题-台区水平评价") + @ApiImplicitParam(name = "param", value = "实体参数", required = true) + public HttpResult> areaWithEvaluation(@Validated @RequestBody OverAreaVO param) { + String methodDescribe = getMethodDescribe("areaWithEvaluation"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/areaWarningManage") + @ApiOperation("区域告警管理") + @ApiImplicitParam(name = "param", value = "实体参数", required = true) + public HttpResult> areaWarningManage(@Validated @RequestBody OverAreaVO param) { + String methodDescribe = getMethodDescribe("areaWarningManage"); + Page page = photovoltaicService.areaWarningManage(param); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/monitorWarningManage") + @ApiOperation("监测点告警管理") + @ApiImplicitParam(name = "param", value = "实体参数", required = true) + public HttpResult> monitorWarningManage(@Validated @RequestBody OverAreaVO param) { + String methodDescribe = getMethodDescribe("monitorWarningManage"); + Page page = photovoltaicService.monitorWarningManage(param); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe); + } + + + +} diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/PhotovoltaicService.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/PhotovoltaicService.java new file mode 100644 index 000000000..4de896fa5 --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/PhotovoltaicService.java @@ -0,0 +1,32 @@ +package com.njcn.harmonic.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.harmonic.pojo.photoVO.WarningAreaVO; +import com.njcn.harmonic.pojo.photoVO.WarningMonitorVO; +import com.njcn.harmonic.pojo.vo.OverAreaVO; + +/** + * @author 徐扬 + */ +public interface PhotovoltaicService { + + /** + * 功能描述:区域告警管理 + * @author xy + * @param param 参数 + * @date 2022/7/7 9:48 + * @return 分页数据 + */ + Page areaWarningManage(OverAreaVO param); + + /** + * 功能描述:监测点告警管理 + * @author xy + * @param param 参数 + * @date 2022/7/7 9:48 + * @return 分页数据 + */ + Page monitorWarningManage(OverAreaVO param); + + +} diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/AnalyzeServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/AnalyzeServiceImpl.java index e42dd4204..913e8ba26 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/AnalyzeServiceImpl.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/AnalyzeServiceImpl.java @@ -152,8 +152,6 @@ public class AnalyzeServiceImpl implements IAnalyzeService { LimitRate limitRate = map.get(item2).get(0); if (!Objects.isNull(limitRate)){ onlineMonitorCount++; - System.out.println("1==:" + limitRate.getFreqDevOverTime()); - System.out.println("2==:" + limitRate.getVoltageDevOverTime()); if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0){ alertMonitorCount++; } diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/PhotovoltaicServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/PhotovoltaicServiceImpl.java new file mode 100644 index 000000000..e4379a518 --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/PhotovoltaicServiceImpl.java @@ -0,0 +1,443 @@ +package com.njcn.harmonic.service.impl; + +import com.alibaba.nacos.shaded.com.google.common.collect.Lists; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.device.api.GeneralDeviceInfoClient; +import com.njcn.device.api.LineFeignClient; +import com.njcn.device.pojo.dto.GeneralDeviceDTO; +import com.njcn.device.pojo.dto.OverLimitLineDTO; +import com.njcn.device.pojo.dto.PollutionParamDTO; +import com.njcn.device.pojo.dto.WarningSubstationDTO; +import com.njcn.harmonic.constant.Param; +import com.njcn.harmonic.enums.HarmonicResponseEnum; +import com.njcn.harmonic.pojo.photoVO.WarningAreaVO; +import com.njcn.harmonic.pojo.photoVO.WarningMonitorVO; +import com.njcn.harmonic.pojo.po.EventDetail; +import com.njcn.harmonic.pojo.po.LimitRate; +import com.njcn.harmonic.pojo.po.LimitTarget; +import com.njcn.harmonic.pojo.vo.OverAreaVO; +import com.njcn.harmonic.service.PhotovoltaicService; +import com.njcn.influxdb.utils.InfluxDbUtils; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.influxdb.dto.QueryResult; +import org.influxdb.impl.InfluxDBResultMapper; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/7/7 9:26 + */ +@Slf4j +@Service +@AllArgsConstructor +public class PhotovoltaicServiceImpl implements PhotovoltaicService { + + private final GeneralDeviceInfoClient generalDeviceInfoClient; + + private final InfluxDbUtils influxDbUtils; + + private final LineFeignClient lineFeignClient; + + @Override + @SuppressWarnings("unchecked") + public Page areaWarningManage(OverAreaVO param) { + List line = new ArrayList<>(); + Map> map = new HashMap<>(); + Map> map2 = new HashMap<>(); + Page page = new Page<>(); + List list = new ArrayList<>(); + page.setSize(param.getPageSize()); + page.setCurrent(param.getPageNum()); + List subList = generalDeviceInfoClient.getPracticalRunDeviceInfo(param).getData(); + if (!CollectionUtils.isEmpty(subList)){ + page.setTotal(subList.size()); + int pages = (int)Math.ceil(subList.size()*1.0/param.getPageSize()); + page.setPages(pages); + List> pageList = Lists.partition(subList,param.getPageSize()); + List temList = pageList.get(param.getPageNum()-1); + temList.forEach(item->{ + line.addAll(item.getLineIndexes()); + }); + if (!CollectionUtils.isEmpty(line)){ + List limitRateList = (List)getAllData(line,param.getSearchBeginTime(),param.getSearchEndTime(), Param.LIMIT_RATE); + if (!CollectionUtils.isEmpty(limitRateList)){ + map = limitRateList.stream().collect(Collectors.groupingBy(LimitRate::getLineId)); + } + List eventDetailList = getEventDetail(line,param.getSearchBeginTime(),param.getSearchEndTime()); + if (!CollectionUtils.isEmpty(eventDetailList)){ + map2 = eventDetailList.stream().collect(Collectors.groupingBy(EventDetail::getLineId)); + } + } + if (!CollectionUtils.isEmpty(temList)){ + for (GeneralDeviceDTO item : temList) { + int onlineMonitorCount = 0,alertMonitorCount = 0,alertCount = 0,freqCount = 0,voltageCount = 0,ubalanceCount = 0,flickerCount = 0,iNegCount = 0,uharmCount = 0,iharmCount = 0,inuharmCount = 0; + int freqCounts = 0,voltageCounts = 0,uharmCounts = 0,iharmCounts = 0,ubalanceCounts = 0,flickerCounts = 0,inuharmCounts = 0,iNegCounts = 0; + int eventUp = 0,eventDown = 0,eventInterrupt = 0,eventUps = 0,eventDowns = 0,eventInterrupts = 0; + WarningAreaVO warningAreaVO = new WarningAreaVO(); + //单位id + warningAreaVO.setId(item.getIndex()); + //单位名称 + warningAreaVO.setName(item.getName()); + if (!CollectionUtils.isEmpty(item.getLineIndexes())){ + for (String item2 : item.getLineIndexes()) { + //谐波统计 + if (!CollectionUtils.isEmpty(map.get(item2))){ + LimitRate limitRate = map.get(item2).get(0); + if (!Objects.isNull(limitRate)){ + onlineMonitorCount++; + if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0){ + alertMonitorCount++; + } + if (limitRate.getFreqDevOverTime() > 0){ + freqCount++; + freqCounts = freqCounts + limitRate.getFreqDevOverTime(); + } + if (limitRate.getVoltageDevOverTime() > 0){ + voltageCount++; + voltageCounts = voltageCounts + limitRate.getVoltageDevOverTime(); + } + if (limitRate.getUHarm2OverTime() > 0){ + uharmCount++; + uharmCounts = uharmCounts + limitRate.getUHarm2OverTime(); + } + if (limitRate.getIHarm2OverTime() > 0){ + iharmCount++; + iharmCounts = iharmCounts + limitRate.getIHarm2OverTime(); + } + if (limitRate.getUBalanceOverTime() > 0){ + ubalanceCount++; + ubalanceCounts = ubalanceCounts + limitRate.getUBalanceOverTime(); + } + if (limitRate.getFlickerOverTime() > 0){ + flickerCount++; + flickerCounts = flickerCounts + limitRate.getFlickerOverTime(); + } + if (limitRate.getInuHarm1OverTime() > 0){ + inuharmCount++; + inuharmCounts = inuharmCounts + limitRate.getInuHarm1OverTime(); + } + if (limitRate.getINegOverTime() > 0){ + iNegCount++; + iNegCounts = iNegCounts + limitRate.getINegOverTime(); + } + alertCount = limitRate.getFreqDevOverTime() + limitRate.getVoltageDevOverTime() + limitRate.getUBalanceOverTime() + limitRate.getFlickerOverTime() + limitRate.getINegOverTime() + limitRate.getUHarm2OverTime() + limitRate.getIHarm2OverTime() + limitRate.getInuHarm1OverTime(); + } else { + log.info("此监测点在限值表中无数据:" + item2); + throw new BusinessException(HarmonicResponseEnum.LIMIT_MISSING_ERROR); + } + } + //暂降统计 + if (!CollectionUtils.isEmpty(map2.get(item2))){ + List eventDetailList = map2.get(item2); + if (!CollectionUtils.isEmpty(eventDetailList)){ + for (EventDetail item3 : eventDetailList) { + if (item3.getWaveType() == 1){ + eventDowns++; + } else if (item3.getWaveType() == 2){ + eventUps++; + } else if (item3.getWaveType() == 3){ + eventInterrupts++; + } + } + } + } + if (eventDowns > 0){ + eventDown++; + } + if (eventUps > 0){ + eventUp++; + } + if (eventInterrupts > 0){ + eventInterrupt++; + } + } + } + //在线监测点数量(个) + warningAreaVO.setOnlineMonitorCounts(onlineMonitorCount); + if (onlineMonitorCount != 0){ + //告警监测点数量(个) + warningAreaVO.setAlertMonitorCounts(alertMonitorCount); + //告警次数 + warningAreaVO.setAlertCounts(alertCount); + //告警频次(次/点) + warningAreaVO.setAlertAlarmFrequency(alertMonitorCount==0?0: BigDecimal.valueOf(alertCount*1.0/alertMonitorCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //频率偏差 + warningAreaVO.setFrequencyDeviation(freqCount==0?0:BigDecimal.valueOf(freqCounts*1.0/freqCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //电压偏差 + warningAreaVO.setVoltageDeviation(voltageCount==0?0:BigDecimal.valueOf(voltageCounts*1.0/voltageCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //谐波电压 + warningAreaVO.setHarmonicVoltage(uharmCount==0?0:BigDecimal.valueOf(uharmCounts*1.0/uharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //谐波电流 + warningAreaVO.setHarmonicCurrent(iharmCount==0?0:BigDecimal.valueOf(iharmCounts*1.0/iharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //三相电压不平衡 + warningAreaVO.setThreePhaseVoltageUnbalance(ubalanceCount==0?0:BigDecimal.valueOf(ubalanceCounts*1.0/ubalanceCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //闪变 + warningAreaVO.setFlicker(flickerCount==0?0:BigDecimal.valueOf(flickerCounts*1.0/flickerCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //间谐波电压 + warningAreaVO.setInterHarmonic(inuharmCount==0?0:BigDecimal.valueOf(inuharmCounts*1.0/inuharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //负序电流 + warningAreaVO.setNegative(iNegCount==0?0:BigDecimal.valueOf(iNegCounts*1.0/iNegCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //电压暂降 + warningAreaVO.setVoltageDip(eventDown==0?0:BigDecimal.valueOf(eventDowns*1.0/eventDown).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //电压暂升 + warningAreaVO.setVoltageSwell(eventUp==0?0:BigDecimal.valueOf(eventUps*1.0/eventUp).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //短时中断 + warningAreaVO.setShortInterruption(eventInterrupt==0?0:BigDecimal.valueOf(eventInterrupts*1.0/eventInterrupt).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + list.add(warningAreaVO); + } + } + } + if (!CollectionUtils.isEmpty(list)){ + List recordList = new ArrayList<>(); + //默认 在线监测点数量 倒叙排序 + recordList = list.stream().sorted(Comparator.comparing(WarningAreaVO::getOnlineMonitorCounts).reversed().thenComparing(WarningAreaVO::getName)).collect(Collectors.toList()); + page.setRecords(recordList); + return page; + } + return page; + } + + @Override + @SuppressWarnings("unchecked") + public Page monitorWarningManage(OverAreaVO param) { + List line = new ArrayList<>(),temList = new ArrayList<>(); + Map> map = new HashMap<>(); + Map> map2 = new HashMap<>(); + Page page = new Page<>(); + List list = new ArrayList<>(); + page.setSize(param.getPageSize()); + page.setCurrent(param.getPageNum()); + List areaList = generalDeviceInfoClient.getPracticalRunDeviceInfo(param).getData(); + if (!CollectionUtils.isEmpty(areaList)){ + areaList.forEach(item->{ + line.addAll(item.getLineIndexes()); + }); + if (!CollectionUtils.isEmpty(line)){ + page.setTotal(line.size()); + int pages = (int)Math.ceil(line.size()*1.0/param.getPageSize()); + page.setPages(pages); + List> pageList = Lists.partition(line,param.getPageSize()); + temList = pageList.get(param.getPageNum()-1); + } + if (!CollectionUtils.isEmpty(temList)){ + List limitRateList = (List)getAllData(temList,param.getSearchBeginTime(),param.getSearchEndTime(), Param.LIMIT_RATE); + if (!CollectionUtils.isEmpty(limitRateList)){ + map = limitRateList.stream().collect(Collectors.groupingBy(LimitRate::getLineId)); + } + List eventDetailList = getEventDetail(temList,param.getSearchBeginTime(),param.getSearchEndTime()); + if (!CollectionUtils.isEmpty(eventDetailList)){ + map2 = eventDetailList.stream().collect(Collectors.groupingBy(EventDetail::getLineId)); + } + PollutionParamDTO pollutionParamDTO = new PollutionParamDTO(); + pollutionParamDTO.setLineList(temList); + List overLimitLineList = lineFeignClient.getOverLimitLineInfo(pollutionParamDTO).getData(); + for (OverLimitLineDTO pojo:overLimitLineList) { + String item = pojo.getId(); + String name = pojo.getLineName(); + int alertMonitorCount = 0,alertCount = 0,freqCount = 0,voltageCount = 0,ubalanceCount = 0,flickerCount = 0,iNegCount = 0,uharmCount = 0,iharmCount = 0,inuharmCount = 0; + int freqCounts = 0,voltageCounts = 0,uharmCounts = 0,iharmCounts = 0,ubalanceCounts = 0,flickerCounts = 0,inuharmCounts = 0,iNegCounts = 0; + int eventUp = 0,eventDown = 0,eventInterrupt = 0,eventUps = 0,eventDowns = 0,eventInterrupts = 0; + WarningMonitorVO warningMonitorVO = new WarningMonitorVO(); + //监测点id + warningMonitorVO.setId(item); + //监测点名称 + warningMonitorVO.setName(name); + //谐波统计 + if (!CollectionUtils.isEmpty(map.get(item))){ + LimitRate limitRate = map.get(item).get(0); + if (!Objects.isNull(limitRate)){ + if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0){ + alertMonitorCount++; + } + if (limitRate.getFreqDevOverTime() > 0){ + freqCount++; + freqCounts = freqCounts + limitRate.getFreqDevOverTime(); + } + if (limitRate.getVoltageDevOverTime() > 0){ + voltageCount++; + voltageCounts = voltageCounts + limitRate.getVoltageDevOverTime(); + } + if (limitRate.getUHarm2OverTime() > 0){ + uharmCount++; + uharmCounts = uharmCounts + limitRate.getUHarm2OverTime(); + } + if (limitRate.getIHarm2OverTime() > 0){ + iharmCount++; + iharmCounts = iharmCounts + limitRate.getIHarm2OverTime(); + } + if (limitRate.getUBalanceOverTime() > 0){ + ubalanceCount++; + ubalanceCounts = ubalanceCounts + limitRate.getUBalanceOverTime(); + } + if (limitRate.getFlickerOverTime() > 0){ + flickerCount++; + flickerCounts = flickerCounts + limitRate.getFlickerOverTime(); + } + if (limitRate.getInuHarm1OverTime() > 0){ + inuharmCount++; + inuharmCounts = inuharmCounts + limitRate.getInuHarm1OverTime(); + } + if (limitRate.getINegOverTime() > 0){ + iNegCount++; + iNegCounts = iNegCounts + limitRate.getINegOverTime(); + } + alertCount = limitRate.getFreqDevOverTime() + limitRate.getVoltageDevOverTime() + limitRate.getUBalanceOverTime() + limitRate.getFlickerOverTime() + limitRate.getINegOverTime() + limitRate.getUHarm2OverTime() + limitRate.getIHarm2OverTime() + limitRate.getInuHarm1OverTime(); + } else { + log.info("此监测点在限值表中无数据:" + item); + throw new BusinessException(HarmonicResponseEnum.LIMIT_MISSING_ERROR); + } + } + //暂降统计 + if (!CollectionUtils.isEmpty(map2.get(item))){ + List eventDetailList2 = map2.get(item); + if (!CollectionUtils.isEmpty(eventDetailList2)){ + for (EventDetail item3 : eventDetailList2) { + if (item3.getWaveType() == 1){ + eventDowns++; + } else if (item3.getWaveType() == 2){ + eventUps++; + } else if (item3.getWaveType() == 3){ + eventInterrupts++; + } + } + } + } + if (eventDowns > 0){ + eventDown++; + } + if (eventUps > 0){ + eventUp++; + } + if (eventInterrupts > 0){ + eventInterrupt++; + } + //告警次数 + warningMonitorVO.setAlertCounts(alertCount); + //告警频次(次/点) + warningMonitorVO.setAlertAlarmFrequency(alertMonitorCount==0?0: BigDecimal.valueOf(alertCount*1.0/alertMonitorCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //频率偏差 + warningMonitorVO.setFrequencyDeviation(freqCount==0?0:BigDecimal.valueOf(freqCounts*1.0/freqCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //电压偏差 + warningMonitorVO.setVoltageDeviation(voltageCount==0?0:BigDecimal.valueOf(voltageCounts*1.0/voltageCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //谐波电压 + warningMonitorVO.setHarmonicVoltage(uharmCount==0?0:BigDecimal.valueOf(uharmCounts*1.0/uharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //谐波电流 + warningMonitorVO.setHarmonicCurrent(iharmCount==0?0:BigDecimal.valueOf(iharmCounts*1.0/iharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //三相电压不平衡 + warningMonitorVO.setThreePhaseVoltageUnbalance(ubalanceCount==0?0:BigDecimal.valueOf(ubalanceCounts*1.0/ubalanceCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //闪变 + warningMonitorVO.setFlicker(flickerCount==0?0:BigDecimal.valueOf(flickerCounts*1.0/flickerCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //间谐波电压 + warningMonitorVO.setInterHarmonic(inuharmCount==0?0:BigDecimal.valueOf(inuharmCounts*1.0/inuharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //负序电流 + warningMonitorVO.setNegative(iNegCount==0?0:BigDecimal.valueOf(iNegCounts*1.0/iNegCount).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //电压暂降 + warningMonitorVO.setVoltageDip(eventDown==0?0:BigDecimal.valueOf(eventDowns*1.0/eventDown).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //电压暂升 + warningMonitorVO.setVoltageSwell(eventUp==0?0:BigDecimal.valueOf(eventUps*1.0/eventUp).setScale(2, RoundingMode.HALF_UP).doubleValue()); + //短时中断 + warningMonitorVO.setShortInterruption(eventInterrupt==0?0:BigDecimal.valueOf(eventInterrupts*1.0/eventInterrupt).setScale(2, RoundingMode.HALF_UP).doubleValue()); + list.add(warningMonitorVO); + } + } + if (!CollectionUtils.isEmpty(list)){ + List recordList = new ArrayList<>(); + //默认 监测点告警次数 倒叙排序 + recordList = list.stream().sorted(Comparator.comparing(WarningMonitorVO::getAlertCounts).reversed()).collect(Collectors.toList()); + page.setRecords(recordList); + return page; + } + } + return page; + } + + + /** + * 功能描述: 处理区域在线监测点数、超标监测点数 + * @param list 集合 + * @return + * @author xy + * @date 2022/2/25 15:05 + */ + private List getAllData(List list, String startTime, String endTime, String databaseName){ + List result = new ArrayList<>(); + StringBuilder stringBuilder = new StringBuilder(); + StringBuilder stringBuilder1 = new StringBuilder(); + stringBuilder.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and ("); + for (int i=0;i getEventDetail(List list, String startTime, String endTime){ + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and ("); + for (int i=0;i clauses, WhereQueryImpl whereQuery) { + WhereNested> andNested = whereQuery.andNested(); + for (Clause clause : clauses) { + andNested.or(clause); + } + andNested.close(); + } + /** * 谐波电压 -> 电压总谐波畸变率 * 各监测点最新的A、B、C三相数据 * 按照监测点分组,每个监测点取最大 */ private Map> getDistortionData(){ - String sql = "SELECT * FROM day_v where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3"; + String sql = "SELECT * FROM day_v where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; @@ -226,7 +238,7 @@ public class PollutionJob { * 各监测点最新的A、B、C三相数据 */ private Map> getContentData(){ - String sql = "SELECT * FROM day_harmrate_v where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3"; + String sql = "SELECT * FROM day_harmrate_v where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; @@ -279,7 +291,7 @@ public class PollutionJob { * 各监测点最新的A、B、C三相数据 */ private Map> getIharm(){ - String sql = "SELECT * FROM day_i where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3"; + String sql = "SELECT * FROM day_i where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; @@ -332,7 +344,7 @@ public class PollutionJob { * 各监测点最新的T相数据 */ private Map> getFreq(){ - String sql = "SELECT line_id,abs(freq_dev) AS freq_dev FROM day_v where phasic_type = 'T' and (value_type = 'MIN' or value_type = 'MAX') group by line_id order by time desc limit 2"; + String sql = "SELECT line_id,abs(freq_dev) AS freq_dev FROM day_v where phasic_type = 'T' and (value_type = 'MIN' or value_type = 'MAX') group by line_id order by time desc limit 2 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; @@ -362,7 +374,7 @@ public class PollutionJob { * 各监测点最新的A、B、C三相数据 */ private Map> getDev(){ - String sql = "SELECT line_id,vu_dev,vl_dev,value_type FROM day_v where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and (value_type = 'MIN' or value_type = 'MAX') group by line_id order by time desc limit 6"; + String sql = "SELECT line_id,vu_dev,vl_dev,value_type FROM day_v where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and (value_type = 'MIN' or value_type = 'MAX') group by line_id order by time desc limit 6 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; @@ -393,7 +405,7 @@ public class PollutionJob { * 各监测点最新的T相数据 */ private Map> getUbalance(){ - String sql = "SELECT line_id,v_unbalance,value_type FROM day_v where phasic_type = 'T' and (value_type = 'CP95' or value_type = 'MAX') group by line_id order by time desc limit 2"; + String sql = "SELECT line_id,v_unbalance,value_type FROM day_v where phasic_type = 'T' and (value_type = 'CP95' or value_type = 'MAX') group by line_id order by time desc limit 2 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; @@ -423,7 +435,7 @@ public class PollutionJob { * 各监测点最新的T相数据 */ private Map> getIneg(){ - String sql = "SELECT line_id,i_neg,value_type FROM day_i where phasic_type = 'T' and (value_type = 'CP95' or value_type = 'MAX') group by line_id order by time desc limit 2"; + String sql = "SELECT line_id,i_neg,value_type FROM day_i where phasic_type = 'T' and (value_type = 'CP95' or value_type = 'MAX') group by line_id order by time desc limit 2 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; @@ -453,7 +465,7 @@ public class PollutionJob { * 各监测点最新的A、B、C三相数据 */ private Map> getInuharm(){ - String sql = "SELECT * FROM day_inharm_v where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and value_type = 'CP95' group by line_id order by time desc limit 3"; + String sql = "SELECT * FROM day_inharm_v where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and value_type = 'CP95' group by line_id order by time desc limit 3 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; @@ -498,7 +510,7 @@ public class PollutionJob { * 各监测点最新的A、B、C三相数据 */ private Map> getFlicker(){ - String sql = "SELECT * FROM day_plt where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and value_type = 'CP95' group by line_id order by time desc limit 3"; + String sql = "SELECT * FROM day_plt where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and value_type = 'CP95' group by line_id order by time desc limit 3 tz('Asia/Shanghai')"; QueryResult sqlResult = influxDbUtils.query(sql); InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); List data; diff --git a/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/PqsIntegrityJob.java b/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/PqsIntegrityJob.java new file mode 100644 index 000000000..2908a7b54 --- /dev/null +++ b/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/PqsIntegrityJob.java @@ -0,0 +1,178 @@ +package com.njcn.executor.handler; + +import com.njcn.common.pojo.constant.PatternRegex; +import com.njcn.device.api.LineFeignClient; +import com.njcn.device.pojo.po.LineDetail; +import com.njcn.executor.pojo.vo.*; +import com.njcn.influxdb.param.InfluxDBPublicParam; +import com.njcn.influxdb.utils.InfluxDbUtils; +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.influxdb.InfluxDB; +import org.influxdb.dto.BatchPoints; +import org.influxdb.dto.Point; +import org.influxdb.dto.QueryResult; +import org.influxdb.impl.InfluxDBResultMapper; +import org.influxdb.querybuilder.SelectQueryImpl; +import org.influxdb.querybuilder.WhereNested; +import org.influxdb.querybuilder.WhereQueryImpl; +import org.influxdb.querybuilder.clauses.Clause; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import static com.njcn.influxdb.param.InfluxDBPublicParam.*; +import static com.njcn.influxdb.param.InfluxDBPublicParam.LINE_ID; +import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.*; +import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/7/8 13:44 + */ +@Slf4j +@Component +@AllArgsConstructor +public class PqsIntegrityJob { + + private final InfluxDbUtils influxDbUtils; + + private final LineFeignClient lineFeignClient; + + @XxlJob("pqsIntegrityJobHandler") + public void pqsIntegrityJobHandler() throws ParseException { + List result = new ArrayList<>(); + List paramList = new ArrayList<>(),lineList = new ArrayList<>(); + List dataList = new ArrayList<>(); + String command = XxlJobHelper.getJobParam(); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)-1, 0, 0, 0); + calendar.set(Calendar.MILLISECOND, 0); + Calendar calendar2 = Calendar.getInstance(); + calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH)-1, 23, 59, 59); + calendar2.set(Calendar.MILLISECOND, 0); + String startTime = format.format(calendar.getTime()); + String endTime = format.format(calendar2.getTime()); + if (!StringUtils.isEmpty(command)){ + paramList = Arrays.asList(command.split(",")); + startTime = paramList.get(0); + endTime = paramList.get(1); + lineList = paramList.subList(2,paramList.size()); + boolean s1 = Pattern.matches(PatternRegex.TIME_FORMAT,startTime); + boolean e1 = Pattern.matches(PatternRegex.TIME_FORMAT,endTime); + if (!s1 || !e1){ + log.error("补招时间格式错误"); + return; + } else { + startTime = startTime + " 00:00:00"; + endTime = endTime + " 23:59:59"; + } + } + List lineDetail = lineFeignClient.getLineDetail(lineList).getData(); + if (!CollectionUtils.isEmpty(lineDetail)){ + //获取dataV表中监测点的数据数量 + lineList = lineDetail.stream().map(LineDetail::getId).collect(Collectors.toList()); + long diff,diffDays,a,b = 0; + Date d1 = format.parse(startTime); + Date d2 = format.parse(endTime); + diff = d2.getTime() - d1.getTime(); + diffDays = diff / (24 * 60 * 60 * 1000-1000); + int days = (int) diffDays; + for (int i = 1; i <= days; i++) { + a = d1.getTime() + (long)(i-1)*(24 * 60 * 60) * 1000; + b = d1.getTime() + (long)i*(24 * 60 * 60) * 1000-1000; + startTime = format.format(a); + endTime = format.format(b); + dataList = getDataV(lineList,startTime,endTime); + for (LineDetail detail : lineDetail) { + PqsIntegrity pqsIntegrity = new PqsIntegrity(); + pqsIntegrity.setTime(Instant.ofEpochMilli(a)); + pqsIntegrity.setLineId(detail.getId()); + pqsIntegrity.setDue(DAY_MINUTE/detail.getTimeInterval()); + if (!CollectionUtils.isEmpty(dataList)){ + Map> lineMap = dataList.stream().collect(Collectors.groupingBy(DataV::getLineId)); + List l1 = lineMap.get(detail.getId()); + if (!CollectionUtils.isEmpty(l1)){ + Map> timeMap = l1.stream().collect(Collectors.groupingBy(DataV::getTime)); + pqsIntegrity.setReal(timeMap.size()); + } + } + result.add(pqsIntegrity); + } + } + } + insertData(result); + } + + + /** + * 获取dataV数据 + * @param list 监测点集合 + * @return dataV数据 + */ + private List getDataV(List list, String startTime, String endTime){ + SelectQueryImpl selectQuery = select().from(DATABASE, DATA_V); + WhereQueryImpl where = selectQuery.where(); + whereAndNested(list, where); + where.and(gte(TIME, startTime)).and(lte(TIME, endTime)); + where.tz(TZ); + QueryResult queryResult = influxDbUtils.query(selectQuery.getCommand()); + InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); + return resultMapper.toPOJO(queryResult, DataV.class); + } + + /** + * 拼接监测点条件 + * @param list 监测点集合 + * @param whereQuery WhereQueryImpl + */ + private void whereAndNested(List list, WhereQueryImpl whereQuery) { + List clauses = new ArrayList<>(); + list.forEach(item->{ + Clause clause = eq(LINE_ID, item); + clauses.add(clause); + }); + WhereNested> andNested = whereQuery.andNested(); + for (Clause clause : clauses) { + andNested.or(clause); + } + andNested.close(); + } + + /** + * 功能描述:插入pqs_integrity表数据 + * @author xy + * @param list 数据集合 + * @date 2022/5/12 8:55 + */ + private void insertData(List list){ + List records = new ArrayList<>(); + list.forEach(item->{ + Map tags = new HashMap<>(); + Map fields = new HashMap<>(); + tags.put(LINE_ID,item.getLineId()); + fields.put(DUE,item.getDue()); + fields.put(REAL,item.getReal()); + Point point = influxDbUtils.pointBuilder(PQS_INTEGRITY, item.getTime().toEpochMilli(), TimeUnit.MILLISECONDS, tags, fields); + BatchPoints batchPoints = BatchPoints.database(DATABASE).tag(LINE_ID, item.getLineId()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build(); + batchPoints.point(point); + records.add(batchPoints.lineProtocol()); + }); + influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records); + } + +} diff --git a/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/PqsOnlineRateJob.java b/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/PqsOnlineRateJob.java new file mode 100644 index 000000000..c5a22465f --- /dev/null +++ b/pqs-job/job-executor/src/main/java/com/njcn/executor/handler/PqsOnlineRateJob.java @@ -0,0 +1,29 @@ +package com.njcn.executor.handler; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/7/8 13:43 + */ +@Slf4j +@Component +@AllArgsConstructor +public class PqsOnlineRateJob { + + + + + + + + + + + +} diff --git a/pqs-job/job-executor/src/main/java/com/njcn/executor/pojo/vo/PqsIntegrity.java b/pqs-job/job-executor/src/main/java/com/njcn/executor/pojo/vo/PqsIntegrity.java new file mode 100644 index 000000000..2a5ac243c --- /dev/null +++ b/pqs-job/job-executor/src/main/java/com/njcn/executor/pojo/vo/PqsIntegrity.java @@ -0,0 +1,31 @@ +package com.njcn.executor.pojo.vo; + +import lombok.Data; +import org.influxdb.annotation.Column; +import org.influxdb.annotation.Measurement; + +import java.time.Instant; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/5/11 16:08 + */ +@Data +@Measurement(name = "pqs_integrity") +public class PqsIntegrity { + + @Column(name = "time") + private Instant time; + + @Column(name = "line_id") + private String lineId; + + @Column(name = "due") + private Integer due; + + @Column(name = "real") + private Integer real = 0; +} diff --git a/pqs-job/job-executor/src/main/resources/bootstrap.yml b/pqs-job/job-executor/src/main/resources/bootstrap.yml index e099209c5..107705fde 100644 --- a/pqs-job/job-executor/src/main/resources/bootstrap.yml +++ b/pqs-job/job-executor/src/main/resources/bootstrap.yml @@ -41,12 +41,12 @@ logging: xxl: job: admin: - addresses: http://@server.url@:10217/job-admin + addresses: http://192.168.1.13:10217/job-admin #执行器通讯TOKEN [选填]:非空时启用; accessToken: executor: #执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册 - appname: executorCdf + appname: executor #执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。 address: #执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务"; diff --git a/pqs-job/job-executor/src/test/java/Test1.java b/pqs-job/job-executor/src/test/java/Test1.java new file mode 100644 index 000000000..a26d48b0a --- /dev/null +++ b/pqs-job/job-executor/src/test/java/Test1.java @@ -0,0 +1,56 @@ +import com.njcn.executor.pojo.vo.DataFlicker; +import com.njcn.influxdb.utils.InfluxDbUtils; +import org.influxdb.dto.QueryResult; +import org.influxdb.impl.InfluxDBResultMapper; +import org.influxdb.querybuilder.SelectQueryImpl; +import org.influxdb.querybuilder.WhereNested; +import org.influxdb.querybuilder.WhereQueryImpl; +import org.influxdb.querybuilder.clauses.Clause; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.List; + +import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq; +import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/7/4 19:04 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Test1.class) +public class Test1 { + + @Test + public void testMethod(){ + InfluxDbUtils influxDBUtil = new InfluxDbUtils("admin", "njcnpqs", "http://192.168.1.18:8086", "pqsbase", ""); + SelectQueryImpl selectQuery = select().from("pqsbase","data_flicker").where(eq("fluc",0)).limit(1).tz("Asia/Shanghai"); + WhereQueryImpl where = selectQuery.where(); + QueryResult queryResult = influxDBUtil.query(selectQuery.getCommand()); + InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); + List list = resultMapper.toPOJO(queryResult, DataFlicker.class); + System.out.println("list===:" + list); + } + + private List getClauses() { + Clause c1 = eq("line_id", "5e467a40023b299070682eb21f2ec9a1"); + Clause c2 = eq("line_id", "183245996f303ebfd80eeb3377cecdc2"); + Clause c3 = eq("line_id", "0d46f54420246e999d5c68b3133f668c"); + return Arrays.asList(c1, c2, c3); + } + + private void whereAndNested(List clauses, WhereQueryImpl whereQuery) { + WhereNested> andNested = whereQuery.andNested(); + for (Clause clause : clauses) { + andNested.or(clause); + } + andNested.close(); + } +} diff --git a/pqs-quality/quality-api/src/main/java/com/njcn/quality/enums/EnergyResponseEnum.java b/pqs-quality/quality-api/src/main/java/com/njcn/quality/enums/EnergyResponseEnum.java index dbf9b3902..823cbe50e 100644 --- a/pqs-quality/quality-api/src/main/java/com/njcn/quality/enums/EnergyResponseEnum.java +++ b/pqs-quality/quality-api/src/main/java/com/njcn/quality/enums/EnergyResponseEnum.java @@ -65,7 +65,9 @@ public enum EnergyResponseEnum { TASK_HAS_START("508","任务已经执行完毕"), TASK_DEL_ERROR("509","定时任务删除失败,请联系管理员"), - TASK_RUNING("510","任务正在执行无法操作,请先停止任务") + TASK_RUNING("510","任务正在执行无法操作,请先停止任务"), + + FILE_EMPTY("511","上传的文件为空,请检查文件") ; private final String code; diff --git a/pqs-quality/quality-api/src/main/java/com/njcn/quality/param/UpdateDeviceVersion.java b/pqs-quality/quality-api/src/main/java/com/njcn/quality/param/UpdateDeviceVersion.java new file mode 100644 index 000000000..be13872e7 --- /dev/null +++ b/pqs-quality/quality-api/src/main/java/com/njcn/quality/param/UpdateDeviceVersion.java @@ -0,0 +1,32 @@ +package com.njcn.quality.param; + +import com.njcn.common.pojo.constant.PatternRegex; +import com.njcn.web.constant.ValidMessage; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.web.multipart.MultipartFile; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2022/7/6 9:24 + */ +@Data +public class UpdateDeviceVersion { + + @ApiModelProperty("装置id") + @NotBlank(message = ValidMessage.ID_NOT_BLANK) + @Pattern(regexp = PatternRegex.NORMAL, message = ValidMessage.ID_FORMAT_ERROR) + private String name; + + @ApiModelProperty("装置版本文件") + @NotNull(message = ValidMessage.DEVICE_VERSION_NOT_BLANK) + private MultipartFile deviceVersionFile; +} diff --git a/pqs-quality/quality-api/src/main/java/com/njcn/quality/pojo/dto/AskDataParamDTO.java b/pqs-quality/quality-api/src/main/java/com/njcn/quality/pojo/dto/AskDataParamDTO.java index 1d0fd033b..37425a24e 100644 --- a/pqs-quality/quality-api/src/main/java/com/njcn/quality/pojo/dto/AskDataParamDTO.java +++ b/pqs-quality/quality-api/src/main/java/com/njcn/quality/pojo/dto/AskDataParamDTO.java @@ -22,4 +22,6 @@ public class AskDataParamDTO implements Serializable { private String endTime; + private Object dataArray; + } diff --git a/pqs-quality/quality-boot/Dockerfile b/pqs-quality/quality-boot/Dockerfile new file mode 100644 index 000000000..bc4e4fa9c --- /dev/null +++ b/pqs-quality/quality-boot/Dockerfile @@ -0,0 +1,6 @@ +FROM openjdk:8-jdk-alpine +ADD target/qualityboot.jar qualityboot.jar +ENTRYPOINT ["java","-jar","/qualityboot.jar"] +EXPOSE 10209 +RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone + diff --git a/pqs-quality/quality-boot/src/main/java/com/njcn/quality/controller/ModelController.java b/pqs-quality/quality-boot/src/main/java/com/njcn/quality/controller/ModelController.java index c5829ecbb..45a9c4f8a 100644 --- a/pqs-quality/quality-boot/src/main/java/com/njcn/quality/controller/ModelController.java +++ b/pqs-quality/quality-boot/src/main/java/com/njcn/quality/controller/ModelController.java @@ -1,21 +1,31 @@ package com.njcn.quality.controller; +import cn.hutool.core.util.StrUtil; import com.njcn.common.pojo.annotation.OperateInfo; +import com.njcn.common.pojo.constant.OperateType; 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.common.utils.LogUtil; +import com.njcn.quality.param.UpdateDeviceVersion; import com.njcn.quality.service.IModelService; +import com.njcn.system.pojo.param.ThemeParam; import com.njcn.web.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.StringUtils; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Objects; /** * 类的介绍: @@ -66,5 +76,12 @@ public class ModelController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); } - + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @PostMapping("/updateDevVersion") + @ApiOperation("更新装置模板信息") + public HttpResult updateDevVersion(@Validated UpdateDeviceVersion updateDeviceVersion) throws Exception { + String methodDescribe = getMethodDescribe("updateDevVersion"); + modelService.updateDevVersion(updateDeviceVersion); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); + } } diff --git a/pqs-quality/quality-boot/src/main/java/com/njcn/quality/handler/MqttMessageHandler.java b/pqs-quality/quality-boot/src/main/java/com/njcn/quality/handler/MqttMessageHandler.java index 4fa7a924d..a4843ebf6 100644 --- a/pqs-quality/quality-boot/src/main/java/com/njcn/quality/handler/MqttMessageHandler.java +++ b/pqs-quality/quality-boot/src/main/java/com/njcn/quality/handler/MqttMessageHandler.java @@ -7,8 +7,9 @@ import com.github.tocrhz.mqtt.annotation.Payload; import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.njcn.quality.enums.EnergyResponseEnum; import com.njcn.quality.pojo.constant.ApiParam; -import com.njcn.quality.pojo.dto.DeviceOperateDTO; -import com.njcn.quality.pojo.dto.RegisterDTO; +import com.njcn.quality.pojo.constant.DataType; +import com.njcn.quality.pojo.constant.ModelState; +import com.njcn.quality.pojo.dto.*; import com.njcn.quality.pojo.po.EleLogs; import com.njcn.quality.service.IEleLogsService; import com.njcn.quality.service.IModelService; @@ -127,28 +128,28 @@ public class MqttMessageHandler { //回复装置信息 publisher.send("/device/pltrep/"+version+"/" + edgeId,result,1,false); -// //询问模板数据 暂时线下传递模板数据 -// Gson gson = new Gson(); -// AccessDTO.AccessResponse response = gson.fromJson(result,AccessDTO.AccessResponse.class); -// if (response.getCode() == Integer.parseInt(EnergyResponseEnum.NO_MODEL_FIND.getCode())){ -// AskDataDTO.AskDataRequest askDataDTO = new AskDataDTO.AskDataRequest(); -// askDataDTO.setTimestamp(Long.toString(System.currentTimeMillis()/1000)); -// askDataDTO.setLevel(0); -// askDataDTO.setType(ApiParam.CMD_DEV_DATA); -// AskDataParamDTO askDataParamDTO = new AskDataParamDTO(); -// askDataParamDTO.setDataType(DataType.TEMPLATE); -// askDataParamDTO.setOperate(ModelState.READ); -// askDataParamDTO.setStartTime(Long.toString(System.currentTimeMillis()/1000)); -// askDataDTO.setParam(askDataParamDTO); -// publisher.send("/platform/command/v1/" + edgeId,gson.toJson(askDataDTO),1,false); -// } + //询问模板数据 暂时线下传递模板数据 + Gson gson2 = new Gson(); + AccessDTO.AccessResponse response2 = gson2.fromJson(result,AccessDTO.AccessResponse.class); + if (response2.getCode() == Integer.parseInt(EnergyResponseEnum.NO_MODEL_FIND.getCode())){ + AskDataDTO.AskDataRequest askDataDTO = new AskDataDTO.AskDataRequest(); + askDataDTO.setTimestamp(Long.toString(System.currentTimeMillis()/1000)); + askDataDTO.setLevel(0); + askDataDTO.setDeviceId(registerDTO.getParam().getDid().get(0)); + askDataDTO.setType(ApiParam.CMD_DEV_DATA); + AskDataParamDTO askDataParamDTO = new AskDataParamDTO(); + askDataParamDTO.setDataType(DataType.TEMPLATE); + askDataParamDTO.setOperate(ModelState.READ); + askDataParamDTO.setStartTime(Long.toString(System.currentTimeMillis()/1000)); + askDataDTO.setParam(askDataParamDTO); + publisher.send("/platform/devcmd/"+version+"/" + edgeId,gson.toJson(askDataDTO),1,false); + } } - /** * 获取模板信息 */ - @MqttSubscribe(value = "/platform/reply/{version}/{edgeId}",qos = 1) + @MqttSubscribe(value = "/platform/devack/{version}/{edgeId}",qos = 1) public void replyTemplate(String topic, MqttMessage message, @NamedValue("edgeId") String edgeId, @Payload String payload) { String result = modelService.deviceData(new String(message.getPayload(), StandardCharsets.UTF_8)); //模板发生变更通知其他云服务 diff --git a/pqs-quality/quality-boot/src/main/java/com/njcn/quality/service/IModelService.java b/pqs-quality/quality-boot/src/main/java/com/njcn/quality/service/IModelService.java index f9201f3a0..4c5336a1c 100644 --- a/pqs-quality/quality-boot/src/main/java/com/njcn/quality/service/IModelService.java +++ b/pqs-quality/quality-boot/src/main/java/com/njcn/quality/service/IModelService.java @@ -1,6 +1,8 @@ package com.njcn.quality.service; +import com.njcn.quality.param.UpdateDeviceVersion; + import java.util.List; import java.util.concurrent.CompletableFuture; @@ -58,4 +60,14 @@ public interface IModelService { */ List monitorHeartbeat(String ndid, String time); + + /** + * 功能描述: 手动更新装置模板版本 + * @author xy + * @param updateDeviceVersion 参数 + * @date 2022/7/6 20:19 + */ + void updateDevVersion(UpdateDeviceVersion updateDeviceVersion) throws Exception; + + } diff --git a/pqs-quality/quality-boot/src/main/java/com/njcn/quality/service/impl/ModelServiceImpl.java b/pqs-quality/quality-boot/src/main/java/com/njcn/quality/service/impl/ModelServiceImpl.java index 706440bbb..a96a1fe02 100644 --- a/pqs-quality/quality-boot/src/main/java/com/njcn/quality/service/impl/ModelServiceImpl.java +++ b/pqs-quality/quality-boot/src/main/java/com/njcn/quality/service/impl/ModelServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil; import com.alibaba.nacos.shaded.com.google.gson.Gson; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.quality.enums.EnergyResponseEnum; @@ -18,11 +19,15 @@ import com.njcn.quality.pojo.dto.*; import com.njcn.quality.pojo.po.*; import com.njcn.quality.service.*; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; +import java.io.*; +import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; @@ -37,10 +42,13 @@ import java.util.stream.Stream; * @version 1.0.0 * @createTime 2022/2/28 15:02 */ +@Slf4j @Service @AllArgsConstructor public class ModelServiceImpl implements IModelService { + private final MqttPublisher publisher; + private final NetDevMapper netDevMapper; private final DevVersionMapper devVersionMapper; @@ -81,8 +89,6 @@ public class ModelServiceImpl implements IModelService { private final IEleCtrlService eleCtrlService; - private final IEleActrlService eleActrlService; - private final IDataGroupService dataGroupService; private final IGroupArrayService groupArrayService; @@ -416,7 +422,6 @@ public class ModelServiceImpl implements IModelService { BeanUtil.copyProperties(netDevDTO.getSoftInfoDTO(),hardwareParam); hardwareParam.setType(ModelState.NET_DEV); hardwareService.addHardware(hardwareParam); - /** * 解析装置模板 */ @@ -496,7 +501,7 @@ public class ModelServiceImpl implements IModelService { }); } } else { - System.out.println("获取数据失败"); + log.error("获取数据失败"); } AccessDTO.AccessResponse result = new AccessDTO.AccessResponse(); result.setCode(Integer.parseInt(EnergyResponseEnum.SUCCESS.getCode())); @@ -600,6 +605,49 @@ public class ModelServiceImpl implements IModelService { return null; } + /** + * 文件流解析成json + * @param updateDeviceVersion 参数 + */ + @Override + public void updateDevVersion(UpdateDeviceVersion updateDeviceVersion) throws Exception { + File file = multipartFileToFile(updateDeviceVersion.getDeviceVersionFile()); + if (Objects.isNull(file)){ + throw new BusinessException(EnergyResponseEnum.FILE_EMPTY); + } + String jsonStr = ""; + try { + FileReader fileReader = new FileReader(file); + Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); + int ch = 0; + StringBuffer sb = new StringBuffer(); + while ((ch = reader.read()) != -1) { + sb.append((char) ch); + } + fileReader.close(); + reader.close(); + jsonStr = sb.toString(); + Gson gson = new Gson(); + AskDataDTO.AskDataResponse response = gson.fromJson(jsonStr,AskDataDTO.AskDataResponse.class); + String edgeId = response.getDeviceId(); + DataArrayListDTO dataArrayListDTO = response.getParam().getDataArray().get(0); + Gson gson2 = new Gson(); + AskDataDTO.AskDataRequest askDataDTO = new AskDataDTO.AskDataRequest(); + askDataDTO.setTimestamp(Long.toString(System.currentTimeMillis()/1000)); + askDataDTO.setMid(0); + askDataDTO.setLevel(0); + askDataDTO.setType(ApiParam.CMD_DEV_DATA); + AskDataParamDTO askDataParamDTO = new AskDataParamDTO(); + askDataParamDTO.setDataType(DataType.TEMPLATE); + askDataParamDTO.setOperate(ModelState.WRITE); + askDataParamDTO.setStartTime(Long.toString(System.currentTimeMillis()/1000)); + askDataParamDTO.setDataArray(dataArrayListDTO); + askDataDTO.setParam(askDataParamDTO); + publisher.send("/platform/command/v1/" + edgeId,gson2.toJson(askDataDTO),1,false); + } catch (IOException e) { + e.getMessage(); + } + } /** * 解析设备模板 @@ -1320,4 +1368,36 @@ public class ModelServiceImpl implements IModelService { } } + public static File multipartFileToFile(MultipartFile file) throws Exception { + File toFile = null; + if (Objects.equals("",file) || file.getSize() <= 0) { + file = null; + } else { + InputStream ins = null; + ins = file.getInputStream(); + toFile = new File(Objects.requireNonNull(file.getOriginalFilename())); + inputStreamToFile(ins, toFile); + ins.close(); + } + return toFile; + } + + /** + * 获取流文件 + */ + private static void inputStreamToFile(InputStream ins, File file) { + try { + OutputStream os = new FileOutputStream(file); + int bytesRead = 0; + byte[] buffer = new byte[8192]; + while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { + os.write(buffer, 0, bytesRead); + } + os.close(); + ins.close(); + } catch (Exception e) { + e.getMessage(); + } + } + }