package com.hzs.member.achieve.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.hzs.common.domain.member.achieve.CuMemberAchieve;
import com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt;
import com.hzs.common.domain.sale.order.SaOrder;
import com.hzs.member.achieve.controller.vo.*;
import com.hzs.member.achieve.param.MemberAchieveDisParam;
import com.hzs.member.achieve.param.MemberAchieveParam;
import com.hzs.member.achieve.param.MonthAchieveParam;
import com.hzs.member.achieve.vo.*;
import com.hzs.member.settlecenter.param.PlacementDataParam;
import com.hzs.member.settlecenter.vo.PlacementDataVO;
import com.hzs.member.settlecenter.vo.PlacementImageDataVO;
import com.hzs.member.settlecenter.vo.RecommendImageDataVO;
import com.hzs.member.settlecenter.vo.RecommendTeamImagVO;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 会员业绩记录 服务类
 * </p>
 *
 * @author hzs
 * @since 2022-10-26
 */
public interface ICuMemberAchieveService extends IService<CuMemberAchieve> {

    /**
     * 查询会员最新业绩
     *
     * @param pkMember  会员主键
     * @param pkCountry 公司
     * @return: CuMemberAchieve
     * @Author: sui q
     * @Date: 2022/10/26 15:04
     */
    CuMemberAchieve queryCuMemberAchieveByPkMember(Long pkMember, Integer pkCountry);

    /**
     * 计算业绩（根据订单，用于秒接）
     *
     * @param saOrder 订单
     * @return: void
     * @Author: sui q
     * @Date: 2022/10/31 10:03
     */
    void calculateAchieveBySaOrder(SaOrder saOrder);

    /**
     * 计算业绩（根据订单列表，7天内所有订单）
     *
     * @param saOrderMap 订单列表
     * @return: void
     * @Author: sui q
     * @Date: 2022/10/31 10:01
     */
    void calculateAchieveBySaOrder(Map<String, List<SaOrder>> saOrderMap);

    /**
     * 创建每月的会员业绩记录表
     *
     * @param date 日期
     * @return: void
     * @Author: sui q
     * @Date: 2022/10/31 15:17
     */
    String createCuMemberAchieve(String date);

    /**
     * 创建每年的业绩统计年表，用于放月表
     *
     * @param tableName 表名
     * @return: void
     * @Author: sui q
     * @Date: 2022/11/7 14:10
     */
    void createCuMemberMonthTable(String tableName);

    /*
     * @description:更新会员业绩表 每月月统计报表
     * @author: sui q
     * @date: 2023/8/29 10:57
     * @param: null null
     **/
    void mergeCuMemberMonth(Integer day, String date);

    /**
     * 将结算日表的值插入到结算月表中
     *
     * @param targetTableName 目标表 网体月表
     * @param sourceTableName 来源表 结算日表
     * @param period          期间
     * @return: void
     * @Author: sui q
     * @Date: 2023/2/16 11:35
     */
    void insertCuMemberAchieveBySettleDate(String targetTableName, String sourceTableName, Integer period);

    /**
     * 将结算日表的值插入到结算月表中
     *
     * @param targetTableName 目标表 网体月表
     * @param sourceTableName 来源表 结算日表
     * @param period          期间
     * @return: void
     * @Author: sui q
     * @Date: 2023/2/16 11:35
     */
    void mergeCuMemberAchieveBySettleDate(String targetTableName, String sourceTableName, Integer period);

    /**
     * 根据每日日业绩开始更新会员业绩 新增业绩、累计业绩
     *
     * @param memberAchieveParamMap 修改的结算
     * @param tablaName             修改的结算期间表
     * @return: Boolean
     * @Author: sui q
     * @Date: 2022/11/2 11:30
     */
    Boolean updateCuMemberAchieveEveryDay(Map<Long, MemberAchieveParam> memberAchieveParamMap, String tablaName);


    /**
     * 根据每日日业绩开始回退更新会员业绩 新增业绩、累计业绩
     *
     * @param memberAchieveParamMap 修改的结算
     * @param tablaName             修改的结算期间表
     * @return: Boolean
     * @Author: sui q
     * @Date: 2022/11/2 11:30
     */
    void updateCuMemberBackOldAchieveEveryDay(Map<Long, MemberAchieveParam> memberAchieveParamMap, String tablaName);

    /**
     * 将昨天日表数据插入今天日表中, 昨日日表更新今天日表网体表
     * 根据昨天结算表数据更新今天结算表的业绩数据
     *
     * @param targetTable 目标表 记录10天跟月表一摸一样的滚动表数据
     * @return: void
     * @Author: sui q
     * @Date: 2022/10/31 16:26
     */
    void updateCuMemberSettleInitAchieve(String targetTable);

