Browse Source

优化设备在线率

develop
gaoguangchao 4 months ago
parent
commit
7fa7637f2c
  1. 49
      zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java
  2. 67
      zc-business/src/main/java/com/zc/business/controller/queryParams/OnlineQueryParams.java
  3. 12
      zc-business/src/main/java/com/zc/business/domain/OnlineLog.java
  4. 7
      zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java
  5. 7
      zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java
  6. 9
      zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java
  7. 33
      zc-business/src/main/resources/mapper/OnlineSumMapper.xml
  8. 1
      zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml

49
zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java

@ -1,5 +1,6 @@
package com.zc.business.controller; package com.zc.business.controller;
import cn.hutool.core.lang.tree.Tree;
import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.DateUtils;
import com.github.pagehelper.util.StringUtil; import com.github.pagehelper.util.StringUtil;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
@ -11,6 +12,7 @@ import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.business.constant.RedisKeyConstants; import com.zc.business.constant.RedisKeyConstants;
import com.zc.business.controller.queryParams.OnlineQueryParams;
import com.zc.business.domain.*; import com.zc.business.domain.*;
import com.zc.business.enums.UniversalEnum; import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.IDcRoadSectionService; import com.zc.business.service.IDcRoadSectionService;
@ -54,23 +56,37 @@ public class DcDeviceOnlineController extends BaseController {
private static final String ORDERRULE = "orderRule";//排序策略key private static final String ORDERRULE = "orderRule";//排序策略key
/*@ApiOperation("设备状态导出")
@Log(title = "【设备状态导出】", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Status status) {
if (status.getDeviceName() != null) {
status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()));
}
String type = status.getType();
if (type != null) {
status.setTypes(type.split(UniversalEnum.COMMA.getValue()));
}
List<Status> listStatus = statusService.export(status);
ExcelUtil<Status> util = new ExcelUtil<>(Status.class);
util.exportExcel(response, listStatus, UniversalEnum.DEVICE_STATUS_LIST.getValue());
}*/
@ApiOperation("设备状态列表按时间和类型") @ApiOperation("设备状态列表按时间和类型")
@GetMapping("/tablist") @GetMapping("/tablist")
public TableDataInfo getTabList(@RequestParam("type") String[] deviceTypes, public TableDataInfo getTabList(OnlineQueryParams params) {
@RequestParam(required = false) String orderByField,
@RequestParam(required = false) String orderDirection, if(ObjectUtils.isEmpty(params.getType())) {
@RequestParam(required = false) String searchValue) {
if(ObjectUtils.isEmpty(deviceTypes)) {
return getDataTable(new ArrayList<>()); return getDataTable(new ArrayList<>());
} }
if(StringUtil.isEmpty(orderByField) ||"time".equals(orderByField)) { if(StringUtil.isEmpty(params.getOrderByField()) ||"time".equals(params.getOrderByField())) {
orderByField = "online_rate"; params.setOrderByField("online_rate");
} }
startPage(); startPage();
List<OnlineSum> sums = onlineSumService.queryByDeviceTypesOfToday(deviceTypes, orderByField, orderDirection, searchValue); List<OnlineSum> sums = onlineSumService.queryByDeviceTypesOfToday(params);
Map<String,OnlineSum> onlineSumMap = redisCache.getCacheMap(RedisKeyConstants.DEVICE_ONLINE); /*Map<String,OnlineSum> onlineSumMap = redisCache.getCacheMap(RedisKeyConstants.DEVICE_ONLINE);
String date = LocalDate.now().toString(); String date = LocalDate.now().toString();*/
for (OnlineSum sum : sums) { /*for (OnlineSum sum : sums) {
String deviceId = sum.getDeviceId().toString(); String deviceId = sum.getDeviceId().toString();
String hKey = date+":"+deviceId; String hKey = date+":"+deviceId;
OnlineSum online = onlineSumMap.get(hKey); OnlineSum online = onlineSumMap.get(hKey);
@ -79,7 +95,7 @@ public class DcDeviceOnlineController extends BaseController {
} }
sum.setLastOnlineTime(onlineSumMap.get(hKey).getLastOnlineTime()); sum.setLastOnlineTime(onlineSumMap.get(hKey).getLastOnlineTime());
sum.setDeviceStatus(onlineSumMap.get(hKey).getDeviceStatus()); sum.setDeviceStatus(onlineSumMap.get(hKey).getDeviceStatus());
} }*/
return getDataTable(sums); return getDataTable(sums);
} }
//按时间划分设备柱状图 //按时间划分设备柱状图
@ -231,8 +247,8 @@ public class DcDeviceOnlineController extends BaseController {
@RequestParam("deviceId") Long deviceId, @RequestParam("deviceId") Long deviceId,
@RequestParam("queryDate")String queryDate) { @RequestParam("queryDate")String queryDate) {
LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime end = LocalDateTime.now(); LocalDateTime end = LocalDateTime.parse(queryDate + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
startPage(); //startPage();
List<OnlineLog> onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId); List<OnlineLog> onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId);
return getDataTable(onlineLogs); return getDataTable(onlineLogs);
} }
@ -245,7 +261,7 @@ public class DcDeviceOnlineController extends BaseController {
String RTT_AVG = "rttAvg";//平均往返时延 String RTT_AVG = "rttAvg";//平均往返时延
String MONITOR_TIME = "time";//监控时间 String MONITOR_TIME = "time";//监控时间
LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime end = LocalDateTime.now(); LocalDateTime end = LocalDateTime.parse(queryDate + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
List<OnlineLog> onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId); List<OnlineLog> onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId);
Map<String,Object> returnMap = new HashMap<>(); Map<String,Object> returnMap = new HashMap<>();
List<String> xAxis = new ArrayList<>(); List<String> xAxis = new ArrayList<>();
@ -259,7 +275,7 @@ public class DcDeviceOnlineController extends BaseController {
returnMap.put(LOST_RATE,lossRate); returnMap.put(LOST_RATE,lossRate);
returnMap.put(RTT_AVG,rttAvg); returnMap.put(RTT_AVG,rttAvg);
returnMap.put(MONITOR_TIME,xAxis); returnMap.put(MONITOR_TIME,xAxis);
return AjaxResult.success(returnMap); return AjaxResult.success(new TreeMap<>(returnMap));
} }
enum DeviceType { enum DeviceType {
GUN_CAMERA("1-1","高清网络枪型固定摄像机"), GUN_CAMERA("1-1","高清网络枪型固定摄像机"),
@ -327,4 +343,5 @@ public class DcDeviceOnlineController extends BaseController {
return stringBuilder.toString(); return stringBuilder.toString();
} }
} }
} }

