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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.feesapi.common.core.ResultRespone;

import com.tofly.feesapi.wxgl.wechatbasicmgt.entity.WxFwtz;
import com.tofly.feesapi.wxgl.wechatbasicmgt.mapper.WxFwtzMapper;
import com.tofly.feesapi.wxgl.wechatbasicmgt.service.WxFwtzService;
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/wxfwnotice")
@Api(tags = "微信管理-微信推送服务通知接口")
public class WxFwtzController {

    @Autowired
    private WxFwtzService wxFwtzService;
    @Autowired
    private WxFwtzMapper wxFwTzMapper;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页码", required = true, dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页显示数据条数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pages", value = "共几页,输出参数", dataType = "int"),
            @ApiImplicitParam(name = "maxLimit", value = "每页最大显示数据", dataType = "int"),
            @ApiImplicitParam(name = "orders[0].asc", value = "排序,bool类型", dataType = "String"),
            @ApiImplicitParam(name = "orders[0].column", value = "排序,字段名", dataType = "String"),
            @ApiImplicitParam(name = "state", value = "是否发送，0,1", dataType = "String"),
            @ApiImplicitParam(name = "editDateStart", value = "开始日期", dataType = "String"),
            @ApiImplicitParam(name = "editDateEnd", value = "结束日期", dataType = "String"),
            @ApiImplicitParam(name = "searchText", value = "模糊查询(编辑人员、标题、停水区域)", dataType = "String")
    })
    public ResultRespone getWxFwNoticePage(Page page, String searchText, String state, String editDateStart, String editDateEnd) {
        IPage<WxFwtz> WxTsPage = wxFwTzMapper.selectWxFwNoticePage(page, searchText, state, editDateStart, editDateEnd);
        return ResultRespone.success(WxTsPage);
    }

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

    @ApiOperation(value = "新增微信推送服务通知")
    @PostMapping
    public ResultRespone save(@RequestBody WxFwtz wxFwTz) {
        int id = wxFwTzMapper.SelectChargeMaxCode();
        wxFwTz.setId(id + 1);
        wxFwTz.setState("0");//发送状态
        wxFwTz.setAuditFlag("0");//审核标志
        return ResultRespone.success(wxFwtzService.save(wxFwTz));
    }

    @PutMapping
    @ApiOperation(value = "修改微信推送服务通知")
    public ResultRespone updateById(@RequestBody WxFwtz wxFwTz) {
        return ResultRespone.success(wxFwtzService.updateById(wxFwTz));
    }

    @ApiOperation(value = "通过ID删除微信推送服务通知")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "BigDecimal")
    })
    @DeleteMapping("/{id}")
    public ResultRespone removeById(@PathVariable Integer id) {
        return ResultRespone.success(wxFwtzService.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(wxFwtzService.removeByIds(Arrays.asList(ids.split(","))));
    }

}
