package com.hzs.report.member.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.enums.*;
import com.hzs.report.member.mapper.CuMemberAwardsStatMapper;
import com.hzs.report.member.service.ICuMemberAwardsStatService;
import com.hzs.report.member.vo.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 会员信息-奖衔升级记录 服务实现类
 *
 * @author hzs
 * @since 2022-08-31
 */
@Service
public class CuMemberAwardsStatServiceImpl implements ICuMemberAwardsStatService {

    @Autowired
    private CuMemberAwardsStatMapper memberAwardsStatMapper;

    /**
     * @description: 真实业绩新增奖衔查询
     * @author: zhang jing
     * @date: 2023/8/24 17:56
     * @param: [cuMemberAwardsVO]
     * @return: java.util.List<com.hzs.member.detail.vo.CuMemberAwardsVO>
     **/
    @Override
    public List<CuMemberAwardsStatVO> selectCuMemberAwardsList(CuMemberAwardsStatVO cuMemberAwardsStatVO) {
        return memberAwardsStatMapper.selectCuMemberAwardsList(cuMemberAwardsStatVO);
    }

    /**
     * @description: 奖衔晋升列表
     * @author: zhang jing
     * @date: 2024/1/2 10:37
     * @param: [awardPromotionVO]
     * @return: java.util.List<com.hzs.report.member.vo.AwardPromotionVO>
     **/
    @Override
    public List<AwardPromotionVO> awardPromotionList(AwardPromotionVO awardPromotionVO) {
        return memberAwardsStatMapper.awardPromotionList(awardPromotionVO);
    }

    /**
     * @description: 会员业绩数据查询
     * @author: zhang jing
     * @date: 2024/1/4 14:32
     * @param: [memberAchieveVO]
     * @return: java.util.List<com.hzs.report.member.vo.MemberAchieveVO>
     **/
    @Override
    public List<MemberAchieveVO> memberAchieveList(MemberAchieveVO memberAchieveVO) {
        return memberAwardsStatMapper.memberAchieveList(memberAchieveVO);
    }


    /**
     * @description: 个人统计
     * @author: zhang jing
     * @date: 2023/9/1 10:37
     * @param: [personStatVO]
     * @return: java.util.List<com.hzs.report.member.vo.PersonStatVO>
     **/
    @Override
    public List<PersonStatVO> selectPersonStatList(PersonStatVO personStatVO) {
        return memberAwardsStatMapper.selectPersonStatList(personStatVO);
    }

    /**
     * @description: 真实奖衔分析
     * @author: zhang jing
     * @date: 2023/8/26 16:01
     * @param: [cuMemberAwardsAnalysisVO]
     * @return: java.util.List<com.hzs.report.member.vo.CuMemberAwardsAnalysisVO>
     **/
    @Override
    public List<CuMemberAwardsAnalysisVO> selectCuMemberAwardsAnalysisList(CuMemberAwardsAnalysisVO cuMemberAwardsAnalysisVO) {
        return memberAwardsStatMapper.selectCuMemberAwardsAnalysisList(cuMemberAwardsAnalysisVO);
    }

    /**
     * @description: 查询会员结算等级升级记录
     * @author: zhang jing
     * @date: 2025/3/3 16:01
     * @param: [cuMemberGradeRecordVO]
     * @return: java.util.List<com.hzs.report.member.vo.CuMemberGradeRecordVO>
     **/
    @Override
    public List<CuMemberGradeRecordVO> querMemberGradeRecordList(CuMemberGradeRecordVO cuMemberGradeRecordVO) {
        return memberAwardsStatMapper.querMemberGradeRecordList(cuMemberGradeRecordVO);
    }

    /**
     * @description: 查询会员左右区累计真实业绩
     * @author: zhang jing
     * @date: 2024/8/20 10:00
     * @param: [cuMemberAwardsAnalysisVO]
     * @return: java.util.List<com.hzs.report.member.vo.CuMemberAwardsAnalysisVO>
     **/
    @Override
    public List<CuMemberAwardsAnalysisVO> selectAwardsAnalysisList(List<CuMemberAwardsAnalysisVO> list) {
        return memberAwardsStatMapper.selectAwardsAnalysisList(list);
    }

