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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.constant.CountryConstants;
import com.hzs.common.core.constant.EnumsPrefixConstants;
import com.hzs.common.core.constant.TableNameConstants;
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.page.TableDataInfo;
import com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt;
import com.hzs.common.domain.member.base.CuMember;
import com.hzs.common.domain.member.ext.CuMemberExt;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.service.ITransactionCommonService;
import com.hzs.member.base.IMemberServiceApi;
import com.hzs.report.member.param.*;
import com.hzs.report.member.service.IMemberService;
import com.hzs.report.member.service.MemberReportService;
import com.hzs.report.member.vo.*;
import com.hzs.report.report.service.ICuMemberSettlePeriodService;
import com.hzs.system.base.IAreaServiceApi;
import com.hzs.system.base.ICurrencyServiceApi;
import com.hzs.system.base.dto.CurrencyDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@RequestMapping("/manager/member-report")
@RestController
public class MemberReportController extends BaseController {

    @Autowired
    private MemberReportService memberReportService;
    @Autowired
    private ITransactionCommonService iTransactionCommonService;
    @Autowired
    private IMemberService iMemberService;
    @Autowired
    private ICuMemberSettlePeriodService iCuMemberSettlePeriodService;

    @DubboReference
    IMemberServiceApi iMemberServiceApi;
    @DubboReference
    IAreaServiceApi iAreaServiceApi;
    @DubboReference
    ICurrencyServiceApi iCurrencyServiceApi;

