package com.hzs.member.base.controller.manage;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.annotation.AccessPermissions;
import com.hzs.common.core.annotation.ColumnAuthority;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.constant.*;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.member.account.CuMemberTransfer;
import com.hzs.common.domain.member.account.CuMemberWithdraw;
import com.hzs.common.domain.member.achieve.CuMemberSettlePeriod;
import com.hzs.common.domain.member.base.CuMember;
import com.hzs.common.domain.member.ext.CuMemberExt;
import com.hzs.common.domain.system.config.BdAwards;
import com.hzs.common.security.service.MemberTokenService;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.service.ITransactionCommonService;
import com.hzs.member.account.service.ICuMemberTransferService;
import com.hzs.member.account.service.ICuMemberWithdrawService;
import com.hzs.member.achieve.service.ICuMemberSettlePeriodService;
import com.hzs.member.achieve.service.ICuMemberTreeService;
import com.hzs.member.base.dto.LoginMember;
import com.hzs.member.base.dto.MemberBusinessTemplate;
import com.hzs.member.base.param.*;
import com.hzs.member.base.service.ICuMemberService;
import com.hzs.member.base.service.ICuMemberTeamService;
import com.hzs.member.base.vo.*;
import com.hzs.member.login.service.IMemberLoginService;
import com.hzs.system.base.IAreaServiceApi;
import com.hzs.system.base.ICurrencyServiceApi;
import com.hzs.system.base.dto.CurrencyDTO;
import com.hzs.system.config.IAwardsServiceApi;
import com.hzs.system.config.IGradeServiceApi;
import com.hzs.system.config.dto.GradeDTO;
import com.hzs.system.sys.IMenuColumnServiceApi;
import com.hzs.system.sys.IUserServiceApi;
import com.hzs.system.sys.dto.UserAuthorityDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@RequestMapping("/manager/member")
@RestController
public class CuMemberController extends BaseController {

    @Autowired
    private ICuMemberWithdrawService iCuMemberWithdrawService;
    @Autowired
    private ICuMemberSettlePeriodService iCuMemberSettlePeriodService;
    @Autowired
    private ICuMemberTransferService iCuMemberTransferService;
    @Autowired
    private ICuMemberService iCuMemberService;
    @Autowired
    private ICuMemberTeamService iCuMemberTeamService;
    @Autowired
    private ICuMemberTreeService iCuMemberTreeService;
    @Autowired
    private ITransactionCommonService iTransactionCommonService;
    @Autowired
    private MemberTokenService memberTokenService;
    @Autowired
    private IMemberLoginService iMemberLoginService;

    @DubboReference
    IUserServiceApi iUserServiceApi;
    @DubboReference
    IAwardsServiceApi iAwardsServiceApi;
    @DubboReference
    IGradeServiceApi iGradeServiceApi;
    @DubboReference
    IAreaServiceApi iAreaServiceApi;
    @DubboReference
    ICurrencyServiceApi iCurrencyServiceApi;
    @DubboReference
    IMenuColumnServiceApi iMenuColumnServiceApi;

    /**
     * 会员
     */
    @AccessPermissions("Member")
    @ColumnAuthority(perms = "Member")
    @Log(module = EOperationModule.MEMBER_INFORMATION, business = EOperationBusiness.MEMBER_INFORMATION, method = EOperationMethod.SELECT)
    @GetMapping("/query-member")
    public TableDataInfo queryMember(CuMemberVO memberParam) {
        memberParam.setPkCountry(SecurityUtils.getPkCountry());
        EMemberAccount memberAccountEnum = null;
        if (memberParam.getMemberAccount() != null) {
            Map<Integer, EMemberAccount> memberAccountMap = Arrays.stream(EMemberAccount.values())
                    .collect(Collectors.toMap(EMemberAccount::getValue, e -> e));
            memberAccountEnum = memberAccountMap.getOrDefault(memberParam.getMemberAccount(), null);
        }
        if (memberAccountEnum != null) {
            switch (memberAccountEnum) {
                case NORMAL:
                    memberParam.setIsTransfer(EYesNo.YES.getIntValue());
                    memberParam.setIsWithdraw(EYesNo.YES.getIntValue());
                    memberParam.setIsConsume(EYesNo.YES.getIntValue());
                    break;
                case PROHIBIT_TRANSFER:
                    memberParam.setIsTransfer(EYesNo.NO.getIntValue());
                    break;
                case PROHIBIT_WITHDRAW:
                    memberParam.setIsWithdraw(EYesNo.NO.getIntValue());
                    break;
                case PROHIBIT_CONSUME:
                    memberParam.setIsConsume(EYesNo.NO.getIntValue());
                    memberParam.setIsTransfer(EMemberAccount.PROHIBIT_CONSUME.getIsYesNo());
                    break;
                case WHOLE_TRANSFER:
                    memberParam.setIsTransfer(EYesNo.YES.getIntValue());
                    memberParam.setTransferStatus(ETransferStatus.FREEZE.getValue());
                    break;
                default:
                    break;
            }
        }

        // 获取管理员权限（角色地区范围、体系列表、团队列表）
        UserAuthorityDTO userAuthorityDTO = iUserServiceApi.getUserAuthority(SecurityUtils.getUserId()).getData();
        memberParam.setVertexList(userAuthorityDTO.getUserVertexList());
        memberParam.setTeamList(userAuthorityDTO.getUserTeamList());

        startPage();
        List<CuMemberVO> queryCuMemberVoList = iCuMemberService.queryCuMemberByCondition(memberParam);
        List<CuMemberVO> cuMemberVOList = new ArrayList<>();

        if (CollectionUtil.isNotEmpty(queryCuMemberVoList)) {

            cuMemberVOList = iCuMemberService.queryCuMemberByMemberList(queryCuMemberVoList, memberParam);
            if (CollectionUtil.isNotEmpty(cuMemberVOList)) {
                // 获取需要翻译的枚举翻译
                Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(EMemberAccount.values());

                cuMemberVOList.forEach(cvo -> {
                    EExpireStatus eExpireStatus = EExpireStatus.getEnumByValue(cvo.getExpireStatus());
                    if (null != eExpireStatus) {
                        cvo.setExpireStatusVal(eExpireStatus.getLabel());
                    }
                    if (StringUtils.isNotNull(memberParam.getIsConsume()) &&
                            (memberParam.getIsConsume() == EMemberAccount.PROHIBIT_CONSUME.getValue()
                                    || memberParam.getIsConsume() == EMemberAccount.WHOLE_TRANSFER.getValue())) {
                        cvo.setMemberAccountVal(getMemberAccountVal(cvo, transactionMap));
                    }

                    if (StringUtils.isNull(cvo.getDirectPushNumber())) {
                        cvo.setDirectPushNumber(0);
                    }

                    if (StringUtils.isNull(cvo.getChangeNumber())) {
                        cvo.setChangeNumber(0);
                    }
                    if (cvo.getCategory() == ECategory.DEAD_POINT.getValue() ||
                            cvo.getCustomerType() == ECustomerType.DEAD_POINT.getValue()) {
                        cvo.setAccountStatus(EAccountStatus.SHUT_DOWN.getValue());
                        cvo.setIsTransfer(EYesNo.NO.getIntValue());
                        cvo.setIsWithdraw(EYesNo.NO.getIntValue());
                        cvo.setIsConsume(EYesNo.NO.getIntValue());
                    }
                    cvo.setMemberAccountVal(getMemberAccountVal(cvo, transactionMap));
                    cvo.setServiceAgreementVal(EServiceStatus.getEnumByValue(cvo.getServiceAgreement()).getLabel());
                });
            }
        }
        TableDataInfo tableDataInfo = getDataTable(queryCuMemberVoList);
        tableDataInfo.setRows(cuMemberVOList);
        return tableDataInfo;
    }

