package cn.hmsoft.frame.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.data.dao.FrameParamDao;
import cn.hmsoft.frame.data.model.FrameParam;
import cn.hmsoft.frame.service.FrameParamService;
import cn.hmsoft.frame.util.FrameAssertUtil;
import cn.hmsoft.frame.util.FrameParamUtil;

@RestController
public class FrameParamContorl extends FrameControl {

	@Autowired
	private FrameParamService sFrameParam;
	@Autowired
	private FrameParamDao daoFrameParam;

	@RequestMapping("frame/param/page")
	public Ajax page(String query, Integer limit, Integer start, String order, String type) {
		return new Ajax(this.daoFrameParam.pageParam(start, limit, query, getQueryOrder(order, type)));
	}

	@RequestMapping("frame/param/find")
	public Ajax find(String paramName) {
		return new Ajax(this.daoFrameParam.find("param_name", paramName));
	}

	@RequestMapping("frame/param/edit")
	public Ajax edit(FrameParam param) {
		this.authAdminRole();
		this.sFrameParam.editParam(param);
		return new Ajax();
	}

	@RequestMapping("frame/param/add")
	public Ajax add(FrameParam param) {
		this.authAdminRole();
		this.sFrameParam.addParam(param);
		return new Ajax();
	}
	@RequestMapping("frame/param/delete")
	public Ajax delete(FrameParam param) {
		this.authAdminRole();
		this.sFrameParam.deleteParam(param);
		return new Ajax();
	}

	@RequestMapping("frame/param/reload")
	public Ajax reload() {
		FrameAssertUtil.adminOptr(this.getFrameOptr());
		FrameParamUtil.ReloadFrameParams();
		return new Ajax();
	}
}
