package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.LinkMapper;
import com.gxwebsoft.apps.service.LinkService;
import com.gxwebsoft.apps.entity.Link;
import com.gxwebsoft.apps.param.LinkParam;
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 2022-11-25 12:55:33
 */
@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link> implements LinkService {

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

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

    @Override
    public Link getByIdRel(Integer linkId) {
        LinkParam param = new LinkParam();
        param.setLinkId(linkId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
