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.CuMemberSettleExt;
import com.hzs.member.achieve.param.MemberParentCountParam;
import com.hzs.member.achieve.vo.CuMemberAwardsUnderVO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

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

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

    /**
     * 查询会员结算表，查询出结算表中会员伞下左右区满足等级
     *
     * @param settleTableName 结算表
     * @param awardsValue     验证等级对应的值
     * @param placeDept       部门
     * @param pkMember        会员
     */
    Integer queryCuMemberSettlePlaceUnderUmbrella(@Param("settleTableName") String settleTableName,
                                                  @Param("awardsValue") Integer awardsValue,
                                                  @Param("placeDept") Integer placeDept,
                                                  @Param("pkMember") Long pkMember);

    /**
     * 查询会员结算表，查询出结算表中会员血缘关系满足等级
     *
     * @param settleTableName 结算表
     * @param pkMember        会员
     */
    Integer queryCuMemberSettleBloodUnderUmbrella(@Param("settleTableName") String settleTableName,
                                                  @Param("awardsValue") Integer awardsValue,
                                                  @Param("placeDept") Integer placeDept,
                                                  @Param("pkMember") Long pkMember);

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

    /**
     * 查询推荐关系
     *
     * @param settleTableName
     * @param pkMember
     * @param vertexIdList    体系
     * @return
     */
    List<CuMemberSettleExt> queryCuMemberTreeParentTable(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember, @Param("level") Integer level, @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
     */
    List<CuMemberSettleExt> queryCuMemberTreePlaceParentHistoryTable(@Param("tableName") String settleTableName, @Param("pkMember") Long pkMember, @Param("memberIdList") List<Long> memberIdList, @Param("level") Integer level);

    /**
     * 查询秒结表会员信息
     *
     * @param pkMember
     * @param settleTableName
     * @return
     */
    List<CuMemberSettleExt> selectByTreeMemberList(@Param("pkMember") Long pkMember, @Param("tableName") String settleTableName, @Param("level") Integer level, @Param("vertexIdList") List<Integer> vertexIdList);

    /**
     * 查询秒结表是否有值
     *
     * @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 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 pkMember
     * @param level
     * @return
     */
    List<CuMemberSettleExt> selectByTreeMemberListFive(@Param("pkMember") Long pkMember, @Param("level") Integer level, @Param("vertexIdList") List<Integer> vertexIdList);

    /**
     * 查询会员显示业绩
     *
     * @param settleTable
     * @param pkMember
     * @param monthTable
     * @return
     */
    CuMemberAwardsUnderVO queryMemberPv(@Param("settleTable") String settleTable,
                                        @Param("pkMember") Long pkMember,
                                        @Param("monthTable") String monthTable);

    /**
     * 查询会员当天业绩
     *
     * @param pkMember
     * @return
     */
    CuMemberAwardsUnderVO queryMemberTodayPv(@Param("pkMember") Long pkMember);

}
