package com.mosty.base.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.manager.service.TbJcglXfCyryService;
import com.mosty.base.model.entity.jcgl.TbJcglXfCyry;
import com.mosty.base.model.query.jcgl.TbJcglXfCyryQuery;
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("/tbJcglXfCyry")
public class TbJcglXfCyryController {

    private final TbJcglXfCyryService tbJcglXfCyryService;

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

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

    /**
     * 新增数据
     *
     * @param xf 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "从业人员新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbJcglXfCyry xf) {
        return ResponseResult.success(tbJcglXfCyryService.insert(xf));
    }

    /**
     * 更新数据
     *
     * @param xf 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "从业人员更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbJcglXfCyry xf) {
        return ResponseResult.success(tbJcglXfCyryService.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(tbJcglXfCyryService.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(tbJcglXfCyryService.deleteByIds(id));
    }

}