package com.gxwebsoft.common.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.Cart;
import com.gxwebsoft.common.system.mapper.CartMapper;
import com.gxwebsoft.common.system.param.CartParam;
import com.gxwebsoft.common.system.service.CartService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 购物车Service实现
 *
 * @author 科技小王子
 * @since 2024-10-26 10:54:51
 */
@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(Long id) {
        CartParam param = new CartParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
