package com.iamberry.wechat.service.cart.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.iamberry.wechat.core.entity.PaperBean;
import com.iamberry.wechat.core.entity.cart.CartDto;
import com.iamberry.wechat.core.entity.cart.ShopOrderAndItemDto;
import com.iamberry.wechat.core.entity.cart.ShopOrderItemDto;
import com.iamberry.wechat.core.entity.cart.ShopSalesOrderDto;
import com.iamberry.wechat.core.entity.coupon.CouponItem;
import com.iamberry.wechat.core.entity.coupon.CouponType;
import com.iamberry.wechat.core.entity.order.Order;
import com.iamberry.wechat.core.entity.order.OrderItem;
import com.iamberry.wechat.service.cart.dao.CartDao;
import com.iamberry.wechat.service.mapper.CartMapper;
import com.iamberry.wechat.service.mapper.OrderMapper;

@Repository
public class CartDaoImpl implements CartDao{
	
	@Autowired
	private CartMapper cartMapper;

	@Autowired
	private OrderMapper orderMapper;

	@Override
	public List<CartDto> getCartDtoList(CartDto cartDto) {
		return cartMapper.getCartDtoList(cartDto);
	}

	@Override
	public List<CartDto> selectCartByOpenId(String openId) {
		// TODO Auto-generated method stub
		return cartMapper.selectCartByOpenId(openId);
	}


	@Override
	public Integer getCartNumByCartOpenId(String openId) {
		// TODO Auto-generated method stub
		return cartMapper.getCartNumByCartOpenId(openId);
	}


	@Override
	public Integer updateCartByOpenId(CartDto cartDto) {
		// TODO Auto-generated method stub
		return cartMapper.updateCartByOpenId(cartDto);
	}


	@Override
	public Integer getCartNumByOpenId(CartDto cartDto) {
		// TODO Auto-generated method stub
		return cartMapper.getCartNumByOpenId(cartDto);
	}


	@Override
	public CartDto getCartByCartProductId(CartDto cartDto) {
		// TODO Auto-generated method stub
		return cartMapper.getCartByCartProductId(cartDto);
	}


	@Override
	public Integer addProductToCart(CartDto cartDto) {
		// TODO Auto-generated method stub
		return cartMapper.addProductToCart(cartDto);
	}


	@Override
	public Integer deleteCartByCartId(CartDto cartDto) {
		// TODO Auto-generated method stub
		return cartMapper.deleteCartByCartId(cartDto);
	}


	@Override
	public List<ShopOrderAndItemDto> selectShopOrder(PaperBean paperBean) {
		// TODO Auto-generated method stub
		return cartMapper.selectShopOrder(paperBean);
	}


	@Override
	public List<ShopOrderItemDto> selectShopOrderItem(String itemSalesOrderid) {
		// TODO Auto-generated method stub
		return cartMapper.selectShopOrderItem(itemSalesOrderid);
	}

	@Override
	public ShopSalesOrderDto getShopOrderByOrderId(String salesOrderId,
			String salesOpenId) {
		// TODO Auto-generated method stub
		return cartMapper.getShopOrderByOrderId(salesOrderId, salesOpenId);
	}

	@Override
	public List<CartDto> selectCartItemByListId(Integer[] carts) {
		// TODO Auto-generated method stub
		return cartMapper.selectCartItemByListId(carts);
	}


	@Override
	public Integer insertOrderInfo(Order order) {
		// TODO Auto-generated method stub
		return orderMapper.insertOrderInfo(order);
	}


	@Override
	public Integer insertOrderItemList(List<OrderItem> items) {
		// TODO Auto-generated method stub
		return orderMapper.insertOrderItemList(items);
	}

	/**
	 * 增加数据
	 * @param  orderItem
	 * @return Integer
	 */
	@Override
	public  Integer  save(OrderItem  orderItem){
		return  orderMapper.save(orderItem);
	}


	@Override
	public Integer updateOrderStatus(Order order) {
		// TODO Auto-generated method stub
		return orderMapper.updateOrderStatus(order);
	}


	@Override
	public Integer selectOrderStatusByOrderId(String orderId) {
		// TODO Auto-generated method stub
		return orderMapper.selectOrderStatusByOrderId(orderId);
	}

	@Override
	public Integer updateOrderByOrderId(Order order) {
		// TODO Auto-generated method stub
		return cartMapper.updateOrderByOrderId(order);
	}


	@Override
	public ShopSalesOrderDto getOpenIdAndStatus(String salesOrderid) {
		// TODO Auto-generated method stub
		return cartMapper.getOpenIdAndStatus(salesOrderid);
	}


	@Override
	public Integer deleteBatchCartListById(List<Integer> cartIds) {
		// TODO Auto-generated method stub
		return cartMapper.deleteBatchCartListById(cartIds);
	}


	@Override
	public Order selectOrderInfoById(Order order) {
		// TODO Auto-generated method stub
		return orderMapper.selectOrderInfoById(order);
	}


	@Override
	public Integer getOrderNumByOpenId(PaperBean paperBean) {
		// TODO Auto-generated method stub
		return cartMapper.getOrderNumByOpenId(paperBean);
	}
	
	/**
	 * 根据单号查询该订单的产品总数 
	 * 2016年5月18日
	 * @param orderid
	 * @return
	 */
	public Integer getItemNumByOrderId(String orderid){
		return orderMapper.getItemNumByOrderId(orderid);
	}


	@Override
	public CouponType getCouponReduceByItemId(CouponItem couponItem) {
		// TODO Auto-generated method stub
		return cartMapper.getCouponReduceByItemId(couponItem);
	}


	@Override
	public List<ShopSalesOrderDto> getOrderList(
			ShopSalesOrderDto shopSalesOrderDto) {
		// TODO Auto-generated method stub
		return cartMapper.getOrderList(shopSalesOrderDto);
	}
	
	public Order getRecentOrderAddress(String openid){
		return orderMapper.getOrderAddressInfo(openid);
	}

	@Override
	public Integer selectOrderCount(ShopSalesOrderDto shopSalesOrderDto) {
		// TODO Auto-generated method stub
		return cartMapper.selectOrderCount(shopSalesOrderDto);
	}

	@Override
	public Integer updateOrderSpellOrderId(Order order) {
		return orderMapper.updateOrderSpellOrderId(order);
	}

	@Override
	public Integer selectIsOrder(String oprnId) {
		return orderMapper.selectIsOrder(oprnId);
	}
}
