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.FrameTimerDao;
import cn.hmsoft.frame.data.model.FrameTimer;
import cn.hmsoft.frame.service.FrameTimerService;

@RestController
public class FrameTimerControl extends FrameControl {

	@Autowired
	private FrameTimerService sTimer;
	@Autowired
	private FrameTimerDao daoTimer;

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

	@RequestMapping("frame/timer/add")
	public Ajax add(final FrameTimer timer) {
		this.authAdminRole();
		this.sTimer.addTimer(timer);
		return new Ajax(timer);
	}

	@RequestMapping("frame/timer/edit")
	public Ajax edit(final FrameTimer timer) {
		this.authAdminRole();
		this.sTimer.editTimer(timer);
		return new Ajax();
	}

	@RequestMapping("frame/timer/delete")
	public Ajax delete(final int timer_id) {
		this.authAdminRole();
		this.sTimer.deleteTimer(timer_id);
		return new Ajax();
	}

	@RequestMapping("frame/timer/log/page")
	public Ajax pageLog(int timer_id, Integer limit, Integer start) {
		return new Ajax(this.daoTimer.pageTimerLog(timer_id, start, limit));
	}

}