    /**
     * 导入批量查询会员信息
     **/
    @Log(module = EOperationModule.SPECIAL_BUSINESS, business = EOperationBusiness.MODIFY_CODE, method = EOperationMethod.IMPORT)
    @PostMapping("/batch-importData")
    public AjaxResult batchImportData(MultipartFile file) throws Exception {
        ExcelUtil<CuMemberImportVO> util = new ExcelUtil<>(CuMemberImportVO.class);
        StringBuilder memberCodeStr = new StringBuilder();
        List<CuMemberImportVO> memberCodeList = util.importExcel(file.getInputStream());
        if (CollectionUtil.isNotEmpty(memberCodeList)) {
            List<CuMemberImportVO> distinctList = new ArrayList<>(memberCodeList.stream()
                    .collect(Collectors.toMap(CuMemberImportVO::getMemberCode,
                            vo -> vo,
                            (existing, replacement) -> existing))
                    .values());
            for (CuMemberImportVO cu : distinctList) {
                memberCodeStr.append(cu.getMemberCode()).append(",");
            }
        }
        return AjaxResult.success(memberCodeStr.toString());
    }

    /**
     * 获取会员账户信息值
     *
     * @param cvo            会员对象
     * @param transactionMap 枚举翻译Map
     * @return 账户信息值
     */
    private String getMemberAccountVal(CuMemberVO cvo, Map<String, String> transactionMap) {
        String memberAccountVal = "";
        if (StringUtils.isNotNull(cvo.getIsTransfer()) && cvo.getIsTransfer() == EYesNo.NO.getIntValue()) {
            memberAccountVal = transactionMap.get(EnumsPrefixConstants.MEMBER_ACCOUNT + EMemberAccount.PROHIBIT_TRANSFER.getValue());
        }
        if (StringUtils.isNotNull(cvo.getIsWithdraw()) && cvo.getIsWithdraw() == EYesNo.NO.getIntValue()) {
            memberAccountVal = memberAccountVal + "/" + transactionMap.get(EnumsPrefixConstants.MEMBER_ACCOUNT + EMemberAccount.PROHIBIT_WITHDRAW.getValue());
            if (StringUtils.isNotNull(cvo.getTransferStatus()) && cvo.getTransferStatus() == ETransferStatus.FREEZE.getValue()) {
                memberAccountVal = memberAccountVal + "/" + transactionMap.get(EnumsPrefixConstants.MEMBER_ACCOUNT + EMemberAccount.WHOLE_TRANSFER.getValue());
            }
        }
        if (StringUtils.isNotNull(cvo.getIsConsume()) && cvo.getIsConsume() == EYesNo.NO.getIntValue()) {
            memberAccountVal = memberAccountVal + "/" + transactionMap.get(EnumsPrefixConstants.MEMBER_ACCOUNT + EMemberAccount.PROHIBIT_CONSUME.getValue());
            if (StringUtils.isNotNull(cvo.getTransferStatus()) && cvo.getTransferStatus() == ETransferStatus.FREEZE.getValue()) {
                memberAccountVal = memberAccountVal + "/" + transactionMap.get(EnumsPrefixConstants.MEMBER_ACCOUNT + EMemberAccount.WHOLE_TRANSFER.getValue());
            }
        }
        if (StringUtils.isNotNull(cvo.getIsTransfer()) && cvo.getIsTransfer() == EYesNo.YES.getIntValue()
                && StringUtils.isNotNull(cvo.getIsWithdraw()) && cvo.getIsWithdraw() == EYesNo.YES.getIntValue()
                && StringUtils.isNotNull(cvo.getIsConsume()) && cvo.getIsConsume() == EYesNo.YES.getIntValue()) {
            memberAccountVal = transactionMap.get(EnumsPrefixConstants.MEMBER_ACCOUNT + EMemberAccount.NORMAL.getValue());
            if (StringUtils.isNotNull(cvo.getTransferStatus()) && cvo.getTransferStatus() == ETransferStatus.FREEZE.getValue()) {
                memberAccountVal = memberAccountVal + "/" + transactionMap.get(EnumsPrefixConstants.MEMBER_ACCOUNT + EMemberAccount.WHOLE_TRANSFER.getValue());
            }
        }
        return memberAccountVal;
    }


