package com.jiayue.insu.inclientqn.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.insu.common.core.util.R;
import com.jiayue.insu.inclientqn.entity.QuartzBase;
import com.jiayue.insu.inclientqn.service.QuartzBaseService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * QuartzController
 *
 * @author yh
 * @date 2022-03-18 15:48:48
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/quartzBase")
public class QuartzBaseController {

    private final QuartzBaseService quartzBaseService;

    /**
     * 分页查询
     *
     * @param page   分页对象
     * @param quartzBase quartzBase
     * @return
     */

    @GetMapping("/page")
    public R getPage(Page page, QuartzBase quartzBase) {
        LambdaQueryWrapper<QuartzBase> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(quartzBase.getName()!=null){
            lambdaQueryWrapper.like(QuartzBase::getName,quartzBase.getName());
        }

        return R.ok(quartzBaseService.page(page, lambdaQueryWrapper));
    }

    @GetMapping("/all")
    public R getAll() {
        return R.ok(quartzBaseService.list());
    }

    /**
     * 通过执行类
     *
     * @param executeClass executeClass
     * @return R
     */
        @GetMapping("/executeClass/{executeClass}")
    public R getByExecuteClass(@PathVariable("executeClass") String  executeClass) {
        return R.ok(quartzBaseService.findByExecuteClass(executeClass));
    }

    /**
     * 通过标识
     *
     * @param code code
     * @return R
     */
    @GetMapping("/code/{code}")
    public R getByCode(@PathVariable("code") String  code) {
        return R.ok(quartzBaseService.findByCode(code));
    }


    /**
     * 新增quartzBase
     *
     * @param quartzBase quartzBase
     * @return R
     */

    @PostMapping
    public R save(@RequestBody  QuartzBase quartzBase) {
        return R.ok(quartzBaseService.save(quartzBase));
    }

    /**
     * 修改quartzBase
     *
     * @param quartzBase quartzBase
     * @return R
     */

    @PutMapping
    public R updateById(@RequestBody QuartzBase quartzBase) {
        return R.ok(quartzBaseService.updateById(quartzBase));
    }

    /**
     * 通过id删除
     *
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Integer id) {
        return R.ok(quartzBaseService.removeById(id));
    }


}
