package cn.hmsoft.weixin.control;

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.weixin.data.dao.WxParamDao;
import cn.hmsoft.weixin.data.model.WxParam;
import cn.hmsoft.weixin.request.ClearQuotaRequest;
import cn.hmsoft.weixin.service.WxParamService;

@RestController
public class WxParamControl extends FrameControl {
	@Autowired
	private WxParamDao daoParam;
	@Autowired
	private WxParamService sParam;

	@RequestMapping("weixin/param/page")
	public Ajax page(Integer wx_id, int start, int limit, String query, String order, String type) {
		if (StringHelper.isEmpty(order))
			order = "param_name";
		return new Ajax(this.daoParam.pageParam(wx_id, start, limit, query, this.getQueryOrder(order, type)));
	}

	@RequestMapping("weixin/param/edit")
	public Ajax edit(int wx_id, WxParam param) {
		this.sParam.editParam(wx_id, param, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("weixin/param/delete")
	public Ajax delete(int wx_id, String param_name) {
		this.sParam.delParam(wx_id, param_name, this.getFrameOptr());
		return new Ajax();
	}


	@RequestMapping("weixin/appid/clear")
	public Ajax clearQuota(int wx_id) {
		ClearQuotaRequest rq = new ClearQuotaRequest();
		rq.setWxDefine(wx_id);
		rq.request();
		return new Ajax();
	}


}
