package com.iamberry.wechat.service.home;
import java.util.List;

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

import com.iamberry.wechat.core.entity.banner.ActionBannerImage;
import com.iamberry.wechat.core.entity.member.Member;
import com.iamberry.wechat.face.banner.AdminBannerService;
import com.iamberry.wechat.face.home.HomeService;
import com.iamberry.wechat.service.home.dao.HomeServiceDao;
/**
 * @author 何秀刚
 * Class Description: 首页Service接口
 * Create Date:2016年4月18日
 * Update Date:2016年4月18日
 */
@Service
public class HomeServiceImpl implements HomeService {

	@Autowired
	private AdminBannerService adminBannerService;
	@Autowired
	private HomeServiceDao homeServiceDao;
	
	public List<ActionBannerImage> selectNowBannerByType() {
		// TODO Auto-generated method stub
		return adminBannerService.selectNowBannerByType(null);
	}

	
	public Member selectMemberInfoByOpenId(String openid) {
		// TODO Auto-generated method stub
		return homeServiceDao.selectMemberInfoByOpenId(openid);
	}

	
	public Integer updateWechatMemberInfoByByOpenid(Member member) {
		// TODO Auto-generated method stub
		return homeServiceDao.updateWechatMemberInfoByByOpenid(member);
	}

	
	public Integer insertMemberInfo(Member member) {
		// TODO Auto-generated method stub
		try {
			return homeServiceDao.insertMemberInfo(member);
		} catch (DuplicateKeyException e) { // 报错，触发数据库唯一约束错误，系统捕获，而后对获取数据重头再来
			// TODO: handle exception
			member = homeServiceDao.selectMemberInfoByOpenId(member.getUserOpenid());
			return 1;
		}
	}

	
	public Integer updateUserResAndTypeByOpenid(Member member) {
		// TODO Auto-generated method stub
		return homeServiceDao.updateUserResAndTypeByOpenid(member);
	}

	
	public Integer updateMemberStatusByOpenId(String openid) {
		// TODO Auto-generated method stub
		return homeServiceDao.updateMemberStatusByOpenId(openid);
	}

	
	public Member selectMemberQrcodeUrlByOpenid(String openid) {
		// TODO Auto-generated method stub
		return homeServiceDao.selectMemberQrcodeUrlByOpenid(openid);
	}

	
	public Integer updateMemberQrcodeByOpenid(Member member) {
		// TODO Auto-generated method stub
		return homeServiceDao.updateMemberQrcodeByOpenid(member);
	}
	public Integer selectUserIntegralByOpenid(String openid) {
		// TODO Auto-generated method stub
		return homeServiceDao.selectUserIntegralByOpenid(openid);
	}

	
	public Member selectUserInfoByPlaceId(Integer placeId) {
		// TODO Auto-generated method stub
		return homeServiceDao.selectUserInfoByPlaceId(placeId);
	}
	
	/**
	 * 根据Openid，更新绑定状态
	 * @param member
	 * @return
	 */
	public Integer updateMemberIsFlagByOpenid(Member member) {
		// TODO Auto-generated method stub
		return homeServiceDao.updateMemberIsFlagByOpenid(member);
	}
}
