Search in sources :

Example 1 with QueryFillDataJobListDTO

use of com.dtstack.taier.scheduler.dto.fill.QueryFillDataJobListDTO in project Taier by DTStack.

the class JobService method fillDataJobList.

/**
 * 补数据实例列表
 *
 * @param dto 查询列表条件
 * @return 列表
 */
public PageResult<ReturnFillDataJobListVO> fillDataJobList(QueryFillDataJobListDTO dto) {
    Integer totalCount = 0;
    ReturnFillDataJobListVO dataJobDetailVO = new ReturnFillDataJobListVO();
    // 查询补数据是否存在,不存在直接返回结果
    ScheduleFillDataJob fillDataJob = fillDataJobService.getById(dto.getFillId());
    if (!checkFillDataJobList(fillDataJob, dataJobDetailVO)) {
        return new PageResult<>(dto.getCurrentPage(), dto.getPageSize(), totalCount, dataJobDetailVO);
    }
    dataJobDetailVO.setId(fillDataJob.getId());
    dataJobDetailVO.setFillDataName(fillDataJob.getJobName());
    // 关联任务
    List<Long> taskIds = null;
    if (StringUtils.isNotBlank(dto.getTaskName()) || dto.getOperatorId() != null) {
        List<ScheduleTaskShade> scheduleTaskShadeList = taskService.findTaskByTaskName(dto.getTaskName(), null, dto.getOperatorId());
        if (CollectionUtils.isEmpty(scheduleTaskShadeList)) {
            return new PageResult<>(dto.getCurrentPage(), dto.getPageSize(), totalCount, dataJobDetailVO);
        } else {
            taskIds = scheduleTaskShadeList.stream().map(ScheduleTaskShade::getTaskId).collect(Collectors.toList());
        }
    }
    // 查询实例表
    Page<ScheduleJob> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
    page = this.lambdaQuery().eq(ScheduleJob::getFlowJobId, 0).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).eq(ScheduleJob::getTenantId, dto.getTenantId()).eq(ScheduleJob::getFillId, dto.getFillId()).eq(ScheduleJob::getType, EScheduleType.FILL_DATA.getType()).in(ScheduleJob::getFillType, Lists.newArrayList(FillJobTypeEnum.DEFAULT.getType(), FillJobTypeEnum.RUN_JOB.getType())).in(CollectionUtils.isNotEmpty(taskIds), ScheduleJob::getTaskId, taskIds).in(CollectionUtils.isNotEmpty(dto.getTaskTypeList()), ScheduleJob::getTaskType, dto.getTaskTypeList()).in(CollectionUtils.isNotEmpty(dto.getJobStatusList()), ScheduleJob::getStatus, transform(dto.getJobStatusList())).between((dto.getCycStartDay() != null && dto.getCycEndDay() != null), ScheduleJob::getCycTime, getCycTime(dto.getCycStartDay()), getCycTime(dto.getCycEndDay())).orderBy(StringUtils.isNotBlank(dto.getExecTimeSort()), isAsc(dto.getExecTimeSort()), ScheduleJob::getExecTime).orderBy(StringUtils.isNotBlank(dto.getExecStartSort()), isAsc(dto.getExecStartSort()), ScheduleJob::getExecStartTime).orderBy(StringUtils.isNotBlank(dto.getExecEndSort()), isAsc(dto.getExecEndSort()), ScheduleJob::getExecEndTime).orderBy(StringUtils.isNotBlank(dto.getCycSort()), isAsc(dto.getCycSort()), ScheduleJob::getCycTime).orderBy(StringUtils.isNotBlank(dto.getRetryNumSort()), isAsc(dto.getRetryNumSort()), ScheduleJob::getRetryNum).orderBy(Boolean.TRUE, Boolean.FALSE, ScheduleJob::getGmtCreate).page(page);
    List<ScheduleJob> records = page.getRecords();
    // 封装结果集
    if (CollectionUtils.isNotEmpty(records)) {
        List<FillDataJobVO> fillDataJobVOS = Lists.newArrayList();
        List<Long> taskIdList = records.stream().map(ScheduleJob::getTaskId).collect(Collectors.toList());
        Map<Long, ScheduleTaskShade> taskShadeMap = taskService.lambdaQuery().in(ScheduleTaskShade::getTaskId, taskIdList).eq(ScheduleTaskShade::getIsDeleted, Deleted.NORMAL.getStatus()).list().stream().collect(Collectors.toMap(ScheduleTaskShade::getTaskId, g -> (g)));
        Map<Long, User> userMap = userService.listAll().stream().collect(Collectors.toMap(User::getId, g -> (g)));
        records.forEach(record -> {
            FillDataJobVO vo = FillDataJobMapstructTransfer.INSTANCE.scheduleJobToFillDataJobVO(record);
            vo.setStartExecTime(DateUtil.getDate(record.getExecStartTime(), DateUtil.STANDARD_DATETIME_FORMAT));
            vo.setEndExecTime(DateUtil.getDate(record.getExecEndTime(), DateUtil.STANDARD_DATETIME_FORMAT));
            vo.setCycTime(DateUtil.addTimeSplit(record.getCycTime()));
            vo.setExecTime(getExecTime(record));
            vo.setStatus(TaskStatus.getShowStatus(record.getStatus()));
            ScheduleTaskShade scheduleTaskShade = taskShadeMap.get(record.getTaskId());
            if (scheduleTaskShade != null) {
                vo.setTaskName(scheduleTaskShade.getName());
                vo.setOperatorId(scheduleTaskShade.getCreateUserId());
                vo.setOperatorName(userMap.get(scheduleTaskShade.getCreateUserId()) != null ? userMap.get(scheduleTaskShade.getCreateUserId()).getUserName() : "");
            }
            fillDataJobVOS.add(vo);
        });
        dataJobDetailVO.setFillDataJobVOLists(fillDataJobVOS);
    }
    dataJobDetailVO.setFillGenerateStatus(FillGeneratStatusEnum.FILL_FINISH.getType());
    return new PageResult<>(dto.getCurrentPage(), dto.getPageSize(), page.getTotal(), (int) page.getPages(), dataJobDetailVO);
}
Also used : ReturnJobStatusStatisticsVO(com.dtstack.taier.develop.vo.schedule.ReturnJobStatusStatisticsVO) CountFillDataJobStatusPO(com.dtstack.taier.dao.domain.po.CountFillDataJobStatusPO) UserService(com.dtstack.taier.develop.service.user.UserService) FillDataJobMapstructTransfer(com.dtstack.taier.develop.mapstruct.fill.FillDataJobMapstructTransfer) PageResult(com.dtstack.taier.dao.pager.PageResult) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) NumberUtils(org.apache.commons.lang.math.NumberUtils) DateUtil(com.dtstack.taier.pluginapi.util.DateUtil) StatusCountPO(com.dtstack.taier.dao.domain.po.StatusCountPO) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade) QueryFillDataListDTO(com.dtstack.taier.scheduler.dto.fill.QueryFillDataListDTO) Timestamp(java.sql.Timestamp) ReturnJobListVO(com.dtstack.taier.develop.vo.schedule.ReturnJobListVO) QueryFillDataJobListDTO(com.dtstack.taier.scheduler.dto.fill.QueryFillDataJobListDTO) ReturnFillDataJobListVO(com.dtstack.taier.develop.vo.fill.ReturnFillDataJobListVO) ScheduleFillDataInfoDTO(com.dtstack.taier.scheduler.dto.fill.ScheduleFillDataInfoDTO) Collectors(java.util.stream.Collectors) ReturnDisplayPeriodVO(com.dtstack.taier.develop.vo.schedule.ReturnDisplayPeriodVO) FillGeneratStatusEnum(com.dtstack.taier.scheduler.enums.FillGeneratStatusEnum) Deleted(com.dtstack.taier.common.enums.Deleted) FillDataJobVO(com.dtstack.taier.develop.vo.fill.FillDataJobVO) java.util(java.util) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) FillDataRunnable(com.dtstack.taier.scheduler.server.action.fill.FillDataRunnable) FillDataThreadPoolExecutor(com.dtstack.taier.scheduler.server.action.fill.FillDataThreadPoolExecutor) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) FillStatusUpdateFinishEvent(com.dtstack.taier.develop.event.FillStatusUpdateFinishEvent) QueryJobListDTO(com.dtstack.taier.scheduler.dto.schedule.QueryJobListDTO) ErrorCode(com.dtstack.taier.common.exception.ErrorCode) ReturnFillDataListVO(com.dtstack.taier.develop.vo.fill.ReturnFillDataListVO) ScheduleFillDataJob(com.dtstack.taier.dao.domain.ScheduleFillDataJob) FillDataTypeEnum(com.dtstack.taier.scheduler.enums.FillDataTypeEnum) ScheduleJobMapper(com.dtstack.taier.dao.mapper.ScheduleJobMapper) User(com.dtstack.taier.dao.domain.User) DateTime(org.joda.time.DateTime) EScheduleType(com.dtstack.taier.common.enums.EScheduleType) Maps(com.google.common.collect.Maps) ApplicationContext(org.springframework.context.ApplicationContext) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) ScheduleFillJobParticipateDTO(com.dtstack.taier.scheduler.dto.fill.ScheduleFillJobParticipateDTO) JSON(com.alibaba.fastjson.JSON) QueryJobStatusStatisticsDTO(com.dtstack.taier.scheduler.dto.schedule.QueryJobStatusStatisticsDTO) JobMapstructTransfer(com.dtstack.taier.develop.mapstruct.job.JobMapstructTransfer) FillJobTypeEnum(com.dtstack.taier.scheduler.enums.FillJobTypeEnum) JobsStatusStatisticsPO(com.dtstack.taier.dao.domain.po.JobsStatusStatisticsPO) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) User(com.dtstack.taier.dao.domain.User) ReturnFillDataJobListVO(com.dtstack.taier.develop.vo.fill.ReturnFillDataJobListVO) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) PageResult(com.dtstack.taier.dao.pager.PageResult) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade) FillDataJobVO(com.dtstack.taier.develop.vo.fill.FillDataJobVO) ScheduleFillDataJob(com.dtstack.taier.dao.domain.ScheduleFillDataJob)

