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

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.drp.PlaceInfo;
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.StaticCacheMemory;
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;
	public void setAdminBannerService(AdminBannerService adminBannerService) {
		this.adminBannerService = adminBannerService;
	}
	
	@Autowired
	private HomeServiceDao homeServiceDao;
	public void setHomeServiceDao(HomeServiceDao homeServiceDao) {
		this.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 PlaceInfo selectOnePlaceInfoByCode(String code) {
		// TODO Auto-generated method stub
		return homeServiceDao.selectOnePlaceInfoByCode(code);
	}

	
	public Integer updateOpenidById(PlaceInfo info) {
		// TODO Auto-generated method stub
		return homeServiceDao.updateOpenidById(info);
	}

	
	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);
	}
}
