package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.OrderDeliveryMapper;
import com.gxwebsoft.shop.service.OrderDeliveryService;
import com.gxwebsoft.shop.entity.OrderDelivery;
import com.gxwebsoft.shop.param.OrderDeliveryParam;
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 OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryMapper, OrderDelivery> implements OrderDeliveryService {

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

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

    @Override
    public OrderDelivery getByIdRel(Integer deliveryId) {
        OrderDeliveryParam param = new OrderDeliveryParam();
        param.setDeliveryId(deliveryId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
