@ -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 < Status > listStatus = statusService . export ( status ) ;
ExcelUtil < Status > 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 . getO rderByField( ) ) | | "time" . equals ( params . getO rderByField( ) ) ) {
params . setOrderByField ( "online_rate" ) ;
}
startPage ( ) ;
List < OnlineSum > sums = onlineSumService . queryByDeviceTypesOfToday ( deviceTypes , orderByField , orderDirection , searchValue ) ;
Map < String , OnlineSum > onlineSumMap = redisCache . getCacheMap ( RedisKeyConstants . DEVICE_ONLINE ) ;
String date = LocalDate . now ( ) . toString ( ) ;
for ( OnlineSum sum : sums ) {
List < OnlineSum > sums = onlineSumService . queryByDeviceTypesOfToday ( params ) ;
/ * Map < String , OnlineSum > 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 < OnlineLog > 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 < OnlineLog > onlineLogs = onlineLogService . queryByDateAndDevice ( start , end , deviceId ) ;
Map < String , Object > returnMap = new HashMap < > ( ) ;
List < String > 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 ( ) ;
}
}
}