package org.cs.web.message;

import java.util.HashMap;
import java.util.Map;

import org.cs.constants.Constants;
import org.cs.core.ctl.BaseCtl;
import org.cs.mgr.admin.service.ITbNewsService;
import org.cs.util.Pager;
import org.cs.util.StringUtil;
import org.cs.ws.inteceptor.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/web/news")
public class NewsWebCtl extends BaseCtl{

	@Autowired
	private ITbNewsService tbNewsService;
	
	@RequestMapping(value="/newsList")
	public String msgList(String page,ModelMap mm,HttpServletRequest request){
		Map<String, String> user = (Map<String, String>) request.getSession().getAttribute(Constants.SESSION_WEB_USER);
		Map<String, String> map = new HashMap<String,String>();
		Integer pagetemp=1;
		if(StringUtil.isNotBlank(page)){
			pagetemp = Integer.valueOf(page);
		}
		Pager pageData = tbNewsService.getList(new Pager(pagetemp), "1", "1", user.get("type"));
		mm.put("list", pageData.getResults());
		mm.put("pageTotal", pageData.getPageTotal());
		return "app/newslist";
	}
	
	@RequestMapping(value="/newsListMore")
	public String msgListmore(String page,ModelMap mm,HttpServletRequest request){
		Map<String, String> user = (Map<String, String>) request.getSession().getAttribute(Constants.SESSION_WEB_USER);
		Map<String, String> map = new HashMap<String,String>();
		Integer pagetemp=1;
		if(StringUtil.isNotBlank(page)){
			pagetemp = Integer.valueOf(page);
		}
		Pager pageData = tbNewsService.getList(new Pager(pagetemp), "1", "1", user.get("type"));
		mm.put("list", pageData.getResults());
		mm.put("pageTotal", pageData.getPageTotal());
		return "app/newslistmore";
	}
	
	@RequestMapping(value="/newsdetil")
	public String msgDetil(String id,ModelMap mm){
		Map<String, String> map = new HashMap<String,String>();
		map.put("id", id);
		Map<String, Object> pageData = tbNewsService.queryDetail(map);
		mm.put("map", pageData);
		return "app/newsdetil";
	}
	
	
}
