package com.tofly.feesapi.cbgl.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.feesapi.common.core.ResultRespone;

import com.tofly.feesapi.cbgl.entity.YyCblrLs;
import com.tofly.feesapi.cbgl.service.YyCblrLsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("api/cbgl/yycblrls")
@Api(tags="抄表录入历史记录")
public class YyCblrLsController {

    @Autowired
    private YyCblrLsService yyCblrLsService;

    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getYyCblrLsPage(Page page, @ModelAttribute YyCblrLs yyCblrLs) {
      return ResultRespone.success(yyCblrLsService.page(page, Wrappers.query(yyCblrLs)));
    }


    @GetMapping("/{shryxm}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shryxm", value = "ID", required = true, dataType = "String")
    })
    public ResultRespone getById(@PathVariable("shryxm" ) String shryxm) {
      return ResultRespone.success(yyCblrLsService.getById(shryxm));
    }

    @ApiOperation(value = "新增")
    @PostMapping
    public ResultRespone save(@RequestBody YyCblrLs yyCblrLs) {
      return ResultRespone.success(yyCblrLsService.save(yyCblrLs));
    }

    @ApiOperation(value = "修改")
    @PutMapping
    public ResultRespone updateById(@RequestBody YyCblrLs yyCblrLs) {
      return ResultRespone.success(yyCblrLsService.updateById(yyCblrLs));
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shryxm", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{shryxm}" )
    public ResultRespone removeById(@PathVariable String shryxm) {
      return ResultRespone.success(yyCblrLsService.removeById(shryxm));
    }

    @ApiOperation(value = "批量删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeByIds(String ids) {
        return ResultRespone.success(yyCblrLsService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
