From cce56ec69bf060553677e2737ff563060788792b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=B6=85?= <973677575@qq.com> Date: Thu, 18 Aug 2022 19:32:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/pojo/dto/DeviceOnlineDataDTO.java | 17 ++ .../device/pojo/param/TabCensusParam.java | 49 ++++++ .../java/com/njcn/device/pojo/po/TopMsg.java | 48 ++++++ .../device/pojo/vo/DeviceOnlineTabVO.java | 39 +++++ .../controller/TabCensusController.java | 58 +++++++ .../device/mapper/DeviceOnlineDataMapper.java | 25 +++ .../mapper/mapping/DeviceOnlineDataMapper.xml | 75 +++++++++ .../service/DeviceOnlineDataService.java | 17 ++ .../impl/DeviceOnlineDataServiceImpl.java | 152 ++++++++++++++++++ 9 files changed, 480 insertions(+) create mode 100644 pqs-device/device-api/src/main/java/com/njcn/device/pojo/dto/DeviceOnlineDataDTO.java create mode 100644 pqs-device/device-api/src/main/java/com/njcn/device/pojo/param/TabCensusParam.java create mode 100644 pqs-device/device-api/src/main/java/com/njcn/device/pojo/po/TopMsg.java create mode 100644 pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/DeviceOnlineTabVO.java create mode 100644 pqs-device/device-boot/src/main/java/com/njcn/device/controller/TabCensusController.java create mode 100644 pqs-device/device-boot/src/main/java/com/njcn/device/mapper/DeviceOnlineDataMapper.java create mode 100644 pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/DeviceOnlineDataMapper.xml create mode 100644 pqs-device/device-boot/src/main/java/com/njcn/device/service/DeviceOnlineDataService.java create mode 100644 pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/DeviceOnlineDataServiceImpl.java diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/dto/DeviceOnlineDataDTO.java b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/dto/DeviceOnlineDataDTO.java new file mode 100644 index 000000000..0825b8020 --- /dev/null +++ b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/dto/DeviceOnlineDataDTO.java @@ -0,0 +1,17 @@ +package com.njcn.device.pojo.dto; + +import lombok.Data; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/17 16:02 + */ +@Data +public class DeviceOnlineDataDTO { + + private String deviceId; + private String lineGrade; + private String levelName; + +} diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/param/TabCensusParam.java b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/param/TabCensusParam.java new file mode 100644 index 000000000..d06df59b1 --- /dev/null +++ b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/param/TabCensusParam.java @@ -0,0 +1,49 @@ +package com.njcn.device.pojo.param; + +import com.njcn.common.pojo.constant.PatternRegex; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/16 14:30 + */ +@Data +@ApiModel +public class TabCensusParam { + + @ApiModelProperty("开始时间") + @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误") + private String searchBeginTime; + + @ApiModelProperty("结束时间") + @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误") + private String searchEndTime; + + /** + * (监测点、终端)等级 + */ + @ApiModelProperty("(监测点、终端)等级:0-全部;1-极重要;2-重要;3-普通;4-不重要;") + @NotNull(message = "(监测点、终端)等级不可为空") + @Max(value = 4) + @Min(value = 0) + private Integer level; + + /** + * 是否合格 + */ + @ApiModelProperty("是否合格:0-全部;1-不合格;2-合格;") + @NotNull(message = "是否合格不可为空") + @Max(value = 2) + @Min(value = 0) + private Integer qualify; + + +} diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/po/TopMsg.java b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/po/TopMsg.java new file mode 100644 index 000000000..8481a75c3 --- /dev/null +++ b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/po/TopMsg.java @@ -0,0 +1,48 @@ +package com.njcn.device.pojo.po; + +import lombok.Data; +import org.influxdb.annotation.Column; +import org.influxdb.annotation.Measurement; + +import java.time.Instant; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/16 16:13 + */ +@Data +@Measurement(name = "pqs_top_msg") +public class TopMsg { + + @Column(name = "time") + private Instant timeId; + + @Column(name = "dev_id") + private String deviceId; + + @Column(name = "alarm_num") + private Integer alarmNum; + + @Column(name = "com_out_num") + private Integer comOutNum; + + @Column(name = "flow_num") + private Integer flowNum; + + @Column(name = "over_limit") + private Integer overLimit; + + @Column(name = "flow_stand") + private Integer flowStand; + + @Column(name = "state") + private Integer state; + + @Column(name = "com_out_desc") + private String comOutDesc; + + @Column(name = "alarm_desc") + private String alarmDesc; + +} diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/DeviceOnlineTabVO.java b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/DeviceOnlineTabVO.java new file mode 100644 index 000000000..aa6635feb --- /dev/null +++ b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/DeviceOnlineTabVO.java @@ -0,0 +1,39 @@ +package com.njcn.device.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/16 15:06 + */ +@Data +public class DeviceOnlineTabVO { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("终端Id") + private String deviceId; + + @ApiModelProperty("省份名称") + private String provinceName; + + @ApiModelProperty("供电公司名称") + private String gdName; + + @ApiModelProperty("变电站名称") + private String subName; + + @ApiModelProperty("终端名称") + private String deviceName; + + @ApiModelProperty("在线率") + private Double onlineRate; + + @ApiModelProperty("中断次数") + private Integer comOutNumber; + + @ApiModelProperty("等级") + private String level; + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/controller/TabCensusController.java b/pqs-device/device-boot/src/main/java/com/njcn/device/controller/TabCensusController.java new file mode 100644 index 000000000..116c53ac3 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/controller/TabCensusController.java @@ -0,0 +1,58 @@ +package com.njcn.device.controller; + +import com.alibaba.nacos.client.naming.utils.CollectionUtils; +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.TabCensusParam; +import com.njcn.device.pojo.vo.DeviceOnlineTabVO; +import com.njcn.device.service.DeviceOnlineDataService; +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; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/16 14:34 + */ +@Validated +@Slf4j +@RestController +@RequestMapping("/tabCensus") +@Api(tags = "列表统计") +@AllArgsConstructor +public class TabCensusController extends BaseController { + + private final DeviceOnlineDataService deviceOnlineDataService; + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/getDeviceOnlineData") + @ApiOperation("获取终端在线率列表") + @ApiImplicitParam(name = "tabCensusParam", value = "区域统计查询参数", required = true) + public HttpResult> getDeviceOnlineData(@RequestBody @Validated TabCensusParam tabCensusParam) { + String methodDescribe = getMethodDescribe("getDeviceOnlineData"); + LogUtil.njcnDebug(log, "{}", methodDescribe, tabCensusParam); + List result = deviceOnlineDataService.getDeviceOnlineData(tabCensusParam); + if (CollectionUtils.isEmpty(result)) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + } + + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/DeviceOnlineDataMapper.java b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/DeviceOnlineDataMapper.java new file mode 100644 index 000000000..7c61463d5 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/DeviceOnlineDataMapper.java @@ -0,0 +1,25 @@ +package com.njcn.device.mapper; + +import com.njcn.device.pojo.dto.DeviceOnlineDataDTO; +import com.njcn.device.pojo.vo.DeviceOnlineTabVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/17 15:00 + */ +public interface DeviceOnlineDataMapper { + + /**获取终端对应的等级 */ + List getMinDeviceLevel(@Param("deviceIds") List deviceIds); + + + DeviceOnlineDataDTO getMinDeviceLevelById(String deviceIds); + + /**获取终端集合父级名称 */ + List getDeviceFatherData(@Param("deviceIds") List deviceIds); + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/DeviceOnlineDataMapper.xml b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/DeviceOnlineDataMapper.xml new file mode 100644 index 000000000..17e3a0eea --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/DeviceOnlineDataMapper.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/service/DeviceOnlineDataService.java b/pqs-device/device-boot/src/main/java/com/njcn/device/service/DeviceOnlineDataService.java new file mode 100644 index 000000000..41a343178 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/service/DeviceOnlineDataService.java @@ -0,0 +1,17 @@ +package com.njcn.device.service; + +import com.njcn.device.pojo.param.TabCensusParam; +import com.njcn.device.pojo.vo.DeviceOnlineTabVO; + +import java.util.List; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/16 14:53 + */ +public interface DeviceOnlineDataService { + + List getDeviceOnlineData(TabCensusParam tabCensusParam); + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/DeviceOnlineDataServiceImpl.java b/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/DeviceOnlineDataServiceImpl.java new file mode 100644 index 000000000..afe981fd9 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/DeviceOnlineDataServiceImpl.java @@ -0,0 +1,152 @@ +package com.njcn.device.service.impl; + +import com.njcn.device.mapper.DeviceOnlineDataMapper; +import com.njcn.device.pojo.dto.DeviceOnlineDataDTO; +import com.njcn.device.pojo.param.TabCensusParam; +import com.njcn.device.pojo.po.TopMsg; +import com.njcn.device.pojo.vo.DeviceOnlineTabVO; +import com.njcn.device.pojo.vo.LineInfluxDbOnlineVO; +import com.njcn.device.service.DeviceOnlineDataService; +import com.njcn.influxdb.param.InfluxDBPublicParam; +import com.njcn.influxdb.utils.InfluxDbUtils; +import lombok.AllArgsConstructor; +import org.influxdb.dto.QueryResult; +import org.influxdb.impl.InfluxDBResultMapper; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/16 14:55 + */ +@Service +@AllArgsConstructor +public class DeviceOnlineDataServiceImpl implements DeviceOnlineDataService { + + private final DeviceOnlineDataMapper deviceOnlineDataMapper; + + private final InfluxDbUtils influxDbUtils; + + private final AreaDeviceOnlineServiceImpl areaDeviceOnlineService; + + @Override + public List getDeviceOnlineData(TabCensusParam tabCensusParam) { + List deviceOnlineTabVOS = new ArrayList<>(); + + List topMsg = getTopMsg(tabCensusParam.getSearchBeginTime(), tabCensusParam.getSearchEndTime()); + if (!CollectionUtils.isEmpty(topMsg)) { + List deviceIds = topMsg.stream().map(TopMsg::getDeviceId).collect(Collectors.toList()); + List onlineData = areaDeviceOnlineService.getOnlineData(deviceIds, tabCensusParam.getSearchBeginTime(), tabCensusParam.getSearchEndTime()); + if (!CollectionUtils.isEmpty(onlineData)) { + for (LineInfluxDbOnlineVO onlineVO: onlineData) { + onlineVO.setOnlineRate(new BigDecimal(onlineVO.getOnlineRate()).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + Integer qualify = tabCensusParam.getQualify(); + if (qualify==1) { + onlineData = onlineData.stream().filter(item -> item.getOnlineRate() < 95).collect(Collectors.toList()); + } if (qualify==2) { + onlineData = onlineData.stream().filter(item -> item.getOnlineRate() >= 95).collect(Collectors.toList()); + } + List devIndexes = onlineData.stream().map(LineInfluxDbOnlineVO::getDevIndex).collect(Collectors.toList()); + + List devIndexesByLevel = getDevIndexesByLevel(devIndexes, tabCensusParam.getLevel()); + topMsg = topMsg.stream().filter(item -> devIndexesByLevel.contains(item.getDeviceId())).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(topMsg)) { + List deviceFatherData = deviceOnlineDataMapper.getDeviceFatherData(devIndexesByLevel); + for (TopMsg msg: topMsg) { + DeviceOnlineTabVO deviceOnlineTabVO = new DeviceOnlineTabVO(); + DeviceOnlineTabVO tabVO = deviceFatherData.stream().filter(item -> item.getDeviceId().equals(msg.getDeviceId())).collect(Collectors.toList()).get(0); + BeanUtils.copyProperties(tabVO, deviceOnlineTabVO); + deviceOnlineTabVO.setDeviceId(msg.getDeviceId()); + deviceOnlineTabVO.setComOutNumber(msg.getComOutNum()); + Double onlineRate = onlineData.stream().filter(item -> item.getDevIndex().equals(msg.getDeviceId())).collect(Collectors.toList()).get(0).getOnlineRate(); + deviceOnlineTabVO.setOnlineRate(onlineRate); + switch (tabCensusParam.getLevel()) { + case 0: + DeviceOnlineDataDTO minDeviceLevelById = deviceOnlineDataMapper.getMinDeviceLevelById(msg.getDeviceId()); + deviceOnlineTabVO.setLevel(minDeviceLevelById.getLevelName()); + break; + case 1: + deviceOnlineTabVO.setLevel("极重要"); + break; + case 2: + deviceOnlineTabVO.setLevel("重要"); + break; + case 3: + deviceOnlineTabVO.setLevel("普通"); + break; + case 4: + deviceOnlineTabVO.setLevel("不重要"); + break; + } + deviceOnlineTabVOS.add(deviceOnlineTabVO); + } + + } + + } + + } + + return deviceOnlineTabVOS; + } + + + /**通过监测点等级获取终端集合 */ + public List getDevIndexesByLevel(List deviceIds, Integer level) { + switch (level) { + case 0: + return deviceIds; + case 1: + List minDeviceLevelOne = deviceOnlineDataMapper.getMinDeviceLevel(deviceIds); + List collectListOne = minDeviceLevelOne.stream().filter(item -> item.getLineGrade().equals("486927bc1c09c14f1e54a5b1757bf5c4")).collect(Collectors.toList()); + deviceIds = collectListOne.stream().map(DeviceOnlineDataDTO::getDeviceId).distinct().collect(Collectors.toList()); + return deviceIds; + case 2: + List minDeviceLevelTwo = deviceOnlineDataMapper.getMinDeviceLevel(deviceIds); + List collectListTwo = minDeviceLevelTwo.stream().filter(item -> item.getLineGrade().equals("eae449e73806a5c810fa2d3b01bc3e50")).collect(Collectors.toList()); + deviceIds = collectListTwo.stream().map(DeviceOnlineDataDTO::getDeviceId).collect(Collectors.toList()); + return deviceIds; + case 3: + List minDeviceLevelThr = deviceOnlineDataMapper.getMinDeviceLevel(deviceIds); + List collectListThr = minDeviceLevelThr.stream().filter(item -> item.getLineGrade().equals("64b4afe96e874c3c3dc634ea3ef79a21")).collect(Collectors.toList()); + deviceIds = collectListThr.stream().map(DeviceOnlineDataDTO::getDeviceId).collect(Collectors.toList()); + return deviceIds; + case 4: + List minDeviceLevelFour = deviceOnlineDataMapper.getMinDeviceLevel(deviceIds); + List collectListFour = minDeviceLevelFour.stream().filter(item -> item.getLineGrade().equals("d3dac5ffa1daf6564e29e989e465135e")).collect(Collectors.toList()); + deviceIds = collectListFour.stream().map(DeviceOnlineDataDTO::getDeviceId).collect(Collectors.toList()); + return deviceIds; + } + + return null; + } + + + + /**查询按终端分组的中断次数 */ + private List getTopMsg(String startTime, String endTime) { + //组装sql语句 + StringBuilder string = new StringBuilder(); + string.append(InfluxDBPublicParam.TIME + " >= '" + startTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + endTime + InfluxDBPublicParam.END_TIME + "'"); + //sql语句 + String sql = "SELECT sum(com_out_num) as com_out_num FROM pqs_top_msg WHERE " + string + " group by dev_id " + InfluxDBPublicParam.TIME_ZONE; + //结果集 + QueryResult results = influxDbUtils.query(sql); + //结果集映射到对象中 + InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); + List topMsgList = resultMapper.toPOJO(results, TopMsg.class); + + return topMsgList; + } + + +}