package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.OrderGoodsMapper;
import com.gxwebsoft.shop.service.OrderGoodsService;
import com.gxwebsoft.shop.entity.OrderGoods;
import com.gxwebsoft.shop.param.OrderGoodsParam;
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 2022-12-09 17:15:31
 */
@Service
public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGoods> implements OrderGoodsService {

    @Override
    public List<OrderGoods> listByOrderIds(List<Integer> orderIds) {
      return baseMapper.selectByOrderIds(orderIds);
    }

    @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 orderGoodsId) {
        OrderGoodsParam param = new OrderGoodsParam();
        param.setOrderGoodsId(orderGoodsId);
        return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public int countBySettled(OrderGoodsParam param) {
        return baseMapper.selectCountBySettled(param);
    }
}
