package com.hzs.member.achieve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzs.common.domain.member.achieve.CuMemberAchieve;
import com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt;
import com.hzs.member.achieve.controller.vo.*;
import com.hzs.member.achieve.param.MonthAchieveParam;
import com.hzs.member.achieve.vo.CuMemberAwardsUnderVO;
import com.hzs.member.achieve.vo.CuMemberMonthAchieveContrastVO;
import com.hzs.member.achieve.vo.CuMemberNewAddAchieveVO;
import com.hzs.member.settlecenter.param.PlacementDataParam;
import com.hzs.member.settlecenter.vo.*;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 会员业绩记录 Mapper 接口
 * </p>
 *
 * @author hzs
 * @since 2022-10-26
 */
public interface CuMemberAchieveMapper extends BaseMapper<CuMemberAchieve> {

    /**
     * 创建会员网体记录表
     *
     * @param tableName 日期
     * @return: void
     * @Author: sui q
     * @Date: 2022/10/31 11:44
     */
    void createCuMemberAchieveTable(String tableName);

    /**
     * 创建每年的会员考核表
     *
     * @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(@Param("date") String date, @Param("period") Integer period);

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

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

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

    /*
     * @description: 更新为最初始的数据，新增的为0，历史的通过昨天进行更新
     * @author: sui q
     * @date: 2023/8/11 14:57
     * @param: null null
     **/
    void updateCuMemberSettleInitAchieve(String targetTable);

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

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


    /**
     * 根据每日日业绩开始更新会员业绩 新增业绩、累计业绩
     *
     * @param memberAchieveParamList 会员业绩
     * @param tableName              更新的表，结算日的日表
     * @return: Boolean
     * @Author: sui q
     * @Date: 2022/11/2 11:30
     */
    Boolean updateCuMemberBackOldAchieveEveryDay(@Param("memberAchieveParamList") List<?> memberAchieveParamList,
                                                 @Param("tableName") String tableName);

    /**
     * 根据每日日业绩开始更新会员业绩 新增业绩、累计业绩
     *
     * @param memberAchieveParamList 会员业绩
     * @param tableName              更新的表，结算日的日表
     * @return: Boolean
     * @Author: sui q
     * @Date: 2022/11/2 11:30
     */
    Boolean updateCuMemberBackAchieveEveryDay(@Param("memberAchieveParamList") List<?> memberAchieveParamList,
                                              @Param("tableName") String tableName);

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

    /*
     * description: 查询会员伞下血缘业绩
     * @author: sui q
     * @date: 2023/4/7 15:13
     * @param: null null
     **/
    BigDecimal queryCuMemberUnderBloodAchieveByPkMember(@Param("treeTable") String treeTable, @Param("achieveTable") String achieveTable,
                                                        @Param("pkMember") Long pkMember, @Param("period") Integer period);


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

    /**
     * 根据用户ID查询奖衔
     *
     * @param memberAwardsUnderVO 奖衔VO
     * @return CuMemberAwardsUnderVO
     */
    List<CuMemberAwardsUnderVO> selectAwardsByPkMember(CuMemberAwardsUnderVO memberAwardsUnderVO);

    /**
     * 根据会员ID查询安置位置最小业绩
     *
     * @param memberAwardsUnderVO 奖衔VO
     * @return CuMemberAwardsUnderVO
     */
    CuMemberAwardsUnderVO selectMinRealPvByPkMember(CuMemberAwardsUnderVO memberAwardsUnderVO);

    /**
     * 根据用户ID查询奖衔伞下
     *
     * @param memberAwardsUnderVO 奖衔VO
     * @return List<CuMemberAwardsUnderVO>
     */
    List<CuMemberAwardsUnderVO> selectUnderMemberAwards(CuMemberAwardsUnderVO memberAwardsUnderVO);


    /**
     * 月度新增业绩对比
     *
     * @param memberMonthAchieveContrastVO 参数
     * @return CuMemberMonthAchieveContrastVO
     */
    CuMemberMonthAchieveContrastVO selectNewAddAchieveContrast(CuMemberMonthAchieveContrastVO memberMonthAchieveContrastVO);

    /**
     * 查询安置伞下前五的荣誉奖衔
     *
     * @param memberAwardsList 荣誉奖衔
     * @return List<CuMemberAwardsUnderVO>
     */
    List<CuMemberAwardsUnderVO> selectUnderMemberAwardsFive(@Param("memberAwardsList") List<CuMemberAwardsUnderVO> memberAwardsList);

