import request from '@/utils/request'

// 查询定时任务列表
export function listJob(query) {
  return request({
    url: '/schedule/job/list',
    method: 'get',
    params: query
  })
}

// 查询定时任务详细
export function getJob(jobId) {
  return request({
    url: '/schedule/job/' + jobId,
    method: 'get'
  })
}

// 新增定时任务
export function addJob(data) {
  return request({
    url: '/schedule/job',
    method: 'post',
    data: data
  })
}

// 修改定时任务
export function updateJob(data) {
  return request({
    url: '/schedule/job',
    method: 'put',
    data: data
  })
}

// 删除定时任务
export function delJob(jobId) {
  return request({
    url: '/schedule/job/' + jobId,
    method: 'delete'
  })
}

// 导出定时任务
export function exportJob(query) {
  return request({
    url: '/schedule/job/export',
    method: 'get',
    params: query
  })
}

// 定时任务立即执行一次
export function runJob(jobId, jobGroup) {
  const data = {
    jobId,
    jobGroup
  }
  return request({
    url: '/schedule/job/run',
    method: 'put',
    data: data
  })
}

// 启动定时任务
export function startJob(jobId, jobGroup) {
  const data = {
    jobId,
    jobGroup
  }
  return request({
    url: '/schedule/job/changeStatus',
    method: 'put',
    data: { ...data, status: '0' }
  })
}

// 停止定时任务
export function stopJob(jobId, jobGroup) {
  const data = {
    jobId,
    jobGroup
  }
  return request({
    url: '/schedule/job/changeStatus',
    method: 'put',
    data: { ...data, status: '1' }
  })
}