package com.hzs.member.achieve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzs.common.domain.member.achieve.CuMemberTree;
import com.hzs.common.domain.member.ext.CuMemberSettleDExt;
import com.hzs.common.domain.member.ext.CuMemberSettleExt;
import com.hzs.member.achieve.param.MemberParentCountParam;
import com.hzs.member.census.param.CensusSummaryParam;
import com.hzs.member.census.vo.CensusSummaryVo;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 会员网体历史记录 Mapper 接口
 * </p>
 *
 * @author hzs
 * @since 2022-10-31
 */
public interface CuMemberTreeMapper extends BaseMapper<CuMemberTree> {

    /**
     * 判断是否存在临时表
     *
     * @param tableName 表名
     * @Description:
     * @return: void
     * @Author: sui q
     * @Date: 2022/4/13 19:34
     */
    Integer queryExistOracleTable(String tableName);

    /**
     * 根据会员编号查询会员历史业绩、网体记录，用于结算前7天-到前2天
     *
     * @param pkMember        会员主键
     * @param period          期间
     * @param settleTableName 需要结算的表
     * @return: List<CuMemberTreeExt>
     * @Author: sui q
     * @Date: 2022/10/31 15:53
     */
    List<CuMemberSettleExt> queryCuMemberTreeExt(@Param("pkMember") Long pkMember, @Param("period") Integer period,
                                                 @Param("settleTableName") String settleTableName);

    /**
     * 查询历史会员网体信息,查询某一天免考的会员
     *
     * @param tableName 结算表
     * @return: List<CuMemberSettleExt>
     * @Author: sui q
     * @Date: 2022/11/8 18:44
     */
    List<CuMemberSettleExt> queryExemptCuMemberSettle(String tableName);

    /**
     * 查询出符合下一等级足够业绩的会员
     *
     * @param settleTableName 结算表
     * @return: List<CuMemberSettleExt>
     * @Author: sui q
     * @Date: 2022/11/4 17:41
     */
    List<CuMemberSettleExt> queryCuMemberSettleEnoughAwardAchieve(String settleTableName);


    /**
     * 查询会员结算表，查询出结算表中会员伞下左右区满足等级
     *
     * @param settleTableName 结算表
     * @param awardsValue     验证等级对应的值
     * @param placeDept       部门
     * @param pkMember        会员
     * @return: List<CuMemberSettleExt>
     * @Author: sui q
     * @Date: 2022/11/4 18:21
     */
    Integer queryCuMemberSettlePlaceUnderUmbrella(@Param("settleTableName") String settleTableName,
                                                                  @Param("awardsValue") Integer awardsValue,
                                                                  @Param("placeDept") Integer placeDept,
                                                                  @Param("pkMember") Long pkMember);

    /**
     * 查询会员结算表，查询出结算表中会员血缘关系满足等级
     *
     * @param settleTableName       结算表
     * @param pkMember              会员
     * @return: List<CuMemberSettleExt>
     * @Author: sui q
     * @Date: 2022/11/4 18:21
     */
    Integer queryCuMemberSettleBloodUnderUmbrella(@Param("settleTableName") String settleTableName,
                                                  @Param("awardsValue") Integer awardsValue,
                                                  @Param("placeDept") Integer placeDept,
                                                  @Param("pkMember") Long pkMember);

    /**
     * 根据pkmember查询
     *
     * @param pkMember
     * @return
     */
    CuMemberSettleExt queryCuMemberTreeByPkMemberTable( @Param("pkMember") Long pkMember);

    /**
     * 查询推荐关系
     *
     * @param settleTableName
     * @param pkMember
     * @return
     */
    List<CuMemberSettleExt> queryCuMemberTreeParentTable(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember,  @Param("level") Integer level);

    /**
     * 查询直推人数
     *
     * @param settleTableName
     * @param pkMember
     * @return
     */
    Long queryCuMemberTreeParentTableCount(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember);

    /**
     * 查询历史安置上下级
     *
     * @param settleTableName
     * @param pkMember
     * @return
     */
    List<CuMemberSettleExt> queryCuMemberTreePlaceParentHistoryTable(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember, @Param("memberIdList") List<Long> memberIdList,@Param("level") Integer level);

    /**
     * 查询每一期汇总
     *
     * @param settleTableName
     * @return
     */
    CensusSummaryVo queryCuMemberTreeParentSumTable(@Param("tableName") String settleTableName,@Param("censusSummaryParam") CensusSummaryParam censusSummaryParam);