    /**
     * @description: 查询全部伞下血缘业绩
     * @author: zhang jing
     * @date: 2023/10/14 16:05
     * @param: [bloodList]
     * @return: java.util.List<com.hzs.report.member.vo.BloodRemoveSameVO>
     **/
    @Override
    public List<BloodRemoveSameVO> bloodRemoveSameAllList(BloodRemoveSameVO bloodList,
                                                          String startDate, String endDate,
                                                          List<Integer> orderTypeList,
                                                          List<Integer> pkAwardsList
    ) {
        return memberAwardsStatMapper.bloodRemoveSameAllList(bloodList, startDate, endDate, orderTypeList, pkAwardsList);
    }

    /**
     * @description: 查询会员推荐伞下业绩(历史)
     * @author: zhang jing
     * @date: 2024/5/15 14:03
     * @param: [bloodList, periodEnd, periodSta, achieveTableNameEnd, achieveTableNameSta, settleTableNameSta, settleTableNameEnd, orderType]
     * @return: java.util.List<com.hzs.report.member.vo.BloodRemoveSameVO>
     **/
    @Override
    public List<BloodRemoveSameVO> bloodSameAllListHistory(List<BloodRemoveSameVO> bloodList,
                                                           Integer periodEnd,
                                                           Integer periodSta,
                                                           String achieveTableNameEnd,
                                                           String achieveTableNameSta,
                                                           String settleTableNameSta,
                                                           String settleTableNameEnd,
                                                           Integer orderType

    ) {
        return memberAwardsStatMapper.bloodSameAllListHistory(bloodList, periodEnd, periodSta, achieveTableNameEnd,
                achieveTableNameSta, settleTableNameSta, settleTableNameEnd, orderType);
    }

    /**
     * @description: 伞下去重业绩查询（新）
     * @author: zhang jing
     * @date: 2024/5/23 14:50
     * @param: [bloodList, periodEnd, periodSta, achieveTableNameEnd, achieveTableNameSta, settleTableNameSta, settleTableNameEnd, orderType, pkCountry, pkAwardsList]
     * @return: java.util.List<com.hzs.report.member.vo.BloodRemoveSameVO>
     **/
    @Override
    public List<BloodRemoveSameVO> bloodRemoveSameMemberAchieveNew(List<BloodRemoveSameVO> bloodList,
                                                                   Integer periodEnd,
                                                                   Integer periodSta,
                                                                   String achieveTableNameEnd,
                                                                   String achieveTableNameSta,
                                                                   String settleTableNameSta,
                                                                   String settleTableNameEnd,
                                                                   Integer orderType,
                                                                   Integer pkCountry, List<Integer> pkAwardsList

    ) {
        return memberAwardsStatMapper.bloodRemoveSameMemberAchieveNew(bloodList, periodEnd, periodSta, achieveTableNameEnd,
                achieveTableNameSta, settleTableNameSta, settleTableNameEnd, orderType, pkCountry, pkAwardsList);
    }


    /**
     * @description: 根据奖衔查询所有会员
     * @author: zhang jing
     * @date: 2023/10/11 14:05
     * @param: [bloodRemoveSameVO]
     * @return: java.util.List<com.hzs.report.member.vo.BloodRemoveSameVO>
     **/
    @Override
    public List<BloodRemoveSameVO> queryAwardAchieList(BloodRemoveSameVO bloodRemoveSameVO) {
        return memberAwardsStatMapper.queryAwardAchieList(bloodRemoveSameVO);
    }

    /**
     * @description: 根据奖衔查询会员（历史）
     * @author: zhang jing
     * @date: 2024/5/17 14:15
     * @param: [bloodRemoveSameVO]
     * @return: java.util.List<com.hzs.report.member.vo.BloodRemoveSameVO>
     **/
    @Override
    public List<BloodRemoveSameVO> queryAwardAchieListHistory(BloodRemoveSameVO bloodRemoveSameVO) {
        return memberAwardsStatMapper.queryAwardAchieListHistory(bloodRemoveSameVO);
    }


    /**
     * @description: 真实奖衔分析详情（穿透页面接口）
     * @author: zhang jing
     * @date: 2023/9/26 14:27
     * @param: [cuMemberAwardsAnalysisVO]
     * @return: java.util.List<com.hzs.report.member.vo.CuMemberAwardsAnalysisVO>
     **/
    @Override
    public List<CuMemberAwardsAnalysisVO> selectCuMemberAwardsAnalysisDetailsList(CuMemberAwardsAnalysisVO cuMemberAwardsAnalysisVO) {
        return memberAwardsStatMapper.selectCuMemberAwardsAnalysisDetailsList(cuMemberAwardsAnalysisVO);
    }