    /**
     * 伞下直推新增业绩
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.DIRECT_PUSH_NEW, method = EOperationMethod.SELECT)
    @GetMapping("/direct-push-new")
    public TableDataInfo directPushNew(String memberCode, String memberName, Integer pkAwards, Integer pkTeamCode,
                                       Date startPayTime, Date endPayTime, Integer pkVertex, Integer orderType) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        List<Integer> orderTypeList = EOrderBusiness.getOrderTypeList(orderType);

        Long pkMember;
        if (StringUtils.isNotBlank(memberCode)) {
            CuMember member = iMemberServiceApi.getMemberByCode(memberCode).getData();
            if (null != member) {
                pkMember = member.getPkId();
            } else {
                return getDataTable(new ArrayList<>());
            }
        } else {
            return getDataTable(new ArrayList<>());
        }

        Date date = DateUtils.currentDate();
        if (StringUtils.isNull(startPayTime) || StringUtils.isNull(endPayTime)) {
            //当前月的第一天
            startPayTime = DateUtils.currentMonthFirstDate();
            endPayTime = date;
        }

        //伞下直推新增业绩
        startPage();
        List<DirectPushNewVo> memberList = memberReportService.directPushNewList(pkMember, memberName, pkAwards, pkTeamCode, pkCountry, startPayTime, endPayTime, pkVertex);

        if (CollectionUtil.isNotEmpty(memberList)) {
            startPayTime = DateUtils.getStartTime(startPayTime);
            endPayTime = DateUtils.getEndTime(endPayTime);
            List<DirectPushNewVo> achieList = memberReportService.directPushNewAchieList(pkMember, startPayTime, endPayTime, orderTypeList, pkCountry);

            R<CurrencyDTO> currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
            memberList.forEach(itm -> {
                if (null != achieList.get(0)) {
                    itm.setOrderAchieve(achieList.get(0).getOrderAchieve().multiply(currency.getData().getInExchangeRate()));
                    itm.setOrderType(orderType);
                    itm.setOrderAmount(achieList.get(0).getOrderAmount());
                }
            });
        }
        return getDataTable(memberList);
    }

    /**
     * 伞下直推新增业绩导出
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.DIRECT_PUSH_NEW, method = EOperationMethod.EXPORT)
    @PostMapping("/export-direct-push-new")
    public void export(DirectPushNewVo directPushNewVo, HttpServletResponse response) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        List<Integer> orderTypeList = EOrderBusiness.getOrderTypeList(directPushNewVo.getOrderType());

        Long pkMember = null;
        if (StringUtils.isNotBlank(directPushNewVo.getMemberCode())) {
            CuMember member = iMemberServiceApi.getMemberByCode(directPushNewVo.getMemberCode()).getData();
            if (null != member) {
                pkMember = member.getPkId();
            } else {
                ExcelUtil<DirectPushNewVo> util = new ExcelUtil<>(DirectPushNewVo.class);
                util.exportExcel(response, new ArrayList<>(), "伞下直推新增业绩导出");
            }
        } else {
            ExcelUtil<DirectPushNewVo> util = new ExcelUtil<>(DirectPushNewVo.class);
            util.exportExcel(response, new ArrayList<>(), "伞下直推新增业绩导出");
        }

        Date date = DateUtils.currentDate();
        if (StringUtils.isNull(directPushNewVo.getStartPayTime()) || StringUtils.isNull(directPushNewVo.getEndPayTime())) {
            //当前月的第一天
            directPushNewVo.setStartPayTime(DateUtils.currentMonthFirstDate());
            directPushNewVo.setEndPayTime(date);
        }
        //伞下直推新增业绩
        List<DirectPushNewVo> memberList = memberReportService.directPushNewList(pkMember, directPushNewVo.getMemberName(),
                directPushNewVo.getPkAwards(), directPushNewVo.getPkTeamCode(), pkCountry, directPushNewVo.getStartPayTime(),
                directPushNewVo.getEndPayTime(), directPushNewVo.getPkVertex());

        if (CollectionUtil.isNotEmpty(memberList)) {
            Date startPayTime = DateUtils.getStartTime(directPushNewVo.getStartPayTime());
            Date endPayTime = DateUtils.getEndTime(directPushNewVo.getEndPayTime());
            List<DirectPushNewVo> achieList = memberReportService.directPushNewAchieList(pkMember, startPayTime, endPayTime, orderTypeList, pkCountry);

            R<CurrencyDTO> currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
            Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(EOrderBusiness.values());
            memberList.forEach(itm -> {
                if (null != achieList.get(0)) {
                    itm.setOrderType(directPushNewVo.getOrderType());
                    itm.setOrderTypeVal(transactionMap.get(EnumsPrefixConstants.ORDER_BUSINESS + directPushNewVo.getOrderType()));
                    itm.setOrderAchieve(achieList.get(0).getOrderAchieve().multiply(currency.getData().getInExchangeRate()));
                    itm.setOrderAmount(achieList.get(0).getOrderAmount());
                }
            });
        }
        ExcelUtil<DirectPushNewVo> util = new ExcelUtil<>(DirectPushNewVo.class);
        util.exportExcel(response, memberList, "伞下直推新增业绩导出");
    }

    /**
     * 伞下直推新增业绩（历史）
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.DIRECT_PUSH_NEW, method = EOperationMethod.SELECT)
    @GetMapping("/direct-push-new-up")
    public TableDataInfo directPushNewUp(String memberCode, String memberName, Integer pkAwards, Integer pkTeamCode,
                                         Date startPayTime, Date endPayTime, Integer pkVertex, Integer orderType) {
        if (orderType == null) {
            orderType = EOrderUpBusiness.WHOLE.getValue();
        }

        Integer pkCountry = SecurityUtils.getPkCountry();
        Long pkMember;
        if (StringUtils.isNotBlank(memberCode)) {
            CuMember member = iMemberServiceApi.getMember(memberCode).getData();
            if (null != member) {
                pkMember = member.getPkId();
            } else {
                return getDataTable(new ArrayList<>());
            }
        } else {
            return getDataTable(new ArrayList<>());
        }

        Date date = DateUtils.currentDate();
        if (DateUtils.compareDate(startPayTime, date) > 0) {
            startPayTime = null;
            endPayTime = null;
        }
        if (StringUtils.isNull(startPayTime) || StringUtils.isNull(endPayTime)) {
            //当前月的第一天
            startPayTime = DateUtils.currentMonthFirstDate();
            endPayTime = date;
        }

        //开始时间减一天
        String startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.beforeDate(1, ChronoUnit.DAYS, startPayTime));
        String endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endPayTime);
        DirectPushNewVo dpo = new DirectPushNewVo();
        dpo.setPkCountry(pkCountry);
        //查询最新期数
        dpo.setPeriodSta(iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(
                DateUtils.parseDateToStr(startDateStr)).getPkId());
        dpo.setPeriodEnd(iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(
                DateUtils.parseDateToStr(endDateStr)).getPkId());
        dpo.setAchieveTableNameSta(TableNameConstants.CU_MEMBER_ACHIEVE + DateUtils.getMonth(startDateStr));
        dpo.setAchieveTableNameEnd(TableNameConstants.CU_MEMBER_ACHIEVE + DateUtils.getMonth(endDateStr));
        dpo.setSettleTableNameSta(TableNameConstants.CU_MEMBER_TREE + DateUtils.getMonth(startDateStr));
        dpo.setSettleTableNameEnd(TableNameConstants.CU_MEMBER_TREE + DateUtils.getMonth(endDateStr));
        //伞下直推新增业绩
        List<DirectPushNewVo> memberList = memberReportService.directPushNewList(pkMember, memberName, pkAwards, pkTeamCode, pkCountry, startPayTime, endPayTime, pkVertex);
        if (CollectionUtil.isNotEmpty(memberList)) {
            CurrencyDTO currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry()).getData();
            List<DirectPushNewVo> achieList = memberReportService.directPushNewAchieUpList(dpo, pkMember, orderType);
            Integer finalOrderType = orderType;

            memberList.forEach(itm -> {
                if (null != achieList.get(0)) {
                    itm.setOrderAchieve(achieList.get(0).getOrderAchieve());
                    itm.setOrderAmount(achieList.get(0).getOrderAmount());
                    itm.setOrderAchieve(itm.getOrderAchieve().multiply(currency.getInExchangeRate()));
                    itm.setOrderAmount(itm.getOrderAmount().multiply(currency.getInExchangeRate()));
                    itm.setOrderType(finalOrderType);
                }
            });
        }
        return getDataTable(memberList);
    }


    /**
     * 伞下直推新增业绩导出(历史)
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.DIRECT_PUSH_NEW, method = EOperationMethod.EXPORT)
    @PostMapping("/export-direct-push-new-up")
    public void exportUp(String memberCode, String memberName, Integer pkAwards, Integer pkTeamCode,
                         Date startPayTime, Date endPayTime, Integer pkVertex, Integer orderType,
                         HttpServletResponse response) {
        if (orderType == null) {
            orderType = EOrderUpBusiness.WHOLE.getValue();
        }

        Integer pkCountry = SecurityUtils.getPkCountry();
        Long pkMember;
        if (StringUtils.isNotBlank(memberCode)) {
            CuMember member = iMemberServiceApi.getMember(memberCode).getData();
            if (null != member) {
                pkMember = member.getPkId();
            } else {
                return;
            }
        } else {
            return;
        }

        Date date = DateUtils.currentDate();
        if (DateUtils.compareDate(startPayTime, date) > 0) {
            startPayTime = null;
            endPayTime = null;
        }
        if (StringUtils.isNull(startPayTime) || StringUtils.isNull(endPayTime)) {
            //当前月的第一天
            startPayTime = DateUtils.currentMonthFirstDate();
            endPayTime = date;
        }

        //开始时间减一天
        String startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.beforeDate(1, ChronoUnit.DAYS, startPayTime));
        String endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endPayTime);
        DirectPushNewVo dpo = new DirectPushNewVo();
        dpo.setPkCountry(pkCountry);
        //查询最新期数
        dpo.setPeriodSta(iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(
                DateUtils.parseDateToStr(startDateStr)).getPkId());
        dpo.setPeriodEnd(iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(
                DateUtils.parseDateToStr(endDateStr)).getPkId());
        dpo.setAchieveTableNameSta(TableNameConstants.CU_MEMBER_ACHIEVE + DateUtils.getMonth(startDateStr));
        dpo.setAchieveTableNameEnd(TableNameConstants.CU_MEMBER_ACHIEVE + DateUtils.getMonth(endDateStr));
        dpo.setSettleTableNameSta(TableNameConstants.CU_MEMBER_TREE + DateUtils.getMonth(startDateStr));
        dpo.setSettleTableNameEnd(TableNameConstants.CU_MEMBER_TREE + DateUtils.getMonth(endDateStr));
        //伞下直推新增业绩
        List<DirectPushNewVo> memberList = memberReportService.directPushNewList(pkMember, memberName, pkAwards, pkTeamCode, pkCountry, startPayTime, endPayTime, pkVertex);
        if (CollectionUtil.isNotEmpty(memberList)) {
            CurrencyDTO currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry()).getData();
            List<DirectPushNewVo> achieList = memberReportService.directPushNewAchieUpList(dpo, pkMember, orderType);
            Integer finalOrderType = orderType;
            Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(EOrderUpBusiness.values());

            memberList.forEach(itm -> {
                if (null != achieList.get(0)) {
                    itm.setOrderAchieve(achieList.get(0).getOrderAchieve());
                    itm.setOrderAmount(achieList.get(0).getOrderAmount());
                    itm.setOrderAchieve(itm.getOrderAchieve().multiply(currency.getInExchangeRate()));
                    itm.setOrderAmount(itm.getOrderAmount().multiply(currency.getInExchangeRate()));
                    itm.setOrderTypeVal(transactionMap.get(EnumsPrefixConstants.ORDER_UP_BUSINESS + finalOrderType));
                }
            });
        }
        ExcelUtil<DirectPushNewVo> util = new ExcelUtil<>(DirectPushNewVo.class);
        util.exportExcel(response, memberList, "伞下直推新增业绩导出");
    }

    /**
     * 用户消费统计
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.MEMBER_CONSUMPTION, method = EOperationMethod.SELECT)
    @GetMapping("/member-consumption")
    public TableDataInfo memberConsumptionList(String memberCode, String memberName, Date startPayTime, Date endPayTime, Integer pkWares) {
        startPage();
        List<MemberConsumptionVo> memberReportList = memberReportService.memberConsumptionList(memberCode, memberName, startPayTime, endPayTime, pkWares);
        return getDataTable(memberReportList);
    }

    /**
     * 用户消费统计导出
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.MEMBER_CONSUMPTION, method = EOperationMethod.EXPORT)
    @PostMapping("/member-consumption-export")
    public void memberConsumptionListExport(MemberConsumptionParam memberConsumptionParam, HttpServletResponse response) {
        List<MemberConsumptionVo> memberReportList = memberReportService.memberConsumptionList(memberConsumptionParam.getMemberCode(), memberConsumptionParam.getMemberName(), memberConsumptionParam.getStartPayTime(), memberConsumptionParam.getEndPayTime(), memberConsumptionParam.getPkWares());
        ExcelUtil<MemberConsumptionVo> util = new ExcelUtil<>(MemberConsumptionVo.class);
        util.exportExcel(response, memberReportList, "用户消费统计导出");
    }

    /**
     * 伞下新增安置业绩 列表
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.MEMBER_RESETTLE_ACHIEVE, method = EOperationMethod.SELECT)
    @GetMapping("/member-resettle-achieve")
    public TableDataInfo memberResettleAchieve(String memberCode, String memberName, Date startPayTime, Date endPayTime, Integer pkVertex, Integer pkTeamCode, Integer orderType, Integer pkAwards) {
        if (StringUtils.isEmpty(memberCode)) {
            return getDataTable(new ArrayList<>());
        }
        if (startPayTime != null) {
            startPayTime = DateUtils.getStartTime(startPayTime);
        }
        if (endPayTime != null) {
            endPayTime = DateUtils.getEndTime(endPayTime);
        }

        CuMember member = iMemberServiceApi.getMember(memberCode).getData();
        if (member == null) {
            return getDataTable(new ArrayList<>());
        }

        Integer pkCountry = SecurityUtils.getPkCountry();
        List<Integer> orderTypeList = EOrderBusiness.getOrderTypeList(orderType);
        List<MemberResettleAchieveVo> memberResettleAchieveList = memberReportService.memberResettleAchieve(member.getPkId(), memberName, startPayTime, endPayTime,
                pkVertex, pkTeamCode, pkCountry, pkAwards, orderTypeList);

        Map<Integer, MemberResettleAchieveVo> memberResettleAchieveMap = memberResettleAchieveList.stream().collect(Collectors.toMap(MemberResettleAchieveVo::getPlaceDept, Function.identity()));
        // 左区新增业绩
        BigDecimal leftNewAddAchieve = memberResettleAchieveMap.get(EPlaceDept.LEFT_DEPT.getValue()).getAchieve();
        // 右区新增业绩
        BigDecimal rightNewAddAchieve = memberResettleAchieveMap.get(EPlaceDept.RIGHT_DEPT.getValue()).getAchieve();
        // 左区新增金额
        BigDecimal leftNewAddAmount = memberResettleAchieveMap.get(EPlaceDept.LEFT_DEPT.getValue()).getAmount();
        // 右区新增金额
        BigDecimal rightNewAddAmount = memberResettleAchieveMap.get(EPlaceDept.RIGHT_DEPT.getValue()).getAmount();

        MemberResettleAchieveVo mr = memberResettleAchieveList.get(0);
        // 查询会员业绩
        MemberResettleAchieveVo memberResettleAchieveVo = new MemberResettleAchieveVo();
        memberResettleAchieveVo.setPkMember(member.getPkId());
        memberResettleAchieveVo.setNationalFlag(mr.getNationalFlag());
        memberResettleAchieveVo.setShortName(mr.getShortName());
        memberResettleAchieveVo.setMemberCode(mr.getMemberCode());
        memberResettleAchieveVo.setMemberName(mr.getMemberName());
        memberResettleAchieveVo.setPhone(mr.getPhone());
        memberResettleAchieveVo.setAwardsName(mr.getAwardsName());
        memberResettleAchieveVo.setVertexName(mr.getVertexName());
        memberResettleAchieveVo.setTeamCodeName(mr.getTeamCodeName());

        CurrencyDTO currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry()).getData();
        BigDecimal inExchangeRate = currency.getInExchangeRate();
        memberResettleAchieveVo.setLeftNewAddAmount(leftNewAddAmount);
        memberResettleAchieveVo.setRightNewAddAmount(rightNewAddAmount);
        memberResettleAchieveVo.setLeftNewAddAchieve(leftNewAddAchieve.multiply(inExchangeRate));
        memberResettleAchieveVo.setRightNewAddAchieve(rightNewAddAchieve.multiply(inExchangeRate));
        memberResettleAchieveVo.setOrderTime(mr.getOrderTime());

        return getDataTable(Collections.singletonList(memberResettleAchieveVo));
    }

    /**
     * 伞下新增安置业绩导出
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.MEMBER_RESETTLE_ACHIEVE, method = EOperationMethod.EXPORT)
    @PostMapping("/member-resettle-achieve-export")
    public void memberResettleAchieveExport(MemberResettleAchieveParam memberResettleAchieveParam, HttpServletResponse response) {
        CuMember member = iMemberServiceApi.getMember(memberResettleAchieveParam.getMemberCode()).getData();
        if (null == member) {
            ExcelUtil<MemberResettleAchieveVo> util = new ExcelUtil<>(MemberResettleAchieveVo.class);
            util.exportExcel(response, Collections.singletonList(new MemberResettleAchieveVo()), "伞下新增安置业绩导出");
        } else {
            if (memberResettleAchieveParam.getStartPayTime() != null) {
                memberResettleAchieveParam.setStartPayTime(DateUtils.getStartTime(memberResettleAchieveParam.getStartPayTime()));
            }
            if (memberResettleAchieveParam.getEndPayTime() != null) {
                memberResettleAchieveParam.setEndPayTime(DateUtils.getEndTime(memberResettleAchieveParam.getEndPayTime()));
            }

            Integer pkCountry = SecurityUtils.getPkCountry();
            List<Integer> orderTypeList = EOrderBusiness.getOrderTypeList(memberResettleAchieveParam.getOrderType());
            List<MemberResettleAchieveVo> memberResettleAchieveList = memberReportService.memberResettleAchieve(member.getPkId(), memberResettleAchieveParam.getMemberName(), memberResettleAchieveParam.getStartPayTime(),
                    memberResettleAchieveParam.getEndPayTime(), memberResettleAchieveParam.getPkVertex(), memberResettleAchieveParam.getPkTeamCode(), pkCountry, memberResettleAchieveParam.getPkAwards(), orderTypeList);
            Map<Integer, MemberResettleAchieveVo> memberResettleAchieveMap = memberResettleAchieveList.stream().collect(Collectors.toMap(MemberResettleAchieveVo::getPlaceDept, Function.identity()));

            // 左区新增业绩
            BigDecimal leftNewAddAchieve = memberResettleAchieveMap.get(EPlaceDept.LEFT_DEPT.getValue()).getAchieve();
            // 右区新增业绩
            BigDecimal rightNewAddAchieve = memberResettleAchieveMap.get(EPlaceDept.RIGHT_DEPT.getValue()).getAchieve();
            // 左区新增金额
            BigDecimal leftNewAddAmount = memberResettleAchieveMap.get(EPlaceDept.LEFT_DEPT.getValue()).getAmount();
            // 右区新增金额
            BigDecimal rightNewAddAmount = memberResettleAchieveMap.get(EPlaceDept.RIGHT_DEPT.getValue()).getAmount();
            MemberResettleAchieveVo mr = memberResettleAchieveList.get(0);
            // 查询会员业绩
            MemberResettleAchieveVo memberResettleAchieveVo = new MemberResettleAchieveVo();
            memberResettleAchieveVo.setPkMember(member.getPkId());
            memberResettleAchieveVo.setNationalFlag(mr.getNationalFlag());
            memberResettleAchieveVo.setShortName(mr.getShortName());
            memberResettleAchieveVo.setMemberCode(mr.getMemberCode());
            memberResettleAchieveVo.setMemberName(mr.getMemberName());
            memberResettleAchieveVo.setPhone(mr.getPhone());
            memberResettleAchieveVo.setAwardsName(mr.getAwardsName());
            memberResettleAchieveVo.setVertexName(mr.getVertexName());
            memberResettleAchieveVo.setTeamCodeName(mr.getTeamCodeName());

            CurrencyDTO currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry()).getData();
            BigDecimal inExchangeRate = currency.getInExchangeRate();
            memberResettleAchieveVo.setLeftNewAddAmount(leftNewAddAmount);
            memberResettleAchieveVo.setRightNewAddAmount(rightNewAddAmount);
            memberResettleAchieveVo.setLeftNewAddAchieve(leftNewAddAchieve.multiply(inExchangeRate));
            memberResettleAchieveVo.setRightNewAddAchieve(rightNewAddAchieve.multiply(inExchangeRate));
            memberResettleAchieveVo.setOrderTime(mr.getOrderTime());
            ExcelUtil<MemberResettleAchieveVo> util = new ExcelUtil<>(MemberResettleAchieveVo.class);
            util.exportExcel(response, Collections.singletonList(memberResettleAchieveVo), "伞下新增安置业绩导出");
        }
    }

    /**
     * 伞下新增安置业绩列表（历史）
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.MEMBER_RESETTLE_ACHIEVE, method = EOperationMethod.SELECT)
    @GetMapping("/member-resettle-achieve_up")
    public TableDataInfo memberResettleAchieveUp(String memberCode, String memberName, Date startPayTime, Date endPayTime,
                                                 Integer pkVertex, Integer pkTeamCode, Integer orderType, Integer pkAwards) {
        if (startPayTime == null || endPayTime == null) {
            return getDataTable(new ArrayList<>());
        }

        Date date = new Date();
        String startDateStr = "";
        String endDateStr = "";
        if (DateUtils.compareDate(startPayTime, date) > 0) {
            startPayTime = date;
            startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startPayTime);
            startDateStr = DateUtils.beforeDateStr(2, ChronoUnit.DAYS, DateUtils.YYYY_MM_DD, startDateStr);
        } else {
            startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startPayTime);
            startDateStr = DateUtils.beforeDateStr(1, ChronoUnit.DAYS, DateUtils.YYYY_MM_DD, startDateStr);
        }
        if (DateUtils.compareDate(endPayTime, date) > 0) {
            endPayTime = date;
            endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endPayTime);
            endDateStr = DateUtils.beforeDateStr(1, ChronoUnit.DAYS, DateUtils.YYYY_MM_DD, endDateStr);
        } else {
            endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endPayTime);
        }

        if (StringUtils.isEmpty(memberCode)) {
            return getDataTable(new ArrayList<>());
        }
        CuMember member = iMemberServiceApi.getMemberByCode(memberCode).getData();
        if (null == member) {
            return getDataTable(new ArrayList<>());
        }

        Integer pkCountry = SecurityUtils.getPkCountry();

        List<MemberResettleAchieveVo> memberResettleAchieveList = new ArrayList<>();

        //查询最新期数
        int staPeriod = iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(
                DateUtils.parseDateToStr(startDateStr)).getPkId();
        int endPeriod = iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(
                DateUtils.parseDateToStr(endDateStr)).getPkId();

        String staAchieveTableName = TableNameConstants.CU_MEMBER_ACHIEVE + DateUtils.getMonth(startDateStr);
        String endAchieveTableName = TableNameConstants.CU_MEMBER_ACHIEVE + DateUtils.getMonth(endDateStr);

        List<MemberResettleAchieveVo> staAchieveList = memberReportService.selectBrollyNewABAchieve(member.getPkId(), memberName, startPayTime, endPayTime,
                pkVertex, pkTeamCode, pkCountry, pkAwards, staAchieveTableName, staPeriod);
        List<MemberResettleAchieveVo> endAchieveList = memberReportService.selectBrollyNewABAchieve(member.getPkId(), memberName, startPayTime, endPayTime,
                pkVertex, pkTeamCode, pkCountry, pkAwards, endAchieveTableName, endPeriod);

        if (CollectionUtil.isNotEmpty(staAchieveList) && CollectionUtil.isNotEmpty(endAchieveList)) {
            CurrencyDTO currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry()).getData();
            BigDecimal inExchangeRate = currency.getInExchangeRate();

            for (MemberResettleAchieveVo end : endAchieveList) {
                for (MemberResettleAchieveVo sta : staAchieveList) {
                    if (end.getPkMember().equals(sta.getPkMember())) {
                        end.setLeftNewAddAmount(end.getASumAmount().subtract(sta.getASumAmount()));
                        end.setRightNewAddAmount(end.getBSumAmount().subtract(sta.getBSumAmount()));
                        end.setLeftNewAddAchieve(end.getASumPv().subtract(sta.getASumPv()));
                        end.setRightNewAddAchieve(end.getBSumPv().subtract(sta.getBSumPv()));
                        end.setLeftNewAddAmount(end.getLeftNewAddAmount().multiply(inExchangeRate));
                        end.setRightNewAddAmount(end.getRightNewAddAmount().multiply(inExchangeRate));
                        end.setLeftNewAddAchieve(end.getLeftNewAddAchieve().multiply(inExchangeRate));
                        end.setRightNewAddAchieve(end.getRightNewAddAchieve().multiply(inExchangeRate));
                    }
                }
                memberResettleAchieveList.add(end);
            }
        }
        return getDataTable(memberResettleAchieveList);
    }

    /**
     * 导出伞下新增安置业绩列表
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.MEMBER_RESETTLE_ACHIEVE, method = EOperationMethod.EXPORT)
    @PostMapping("/member-resettle-achieve_up_export")
    public void memberResettleAchieveUpExport(HttpServletResponse response, String memberCode, String memberName, Date startPayTime, Date endPayTime,
                                              Integer pkVertex, Integer pkTeamCode, Integer orderType, Integer pkAwards) {
        if (startPayTime == null || endPayTime == null) {
            return;
        }

        Date date = new Date();
        String startDateStr = "";
        String endDateStr = "";
        if (DateUtils.compareDate(startPayTime, date) > 0) {
            startPayTime = date;
            startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startPayTime);
            startDateStr = DateUtils.beforeDateStr(2, ChronoUnit.DAYS, DateUtils.YYYY_MM_DD, startDateStr);
        } else {
            startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startPayTime);
            startDateStr = DateUtils.beforeDateStr(1, ChronoUnit.DAYS, DateUtils.YYYY_MM_DD, startDateStr);
        }
        if (DateUtils.compareDate(endPayTime, date) > 0) {
            endPayTime = date;
            endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endPayTime);
            endDateStr = DateUtils.beforeDateStr(1, ChronoUnit.DAYS, DateUtils.YYYY_MM_DD, endDateStr);
        } else {
            endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endPayTime);
        }

        if (StringUtils.isEmpty(memberCode)) {
            return;
        }
        CuMember member = iMemberServiceApi.getMemberByCode(memberCode).getData();
        if (null == member) {
            return;
        }

        Integer pkCountry = SecurityUtils.getPkCountry();

        List<MemberResettleAchieveVo> memberResettleAchieveList = new ArrayList<>();

        //查询最新期数
        int staPeriod = iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(
                DateUtils.parseDateToStr(startDateStr)).getPkId();
        int endPeriod = iCuMemberSettlePeriodService.getCuMemberSettlePeriodByDate(
                DateUtils.parseDateToStr(endDateStr)).getPkId();

        String staAchieveTableName = TableNameConstants.CU_MEMBER_ACHIEVE + DateUtils.getMonth(startDateStr);
        String endAchieveTableName = TableNameConstants.CU_MEMBER_ACHIEVE + DateUtils.getMonth(endDateStr);

        List<MemberResettleAchieveVo> staAchieveList = memberReportService.selectBrollyNewABAchieve(member.getPkId(), memberName, startPayTime, endPayTime,
                pkVertex, pkTeamCode, pkCountry, pkAwards, staAchieveTableName, staPeriod);
        List<MemberResettleAchieveVo> endAchieveList = memberReportService.selectBrollyNewABAchieve(member.getPkId(), memberName, startPayTime, endPayTime,
                pkVertex, pkTeamCode, pkCountry, pkAwards, endAchieveTableName, endPeriod);

        if (CollectionUtil.isNotEmpty(staAchieveList) && CollectionUtil.isNotEmpty(endAchieveList)) {
            CurrencyDTO currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry()).getData();
            BigDecimal inExchangeRate = currency.getInExchangeRate();

            for (MemberResettleAchieveVo end : endAchieveList) {
                for (MemberResettleAchieveVo sta : staAchieveList) {
                    if (end.getPkMember().equals(sta.getPkMember())) {
                        end.setLeftNewAddAmount(end.getASumAmount().subtract(sta.getASumAmount()));
                        end.setRightNewAddAmount(end.getBSumAmount().subtract(sta.getBSumAmount()));
                        end.setLeftNewAddAchieve(end.getASumPv().subtract(sta.getASumPv()));
                        end.setRightNewAddAchieve(end.getBSumPv().subtract(sta.getBSumPv()));
                        end.setLeftNewAddAmount(end.getLeftNewAddAmount().multiply(inExchangeRate));
                        end.setRightNewAddAmount(end.getRightNewAddAmount().multiply(inExchangeRate));
                        end.setLeftNewAddAchieve(end.getLeftNewAddAchieve().multiply(inExchangeRate));
                        end.setRightNewAddAchieve(end.getRightNewAddAchieve().multiply(inExchangeRate));
                    }
                }
                memberResettleAchieveList.add(end);
            }
        }
        ExcelUtil<MemberResettleAchieveVo> util = new ExcelUtil<>(MemberResettleAchieveVo.class);
        util.exportExcel(response, memberResettleAchieveList, "伞下新增安置业绩导出");
    }

    /**
     * 订单币种查询
     *
     * @param
     * @return
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.ORDER_CURRENCY_LIST, method = EOperationMethod.SELECT)
    @GetMapping("/order-currency-list")
    public TableDataInfo orderCurrencyList(String memberCode, String memberName, String orderCode, Integer orderType) {
        if (StringUtils.isBlank(memberCode)) {
            return getDataTable(new ArrayList<>());
        }
        startPage();
        List<OrderCurrencyVo> memberResettleAchieveList = memberReportService.getOrderCurrencyList(memberCode, memberName, orderCode, orderType);
        List<String> orderCodeList = memberResettleAchieveList.stream().map(OrderCurrencyVo::getOrderCode).collect(Collectors.toList());
        List<MemberTradeVo> memberTradeVoList = new ArrayList<>();
        if (orderCodeList.size() > 0) {
            memberTradeVoList = memberReportService.getBySourceCodeMemberTradeList(orderCodeList);
        }

        for (OrderCurrencyVo orderCurrencyVo : memberResettleAchieveList) {
            // 现金
            BigDecimal cashAccount = BigDecimal.ZERO;
            // 奖金
            BigDecimal bonusAccount = BigDecimal.ZERO;
            // 消费
            BigDecimal expendAccount = BigDecimal.ZERO;
            // 政策
            BigDecimal policyAccount = BigDecimal.ZERO;
            // 积分账户
            BigDecimal integralAccount = BigDecimal.ZERO;
            EOrderType enumByValue = EOrderType.getEnumByValue(orderCurrencyVo.getOrderType());
            if (enumByValue != null) {
                orderCurrencyVo.setOrderTypeStr(enumByValue.getLabel());
            }
            for (MemberTradeVo memberTradeVo : memberTradeVoList) {
                if (orderCurrencyVo.getOrderCode().equals(memberTradeVo.getSourceCode())) {
                    if (memberTradeVo.getPkAccount().equals(EAccount.CASH.getValue())) {
                        // 现金
                        cashAccount = cashAccount.add(memberTradeVo.getTradeAmount());
                    }
                    if (memberTradeVo.getPkAccount().equals(EAccount.BONUS.getValue())) {
                        // 奖金
                        bonusAccount = bonusAccount.add(memberTradeVo.getTradeAmount());
                    }
                    if (memberTradeVo.getPkAccount().equals(EAccount.CONSUME.getValue())) {
                        // 消费
                        expendAccount = expendAccount.add(memberTradeVo.getTradeAmount());
                    }
                    if (memberTradeVo.getPkAccount().equals(EAccount.POLICY.getValue())) {
                        // 政策
                        policyAccount = policyAccount.add(memberTradeVo.getTradeAmount());
                    }
                    if (memberTradeVo.getPkAccount().equals(EAccount.INTEGRAL.getValue())) {
                        // 积分
                        integralAccount = integralAccount.add(memberTradeVo.getTradeAmount());
                    }
                }
                orderCurrencyVo.setCashAccount(cashAccount);
                orderCurrencyVo.setBonusAccount(bonusAccount);
                orderCurrencyVo.setExpendAccount(expendAccount);
                orderCurrencyVo.setPolicyAccount(policyAccount);
                orderCurrencyVo.setIntegralAccount(integralAccount);
            }
        }
        return getDataTable(memberResettleAchieveList);
    }

    /**
     * 订单分布统计
     *
     * @param
     * @return
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.GET_ORDER_DISTRIBUTION, method = EOperationMethod.SELECT)
    @GetMapping("/get-order-distribution")
    public TableDataInfo getOrderDistribution(Integer area, Date startTime, Date endTime) {
        // area 1=省 2=市 3=区
        if (area == null) {
            return getDataTable(new ArrayList<>());
        }
        Integer pkCountry = SecurityUtils.getPkCountry();
        List<OrderDistribution> orderDistributionList = new ArrayList<>();
        startPage();
        if (area == 1) {
            // 查询省
            orderDistributionList = memberReportService.getByProvinceOrderDistribution(startTime, endTime, pkCountry);
        } else if (area == 2) {
            // 查询市
            orderDistributionList = memberReportService.getByCityOrderDistribution(startTime, endTime, pkCountry);
        } else if (area == 3) {
            // 查询区县
            orderDistributionList = memberReportService.getByDistrictOrderDistribution(startTime, endTime, pkCountry);
        }
        return getDataTable(orderDistributionList);
    }

    /**
     * 出货明细汇总统计
     *
     * @param
     * @return
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PRODUCT_SHIPPING_DETAILS_LIST, method = EOperationMethod.SELECT)
    @GetMapping("/product-shipping-details-list")
    public TableDataInfo productShippingDetailsList(String productName, Integer pkClassify, Date startTime, Date endTime, Integer orderType) {
        startPage();
        Integer pkCountry = SecurityUtils.getPkCountry();
        List<Integer> orderTypeList = EOrderShipment.getOrderTypeList(orderType);
        if (endTime != null) {
            endTime = DateUtils.getEndTime(endTime);
        }
        List<ProductOrderInfoVo> memberReportList = memberReportService.getProductOrderInfo(productName, pkClassify, startTime, endTime, pkCountry, orderTypeList);
        for (ProductOrderInfoVo productOrderInfoVo : memberReportList) {
            if (productOrderInfoVo.getProductPrice() != null) {
                productOrderInfoVo.setProductTotalPrice(productOrderInfoVo.getProductPrice());
            } else {
                productOrderInfoVo.setProductTotalPrice(BigDecimal.ZERO);
            }

            if (productOrderInfoVo.getOrderType() != null) {
                productOrderInfoVo.setOrderTypeStr(EOrderType.getEnumByValue(productOrderInfoVo.getOrderType()).getLabel());
            }
        }
        // 计算总计
        Integer count = memberReportService.sumQuantity(productName, pkClassify, startTime, endTime, pkCountry, orderTypeList);
        ProductOrderInfoVo productOrderInfoVo = new ProductOrderInfoVo();
        productOrderInfoVo.setProductCode("总计");
        productOrderInfoVo.setProductName("-");
        productOrderInfoVo.setQuantity(count);
        productOrderInfoVo.setProductTotalPrice(BigDecimal.ZERO);
        memberReportList.add(productOrderInfoVo);
        return getDataTable(memberReportList);
    }

    /**
     * 出货明细汇总导出
     *
     * @return
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PRODUCT_SHIPPING_DETAILS_LIST, method = EOperationMethod.EXPORT)
    @PostMapping("/product-shipping-details-export")
    public void productShippingDetailsExport(String productName, Integer pkClassify, Date startTime, Date endTime, Integer orderType, HttpServletResponse response) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        List<Integer> orderTypeList = EOrderShipment.getOrderTypeList(orderType);
        if (endTime != null) {
            endTime = DateUtils.getEndTime(endTime);
        }
        List<ProductOrderInfoVo> memberReportList = memberReportService.getProductOrderInfo(productName, pkClassify, startTime, endTime, pkCountry, orderTypeList);
        for (ProductOrderInfoVo productOrderInfoVo : memberReportList) {
            if (productOrderInfoVo.getProductPrice() != null) {
                productOrderInfoVo.setProductTotalPrice(productOrderInfoVo.getProductPrice());
            } else {
                productOrderInfoVo.setProductTotalPrice(BigDecimal.ZERO);
            }
            if (productOrderInfoVo.getOrderType() != null) {
                productOrderInfoVo.setOrderTypeStr(EOrderType.getEnumByValue(productOrderInfoVo.getOrderType()).getLabel());
            }
        }
        ExcelUtil<ProductOrderInfoVo> util = new ExcelUtil<>(ProductOrderInfoVo.class);
        util.exportExcel(response, memberReportList, "出货明细汇总导出");
    }

    /**
     * 出货明细汇总统计详情
     *
     * @param productName
     * @param pkProduct
     * @return
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PRODUCT_SHIPPING_DETAILS_INFO_LIST, method = EOperationMethod.SELECT)
    @GetMapping("/product-shipping-details-info-list")
    public TableDataInfo productShippingDetailsList(String productName, Integer pkProduct, Integer pkClassify, Integer pkAwards, Integer orderType, Date startTime, Date endTime) {
        startPage();
        Integer pkCountry = SecurityUtils.getPkCountry();
        List<Integer> orderTypeList = new ArrayList<>();
        orderTypeList.add(orderType);
        if (endTime != null) {
            endTime = DateUtils.getEndTime(endTime);
        }
        List<ProductShippingDetailsInfoVo> productOrderInfoVoList = memberReportService.productShippingDetailsList(pkProduct, productName, pkClassify, pkAwards, orderTypeList, startTime, endTime, pkCountry);
        for (ProductShippingDetailsInfoVo productShippingDetailsInfoVo : productOrderInfoVoList) {
            productShippingDetailsInfoVo.setAwardsPrice(productShippingDetailsInfoVo.getPrice());
            productShippingDetailsInfoVo.setPriceTotal(productShippingDetailsInfoVo.getPrice().multiply(BigDecimal.valueOf(productShippingDetailsInfoVo.getQuantity())));
        }
        return getDataTable(productOrderInfoVoList);
    }

    /**
     * 出货明细汇总统计详情导出
     *
     * @param
     * @param
     * @return
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PRODUCT_SHIPPING_DETAILS_INFO_LIST, method = EOperationMethod.EXPORT)
    @PostMapping("/product-shipping-details-info-list-export")
    public void productShippingDetailsListExport(ProductShippingDetailsParam productShippingDetailsParam, HttpServletResponse response) {
        startPage();
        Integer pkCountry = SecurityUtils.getPkCountry();
        List<Integer> orderTypeList = new ArrayList<>();
        orderTypeList.add(productShippingDetailsParam.getOrderType());
        if (productShippingDetailsParam.getEndTime() != null) {
            productShippingDetailsParam.setEndTime(productShippingDetailsParam.getEndTime());
        }
        List<ProductShippingDetailsInfoVo> productOrderInfoVoList = memberReportService.productShippingDetailsList(productShippingDetailsParam.getPkProduct(), productShippingDetailsParam.getProductName(), productShippingDetailsParam.getPkClassify(), productShippingDetailsParam.getPkAwards(), orderTypeList, productShippingDetailsParam.getStartTime(), productShippingDetailsParam.getEndTime(), pkCountry);
        for (ProductShippingDetailsInfoVo productShippingDetailsInfoVo : productOrderInfoVoList) {
            productShippingDetailsInfoVo.setAwardsPrice(productShippingDetailsInfoVo.getPrice());
            productShippingDetailsInfoVo.setPriceTotal(productShippingDetailsInfoVo.getPrice().multiply(BigDecimal.valueOf(productShippingDetailsInfoVo.getQuantity())));
        }
        ExcelUtil<ProductShippingDetailsInfoVo> util = new ExcelUtil<>(ProductShippingDetailsInfoVo.class);
        util.exportExcel(response, productOrderInfoVoList, "出货明细汇总统计详情");
    }

    /**
     * 报单汇总
     *
     * @return
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.REPORT_SUMMARY_LIST, method = EOperationMethod.SELECT)
    @GetMapping("/report-summary-list")
    public TableDataInfo reportSummaryList(ReportSummaryVo reportSummaryVo) {
        if (null != reportSummaryVo.getEndCreateTime()) {
            // 补全23:59:59
            reportSummaryVo.setEndCreateTime(DateUtils.getEndTime(reportSummaryVo.getEndCreateTime()));
        }
        R<CurrencyDTO> currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
        startPage();
        reportSummaryVo.setPkCountry(SecurityUtils.getPkCountry());
        List<ReportSummaryVo> reportSummaryList = memberReportService.reportSummaryList(reportSummaryVo);
        for (ReportSummaryVo summaryVo : reportSummaryList) {
            if (summaryVo.getRegisterAuthority() != null) {
                summaryVo.setRegisterName(ERegistrationAuthority.getEnumByValue(summaryVo.getRegisterAuthority()).getLabel());
            }
            if (SecurityUtils.getPkCountry().equals(CountryConstants.CHINA_COUNTRY)) {
                summaryVo.setConsumeAchieve(summaryVo.getConsumeAchieve().multiply(currency.getData().getInExchangeRate()));
            } else {
                summaryVo.setConsumeAchieve(summaryVo.getConsumeAchieve());
            }

        }
        return getDataTable(reportSummaryList);
    }

    /**
     * 报单汇总
     *
     * @return
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.REPORT_SUMMARY_LIST, method = EOperationMethod.EXPORT)
    @PostMapping("/report-summary-list-export")
    public void reportSummaryListExport(ReportSummaryVo reportSummaryVo, HttpServletResponse response) {
        if (null != reportSummaryVo.getEndCreateTime()) {
            // 补全23:59:59
            reportSummaryVo.setEndCreateTime(DateUtils.getEndTime(reportSummaryVo.getEndCreateTime()));
        }
        R<CurrencyDTO> currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
        reportSummaryVo.setPkCountry(SecurityUtils.getPkCountry());
        List<ReportSummaryVo> reportSummaryList = memberReportService.reportSummaryList(reportSummaryVo);
        for (ReportSummaryVo summaryVo : reportSummaryList) {
            if (summaryVo.getRegisterAuthority() != null) {
                summaryVo.setRegisterName(ERegistrationAuthority.getEnumByValue(summaryVo.getRegisterAuthority()).getLabel());
            }
            if (SecurityUtils.getPkCountry().equals(CountryConstants.CHINA_COUNTRY)) {
                summaryVo.setConsumeAchieve(summaryVo.getConsumeAchieve().multiply(currency.getData().getInExchangeRate()));
            } else {
                summaryVo.setConsumeAchieve(summaryVo.getConsumeAchieve());
            }
        }
        ExcelUtil<ReportSummaryVo> util = new ExcelUtil<>(ReportSummaryVo.class);
        util.exportExcel(response, reportSummaryList, "报单汇总导出");
    }

    /*
     *  安置反查
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PLACE_PEG, method = EOperationMethod.SELECT)
    @PostMapping("/place-peg")
    public TableDataInfo memberPlacePeg(@RequestBody CuMemberUmbrellaParam cuMemberUmbrellaParam) {
        List<CuMemberPushAchieveVO> cuMemberPushAchieveVOList = new ArrayList<>();
        if (StringUtils.isNotEmpty(cuMemberUmbrellaParam.getMemberCode())) {
            if (null != cuMemberUmbrellaParam.getUpDown() &&
                    EUpDown.UP.getValue() == cuMemberUmbrellaParam.getUpDown()) {
                // 反查，没有安置部门
                cuMemberUmbrellaParam.setPlaceDept(null);
            }

            startPage();
            List<CuMemberAchieveExt> cuMemberAchieveExtList = iMemberService.queryPlaceCuMemberAchieveExt(cuMemberUmbrellaParam);
            if (CollectionUtil.isNotEmpty(cuMemberAchieveExtList)) {
                R<CurrencyDTO> currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
                for (CuMemberAchieveExt cuMemberAchieveExt : cuMemberAchieveExtList) {
                    CuMemberPushAchieveVO vo = BeanUtil.copyProperties(cuMemberAchieveExt, CuMemberPushAchieveVO.class);
                    vo.setPlaceDeptVal(EPlaceDept.getEPlaceDept(cuMemberAchieveExt.getPlaceDept()));
                    vo.setCategoryVal(ECategory.getLabelByValue(cuMemberAchieveExt.getCategory()));
                    vo.setABalance(cuMemberAchieveExt.getABalance().multiply(currency.getData().getInExchangeRate()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    vo.setBBalance(cuMemberAchieveExt.getBBalance().multiply(currency.getData().getInExchangeRate()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    cuMemberPushAchieveVOList.add(vo);
                }
            }

            TableDataInfo tableDataInfo = getDataTable(cuMemberAchieveExtList);
            tableDataInfo.setRows(cuMemberPushAchieveVOList);
            return tableDataInfo;
        }
        return getDataTable(cuMemberPushAchieveVOList);
    }

    /**
     * 导出安置反查
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PLACE_PEG, method = EOperationMethod.EXPORT)
    @PostMapping("/export-place-peg")
    public void exportPlacePeg(HttpServletResponse response, CuMemberUmbrellaParam cuMemberUmbrellaParam) {
        List<CuMemberPushAchieveVO> cuMemberPushAchieveVOList = new ArrayList<>();

        if (StringUtils.isNotEmpty(cuMemberUmbrellaParam.getMemberCode())) {
            if (null != cuMemberUmbrellaParam.getUpDown() &&
                    EUpDown.UP.getValue() == cuMemberUmbrellaParam.getUpDown()) {
                // 反查，没有安置部门
                cuMemberUmbrellaParam.setPlaceDept(null);
            }

            List<CuMemberAchieveExt> cuMemberAchieveExtList = iMemberService.queryPlaceCuMemberAchieveExt(cuMemberUmbrellaParam);
            if (CollectionUtil.isNotEmpty(cuMemberAchieveExtList)) {
                R<CurrencyDTO> currency = iCurrencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
                for (CuMemberAchieveExt cuMemberAchieveExt : cuMemberAchieveExtList) {
                    CuMemberPushAchieveVO vo = BeanUtil.copyProperties(cuMemberAchieveExt, CuMemberPushAchieveVO.class);
                    vo.setPlaceDeptVal(EPlaceDept.getEPlaceDept(cuMemberAchieveExt.getPlaceDept()));
                    vo.setCategoryVal(ECategory.getLabelByValue(cuMemberAchieveExt.getCategory()));
                    vo.setABalance(cuMemberAchieveExt.getABalance().multiply(currency.getData().getInExchangeRate()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    vo.setBBalance(cuMemberAchieveExt.getBBalance().multiply(currency.getData().getInExchangeRate()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    cuMemberPushAchieveVOList.add(vo);
                }
            }
        }
        ExcelUtil<CuMemberPushAchieveVO> util = new ExcelUtil<>(CuMemberPushAchieveVO.class);
        util.exportExcel(response, cuMemberPushAchieveVOList, "安置反查");
    }

    /*
     *  推荐反查
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PARENT_PEG, method = EOperationMethod.SELECT)
    @PostMapping("/parent-peg")
    public TableDataInfo memberParentPeg(@RequestBody CuMemberUmbrellaParam cuMemberUmbrellaParam) {
        List<CuMemberPushAchieveVO> cuMemberPushAchieveVOList = new ArrayList<>();
        if (StringUtils.isNotEmpty(cuMemberUmbrellaParam.getMemberCode())) {
            startPage();
            List<CuMemberAchieveExt> cuMemberAchieveExtList = iMemberService.queryParentCuMemberAchieveExt(cuMemberUmbrellaParam);
            if (CollectionUtil.isNotEmpty(cuMemberAchieveExtList)) {
                for (CuMemberAchieveExt cuMemberAchieveExt : cuMemberAchieveExtList) {
                    CuMemberPushAchieveVO vo = BeanUtil.copyProperties(cuMemberAchieveExt, CuMemberPushAchieveVO.class);
                    vo.setPlaceDeptVal(EPlaceDept.getEPlaceDept(cuMemberAchieveExt.getPlaceDept()));
                    vo.setCategoryVal(ECategory.getLabelByValue(cuMemberAchieveExt.getCategory()));
                    cuMemberPushAchieveVOList.add(vo);
                }
            }
            TableDataInfo tableDataInfo = getDataTable(cuMemberAchieveExtList);
            tableDataInfo.setRows(cuMemberPushAchieveVOList);
            return tableDataInfo;
        }
        return getDataTable(cuMemberPushAchieveVOList);
    }

    /**
     * 导出推荐反查
     **/
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PARENT_PEG, method = EOperationMethod.EXPORT)
    @PostMapping("/export-parent-peg")
    public void exportParentPeg(HttpServletResponse response, CuMemberUmbrellaParam cuMemberUmbrellaParam) {
        List<CuMemberPushAchieveVO> cuMemberPushAchieveVOList = new ArrayList<>();

        if (StringUtils.isNotEmpty(cuMemberUmbrellaParam.getMemberCode())) {
            List<CuMemberAchieveExt> cuMemberAchieveExtList = iMemberService.queryParentCuMemberAchieveExt(cuMemberUmbrellaParam);
            if (CollectionUtil.isNotEmpty(cuMemberAchieveExtList)) {
                for (CuMemberAchieveExt cuMemberAchieveExt : cuMemberAchieveExtList) {
                    CuMemberPushAchieveVO vo = BeanUtil.copyProperties(cuMemberAchieveExt, CuMemberPushAchieveVO.class);
                    vo.setPlaceDeptVal(EPlaceDept.getEPlaceDept(cuMemberAchieveExt.getPlaceDept()));
                    vo.setCategoryVal(ECategory.getLabelByValue(cuMemberAchieveExt.getCategory()));
                    cuMemberPushAchieveVOList.add(vo);
                }
            }
        }
        ExcelUtil<CuMemberPushAchieveVO> util = new ExcelUtil<>(CuMemberPushAchieveVO.class);
        util.exportExcel(response, cuMemberPushAchieveVOList, "推荐反查");
    }

    /**
     * 产品明细查询
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PRODUCT_DETAIL_QUERY_LIST, method = EOperationMethod.SELECT)
    @GetMapping("/product-detail-query-list")
    public TableDataInfo productDetailQuery(ProductDetailQueryParam productDetailQueryParam) {
        if (productDetailQueryParam.getStartPayTime() != null) {
            productDetailQueryParam.setStartPayTime(DateUtils.getStartTime(productDetailQueryParam.getStartPayTime()));
        }
        if (productDetailQueryParam.getEndPayTime() != null) {
            productDetailQueryParam.setEndPayTime(DateUtils.getEndTime(productDetailQueryParam.getEndPayTime()));
        }

        R<Map<Integer, String>> areaMap = iAreaServiceApi.getAreaMap(SecurityUtils.getPkCountry());
        Map<Integer, String> map = areaMap.getData();
        startPage();
        List<Integer> orderTypeList = EOrderShipment.getOrderTypeList(productDetailQueryParam.getOrderType());
        productDetailQueryParam.setOrderTypeList(orderTypeList);
        productDetailQueryParam.setPkCountry(SecurityUtils.getPkCountry());
        List<ProductDetailQueryVo> productDetailList = memberReportService.productDetailQueryList(productDetailQueryParam);
        for (ProductDetailQueryVo productDetailQueryVo : productDetailList) {
            if (productDetailQueryVo.getPayType() != null) {
                EPayType payType = EPayType.getEnumByValue(productDetailQueryVo.getPayType());
                // 支付类型
                if (payType != null) {
                    productDetailQueryVo.setPayTypeStr(payType.getLabel());
                }
            }
            if (productDetailQueryVo.getOrderType() != null) {
                EOrderType orderType = EOrderType.getEnumByValue(productDetailQueryVo.getOrderType());
                // 订单类型
                if (orderType != null) {
                    productDetailQueryVo.setOrderTypeVal(orderType.getLabel());
                }
            }
            // 发货方式
            if (productDetailQueryVo.getDeliveryWay() != null) {
                EDelivery delivery = EDelivery.getDelivery(productDetailQueryVo.getDeliveryWay());
                if (delivery != null) {
                    productDetailQueryVo.setDeliveryWayVal(delivery.getLabel());
                }
            }
            productDetailQueryVo.setRecProvinceVal(map.get(productDetailQueryVo.getRecProvince()));
            productDetailQueryVo.setRecCityVal(map.get(productDetailQueryVo.getRecCity()));
            productDetailQueryVo.setRecCountyVal(map.get(productDetailQueryVo.getRecCounty()));

            // 产品名称
            productDetailQueryVo.setProductName(productDetailQueryVo.getProductName());
            // 产品总价
            productDetailQueryVo.setPriceTotal(productDetailQueryVo.getPrice().multiply(BigDecimal.valueOf(productDetailQueryVo.getQuantity())));
            // 订单编号
            productDetailQueryVo.setOrderCode(productDetailQueryVo.getOrderCode());
            // 创建日期
            productDetailQueryVo.setCreateTime(productDetailQueryVo.getCreateTime());
        }
        return getDataTable(productDetailList);
    }

    /**
     * 产品明细查询导出
     */
    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.PRODUCT_DETAIL_QUERY_LIST, method = EOperationMethod.EXPORT)
    @PostMapping("/product-detail-query-list-export")
    public void productDetailQueryExport(ProductDetailQueryParam productDetailQueryParam, HttpServletResponse response) {
        R<Map<Integer, String>> areaMap = iAreaServiceApi.getAreaMap(SecurityUtils.getPkCountry());
        Map<Integer, String> map = areaMap.getData();
        if (productDetailQueryParam.getStartPayTime() != null) {
            productDetailQueryParam.setStartPayTime(DateUtils.getStartTime(productDetailQueryParam.getStartPayTime()));
        }
        if (productDetailQueryParam.getEndPayTime() != null) {
            productDetailQueryParam.setEndPayTime(DateUtils.getEndTime(productDetailQueryParam.getEndPayTime()));
        }
        List<Integer> orderTypeList = EOrderShipment.getOrderTypeList(productDetailQueryParam.getOrderType());
        productDetailQueryParam.setOrderTypeList(orderTypeList);
        productDetailQueryParam.setPkCountry(SecurityUtils.getPkCountry());
        List<ProductDetailQueryVo> productDetailList = memberReportService.productDetailQueryList(productDetailQueryParam);
        for (ProductDetailQueryVo productDetailQueryVo : productDetailList) {
            if (productDetailQueryVo.getPayType() != null) {
                EPayType payType = EPayType.getEnumByValue(productDetailQueryVo.getPayType());
                // 支付类型
                if (payType != null) {
                    productDetailQueryVo.setPayTypeStr(payType.getLabel());
                }
            }
            if (productDetailQueryVo.getOrderType() != null) {
                EOrderType orderType = EOrderType.getEnumByValue(productDetailQueryVo.getOrderType());
                // 订单类型
                if (orderType != null) {
                    productDetailQueryVo.setOrderTypeVal(orderType.getLabel());
                }
            }
            // 发货方式
            if (productDetailQueryVo.getDeliveryWay() != null) {
                EDelivery delivery = EDelivery.getDelivery(productDetailQueryVo.getDeliveryWay());
                if (delivery != null) {
                    productDetailQueryVo.setDeliveryWayVal(delivery.getLabel());
                }
            }
            productDetailQueryVo.setRecProvinceVal(map.get(productDetailQueryVo.getRecProvince()));
            productDetailQueryVo.setRecCityVal(map.get(productDetailQueryVo.getRecCity()));
            productDetailQueryVo.setRecCountyVal(map.get(productDetailQueryVo.getRecCounty()));

            // 产品名称
            productDetailQueryVo.setProductName(productDetailQueryVo.getProductName());
            // 产品总价
            productDetailQueryVo.setPriceTotal(productDetailQueryVo.getPrice().multiply(BigDecimal.valueOf(productDetailQueryVo.getQuantity())));
            // 订单编号
            productDetailQueryVo.setOrderCode(productDetailQueryVo.getOrderCode());
            // 创建日期
            productDetailQueryVo.setCreateTime(productDetailQueryVo.getCreateTime());
        }
        ExcelUtil<ProductDetailQueryVo> util = new ExcelUtil<>(ProductDetailQueryVo.class);
        util.exportExcel(response, productDetailList, "产品明细查询");
    }
}
