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

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

import com.tofly.feesapi.wxgl.wechatbasicmgt.entity.WxUserLs;
import com.tofly.feesapi.wxgl.wechatbasicmgt.mapper.WxUserLsMapper;
import com.tofly.feesapi.wxgl.wechatbasicmgt.service.WxUserLsService;
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/wxcustomerhis")
@Api(tags = "微信管理-微信解绑记录接口")
public class WxUserLsController {

    @Autowired
    private WxUserLsService wxUserLsService;


    @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 = "bindFlag", value = "是否绑定，0,1", dataType = "String"),
            @ApiImplicitParam(name = "searchText", value = "模糊查询(用户编号、用户姓名、用户地址)", required = false, dataType = "String")
    })
    public ResultRespone getWxCustomerHisPage(Page page, String searchText, String bindFlag) {
        QueryWrapper<WxUserLs> queryWrapper = new QueryWrapper<WxUserLs>();
        queryWrapper.eq("1", "1");
        if (StringUtils.isNotBlank(searchText)) {
            queryWrapper.and(i -> i.like("yhbh", searchText).or().like("name", searchText).or().like("address", searchText));
        }
        //if (StringUtils.isNotBlank(bindFlag) && bindFlag != "all") {
            queryWrapper.in("wxbdbz", "0");
       // }
        return ResultRespone.success(wxUserLsService.page(page, queryWrapper));
    }


    @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(wxUserLsService.getById(id));
    }


    @ApiOperation(value = "新增微信解绑记录")
    @PostMapping
    public ResultRespone save(@RequestBody WxUserLs wxUserLs) {
        return ResultRespone.success(wxUserLsService.save(wxUserLs));
    }


    @ApiOperation(value = "修改微信解绑记录")
    @PutMapping
    public ResultRespone updateById(@RequestBody WxUserLs wxUserLs) {
        return ResultRespone.success(wxUserLsService.updateById(wxUserLs));
    }


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