package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsWebsiteMapper;
import com.gxwebsoft.cms.service.CmsWebsiteService;
import com.gxwebsoft.cms.entity.CmsWebsite;
import com.gxwebsoft.cms.param.CmsWebsiteParam;
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:36:14
 */
@Service
public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebsite> implements CmsWebsiteService {

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

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

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

}
