package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopOrderMapper;
import com.gxwebsoft.shop.service.ShopOrderService;
import com.gxwebsoft.shop.entity.ShopOrder;
import com.gxwebsoft.shop.param.ShopOrderParam;
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-10 21:05:07
 */
@Service
public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder> implements ShopOrderService {

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

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

    @Override
    public ShopOrder getByIdRel(Integer orderId) {
        ShopOrderParam param = new ShopOrderParam();
        param.setOrderId(orderId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
