package com.tofly.feesapi.wxgl.wechatbasicmgt.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.wxgl.wechatbasicmgt.entity.WxDtbm;
import com.tofly.feesapi.wxgl.wechatbasicmgt.service.WxDtbmService;
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/wechatbasicmgt/wxdtbm")
@Api(tags = "微信管理-动态编码接口")
public class WxDtbmController {

    @Autowired
    private WxDtbmService wxDtbmService;

    /**
     * 分页查询
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getWxDtbmPage(Page page, @ModelAttribute WxDtbm wxDtbm) {
        return ResultRespone.success(wxDtbmService.page(page, Wrappers.query(wxDtbm)));
    }


    /**
     * 通过id查询动态编码
     *
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    public ResultRespone getById(@PathVariable("id") String id) {
        return ResultRespone.success(wxDtbmService.getById(id));
    }

    /**
     * 新增动态编码
     *
     * @param wxDtbm 动态编码
     * @return ResultRespone
     */
    @ApiOperation(value = "新增动态编码")
    @PostMapping
    public ResultRespone save(@RequestBody WxDtbm wxDtbm) {
        return ResultRespone.success(wxDtbmService.save(wxDtbm));
    }

    /**
     * 修改动态编码
     *
     * @param wxDtbm 动态编码
     * @return ResultRespone
     */
    @ApiOperation(value = "修改动态编码")
    @PutMapping
    public ResultRespone updateById(@RequestBody WxDtbm wxDtbm) {
        return ResultRespone.success(wxDtbmService.updateById(wxDtbm));
    }

    /**
     * 通过id删除动态编码
     *
     * @param id id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过ID删除动态编码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{id}")
    public ResultRespone removeById(@PathVariable String id) {
        return ResultRespone.success(wxDtbmService.removeById(id));
    }

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