From 7fa7637f2cb159e476e07ee394732b646ea790aa Mon Sep 17 00:00:00 2001 From: gaoguangchao <443960933@qq.com> Date: Thu, 25 Jul 2024 17:42:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceOnlineController.java | 49 +++++++++----- .../queryParams/OnlineQueryParams.java | 67 +++++++++++++++++++ .../com/zc/business/domain/OnlineLog.java | 12 +--- .../zc/business/mapper/OnlineSumMapper.java | 7 +- .../business/service/IOnlineSumService.java | 7 +- .../service/impl/OnlineSumServiceImpl.java | 9 +-- .../main/resources/mapper/OnlineSumMapper.xml | 33 ++++++--- .../mapper/business/OnlineLogMapper.xml | 1 + 8 files changed, 132 insertions(+), 53 deletions(-) create mode 100644 zc-business/src/main/java/com/zc/business/controller/queryParams/OnlineQueryParams.java diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java index 30dcf139..e48beea5 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java @@ -1,5 +1,6 @@ package com.zc.business.controller; +import cn.hutool.core.lang.tree.Tree; import com.alibaba.excel.util.DateUtils; import com.github.pagehelper.util.StringUtil; 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.poi.ExcelUtil; import com.zc.business.constant.RedisKeyConstants; +import com.zc.business.controller.queryParams.OnlineQueryParams; import com.zc.business.domain.*; import com.zc.business.enums.UniversalEnum; import com.zc.business.service.IDcRoadSectionService; @@ -54,23 +56,37 @@ public class DcDeviceOnlineController extends BaseController { 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 listStatus = statusService.export(status); + ExcelUtil util = new ExcelUtil<>(Status.class); + util.exportExcel(response, listStatus, UniversalEnum.DEVICE_STATUS_LIST.getValue()); + }*/ + @ApiOperation("设备状态列表按时间和类型") @GetMapping("/tablist") - public TableDataInfo getTabList(@RequestParam("type") String[] deviceTypes, - @RequestParam(required = false) String orderByField, - @RequestParam(required = false) String orderDirection, - @RequestParam(required = false) String searchValue) { - if(ObjectUtils.isEmpty(deviceTypes)) { + public TableDataInfo getTabList(OnlineQueryParams params) { + + if(ObjectUtils.isEmpty(params.getType())) { return getDataTable(new ArrayList<>()); } - if(StringUtil.isEmpty(orderByField) ||"time".equals(orderByField)) { - orderByField = "online_rate"; + if(StringUtil.isEmpty(params.getOrderByField()) ||"time".equals(params.getOrderByField())) { + params.setOrderByField("online_rate"); } startPage(); - List sums = onlineSumService.queryByDeviceTypesOfToday(deviceTypes, orderByField, orderDirection, searchValue); - Map onlineSumMap = redisCache.getCacheMap(RedisKeyConstants.DEVICE_ONLINE); - String date = LocalDate.now().toString(); - for (OnlineSum sum : sums) { + List sums = onlineSumService.queryByDeviceTypesOfToday(params); + /*Map onlineSumMap = redisCache.getCacheMap(RedisKeyConstants.DEVICE_ONLINE); + String date = LocalDate.now().toString();*/ + /*for (OnlineSum sum : sums) { String deviceId = sum.getDeviceId().toString(); String hKey = date+":"+deviceId; OnlineSum online = onlineSumMap.get(hKey); @@ -79,7 +95,7 @@ public class DcDeviceOnlineController extends BaseController { } sum.setLastOnlineTime(onlineSumMap.get(hKey).getLastOnlineTime()); sum.setDeviceStatus(onlineSumMap.get(hKey).getDeviceStatus()); - } + }*/ return getDataTable(sums); } //按时间划分设备柱状图 @@ -231,8 +247,8 @@ public class DcDeviceOnlineController extends BaseController { @RequestParam("deviceId") Long deviceId, @RequestParam("queryDate")String queryDate) { LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - LocalDateTime end = LocalDateTime.now(); - startPage(); + LocalDateTime end = LocalDateTime.parse(queryDate + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + //startPage(); List onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId); return getDataTable(onlineLogs); } @@ -245,7 +261,7 @@ public class DcDeviceOnlineController extends BaseController { String RTT_AVG = "rttAvg";//平均往返时延 String MONITOR_TIME = "time";//监控时间 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 onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId); Map returnMap = new HashMap<>(); List xAxis = new ArrayList<>(); @@ -259,7 +275,7 @@ public class DcDeviceOnlineController extends BaseController { returnMap.put(LOST_RATE,lossRate); returnMap.put(RTT_AVG,rttAvg); returnMap.put(MONITOR_TIME,xAxis); - return AjaxResult.success(returnMap); + return AjaxResult.success(new TreeMap<>(returnMap)); } enum DeviceType { GUN_CAMERA("1-1","高清网络枪型固定摄像机"), @@ -327,4 +343,5 @@ public class DcDeviceOnlineController extends BaseController { return stringBuilder.toString(); } } + } diff --git a/zc-business/src/main/java/com/zc/business/controller/queryParams/OnlineQueryParams.java b/zc-business/src/main/java/com/zc/business/controller/queryParams/OnlineQueryParams.java new file mode 100644 index 00000000..07015556 --- /dev/null +++ b/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; + } +} diff --git a/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java b/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java index 08b3a26e..5d2666ea 100644 --- a/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java +++ b/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()); double lossRate = onlineLog.getSendCount()==0?0:(double) onlineLog.getLossCount() / onlineLog.getSendCount() * 100; 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.setMonitorTime(LocalDateTime.now()); return onlineLog; @@ -225,9 +217,9 @@ public class OnlineLog implements Serializable { onlineLog.setDeviceType(device.getDeviceType()); onlineLog.setNetworkQuality(NetworkQuality.BAD.getValue()); onlineLog.setMonitorTime(LocalDateTime.now()); - onlineLog.setSendCount(4); + onlineLog.setSendCount(10); onlineLog.setReceiveCount(0); - onlineLog.setLossCount(4); + onlineLog.setLossCount(10); onlineLog.setLossRate(MathUtil.doubleTwoDecimal(100)); onlineLog.setRttAvg(0); onlineLog.setDeviceStatus(UniversalEnum.ZERO.getValue()); diff --git a/zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java b/zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java index 14766791..98da126c 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/OnlineSumMapper.java @@ -1,5 +1,6 @@ package com.zc.business.mapper; +import com.zc.business.controller.queryParams.OnlineQueryParams; import com.zc.business.domain.OnlineSum; import org.apache.ibatis.annotations.Param; import java.time.LocalDate; @@ -18,9 +19,5 @@ public interface OnlineSumMapper { ); List queryByDateOfDeviceType(@Param("queryDate") LocalDate queryDate); List queryByDateOfRoad(@Param("queryDate") LocalDate queryDate); - List queryByDeviceTypesOfToday( - @Param("types") String[] deviceTypes, - @Param("orderByField") String orderByField, - @Param("orderDirection") String orderDirection, - @Param("searchValue") String searchValue); + List queryByDeviceTypesOfToday(OnlineQueryParams params); } diff --git a/zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java b/zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java index 3d8277d9..f6d4460c 100644 --- a/zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java +++ b/zc-business/src/main/java/com/zc/business/service/IOnlineSumService.java @@ -1,5 +1,6 @@ package com.zc.business.service; +import com.zc.business.controller.queryParams.OnlineQueryParams; import com.zc.business.domain.OnlineSum; import java.time.LocalDate; @@ -19,9 +20,5 @@ public interface IOnlineSumService { List queryByDateOfDeviceType(LocalDate queryDate); List queryByDateOfRoad(LocalDate queryDate); - List queryByDeviceTypesOfToday( - String[] deviceTypes, - String orderByField, - String orderDirection, - String searchValue); + List queryByDeviceTypesOfToday(OnlineQueryParams params); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java index d365d9ff..0194e120 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/OnlineSumServiceImpl.java @@ -1,5 +1,6 @@ package com.zc.business.service.impl; +import com.zc.business.controller.queryParams.OnlineQueryParams; import com.zc.business.domain.OnlineSum; import com.zc.business.mapper.OnlineSumMapper; import com.zc.business.service.IOnlineSumService; @@ -45,11 +46,7 @@ public class OnlineSumServiceImpl implements IOnlineSumService { } @Override - public List queryByDeviceTypesOfToday(String[] deviceTypes, String orderByField, String orderDirection, String searchValue) { - return onlineSumMapper.queryByDeviceTypesOfToday( - deviceTypes, - orderByField, - orderDirection, - searchValue); + public List queryByDeviceTypesOfToday(OnlineQueryParams params) { + return onlineSumMapper.queryByDeviceTypesOfToday(params); } } diff --git a/zc-business/src/main/resources/mapper/OnlineSumMapper.xml b/zc-business/src/main/resources/mapper/OnlineSumMapper.xml index e068f9ab..e12b3379 100644 --- a/zc-business/src/main/resources/mapper/OnlineSumMapper.xml +++ b/zc-business/src/main/resources/mapper/OnlineSumMapper.xml @@ -21,6 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -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 from dc_online_sum s join dc_device d on s.device_id = d.id where d.use_state = 1 - AND (s.statistical_date BETWEEN #{startDate} AND #{endDate}) - AND (d.device_type in + and (s.statistical_date BETWEEN #{startDate} AND #{endDate}) + + and (d.device_type in #{typeItem} @@ -56,8 +58,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{typeItem} ) + - AND d.direction = #{direction} + and d.direction = #{direction} - 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, offline_rate,loss_rate,rtt_avg,network_quality,statistical_date from dc_device d join dc_online_sum s on s.device_id = d.id where s.statistical_date = CURDATE() - + and (d.device_type in - + #{typeItem} or d.child_type in - + #{typeItem} ) - - and (d.device_ip like concat('%',#{searchValue},'%') - or d.stake_mark like concat('%',#{searchValue},'%')) + + and d.device_ip like concat('%',#{deviceIp},'%') + + + and d.stake_mark like concat('%',#{stakeMark},'%') + + + and d.device_state = #{deviceState} + + + and d.use_state = #{useState} order by ${orderByField} ${orderDirection} diff --git a/zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml b/zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml index 8435073e..4f3200bb 100644 --- a/zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml +++ b/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, 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} + order by monitor_time desc