67
zc-business/src/main/java/com/zc/business/controller/queryParams/OnlineQueryParams.java

@ -0,0 +1,67 @@
package com.zc.business.controller.queryParams;
public class OnlineQueryParams {
private String[] type;
private String orderByField;
private String orderDirection;
private String useState;
private String deviceIp;
private String stakeMark;
private String deviceState;
public String[] getType() {
return type;
}
public void setType(String[] type) {
this.type = type;
}
public String getOrderByField() {
return orderByField;
}
public void setOrderByField(String orderByField) {
this.orderByField = orderByField;
}
public String getOrderDirection() {
return orderDirection;
}
public void setOrderDirection(String orderDirection) {
this.orderDirection = orderDirection;
}
public String getUseState() {
return useState;
}
public void setUseState(String useState) {
this.useState = useState;
}
public String getDeviceIp() {
return deviceIp;
}
public void setDeviceIp(String deviceIp) {
this.deviceIp = deviceIp;
}
public String getStakeMark() {
return stakeMark;
}
public void setStakeMark(String stakeMark) {
this.stakeMark = stakeMark;
}
public String getDeviceState() {
return deviceState;
}
public void setDeviceState(String deviceState) {
this.deviceState = deviceState;
}
}

12
zc-business/src/main/java/com/zc/business/domain/OnlineLog.java