    /**
     * 导出会员信息
     *
     * @param response
     * @param memberParam
     */
    @Log(module = EOperationModule.MEMBER_INFORMATION, business = EOperationBusiness.MEMBER_INFORMATION, method = EOperationMethod.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CuMemberVO memberParam) {
        memberParam.setPkCountry(SecurityUtils.getPkCountry());
        List<String> memberCodeList = new ArrayList<>();
        List<CuMemberVO> memberCodeList1 = new ArrayList<>();
        if (StringUtils.isNotEmpty(memberParam.getMemberCodeStr())) {
            memberCodeList = Arrays.asList(memberParam.getMemberCodeStr().split(","));
            if (CollectionUtil.isNotEmpty(memberCodeList)) {
                memberParam.setMemberCodeList(memberCodeList);
            }
            for (String st : memberCodeList) {
                CuMemberVO cu = new CuMemberVO();
                cu.setMemberCode(st);
                memberCodeList1.add(cu);
            }
        }
        EMemberAccount memberAccountEnum = null;
        if (memberParam.getMemberAccount() != null) {
            Map<Integer, EMemberAccount> memberAccountMap = Arrays.stream(EMemberAccount.values())
                    .collect(Collectors.toMap(EMemberAccount::getValue, e -> e));
            memberAccountEnum = memberAccountMap.getOrDefault(memberParam.getMemberAccount(), null);
        }
        if (memberAccountEnum != null) {
            switch (memberAccountEnum) {
                case NORMAL:
                    memberParam.setIsTransfer(EYesNo.YES.getIntValue());
                    memberParam.setIsWithdraw(EYesNo.YES.getIntValue());
                    memberParam.setIsConsume(EYesNo.YES.getIntValue());
                    break;
                case PROHIBIT_TRANSFER:
                    memberParam.setIsTransfer(EYesNo.NO.getIntValue());
                    break;
                case PROHIBIT_WITHDRAW:
                    memberParam.setIsWithdraw(EYesNo.NO.getIntValue());
                    break;
                case PROHIBIT_CONSUME:
                    memberParam.setIsConsume(EYesNo.NO.getIntValue());
                    memberParam.setIsTransfer(EMemberAccount.PROHIBIT_CONSUME.getIsYesNo());
                    break;
                case WHOLE_TRANSFER:
                    memberParam.setIsTransfer(EYesNo.YES.getIntValue());
                    memberParam.setTransferStatus(ETransferStatus.FREEZE.getValue());
                    break;
                default:
                    break;
            }
        }

        // 获取管理员权限（角色地区范围、体系列表、团队列表）
        UserAuthorityDTO userAuthorityDTO = iUserServiceApi.getUserAuthority(SecurityUtils.getUserId()).getData();
        memberParam.setVertexList(userAuthorityDTO.getUserVertexList());
        memberParam.setTeamList(userAuthorityDTO.getUserTeamList());
        List<CuMemberVO> cuMemberVOList = iCuMemberService.queryCuMemberByMemberListExcel(memberParam);

        if (CollectionUtil.isNotEmpty(cuMemberVOList)) {
            // 获取需要翻译的枚举翻译
            Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(EMemberAccount.values(),
                    EYesNoAttestation.values(), EOrderSource.values(), ERegistrationAuthority.values(),
                    EAccountStatus.values(), EWalletStatus.values(), ECategory.values(), EIncomeStatus.values()
                    , EDealerYesNo.values());
            Map<Integer, String> transactionMap1 = iTransactionCommonService.exportEnumTransactionByDB(EnumsPrefixConstants.KEY_GRADE,
                    EnumsPrefixConstants.KEY_AWARD);

            cuMemberVOList.forEach(cvo -> {
                if (StringUtils.isNotNull(memberParam.getIsConsume()) &&
                        (memberParam.getIsConsume() == EMemberAccount.PROHIBIT_CONSUME.getValue()
                                || memberParam.getIsConsume() == EMemberAccount.WHOLE_TRANSFER.getValue())) {
                    cvo.setMemberAccountVal(getMemberAccountVal(cvo, transactionMap));
                }
                EExpireStatus eExpireStatus = EExpireStatus.getEnumByValue(cvo.getExpireStatus());
                if (null != eExpireStatus) {
                    cvo.setExpireStatusVal(eExpireStatus.getLabel());
                }
                if (StringUtils.isNull(cvo.getDirectPushNumber())) {
                    cvo.setDirectPushNumber(0);
                }
                if (StringUtils.isNull(cvo.getChangeNumber())) {
                    cvo.setChangeNumber(0);
                }
                if ((cvo.getCategory() != null && cvo.getCategory() == ECategory.DEAD_POINT.getValue()) ||
                        (cvo.getCustomerType() != null && cvo.getCustomerType() == ECustomerType.DEAD_POINT.getValue())) {
                    cvo.setAccountStatus(EAccountStatus.SHUT_DOWN.getValue());
                    cvo.setIsTransfer(EYesNo.NO.getIntValue());
                    cvo.setIsWithdraw(EYesNo.NO.getIntValue());
                    cvo.setIsConsume(EYesNo.NO.getIntValue());
                }
                cvo.setCategoryVal(transactionMap.get(EnumsPrefixConstants.ENU_CAT + cvo.getCategory()));
                cvo.setAccountStatusVal(transactionMap.get(EnumsPrefixConstants.ACCOUNT_STATUS + cvo.getAccountStatus()));
                cvo.setIsBusLicenseVal(transactionMap.get(EnumsPrefixConstants.YES_NO_UPLOADS + cvo.getIsBusLicense()));
                cvo.setIsRealNameVal(transactionMap.get(EnumsPrefixConstants.YES_NO_ATTESTATION + cvo.getIsRealName()));
                cvo.setOrderSourceVal(transactionMap.get(EnumsPrefixConstants.ORDER_SOURCE + cvo.getOrderSource()));
                cvo.setAgentGradeVal(transactionMap.get(EnumsPrefixConstants.KEY_GRADE + cvo.getAgentGrade()));
                cvo.setPkRegisterGradeVal(transactionMap1.get(cvo.getPkRegisterGrade()));
                cvo.setPkSettleGradeVal(transactionMap1.get(cvo.getPkSettleGrade()));
                cvo.setPkAwardsVal(transactionMap1.get(cvo.getPkAwards()));
                cvo.setPkMaxAwardsVal(transactionMap1.get(cvo.getPkMaxAwards()));
                cvo.setMemberAccountVal(getMemberAccountVal(cvo, transactionMap));
                cvo.setWalletStatusVal(transactionMap.get(EnumsPrefixConstants.WALLET_STATUS + cvo.getWalletStatus()));
                cvo.setAccountStatusVal(transactionMap.get(EnumsPrefixConstants.ACCOUNT_STATUS + cvo.getAccountStatus()));
                cvo.setRegisterAuthorityVal(transactionMap.get(EnumsPrefixConstants.REGISTRATION_AUTHORITY + cvo.getRegisterAuthority()));
                cvo.setIncomeStatusVal(transactionMap.get(EnumsPrefixConstants.INCOME_STATUS + cvo.getIncomeStatus()));
                if (cvo.getServiceAgreement() != null) {
                    cvo.setServiceAgreementVal(EServiceStatus.getEnumByValue(cvo.getServiceAgreement()).getLabel());
                }
            });
        }
        if (CollectionUtil.isNotEmpty(cuMemberVOList) && CollectionUtil.isNotEmpty(memberCodeList) &&
                cuMemberVOList.size() != memberCodeList.size()) {
            Set<String> bFieldSet = cuMemberVOList.stream()
                    .map(CuMemberVO::getMemberCode)  // 假设Item类中有一个名为getField的方法来获取某个字段
                    .collect(Collectors.toSet());
            List<CuMemberVO> result = memberCodeList1.stream()
                    .filter(item -> !bFieldSet.contains(item.getMemberCode()))
                    .collect(Collectors.toList());
            cuMemberVOList.addAll(result);
        }
        ExcelUtil<CuMemberVO> util = new ExcelUtil<>(CuMemberVO.class, iMenuColumnServiceApi.queryMenuColumn("Member", SecurityUtils.getUserId()).getData());
        util.exportExcel(response, cuMemberVOList, "会员信息");
    }

