package com.mosty.qwzx.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mosty.base.model.query.qwzx.TbQwQxjMyQuery;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.token.JwtSysUser;
import com.mosty.base.model.dto.qwzx.TbQwQxjEditDto;
import com.mosty.base.model.entity.qwzx.TbQwQxj;
import com.mosty.base.model.query.qwzx.TbQwQxjQuery;
import com.mosty.qwzx.service.TbQwQxjService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zengbo
 * @since 2022-06-27
 */
@Api(tags = "请休假接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbQwQxj")
public class TbQwQxjController {

    private TbQwQxjService tbQwQxjService;


    @ApiOperation("通过ID查询单条数据")
    @JwtSysUser
    @GetMapping("{id}")
    @Log(title = "请休假单条数据", businessType = BusinessType.OTHER)
    @ApiImplicitParam(name = "id", value = "报备ID", paramType = "path", required = true, dataType="String")
    public ResponseResult<TbQwQxj> queryById(@PathVariable String id){
        return ResponseResult.success(tbQwQxjService.selectById(id));
    }

    @ApiOperation("分页查询")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbQwQxj>> paginQuery(TbQwQxjQuery tbQwQxjQuery){
        IPage<TbQwQxj> page = new Page<>(tbQwQxjQuery.getPageCurrent(), tbQwQxjQuery.getPageSize());
        return ResponseResult.success(tbQwQxjService.getQxj(tbQwQxjQuery, page));
    }

    @ApiOperation("APP查询我的请休假记录")
    @JwtSysUser
    @GetMapping("getMyQxjList")
    public ResponseResult<IPage<TbQwQxj>> getMyQxjList(TbQwQxjMyQuery dto){
        return ResponseResult.success(tbQwQxjService.getMyQxjList(dto));
    }

    @ApiOperation("请休假新增")
    @JwtSysUser
    @PostMapping
    @Log(title = "请休假新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbQwQxj qxj){
        return ResponseResult.success(tbQwQxjService.addQxj(qxj));
    }

    @ApiOperation("请休假更新")
    @JwtSysUser
    @PutMapping
    @Log(title = "请休假更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbQwQxjEditDto qxj){
        return ResponseResult.success(tbQwQxjService.editQxj(qxj));
    }

    @ApiOperation("通过主键删除数据")
    @DeleteMapping("{id}")
    @Log(title = "请休假删除", businessType = BusinessType.UPDATE)
    @ApiImplicitParam(name = "id", value = "标签主键", paramType = "path", required = true, dataType="String")
    public ResponseResult<Boolean> deleteById(@PathVariable("id") String id){
        return ResponseResult.success(tbQwQxjService.deleteById(id));
    }

    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/bacth")
    @Log(title = "请休假删除", businessType = BusinessType.UPDATE)
    @ApiImplicitParam(name = "id", value = "标签主键", paramType = "path", required = true, dataType="String")
    public ResponseResult<Boolean> deleteByIds(@RequestParam List<String> id){
        return ResponseResult.success(tbQwQxjService.deleteBatch(id));
    }
}

