package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.GoodsSkuMapper;
import com.gxwebsoft.shop.service.GoodsSkuService;
import com.gxwebsoft.shop.entity.GoodsSku;
import com.gxwebsoft.shop.param.GoodsSkuParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品sku列表Service实现
 *
 * @author 科技小王子
 * @since 2024-07-26 10:49:02
 */
@Service
public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> implements GoodsSkuService {

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

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

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

}
