Search in sources :

Example 1 with SchedulerTaskRecordStatisticsDTO

use of com.orion.ops.entity.dto.SchedulerTaskRecordStatisticsDTO 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);
    }
}
Also used : com.orion.ops.dao(com.orion.ops.dao) java.util(java.util) Dates(com.orion.utils.time.Dates) Resource(javax.annotation.Resource) StatisticCountVO(com.orion.ops.entity.vo.StatisticCountVO) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) SchedulerTaskRecordStatisticsChartVO(com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsChartVO) SchedulerTaskRecordStatisticsVO(com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsVO) TimeUnit(java.util.concurrent.TimeUnit) StatisticsService(com.orion.ops.service.api.StatisticsService) Converts(com.orion.utils.convert.Converts) JSON(com.alibaba.fastjson.JSON) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr) Service(org.springframework.stereotype.Service) SchedulerTaskRecordStatisticsDTO(com.orion.ops.entity.dto.SchedulerTaskRecordStatisticsDTO) Arrays1(com.orion.utils.Arrays1) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) StatisticCountDTO(com.orion.ops.entity.dto.StatisticCountDTO) KeyConst(com.orion.ops.consts.KeyConst) StatisticsVO(com.orion.ops.entity.vo.StatisticsVO) Strings(com.orion.utils.Strings) SchedulerTaskRecordStatisticsChartVO(com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsChartVO) SchedulerTaskRecordStatisticsVO(com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsVO) SchedulerTaskRecordStatisticsDTO(com.orion.ops.entity.dto.SchedulerTaskRecordStatisticsDTO)

Aggregations

JSON (com.alibaba.fastjson.JSON)1 KeyConst (com.orion.ops.consts.KeyConst)1 SystemEnvAttr (com.orion.ops.consts.system.SystemEnvAttr)1 com.orion.ops.dao (com.orion.ops.dao)1 SchedulerTaskRecordStatisticsDTO (com.orion.ops.entity.dto.SchedulerTaskRecordStatisticsDTO)1 StatisticCountDTO (com.orion.ops.entity.dto.StatisticCountDTO)1 SchedulerTaskRecordStatisticsChartVO (com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsChartVO)1 SchedulerTaskRecordStatisticsVO (com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsVO)1 StatisticCountVO (com.orion.ops.entity.vo.StatisticCountVO)1 StatisticsVO (com.orion.ops.entity.vo.StatisticsVO)1 StatisticsService (com.orion.ops.service.api.StatisticsService)1 Arrays1 (com.orion.utils.Arrays1)1 Strings (com.orion.utils.Strings)1 Converts (com.orion.utils.convert.Converts)1 Dates (com.orion.utils.time.Dates)1 java.util (java.util)1 TimeUnit (java.util.concurrent.TimeUnit)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1