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

import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.newfeifan.mall.module.distri.controller.admin.sharepath.vo.*;
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())
                .eqIfPresent(SharePathDO::getAncestor, reqVO.getAncestor())
                .eqIfPresent(SharePathDO::getDescendant, reqVO.getDescendant())
                .eqIfPresent(SharePathDO::getSort, reqVO.getSort())
                .likeIfPresent(SharePathDO::getAncName, reqVO.getAncName())
                .eqIfPresent(SharePathDO::getAncPhone, reqVO.getAncPhone())
                .likeIfPresent(SharePathDO::getDescName, reqVO.getDescName())
                .eqIfPresent(SharePathDO::getDescPhone, reqVO.getDescPhone())
                .likeIfPresent(SharePathDO::getAncNickName, reqVO.getAncNickName())
                .likeIfPresent(SharePathDO::getDescNickName, reqVO.getDescNickName())
                .orderByDesc(SharePathDO::getId));
    }

    void addNode(@Param("parentId") Long parentId,
                 @Param("parentName") String parentName,
                 @Param("parentNickName") String parentNickName,
                 @Param("parentMobile") String parentMobile,

                 @Param("newDescendantId") Long newDescendantId,
                 @Param("newDescendantName") String newDescendantName,
                 @Param("newDescendantNickName") String newDescendantNickName,
                 @Param("newDescendantMobile") String newDescendantMobile);


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

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

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

}




