区域统计终端在线率 数据完整性
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ import java.io.Serializable;
|
|||||||
@Data
|
@Data
|
||||||
@Measurement(name = "pqs_onlinerate")
|
@Measurement(name = "pqs_onlinerate")
|
||||||
public class LineInfluxDbOnlineVO implements Serializable {
|
public class LineInfluxDbOnlineVO implements Serializable {
|
||||||
@Column(name = "dev_index")
|
@Column(name = "dev_id")
|
||||||
private String devIndex;
|
private String devIndex;
|
||||||
|
|
||||||
@Column(name = "onlinerate")
|
@Column(name = "onlinerate")
|
||||||
|
|||||||
@@ -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<List<AreaDeviceOnlineVO>> getAreaDeviceOnline(@RequestBody @Validated AreaDeviceOnlineParam areaDeviceOnlineParam) {
|
||||||
|
String methodDescribe = getMethodDescribe("getAreaDeviceOnline");
|
||||||
|
LogUtil.njcnDebug(log, "{}", methodDescribe, areaDeviceOnlineParam);
|
||||||
|
List<AreaDeviceOnlineVO> 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<List<AreaIntegrityVO>> getAreaIntegrity(@RequestBody @Validated AreaDeviceOnlineParam areaDeviceOnlineParam) {
|
||||||
|
String methodDescribe = getMethodDescribe("getAreaIntegrity");
|
||||||
|
LogUtil.njcnDebug(log, "{}", methodDescribe, areaDeviceOnlineParam);
|
||||||
|
List<AreaIntegrityVO> result = areaIntegrityService.getAreaIntegrity(areaDeviceOnlineParam);
|
||||||
|
if (CollectionUtils.isEmpty(result)) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<String> selectLineIds(String deviceId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过监测点等级获取监测点ID集合
|
||||||
|
*/
|
||||||
|
List<String> selectLineIdBylineLevel(String lineLevel);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.njcn.device.mapper.AreaDeviceOnlineMapper">
|
||||||
|
|
||||||
|
<select id="selectLineIds" resultType="java.lang.String">
|
||||||
|
SELECT
|
||||||
|
A2.Id
|
||||||
|
FROM
|
||||||
|
pq_line A,
|
||||||
|
pq_line A1,
|
||||||
|
pq_line A2
|
||||||
|
WHERE A.Id = #{deviceId}
|
||||||
|
AND A1.Pid = A.Id
|
||||||
|
AND A2.Pid = A1.Id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectLineIdBylineLevel" resultType="java.lang.String">
|
||||||
|
SELECT
|
||||||
|
Id
|
||||||
|
FROM
|
||||||
|
pq_line_detail
|
||||||
|
WHERE Line_Grade = #{lineLevel}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -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<AreaDeviceOnlineVO> getAreaDeviceOnline(AreaDeviceOnlineParam areaDeviceOnlineParam);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<AreaIntegrityVO> getAreaIntegrity(AreaDeviceOnlineParam areaDeviceOnlineParam);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.njcn.device.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author: chenchao
|
||||||
|
* @date: 2022/08/15 15:33
|
||||||
|
*/
|
||||||
|
public interface DeviceOnlineService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<AreaDeviceOnlineVO> getAreaDeviceOnline(AreaDeviceOnlineParam areaDeviceOnlineParam) {
|
||||||
|
List<AreaDeviceOnlineVO> areaDeviceOnlineVOS = new ArrayList<>();
|
||||||
|
List<GeneralDeviceDTO> generalDeviceDTOS = generalDeviceInfoController.getPracticalAllDeviceInfo(areaDeviceOnlineParam).getData();
|
||||||
|
|
||||||
|
// //区域下的所有终端id集合
|
||||||
|
// List<String> deviceIds = generalDeviceDTOS.stream().flatMap(dto -> dto.getDeviceIndexes().stream()).collect(Collectors.toList());
|
||||||
|
if (!CollectionUtils.isEmpty(generalDeviceDTOS)) {
|
||||||
|
for (GeneralDeviceDTO generalDeviceDTO: generalDeviceDTOS) {
|
||||||
|
AreaDeviceOnlineVO areaDeviceOnlineVO = new AreaDeviceOnlineVO();
|
||||||
|
List<String> 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<String> deviceIndexes, AreaDeviceOnlineVO areaDeviceOnlineVO, AreaDeviceOnlineParam areaDeviceOnlineParam) {
|
||||||
|
List<Device> devices = deviceMapper.selectBatchIds(deviceIndexes);
|
||||||
|
BiFunction<Integer, List<String>, 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<LineInfluxDbOnlineVO> 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<String> deviceIndexes, List<String> lineIndexes) {
|
||||||
|
List<String> lineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(lineLevel);
|
||||||
|
List<String> result = lineIdList.stream().filter(item -> lineIndexes.contains(item)).collect(Collectors.toList());
|
||||||
|
int i = 0;
|
||||||
|
for (String id: deviceIndexes) {
|
||||||
|
List<String> strings = areaDeviceOnlineMapper.selectLineIds(id);
|
||||||
|
List<String> lineIds = result.stream().filter(item -> strings.contains(item)).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isEmpty(lineIds)) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取终端运行状态*/
|
||||||
|
private BiFunction<Integer, List<String>, Long> countDeviceRunStatus(List<Device> pqDeviceList) {
|
||||||
|
return (runFlag, deviceIndexes) -> pqDeviceList.stream()
|
||||||
|
.filter(t -> Objects.equals(t.getRunFlag(), runFlag))
|
||||||
|
.filter(t -> deviceIndexes.contains(t.getId()))
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取按终端分组的终端在线率*/
|
||||||
|
public List<LineInfluxDbOnlineVO> getOnlineData(List<String> 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<LineInfluxDbOnlineVO> lineInfluxDbOnlineVOS = influxDBResultMapper.toPOJO(result, LineInfluxDbOnlineVO.class);
|
||||||
|
return lineInfluxDbOnlineVOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<AreaIntegrityVO> getAreaIntegrity(AreaDeviceOnlineParam areaDeviceOnlineParam) {
|
||||||
|
List<AreaIntegrityVO> areaIntegrityVOS = new ArrayList<>();
|
||||||
|
List<GeneralDeviceDTO> generalDeviceDTOS = generalDeviceInfoController.getPracticalAllDeviceInfo(areaDeviceOnlineParam).getData();
|
||||||
|
if (!CollectionUtils.isEmpty(generalDeviceDTOS)) {
|
||||||
|
for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOS) {
|
||||||
|
AreaIntegrityVO areaIntegrityVO = new AreaIntegrityVO();
|
||||||
|
List<String> 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<String> firstLineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(firstLevel);
|
||||||
|
List<String> 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<String> secLineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(secLevel);
|
||||||
|
List<String> 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<String> thiLineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(thiLevel);
|
||||||
|
List<String> 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<String> fourLineIdList = areaDeviceOnlineMapper.selectLineIdBylineLevel(fourLevel);
|
||||||
|
List<String> 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<String> lineIndexes, AreaIntegrityVO areaIntegrityVO, AreaDeviceOnlineParam areaDeviceOnlineParam) {
|
||||||
|
List<LineInfluxDbInegrityVO> 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<LineInfluxDbInegrityVO> getIntegrityData(List<String> 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<LineInfluxDbInegrityVO> eventDetailList = influxDBResultMapper.toPOJO(result, LineInfluxDbInegrityVO.class);
|
||||||
|
return eventDetailList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user