package com.mosty.qwzx.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.TbQwQwdjDto;
import com.mosty.base.model.dto.qwzx.TbQwQwdjEditDto;
import com.mosty.base.model.entity.qwzx.TbQwQwdj;
import com.mosty.base.model.query.qwzx.TbQwQwdjQuery;
import com.mosty.qwzx.service.TbQwQwdjService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 勤务等级表 前端控制器
 * </p>
 *
 * @author zengbo
 * @since 2022-06-27
 */
@Api(tags = "勤务等级接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbQwQwdj")
public class TbQwQwdjController {

    private TbQwQwdjService tbQwQwdjService;


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

    @ApiOperation("分页查询")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbQwQwdj>> paginQuery(TbQwQwdjQuery dto) {
        IPage<TbQwQwdj> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        return ResponseResult.success(tbQwQwdjService.getQwdj(dto, page));
    }

    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "勤务等级新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbQwQwdj qwdj) {
        return ResponseResult.success(tbQwQwdjService.addQwdj(qwdj));
    }

    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "勤务等级更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbQwQwdjEditDto qwdj) {
        return ResponseResult.success(tbQwQwdjService.editQwdj(qwdj));
    }

    @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(tbQwQwdjService.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(tbQwQwdjService.deleteBatch(id));
    }

    @ApiOperation("发布勤务等级")
    @PostMapping("/publish")
    @Log(title = "发布勤务等级", businessType = BusinessType.UPDATE)
    public ResponseResult<Boolean> publishQwdj(@RequestBody TbQwQwdjDto dto) {
        return ResponseResult.success(tbQwQwdjService.publishQwdj(dto.getId()));
    }

    @ApiOperation("查询当前勤务等级")
    @JwtSysUser
    @GetMapping("/currentQwdj")
    @Log(title = "查询当前勤务等级", businessType = BusinessType.OTHER)
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "dateTime", value = "dateTime", dataType = "String", required = true)})
    public ResponseResult<TbQwQwdj> currentQwdj(String dateTime) {
        return ResponseResult.success(tbQwQwdjService.queryCurrentQwdj(dateTime));
    }
}

