package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.DealerRefereeMapper;
import com.gxwebsoft.shop.service.DealerRefereeService;
import com.gxwebsoft.shop.entity.DealerReferee;
import com.gxwebsoft.shop.param.DealerRefereeParam;
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 2024-07-28 11:57:41
 */
@Service
public class DealerRefereeServiceImpl extends ServiceImpl<DealerRefereeMapper, DealerReferee> implements DealerRefereeService {

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

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

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

}
