use of com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsChartVO in project orion-ops by lijiahangmax.
the class StatisticsServiceImpl method schedulerTaskStatistic.
@Override
public SchedulerTaskRecordStatisticsVO schedulerTaskStatistic(Long taskId) {
// 查询缓存
String cacheKey = Strings.format(KeyConst.SCHEDULER_TASK_STATISTIC_KEY, taskId);
String cacheData = redisTemplate.opsForValue().get(cacheKey);
if (Strings.isBlank(cacheData)) {
// 获取图表时间
Date[] chartDates = Dates.getIncrementDates(Dates.clearHms(), Calendar.DAY_OF_MONTH, -1, 7);
Date rangeStartDate = Arrays1.last(chartDates);
// 获取任务统计信息
SchedulerTaskRecordStatisticsDTO taskStatisticDTO = schedulerTaskRecordDAO.getTaskRecordStatistic(taskId, rangeStartDate);
SchedulerTaskRecordStatisticsVO statisticTask = Converts.to(taskStatisticDTO, SchedulerTaskRecordStatisticsVO.class);
// 获取机器统计信息
// List<SchedulerTaskRecordStatisticsDTO> machines = schedulerTaskRecordDAO.getTaskMachineRecordStatistic(taskId);
// List<SchedulerTaskMachineRecordStatisticsVO> statisticMachines = Converts.toList(machines, SchedulerTaskMachineRecordStatisticsVO.class);
// statisticTask.setMachineList(statisticMachines);
// 获取任务统计图表
List<SchedulerTaskRecordStatisticsDTO> dateStatistic = schedulerTaskRecordDAO.getTaskRecordDateStatistic(taskId, rangeStartDate);
Map<String, SchedulerTaskRecordStatisticsDTO> dateStatisticMap = dateStatistic.stream().collect(Collectors.toMap(s -> Dates.format(s.getDate(), Dates.YMD), Function.identity(), (e1, e2) -> e2));
// 填充数据
List<SchedulerTaskRecordStatisticsChartVO> statisticCharts = Arrays.stream(chartDates).sorted().map(s -> Dates.format(s, Dates.YMD)).map(date -> Optional.ofNullable(dateStatisticMap.get(date)).map(s -> Converts.to(s, SchedulerTaskRecordStatisticsChartVO.class)).orElseGet(() -> {
SchedulerTaskRecordStatisticsChartVO dateChart = new SchedulerTaskRecordStatisticsChartVO();
dateChart.setDate(date);
dateChart.setScheduledCount(0);
dateChart.setSuccessCount(0);
dateChart.setFailureCount(0);
return dateChart;
})).collect(Collectors.toList());
statisticTask.setCharts(statisticCharts);
// 设置缓存
redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(statisticTask), Integer.parseInt(SystemEnvAttr.STATISTICS_CACHE_EXPIRE.getValue()), TimeUnit.MINUTES);
return statisticTask;
} else {
return JSON.parseObject(cacheData, SchedulerTaskRecordStatisticsVO.class);
}
}
Aggregations