package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.LinkMapper;
import com.gxwebsoft.oa.service.LinkService;
import com.gxwebsoft.oa.entity.Link;
import com.gxwebsoft.oa.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 2024-01-14 11:50:39
 */
@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("sort_number asc,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("sort_number asc,create_time desc");
        return page.sortRecords(list);
    }

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

}
