package com.tofly.feesapi.bmgl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.feesapi.bmgl.entity.BmCbpl;
import com.tofly.feesapi.bmgl.entity.dto.BmcbplFilter;
import com.tofly.feesapi.bmgl.service.BmCbplService;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;
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("api/bmgl/bmcbpl")
@Api(tags="抄表频率接口")
public class BmCbplController {
    @Autowired
    private BmCbplService bmCbplService;

//    @GetMapping("/page" )
//    @ApiOperation(value = "抄表频率接口")
//    public ResultRespone getBmCbplPage(Page page, @ModelAttribute BmCbpl bmCbpl) {
//      return ResultRespone.success(bmCbplService.page(page, Wrappers.query(bmCbpl)));
//    }

    @ApiOperationSupport(order = 1)
    @GetMapping("/page")
    @ApiOperation(value = "查询抄表频率（分页）", tags = {"抄表频率接口"})
    public ResultRespone<PageResult<BmCbpl>> getPage(@ModelAttribute PageDto pageDto, @ModelAttribute BmcbplFilter filter) {
        return ResultRespone.success(bmCbplService.getPage(pageDto, filter));
    }

    /**
     * 通过id查询抄表频率
     * @param code id
     * @return ResultRespone
     */
    @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(bmCbplService.getById(code));
    }

    /**
     * 新增抄表频率
     * @param bmCbpl 抄表频率
     * @return ResultRespone
     */
    @ApiOperation(value = "新增抄表频率")
    @PostMapping
    public ResultRespone save(@RequestBody BmCbpl bmCbpl) {
         String maxid=bmCbplService.getMaxid();
         bmCbpl.setCode(maxid);
        return ResultRespone.success(bmCbplService.save(bmCbpl));
    }

    /**
     * 修改抄表频率
     * @param bmCbpl 抄表频率
     * @return ResultRespone
     */
    @ApiOperation(value = "修改抄表频率")
    @PutMapping
    public ResultRespone updateById(@RequestBody BmCbpl bmCbpl) {
      return ResultRespone.success(bmCbplService.updateById(bmCbpl));
    }

    /**
     * 通过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(bmCbplService.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(bmCbplService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
