package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.SplashMapper;
import com.gxwebsoft.shop.service.SplashService;
import com.gxwebsoft.shop.entity.Splash;
import com.gxwebsoft.shop.param.SplashParam;
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-30 22:07:41
 */
@Service
public class SplashServiceImpl extends ServiceImpl<SplashMapper, Splash> implements SplashService {

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

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

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

}
