package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.WebsiteMapper;
import com.gxwebsoft.cms.service.WebsiteService;
import com.gxwebsoft.cms.entity.Website;
import com.gxwebsoft.cms.param.WebsiteParam;
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-03-04 21:14:15
 */
@Service
public class WebsiteServiceImpl extends ServiceImpl<WebsiteMapper, Website> implements WebsiteService {

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

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

    @Override
    public Website getByIdRel(Integer websiteId) {
        WebsiteParam param = new WebsiteParam();
        param.setWebsiteId(websiteId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
