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.jdbc.entity.Pager;
import cn.hmsoft.weixin.constants.WxResId;
import cn.hmsoft.weixin.data.dao.WxMsgReplyDao;
import cn.hmsoft.weixin.data.model.WxMsgReply;
import cn.hmsoft.weixin.service.WxMsgReplyService;

@RestController
public class WxMsgReplyControl extends FrameControl {
	@Autowired
	private WxMsgReplyDao daoMsgReply;
	@Autowired
	private WxMsgReplyService sMsgReply;

	@RequestMapping("weixin/msgreply/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>()));
		return new Ajax(this.daoMsgReply.pageMsgReply(wx_id, start, limit, query, getQueryOrder(order, type)));
	}

	@RequestMapping("weixin/msgreply/edit")
	public Ajax edit(int wx_id, WxMsgReply msgreply) {
		this.authOptrRole(WxResId.MsgReply_Manage);
		if (msgreply.getMsg_id() != null)
			this.sMsgReply.editMsgReply(wx_id, msgreply, this.getFrameOptr());
		else
			this.sMsgReply.addMsgReply(wx_id, msgreply, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("weixin/msgreply/delete")
	public Ajax delete(int wx_id, int msg_id) {
		this.authOptrRole(WxResId.MsgReply_Manage);
		this.sMsgReply.delMsgReply(wx_id, msg_id, this.getFrameOptr());
		return new Ajax();
	}

}
