Search in sources :

Example 1 with ReturnDisplayPeriodVO

use of com.dtstack.taier.develop.vo.schedule.ReturnDisplayPeriodVO in project Taier by DTStack.

the class JobService method displayPeriods.

/**
 * 查询上一个周期或者下一个周期实例
 *
 * @param isAfter 是否是上个周期
 * @param jobId 实例id
 * @param limit 查询个数
 */
public List<ReturnDisplayPeriodVO> displayPeriods(Boolean isAfter, String jobId, Integer limit) {
    ScheduleJob scheduleJob = this.lambdaQuery().eq(ScheduleJob::getJobId, jobId).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).one();
    if (scheduleJob == null) {
        throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_JOB);
    }
    // 需要根据查询的job的类型来
    List<ScheduleJob> scheduleJobList = this.baseMapper.listAfterOrBeforeJobs(scheduleJob.getTaskId(), isAfter, scheduleJob.getCycTime(), scheduleJob.getType());
    scheduleJobList.sort((o1, o2) -> {
        if (!NumberUtils.isNumber(o1.getCycTime())) {
            return 1;
        }
        if (!NumberUtils.isNumber(o2.getCycTime())) {
            return -1;
        }
        return Long.compare(Long.parseLong(o2.getCycTime()), Long.parseLong(o1.getCycTime()));
    });
    if (scheduleJobList.size() > limit) {
        scheduleJobList = scheduleJobList.subList(0, limit);
    }
    List<ReturnDisplayPeriodVO> vos = new ArrayList<>(scheduleJobList.size());
    scheduleJobList.forEach(nextScheduleJob -> {
        ReturnDisplayPeriodVO vo = new ReturnDisplayPeriodVO();
        vo.setJobId(nextScheduleJob.getJobId());
        vo.setCycTime(DateUtil.addTimeSplit(nextScheduleJob.getCycTime()));
        vo.setStatus(nextScheduleJob.getStatus());
        vos.add(vo);
    });
    return vos;
}
Also used : ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ReturnDisplayPeriodVO(com.dtstack.taier.develop.vo.schedule.ReturnDisplayPeriodVO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)1 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)1 ReturnDisplayPeriodVO (com.dtstack.taier.develop.vo.schedule.ReturnDisplayPeriodVO)1