package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.OaLinkMapper;
import com.gxwebsoft.oa.service.OaLinkService;
import com.gxwebsoft.oa.entity.OaLink;
import com.gxwebsoft.oa.param.OaLinkParam;
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-09-10 20:57:42
 */
@Service
public class OaLinkServiceImpl extends ServiceImpl<OaLinkMapper, OaLink> implements OaLinkService {

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

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

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

}
