package com.cab.service;

import java.util.Date;
import java.util.List;

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

import com.cab.dao.CabMymessageMapper;
import com.cab.dao.CabThirdPartyMapper;
import com.cab.model.CabThirdParty;
import com.cab.model.MyMessageCount;
import com.cku.dao.CkuDvUserMapper;
import com.cku.dao.CkuMyMatchMapper;
import com.cku.dao.SPOrderInfoMapper;
import com.cku.model.CkuDvUserModel;
import com.cku.model.CkuMyMatchModel;

/**
 *user chaixueteng
 *2016年5月3日
 */
@Service("MyMessageCountService")
public class MyMessageCountServiceImpl {
	@Autowired
	public CabThirdPartyMapper cabThirdPartyMapper;
	@Autowired
	public CkuDvUserMapper ckuDvUserMapper;
	@Autowired
	public CkuMyMatchMapper ckuMyMatchMapper;
	@Autowired
	public CabMymessageMapper cabMymessageMapper;
	@Autowired
	public SPOrderInfoMapper spOrderInfoMapper;
	
	public MyMessageCount getMessageCount(Long userId) {
		MyMessageCount myMessageCount = new MyMessageCount();
		//得到未读消息总数
		long mymessageCountByRead = cabMymessageMapper.getMymessageCountByRead(userId);
		myMessageCount.setMyMessageCount(mymessageCountByRead);
		String dvUserId = "-1";
		String ckuId = "-1";
		//根据cab用户id查询出第三方表中对应的CKU账号信息
		CabThirdParty cabThirdParty = cabThirdPartyMapper.selectByUserId(new Long(userId).intValue());
		if(cabThirdParty != null){
			dvUserId = cabThirdParty.getCkuUserId();
		}
		//根据CKU账号id查询出CKU账号信息
		CkuDvUserModel ckuDvUserModel = ckuDvUserMapper.getckuMemberByUserId(dvUserId);
		if(ckuDvUserModel != null){
			ckuId = ckuDvUserModel.getCkuId();
		}
		//根据会员号和支付状态得到未支付的订单数
		long UnPayOrderCount=spOrderInfoMapper.getCountByUnPay(ckuId);
		//得到已支付的订单数
		long payOrderCount=spOrderInfoMapper.getCountByPay(ckuId);
		myMessageCount.setMyOrderPayCount(payOrderCount);
		myMessageCount.setMyOrderCount(UnPayOrderCount);
		//近期赛事查询条数
		String flag="There";
		int myMatchThereCount = ckuMyMatchMapper.getMyMatchByLoginUser(null, null, ckuId, flag, null).size();
		myMessageCount.setMyCkuMatchCount(myMatchThereCount);
		return myMessageCount;
	}
	
}
