package cn.newfeifan.mall.module.distri.service.sharepath;

import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.newfeifan.mall.module.distri.dal.dataobject.sharepath.SharePathDO;
import cn.newfeifan.mall.module.distri.dal.mysql.sharepath.SharePathMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分销用户关系 Service 实现类
 *
 * @author 非繁人
 */
@Service
@Validated
public class SharePathServiceImpl implements SharePathService {

    @Resource
    private SharePathMapper sharePathMapper;
    @Override
    public SharePathDO getSharePathByDescendant(Long userId) {

        List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eqIfPresent(SharePathDO::getDescendant, userId)
                .eqIfPresent(SharePathDO::getDepth, 1));
        if (sharePathDOS.isEmpty()) {
            return null;
        }
        return sharePathDOS.get(0);
    }



}