diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/param/AreaDeviceOnlineParam.java b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/param/AreaDeviceOnlineParam.java new file mode 100644 index 000000000..a89eb79ef --- /dev/null +++ b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/param/AreaDeviceOnlineParam.java @@ -0,0 +1,31 @@ +package com.njcn.device.pojo.param; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/11 21:05 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ApiModel +public class AreaDeviceOnlineParam extends DeviceInfoParam.BusinessParam { + + /** + * 监测点等级 + */ + @ApiModelProperty("监测点等级:0-全部;1-极重要;2-重要;3-普通;4-不重要;") + @NotNull(message = "监测点等级不可为空") + @Max(value = 4) + @Min(value = 0) + private Integer lineLevel; + +} diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/AreaDeviceOnlineVO.java b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/AreaDeviceOnlineVO.java new file mode 100644 index 000000000..bda11bd57 --- /dev/null +++ b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/AreaDeviceOnlineVO.java @@ -0,0 +1,45 @@ +package com.njcn.device.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 区域终端在线率 + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/11 14:23 + */ +@Data +public class AreaDeviceOnlineVO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("区域名称") + private String areaName; + + @ApiModelProperty("终端数量") + private Integer number=0; + + @ApiModelProperty("投运") + private Integer normal=0; + + @ApiModelProperty("投运率") + private Double normalRate=3.14159; + + @ApiModelProperty("热备用") + private Integer breaks=0; + + @ApiModelProperty("热备用率") + private Double breaksRate=3.14159; + + @ApiModelProperty("停运") + private Integer shutdown=0; + + @ApiModelProperty("停运率") + private Double shutdownRate=3.14159; + + @ApiModelProperty("在线率") + private Double onlineRate=3.14159; + +} diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/AreaIntegrityVO.java b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/AreaIntegrityVO.java new file mode 100644 index 000000000..4aa36df96 --- /dev/null +++ b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/AreaIntegrityVO.java @@ -0,0 +1,25 @@ +package com.njcn.device.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 区域数据完整性 + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/15 15:49 + */ +@Data +public class AreaIntegrityVO { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("区域名称") + private String areaName; + + @ApiModelProperty("监测点数量") + private Integer number=0; + + @ApiModelProperty("数据完整性") + private Double integrity=3.14159; + +} diff --git a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/LineInfluxDbOnlineVO.java b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/LineInfluxDbOnlineVO.java index 2c64de870..4de73f5e6 100644 --- a/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/LineInfluxDbOnlineVO.java +++ b/pqs-device/device-api/src/main/java/com/njcn/device/pojo/vo/LineInfluxDbOnlineVO.java @@ -14,7 +14,7 @@ import java.io.Serializable; @Data @Measurement(name = "pqs_onlinerate") public class LineInfluxDbOnlineVO implements Serializable { - @Column(name = "dev_index") + @Column(name = "dev_id") private String devIndex; @Column(name = "onlinerate") diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/controller/AreaDeviceOnlineController.java b/pqs-device/device-boot/src/main/java/com/njcn/device/controller/AreaDeviceOnlineController.java new file mode 100644 index 000000000..88ea4e6f2 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/controller/AreaDeviceOnlineController.java @@ -0,0 +1,78 @@ +package com.njcn.device.controller; + +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.AreaDeviceOnlineParam; +import com.njcn.device.pojo.vo.AreaDeviceOnlineVO; +import com.njcn.device.pojo.vo.AreaIntegrityVO; +import com.njcn.device.service.AreaDeviceOnlineService; +import com.njcn.device.service.AreaIntegrityService; +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.CollectionUtils; +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/11 14:05 + */ +@Validated +@Slf4j +@RestController +@RequestMapping("/areaDeviceOnline") +@Api(tags = "区域统计") +@AllArgsConstructor +public class AreaDeviceOnlineController extends BaseController { + + private final AreaDeviceOnlineService areaDeviceOnlineService; + + private final AreaIntegrityService areaIntegrityService; + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/getAreaDeviceOnline") + @ApiOperation("获取区域终端在线率") + @ApiImplicitParam(name = "areaDeviceOnlineParam", value = "查询参数实体", required = true) + public HttpResult> getAreaDeviceOnline(@RequestBody @Validated AreaDeviceOnlineParam areaDeviceOnlineParam) { + String methodDescribe = getMethodDescribe("getAreaDeviceOnline"); + LogUtil.njcnDebug(log, "{}", methodDescribe, areaDeviceOnlineParam); + List result = areaDeviceOnlineService.getAreaDeviceOnline(areaDeviceOnlineParam); + if (CollectionUtils.isEmpty(result)) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + } + + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/getAreaIntegrity") + @ApiOperation("获取区域数据完整性") + @ApiImplicitParam(name = "areaDeviceOnlineParam", value = "查询参数实体", required = true) + public HttpResult> getAreaIntegrity(@RequestBody @Validated AreaDeviceOnlineParam areaDeviceOnlineParam) { + String methodDescribe = getMethodDescribe("getAreaIntegrity"); + LogUtil.njcnDebug(log, "{}", methodDescribe, areaDeviceOnlineParam); + List result = areaIntegrityService.getAreaIntegrity(areaDeviceOnlineParam); + 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/AreaDeviceOnlineMapper.java b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/AreaDeviceOnlineMapper.java new file mode 100644 index 000000000..d4a2dee82 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/AreaDeviceOnlineMapper.java @@ -0,0 +1,23 @@ +package com.njcn.device.mapper; + +import java.util.List; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/12 13:29 + */ +public interface AreaDeviceOnlineMapper { + + + /** + * 通过终端ID获取监测点集合 + */ + List selectLineIds(String deviceId); + + /** + * 通过监测点等级获取监测点ID集合 + */ + List selectLineIdBylineLevel(String lineLevel); + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/AreaDeviceOnlineMapper.xml b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/AreaDeviceOnlineMapper.xml new file mode 100644 index 000000000..92d59d553 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/mapper/mapping/AreaDeviceOnlineMapper.xml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/service/AreaDeviceOnlineService.java b/pqs-device/device-boot/src/main/java/com/njcn/device/service/AreaDeviceOnlineService.java new file mode 100644 index 000000000..7b907b2b5 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/service/AreaDeviceOnlineService.java @@ -0,0 +1,17 @@ +package com.njcn.device.service; + +import com.njcn.device.pojo.param.AreaDeviceOnlineParam; +import com.njcn.device.pojo.vo.AreaDeviceOnlineVO; + +import java.util.List; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/11 20:52 + */ +public interface AreaDeviceOnlineService { + + List getAreaDeviceOnline(AreaDeviceOnlineParam areaDeviceOnlineParam); + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/service/AreaIntegrityService.java b/pqs-device/device-boot/src/main/java/com/njcn/device/service/AreaIntegrityService.java new file mode 100644 index 000000000..03fcc4602 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/service/AreaIntegrityService.java @@ -0,0 +1,17 @@ +package com.njcn.device.service; + +import com.njcn.device.pojo.param.AreaDeviceOnlineParam; +import com.njcn.device.pojo.vo.AreaIntegrityVO; + +import java.util.List; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/15 15:43 + */ +public interface AreaIntegrityService { + + List getAreaIntegrity(AreaDeviceOnlineParam areaDeviceOnlineParam); + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/service/DeviceOnlineService.java b/pqs-device/device-boot/src/main/java/com/njcn/device/service/DeviceOnlineService.java new file mode 100644 index 000000000..099307b37 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/service/DeviceOnlineService.java @@ -0,0 +1,12 @@ +package com.njcn.device.service; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/15 15:33 + */ +public interface DeviceOnlineService { + + + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/AreaDeviceOnlineServiceImpl.java b/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/AreaDeviceOnlineServiceImpl.java new file mode 100644 index 000000000..ff7b072ef --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/AreaDeviceOnlineServiceImpl.java @@ -0,0 +1,177 @@ +package com.njcn.device.service.impl; + +import cn.hutool.core.date.DateUtil; +import com.njcn.device.controller.GeneralDeviceInfoController; +import com.njcn.device.mapper.AreaDeviceOnlineMapper; +import com.njcn.device.mapper.DeviceMapper; +import com.njcn.device.pojo.dto.GeneralDeviceDTO; +import com.njcn.device.pojo.param.AreaDeviceOnlineParam; +import com.njcn.device.pojo.param.DeviceInfoParam; +import com.njcn.device.pojo.po.Device; +import com.njcn.device.pojo.vo.AreaDeviceOnlineVO; +import com.njcn.device.pojo.vo.LineInfluxDbOnlineVO; +import com.njcn.device.service.AreaDeviceOnlineService; +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.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.Objects; +import java.util.function.BiFunction; +import java.util.stream.Collectors; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/08/11 20:53 + */ +@Service +@AllArgsConstructor +public class AreaDeviceOnlineServiceImpl implements AreaDeviceOnlineService { + + private final GeneralDeviceInfoController generalDeviceInfoController; + + private final AreaDeviceOnlineMapper areaDeviceOnlineMapper; + + private final DeviceMapper deviceMapper; + + private final InfluxDbUtils influxDbUtils; + + @Override + public List getAreaDeviceOnline(AreaDeviceOnlineParam areaDeviceOnlineParam) { + List areaDeviceOnlineVOS = new ArrayList<>(); + List generalDeviceDTOS = generalDeviceInfoController.getPracticalAllDeviceInfo(areaDeviceOnlineParam).getData(); + + // //区域下的所有终端id集合 + // List deviceIds = generalDeviceDTOS.stream().flatMap(dto -> dto.getDeviceIndexes().stream()).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(generalDeviceDTOS)) { + for (GeneralDeviceDTO generalDeviceDTO: generalDeviceDTOS) { + AreaDeviceOnlineVO areaDeviceOnlineVO = new AreaDeviceOnlineVO(); + List deviceIndexes = generalDeviceDTO.getDeviceIndexes(); + if (CollectionUtils.isEmpty(deviceIndexes)) { + areaDeviceOnlineVO.setAreaName(generalDeviceDTO.getName()); + areaDeviceOnlineVOS.add(areaDeviceOnlineVO); + continue; + } + areaDeviceOnlineVO.setAreaName(generalDeviceDTO.getName()); + switch (areaDeviceOnlineParam.getLineLevel()) { + case 0: + // 查全部 + areaDeviceOnlineVO.setNumber(deviceIndexes.size()); + areaDeviceOnlineVO = deviceToAreaDeviceOnlineVO(deviceIndexes, areaDeviceOnlineVO, areaDeviceOnlineParam); + + break; + case 1: + // 查极重要 + String firstLevel = "486927bc1c09c14f1e54a5b1757bf5c4"; + int deviceNumberFirst = getDeviceNumber(firstLevel, deviceIndexes, generalDeviceDTO.getLineIndexes()); + areaDeviceOnlineVO.setNumber(deviceNumberFirst); + areaDeviceOnlineVO = deviceToAreaDeviceOnlineVO(deviceIndexes, areaDeviceOnlineVO, areaDeviceOnlineParam); + + break; + case 2: + // 查重要 + String secLevel = "eae449e73806a5c810fa2d3b01bc3e50"; + int deviceNumberSec = getDeviceNumber(secLevel, deviceIndexes, generalDeviceDTO.getLineIndexes()); + areaDeviceOnlineVO.setNumber(deviceNumberSec); + areaDeviceOnlineVO = deviceToAreaDeviceOnlineVO(deviceIndexes, areaDeviceOnlineVO, areaDeviceOnlineParam); + + break; + case 3: + // 查普通 + String thiLevel = "64b4afe96e874c3c3dc634ea3ef79a21"; + int deviceNumberThi = getDeviceNumber(thiLevel, deviceIndexes, generalDeviceDTO.getLineIndexes()); + areaDeviceOnlineVO.setNumber(deviceNumberThi); + areaDeviceOnlineVO = deviceToAreaDeviceOnlineVO(deviceIndexes, areaDeviceOnlineVO, areaDeviceOnlineParam); + + break; + case 4: + // 查不重要 + String fourLevel = "d3dac5ffa1daf6564e29e989e465135e"; + int deviceNumberFour = getDeviceNumber(fourLevel, deviceIndexes, generalDeviceDTO.getLineIndexes()); + areaDeviceOnlineVO.setNumber(deviceNumberFour); + areaDeviceOnlineVO = deviceToAreaDeviceOnlineVO(deviceIndexes, areaDeviceOnlineVO, areaDeviceOnlineParam); + + break; + } + areaDeviceOnlineVOS.add(areaDeviceOnlineVO); + } + } + + return areaDeviceOnlineVOS; + } + + + private AreaDeviceOnlineVO deviceToAreaDeviceOnlineVO(List deviceIndexes, AreaDeviceOnlineVO areaDeviceOnlineVO, AreaDeviceOnlineParam areaDeviceOnlineParam) { + List devices = deviceMapper.selectBatchIds(deviceIndexes); + BiFunction, Long> integerListLongBiFunction = countDeviceRunStatus(devices); + areaDeviceOnlineVO.setNormal(integerListLongBiFunction.apply(0, deviceIndexes).intValue()); + areaDeviceOnlineVO.setBreaks(integerListLongBiFunction.apply(1, deviceIndexes).intValue()); + areaDeviceOnlineVO.setShutdown(integerListLongBiFunction.apply(2, deviceIndexes).intValue()); + double normalRate = areaDeviceOnlineVO.getNormal().doubleValue() / deviceIndexes.size() * 100; + areaDeviceOnlineVO.setNormalRate(new BigDecimal(normalRate).setScale(2, RoundingMode.HALF_UP).doubleValue()); + double breaksRate = areaDeviceOnlineVO.getBreaks().doubleValue() / deviceIndexes.size() * 100; + areaDeviceOnlineVO.setBreaksRate(new BigDecimal(breaksRate).setScale(2, RoundingMode.HALF_UP).doubleValue()); + double shutdownRate = areaDeviceOnlineVO.getShutdown().doubleValue() / deviceIndexes.size() * 100; + areaDeviceOnlineVO.setShutdownRate(new BigDecimal(shutdownRate).setScale(2, RoundingMode.HALF_UP).doubleValue()); + List onlineData = getOnlineData(deviceIndexes, areaDeviceOnlineParam); + if (!CollectionUtils.isEmpty(onlineData)) { + double avgOnline = onlineData.stream().mapToDouble(LineInfluxDbOnlineVO::getOnlineRate).sum() / onlineData.size(); + areaDeviceOnlineVO.setOnlineRate(new BigDecimal(avgOnline).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + return areaDeviceOnlineVO; + } + + private int getDeviceNumber(String lineLevel, List deviceIndexes, List lineIndexes) { + List lineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(lineLevel); + List result = lineIdList.stream().filter(item -> lineIndexes.contains(item)).collect(Collectors.toList()); + int i = 0; + for (String id: deviceIndexes) { + List strings = areaDeviceOnlineMapper.selectLineIds(id); + List lineIds = result.stream().filter(item -> strings.contains(item)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(lineIds)) { + ++i; + } + } + return i; + } + + /** 获取终端运行状态*/ + private BiFunction, Long> countDeviceRunStatus(List pqDeviceList) { + return (runFlag, deviceIndexes) -> pqDeviceList.stream() + .filter(t -> Objects.equals(t.getRunFlag(), runFlag)) + .filter(t -> deviceIndexes.contains(t.getId())) + .count(); + } + + /** 获取按终端分组的终端在线率*/ + public List getOnlineData(List deviceIndexes, DeviceInfoParam.BusinessParam deviceInfoParam) { + //组装sql语句 + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(deviceInfoParam.getSearchBeginTime()))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(deviceInfoParam.getSearchEndTime()))).append("' and "); + + for (int i = 0; i < deviceIndexes.size(); i++) { + if (deviceIndexes.size() - i != 1) { + stringBuilder.append("dev_id ='").append(deviceIndexes.get(i)).append("' or "); + } else { + stringBuilder.append("dev_id ='").append(deviceIndexes.get(i)).append("' "); + } + } + String sql = "select sum(online_min)/(sum(online_min) +sum(offline_min))*100 as onlinerate from pqs_onlinerate where " + stringBuilder + "group by dev_id " + InfluxDBPublicParam.TIME_ZONE; + System.out.println("sql>>>>>>>>>>>>>>>>>>>>>"+sql); + //获取暂降事件 + QueryResult result = influxDbUtils.query(sql); + InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); + List lineInfluxDbOnlineVOS = influxDBResultMapper.toPOJO(result, LineInfluxDbOnlineVO.class); + return lineInfluxDbOnlineVOS; + } + + +} diff --git a/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/AreaIntegrityServiceImpl.java b/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/AreaIntegrityServiceImpl.java new file mode 100644 index 000000000..7b871f5c4 --- /dev/null +++ b/pqs-device/device-boot/src/main/java/com/njcn/device/service/impl/AreaIntegrityServiceImpl.java @@ -0,0 +1,141 @@ +package com.njcn.device.service.impl; + +import cn.hutool.core.date.DateUtil; +import com.njcn.device.controller.GeneralDeviceInfoController; +import com.njcn.device.mapper.AreaDeviceOnlineMapper; +import com.njcn.device.pojo.dto.GeneralDeviceDTO; +import com.njcn.device.pojo.param.AreaDeviceOnlineParam; +import com.njcn.device.pojo.param.DeviceInfoParam; +import com.njcn.device.pojo.vo.AreaIntegrityVO; +import com.njcn.device.pojo.vo.LineInfluxDbInegrityVO; +import com.njcn.device.service.AreaIntegrityService; +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.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/15 15:53 + */ +@Service +@AllArgsConstructor +public class AreaIntegrityServiceImpl implements AreaIntegrityService { + + private final GeneralDeviceInfoController generalDeviceInfoController; + + private final AreaDeviceOnlineMapper areaDeviceOnlineMapper; + + private final InfluxDbUtils influxDbUtils; + + @Override + public List getAreaIntegrity(AreaDeviceOnlineParam areaDeviceOnlineParam) { + List areaIntegrityVOS = new ArrayList<>(); + List generalDeviceDTOS = generalDeviceInfoController.getPracticalAllDeviceInfo(areaDeviceOnlineParam).getData(); + if (!CollectionUtils.isEmpty(generalDeviceDTOS)) { + for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOS) { + AreaIntegrityVO areaIntegrityVO = new AreaIntegrityVO(); + List lineIndexes = generalDeviceDTO.getLineIndexes(); + if (CollectionUtils.isEmpty(lineIndexes)) { + areaIntegrityVO.setAreaName(generalDeviceDTO.getName()); + areaIntegrityVOS.add(areaIntegrityVO); + continue; + } + areaIntegrityVO.setAreaName(generalDeviceDTO.getName()); + switch (areaDeviceOnlineParam.getLineLevel()) { + case 0: + // 查全部 + areaIntegrityVO.setNumber(lineIndexes.size()); + areaIntegrityVO = lineIdsToAreaOnlineVO(lineIndexes, areaIntegrityVO, areaDeviceOnlineParam); + areaIntegrityVOS.add(areaIntegrityVO); + + break; + case 1: + // 查极重要 + String firstLevel = "486927bc1c09c14f1e54a5b1757bf5c4"; + List firstLineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(firstLevel); + List firstResult = firstLineIdList.stream().filter(item -> lineIndexes.contains(item)).collect(Collectors.toList()); + areaIntegrityVO.setNumber(firstResult.size()); + areaIntegrityVO = lineIdsToAreaOnlineVO(lineIndexes, areaIntegrityVO, areaDeviceOnlineParam); + areaIntegrityVOS.add(areaIntegrityVO); + + break; + case 2: + // 查重要 + String secLevel = "eae449e73806a5c810fa2d3b01bc3e50"; + List secLineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(secLevel); + List secResult = secLineIdList.stream().filter(item -> lineIndexes.contains(item)).collect(Collectors.toList()); + areaIntegrityVO.setNumber(secResult.size()); + areaIntegrityVO = lineIdsToAreaOnlineVO(lineIndexes, areaIntegrityVO, areaDeviceOnlineParam); + areaIntegrityVOS.add(areaIntegrityVO); + + break; + case 3: + // 查普通 + String thiLevel = "64b4afe96e874c3c3dc634ea3ef79a21"; + List thiLineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(thiLevel); + List thiResult = thiLineIdList.stream().filter(item -> lineIndexes.contains(item)).collect(Collectors.toList()); + areaIntegrityVO.setNumber(thiResult.size()); + areaIntegrityVO = lineIdsToAreaOnlineVO(lineIndexes, areaIntegrityVO, areaDeviceOnlineParam); + areaIntegrityVOS.add(areaIntegrityVO); + + break; + case 4: + // 查不重要 + String fourLevel = "d3dac5ffa1daf6564e29e989e465135e"; + List fourLineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(fourLevel); + List fourResult = fourLineIdList.stream().filter(item -> lineIndexes.contains(item)).collect(Collectors.toList()); + areaIntegrityVO.setNumber(fourResult.size()); + areaIntegrityVO = lineIdsToAreaOnlineVO(lineIndexes, areaIntegrityVO, areaDeviceOnlineParam); + areaIntegrityVOS.add(areaIntegrityVO); + + break; + } + + areaIntegrityVO.setAreaName(generalDeviceDTO.getName()); + } + } + return areaIntegrityVOS; + } + + private AreaIntegrityVO lineIdsToAreaOnlineVO(List lineIndexes, AreaIntegrityVO areaIntegrityVO, AreaDeviceOnlineParam areaDeviceOnlineParam) { + List integrityData = getIntegrityData(lineIndexes, areaDeviceOnlineParam); + if (!CollectionUtils.isEmpty(integrityData)) { + double avgIntegrity = integrityData.stream().mapToDouble(LineInfluxDbInegrityVO::getIntegrity).sum() / integrityData.size(); + areaIntegrityVO.setIntegrity(new BigDecimal(avgIntegrity).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + return areaIntegrityVO; + } + + /** 获取按监测点分组的数据完整性*/ + public List getIntegrityData(List lineIndexes, DeviceInfoParam.BusinessParam deviceInfoParam) { + //组装sql语句 + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(deviceInfoParam.getSearchBeginTime()))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(deviceInfoParam.getSearchEndTime()))).append("' and "); + for (int i = 0; i < lineIndexes.size(); i++) { + if (lineIndexes.size() - i != 1) { + stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("' or "); + } else { + stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("' "); + } + } + String sql = "select sum(real)/(sum(due))*100 as integrity from pqs_integrity where " + stringBuilder + "group by line_id " + InfluxDBPublicParam.TIME_ZONE; + //获取暂降事件 + QueryResult result = influxDbUtils.query(sql); + InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper(); + List eventDetailList = influxDBResultMapper.toPOJO(result, LineInfluxDbInegrityVO.class); + return eventDetailList; + } + + +}