package com.mosty.base.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.manager.service.TbJcglXfDwglService;
import com.mosty.base.model.entity.jcgl.TbJcglXfDwgl;
import com.mosty.base.model.query.jcgl.TbJcglXfDwglQuery;
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 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("/tbJcglXfDwgl")
public class TbJcglXfDwglController {

    private final TbJcglXfDwglService tbJcglXfDwglService;

    /**
     * 通过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<TbJcglXfDwgl> queryById(@PathVariable String id) {
        return ResponseResult.success(tbJcglXfDwglService.queryById(id));
    }

    /**
     * 分页查询
     *
     * @param query 筛选条件
     * @return 查询结果
     */
    @ApiOperation("分页查询")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbJcglXfDwgl>> paginQuery(TbJcglXfDwglQuery query) {
        IPage<TbJcglXfDwgl> page = tbJcglXfDwglService.paginQuery(query);
        return ResponseResult.success(page);
    }

    /**
     * 新增数据
     *
     * @param xf 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "单位管理新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbJcglXfDwgl xf) {
        return ResponseResult.success(tbJcglXfDwglService.insert(xf));
    }

    /**
     * 更新数据
     *
     * @param xf 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "单位管理更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbJcglXfDwgl xf) {
        return ResponseResult.success(tbJcglXfDwglService.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(tbJcglXfDwglService.deleteById(id));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @ApiOperation("通过主键删除数据")
    @PostMapping("/bacth")
    @Log(title = "单位管理删除", businessType = BusinessType.DELETE)
    @ApiImplicitParam(name = "id", value = "标签主键", paramType = "path", required = true, dataType = "String")
    public ResponseResult<Boolean> deleteByIds(@RequestBody List<String> id) {
        return ResponseResult.success(tbJcglXfDwglService.deleteByIds(id));
    }

}