package com.tofly.feesapi.bjgl.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.bjgl.entity.Yhbgl;
import com.tofly.feesapi.bjgl.service.YhbglService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;

@RestController
@AllArgsConstructor
@RequestMapping("api/bjgl/yhbgl")
@Api(tags="水表档案-校表管理接口")
public class YhbglController {

    @Autowired
    private YhbglService yhbglService;

    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getYhbglPage(Page page, @ModelAttribute Yhbgl yhbgl) {
      return ResultRespone.success(yhbglService.page(page, Wrappers.query(yhbgl)));
    }

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

    @ApiOperation(value = "新增校表管理")
    @PostMapping
    public ResultRespone save(@RequestBody Yhbgl yhbgl) {
      return ResultRespone.success(yhbglService.save(yhbgl));
    }

    @ApiOperation(value = "修改校表管理")
    @PutMapping
    public ResultRespone updateById(@RequestBody Yhbgl yhbgl) {
      return ResultRespone.success(yhbglService.updateById(yhbgl));
    }

    @ApiOperation(value = "通过ID删除校表管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lsbh", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{lsbh}" )
    public ResultRespone removeById(@PathVariable String lsbh) {
      return ResultRespone.success(yhbglService.removeById(lsbh));
    }

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

}
