package com.ruoyi.mall.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallMemberCartMapper;
import com.ruoyi.mall.domain.MallMemberCart;
import com.ruoyi.mall.service.IMallMemberCartService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 购物车Service业务层处理
 * 
 * @author chang
 * @date 2021-11-25
 */
@Service
public class MallMemberCartServiceImpl implements IMallMemberCartService 
{
    @Autowired
    private MallMemberCartMapper mallMemberCartMapper;

    /**
     * 查询购物车
     * 
     * @param id 购物车主键
     * @return 购物车
     */
    @Override
    public MallMemberCart selectMallMemberCartById(Long id)
    {
        return mallMemberCartMapper.selectMallMemberCartById(id);
    }

    /**
     * 查询购物车列表
     * 
     * @param mallMemberCart 购物车
     * @return 购物车
     */
    @Override
    public List<MallMemberCart> selectMallMemberCartList(MallMemberCart mallMemberCart)
    {
        return mallMemberCartMapper.selectMallMemberCartList(mallMemberCart);
    }

    /**
     * 新增购物车
     * 
     * @param mallMemberCart 购物车
     * @return 结果
     */
    @Override
    public int insertMallMemberCart(MallMemberCart mallMemberCart)
    {
        return mallMemberCartMapper.insertMallMemberCart(mallMemberCart);
    }

    /**
     * 修改购物车
     * 
     * @param mallMemberCart 购物车
     * @return 结果
     */
    @Override
    public int updateMallMemberCart(MallMemberCart mallMemberCart)
    {
        return mallMemberCartMapper.updateMallMemberCart(mallMemberCart);
    }

    /**
     * 批量删除购物车
     * 
     * @param ids 需要删除的购物车主键
     * @return 结果
     */
    @Override
    public int deleteMallMemberCartByIds(Long[] ids)
    {
        return mallMemberCartMapper.deleteMallMemberCartByIds(ids);
    }

    /**
     * 删除购物车信息
     * 
     * @param id 购物车主键
     * @return 结果
     */
    @Override
    public int deleteMallMemberCartById(Long id)
    {
        return mallMemberCartMapper.deleteMallMemberCartById(id);
    }

    /*
    * 批量删除购物车
    * */
    @Transactional
    @Override
    public void removeByUserIdAndCardIds(String cartsId, String userId) {
        String[] cartIdList = cartsId.split(",");
        for (String cartId :cartIdList) {
            MallMemberCart cart = new MallMemberCart();
            cart.setId(Long.parseLong(cartId));
            cart.setUserId(Long.parseLong(userId));
            mallMemberCartMapper.deleteMallMemberCartByCart(cart);
        }
    }

    @Override
    public MallMemberCart selectMallMemberCartByCart(MallMemberCart cart) {
        return mallMemberCartMapper.selectMallMemberCartByCart(cart);
    }
}