    /**
     * @description: 收入明细
     * @author: zhang jing
     * @date: 2023/9/26 15:07
     * @param: [revenueDetailsVO]
     * @return: java.util.List<com.hzs.report.member.vo.RevenueDetailsVO>
     **/
    @Override
    public List<RevenueDetailsVO> selectRevenueDetailsList(RevenueDetailsVO revenueDetailsVO) {
        return memberAwardsStatMapper.selectRevenueDetailsList(revenueDetailsVO);
    }

    /**
     * @description: 复购bv统计
     * @author: zhang jing
     * @date: 2023/8/29 15:31
     * @param: [repurchasePVStatVO]
     * @return: java.util.List<com.hzs.report.member.vo.RepurchasePVStatVO>
     **/
    @Override
    public List<RepurchasePVStatVO> selectRepurchasePVStatList(RepurchasePVStatVO repurchasePVStatVO) {
        return memberAwardsStatMapper.selectRepurchasePVStatList(repurchasePVStatVO);
    }

    /**
     * @description: 商城BV统计
     * @author: zhang jing
     * @date: 2023/8/30 10:54
     * @param: [mallPVStatVO]
     * @return: java.util.List<com.hzs.report.member.vo.RepurchasePVStatVO>
     **/
    @Override
    public List<MallPVStatVO> selectMallPVStatList(MallPVStatVO mallPVStatVO) {
        return memberAwardsStatMapper.selectMallPVStatList(mallPVStatVO);
    }

    /**
     * @description: 个人统计业绩查询
     * @author: zhang jing
     * @date: 2023/9/1 11:04
     * @param: [personStatVO]
     * @return: java.util.List<com.hzs.report.member.vo.PersonStatVO>
     **/
    @Override
    public List<PersonStatVO> selectPersonPvList(List<PersonStatVO> perList) {
        return memberAwardsStatMapper.selectPersonPvList(perList);
    }

    /**
     * @description: 直推统计
     * @author: zhang jing
     * @date: 2023/9/4 11:46
     * @param: [directPushVO]
     * @return: java.util.List<com.hzs.report.member.vo.DirectPushVO>
     **/
    @Override
    public List<DirectPushVO> selectDirectPushStatList(DirectPushVO directPushVO) {
        return memberAwardsStatMapper.selectDirectPushStatList(directPushVO);
    }

    @Override
    public List<DirectPushVO> selectThreeDirectPushStatList(DirectPushVO directPushVO) {
        return memberAwardsStatMapper.selectThreeDirectPushStatList(directPushVO);
    }

    /**
     * @description: 直推数据列表
     * @author: zhang jing
     * @date: 2023/12/18 17:15
     * @param: [dpdVO]
     * @return: java.util.List<com.hzs.report.member.vo.DirectPushDataVO>
     **/
    @Override
    public List<DirectPushDataVO> selectDirectPushDataList(DirectPushDataVO dpdVO) {
        return memberAwardsStatMapper.selectDirectPushDataList(dpdVO);
    }

    /**
     * @description: 直推数据详情
     * @author: zhang jing
     * @date: 2023/12/20 14:36
     * @param: [dpdVO]
     * @return: java.util.List<com.hzs.report.member.vo.DirectPushDataVO>
     **/
    @Override
    public List<DirectPushDataVO> selectDirectPushDataDetails(DirectPushDataVO dpdVO) {
        return memberAwardsStatMapper.selectDirectPushDataDetails(dpdVO);
    }


    /**
     * @description: 会员订单分布统计
     * @author: zhang jing
     * @date: 2023/9/20 14:46
     * @param: [orderScatterVO]
     * @return: java.util.List<com.hzs.report.member.vo.OrderScatterVO>
     **/
    @Override
    public List<OrderScatterVO> memberOrderScatter(OrderScatterVO orderScatterVO) {
        return memberAwardsStatMapper.memberOrderScatter(orderScatterVO);
    }

    @Override
    public List<OrderScatterVO> memberThreeOrderScatter(OrderScatterVO orderScatterVO) {
        return memberAwardsStatMapper.memberThreeOrderScatter(orderScatterVO);
    }


    /**
     * @description: 根据奖衔级别查询奖衔
     * @author: zhang jing
     * @date: 2023/10/17 11:17
     * @param: [pkAwardsList]
     * @return: java.util.List<java.lang.Integer>
     **/
    @Override
    public List<Integer> awardsLevellist(List<Integer> pkAwardsList, Integer pkCountry) {
        return memberAwardsStatMapper.awardsLevellist(pkAwardsList, pkCountry);
    }


