package com.mosty.base.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.manager.service.TbJcglXfNrmbService;
import com.mosty.base.manager.service.TbJcglXfService;
import com.mosty.base.model.entity.jcgl.TbJcglXf;
import com.mosty.base.model.entity.jcgl.TbJcglXfNrmb;
import com.mosty.base.model.query.jcgl.TbJcglXfNrmbQuery;
import com.mosty.base.model.query.jcgl.TbJcglXfQuery;
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("/tbJcglXfNrmb")
public class TbJcglXfNrmbController {

    private final TbJcglXfNrmbService tbJcglXfNrmbService;

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

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

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

    /**
     * 更新数据
     *
     * @param xf 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "巡访内容更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbJcglXfNrmb xf) {
        return ResponseResult.success(tbJcglXfNrmbService.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(tbJcglXfNrmbService.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(tbJcglXfNrmbService.deleteByIds(id));
    }

}