    /**
     * 会员信息显示隐藏表头列表
     **/
    @Log(module = EOperationModule.MEMBER_INFORMATION)
    @GetMapping("/query-theLable")
    public AjaxResult queryTheLable() {
        List<TheLableVO> theLableVOList = new ArrayList<>();
        for (ETheLable value : ETheLable.values()) {
            theLableVOList.add(new TheLableVO(value.getTitel(), value.getProp(), value.getKeyId(), value.getShow()));
        }
        return AjaxResult.success(theLableVOList);
    }

    /**
     * 真实信息
     **/
    @Log(module = EOperationModule.MEMBER_INFORMATION, business = EOperationBusiness.MEMBER_INFO_REAL, method = EOperationMethod.SELECT)
    @PostMapping("/real-member")
    public TableDataInfo realMember(@RequestBody CuMemberVO memberParam) {
        memberParam.setPkCountry(SecurityUtils.getPkCountry());
        List<CuMemberVO> cuMemberVOS = iCuMemberService.realCuMemberByCondition(memberParam);
        if (CollectionUtil.isNotEmpty(cuMemberVOS)) {
            for (CuMemberVO cvo : cuMemberVOS) {

                if (cvo.getSex() == ESex.MAN.getValue()) {
                    cvo.setSexVal(ESex.MAN.getLabel());
                }
                if (cvo.getSex() == ESex.WOMAN.getValue()) {
                    cvo.setSexVal(ESex.WOMAN.getLabel());
                }
                if (cvo.getCardType() == ECardType.CARD.getValue()) {
                    cvo.setCardTypeVal(ECardType.CARD.getLabel());
                }
                if (cvo.getCardType() == ECardType.OFFICER.getValue()) {
                    cvo.setCardTypeVal(ECardType.OFFICER.getLabel());
                }
                if (cvo.getCardType() == ECardType.STUDENT.getValue()) {
                    cvo.setCardTypeVal(ECardType.STUDENT.getLabel());
                }
                if (cvo.getCardType() == ECardType.DRIVE.getValue()) {
                    cvo.setCardTypeVal(ECardType.DRIVE.getLabel());
                }
                if (cvo.getCardType() == ECardType.PASSPORT.getValue()) {
                    cvo.setCardTypeVal(ECardType.PASSPORT.getLabel());
                }
            }
        }

        return getDataTable(cuMemberVOS);
    }

    /**
     * 根据会员编号查询会员信息
     **/
    @GetMapping("/getOne/{memberCode}")
    public AjaxResult getOne(@PathVariable String memberCode) {
        CuMember cuMember = iCuMemberService.getMember(memberCode);
        return AjaxResult.success(cuMember);
    }

    /**
     * 会员选择
     *
     * @param param
     * @return
     */
    @GetMapping("/member-select")
    public TableDataInfo memberSelect(MemberSelectParam param) {
        // 返回结果
        List<MemberSelectVO> resultList = new ArrayList<>();

        startPage();
        handleMemberSelect(resultList, param);

        return getDataTable(resultList);
    }

    /**
     * 会员选择下载模板
     *
     * @param response
     */
    @PostMapping("/member-select-template")
    public void memberSelectTemplate(HttpServletResponse response) {
        ExcelUtil<MemberBusinessTemplate> util = new ExcelUtil<>(MemberBusinessTemplate.class);
        util.exportExcel(response, null, "会员信息");
    }

    /**
     * 会员选择导入数据
     *
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/member-select-import")
    public AjaxResult memberSelectImport(MultipartFile file) throws Exception {
        ExcelUtil<MemberBusinessTemplate> util = new ExcelUtil<>(MemberBusinessTemplate.class);
        List<MemberBusinessTemplate> templateList = util.importExcel(file.getInputStream());

        // 返回结果
        List<MemberSelectVO> resultList = new ArrayList<>();

        if (CollectionUtil.isNotEmpty(templateList)) {
            MemberSelectParam param = new MemberSelectParam();
            param.setMemberCodeList(templateList.stream().map(MemberBusinessTemplate::getMemberCode).collect(Collectors.toList()));

            handleMemberSelect(resultList, param);
        }
        return AjaxResult.success(resultList);
    }

    /**
     * 处理选择会员数据
     *
     * @param resultList
     * @param param
     */
    private void handleMemberSelect(List<MemberSelectVO> resultList, MemberSelectParam param) {
        List<CuMemberExt> cuMemberExtList = iCuMemberService.queryMemberSelect(param, SecurityUtils.getPkCountry());

        if (CollectionUtil.isNotEmpty(cuMemberExtList)) {
            for (CuMemberExt cuMemberExt : cuMemberExtList) {
                MemberSelectVO memberSelectVO = BeanUtil.copyProperties(cuMemberExt, MemberSelectVO.class);
                // 翻译key值进行处理
                memberSelectVO.setRegisterGrade(cuMemberExt.getRegisterGradeKey());
                memberSelectVO.setSettleGrade(cuMemberExt.getSettleGradeKey());
                memberSelectVO.setAwards(cuMemberExt.getAwardsKey());
                resultList.add(memberSelectVO);
            }
        }
    }


