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.ITopicService;
import com.cmos.msgframe.common.util.OutPutParameter;

/**
 * 项目名称：cmos-msg-admin 类名称：TopicAction 类描述：主题管理控制层 创建人：guozq5 创建时间：2016-11-11
 * 上午10:41:16 修改人：guozq5 修改时间：2016-11-11 上午10:41:16 修改备注：
 * 
 * @version
 * 
 */
@Controller
@RequestMapping("/topic")
public class TopicController {
	@Resource
	private ITopicService topicService;

	/**
	 * @Title: getTopicList
	 * @Description: 查询主题列表信息
	 * @param @param request
	 * @param @return
	 * @param @throws Exception
	 * @return Object 返回类型
	 * @throws
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter getTopicList(HttpServletRequest request)
			throws Exception {
		int start = Integer.parseInt(request.getParameter("start"));		
		int end = Integer.parseInt(request.getParameter("limit"));
		String topicCode = request.getParameter("topicCode");
		
		return topicService.getTopicList(topicCode, start, end+start);
	}

	/**
	 * @Title: addTopic
	 * @Description: 添加主题
	 * @param @param request
	 * @param @return
	 * @param @throws Exception
	 * @return Object 返回类型
	 * @throws
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter addTopic(HttpServletRequest request) throws Exception {
		String topicCode = request.getParameter("topicCode");
		String readQueueNums = request.getParameter("readQueueNums");
		String writeQueueNums = request.getParameter("writeQueueNums");
		String clusterName = request.getParameter("clusterName");
		return topicService.addTopic(topicCode, readQueueNums, writeQueueNums, clusterName);
	}

	/**
	 * @Title: updateTopic
	 * @Description: 修改主题信息
	 * @param @param request
	 * @param @return
	 * @param @throws Exception
	 * @return Object 返回类型
	 * @throws
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter updateTopic(HttpServletRequest request) throws Exception {
		String topicCode = request.getParameter("topicCode");
		String readQueueNums = request.getParameter("readQueueNums");
		String writeQueueNums = request.getParameter("writeQueueNums");
		String clusterName = request.getParameter("clusterName");
		return topicService.updateTopic(topicCode, readQueueNums, writeQueueNums,clusterName);
	}

	/**
	 * @Title: deleteTopic
	 * @Description:删除主题信息
	 * @param @param request
	 * @param @return
	 * @param @throws Exception
	 * @return Object 返回类型
	 * @throws
	 */
	@RequestMapping(value = "/delte", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter deleteTopic(HttpServletRequest request) throws Exception {
		String topicCode = request.getParameter("topicCode");
		String clusterName = request.getParameter("clusterName");
		return topicService.deleteTopic(topicCode, clusterName);
	}

	/**
	 * @Title: getTopicDetail
	 * @Description: 根据主题编码查询当前主题详情信息
	 * @param @param topicCode
	 * @param @return
	 * @param @throws Exception
	 * @return OutPutParameter 返回类型
	 * @throws
	 */
	@RequestMapping(value = "/detail", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter getTopicDetail(HttpServletRequest request) throws Exception {
		String topicCode = request.getParameter("topicCode");
		return topicService.getTopicDetail(topicCode);
	}
	/**
	* @Title: getTopicDetail
	* @Description: 获取监控的详情页面
	* @param @param topicCode
	* @param @return
	* @param @throws Exception
	* @return OutPutParameter    返回类型
	* @throws
	 */
	@RequestMapping(value = "/detailById", method = RequestMethod.POST)
	@ResponseBody
	public OutPutParameter getTopicDetailById(HttpServletRequest request) throws Exception {
		String topicCode = request.getParameter("topicCode");
		int start = Integer.parseInt(request.getParameter("start"));		
		int end = Integer.parseInt(request.getParameter("limit"));
		return topicService.getTopicDetailById(topicCode,start,end+start);
	}

} 
