package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.entity.CmsBanner;
import com.gxwebsoft.cms.mapper.CmsBannerMapper;
import com.gxwebsoft.cms.param.CmsBannerParam;
import com.gxwebsoft.cms.service.CmsBannerService;
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 WorkBuddy
 * @since 2026-07-17
 */
@Service
public class CmsBannerServiceImpl extends ServiceImpl<CmsBannerMapper, CmsBanner> implements CmsBannerService {

    @Override
    public PageResult<CmsBanner> pageRel(CmsBannerParam param) {
        PageParam<CmsBanner, CmsBannerParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number asc, create_time desc");
        IPage<CmsBanner> result = page(page, page.getOrderWrapper());
        return new PageResult<>(result.getRecords(), result.getTotal());
    }

    @Override
    public List<CmsBanner> listRel(CmsBannerParam param) {
        PageParam<CmsBanner, CmsBannerParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number asc, create_time desc");
        return list(page.getOrderWrapper());
    }

    @Override
    public CmsBanner getByIdRel(Integer bannerId) {
        return getById(bannerId);
    }
}