    /**
     * 将昨天日表数据插入今天日表中, 昨日日表更新今天日表网体表
     * 根据昨天结算表数据更新今天结算表的业绩数据
     *
     * @param sourceTable 来源表，记录10天跟月表一摸一样的滚动表数据
     * @param targetTable 目标表 记录10天跟月表一摸一样的滚动表数据
     * @return: void
     * @Author: sui q
     * @Date: 2022/10/31 16:26
     */
    void updateCuMemberSettleAchieveByBeforeDay(String sourceTable, String targetTable);

    /**
     * 根据特殊业务更新业绩
     *
     * @param targetTable 结算表
     * @param period      期间
     * @param pkId        主键
     * @return: void
     * @Author: sui q
     * @Date: 2023/3/11 13:42
     */
    void updateCuMemberSettleAchieveBySpecialBus(String targetTable, Integer period, Long pkId);

    /*
     * @description: 根据到期日期更新业绩，到期后需要还原到实际累计金额
     * @author: sui q
     * @date: 2023/4/8 15:32
     * @param: null null
     **/
    void updateCuMemberSettleAchieveByDueDate(String currentTableName, String yesTableName, Date currentDate);

    /*
     * description: 业绩分布-安置图
     * @author: sui q
     * @date: 2023/4/6 18:01
     * @param: null null
     **/
    CuMemberDisVO queryCuMemberAchieveDis(MemberAchieveDisParam memberAchieveDisParam);

    /*
     * @description: 点击架构树显示会员的业绩情况
     * @author: sui q
     * @date: 2023/5/10 16:04
     * @param: null null
     **/
    CuMemberDisVO queryCuMemberDis(MemberAchieveDisParam memberAchieveDisParam);

    /*
     * description: 查询会员伞下血缘业绩
     * @author: sui q
     * @date: 2023/4/7 15:13
     * @param: null null
     **/
    BigDecimal queryCuMemberUnderBloodAchieveByPkMember(MemberAchieveDisParam memberAchieveDisParam);

    /**
     * 会员端新增业绩
     *
     * @param cuMemberNewAddAchieveVO 端新增业绩
     * @return List<CuMemberNewAddAchieveVO>
     */
    List<CuMemberNewAddAchieveVO> selectNewAddAchieve(CuMemberNewAddAchieveVO cuMemberNewAddAchieveVO);

    /**
     * 根据天数查询新增业绩
     *
     * @param cuMemberNewAddAchieveVO 端新增业绩
     * @return List<CuMemberNewAddAchieveVO>
     */
    List<CuMemberNewAddAchieveVO> selectNewAddAchieveByDay(CuMemberNewAddAchieveVO cuMemberNewAddAchieveVO);

    /**
     * 会员端首页荣誉奖衔
     *
     * @param pkMember  用户ID
     * @param pkCountry 国家ID
     * @return
     */
    CuMemberAwardsDisVO selectAwardsByPkMember(Long pkMember, Integer pkCountry);

    /**
     * 查询个人的奖衔信息
     *
     * @param pkMember  用户ID
     * @param pkCountry 国家ID
     * @return CuMemberAwardsUnderVO
     */
    CuMemberAwardsUnderVO selectMemberAwards(Long pkMember, Integer pkCountry);

    /**
     * 月度新增业绩对比
     *
     * @param pkMember  用户ID
     * @param pkCountry 国家ID
     * @param month     月份
     * @return CuMemberMonthAchieveContrastVO
     */
    List<CuMemberMonthAchieveContrastVO> selectNewAddAchieveContrast(Long pkMember, Integer pkCountry, Integer month);

    LocalDate getStartDateByType(Integer dayType, LocalDate localDate);

    /**
     * @description: 业绩分布-新增业绩统计
     * @author: zhang jing
     * @date: 2023/5/19 10:29
     * @param: []
     * @return: com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO
     **/
    PlaceNewAddAchieveVO placeNewAddAchieveStat(PlaceNewAddAchieveVO pna);

    Date getDateFromYearAndMonth(String year, String month);

    /**
     * @description: 月度业绩-左右区人数详情(最新)
     * @author: zhang jing
     * @date: 2023/9/28 11:38
     * @param: [pna]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO>
     **/
    List<PlaceNewAddAchieveVO> placeNewAddAchieveDetails(PlaceNewAddAchieveVO pna);

    /**
     * @description: 月度业绩-左右区人数详情(历史)
     * @author: zhang jing
     * @date: 2023/9/28 11:38
     * @param: [pna]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO>
     **/
    List<PlaceNewAddAchieveVO> placeNewAddAchieveHistoryDetails(PlaceNewAddAchieveVO pna);

    /**
     * @description:月度业绩-左右区业绩详情
     * @author: zhang jing
     * @date: 2023/11/30 9:17
     * @param: [pna]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO>
     **/
    List<PlaceNewAddAchieveVO> leftRightAchieveDetails(PlaceNewAddAchieveVO pna);

