package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopOrderCartInfoMapper;
import com.gxwebsoft.shop.service.ShopOrderCartInfoService;
import com.gxwebsoft.shop.entity.ShopOrderCartInfo;
import com.gxwebsoft.shop.param.ShopOrderCartInfoParam;
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 ShopOrderCartInfoServiceImpl extends ServiceImpl<ShopOrderCartInfoMapper, ShopOrderCartInfo> implements ShopOrderCartInfoService {

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

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

    @Override
    public ShopOrderCartInfo getByIdRel(Long id) {
        ShopOrderCartInfoParam param = new ShopOrderCartInfoParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
