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.util.Date;
import java.util.List;

/**
 * 会员业绩记录 Mapper 接口
 */
public interface CuMemberAchieveMapper extends BaseMapper<CuMemberAchieve> {

    /**
     * 创建会员网体记录表
     *
     * @param tableName 日期
     */
    void createCuMemberAchieveTable(String tableName);

    /**
     * 创建每年的会员考核表
     *
     * @param tableName 表名
     */
    void createCuMemberMonthTable(String tableName);

    /*
     * 更新会员业绩表 每月月统计报表
     **/
    void mergeCuMemberMonth(@Param("date") String date, @Param("period") Integer period);

    /**
     * 将结算日表的值插入到结算月表中
     *
     * @param targetTableName 目标表 网体月表
     * @param sourceTableName 来源表 结算日表
     * @param period          期间
     */
    void insertCuMemberAchieveBySettleDate(@Param("targetTableName") String targetTableName,
                                           @Param("sourceTableName") String sourceTableName, @Param("period") Integer period);

    /**
     * 将结算日表的值插入到结算月表中
     *
     * @param targetTableName 目标表 网体月表
     * @param sourceTableName 来源表 结算日表
     * @param period          期间
     */
    void mergeCuMemberAchieveBySettleDate(@Param("targetTableName") String targetTableName,
                                          @Param("sourceTableName") String sourceTableName, @Param("period") Integer period);

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

    /*
     *  更新为最初始的数据，新增的为0，历史的通过昨天进行更新
     **/
    void updateCuMemberSettleInitAchieve(String targetTable);

    /**
     * 根据特殊业务更新业绩
     *
     * @param targetTable 结算表
     * @param period      期间
     * @param pkId        主键
     */
    void updateCuMemberSettleAchieveBySpecialBus(@Param("targetTable") String targetTable, @Param("period") Integer period,
                                                 @Param("pkId") Long pkId);

    /*
     *  根据到期日期更新业绩，到期后需要还原到实际累计金额
     **/
    void updateCuMemberSettleAchieveByDueDate(@Param("currentTableName") String currentTableName, @Param("yesTableName") String yesTableName,
                                              @Param("currentDate") Date currentDate);


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

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

    /**
     * 查询会员最新业绩
     *
     * @param pkMember  会员主键
     * @param pkCountry 公司
     * @param tableName 结算表
     */
    CuMemberAchieve queryCuMemberAchieveByPkMember(@Param("pkMember") Long pkMember, @Param("pkCountry") Integer pkCountry, @Param("tableName") String tableName);

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

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

    /**
     * 根据用户ID查询结余大小信息
     *
     * @param memberAwardsUnderVO 奖衔VO
     * @return CuMemberAwardsUnderVO
     */
    CuMemberAwardsUnderVO selectBalanceByPkMember(CuMemberAwardsUnderVO memberAwardsUnderVO);

    /**
     * 查询本月小区新增业绩
     *
     * @param memberAwardsUnderVO 入参
     * @return CuMemberAwardsUnderVO
     */
    CuMemberAwardsUnderVO selectMemberSmallAchieve(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);

    /**
     * 查询左右区新增业绩
     **/
    PlaceNewAddAchieveVO selectNewABAchieve(PlaceNewAddAchieveVO pna);

    List<PlaceNewAddAchieveVO> selectABDirectAchieve(PlaceNewAddAchieveVO pna);

    /**
     * 月度业绩-左右区人数详情(最新)
     **/
    List<PlaceNewAddAchieveVO> placeNewAddAchieveDetails(PlaceNewAddAchieveVO pna);

    /**
     * 月度业绩-左右区人数详情(历史)
     **/
    List<PlaceNewAddAchieveVO> placeNewAddAchieveHistoryDetails(PlaceNewAddAchieveVO pna);

    /**
     * 月度业绩-左右区业绩详情
     **/
    List<PlaceNewAddAchieveVO> leftRightAchieveDetails(PlaceNewAddAchieveVO pna);

    /**
     * 月度业绩-左右区血缘业绩详情
     **/
    List<PlaceNewAddAchieveVO> leftRightDirectAchieveDetails(PlaceNewAddAchieveVO pna);

    /**
     * 月度业绩-查询血缘业绩详情
     **/
    List<PlaceNewAddAchieveVO> directAchieveDetails(PlaceNewAddAchieveVO pna);

    /**
     * 查询直推业绩
     **/
    PlaceNewAddAchieveVO selectParentAchieve(PlaceNewAddAchieveVO pna);

    /**
     * 查询左右区人数
     **/
    List<PlaceNewAddAchieveVO> selectABCoun(PlaceNewAddAchieveVO pna);

    /**
     * 查询最新月份左右区人数
     **/
    List<PlaceNewAddAchieveVO> selectABNewMonthCoun(PlaceNewAddAchieveVO pna);

    /**
     * 查询各个等级直推人数和业绩
     **/
    List<ParentAchieveVO> selectParentCounAchieve(ParentAchieveVO pav);

    /**
     * 查询本人直推业绩
     **/
    List<ParentAchieveVO> selfParentCounAchieve(ParentAchieveVO pav);

    /**
     * 查询前10直推业绩
     **/
    List<ParentAchieveVO> parentCounAchieveTop(ParentAchieveVO pav);

    /**
     * 直推业绩前十人伞下等级业绩
     **/
    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);

    /*
     *  更新会员的业绩
     **/
    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);

    /*
     *  查询月统计数据，按照月倒叙
     **/
    List<CuMemberAchieveExt> queryMemberMonthAchieve(@Param("pkMember") Long pkMember, @Param("monthList") List<String> monthList);

    /*
     *  查询会员一代伞下
     **/
    List<Long> queryPkMemberMonthAchieve(@Param("month") String month, @Param("pkMember") Long pkMember);

    /*
     *  查询月统计数据，查询明细
     **/
    List<CuMemberAchieveExt> queryMemberMonthAchieveDetail(@Param("monthAchieveParam") MonthAchieveParam monthAchieveParam,
                                                           @Param("memberList") List<Long> memberList);

    /*
     *  查询月统计数据，查询明细，安置伞下
     **/
    List<CuMemberAchieveExt> queryPlaceParentMemberMonthAchieve(MonthAchieveParam monthAchieveParam);

    /*
     *  查询月统计数据，查询明细，安置伞下
     **/
    List<CuMemberAchieveExt> queryParentMemberMonthAchieve(MonthAchieveParam monthAchieveParam);
}