    /**
     * @description: 处理伞下去重查询方法
     * @author: zhang jing
     * @date: 2024/5/14 14:38
     * @param: [bloodRemoveSameVO]
     * @return: java.util.List<com.hzs.report.member.vo.BloodRemoveSameVO>
     **/
    @Override
    public List<BloodRemoveSameVO> bloodRemoveSameList(BloodRemoveSameVO bloodRemoveSameVO) {
        List<Integer> orderTypeList = bloodRemoveSameVO.getOrderTypeList();
        List<Integer> pkAwardsList = bloodRemoveSameVO.getPkAwardsList();
        bloodRemoveSameVO.setOrderTypeList(orderTypeList);
        if (null != bloodRemoveSameVO.getPkAwards() && CollectionUtil.isEmpty(pkAwardsList)) {
            pkAwardsList.add(bloodRemoveSameVO.getPkAwards());
            bloodRemoveSameVO.setPkAwardsList(pkAwardsList);
        }
        //根据奖衔查询所有会员
        List<BloodRemoveSameVO> achieList = queryAwardAchieList(bloodRemoveSameVO);

        List<BloodRemoveSameVO> allList = new ArrayList<>();
        //查询直推血缘去重的业绩金额
        if (CollectionUtil.isNotEmpty(achieList)) {
            //查询全部伞下血缘业绩
            for (BloodRemoveSameVO brs : achieList) {
                List<BloodRemoveSameVO> allList1 = bloodRemoveSameAllList(brs, bloodRemoveSameVO.getStartDate(),
                        bloodRemoveSameVO.getEndDate(), orderTypeList, pkAwardsList);
                allList.addAll(allList1);
            }

        }
        return allList;
    }

    /**
     * @description: 伞下去重业绩查询（新）
     * @author: zhang jing
     * @date: 2024/5/23 14:50
     * @param: [bloodRemoveSameVO]
     * @return: java.util.List<com.hzs.report.member.vo.BloodRemoveSameVO>
     **/
    @Override
    public List<BloodRemoveSameVO> bloodRemoveSameListHistoryNew(BloodRemoveSameVO bloodRemoveSameVO) {
        List<Integer> orderTypeList = bloodRemoveSameVO.getOrderTypeList();
        List<Integer> pkAwardsList = bloodRemoveSameVO.getPkAwardsList();
        bloodRemoveSameVO.setOrderTypeList(orderTypeList);
        if (null != bloodRemoveSameVO.getPkAwards() && CollectionUtil.isEmpty(pkAwardsList)) {
            pkAwardsList.add(bloodRemoveSameVO.getPkAwards());
            bloodRemoveSameVO.setPkAwardsList(pkAwardsList);
        }
        List<BloodRemoveSameVO> allList = new ArrayList<>();
        //根据奖衔查询所有会员
        List<BloodRemoveSameVO> achieList = queryAwardAchieListHistory(bloodRemoveSameVO);
//        List<BloodRemoveSameVO> achieList1 = new ArrayList<>();
//        achieList1.add(achieList.get(0));

        if (CollectionUtil.isNotEmpty(achieList)) {
            //查询会员的所有血缘业绩
            allList = bloodSameAllListHistory(achieList, bloodRemoveSameVO.getPeriodEnd(), bloodRemoveSameVO.getPeriodSta(),
                    bloodRemoveSameVO.getAchieveTableNameEnd(), bloodRemoveSameVO.getAchieveTableNameSta(),
                    bloodRemoveSameVO.getSettleTableNameSta(),
                    bloodRemoveSameVO.getSettleTableNameEnd(), bloodRemoveSameVO.getOrderType());
            Map<Long, BloodRemoveSameVO> allMap = allList.stream()
                    .collect(Collectors.toMap(BloodRemoveSameVO::getPkMember, Function.identity()));
            //查询伞下要去重的会员业绩
            List<BloodRemoveSameVO> brsmAchieveListAll = new ArrayList<>();
            for (BloodRemoveSameVO brs : achieList) {
                List<BloodRemoveSameVO> brsmAchieveList = bloodRemoveSameMemberAchieveNew(Collections.singletonList(brs), bloodRemoveSameVO.getPeriodEnd(), bloodRemoveSameVO.getPeriodSta(),
                        bloodRemoveSameVO.getAchieveTableNameEnd(), bloodRemoveSameVO.getAchieveTableNameSta(),
                        bloodRemoveSameVO.getSettleTableNameSta(),
                        bloodRemoveSameVO.getSettleTableNameEnd(), bloodRemoveSameVO.getOrderType(),
                        bloodRemoveSameVO.getPkCountry(), pkAwardsList);
                brsmAchieveListAll.addAll(brsmAchieveList);
            }
            if (CollectionUtil.isNotEmpty(brsmAchieveListAll)) {
                Map<Long, BloodRemoveSameVO> brsmAchieveMap = brsmAchieveListAll.stream()
                        .collect(Collectors.toMap(BloodRemoveSameVO::getPkMember, Function.identity()));
                allMap.forEach((key, value) -> {
                    brsmAchieveMap.forEach((key1, value1) -> {
                        if (key.equals(key1)) {
                            value.setOrderAmount(value.getOrderAmount().subtract(brsmAchieveMap.get(key1).getOrderAmount()));
                            value.setOrderAchieve(value.getOrderAchieve().subtract(brsmAchieveMap.get(key1).getOrderAchieve()));
                        }
                    });
                });
            }
        }
        return allList;
    }

