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.constants.FrameResIdConstants;
import cn.hmsoft.frame.data.dao.FrameDeptDao;
import cn.hmsoft.frame.data.model.FrameDept;
import cn.hmsoft.frame.service.FrameDeptService;

@RestController
public class FrameDeptControl extends FrameControl {

	@Autowired
	private FrameDeptService sDept;
	@Autowired
	private FrameDeptDao daoDept;

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

	@RequestMapping("frame/dept/all")
	public Ajax all(String order, String type) {
		return new Ajax(this.daoDept.all(this.getQueryOrder(order, type)));
	}

	@RequestMapping("frame/dept/add")
	public Ajax add(final FrameDept dept) {
		this.authOptrRole(FrameResIdConstants.Dept_Manage);
		this.sDept.addDept(dept);
		return new Ajax(dept);
	}

	@RequestMapping("frame/dept/edit")
	public Ajax edit(final FrameDept dept) {
		this.authOptrRole(FrameResIdConstants.Dept_Manage);
		this.sDept.editDept(dept);
		return new Ajax();
	}

	@RequestMapping("frame/dept/find")
	public Ajax find(final int dept_id) {
		return new Ajax(this.daoDept.find(dept_id));
	}

	@RequestMapping("frame/dept/delete")
	public Ajax delete(final int dept_id) {
		this.authOptrRole(FrameResIdConstants.Dept_Manage);
		this.sDept.deleteDept(dept_id);
		return new Ajax();
	}

}
