package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsDesignMapper;
import com.gxwebsoft.cms.service.CmsDesignService;
import com.gxwebsoft.cms.entity.CmsDesign;
import com.gxwebsoft.cms.param.CmsDesignParam;
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:47:57
 */
@Service
public class CmsDesignServiceImpl extends ServiceImpl<CmsDesignMapper, CmsDesign> implements CmsDesignService {

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

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

    @Override
    public CmsDesign getByIdRel(Integer pageId) {
        CmsDesignParam param = new CmsDesignParam();
        param.setPageId(pageId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
