package com.tofly.feesapi.bmgl.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.bmgl.entity.BmCblx;
import com.tofly.feesapi.bmgl.service.BmCblxService;
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
@RequestMapping("/bmcblx")
@Api(tags="编码_水表运行状态接口")
public class BmCblxController {

    @Autowired
    private BmCblxService bmCblxService;

    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getBmCblxPage(Page page, @ModelAttribute BmCblx bmCblx) {
      return ResultRespone.success(bmCblxService.page(page, Wrappers.query(bmCblx)));
    }

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

    /**
     * 新增编码_水表运行状态
     * @param bmCblx 编码_水表运行状态
     * @return ResultRespone
     */
    @ApiOperation(value = "新增编码_水表运行状态")
    @PostMapping
    public ResultRespone save(@RequestBody BmCblx bmCblx) {
      return ResultRespone.success(bmCblxService.save(bmCblx));
    }

    /**
     * 修改编码_水表运行状态
     * @param bmCblx 编码_水表运行状态
     * @return ResultRespone
     */
    @ApiOperation(value = "修改编码_水表运行状态")
    @PutMapping
    public ResultRespone updateById(@RequestBody BmCblx bmCblx) {
      return ResultRespone.success(bmCblxService.updateById(bmCblx));
    }

    /**
     * 通过id删除编码_水表运行状态
     * @param code id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过ID删除编码_水表运行状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{code}" )
    public ResultRespone removeById(@PathVariable String code) {
      return ResultRespone.success(bmCblxService.removeById(code));
    }

    /**
     * 通过id批量删除编码_水表运行状态
     * @param ids id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过ID批量删除编码_水表运行状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeByIds(String ids) {
        return ResultRespone.success(bmCblxService.removeByIds(Arrays.asList(ids.split(","))));
    }

    @GetMapping("/getAll" )
    @ApiOperation(value = "查询所有类型")
    public ResultRespone getBmCblxAll() {
        return ResultRespone.success(bmCblxService.GetAll());
    }

}
