package org.cs.ws.user.ctl;

import java.util.Map;

import org.cs.core.ctl.BaseCtl;
import org.cs.mgr.admin.service.ITbNewsService;
import org.cs.mgr.user.model.MgmUser;
import org.cs.mgr.user.service.IMgmUserService;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

@Controller
@RequestMapping("/rest/news")
public class MsgApi extends BaseCtl{

	@Autowired
	private ITbNewsService tbNewsService;
	
	@Autowired
	private IMgmUserService mgmUserService;
	@RequestMapping(value="/msgList",method = RequestMethod.POST)
	@ResponseBody
	public String msgList(String data){
		Map<String, String> map = getMapFromJson(data);
		
		MgmUser user=null;
		String userId=map.get("userId");
		if(StringUtil.isNotBlank(userId)){
			user = this.mgmUserService.findById(Integer.valueOf(userId));
			if(user!=null){
				map.put("userType", user.getType());
			}
		}
		
		
		Integer page = Integer.valueOf(map.get("page"));
//		Pager pageData = tbNewsService.getList(new Pager(page), "1", "1");
//		增加用户id判断用户类型
		Pager pageData = tbNewsService.getMapList(new Pager(page), "1", "1",map);
		return JSONObject.toJSONString(getJson(1, pageData, "1"));
	}
	
	@RequestMapping(value="/msgDetil",method = RequestMethod.POST)
	@ResponseBody
	public String msgDetil(String data){
		Map<String, String> map = getMapFromJson(data);
		Integer page = Integer.valueOf(map.get("id"));
		Map<String, Object> pageData = tbNewsService.queryDetail(map);
		
		return JSONObject.toJSONString(getJson(1, pageData, "1"));
	}
	
	
}
