package com.jiayue.ipp.idp.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.Quartz;
import com.jiayue.ipp.idp.service.QuartzService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * idp_quartz
 *
 * @author whc
 * @date 2022-03-18 15:49:31
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/quartz")
@Api(value = "quartz", tags = "idp_quartz管理")
public class QuartzController {

    private final QuartzService quartzService;

    /**
     * 分页查询
     *
     * @param page   分页对象
     * @param quartz idp_quartz
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    //@PreAuthorize("@pms.hasPermission('idp_quartz_get')")
    public R getQuartzPage(Page page, Quartz quartz) {
        return R.ok(quartzService.page(page, Wrappers.query(quartz)));
    }

    /**
     * 通过id查询idp_quartz
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_quartz_get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(quartzService.getById(id));
    }

    /**
     * 新增idp_quartz
     *
     * @param quartz idp_quartz
     * @return R
     */
    @ApiOperation(value = "新增idp_quartz", notes = "新增idp_quartz")
    //    @SysLog("新增idp_quartz")
    @PostMapping
    //@PreAuthorize("@pms.hasPermission('idp_quartz_add')")
    public R save(@RequestBody Quartz quartz) {
        return R.ok(quartzService.save(quartz));
    }

    /**
     * 修改idp_quartz
     *
     * @param quartz idp_quartz
     * @return R
     */
    @ApiOperation(value = "修改idp_quartz", notes = "修改idp_quartz")
    //    @SysLog("修改idp_quartz")
    @PutMapping
    //@PreAuthorize("@pms.hasPermission('idp_quartz_edit')")
    public R updateById(@RequestBody Quartz quartz) {
        return R.ok(quartzService.updateById(quartz));
    }

    /**
     * 通过id删除idp_quartz
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除idp_quartz", notes = "通过id删除idp_quartz")
    //    @SysLog("通过id删除idp_quartz")
    @DeleteMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_quartz_del')")
    public R removeById(@PathVariable String id) {
        return R.ok(quartzService.removeById(id));
    }

}
