package cn.lihongjie.coal.cronJob.controller;

import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.cronJob.dto.CreateCronJobDto;
import cn.lihongjie.coal.cronJob.dto.CronJobDto;
import cn.lihongjie.coal.cronJob.dto.RunOnceRequest;
import cn.lihongjie.coal.cronJob.dto.UpdateCronJobDto;
import cn.lihongjie.coal.cronJob.service.CronJobService;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/cronJob")
@SysLog(
    module = "定时任务"
)
@Slf4j
public class CronJobController {
  @Autowired
  private CronJobService service;

  @PostMapping("/create")
  public CronJobDto create(@RequestBody CreateCronJobDto request) {
    return this.service.create(request)
        ;
  }

  @PostMapping("/update")
  public CronJobDto update(@RequestBody UpdateCronJobDto request) {
    return this.service.update(request)
        ;
  }

  @PostMapping("/delete")
  public Object delete(@RequestBody IdRequest request) {
    this.service.delete(request);
        return true
        ;
  }

  @PostMapping("/runOnce")
  public Object runOnce(@RequestBody RunOnceRequest request) {
    this.service.runOnce(request);
    return true
            ;
  }


  @PostMapping("/switchStatus")
  public Object switchStatus(@RequestBody IdRequest request) {
    this.service.switchStatus(request);
    return true
            ;
  }
  @PostMapping("/getById")
  public CronJobDto getById(@RequestBody IdRequest request) {
    return this.service.getById(request.getId())
        ;
  }

  @PostMapping("/list")
  public Page<CronJobDto> list(@RequestBody CommonQuery request) {
    return this.service.list(request)
        ;
  }
  
  
}
