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.weixin.data.dao.WxDefineDao;
import cn.hmsoft.weixin.data.model.WxDefine;
import cn.hmsoft.weixin.service.WxDefineService;
import cn.hmsoft.weixin.util.WeiXinModuleConfig;
import cn.hmsoft.weixin.util.WeiXinParamUtil;

@RestController
public class WxDefineControl extends FrameControl {

	@Autowired
	private WxDefineDao daoDefine;

	@Autowired
	private WxDefineService sDefine;

	@RequestMapping("weixin/define/page")
	public Ajax page(Integer start, Integer limit, String query, String order, String type) {
		return new Ajax(this.daoDefine.pageDefine(start, limit, query, this.getQueryOrder(order, type)));
	}

	@RequestMapping("weixin/define/find")
	public Ajax add(int wx_id) {
		return new Ajax(this.daoDefine.find(wx_id));
	}

	@RequestMapping("weixin/define/add")
	public Ajax add(WxDefine wx) {
		this.sDefine.addDefine(wx, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("weixin/define/edit")
	public Ajax edit(WxDefine wx) {
		this.sDefine.editDefine(wx, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("weixin/define/delete")
	public Ajax delete(int wx_id) {
		this.sDefine.deleteDefine(wx_id, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("weixin/define/reload")
	public Ajax reload(int wx_id) {
		// 可能没运行
		try {
			WeiXinModuleConfig.loadWeiXinConfig(WeiXinParamUtil.WeiXinModuleConfig.getModule(), wx_id);
		} catch (Exception e) {

		}
		return new Ajax();
	}
}
