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.TbQwBxfsqEditDto;
import com.mosty.base.model.entity.qwzx.TbQwXfBxfsq;
import com.mosty.base.model.query.qwzx.TbQwXfBxfsqQuery;
import com.mosty.qwzx.service.TbQwXfBxfsqService;
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;

@Api(tags = "不巡防申请接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbQwXfBxfsq")
public class TbQwXfBxfsqController {

    private TbQwXfBxfsqService tbQwXfBxfsqService;

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

    @ApiOperation("分页查询")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbQwXfBxfsq>> paginQuery(TbQwXfBxfsqQuery dto){
        IPage<TbQwXfBxfsq> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        return ResponseResult.success(tbQwXfBxfsqService.getBxfsq(dto, page));
    }

    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "不巡防申请新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbQwXfBxfsq bxfsq){
        return ResponseResult.success(tbQwXfBxfsqService.addBxfsq(bxfsq));
    }


    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "不巡防申请更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbQwXfBxfsq dto){
        return ResponseResult.success(tbQwXfBxfsqService.editBxfsq(dto));
    }


    @ApiOperation("审批不巡防申请")
    @JwtSysUser
    @PutMapping("judge")
    @Log(title = "审批不巡防申请", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> judge(@RequestBody TbQwBxfsqEditDto dto){
        return ResponseResult.success(tbQwXfBxfsqService.judge(dto));
    }

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

}

