package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.entity.Goods;
import com.gxwebsoft.shop.mapper.GoodsMapper;
import com.gxwebsoft.shop.param.GoodsParam;
import com.gxwebsoft.shop.service.GoodsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品记录表Service实现
 *
 * @author 科技小王子
 * @since 2022-11-23 12:47:16
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

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

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

    @Override
    public Goods getByIdRel(Integer goodsId) {
        GoodsParam param = new GoodsParam();
        param.setGoodsId(goodsId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
