package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.CartMapper;
import com.gxwebsoft.shop.service.CartService;
import com.gxwebsoft.shop.entity.Cart;
import com.gxwebsoft.shop.param.CartParam;
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-11-25 19:04:43
 */
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements CartService {

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

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

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

}