    /**
     * 会员真实信息
     *
     * @return
     */
    @AccessPermissions("RealInfo")
    @ColumnAuthority(perms = "RealInfo")
    @Log(module = EOperationModule.MEMBER_INFORMATION, business = EOperationBusiness.MEMBER_INFO_REAL, method = EOperationMethod.SELECT)
    @GetMapping("/member-real-info")
    public TableDataInfo memberRealInfo(MemberRealInfoParam memberRealInfoParam) {
        memberRealInfoParam.setPkCountry(SecurityUtils.getPkCountry());

        // 获取管理员权限（角色地区范围、体系列表、团队列表）
        UserAuthorityDTO userAuthorityDTO = iUserServiceApi.getUserAuthority(SecurityUtils.getUserId()).getData();
        memberRealInfoParam.setVertexList(userAuthorityDTO.getUserVertexList());
        memberRealInfoParam.setTeamList(userAuthorityDTO.getUserTeamList());
        if (StringUtils.isNotEmpty(memberRealInfoParam.getBirthDate())) {
            memberRealInfoParam.setBirthDate(memberRealInfoParam.getBirthDate().replace("-", ""));
        }
        startPage();
        List<MemberRealInfoVO> resultList = iCuMemberService.selectByMemberRealInfo(memberRealInfoParam);

        if (CollectionUtil.isNotEmpty(resultList)) {
            //数据库内容翻译
            Map<Integer, String> transactionMap1 = iTransactionCommonService.exportEnumTransactionByDB(EnumsPrefixConstants.KEY_GRADE,
                    EnumsPrefixConstants.KEY_AWARD);

            R<List<BdAwards>> awardsListDate = iAwardsServiceApi.queryAwards(SecurityUtils.getPkCountry());
            // 奖衔
            List<BdAwards> awardsList = awardsListDate.getData();
            R<List<GradeDTO>> gradeListDate = iGradeServiceApi.queryGradeList(SecurityUtils.getPkCountry());
            // 等级
            List<GradeDTO> gradeList = gradeListDate.getData();
            Map<Integer, String> areaDate = iAreaServiceApi.getAreaMap(SecurityUtils.getPkCountry()).getData();

            for (MemberRealInfoVO cuMemberExt : resultList) {
                cuMemberExt.setRegisterGradeVal(transactionMap1.get(cuMemberExt.getPkRegisterGrade()));
                cuMemberExt.setSettleGradeVal(transactionMap1.get(cuMemberExt.getPkSettleGrade()));
                cuMemberExt.setAwardsVal(transactionMap1.get(cuMemberExt.getPkAwards()));
                if (cuMemberExt.getPkProvince() != null) {
                    // 省
                    cuMemberExt.setProvinceName(areaDate.get(cuMemberExt.getPkProvince()));
                }
                if (cuMemberExt.getPkCity() != null) {
                    // 市
                    cuMemberExt.setCityName(areaDate.get(cuMemberExt.getPkCity()));
                }
                if (cuMemberExt.getPkCounty() != null) {
                    // 区县
                    cuMemberExt.setCountyName(areaDate.get(cuMemberExt.getPkCounty()));
                }
                // 注册等级
                if (cuMemberExt.getPkRegisterGrade() != null) {
                    for (GradeDTO grade : gradeList) {
                        if (grade.getPkId().equals(cuMemberExt.getPkRegisterGrade())) {
                            cuMemberExt.setRegisterGradeVal(grade.getGradeName());
                        }
                    }
                }
                // 结算等级
                if (cuMemberExt.getPkSettleGrade() != null) {
                    for (GradeDTO grade : gradeList) {
                        if (grade.getPkId().equals(cuMemberExt.getPkSettleGrade())) {
                            cuMemberExt.setSettleGradeVal(grade.getGradeName());
                        }
                    }
                }
                // 真实奖衔
                if (cuMemberExt.getPkAwards() != null) {
                    for (BdAwards awards : awardsList) {
                        if (awards.getPkId().equals(cuMemberExt.getPkAwards())) {
                            cuMemberExt.setAwardsVal(awards.getAwardsName());
                        }
                    }
                }
                // 生日
                if (StringUtils.isNotBlank(cuMemberExt.getIdCard()) && (checkIdCard(cuMemberExt.getIdCard()))) {
                    cuMemberExt.setBirthDate(IdcardUtil.getBirthDate(cuMemberExt.getIdCard()));
                }
                if (cuMemberExt.getIdType() != null) {
                    cuMemberExt.setCardTypeVal(EIdType.getLabel(cuMemberExt.getIdType()));
                }
            }
        }

        return getDataTable(resultList);
    }


