package com.mosty.qwzx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.entity.qwzx.TbQwFa;
import com.mosty.base.model.query.qwzx.TbQwFaQuery;
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.qwzx.service.TbQwFaService;
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 = "巡防方案")
@RestController
@AllArgsConstructor
@RequestMapping("/tbqwfa")
public class TbQwFaController {

    private final TbQwFaService tbQwFaService;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @ApiOperation("通过ID查询单条数据")
    @JwtSysUser
    @GetMapping("{id}")
    @Log(title = "巡防方案单条数据", businessType = BusinessType.OTHER)
    @ApiImplicitParam(name = "id", value = "方案ID", paramType = "path", required = true, dataType = "String")
    public ResponseResult<TbQwFa> queryById(@PathVariable String id) {
        return ResponseResult.success(tbQwFaService.queryById(id));
    }

    /**
     * 分页查询
     *
     * @param query 筛选条件
     * @return 查询结果
     */
    @ApiOperation("巡防方案分页查询")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbQwFa>> paginQuery(TbQwFaQuery query) {
        IPage<TbQwFa> page = tbQwFaService.paginQuery(query);
        return ResponseResult.success(page);
    }

    /**
     * 新增数据
     *
     * @param xf 实例对象
     * @return 实例对象
     */
    @ApiOperation("巡防方案新增")
    @JwtSysUser
    @PostMapping
    @Log(title = "巡防方案新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbQwFa xf) {
        return ResponseResult.success(tbQwFaService.insert(xf));
    }

    /**
     * 更新数据
     *
     * @param xf 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新巡防方案")
    @JwtSysUser
    @PutMapping
    @Log(title = "巡防方案更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbQwFa xf) {
        return ResponseResult.success(tbQwFaService.update(xf));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @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(tbQwFaService.deleteById(id));
    }

    /**
     * 批量删除
     *
     * @param id 主键
     * @return 是否成功
     */
    @ApiOperation("批量删除")
    @PostMapping("/bacth")
    @Log(title = "巡防方案删除", businessType = BusinessType.UPDATE)
    @ApiImplicitParam(name = "id", value = "标签主键", paramType = "path", required = true, dataType = "String")
    public ResponseResult<Boolean> deleteByIds(@RequestBody List<String> id) {
        return ResponseResult.success(tbQwFaService.deleteByIds(id));
    }
}