@ -204,14 +204,6 @@ public class OnlineLog implements Serializable {
onlineLog.setLossCount(onlineLog.getSendCount() - onlineLog.getReceiveCount()); onlineLog.setLossCount(onlineLog.getSendCount() - onlineLog.getReceiveCount());
double lossRate = onlineLog.getSendCount()==0?0:(double) onlineLog.getLossCount() / onlineLog.getSendCount() * 100; double lossRate = onlineLog.getSendCount()==0?0:(double) onlineLog.getLossCount() / onlineLog.getSendCount() * 100;
onlineLog.setLossRate(lossRate); onlineLog.setLossRate(lossRate);
double rttAvg = onlineLog.getRttAvg();
if(rttAvg > 0 && rttAvg <= 30){
onlineLog.setNetworkQuality(NetworkQuality.GOOD.getValue());
}else if(rttAvg >30 && rttAvg <= 100){
onlineLog.setNetworkQuality(NetworkQuality.NORMAL.getValue());
}else {
onlineLog.setNetworkQuality(NetworkQuality.BAD.getValue());
}
onlineLog.setNetworkQuality(NetworkQuality.ofNetworkQuality(onlineLog.getLossRate(),onlineLog.getRttAvg())); onlineLog.setNetworkQuality(NetworkQuality.ofNetworkQuality(onlineLog.getLossRate(),onlineLog.getRttAvg()));
onlineLog.setMonitorTime(LocalDateTime.now()); onlineLog.setMonitorTime(LocalDateTime.now());
return onlineLog; return onlineLog;
@ -225,9 +217,9 @@ public class OnlineLog implements Serializable {
onlineLog.setDeviceType(device.getDeviceType()); onlineLog.setDeviceType(device.getDeviceType());
onlineLog.setNetworkQuality(NetworkQuality.BAD.getValue()); onlineLog.setNetworkQuality(NetworkQuality.BAD.getValue());
onlineLog.setMonitorTime(LocalDateTime.now()); onlineLog.setMonitorTime(LocalDateTime.now());
onlineLog.setSendCount(4); onlineLog.setSendCount(10);
onlineLog.setReceiveCount(0); onlineLog.setReceiveCount(0);
onlineLog.setLossCount(4); onlineLog.setLossCount(10);
onlineLog.setLossRate(MathUtil.doubleTwoDecimal(100)); onlineLog.setLossRate(MathUtil.doubleTwoDecimal(100));
onlineLog.setRttAvg(0); onlineLog.setRttAvg(0);
onlineLog.setDeviceStatus(UniversalEnum.ZERO.getValue()); onlineLog.setDeviceStatus(UniversalEnum.ZERO.getValue());

7
zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java

@ -1,5 +1,6 @@
package com.zc.business.mapper; package com.zc.business.mapper;
import com.zc.business.controller.queryParams.OnlineQueryParams;
import com.zc.business.domain.OnlineSum; import com.zc.business.domain.OnlineSum;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.time.LocalDate; import java.time.LocalDate;
@ -18,9 +19,5 @@ public interface OnlineSumMapper {
); );
List<OnlineSum> queryByDateOfDeviceType(@Param("queryDate") LocalDate queryDate); List<OnlineSum> queryByDateOfDeviceType(@Param("queryDate") LocalDate queryDate);
List<OnlineSum> queryByDateOfRoad(@Param("queryDate") LocalDate queryDate); List<OnlineSum> queryByDateOfRoad(@Param("queryDate") LocalDate queryDate);
List<OnlineSum> queryByDeviceTypesOfToday( List<OnlineSum> queryByDeviceTypesOfToday(OnlineQueryParams params);
@Param("types") String[] deviceTypes,
@Param("orderByField") String orderByField,
@Param("orderDirection") String orderDirection,
@Param("searchValue") String searchValue);
} }

7
zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java

@ -1,5 +1,6 @@
package com.zc.business.service; package com.zc.business.service;
import com.zc.business.controller.queryParams.OnlineQueryParams;
import com.zc.business.domain.OnlineSum; import com.zc.business.domain.OnlineSum;
import java.time.LocalDate; import java.time.LocalDate;
@ -19,9 +20,5 @@ public interface IOnlineSumService {
List<OnlineSum> queryByDateOfDeviceType(LocalDate queryDate); List<OnlineSum> queryByDateOfDeviceType(LocalDate queryDate);
List<OnlineSum> queryByDateOfRoad(LocalDate queryDate); List<OnlineSum> queryByDateOfRoad(LocalDate queryDate);
List<OnlineSum> queryByDeviceTypesOfToday( List<OnlineSum> queryByDeviceTypesOfToday(OnlineQueryParams params);
String[] deviceTypes,
String orderByField,
String orderDirection,
String searchValue);
} }

9
zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java

@ -1,5 +1,6 @@
package com.zc.business.service.impl; package com.zc.business.service.impl;
import com.zc.business.controller.queryParams.OnlineQueryParams;
import com.zc.business.domain.OnlineSum; import com.zc.business.domain.OnlineSum;
import com.zc.business.mapper.OnlineSumMapper; import com.zc.business.mapper.OnlineSumMapper;
import com.zc.business.service.IOnlineSumService; import com.zc.business.service.IOnlineSumService;
@ -45,11 +46,7 @@ public class OnlineSumServiceImpl implements IOnlineSumService {
} }
@Override @Override
public List<OnlineSum> queryByDeviceTypesOfToday(String[] deviceTypes, String orderByField, String orderDirection, String searchValue) { public List<OnlineSum> queryByDeviceTypesOfToday(OnlineQueryParams params) {
return onlineSumMapper.queryByDeviceTypesOfToday( return onlineSumMapper.queryByDeviceTypesOfToday(params);
deviceTypes,
orderByField,
orderDirection,
searchValue);
} }
} }

33
zc-business/src/main/resources/mapper/OnlineSumMapper.xml