    /**
     * 查询表名是否存在
     *
     * @param tableName 表名
     * @return Integer
     */
    Integer selectExistTable(String tableName);

    /**
     * @description: 查询左右区新增业绩
     * @author: zhang jing
     * @date: 2023/5/19 11:00
     * @param: [pna]
     * @return: com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO
     **/
    PlaceNewAddAchieveVO selectNewABAchieve(PlaceNewAddAchieveVO pna);

    List<PlaceNewAddAchieveVO> selectABDirectAchieve(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> placeNewAddAchieveDetails(PlaceNewAddAchieveVO pna);


    /**
     * @description: 查询直推业绩
     * @author: zhang jing
     * @date: 2023/5/19 15:50
     * @param: [pna]
     * @return: com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO
     **/
    PlaceNewAddAchieveVO selectParentAchieve(PlaceNewAddAchieveVO pna);

    /**
     * @description: 查询左右区人数
     * @author: zhang jing
     * @date: 2023/5/19 14:38
     * @param: [pna]
     * @return: java.lang.Integer
     **/
    List<PlaceNewAddAchieveVO> selectABCoun(PlaceNewAddAchieveVO pna);

    /**
     * @description: 查询最新月份左右区人数
     * @author: zhang jing
     * @date: 2023/9/10 17:51
     * @param: [pna]
     * @return: com.hzs.member.achieve.controller.vo.PlaceNewAddAchieveVO
     **/
    List<PlaceNewAddAchieveVO> selectABNewMonthCoun(PlaceNewAddAchieveVO pna);

    /**
     * @description: 根据日期查询最新期数
     * @author: zhang jing
     * @date: 2023/6/6 14:51
     * @param: [pna]
     * @return: java.lang.Integer
     **/
    Integer mostNewPeriod(PlaceNewAddAchieveVO pna);

    /**
     * @description: 查询各个等级直推人数和业绩
     * @author: zhang jing
     * @date: 2023/5/23 10:18
     * @param: [pav]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.ParentAchieveVO>
     **/
    List<ParentAchieveVO> selectParentCounAchieve(ParentAchieveVO pav);

    /**
     * @description: 查询本人直推业绩
     * @author: zhang jing
     * @date: 2023/5/23 19:29
     * @param: [pav]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.ParentAchieveVO>
     **/
    List<ParentAchieveVO> selfParentCounAchieve(ParentAchieveVO pav);

    /**
     * @description: 查询前10直推业绩
     * @author: zhang jing
     * @date: 2023/5/23 19:31
     * @param: [pav]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.ParentAchieveVO>
     **/
    List<ParentAchieveVO> parentCounAchieveTop(ParentAchieveVO pav);

    List<ParentAchieveVO> allDirectPush(ParentAchieveVO pav);


    /**
     * @description: 直推业绩前十人伞下等级业绩
     * @author: zhang jing
     * @date: 2023/5/31 19:56
     * @param: [pav]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.ParentAchieveVO>
     **/
    List<ParentAchieveVO> umbrellaAchieveTop(ParentAchieveVO pav);


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

    /**
     * 根据会员ID查询安置
     *
     * @param param 入参
     * @return List<PlacementDataBaseVO>
     */
    List<PlacementDataBaseVO> selectAchieveByPkMember(PlacementDataParam param);


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

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


    /**
     * 查询体系总和
     *
     * @param param 入参
     * @return RecommendDataDetailVO
     */
    List<RecommendDataDetailVO> selectRecommendVertexValue(PlacementDataParam param);


    /**
     * 查询大盘总和
     *
     * @param param 入参
     * @return RecommendDataDetailVO
     */
    RecommendDataDetailVO selectRecommendMarketValue(PlacementDataParam param);

    /**
     * 查询会员真实业绩
     *
     * @param pkMember     会员主键
     * @param pkCountry    所属国家
     * @param achieveTable 表名
     * @return
     */
    RealPerformanceVo getQueryRealPerformance(@Param("pkMember") Long pkMember, @Param("pkCountry") Integer pkCountry, @Param("achieveTable") String achieveTable);

    /**
     * @param pkMember     会员主键
     * @param pkCountry    所属国家
     * @param achieveTable 表名
     * @return
     */
    AchievementVo getRepurchasePerformancePic(@Param("pkMember") Long pkMember, @Param("pkCountry") Integer pkCountry, @Param("achieveTable") String achieveTable);

    /**
     * 会员真实业绩
     *
     * @param pkMember
     * @param pkCountry
     * @param achieveTable
     * @return
     */
    AzAchievementPie getQueryRealPerformancePic(@Param("pkMember") Long pkMember, @Param("pkCountry") Integer pkCountry, @Param("achieveTable") String achieveTable);

    /**
     * 安置业绩分布
     *
     * @param pkMember
     * @param pkCountry
     * @param achieveTable
     * @return
     */
    AchievementVo getAzAchievement(@Param("pkMember") Long pkMember, @Param("pkCountry") Integer pkCountry, @Param("achieveTable") String achieveTable);

    /**
     * 查询推荐业绩
     *
     * @param memberIds
     * @param pkCountry
     * @param achieveTable
     * @return
     */
    List<BigDecimal> selectByParent(@Param("memberIds") List<Long> memberIds, @Param("pkCountry") Integer pkCountry, @Param("achieveTable") String achieveTable);

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


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

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


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

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

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

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

    /*
     * @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 cuMemberNewAddAchieveVO 新增业绩入参
     * @return List<CuMemberNewAddAchieveVO>
     */
    List<CuMemberNewAddAchieveVO> selectNewAddAchieveMonthByPeriod(CuMemberNewAddAchieveVO cuMemberNewAddAchieveVO);

    /**
     * 查询表名是否存在
     *
     * @param tableNames 表名
     * @return List<String>
     */
    List<String> selectTableNameIsExist(@Param("tableNames") List<String> tableNames);

    /**
     * 根据期数查询新增业绩
     *
     * @param achieve 入参
     * @return List<CuMemberNewAddAchieveVO>
     */
    List<CuMemberNewAddAchieveVO> selectNewAddAchieveByPeriod(@Param("achieve") CuMemberNewAddAchieveVO achieve);

    /**
     * @description: 安置数据查询
     * @author: zhang jing
     * @date: 2024/7/16 13:14
     * @param: [pfq]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO>
     **/
    List<PlaceFrameQueryVO> placeFrameQuery(PlaceFrameQueryVO pfq);

    /**
     * @description: 查询本期安置伞下业绩和新增人数
     * @author: zhang jing
     * @date: 2024/7/24 9:47
     * @param: [pfq]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO>
     **/
    List<PlaceFrameQueryVO> placeBefFrameQuery(PlaceFrameQueryVO pfq);



    /**
     * @description: 查询会员安置伞下第一层会员
     * @author: zhang jing
     * @date: 2024/7/17 9:22
     * @param: [pfq]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO>
     **/
    List<PlaceFrameQueryVO> placeMemberQuery(PlaceFrameQueryVO pfq);
    /**
     * @description: 查询本期安置网体会员
     * @author: zhang jing
     * @date: 2024/7/24 9:31
     * @param: [pfq]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO>
     **/
    List<PlaceFrameQueryVO> placeBefMemberQuery(PlaceFrameQueryVO pfq);


    /**
     * @description: 校验会员是否在某会员安置伞下
     * @author: zhang jing
     * @date: 2024/7/22 14:22
     * @param: [pfq]
     * @return: com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO
     **/
    PlaceFrameQueryVO checkPlaceMemberQuery(PlaceFrameQueryVO pfq);
    /**
     * @description: 校验会员是否在某会员推荐线
     * @author: zhang jing
     * @date: 2024/7/22 14:22
     * @param: [pfq]
     * @return: com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO
     **/
    PlaceFrameQueryVO checkParentMemberQuery(PlaceFrameQueryVO pfq);

    /**
     * @description: 查询会员推荐伞下第一层会员
     * @author: zhang jing
     * @date: 2024/7/17 9:23
     * @param: [pfq]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO>
     **/
    List<PlaceFrameQueryVO> parentMemberQuery(PlaceFrameQueryVO pfq);

    /**
     * @description: 查询本期推荐伞下第一层会员
     * @author: zhang jing
     * @date: 2024/7/24 9:33
     * @param: [pfq]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO>
     **/
    List<PlaceFrameQueryVO> parentBefMemberQuery(PlaceFrameQueryVO pfq);




    /**
     * @description: 推荐数据查询
     * @author: zhang jing
     * @date: 2024/7/16 16:23
     * @param: [pfq]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO>
     **/
    List<PlaceFrameQueryVO> parentFrameQuery(PlaceFrameQueryVO pfq);

    /**
     * @description: 查询本期推荐伞下业绩和新增人数
     * @author: zhang jing
     * @date: 2024/7/24 10:46
     * @param: [pfq]
     * @return: java.util.List<com.hzs.member.achieve.controller.vo.PlaceFrameQueryVO>
     **/
    List<PlaceFrameQueryVO> parentBefFrameQuery(PlaceFrameQueryVO pfq);

}
