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 org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 会员网体历史记录 Mapper 接口
 */
public interface CuMemberTreeMapper extends BaseMapper<CuMemberTree> {

    /**
     * 判断是否存在临时表
     *
     * @param tableName 表名
     */
    Integer queryExistOracleTable(String tableName);

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