@ -21,6 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="stakeMark" column="stake_mark"/> <result property="stakeMark" column="stake_mark"/>
<result property="direction" column="direction"/> <result property="direction" column="direction"/>
<result property="useState" column="use_state"/> <result property="useState" column="use_state"/>
<result property="deviceStatus" column="device_state"/>
</resultMap> </resultMap>
<insert id="duplicateKeyUpdate"> <insert id="duplicateKeyUpdate">
@ -46,8 +47,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select s.id,s.device_id,total_count,online_rate,offline_rate,loss_rate,rtt_avg,network_quality,statistical_date,COALESCE(d.child_type,d.device_type) as device_type select s.id,s.device_id,total_count,online_rate,offline_rate,loss_rate,rtt_avg,network_quality,statistical_date,COALESCE(d.child_type,d.device_type) as device_type
from dc_online_sum s join dc_device d on s.device_id = d.id from dc_online_sum s join dc_device d on s.device_id = d.id
where d.use_state = 1 where d.use_state = 1
AND (s.statistical_date BETWEEN #{startDate} AND #{endDate}) and (s.statistical_date BETWEEN #{startDate} AND #{endDate})
AND (d.device_type in <if test="types.length != 0">
and (d.device_type in
<foreach item="typeItem" collection="types" open="(" separator="," close=")"> <foreach item="typeItem" collection="types" open="(" separator="," close=")">
#{typeItem} #{typeItem}
</foreach> </foreach>
@ -56,8 +58,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{typeItem} #{typeItem}
</foreach> </foreach>
) )
</if>
<if test="direction != null and direction != ''"> <if test="direction != null and direction != ''">
AND d.direction = #{direction} and d.direction = #{direction}
</if> </if>
</select> </select>
<select id="queryByDateOfDeviceType" resultMap="OnlineSum"> <select id="queryByDateOfDeviceType" resultMap="OnlineSum">
@ -76,29 +79,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where d.use_state = 1 and s.statistical_date = #{queryDate} where d.use_state = 1 and s.statistical_date = #{queryDate}
</select> </select>
<select id="queryByDeviceTypesOfToday" resultMap="OnlineSum"> <select id="queryByDeviceTypesOfToday" parameterType="com.zc.business.controller.queryParams.OnlineQueryParams" resultMap="OnlineSum">
select d.device_ip,d.device_name,d.stake_mark,COALESCE (d.child_type, d.device_type) as device_type, select d.device_ip,d.device_name,d.stake_mark,COALESCE (d.child_type, d.device_type) as device_type,
d.direction,d.use_state, d.direction,d.use_state,d.device_state,
s.id,s.device_id,total_count,online_rate, s.id,s.device_id,total_count,online_rate,
offline_rate,loss_rate,rtt_avg,network_quality,statistical_date offline_rate,loss_rate,rtt_avg,network_quality,statistical_date
from dc_device d from dc_device d
join dc_online_sum s on s.device_id = d.id join dc_online_sum s on s.device_id = d.id
where where
s.statistical_date = CURDATE() s.statistical_date = CURDATE()
<if test="types.length != 0"> <if test="type.length != 0">
and (d.device_type in and (d.device_type in
<foreach item="typeItem" collection="types" open="(" separator="," close=")"> <foreach item="typeItem" collection="type" open="(" separator="," close=")">
#{typeItem} #{typeItem}
</foreach> </foreach>
or d.child_type in or d.child_type in
<foreach item="typeItem" collection="types" open="(" separator="," close=")"> <foreach item="typeItem" collection="type" open="(" separator="," close=")">
#{typeItem} #{typeItem}
</foreach> </foreach>
) )
</if> </if>
<if test="searchValue != null and searchValue != ''"> <if test="deviceIp != null and deviceIp != ''">
and (d.device_ip like concat('%',#{searchValue},'%') and d.device_ip like concat('%',#{deviceIp},'%')
or d.stake_mark like concat('%',#{searchValue},'%')) </if>
<if test="stakeMark != null and stakeMark != ''">
and d.stake_mark like concat('%',#{stakeMark},'%')
</if>
<if test="deviceState != null and deviceState != ''">
and d.device_state = #{deviceState}
</if>
<if test="useState != null and useState != ''">
and d.use_state = #{useState}
</if> </if>
<if test="orderByField != null and orderDirection != null"> <if test="orderByField != null and orderDirection != null">
order by ${orderByField} ${orderDirection} order by ${orderByField} ${orderDirection}

1
zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml

@ -54,6 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id,device_id,device_name,device_ip,stake_mark,device_status,send_count, select id,device_id,device_name,device_ip,stake_mark,device_status,send_count,
receive_count,loss_count,loss_rate,network_quality,rtt_avg,monitor_time receive_count,loss_count,loss_rate,network_quality,rtt_avg,monitor_time
from dc_online_log where device_id = #{deviceId} and monitor_time between #{startTime} and #{endTime} from dc_online_log where device_id = #{deviceId} and monitor_time between #{startTime} and #{endTime}
order by monitor_time desc
</select> </select>
</mapper> </mapper>

Loading…
Cancel
Save