package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.OrderDeliveryGoodsMapper;
import com.gxwebsoft.shop.service.OrderDeliveryGoodsService;
import com.gxwebsoft.shop.entity.OrderDeliveryGoods;
import com.gxwebsoft.shop.param.OrderDeliveryGoodsParam;
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-24 01:39:23
 */
@Service
public class OrderDeliveryGoodsServiceImpl extends ServiceImpl<OrderDeliveryGoodsMapper, OrderDeliveryGoods> implements OrderDeliveryGoodsService {

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

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

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

}