    /*
     * description: 查询历史网体的最末安置人，左右区一起查出来
     * @author: sui q
     * @date: 2023/4/6 17:35
     * @param:
     **/
    List<CuMemberSettleExt> queryCuMemberTreeLastPlaceParent(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember);

    /*
     * description: 查询
     * @author: sui q
     * @date: 2023/4/6 18:46
     * @param: settleTableName 结算国家
     * @param: pkMember 会员
     **/
    List<CuMemberSettleExt> queryCuMemberTree(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember, @Param("pkPlaceParent") Long pkPlaceParent);
    /**
     * 查询秒结表会员信息
     * @param pkMember
     * @param settleTableName
     * @return
     */
    List<CuMemberSettleExt> selectByTreeMemberList(@Param("pkMember") Long pkMember,@Param("tableName") String settleTableName,@Param("level") Integer level);
    /**
     * 查询会员真实业绩
     * @param pkMember
     * @return
     */
    CuMemberSettleExt getCuMemberRealPerformanceByMemberId(@Param("pkMember") Long pkMember,@Param("tableName") String tableName);
    /**
     * 查询安置左右区人数
     * @param memberId  会员id
     * @param placeDept
     * @return
     */
    Long queryPlaceParentPeopleNumber(@Param("memberId") Long memberId,@Param("placeDept") Integer placeDept);
    /**
     * 查询推荐大小区人数
     * @param memberId
     * @param placeDept
     * @return
     */
    Long queryParentPeopleNumber(@Param("memberId") Long memberId,@Param("placeDept") Integer placeDept);
    /**
     * 查询秒结表是否有值
     * @param settleTableName
     * @return
     */
    Long selectByselectByTreeMemberCount(@Param("tableName") String settleTableName,@Param("pkMember") Long pkMember);
    /**
     * 查询伞下安置新增业绩
     * @param settleTableName
     * @param pkMember
     * @return
     */
    List<CuMemberSettleExt> brollyBelowResettle(@Param("tableName") String settleTableName,@Param("pkMember") Long pkMember);
    /**
     * 根据pkmember查询 关联parent
     * @param settleTableName
     * @param pkMember
     * @return
     */
    CuMemberSettleExt queryCuMemberTreeByPlacePkMemberTable(@Param("tableName") String settleTableName,@Param("pkMember") Long pkMember);

    /**
     * 查询会员直推人数
     * @param memberIds
     * @return
     */
    List<MemberParentCountParam> queryByMemberParentCount(@Param("memberIds") List<Long> memberIds);
    /**
     * 查询会员直推业绩
     * @param settleTableName
     * @param memberIds
     * @return
     */
    List<MemberParentCountParam> queryByMemberParentSumPv(@Param("tableName") String settleTableName,@Param("memberIds") List<Long> memberIds);
    /**
     * 查询历史安置架构
     * @param settleTableName
     * @param pkMember
     * @param memberIdList
     * @param level
     * @return
     */
    List<CuMemberSettleExt> queryCuMemberTreePlaceParentHistoryFramework(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember, @Param("memberIdList") List<Long> memberIdList,@Param("level") Integer level);

    /**
     * 查询历史推荐上下架
     * @param settleTableName
     * @param pkMember
     * @param level
     * @return
     */
    List<CuMemberSettleExt> queryCuMemberTreeParentHistoryFramework(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember,  @Param("level") Integer level);

    /**
     * 查询历史会员直推人数
     * @param memberIds
     * @param settleTableName
     * @return
     */
    List<MemberParentCountParam> queryByMemberParentAndMemberSettleCount(@Param("memberIds") List<Long> memberIds,@Param("settleTableName") String settleTableName);
    /**
     * 查询会员历史直推业绩
     * @param settleTableName
     * @param memberIds
     * @return
     */
    List<MemberParentCountParam> queryByMemberParentSettleSumPv(@Param("tableName") String settleTableName,@Param("memberIds") List<Long> memberIds);
    /**
     * 查询会员业绩表
     * @param settleTableName
     * @param pkMembers
     * @return
     */
    List<CuMemberSettleDExt> queryMemberSettle(@Param("tableName") String settleTableName, @Param("pkMembers") List<Long> pkMembers, @Param("level") Integer level);

    /**
     *
     * @param settleTableName
     * @param pkMember
     * @return
     */
    CuMemberSettleExt queryCuMemberTreeByParentPkMemberTable(@Param("tableName") String settleTableName,@Param("pkMember") Long pkMember);

    /**
     * 查询推荐关系
     * @param settleTableName
     * @param pkMember
     * @param level
     * @return
     */
    List<CuMemberSettleExt> queryCuMemberTreeParentIdTable(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember,  @Param("level") Integer level);
}
