package com.cmos.msgframe.admin.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

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.cmos.msgframe.admin.service.IMessageService;
import com.cmos.msgframe.common.util.OutPutParameter;

/**
 * 项目名称：cmos-msg-admin 类名称：MessageAction 类描述：消息管理控制层 创建人：guozq5 创建时间：2016-11-11
 * 上午10:38:05 修改人：guozq5 修改时间：2016-11-11 上午10:38:05 修改备注：
 * 
 * @version
 * 
 */
@Controller
@RequestMapping("/message")
public class MessageController {

	@Resource
	private IMessageService messageService;

	/**
	 * @Title: getMessageById
	 * @Description: 根据消息ID查询消息信息
	 * @param @param msgId
	 * @param @return
	 * @param @throws Exception
	 * @return Map<String,Object> 返回类型
	 * @throws
	 */
	@RequestMapping(value = "/msgForId", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter getMessageById(HttpServletRequest request)
			throws Exception {
		String msgId = request.getParameter("msgId");
		return messageService.getMessageById(msgId);
	}

	/**
	 * @Title: getMessageByKey
	 * @Description:根据消息key查询消息信息
	 * @param @param topic
	 * @param @param Key
	 * @param @param start
	 * @param @param end
	 * @param @return
	 * @param @throws Exception
	 * @return List<Map<String,String>> 返回类型
	 * @throws
	 */
	@RequestMapping(value = "/msgForkey", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter getMessageByKey(HttpServletRequest request) throws Exception {
		int start = Integer.parseInt(request.getParameter("start"));		
		int end = Integer.parseInt(request.getParameter("limit"));
		String topic = request.getParameter("topic");
		String key = request.getParameter("key");
		return messageService.getMessageByKey(topic, key, start, end+start);
	}

	/**
	 * @Title: getMessageByOffset
	 * @Description:根据消息的偏移量查询消息信息
	 * @param @param topic
	 * @param @param brokerName
	 * @param @param offset
	 * @param @param queueId
	 * @param @return
	 * @param @throws Exception
	 * @return Map<String,Object> 返回类型
	 * @throws
	 */
	@RequestMapping(value = "/msgForOffset", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter getMessageByOffset(HttpServletRequest request) throws Exception {
		String queueId = request.getParameter("queueId");
		String brokerName = request.getParameter("brokerName");
		String topic = request.getParameter("topic");
		String offset = request.getParameter("offset");
		return messageService.getMessageByOffset(topic, brokerName, offset,
				queueId);
	}
}
