package com.iformall.controller.mem;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.ErrorCode;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import com.iformall.domain.dto.WxCUserBasicInfoFilterDto;
import com.iformall.domain.po.*;
import com.iformall.domain.po.base.BaseEntity;
import com.iformall.domain.vo.UserTradeRecordVo;
import com.iformall.enums.EnumAssignTagsTrigger;
import com.iformall.enums.EnumCouponOrderStatus;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxMerchantMapper;
import com.iformall.service.*;
import com.iformall.utils.Constant;
import com.iformall.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@RestController
@RequestMapping("wxCUserBasicInfo")
@Api(description = "会员管理相关接口")
public class WxCUserBasicInfoController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private String fmUploadDir;

    @Autowired
    private WxCUserBasicInfoService wxCUserBasicInfoService;

    @Autowired
    private WxCUserTagsService wxCUserTagsService;

    @Autowired
    private WxCUserCarService wxCUserCarService;

    @Autowired
    private WxCouponOrderService wxCouponOrderService;

    @Autowired
    private WxCouponService wxCouponService;

    @Autowired
    private WxLevelConfigService wxLevelConfigService;

    @Autowired
    WxCarPayRecordService wxCarPayRecordService;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Autowired
    private AsyncTask asyncTask;

    @Autowired
    private ExcelService excelService;

    @Autowired
    private WxMerchantMapper wxMerchantMapper;

    private void setUserInfoLevel(WxCUserBasicInfo info) {

        if (info.getPoins() == null || info.getPoins() == 0) {
            info.setLevel(WxLevelConfigService.DEFAULT_LEVEL);
        } else {
            info.setLevel(WxLevelConfigService.DEFAULT_LEVEL);
            List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(info.getTenantId());
            for (WxLevelConfig levelConfig : levelList) {
                if (info.getPoins() >= levelConfig.getPoints()) {
                    info.setLevel(levelConfig.getLevel());
                }
            }
        }
    }

    private void setUserInfoTag(WxCUserBasicInfo info) {

        if (info.getTagId() != null) {
            WxCUserTags uTag = wxCUserTagsService.getById(info.getTagId());
            if (uTag != null && StringUtils.isNotBlank(uTag.getTags())) {
                List<Long> ids = JSONObject.parseArray(uTag.getTags(), Long.class);
                info.setTagsList(wxCUserTagsService.findTagList(getTenantId(), ids));
            }
        }
    }


    private void setUserInfoCar(WxCUserBasicInfo info) {
        WxCUserCar wxCUserCar = new WxCUserCar();
        wxCUserCar.setCUserId(info.getId());
        List<WxCUserCar> list = wxCUserCarService.getList(wxCUserCar);
        if (list.size() > 0) {
            info.setCarList(list.stream().map(p -> p.getCarNumber()).collect(Collectors.toList()));
        }

    }

    private void setUserInfoCarCount(WxCUserBasicInfo info) {
        WxCUserCar wxCUserCar = new WxCUserCar();
        wxCUserCar.setCUserId(info.getId());
        info.setCarCount(wxCUserCarService.countUserCar(wxCUserCar));
    }

    @ApiOperation("分页列表接口")
    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    @SystemControllerLog(description = "会员管理-列表")
    public ResultData list(@ModelAttribute WxCUserBasicInfo wxCUserBasicInfo, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::list");
        if (null == wxCUserBasicInfo) {
            wxCUserBasicInfo = new WxCUserBasicInfo();
        } else {
            if (StringUtils.isBlank(wxCUserBasicInfo.getPhone())) {
                wxCUserBasicInfo.setPhone(null);
            }
            if (StringUtils.isBlank(wxCUserBasicInfo.getName())) {
                wxCUserBasicInfo.setName(null);
            }
        }
        String tenantId = getTenantId();
        wxCUserBasicInfo.setTenantId(tenantId);
        wxCUserBasicInfo.setSortColumns(BaseEntity.SortField.ActiveTime_DESC);
        PageInfo<WxCUserBasicInfo> page = wxCUserBasicInfoService.listAsPage(wxCUserBasicInfo, pageNum, pageSize);

        if (page.getSize() > 0) {
            for (WxCUserBasicInfo info : page.getList()) {
//                setUserInfoLevel(info);
                setUserInfoCarCount(info);
            }
        }
        return new ResultData(page);
    }

    private int checkUniquePhone(String phone, String tenantId) {
        WxCUserBasicInfo baseInfoQ = new WxCUserBasicInfo();
        baseInfoQ.setPhone(phone);
        baseInfoQ.setTenantId(tenantId);
        return wxCUserBasicInfoService.countUser(baseInfoQ);
    }

    @ApiOperation("根据id更新接口")
    @PostMapping("update")
    @SystemControllerLog(description = "会员管理-更新")
    public ResultData update(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::update");
        WxCUserBasicInfo oldInfo = wxCUserBasicInfoService.getById(wxCUserBasicInfo.getId());
        if (!oldInfo.getPhone().equals(wxCUserBasicInfo.getPhone())) {
            if (checkUniquePhone(wxCUserBasicInfo.getPhone(), getTenantId()) > 0) {
                return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(), "手机号已存在");
            }
        }
        wxCUserBasicInfo.setTenantId(getTenantId());
        if (StringUtils.isNotBlank(wxCUserBasicInfo.getTagIds())) {
            WxCUserTags record = new WxCUserTags();
            record.setUserId(oldInfo.getId());
            record.setTenantId(getTenantId());
            PageInfo<WxCUserTags> page = wxCUserTagsService.listAsPage(record, 1, 1);
            if (page.getSize() > 0) {
                WxCUserTags t = page.getList().get(0);
                record.setId(t.getId());
            }
            String tags = wxCUserBasicInfo.getTagIds();
            List<Long> tagIdList = new ArrayList<>();
            for (String t : tags.split(",")) {
                tagIdList.add(Long.valueOf(t));
            }
            record.setTags(JSON.toJSONString(tagIdList));
            wxCUserTagsService.saveOrUpdate(record);
            wxCUserBasicInfo.setTagId(record.getId());
        }
        wxCUserBasicInfoService.update(wxCUserBasicInfo);
        wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT, wxCUserBasicInfo);
        return new ResultData();
    }

    @ApiOperation("根据id删除接口")
    @GetMapping("/del")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "会员管理-删除")
    public ResultData delete(Long id) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::delete");
        wxCUserBasicInfoService.deleteById(id);
        return new ResultData(Result.SUCCESS, "删除成功", null);
    }

    @ApiOperation("根据id查询接口")
    @GetMapping("/findById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "会员管理-查询")
    public ResultData findById(Long id) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::findById");
        WxCUserBasicInfo info = wxCUserBasicInfoService.getById(id);

        if (info == null)
            return new ResultData(ErrorCode.USER_IS_EMPTY);

        setUserInfoTag(info);
        setUserInfoLevel(info);
        setUserInfoCar(info);
        return new ResultData(info);
    }

    @ApiOperation("根据userId查询交易记录接口")
    @GetMapping("/findOrderCouponByUserId")
    @ApiImplicitParam(name = "userId", value = "userId", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "会员管理-userId查询交易记录")
    public ResultData findOrderCouponByUserId(Long userId, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::findOrderCouponByUserId");
        WxCouponOrder corder = new WxCouponOrder();
        corder.setCUserId(userId);
        corder.setTenantId(getTenantId());
        corder.setSortColumns(BaseEntity.SortField.CreateDate_DESC);
        PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(corder, pageNum, pageSize);
        if (page.getSize() > 0) {
            List<WxCouponOrder> list = page.getList();
            for (WxCouponOrder c : list) {
                WxCoupon coupon = wxCouponService.getById(c.getCouponId());
                c.setCouponName(coupon.getTitle());
                c.setSalePrice(coupon.getPrice());

                if(c.getCouponId() != null) {
                    HashMap<String, String> param = new HashMap<>();
                    param.put("id", c.getCouponId() + "");
                    WxMerchant w = wxMerchantMapper.findByTrade(param);
                    if (w != null)
                        c.setMerchantName(w.getName());
                }
            }
        }
        return new ResultData(Result.SUCCESS, "查询成功", page);
    }

    @ApiOperation("导出根据userId查询交易记录接口")
    @GetMapping("/exportOrderCouponByUserId")
    @ApiImplicitParam(name = "userId", value = "userId", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "会员管理-userId查询交易记录")
    public void exportOrderCouponByUserId(HttpServletRequest request, HttpServletResponse response,Long userId) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::exportOrderCouponByUserId");
        WxCouponOrder corder = new WxCouponOrder();
        corder.setCUserId(userId);
        corder.setTenantId(getTenantId());
        corder.setSortColumns(BaseEntity.SortField.CreateDate_DESC);
        PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(corder, 1, Integer.MAX_VALUE);
        if (page.getSize() > 0) {
            List<WxCouponOrder> list = page.getList();
            for (WxCouponOrder c : list) {
                WxCoupon coupon = wxCouponService.getById(c.getCouponId());
                c.setCouponName(coupon.getTitle());
                c.setSalePrice(coupon.getPrice());
            }

            List<UserTradeRecordVo> datalist = new ArrayList<>();
            for (WxCouponOrder wxCouponOrder:list) {
                UserTradeRecordVo userTradeRecordVo = new UserTradeRecordVo();
                userTradeRecordVo.setCouponName(wxCouponOrder.getCouponName());
                BigDecimal b = new BigDecimal(wxCouponOrder.getSalePrice());
                userTradeRecordVo.setPrice(b.divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP).toString());
                b = new BigDecimal(wxCouponOrder.getCouponPrice());
                userTradeRecordVo.setSale(b.divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP).toString());
                userTradeRecordVo.setStatus(EnumCouponOrderStatus.getEnum(wxCouponOrder.getCouponOrderStatus()).getMessage());
                userTradeRecordVo.setTradeTime(DateUtils.formatDateTime(wxCouponOrder.getCreateDate()));
                datalist.add(userTradeRecordVo);
            }
            excelService.exportExcel(datalist, null, "会员交易记录", UserTradeRecordVo.class,  "会员交易记录.xlsx", response, false);
        }


    }

    @ApiOperation("会员记录导出总数")
    @GetMapping("/exportDataCount")
    @SystemControllerLog(description = "会员管理-会员记录导出总数")
    public ResultData exportDataCount(@ModelAttribute WxCUserBasicInfo basicInfo) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::exportDataCount");
        if(basicInfo == null) {
            basicInfo = new WxCUserBasicInfo();
        } else {
            if (StringUtils.isBlank(basicInfo.getPhone())) {
                basicInfo.setPhone(null);
            }
            if (StringUtils.isBlank(basicInfo.getName())) {
                basicInfo.setName(null);
            }
        }

        basicInfo.setTenantId(getTenantId());
        int exportDataCount = wxCUserBasicInfoService.exportDataCount(basicInfo);
        return new ResultData(exportDataCount);


    }

    @ApiOperation("会员记录导出")
    @GetMapping("/exportData")
    @SystemControllerLog(description = "会员管理-会员记录导出")
    public void exportData(@ModelAttribute WxCUserBasicInfo basicInfo, HttpServletRequest request, HttpServletResponse response) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::exportData");
        if(basicInfo == null) {
            basicInfo = new WxCUserBasicInfo();
        } else {
            if (StringUtils.isBlank(basicInfo.getPhone())) {
                basicInfo.setPhone(null);
            }
            if (StringUtils.isBlank(basicInfo.getName())) {
                basicInfo.setName(null);
            }
        }

        basicInfo.setTenantId(getTenantId());
        wxCUserBasicInfoService.exportData(basicInfo, request, response);

    }

    @RequestMapping("/exportTemplate")
    @SystemControllerLog(description = "会员管理-导出模板")
    public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::exportTemplate");

        wxCUserBasicInfoService.exportTemplate(request, response, getTenantId());

    }

    private void set_redis_value(String importKey, String allCount, String allSuccessCount, String processCount, String failCount, boolean fail) {
        stringRedisTemplate.opsForHash().put(importKey, "allCount", allCount);
        stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", allSuccessCount);
        stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount);
        stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount);
        if(fail) {
            stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS);
        }
    }

    @PostMapping(value = "/importTemplate", consumes = "multipart/*")
    @SystemControllerLog(description = "会员管理-导入数据")
    public ResultData importTemplate(@RequestParam("file") MultipartFile mFile) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::importTemplate");
        if (mFile.isEmpty()) {
            throw new MallinkException(Result.ERROR, "上传文件不能为空");
        }
        //得到当前用户ID
        final MallUserInfo user = getUser();
        String userId = "" + user.getId();
        String importKey = Constant.importMemPrev + userId;
        final String tenantId = getTenantId();

        //查询当前用户得到的值是否为空，为空继续，不为空，返回模板正在导入
        Boolean allCount = stringRedisTemplate.opsForHash().hasKey(importKey, "allCount");
        if (allCount) {
            return new ResultData(Result.SUCCESS, "模板正在导入");
        }

        stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", 0 + "");
        stringRedisTemplate.expire(importKey,30,TimeUnit.MINUTES);
        stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allSuccessCount", 0 + "");
        stringRedisTemplate.opsForHash().putIfAbsent(importKey, "processCount", "");
        stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "");

        String fpath = fmUploadDir;
        File targetFile = new File(fpath);
        if (!targetFile.exists()) {
            targetFile.mkdirs();
        }
        String fileName = "1.xlsx";
        int dot = mFile.getOriginalFilename().lastIndexOf('.');
        fileName = fileName + mFile.getOriginalFilename().substring(dot, mFile.getOriginalFilename().length());

        File lFile = new File(fpath + File.separator + fileName);

        FileOutputStream fos = null;
        BufferedInputStream fs = null;
        try {
            fos = new FileOutputStream(lFile);
            fs = (BufferedInputStream) mFile.getInputStream();
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = fs.read(buffer)) != -1) {
                fos.write(buffer, 0, len);
            }
            fos.close();
            fs.close();
        } catch (Exception e) {
            stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS);
            stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1");
            stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1");
            logger.error(e.getMessage());
            return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败");
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS);
                    stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1");
                    stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1");
                    logger.error(e.getMessage());
                    return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败");
                }
            }
            if (fs != null) {
                try {
                    fs.close();
                } catch (IOException e) {
                    stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS);
                    stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1");
                    stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1");
                    logger.error(e.getMessage());
                    return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败");
                }
            }
        }

        asyncTask.importExcelData(lFile, user, importKey, tenantId);

        return new ResultData(Result.SUCCESS, "模板正在导入");
    }


    @GetMapping("/queryTemplateCount")
    @SystemControllerLog(description = "会员管理-导入数据查询")
    public ResultData queryTemplateCount() {
        String importKey = Constant.importMemPrev + getUser().getId();
        Map entries = stringRedisTemplate.opsForHash().entries(importKey);
        logger.info(JSONArray.toJSONString(entries) + ">>>>>>>>>>>>>>>>>>>>>1");
        if (entries.size() < 4) {
            entries.clear();
            return new ResultData(Result.SUCCESS, "ok", entries);
        }
        String allCount = entries.get("allCount").toString();
        String allSuccessCount = entries.get("allSuccessCount").toString();
        String processCount = entries.get("processCount").toString();
        String failCount = entries.get("failCount").toString();

        if (StringUtils.isNotBlank(failCount) && allCount.equals(failCount)) {//stringRedisTemplate.expire(userId,1,TimeUnit.SECONDS);
            logger.info(JSONArray.toJSONString(entries) + ">>>>>>>>>>>>>>>>>>>>>2");
            //完全失败
            stringRedisTemplate.opsForHash().delete(importKey, "allCount");
            stringRedisTemplate.opsForHash().delete(importKey, "allSuccessCount");
            stringRedisTemplate.opsForHash().delete(importKey, "processCount");
            stringRedisTemplate.opsForHash().delete(importKey, "failCount");
            return new ResultData(ErrorCode.MEM_IMPORT_ERR);
        }
        //导入完成
        if (StringUtils.isNotBlank(allSuccessCount) && allSuccessCount.equals(processCount)) {
            ResultData ok = new ResultData(Result.SUCCESS, "ok", entries);
            stringRedisTemplate.opsForHash().delete(importKey, "allCount");
            stringRedisTemplate.opsForHash().delete(importKey, "allSuccessCount");
            stringRedisTemplate.opsForHash().delete(importKey, "processCount");
            stringRedisTemplate.opsForHash().delete(importKey, "failCount");
            return ok;
        }
        return new ResultData(Result.SUCCESS, "查询成功", entries);
    }

    @ApiOperation("进出场车辆分页列表接口")
    @GetMapping("carPayList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "isPay", value = "是否缴费 1是", dataType = "int", paramType = "query")
    })
    @SystemControllerLog(description = "会员管理-进出场车辆分页列表")
    public ResultData carPayList(@ModelAttribute WxCarPayRecord record, Integer pageNum, Integer pageSize){
        record.setTenantId(super.getTenantId());
        return new ResultData(wxCarPayRecordService.findCarPayListByPage(record,pageNum,pageSize));
    }

    @ApiOperation("停车会员记录导出")
    @GetMapping("/exportCarPayData")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "isPay", value = "是否缴费 1是", dataType = "int", paramType = "query")
    })
    @SystemControllerLog(description = "会员管理-停车会员记录导出")
    public void exportCarPayData(@ModelAttribute WxCarPayRecord record,HttpServletRequest request, HttpServletResponse response) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::exportData");
        record.setTenantId(getTenantId());
        wxCUserBasicInfoService.exportCarPayData(record, request, response);

    }

    @ApiOperation("根据手机号查询接口")
    @GetMapping("/findByPhone")
    @ApiImplicitParam(name = "phone", value = "phone", dataType = "String", paramType = "query", required = true)
    @SystemControllerLog(description = "会员管理-根据手机号查询接口")
    public ResultData findByPhone(String phone) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::findByPhone");
        if (StringUtils.isEmpty(phone)) {
            return new ResultData(new ArrayList<WxCUserBasicInfo>());
        }
        List<WxCUserBasicInfo> wxCUserBasicInfoList = wxCUserBasicInfoService.findByPhone(getTenantId(),phone);
        WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo();
        if (wxCUserBasicInfoList != null && wxCUserBasicInfoList.size() > 0) {
            wxCUserBasicInfo = wxCUserBasicInfoList.get(0);
        }
        return new ResultData(wxCUserBasicInfo);
    }

    @ApiOperation("获取会员过滤器")
    @GetMapping("/listFilter")
    @SystemControllerLog(description = "会员管理-获取会员过滤器")
    public ResultData listFilter() {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::listFilter");
        return new ResultData(wxCUserBasicInfoService.listFilters(getTenantId()));
    }


    @ApiOperation("会员过滤器获取数量")
    @PostMapping("/countByFilter")
    @SystemControllerLog(description = "会员管理-会员过滤器获取数量")
    public ResultData countByFilter(@RequestBody List<WxCUserBasicInfoFilterDto> filterList) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::listFilter");
        return new ResultData(wxCUserBasicInfoService.countByFilter(getTenantId(),filterList));
    }

    @ApiOperation("获取会员过滤器")
    @PostMapping("/listByFilter")
    @SystemControllerLog(description = "会员管理-会员过滤器获取")
    public ResultData listByFilter(@RequestParam List<WxCUserBasicInfoFilterDto> filterList) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::listFilter");
        return new ResultData(wxCUserBasicInfoService.listByFilter(getTenantId(),filterList));
    }

    @ApiOperation("根据ID锁定")
    @PostMapping("/updateStatus")
    @SystemControllerLog(description = "会员管理-根据ID锁定")
    public ResultData updateStatus(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) {
        logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::updateStatus");
        if (null == wxCUserBasicInfo.getId()) {
            return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "id不能为空");
        }
        if (null == wxCUserBasicInfo.getStatus()) {

        }
        return wxCUserBasicInfoService.updateStatus(wxCUserBasicInfo);
    }

}