package cn.hmsoft.weixin.control;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hmsoft.application.web.Ajax;
import cn.hmsoft.frame.control.FrameControl;
import cn.hmsoft.helper.StringHelper;
import cn.hmsoft.jdbc.entity.Pager;
import cn.hmsoft.weixin.data.dao.WxMsgProcessorDao;
import cn.hmsoft.weixin.data.model.WxMsgProcessor;
import cn.hmsoft.weixin.service.WxMsgProcessorService;

@RestController
public class WxMsgProcessorControl extends FrameControl {
	@Autowired
	private WxMsgProcessorDao daoProcessor;
	@Autowired
	private WxMsgProcessorService sProcessor;


	@RequestMapping("weixin/processor/page")
	public Ajax page(Integer wx_id, int start, int limit, String query, String order, String type) {
		if (wx_id == null)
			return new Ajax(new Pager(new ArrayList<String>()));
		if (StringHelper.isEmpty(order))
			order = "msg_type";
		return new Ajax(this.daoProcessor.pageMsgProcessor(wx_id, start, limit, query, this.getQueryOrder(order, type)));
	}

	@RequestMapping("weixin/processor/edit")
	public Ajax editProcessor(int wx_id, WxMsgProcessor processor) {
		this.sProcessor.editProcessor(wx_id, processor, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("weixin/processor/add")
	public Ajax addProcessor(int wx_id, WxMsgProcessor processor) {
		this.sProcessor.addProcessor(wx_id, processor, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("weixin/processor/delete")
	public Ajax deleteProcessor(int wx_id, String msg_type) {
		this.sProcessor.delProcessor(wx_id, msg_type, this.getFrameOptr());
		return new Ajax();
	}

}
