package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.SwiperMapper;
import com.gxwebsoft.shop.service.SwiperService;
import com.gxwebsoft.shop.entity.Swiper;
import com.gxwebsoft.shop.param.SwiperParam;
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 SwiperServiceImpl extends ServiceImpl<SwiperMapper, Swiper> implements SwiperService {

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

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

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

}
