package com.hzs.bonus.achieve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzs.bonus.achieve.param.MemberAchieveParam;
import com.hzs.common.domain.member.achieve.CuMemberAchieve;
import com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt;
import com.hzs.bonus.achieve.param.MonthAchieveParam;
import com.hzs.bonus.achieve.vo.CuMemberAwardsUnderVO;
import com.hzs.bonus.achieve.vo.CuMemberMonthAchieveContrastVO;
import com.hzs.bonus.achieve.vo.CuMemberNewAddAchieveVO;
import com.hzs.common.domain.member.swing.ext.CuMemberSwingNetExt;
import org.apache.ibatis.annotations.Param;

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

/**
 * 会员业绩记录 Mapper 接口
 *
 * @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);

    /*
     * @description: 查询每月月业绩，获得血缘业绩 首购复购
     * @author: sui q
     * @date: 2023/12/11 15:36
     * @param: null null
     **/
    List<CuMemberAchieveExt> queryCuMemberMonthAchieveByMemberIdList(@Param("settleTableName") String settleTableName, @Param("memberSwingNetExtList") List<CuMemberSwingNetExt> memberSwingNetExtList);

    /**
     * 将结算日表的值插入到结算月表中
     *
     * @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);

    /**
     * 将昨天日表数据插入今天日表中, 昨日日表更新今天日表网体表
     * 根据昨天结算表数据更新今天结算表的业绩数据
     *
     * @param sourceTable 来源表，记录10天跟月表一摸一样的滚动表数据
     * @param targetTable 目标表 记录10天跟月表一摸一样的滚动表数据
     * @return: void
     * @Author: sui q
     * @Date: 2022/10/31 16:26
     */
    void updateCuMemberExpandSettleAchieveByBeforeDay(@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: 2024/5/23 11:37
     * @param: null null
     **/
    void mergeCuMemberSettleByAchieveLogByDate(@Param("targetTable") String targetTable, @Param("settleDate") Date settleDate);

    /*
     * @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);

    /*
     * @description: 退单回退业绩
     * @author: sui q
     * @date: 2023/9/22 9:27
     * @param: null null
     **/
    void chargeBackSaOrder(@Param("targetTable") String targetTable, @Param("sourceTable") String sourceTable,
                           @Param("period") Integer period, @Param("achieve") MemberAchieveParam memberAchieveParam);

    /**
     * 根据每日日业绩开始更新会员业绩 新增业绩、累计业绩、新増金额、累计金额
     *
     * @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 currentSettleTableName 更新甩网业绩
     * @return: void
     * @Author: sui q
     * @Date: 2022/11/3 13:56
     */
    void updateCuMemberNetAchieve(@Param("updMemberAchieveExtList") List<CuMemberAchieveExt> updMemberAchieveExtList, @Param("tableName") String currentSettleTableName);

    /**
     * 查询会员最新业绩
     *
     * @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
     */
    CuMemberAwardsUnderVO selectAwardsByPkMember(CuMemberAwardsUnderVO memberAwardsUnderVO);

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


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

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

    /**
     * 查询推荐业绩
     *
     * @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);

    /*
     * @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);
}
