package com.tofly.feesapi.wxgl.wechatbasicmgt.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.feesapi.common.core.ResultRespone;

import com.tofly.feesapi.wxgl.wechatbasicmgt.entity.WxYwxz;
import com.tofly.feesapi.wxgl.wechatbasicmgt.entity.WxYwxzbm;
import com.tofly.feesapi.wxgl.wechatbasicmgt.service.WxYwxzbmService;
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.math.BigDecimal;
import java.util.Arrays;

/**
 * 业务须知编码
 */
@RestController
@RequestMapping("/api/wechatbasicmgt/wxbusinesscode")
@Api(tags = "微信管理—业务须知编码接口")
public class WxYwxzbmController {

    @Autowired
    private WxYwxzbmService wxYwxzbmService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getWxBusinessCodePage(Page page, @ModelAttribute WxYwxzbm wxYwxzbm) {

        QueryWrapper<WxYwxzbm> queryWrapper = new QueryWrapper<WxYwxzbm>();
        queryWrapper.eq("isdisabled", "1");

        Page<WxYwxz> wxPage = wxYwxzbmService.page(page, queryWrapper);
        return ResultRespone.success(wxPage);
    }



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

    @ApiOperation(value = "新增业务须知编码")
    @PostMapping
    public ResultRespone save(@RequestBody WxYwxzbm wxYwxzbm) {
        return ResultRespone.success(wxYwxzbmService.save(wxYwxzbm));
    }


    @ApiOperation(value = "修改业务须知编码")
    @PutMapping
    public ResultRespone updateById(@RequestBody WxYwxzbm wxYwxzbm) {
        return ResultRespone.success(wxYwxzbmService.updateById(wxYwxzbm));
    }


    @ApiOperation(value = "通过ID删除业务须知编码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "BigDecimal")
    })
    @DeleteMapping("/{id}")
    public ResultRespone removeById(@PathVariable BigDecimal id) {
        return ResultRespone.success(wxYwxzbmService.removeById(id));
    }


    @ApiOperation(value = "通过ID批量删除业务须知编码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeByIds(String ids) {
        return ResultRespone.success(wxYwxzbmService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
