package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.UserRefereeMapper;
import com.gxwebsoft.shop.service.UserRefereeService;
import com.gxwebsoft.shop.entity.UserReferee;
import com.gxwebsoft.shop.param.UserRefereeParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户推荐关系表Service实现
 *
 * @author 科技小王子
 * @since 2023-04-28 14:07:29
 */
@Service
public class UserRefereeServiceImpl extends ServiceImpl<UserRefereeMapper, UserReferee> implements UserRefereeService {

    @Override
    public PageResult<UserReferee> pageRel(UserRefereeParam param) {
        PageParam<UserReferee, UserRefereeParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<UserReferee> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<UserReferee> listRel(UserRefereeParam param) {
        List<UserReferee> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<UserReferee, UserRefereeParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public UserReferee getByIdRel(Integer id) {
        UserRefereeParam param = new UserRefereeParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
