package com.goafanti.app.service.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.goafanti.app.bo.AppHomePage;
import com.goafanti.app.bo.HomeAchievemend;
import com.goafanti.app.bo.HomeImages;
import com.goafanti.app.service.AppHomePageService;
import com.goafanti.common.dao.AchievementMapper;
import com.goafanti.common.dao.DemandMapper;
import com.goafanti.common.dao.UserIdentityMapper;
import com.goafanti.user.service.UserIdentityService;

@Service
public  class AppHomePageServiceImpl implements AppHomePageService{
	@Autowired
	AchievementMapper	achievementMapper;
	@Autowired
	DemandMapper	demandMapper;
	@Autowired
	UserIdentityMapper	userIdentityMapper;
	@Autowired
	UserIdentityService userIdentityService;
	

	@Override
	public AppHomePage getAppHomePage(HttpServletRequest request) {
		AppHomePage ap=new AppHomePage();
		ap.setHomeImg(new HomeImages().getImagers(request));
		ap.setAdvertising(userIdentityService.advertising());
		List<HomeAchievemend> h=achievementMapper.getAppHomeAchievement();
		for (HomeAchievemend ha : h) {
			if (null!=ha.getImg()&&ha.getImg().indexOf(",")>0) {
				ha.setImg(ha.getImg().substring(0, ha.getImg().indexOf(",")));
			}
		}
		ap.setAchievemend(h);
		return ap;
	}


	@Override
	public List<?> getHomeRecommended(Integer type) {
		if (type==1) {
		return achievementMapper.getAppHomeRecommended();			
		}
		if (type==2) {
			return 	demandMapper.getAppHomeRecommended();
		}
		if (type==3) {
			return userIdentityMapper.getAppHomeRecommended();
		}
		return null;
	}

	

	
}
