package com.mosty.base.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.manager.service.TbJcglBqService;
import com.mosty.base.manager.service.TbJcglXfService;
import com.mosty.base.model.dto.jcgl.TbJcglBqDto;
import com.mosty.base.model.entity.jcgl.TbJcglXf;
import com.mosty.base.model.query.jcgl.TbJcglBqQuery;
import com.mosty.base.model.query.jcgl.TbJcglXfQuery;
import com.mosty.base.model.vo.jcgl.TbJcglBqVo;
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;
import java.util.Map;

/**
 * 巡防接口
 */
@Api(tags = "巡访接口")
@RestController
@AllArgsConstructor
@RequestMapping("/tbJcglXf")
public class TbJcglXfController {

    private final TbJcglXfService tbJcglXfService;

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

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

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

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

    /**
     * 巡访部门统计
     *
     * @param query
     */
    @ApiOperation("巡访部门统计")
    @PostMapping("/xfbmtj")
    @Log(title = "巡访部门统计", businessType = BusinessType.OTHER)
    public ResponseResult<List<Map<String,Object>>> xfbmtj(@RequestBody TbJcglXfQuery query) {
        return ResponseResult.success(tbJcglXfService.xfbmtj(query));
    }

    @ApiOperation("批量申报")
    @PostMapping("/bacthSb")
    @Log(title = "批量申报", businessType = BusinessType.UPDATE)
    @ApiImplicitParam(name = "id", value = "标签主键", paramType = "path", required = true, dataType = "String")
    public ResponseResult<Integer> bacthSb(@RequestBody List<String> id) {
        return ResponseResult.success(tbJcglXfService.bacthSb(id));
    }

}