    /**
     * @description: 安置血缘查询
     * @author: zhang jing
     * @date: 2023/12/6 15:50
     * @param: [resettleBloodVOVO]
     * @return: java.util.List<com.hzs.report.member.vo.ResettleBloodVOVO>
     **/
    @Override
    public List<ResettleBloodVO> resettleBloodList(ResettleBloodVO resettleBloodVO) {
        List<ResettleBloodVO> resettleBloodList = new ArrayList<>();
        List<ResettleBloodVO> lrMemberCountList = memberAwardsStatMapper.lrMemberCountList(resettleBloodVO);
        if (CollectionUtil.isNotEmpty(lrMemberCountList)) {
            lrMemberCountList.forEach(itm -> {
                if (itm.getPlaceDept() == EPlaceDept.LEFT_DEPT.getValue()) {
                    resettleBloodVO.setLMemberCount(itm.getMemberCount());
                }
                if (itm.getPlaceDept() == EPlaceDept.RIGHT_DEPT.getValue()) {
                    resettleBloodVO.setRMemberCount(itm.getMemberCount());
                }
            });
        }
        List<ResettleBloodVO> lrbMemberCountList = memberAwardsStatMapper.lrbMemberCountList(resettleBloodVO);
        if (CollectionUtil.isNotEmpty(lrbMemberCountList)) {
            lrbMemberCountList.forEach(itm -> {
                if (itm.getPlaceDept() == EPlaceDept.LEFT_DEPT.getValue()) {
                    resettleBloodVO.setLbMemberCount(itm.getMemberCount());
                }
                if (itm.getPlaceDept() == EPlaceDept.RIGHT_DEPT.getValue()) {
                    resettleBloodVO.setRbMemberCount(itm.getMemberCount());
                }
            });
        }
        resettleBloodList.add(resettleBloodVO);
        return resettleBloodList;
    }

    /**
     * @description: 安置血缘查询-左右区人数详情列表
     * @author: zhang jing
     * @date: 2023/12/7 11:38
     * @param: [resettleBloodVO]
     * @return: java.util.List<com.hzs.report.member.vo.ResettleBloodVO>
     **/
    @Override
    public List<ResettleBloodVO> lrMemberDetailsList(ResettleBloodVO resettleBloodVO) {
        return memberAwardsStatMapper.lrMemberDetailsList(resettleBloodVO);
    }

    /**
     * @description: 安置血缘查询-左右区血缘人数详情列表
     * @author: zhang jing
     * @date: 2023/12/7 11:38
     * @param: [resettleBloodVO]
     * @return: java.util.List<com.hzs.report.member.vo.ResettleBloodVO>
     **/
    @Override
    public List<ResettleBloodVO> lrbMemberDetailsList(ResettleBloodVO resettleBloodVO) {
        return memberAwardsStatMapper.lrbMemberDetailsList(resettleBloodVO);
    }

    /**
     * @description: 个人复购统计
     * @author: zhang jing
     * @date: 2024/1/25 15:07
     * @param: [prVO]
     * @return: java.util.List<com.hzs.report.member.vo.PersonRepurchaseVO>
     **/
    @Override
    public List<PersonRepurchaseVO> personRepurchaseList(PersonRepurchaseVO prVO) {
        return memberAwardsStatMapper.personRepurchaseList(prVO);
    }

