系统配置细节修改
This commit is contained in:
@@ -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<List<DeviceOnlineTabVO>> getDeviceOnlineData(@RequestBody @Validated TabCensusParam tabCensusParam) {
|
||||
String methodDescribe = getMethodDescribe("getDeviceOnlineData");
|
||||
LogUtil.njcnDebug(log, "{}", methodDescribe, tabCensusParam);
|
||||
List<DeviceOnlineTabVO> result = deviceOnlineDataService.getDeviceOnlineData(tabCensusParam);
|
||||
if (CollectionUtils.isEmpty(result)) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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<DeviceOnlineDataDTO> getMinDeviceLevel(@Param("deviceIds") List<String> deviceIds);
|
||||
|
||||
|
||||
DeviceOnlineDataDTO getMinDeviceLevelById(String deviceIds);
|
||||
|
||||
/**获取终端集合父级名称 */
|
||||
List<DeviceOnlineTabVO> getDeviceFatherData(@Param("deviceIds") List<String> deviceIds);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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.DeviceOnlineDataMapper">
|
||||
|
||||
<select id="getMinDeviceLevel" resultType="DeviceOnlineDataDTO">
|
||||
SELECT
|
||||
a.`Id` deviceId,
|
||||
e.`Line_Grade` lineGrade,
|
||||
f.`Name` levelName,
|
||||
MIN(f.Algo_Describe)
|
||||
FROM
|
||||
pq_line a,
|
||||
pq_line b,
|
||||
pq_line c,
|
||||
pq_line_detail e,
|
||||
sys_dict_data f
|
||||
WHERE
|
||||
a.Id IN
|
||||
<foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND b.Pid = a.Id
|
||||
AND c.Pid = b.Id
|
||||
AND c.Id = e.Id
|
||||
AND e.Line_Grade = f.Id
|
||||
GROUP BY
|
||||
c.Id,
|
||||
e.Line_Grade
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getMinDeviceLevelById" resultType="DeviceOnlineDataDTO">
|
||||
SELECT
|
||||
a.`Id` deviceId,e.`Line_Grade` lineGrade,f.`Name` levelName,MIN(f.Algo_Describe)
|
||||
FROM
|
||||
pq_line a,
|
||||
pq_line b,
|
||||
pq_line c,
|
||||
pq_line_detail e,
|
||||
sys_dict_data f
|
||||
WHERE a.Id = #{deviceIds}
|
||||
AND b.Pid = a.Id
|
||||
AND c.Pid = b.Id
|
||||
AND c.Id = e.Id
|
||||
AND e.Line_Grade = f.Id
|
||||
GROUP BY e.Line_Grade
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getDeviceFatherData" resultType="DeviceOnlineTabVO">
|
||||
SELECT
|
||||
a.`Id` deviceId,
|
||||
a.`Name` deviceName,
|
||||
b.`Name` subName,
|
||||
c.`Name` gdName,
|
||||
e.`Name` provinceName
|
||||
FROM
|
||||
pq_line a,
|
||||
pq_line b,
|
||||
pq_line c,
|
||||
pq_line d,
|
||||
sys_area e
|
||||
WHERE a.Id IN
|
||||
<foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND a.Pid = b.Id
|
||||
AND b.Pid = c.Id
|
||||
AND c.Pid = d.Id
|
||||
AND d.Name = e.Id
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -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<DeviceOnlineTabVO> getDeviceOnlineData(TabCensusParam tabCensusParam);
|
||||
|
||||
}
|
||||
@@ -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<DeviceOnlineTabVO> getDeviceOnlineData(TabCensusParam tabCensusParam) {
|
||||
List<DeviceOnlineTabVO> deviceOnlineTabVOS = new ArrayList<>();
|
||||
|
||||
List<TopMsg> topMsg = getTopMsg(tabCensusParam.getSearchBeginTime(), tabCensusParam.getSearchEndTime());
|
||||
if (!CollectionUtils.isEmpty(topMsg)) {
|
||||
List<String> deviceIds = topMsg.stream().map(TopMsg::getDeviceId).collect(Collectors.toList());
|
||||
List<LineInfluxDbOnlineVO> 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<String> devIndexes = onlineData.stream().map(LineInfluxDbOnlineVO::getDevIndex).collect(Collectors.toList());
|
||||
|
||||
List<String> devIndexesByLevel = getDevIndexesByLevel(devIndexes, tabCensusParam.getLevel());
|
||||
topMsg = topMsg.stream().filter(item -> devIndexesByLevel.contains(item.getDeviceId())).collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(topMsg)) {
|
||||
List<DeviceOnlineTabVO> 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<String> getDevIndexesByLevel(List<String> deviceIds, Integer level) {
|
||||
switch (level) {
|
||||
case 0:
|
||||
return deviceIds;
|
||||
case 1:
|
||||
List<DeviceOnlineDataDTO> minDeviceLevelOne = deviceOnlineDataMapper.getMinDeviceLevel(deviceIds);
|
||||
List<DeviceOnlineDataDTO> 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<DeviceOnlineDataDTO> minDeviceLevelTwo = deviceOnlineDataMapper.getMinDeviceLevel(deviceIds);
|
||||
List<DeviceOnlineDataDTO> 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<DeviceOnlineDataDTO> minDeviceLevelThr = deviceOnlineDataMapper.getMinDeviceLevel(deviceIds);
|
||||
List<DeviceOnlineDataDTO> 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<DeviceOnlineDataDTO> minDeviceLevelFour = deviceOnlineDataMapper.getMinDeviceLevel(deviceIds);
|
||||
List<DeviceOnlineDataDTO> 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<TopMsg> 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<TopMsg> topMsgList = resultMapper.toPOJO(results, TopMsg.class);
|
||||
|
||||
return topMsgList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user