Commit 13b8732d by 向延琳

速度优化

1 parent 5d7dc8d6
...@@ -35,6 +35,8 @@ import org.springframework.util.StopWatch; ...@@ -35,6 +35,8 @@ import org.springframework.util.StopWatch;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -212,34 +214,24 @@ public class DashboardService extends AbstractCommonService { ...@@ -212,34 +214,24 @@ public class DashboardService extends AbstractCommonService {
stopWatch.stop(); stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 今日激活查询", stopWatch.getLastTaskTimeMillis()); log.info("{} 耗时:{} ms", "看板统计信息 - 今日激活查询", stopWatch.getLastTaskTimeMillis());
//在线率
stopWatch.start();
String onLineRate = getOnLineRate(totalActiveDevice);
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 在线率查询", stopWatch.getLastTaskTimeMillis());
//断电报警 //断电报警
stopWatch.start(); stopWatch.start();
List<String> sns = vehicleMapper.getAllDeviceSnByAuth(); List<String> sns = vehicleMapper.getAllDeviceSnByAuth();
stopWatch.stop(); stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - sn查询", stopWatch.getLastTaskTimeMillis()); log.info("{} 耗时:{} ms", "看板统计信息 - sn查询", stopWatch.getLastTaskTimeMillis());
stopWatch.start();
AlarmTrackRecQueryDTO query = new AlarmTrackRecQueryDTO(); AlarmTrackRecQueryDTO query = new AlarmTrackRecQueryDTO();
query.setSns(sns); query.setSns(sns);
query.setStartTime(DateUtil.getTodayFirstDateTimeStr()); query.setStartTime(DateUtil.getTodayFirstDateTimeStr());
query.setStartTime(DateUtil.getTodayLastDateTimeStr()); query.setStartTime(DateUtil.getTodayLastDateTimeStr());
query.setAlarmType(Constants.ALARM_TYPE_POWER_OFF); query.setAlarmType(Constants.ALARM_TYPE_POWER_OFF);
Integer powerOffCount = remoteAlarmService.getAlarmCount(query);
stopWatch.stop(); //断电报警
log.info("{} 耗时:{} ms", "看板统计信息 - 今日断电报警", stopWatch.getLastTaskTimeMillis()); CompletableFuture<Integer> powerOffFutureFuture = CompletableFuture.supplyAsync(() -> getPowerOffCount(query));
//光感报警 //光感报警
stopWatch.start();
query.setAlarmType(Constants.ALARM_TYPE_LIGHT); query.setAlarmType(Constants.ALARM_TYPE_LIGHT);
Integer lightCount = remoteAlarmService.getAlarmCount(query); CompletableFuture<Integer> lightFutureFuture = CompletableFuture.supplyAsync(() -> getLightCount(query));
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 今日光感报警查询", stopWatch.getLastTaskTimeMillis());
//围栏报警 //围栏报警
stopWatch.start(); stopWatch.start();
...@@ -247,10 +239,51 @@ public class DashboardService extends AbstractCommonService { ...@@ -247,10 +239,51 @@ public class DashboardService extends AbstractCommonService {
int fenceCount = fenceList.stream().reduce(0, Integer::sum); int fenceCount = fenceList.stream().reduce(0, Integer::sum);
stopWatch.stop(); stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 今日围栏报警查询", stopWatch.getLastTaskTimeMillis()); log.info("{} 耗时:{} ms", "看板统计信息 - 今日围栏报警查询", stopWatch.getLastTaskTimeMillis());
return new StatisticalInfoVO(totalActiveDevice, totalVehicle, todayActiveDevice, powerOffCount, fenceCount, lightCount, onLineRate);
//在线率
String onlineRate =getOnLineRate(totalActiveDevice);
int powerOffCount;
int lightCount;
try {
powerOffCount = powerOffFutureFuture.get();
lightCount = lightFutureFuture.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
return new StatisticalInfoVO(totalActiveDevice, totalVehicle, todayActiveDevice, powerOffCount, fenceCount, lightCount, onlineRate);
}
/**
* 今日光感
*/
private Integer getLightCount(AlarmTrackRecQueryDTO query) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Integer lightCount = remoteAlarmService.getAlarmCount(query);
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 今日光感报警查询", stopWatch.getLastTaskTimeMillis());
return lightCount;
} }
/**
* 今日断电报警
*/
private Integer getPowerOffCount(AlarmTrackRecQueryDTO query) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Integer powerOffCount = remoteAlarmService.getAlarmCount(query);
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 今日断电报警", stopWatch.getLastTaskTimeMillis());
return powerOffCount;
}
/**
* 在线率
*/
public String getOnLineRate(Integer totalActiveDevice) { public String getOnLineRate(Integer totalActiveDevice) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//获取不计算离线的设备列表(并同时将该设备计算为在线设备数量) by 杨林龙 //获取不计算离线的设备列表(并同时将该设备计算为在线设备数量) by 杨林龙
String offlineSnWhitelist = PropertiesUtils.getProperty("uncalculated.offline.device.sns"); String offlineSnWhitelist = PropertiesUtils.getProperty("uncalculated.offline.device.sns");
StatSearch offlineSearch = new StatSearch().setStatPattern("%Y-%m-%d"); StatSearch offlineSearch = new StatSearch().setStatPattern("%Y-%m-%d");
...@@ -262,7 +295,10 @@ public class DashboardService extends AbstractCommonService { ...@@ -262,7 +295,10 @@ public class DashboardService extends AbstractCommonService {
int onlineNumber = Math.abs(totalActiveDevice - allOfflineNumber); int onlineNumber = Math.abs(totalActiveDevice - allOfflineNumber);
//计算在线率 //计算在线率
NumberFormat numberFormat = NumberFormat.getInstance(); NumberFormat numberFormat = NumberFormat.getInstance();
return numberFormat.format((float) onlineNumber / (float) totalActiveDevice * 100); String result = numberFormat.format((float) onlineNumber / (float) totalActiveDevice * 100);
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 在线率查询", stopWatch.getLastTaskTimeMillis());
return result;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!