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.ISysJobService;
import com.xunmei.system.domain.SysJob;
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>
 * SysJobController 前端控制器
 * </p>
 *
 * @author luojun
 * @since 2023-08-04
 */
@Api(tags = {"SysJobController"})
@RestController
@RequestMapping("/sysJob")
public class SysJobController {

    private Logger log = LoggerFactory.getLogger(getClass());
    @Resource
    private ISysJobService sysJobService;


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

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

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

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

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

}
