Commit 13b8732d by 向延琳

速度优化

1 parent 5d7dc8d6
......@@ -35,6 +35,8 @@ import org.springframework.util.StopWatch;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -212,34 +214,24 @@ public class DashboardService extends AbstractCommonService {
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 今日激活查询", stopWatch.getLastTaskTimeMillis());
//在线率
stopWatch.start();
String onLineRate = getOnLineRate(totalActiveDevice);
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 在线率查询", stopWatch.getLastTaskTimeMillis());
//断电报警
stopWatch.start();
List<String> sns = vehicleMapper.getAllDeviceSnByAuth();
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - sn查询", stopWatch.getLastTaskTimeMillis());
stopWatch.start();
AlarmTrackRecQueryDTO query = new AlarmTrackRecQueryDTO();
query.setSns(sns);
query.setStartTime(DateUtil.getTodayFirstDateTimeStr());
query.setStartTime(DateUtil.getTodayLastDateTimeStr());
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);
Integer lightCount = remoteAlarmService.getAlarmCount(query);
stopWatch.stop();
log.info("{} 耗时:{} ms", "看板统计信息 - 今日光感报警查询", stopWatch.getLastTaskTimeMillis());
CompletableFuture<Integer> lightFutureFuture = CompletableFuture.supplyAsync(() -> getLightCount(query));
//围栏报警
stopWatch.start();
......@@ -247,10 +239,51 @@ public class DashboardService extends AbstractCommonService {
int fenceCount = fenceList.stream().reduce(0, Integer::sum);
stopWatch.stop();
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) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//获取不计算离线的设备列表(并同时将该设备计算为在线设备数量) by 杨林龙
String offlineSnWhitelist = PropertiesUtils.getProperty("uncalculated.offline.device.sns");
StatSearch offlineSearch = new StatSearch().setStatPattern("%Y-%m-%d");
......@@ -262,7 +295,10 @@ public class DashboardService extends AbstractCommonService {
int onlineNumber = Math.abs(totalActiveDevice - allOfflineNumber);
//计算在线率
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!