
package com.pavis.admin.schedule.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.pavis.admin.schedule.api.JobBatchApi;
import com.pavis.admin.schedule.api.JobClient;
import com.pavis.admin.schedule.model.JobInstanceLogPageResult;
import com.pavis.admin.schedule.model.query.JobInstanceLogQuery;
import com.pavis.admin.schedule.model.query.JobInstanceQuery;
import com.pavis.admin.schedule.model.query.JobLogQuery;
import com.pavis.admin.schedule.model.resp.JobInstanceResp;
import com.pavis.admin.schedule.model.resp.JobLogResp;
import com.pavis.admin.schedule.service.JobLogService;
import top.continew.starter.extension.crud.model.resp.PageResp;

import java.util.List;

/**
 * 任务日志业务实现
 *
 * 
 * 
 * @since 2024/6/27 22:54
 */
@Service
@RequiredArgsConstructor
public class JobLogServiceImpl implements JobLogService {

    private final JobClient jobClient;
    private final JobBatchApi jobBatchApi;

    @Override
    public PageResp<JobLogResp> page(JobLogQuery query) {
        return jobClient.requestPage(() -> jobBatchApi.page(query));
    }

    @Override
    public boolean stop(Long id) {
        return Boolean.TRUE.equals(jobClient.request(() -> jobBatchApi.stop(id)));
    }

    @Override
    public boolean retry(Long id) {
        return Boolean.TRUE.equals(jobClient.request(() -> jobBatchApi.retry(id)));
    }

    @Override
    public List<JobInstanceResp> listInstance(JobInstanceQuery query) {
        return jobClient.requestPage(() -> jobBatchApi.pageTask(query)).getList();
    }

    @Override
    public JobInstanceLogPageResult pageInstanceLog(JobInstanceLogQuery query) {
        return jobClient.request(() -> jobBatchApi.pageLog(query));
    }
}
