package cn.newfeifan.mall.module.distri.dal.mysql.sharepath;


import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
import cn.newfeifan.mall.module.distri.controller.app.sharepath.vo.SharePathPageReqVO;
import cn.newfeifan.mall.module.distri.dal.dataobject.sharepath.SharePathDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 分销用户关系 Mapper
 *
 * @author 非繁人
 */
@Mapper
public interface SharePathMapper extends BaseMapperX<SharePathDO> {

    default PageResult<SharePathDO> selectPage(SharePathPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SharePathDO>()
                .eqIfPresent(SharePathDO::getDepth, reqVO.getDepth())
                .betweenIfPresent(SharePathDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SharePathDO::getId));
    }


    int getMaxSortByParentId(@Param("parentId") Long parentId);

    // 删除节点及其子节点的旧祖先关系
    void deleteOldAncestors(@Param("nodeId") Long nodeId);

    // 添加节点及其子节点的新祖先关系
    void addNewAncestors(@Param("nodeId") Long nodeId, @Param("newParentId") Long newParentId);

    Long getAncestorIncreaseIntegralByUserId(@Param("userId") Long userId);

    List<SharePathDO> selectListByUserId(@Param("referrerId") Long referrerId);
}