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.achieve.ext.CuMemberRetailSExt;
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 tableName
     * @param pkMember
     * @return
     */
    CuMemberSettleExt queryCuMemberTreeByPkMemberTable(@Param("tableName") String tableName, @Param("pkMember") Long pkMember);

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

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

    /**
     * 查询秒结表是否有值
     *
     * @param settleTableName
     * @param pkMember
     * @return
     */
    Long selectByTreeMemberCount(@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
     */
    CuMemberRetailSExt queryCuMemberTreeByPlacePkMemberTable(@Param("tableName") String settleTableName,
                                                             @Param("pkMember") Long pkMember);

    /**
     * 查询会员直推人数
     *
     * @param memberIds
     * @return
     */
    List<MemberParentCountParam> queryByMemberParentCount(@Param("memberIds") List<Long> memberIds);

    /**
     * 查询历史会员直推人数
     *
     * @param memberIds
     * @param settleTableName
     * @return
     */
    List<MemberParentCountParam> queryByMemberParentAndMemberSettleCount(@Param("memberIds") List<Long> memberIds,
                                                                         @Param("settleTableName") String settleTableName);

}