Aggregations

JSON (com.alibaba.fastjson.JSON)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)1 Deleted (com.dtstack.taier.common.enums.Deleted)1 EScheduleType (com.dtstack.taier.common.enums.EScheduleType)1 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)1 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)1 ScheduleFillDataJob (com.dtstack.taier.dao.domain.ScheduleFillDataJob)1 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)1 ScheduleTaskShade (com.dtstack.taier.dao.domain.ScheduleTaskShade)1 User (com.dtstack.taier.dao.domain.User)1 CountFillDataJobStatusPO (com.dtstack.taier.dao.domain.po.CountFillDataJobStatusPO)1 JobsStatusStatisticsPO (com.dtstack.taier.dao.domain.po.JobsStatusStatisticsPO)1 StatusCountPO (com.dtstack.taier.dao.domain.po.StatusCountPO)1 ScheduleJobMapper (com.dtstack.taier.dao.mapper.ScheduleJobMapper)1 PageResult (com.dtstack.taier.dao.pager.PageResult)1 FillStatusUpdateFinishEvent (com.dtstack.taier.develop.event.FillStatusUpdateFinishEvent)1 FillDataJobMapstructTransfer (com.dtstack.taier.develop.mapstruct.fill.FillDataJobMapstructTransfer)1 JobMapstructTransfer (com.dtstack.taier.develop.mapstruct.job.JobMapstructTransfer)1