package com.lgx8.gateway.servlet;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.lgx8.gateway.entities.GatewayCategory;
import com.lgx8.gateway.service.IGatewayService;
import com.lgx8.gateway.util.GatewayConstants;
import com.lgx8.gateway.vo.ProductVO;
import freemarker.template.Template;
import freemarker.template.TemplateException;
/**
* Servlet implementation class GatewayNewScreenServlet
*/
public class GatewayNewScreenServlet extends GatewayBaseServlet {
private static final long serialVersionUID = 1L;
/**
* @see GatewayBaseServlet#GatewayBaseServlet()
*/
public GatewayNewScreenServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Map<Object, Object> root = new HashMap<Object, Object>();
root.putAll(super.root);
Template temp = getConfiguration().getTemplate("newscreen.ftl");
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
GatewayCategory gatewayCategory = gatewayService.findGatewayCategoryById(GatewayConstants.CID_XPTJ);
if(gatewayCategory != null)
{
root.put("gatewayCategory", gatewayCategory);
}
//新品推荐
List<ProductVO> productVOs1 = gatewayService.initGatewayInfo(GatewayConstants.CID_XPTJ);
if(productVOs1 != null && productVOs1.size() != 0)
{
root.put("productVOs1", productVOs1);
}
//新品推荐2
List<ProductVO> productVOs2 = gatewayService.initGatewayInfo(GatewayConstants.CID_XPTJ2);
if(productVOs2 != null && productVOs2.size() != 0)
{
root.put("productVOs2", productVOs2);
}
/* 将模板和数据模型合并 */
Writer out = response.getWriter();
try {
temp.process(root, out);
} catch (TemplateException e) {
e.printStackTrace();
}
out.flush();
}
}