    /**
     * 会员团队信息
     *
     * @return
     */
    @AccessPermissions("TeamInfo")
    @GetMapping("/member-team-info")
    public TableDataInfo memberTeamInfo(MemberTeamInfoParam memberTeamInfoParam) {
        String time;
        String settleTableName;
        CuMemberSettlePeriod csPeriod;
        List<MemberTeamVo> memberTeamList = new ArrayList<>();
        R<List<BdAwards>> awardsDto = iAwardsServiceApi.queryAwards(SecurityUtils.getPkCountry());
        if (memberTeamInfoParam.getQueryDate() == null) {

            // 昨日
            time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtil.offsetDay(new Date(), -1));
            csPeriod = iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
            settleTableName = TableNameConstants.CU_MEMBER_SETTLE + csPeriod.getPkId();
        } else {
            String queryDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, memberTeamInfoParam.getQueryDate());
            String currentDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.currentDate());
            time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, memberTeamInfoParam.getQueryDate());
            csPeriod = iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
            if (queryDate.equals(currentDate)) {
                settleTableName = TableNameConstants.CU_MEMBER_SETTLE + csPeriod.getPkId();
            } else {
                // 历史
                settleTableName = TableNameConstants.CU_MEMBER_SETTLE + csPeriod.getPkId();
            }
        }
        // 如果表格不存在则返回空数据
        Integer tableNumber = iCuMemberTreeService.queryExistOracleTable(settleTableName);
        if (tableNumber == null || tableNumber == 0) {
            return getDataTable(new ArrayList<>());
        }
        memberTeamInfoParam.setSettleTableName(settleTableName);
        memberTeamInfoParam.setPeriod(csPeriod.getPkId());
        startPage();
        if (StringUtils.isNotBlank(memberTeamInfoParam.getMemberCode())) {
            if (memberTeamInfoParam.getRelaType() != null && memberTeamInfoParam.getRelaType().equals(ERealType.XY.getIntValue())) {
                // 血缘
                memberTeamList = iCuMemberTeamService.queryMemberTeamInfoList(memberTeamInfoParam);
            } else {
                // 安置
                memberTeamList = iCuMemberTeamService.queryMemberTeamInfoPlaceParentList(memberTeamInfoParam);
            }
        }
        for (MemberTeamVo memberTeamVo : memberTeamList) {
            // 查询安置层级
            if (memberTeamVo.getPlaceDept() != null) {
                memberTeamVo.setPlaceDept(memberTeamVo.getPlaceDept());
                memberTeamVo.setPlaceDeptStr(EPlaceDept.getEPlaceDept(memberTeamVo.getPlaceDept()));
            }
            if (memberTeamVo.getPkAwards() != null) {
                for (BdAwards date : awardsDto.getData()) {
                    if (memberTeamVo.getPkAwards().equals(date.getPkId())) {
                        memberTeamVo.setPkAwardsStr(date.getAwardsName());
                    }
                }
            }
            if (memberTeamVo.getPkPlaceParent() != null) {
                CuMember member = iCuMemberService.getMember(memberTeamVo.getPkPlaceParent());
                if (member != null) {
                    memberTeamVo.setPlaceParentCode(member.getMemberCode());
                }
            }
            memberTeamVo.setResettleLevel(memberTeamVo.getLevel());
            //TODO 血缘代数
            memberTeamVo.setConsanguinityAlgebra("第" + memberTeamVo.getLevel() + "代");
            //TODO 奖金大盘占比
            memberTeamVo.setBonusLargeMarketProportion(BigDecimal.ZERO);
            // 直推人数
            Long directPushPeopleNumber = iCuMemberTreeService.queryCuMemberTreeParentTableCount(settleTableName, memberTeamVo.getMemberId());
            memberTeamVo.setDirectPushPeopleNumber(directPushPeopleNumber);
            // 转账次数
            QueryWrapper<CuMemberTransfer> qew = new QueryWrapper<>();
            qew.eq("PK_MEMBER", memberTeamVo.getMemberId());
            int memberTransferCount = iCuMemberTransferService.count(qew);
            memberTeamVo.setMemberTransferCount(memberTransferCount);

            // 提现次数
            QueryWrapper<CuMemberWithdraw> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("PK_MEMBER", memberTeamVo.getMemberId());
            int memberWithdrawCount = iCuMemberWithdrawService.count(queryWrapper);
            memberTeamVo.setWithdrawalNumber(memberWithdrawCount);
            // 最后一次登录时间
            if (memberTeamVo.getLastLoginTime() != null) {
                // 计算当前时间和 最后一次登陆时间间隔
                memberTeamVo.setLastLoginTimeIntervalDays(DateUtil.betweenDay(DateUtils.currentDate(), memberTeamVo.getLastLoginTime(), true));
            }
        }
        return getDataTable(memberTeamList);
    }

    /**
     * 会员团队信息导出
     */
    @PostMapping("/member-team-info-export")
    public void memberTeamInfoExport(MemberTeamInfoParam memberTeamInfoParam, HttpServletResponse response) {
        String time;
        String settleTableName;
        CuMemberSettlePeriod csPeriod;
        List<MemberTeamVo> memberTeamList = new ArrayList<>();
        R<List<BdAwards>> awardsDto = iAwardsServiceApi.queryAwards(SecurityUtils.getPkCountry());
        if (memberTeamInfoParam.getQueryDate() == null) {

            // 昨日
            time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtil.offsetDay(new Date(), -1));
            csPeriod = iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
            settleTableName = TableNameConstants.CU_MEMBER_SETTLE + csPeriod.getPkId();
        } else {
            String queryDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, memberTeamInfoParam.getQueryDate());
            String currentDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.currentDate());
            time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, memberTeamInfoParam.getQueryDate());
            csPeriod = iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
            if (queryDate.equals(currentDate)) {
                settleTableName = TableNameConstants.CU_MEMBER_SETTLE + csPeriod.getPkId();
            } else {
                // 历史
                settleTableName = TableNameConstants.CU_MEMBER_SETTLE + csPeriod.getPkId();
            }
        }
        // 如果表格不存在则返回空数据
        Integer tableNumber = iCuMemberTreeService.queryExistOracleTable(settleTableName);
        if (tableNumber == null || tableNumber == 0) {
            ExcelUtil<MemberTeamVo> util = new ExcelUtil<>(MemberTeamVo.class);
            util.exportExcel(response, memberTeamList, "会员团队信息");
        }
        memberTeamInfoParam.setSettleTableName(settleTableName);
        memberTeamInfoParam.setPeriod(csPeriod.getPkId());
        startPage();
        if (StringUtils.isNotBlank(memberTeamInfoParam.getMemberCode())) {
            if (memberTeamInfoParam.getRelaType() != null && memberTeamInfoParam.getRelaType().equals(ERealType.XY.getIntValue())) {
                // 血缘
                memberTeamList = iCuMemberTeamService.queryMemberTeamInfoList(memberTeamInfoParam);
            } else {
                // 安置
                memberTeamList = iCuMemberTeamService.queryMemberTeamInfoPlaceParentList(memberTeamInfoParam);
            }
        }
        for (MemberTeamVo memberTeamVo : memberTeamList) {
            // 查询安置层级

            if (memberTeamVo.getPlaceDept() != null) {
                memberTeamVo.setPlaceDept(memberTeamVo.getPlaceDept());
                memberTeamVo.setPlaceDeptStr(EPlaceDept.getEPlaceDept(memberTeamVo.getPlaceDept()));
            }
            if (memberTeamVo.getPkAwards() != null) {
                for (BdAwards date : awardsDto.getData()) {
                    if (memberTeamVo.getPkAwards().equals(date.getPkId())) {
                        memberTeamVo.setPkAwardsStr(date.getAwardsName());
                    }
                }
            }
            if (memberTeamVo.getPkPlaceParent() != null) {
                CuMember member = iCuMemberService.getMember(memberTeamVo.getPkPlaceParent());
                if (member != null) {
                    memberTeamVo.setPlaceParentCode(member.getMemberCode());
                }
            }

            memberTeamVo.setResettleLevel(memberTeamVo.getLevel());

            //血缘代数
            memberTeamVo.setConsanguinityAlgebra("第" + memberTeamVo.getLevel() + "代");
            //奖金大盘占比
            memberTeamVo.setBonusLargeMarketProportion(BigDecimal.ZERO);
            // 直推人数
            Long directPushPeopleNumber = iCuMemberTreeService.queryCuMemberTreeParentTableCount(settleTableName, memberTeamVo.getMemberId());
            memberTeamVo.setDirectPushPeopleNumber(directPushPeopleNumber);
            // 转账次数
            QueryWrapper<CuMemberTransfer> qew = new QueryWrapper<>();
            qew.eq("PK_MEMBER", memberTeamVo.getMemberId());
            int memberTransferCount = iCuMemberTransferService.count(qew);
            memberTeamVo.setMemberTransferCount(memberTransferCount);

            // 提现次数
            QueryWrapper<CuMemberWithdraw> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("PK_MEMBER", memberTeamVo.getMemberId());
            int memberWithdrawCount = iCuMemberWithdrawService.count(queryWrapper);
            memberTeamVo.setWithdrawalNumber(memberWithdrawCount);
            // 最后一次登录时间
            if (memberTeamVo.getLastLoginTime() != null) {
                // 计算当前时间和 最后一次登陆时间间隔
                memberTeamVo.setLastLoginTimeIntervalDays(DateUtil.betweenDay(DateUtils.currentDate(), memberTeamVo.getLastLoginTime(), true));
            }
        }
        ExcelUtil<MemberTeamVo> util = new ExcelUtil<>(MemberTeamVo.class, iMenuColumnServiceApi.queryMenuColumn("TeamInfo", SecurityUtils.getUserId()).getData());
        util.exportExcel(response, memberTeamList, "会员团队信息");
    }

    /**
     * 免密登录
     **/
    @GetMapping("/password-free")
    public AjaxResult passwordFree(CuMemberVO cuMemberVO) {
        // 免密登录
        LoginMember loginMember = iMemberLoginService.passwordFreelogin(cuMemberVO.getMemberCode());
        // 获取登录token
        return AjaxResult.success(memberTokenService.createToken(loginMember));
    }


    /**
     * 导出真实信息
     **/
    @Log(module = EOperationModule.MEMBER_INFORMATION, business = EOperationBusiness.MEMBER_INFORMATION, method = EOperationMethod.EXPORT)
    @PostMapping("/real-info-export")
    public void realInfoExport(HttpServletResponse response, MemberRealInfoParam memberRealInfoParam) {
        memberRealInfoParam.setPkCountry(SecurityUtils.getPkCountry());
        // 获取管理员权限（角色地区范围、体系列表、团队列表）
        UserAuthorityDTO userAuthorityDTO = iUserServiceApi.getUserAuthority(SecurityUtils.getUserId()).getData();
        memberRealInfoParam.setVertexList(userAuthorityDTO.getUserVertexList());
        memberRealInfoParam.setTeamList(userAuthorityDTO.getUserTeamList());
        List<MemberRealInfoVO> resultList = iCuMemberService.selectByMemberRealInfo(memberRealInfoParam);

        if (CollectionUtil.isNotEmpty(resultList)) {
            // 获取需要翻译的枚举翻译
            Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(ECardType.values(),
                    ESex.values()
            );
            //数据库内容翻译
            Map<Integer, String> transactionMap1 = iTransactionCommonService.exportEnumTransactionByDB(EnumsPrefixConstants.KEY_GRADE,
                    EnumsPrefixConstants.KEY_AWARD);

            Map<Integer, String> areaDate = iAreaServiceApi.getAreaMap(SecurityUtils.getPkCountry()).getData();
            for (MemberRealInfoVO cuMemberExt : resultList) {
                cuMemberExt.setRegisterGradeVal(transactionMap1.get(cuMemberExt.getPkRegisterGrade()));
                cuMemberExt.setSettleGradeVal(transactionMap1.get(cuMemberExt.getPkSettleGrade()));
                cuMemberExt.setAwardsVal(transactionMap1.get(cuMemberExt.getPkAwards()));
                cuMemberExt.setPkMaxAwardsVal(transactionMap1.get(cuMemberExt.getPkMaxAwards()));
                if (cuMemberExt.getPkProvince() != null) {
                    // 省
                    cuMemberExt.setProvinceName(areaDate.get(cuMemberExt.getPkProvince()));
                }
                if (cuMemberExt.getPkCity() != null) {
                    // 市
                    cuMemberExt.setCityName(areaDate.get(cuMemberExt.getPkCity()));
                }
                if (cuMemberExt.getPkCounty() != null) {
                    // 区县
                    cuMemberExt.setCountyName(areaDate.get(cuMemberExt.getPkCounty()));
                }
                // 证件类型
                if (cuMemberExt.getCardType() != null) {
                    cuMemberExt.setCardTypeVal(transactionMap.get(EnumsPrefixConstants.CARD_TYPE + cuMemberExt.getCardType()));
                }
                // 性别
                if (cuMemberExt.getSex() != null) {
                    cuMemberExt.setSexVal(transactionMap.get(EnumsPrefixConstants.SEX + cuMemberExt.getSex()));
                }
                // 生日
                if (StringUtils.isNotBlank(cuMemberExt.getIdCard()) && (checkIdCard(cuMemberExt.getIdCard()))) {
                    cuMemberExt.setBirthDate(IdcardUtil.getBirthDate(cuMemberExt.getIdCard()));
                }
                if (cuMemberExt.getIdType() != null) {
                    cuMemberExt.setCardTypeVal(EIdType.getLabel(cuMemberExt.getIdType()));
                }
            }
        }
        ExcelUtil<MemberRealInfoVO> util = new ExcelUtil<>(MemberRealInfoVO.class, iMenuColumnServiceApi.queryMenuColumn("RealInfo", SecurityUtils.getUserId()).getData());
        util.exportExcel(response, resultList, "真实信息");
    }


    /**
     * 下载模板
     *
     * @param response
     * @param
     */
    @Log(module = EOperationModule.MEMBER_INFORMATION, business = EOperationBusiness.MEMBER_INFORMATION, method = EOperationMethod.DOWNLOAD)
    @PostMapping("/download")
    public void download(HttpServletResponse response) {
        List<CuMemberImportVO> list = new ArrayList<>();
        ExcelUtil<CuMemberImportVO> util = new ExcelUtil<>(CuMemberImportVO.class);
        util.exportExcel(response, list, "会员编号");
    }


    /**
     * 校验身份证格式
     **/
    public boolean checkIdCard(String idCard) {
        // 正则表达式校验身份证号码格式
        String reg = "\\d{17}[\\d|x|X]";
        return Pattern.matches(reg, idCard);
    }

    /**
     * 查询顶点会员
     *
     * @return
     */
    @GetMapping("/query-top-member")
    public AjaxResult queryTopMember() {
        List<TopMemberVO> resultList = new ArrayList<>();
        List<CuMemberExt> list = iCuMemberService.queryPlaceMemberList(MemberConstants.GJ30720200CODE, SecurityUtils.getPkCountry());
        if (CollectionUtil.isNotEmpty(list)) {
            resultList = BeanUtil.copyToList(list, TopMemberVO.class);
        }
        return AjaxResult.success(resultList);
    }

    /**
     * 用户消费统计
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.MEMBER_CONSUMPTION, method = EOperationMethod.SELECT)
    @GetMapping("/member_consumption_stat")
    public TableDataInfo getMemberConsumptionStat(MemberConsumptionStatParam memberConsumptionStatParam) {
        if (StringUtils.isNotBlank(memberConsumptionStatParam.getPkProducts())) {
            String[] productId = memberConsumptionStatParam.getPkProducts().split(",");
            memberConsumptionStatParam.setPkProductList(Arrays.asList(productId));
        }
        if (memberConsumptionStatParam.getStartPayTime() != null) {
            memberConsumptionStatParam.setStartPayTime(DateUtils.getStartTime(memberConsumptionStatParam.getStartPayTime()));
        }
        if (memberConsumptionStatParam.getEndPayTime() != null) {
            memberConsumptionStatParam.setEndPayTime(DateUtils.getEndTime(memberConsumptionStatParam.getEndPayTime()));
        }
        // 中国汇率
        R<CurrencyDTO> chinaCurrency = iCurrencyServiceApi.getCurrency(CountryConstants.CHINA_COUNTRY);
        BigDecimal chinaInExchangeRate = chinaCurrency.getData().getInExchangeRate();
        startPage();
        memberConsumptionStatParam.setPkCountry(SecurityUtils.getPkCountry());
        List<MemberConsumptionStatVo> memberConsumptionStatVoList = iCuMemberService.getMemberConsumptionStat(memberConsumptionStatParam);
        for (MemberConsumptionStatVo memberConsumptionStatVo : memberConsumptionStatVoList) {
            memberConsumptionStatVo.setOrderAchieve(memberConsumptionStatVo.getOrderAchieve().multiply(chinaInExchangeRate).setScale(2, BigDecimal.ROUND_HALF_UP));
        }

        return getDataTable(memberConsumptionStatVoList);
    }

    /**
     * 用户消费统计
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.MEMBER_CONSUMPTION, method = EOperationMethod.EXPORT)
    @PostMapping("/member_consumption_stat_export")
    public void getMemberConsumptionStatExport(MemberConsumptionStatParam memberConsumptionStatParam, HttpServletResponse response) {
        if (StringUtils.isNotBlank(memberConsumptionStatParam.getPkProducts())) {
            String[] productId = memberConsumptionStatParam.getPkProducts().split(",");
            memberConsumptionStatParam.setPkProductList(Arrays.asList(productId));
        }
        if (memberConsumptionStatParam.getStartPayTime() != null) {
            memberConsumptionStatParam.setStartPayTime(DateUtils.getStartTime(memberConsumptionStatParam.getStartPayTime()));
        }
        if (memberConsumptionStatParam.getEndPayTime() != null) {
            memberConsumptionStatParam.setEndPayTime(DateUtils.getEndTime(memberConsumptionStatParam.getEndPayTime()));
        }
        // 中国汇率
        R<CurrencyDTO> chinaCurrency = iCurrencyServiceApi.getCurrency(CountryConstants.CHINA_COUNTRY);
        BigDecimal chinaInExchangeRate = chinaCurrency.getData().getInExchangeRate();
        memberConsumptionStatParam.setPkCountry(SecurityUtils.getPkCountry());
        List<MemberConsumptionStatVo> memberConsumptionStatVoList = iCuMemberService.getMemberConsumptionStat(memberConsumptionStatParam);
        for (MemberConsumptionStatVo memberConsumptionStatVo : memberConsumptionStatVoList) {
            memberConsumptionStatVo.setOrderAchieve(memberConsumptionStatVo.getOrderAchieve().multiply(chinaInExchangeRate).setScale(2, BigDecimal.ROUND_HALF_UP));
        }
        ExcelUtil<MemberConsumptionStatVo> util = new ExcelUtil<>(MemberConsumptionStatVo.class);
        util.exportExcel(response, memberConsumptionStatVoList, "用户消费统计");
    }

}
