package com.gxwebsoft.common.system.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.common.system.entity.OrderGoods;
import com.gxwebsoft.common.system.mapper.OrderGoodsMapper;
import com.gxwebsoft.common.system.param.OrderGoodsParam;
import com.gxwebsoft.common.system.service.OrderGoodsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单商品Service实现
 *
 * @author 科技小王子
 * @since 2024-10-26 12:18:05
 */
@Service
public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGoods> implements OrderGoodsService {

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

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

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

}
