package com.xunmei.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunmei.common.core.web.domain.AjaxResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;
import com.xunmei.system.service.IJobService;
import com.xunmei.system.domain.Job;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.xunmei.common.core.web.domain.AjaxResult.success;
import static com.xunmei.common.core.web.domain.AjaxResult.error;
import javax.annotation.Resource;
import com.xunmei.common.security.annotation.RequiresPermissions;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * JobController 前端控制器
 * </p>
 *
 * @author luojun
 * @since 2023-08-04
 */
@Api(tags = {"JobController"})
@RestController
@RequestMapping("/job")
public class JobController {

    private Logger log = LoggerFactory.getLogger(getClass());
    @Resource
    private IJobService jobService;


    @ApiOperation(value = "新增定时任务调度表")
    @RequiresPermissions("system:job:add")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Job job){
        try {
            return jobService.add(job);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "删除定时任务调度表")
    @RequiresPermissions("system:job:delete")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            return jobService.delete(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "更新定时任务调度表")
    @RequiresPermissions("system:job:update")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody Job job){
        try {
            return jobService.updateData(job);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "查询定时任务调度表分页数据")
    @RequiresPermissions("system:job:findByPage")
    @GetMapping("/findByPage")
    public AjaxResult findListByPage(Page<Job> page,Job job){
        try {
            return jobService.findListByPage(page, job);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "id查询定时任务调度表")
    @RequiresPermissions("system:job:findById")
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Long id){
        try {
            return jobService.findById(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

}