    /**
     * @description: 安置业绩统计-查询会员
     * @author: zhang jing
     * @date: 2024/1/25 15:36
     * @param: [psVO]
     * @return: java.util.List<com.hzs.report.member.vo.PositStatVO>
     **/
    @Override
    public List<PositStatVO> positStatList(PositStatVO psVO) {
        return memberAwardsStatMapper.positStatList(psVO);
    }

    /**
     * @description: 安置业绩统计 查询左右区业绩
     * @author: zhang jing
     * @date: 2024/1/26 14:50
     * @param: [psVO]
     * @return: java.util.List<com.hzs.report.member.vo.PositStatVO>
     **/
    @Override
    public List<PositStatVO> positStatAchieve(PositStatVO psVO) {
        return memberAwardsStatMapper.positStatAchieve(psVO);
    }

    /**
     * @description: 查询伞下直推产品列表
     * @author: zhang jing
     * @date: 2024/2/23 16:04
     * @param: [ubpVO]
     * @return: java.util.List<com.hzs.report.member.vo.UmbrellaBelowProductVO>
     **/
    @Override
    public List<UmbrellaBelowProductVO> umbrellaBelowProductList(UmbrellaBelowProductVO ubpVO) {
        return memberAwardsStatMapper.umbrellaBelowProductList(ubpVO);
    }

    /**
     * @description: 伞下直推产品去重
     * @author: zhang jing
     * @date: 2024/2/24 14:46
     * @param: [ubrVO]
     * @return: java.util.List<com.hzs.report.member.vo.UmbrellaBelowRepeatVO>
     **/
    @Override
    public List<UmbrellaBelowRepeatVO> umbrellaBelowRepeatList(UmbrellaBelowRepeatVO ubrVO) {
        return memberAwardsStatMapper.umbrellaBelowRepeatList(ubrVO);
    }

    /**
     * @description: 伞下直推产品统计
     * @author: zhang jing
     * @date: 2024/2/25 11:05
     * @param: [sptVO]
     * @return: java.util.List<com.hzs.report.member.vo.StatProductVO>
     **/
    @Override
    public List<StatProductVO> statProductList(StatProductVO sptVO) {
        return memberAwardsStatMapper.statProductList(sptVO);
    }

    /**
     * @description: 会员户籍数据查询
     * @author: zhang jing
     * @date: 2024/3/11 11:39
     * @param: [ddVO]
     * @return: java.util.List<com.hzs.report.member.vo.DomicileDataVO>
     **/
    @Override
    public List<DomicileDataVO> domicileDataList(DomicileDataVO ddVO) {
        return memberAwardsStatMapper.domicileDataList(ddVO);
    }

    /**
     * @description: 地区业绩统计
     * @author: zhang jing
     * @date: 2024/5/6 16:12
     * @param: [areaAchieveStatVO]
     * @return: java.util.List<com.hzs.report.member.vo.OrderScatterVO>
     **/
    @Override
    public List<AreaAchieveStatVO> areaAchieveStat(AreaAchieveStatVO areaAchieveStatVO) {
        return memberAwardsStatMapper.areaAchieveStat(areaAchieveStatVO);
    }

    /*
     * @description: 系统业绩统计
     * @author: zhang jing
     * @date: 2024/6/18 14:29
     * @param: [vertexAchieveStatVO]
     * @return: java.util.List<com.hzs.report.member.vo.VertexAchieveStatVO>
     **/
    @Override
    public List<VertexAchieveStatVO> vertexAchieveStat(VertexAchieveStatVO vertexAchieveStatVO) {
        return memberAwardsStatMapper.vertexAchieveStat(vertexAchieveStatVO);
    }