    /**
     * @description:月度业绩-左右区血缘业绩详情
     * @author: zhang jing
     * @date: 2023/11/30 11:15
     * @param: [pna]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO>
     **/
    List<PlaceNewAddAchieveVO> leftRightDirectAchieveDetails(PlaceNewAddAchieveVO pna);

    /**
     * @description:月度业绩-查询血缘业绩详情
     * @author: zhang jing
     * @date: 2023/11/30 14:13
     * @param: [pna]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO>
     **/
    List<PlaceNewAddAchieveVO> directAchieveDetails(PlaceNewAddAchieveVO pna);


    /**
     * @description: 业绩分布-直推业绩（右图）
     * @author: zhang jing
     * @date: 2023/5/20 16:22
     * @param: [pa]
     * @return: com.hzs.member.achieve.controller.vo.ParentAchieveVO
     **/
    ParentAchieveVO parentAchieveRight(ParentAchieveVO pa);

    /**
     * @description: 业绩分布-直推业绩（左图）
     * @author: zhang jing
     * @date: 2023/5/23 19:49
     * @param: [pa]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.ParentAchieveVO>
     **/
    List<ParentAchieveVO> parentAchieveLeft(ParentAchieveVO pa);

    /**
     * 查询安置数据
     *
     * @param param 入参
     * @return List<PlacementDataVO>
     */
    List<PlacementDataVO> selectPlacementDataList(PlacementDataParam param);


    /**
     * 查询推荐数据
     *
     * @param param 入参
     * @return List<PlacementDataVO>
     */
    List<PlacementDataVO> selectRecommendDataList(PlacementDataParam param);

    /**
     * 查询会员真实业绩
     *
     * @param pkMember
     * @param pkCountry
     * @param month
     * @return
     */
    RealPerformanceVo queryRealPerformance(Long pkMember, Integer pkCountry, Integer month);


    /**
     * 会员真实业绩饼状图
     *
     * @param pkMember
     * @param pkCountry
     * @param month
     * @return
     */
    AzAchievementPie queryRealPerformancePic(Long pkMember, Integer pkCountry, Integer month);

    /*
     * @description: 更新会员的业绩
     * @author: sui q
     * @date: 2023/8/12 15:46
     * @param: null null
     **/
    void updateCuMemberAchieve();


    /**
     * 查询安置图表
     *
     * @param param 入参
     * @return PlacementImageDataVO
     */
    PlacementImageDataVO selectPlaceImage(PlacementDataParam param);


    /**
     * 查询推荐体第图表
     *
     * @param param 入参
     * @return RecommendImageDataVO
     */
    List<RecommendImageDataVO> selectRecommendVertexImage(PlacementDataParam param);


    /**
     * 查询推荐团队图表
     *
     * @param param 入参
     * @return RecommendImageDataVO
     */
    List<RecommendTeamImagVO> selectRecommendTeamImage(PlacementDataParam param);

    /*
     * @description: 查询月统计数据，按照月倒叙
     * @author: sui q
     * @date: 2023/8/29 16:10
     * @param: null null
     **/
    List<CuMemberAchieveExt> queryMemberMonthAchieve(Long pkMember, String month);

    /*
     * @description: 查询会员一代伞下
     * @author: sui q
     * @date: 2023/8/29 18:07
     * @param: null null
     **/
    List<Long> queryPkMemberMonthAchieve(String month, Long pkMember);

    /*
     * @description: 查询月统计数据，查询明细
     * @author: sui q
     * @date: 2023/8/29 17:43
     * @param: null null
     **/
    List<CuMemberAchieveExt> queryMemberMonthAchieveDetail(List<Long> memberList, MonthAchieveParam monthAchieveParam);

    /*
     * @description: 查询月统计数据，查询明细，安置伞下
     * @author: sui q
     * @date: 2023/9/6 21:12
     * @param: null null
     **/
    List<CuMemberAchieveExt> queryPlaceParentMemberMonthAchieve(MonthAchieveParam monthAchieveParam);

    /*
     * @description: 查询月统计数据，查询明细，安置伞下
     * @author: sui q
     * @date: 2023/9/6 21:12
     * @param: null null
     **/
    List<CuMemberAchieveExt> queryParentMemberMonthAchieve(MonthAchieveParam monthAchieveParam);


    /**
     * 根据实时小区业绩获取奖衔
     *
     * @param pkMember      会员ID
     * @param pkCountry     国家ID
     * @param yesterdayFlag 查询昨日业绩标记（true=查询，false=不查询）
     * @return Integer
     */
    CuMemberAwardsUnderVO getPkAwardBySmallAchieve(Long pkMember, Integer pkCountry, boolean yesterdayFlag);

}
