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.BmSearch;
import com.tofly.feesapi.bmgl.service.BmSearchService;
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/bmsearch")
@Api(tags="编码-条件检索编码接口")
public class BmSearchController {

    @Autowired
    private  BmSearchService bmSearchService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param bmSearch 条件检索编码
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getBmSearchPage(Page page, @ModelAttribute BmSearch bmSearch) {
      return ResultRespone.success(bmSearchService.page(page, Wrappers.query(bmSearch)));
    }


    /**
     * 通过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(bmSearchService.getById(code));
    }

    /**
     * 新增条件检索编码
     * @param bmSearch 条件检索编码
     * @return ResultRespone
     */
    @ApiOperation(value = "新增条件检索编码")
    @PostMapping
    public ResultRespone save(@RequestBody BmSearch bmSearch) {
      return ResultRespone.success(bmSearchService.save(bmSearch));
    }

    /**
     * 修改条件检索编码
     * @param bmSearch 条件检索编码
     * @return ResultRespone
     */
    @ApiOperation(value = "修改条件检索编码")
    @PutMapping
    public ResultRespone updateById(@RequestBody BmSearch bmSearch) {
      return ResultRespone.success(bmSearchService.updateById(bmSearch));
    }

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