    /**
     * @description: 导出地区业绩
     * @author: zhang jing
     * @date: 2024/5/20 10:09
     * @param: [response, fileName, dataList]
     * @return: void
     **/
    @Override
    public void exportExcelWithMergedCells(HttpServletResponse response, String fileName,
                                           List<AreaAchieveStatVO> dataList) throws IOException {

        Workbook workbook = new XSSFWorkbook(); // 创建一个新的Excel工作簿
        Sheet sheet = workbook.createSheet("Sheet1"); // 创建一个新的sheet
        // 样式定义：加粗、居中、灰色背景
        CellStyle headerStyle = workbook.createCellStyle();
        Font headerFont = workbook.createFont();
        headerFont.setBold(true); // 加粗
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 灰色背景
        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 填充模式
        // 写入表头
        Row headerRow = sheet.createRow(0);
        // 创建第一个单元格并合并一行
        Cell headerCell1 = headerRow.createCell(0);
        headerCell1.setCellValue("区域");
        headerCell1.setCellStyle(headerStyle); // 应用样式
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
        //写入第二行每一列的固定值
        Row row1 = sheet.createRow(1);
        for (int i = 1; i < 32; i++) {
            // 创建第二个单元格并合并两列
            Cell headerCell2 = headerRow.createCell(2 * i - 1);
            headerCell2.setCellValue(i);
            headerCell2.setCellStyle(headerStyle); // 应用样式
            sheet.addMergedRegion(new CellRangeAddress(0, 0, (2 * i - 1), 2 * i));
            Cell amountCell = row1.createCell(2 * i - 1);
            amountCell.setCellValue("金额");
            amountCell.setCellStyle(headerStyle);
            Cell achieveCell = row1.createCell(2 * i);
            achieveCell.setCellValue("业绩");
            achieveCell.setCellStyle(headerStyle);
        }
        // 金额总计和业绩总计表头
        Cell totalAmountCell = row1.createCell(63);
        totalAmountCell.setCellValue("金额总计");
        totalAmountCell.setCellStyle(headerStyle); // 应用样式
        Cell totalAchieveCell = row1.createCell(64);
        totalAchieveCell.setCellValue("业绩总计");
        totalAchieveCell.setCellStyle(headerStyle); // 应用样式
        // 写入数据行
        int rowNum = 2; // 从第三行开始写入数据（第一行是表头）
        // 写入数据，并设置居中样式
        CellStyle dataStyle = workbook.createCellStyle();
        dataStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        for (AreaAchieveStatVO data : dataList) {
            Row row = sheet.createRow(rowNum++);
            Cell prNameCell = row.createCell(0); // 假设T有一个getId()方法
            prNameCell.setCellValue(data.getPrName());
            //应用样式
            prNameCell.setCellStyle(dataStyle);
            for (int i = 1; i <= 31; i++) {
                long orderAmount = getPropertyValue(data, "getOrderAmount" + i);
                long orderAchieve = getPropertyValue(data, "getOrderAchieve" + i);

                Cell amount = row.createCell(2 * i - 1);
                amount.setCellValue(orderAmount);
                amount.setCellStyle(dataStyle);

                Cell achieve = row.createCell(2 * i);
                achieve.setCellValue(orderAchieve);
                achieve.setCellStyle(dataStyle);

                Cell amountSum = row.createCell(63);
                amountSum.setCellValue(data.getOrderAmountSum());
                amountSum.setCellStyle(dataStyle);

                Cell achieveSum = row.createCell(64);
                achieveSum.setCellValue(data.getOrderAchieveSum());
                achieveSum.setCellStyle(dataStyle);

            }
        }
        String safeFileName = fileName.replace(" ", "_"); // 将空格替换为下划线
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 同时设置 filename 和 filename*;filename*=UTF-8'' 编码格式是为了兼容不支持 filename* 的浏览器
        response.setHeader("Content-Disposition", "attachment; filename=\"" + safeFileName + "\"; filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8"));
        workbook.write(response.getOutputStream());
        workbook.close();
    }

    /**
     * @description: 导出系统业绩统计
     * @author: zhang jing
     * @date: 2024/6/18 15:39
     * @param: [response, fileName, dataList]
     * @return: void
     **/
    @Override
    public void exportExcelVertexWithMergedCells(HttpServletResponse response, String fileName,
                                                 List<VertexAchieveStatVO> dataList) throws IOException {

        Workbook workbook = new XSSFWorkbook(); // 创建一个新的Excel工作簿
        Sheet sheet = workbook.createSheet("Sheet1"); // 创建一个新的sheet
        // 样式定义：加粗、居中、灰色背景
        CellStyle headerStyle = workbook.createCellStyle();
        Font headerFont = workbook.createFont();
        headerFont.setBold(true); // 加粗
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 灰色背景
        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 填充模式
        // 写入表头
        Row headerRow = sheet.createRow(0);
        // 创建第一个单元格并合并一行
        Cell headerCell1 = headerRow.createCell(0);
        headerCell1.setCellValue("区域");
        headerCell1.setCellStyle(headerStyle); // 应用样式
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
        //写入第二行每一列的固定值
        Row row1 = sheet.createRow(1);
        for (int i = 1; i < 32; i++) {
            // 创建第二个单元格并合并两列
            Cell headerCell2 = headerRow.createCell(2 * i - 1);
            headerCell2.setCellValue(i);
            headerCell2.setCellStyle(headerStyle); // 应用样式
            sheet.addMergedRegion(new CellRangeAddress(0, 0, (2 * i - 1), 2 * i));
            Cell amountCell = row1.createCell(2 * i - 1);
            amountCell.setCellValue("金额");
            amountCell.setCellStyle(headerStyle);
            Cell achieveCell = row1.createCell(2 * i);
            achieveCell.setCellValue("业绩");
            achieveCell.setCellStyle(headerStyle);
        }
        // 金额总计和业绩总计表头
        Cell totalAmountCell = row1.createCell(63);
        totalAmountCell.setCellValue("金额总计");
        totalAmountCell.setCellStyle(headerStyle); // 应用样式
        Cell totalAchieveCell = row1.createCell(64);
        totalAchieveCell.setCellValue("业绩总计");
        totalAchieveCell.setCellStyle(headerStyle); // 应用样式
        // 写入数据行
        int rowNum = 2; // 从第三行开始写入数据（第一行是表头）
        // 写入数据，并设置居中样式
        CellStyle dataStyle = workbook.createCellStyle();
        dataStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        for (VertexAchieveStatVO data : dataList) {
            Row row = sheet.createRow(rowNum++);
            Cell prNameCell = row.createCell(0); // 假设T有一个getId()方法
            prNameCell.setCellValue(data.getVertexName());
            //应用样式
            prNameCell.setCellStyle(dataStyle);
            for (int i = 1; i <= 31; i++) {
                long orderAmount = getPropertyValue(data, "getOrderAmount" + i);
                long orderAchieve = getPropertyValue(data, "getOrderAchieve" + i);

                Cell amount = row.createCell(2 * i - 1);
                amount.setCellValue(orderAmount);
                amount.setCellStyle(dataStyle);

                Cell achieve = row.createCell(2 * i);
                achieve.setCellValue(orderAchieve);
                achieve.setCellStyle(dataStyle);

                Cell amountSum = row.createCell(63);
                amountSum.setCellValue(data.getOrderAmountSum());
                amountSum.setCellStyle(dataStyle);

                Cell achieveSum = row.createCell(64);
                achieveSum.setCellValue(data.getOrderAchieveSum());
                achieveSum.setCellStyle(dataStyle);

            }
        }
        String safeFileName = fileName.replace(" ", "_"); // 将空格替换为下划线
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 同时设置 filename 和 filename*;filename*=UTF-8'' 编码格式是为了兼容不支持 filename* 的浏览器
        response.setHeader("Content-Disposition", "attachment; filename=\"" + safeFileName + "\"; filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8"));
        workbook.write(response.getOutputStream());
        workbook.close();
    }

    /**
     * @description: 月度职级名单查询
     * @author: zhang jing
     * @date: 2024/6/24 15:22
     * @param: [mjlvo]
     * @return: java.util.List<com.hzs.report.member.vo.MonthlyJobLevelVo>
     **/
    @Override
    public List<MonthlyJobLevelVo> monthlyJobLevelList(MonthlyJobLevelVo mjlvo) {
        return memberAwardsStatMapper.monthlyJobLevelList(mjlvo);
    }

    /**
     * @description: 查询收益区域数据
     * @author: zhang jing
     * @date: 2025/1/10 16:28
     * @param: [revenueAreaVO]
     * @return: java.util.List<com.hzs.report.member.vo.RevenueAreaVO>
     **/
    @Override
    public List<RevenueAreaVO> revenueAreaList(RevenueAreaVO revenueAreaVO) {
        return memberAwardsStatMapper.revenueAreaList(revenueAreaVO);
    }

    // 获取对象属性值的通用方法
    private long getPropertyValue(AreaAchieveStatVO data, String methodName) {
        long value = 0;
        try {
            Method method = AreaAchieveStatVO.class.getMethod(methodName);
            value = (long) method.invoke(data);
        } catch (Exception e) {
            // 异常处理
        }
        return value;
    }

    // 获取对象属性值的通用方法
    private long getPropertyValue(VertexAchieveStatVO data, String methodName) {
        long value = 0;
        try {
            Method method = VertexAchieveStatVO.class.getMethod(methodName);
            value = (long) method.invoke(data);
        } catch (Exception e) {
            // 异常处理
        }
        return value;
    }


}
