package com.palmnest.webapp.controller.wechat;

import com.palmnest.application.core.util.FileUploadUtils;
import com.palmnest.application.core.util.PropertiesKit;
import com.palmnest.model.estateserve.ProductCategories;
import com.palmnest.service.estateserve.ServicePackManager;
import com.palmnest.service.ws.UserinformationSync;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品信息导航
 *
 * @author yubing
 * @since 2017-07-19 11:07
 */
@Slf4j
@Controller
@RequestMapping(value = "/wechat/navigation*")
public class ProductNavigationController {


	@Autowired
	private ServicePackManager servicePackManager;

	private String webUrl = PropertiesKit.readPropertiesValue("webUrl", "wechat.properties");

	/**
	 * 进入到影视会员主页
	 */
	@RequestMapping(value = "/filmIndex")
	public ModelAndView memberManageList(HttpServletRequest request, HttpServletResponse response) throws Exception {

		Model model = new ExtendedModelMap();

		String openId      = request.getParameter("openId");
		String developId   = request.getParameter("developId");
		String userId      = request.getParameter("userId");
		String serviceCode = request.getParameter("serviceCode");        //一级分类的业务编码
		String channelCode = request.getParameter("channelCode");        //渠道编码

		log.info("filmIndex--");
		log.info("openId:" + openId);
		log.info("developId:" + developId);
		log.info("userId:" + userId);
		log.info("serviceCode:" + serviceCode);
		log.info("channelCode:" + channelCode);

		//影视会员Banner广告
		String bannerStr = UserinformationSync.getBanner("projectCode=TYLY&serviceType=-2");
		if (StringUtils.isNotBlank(bannerStr)) {
			model.addAttribute("bannerStr", JSONArray.fromObject(bannerStr));
		}
		List<ProductCategories> categoriesList = servicePackManager.queryCategoriesListByServiceCode(serviceCode);
		model.addAttribute("categoriesList", categoriesList);
		model.addAttribute("openId", openId);
		model.addAttribute("developId", developId);
		model.addAttribute("userId", userId);
		model.addAttribute("channelCode", channelCode);
		model.addAttribute("imageServer", FileUploadUtils.getVisitPrefix());
		model.addAttribute("webUrl", webUrl);
		model.addAttribute("serviceCode", serviceCode);
		return new ModelAndView("wechat/movieVipHome", model.asMap());
	}

}
