package cn.hmsoft.skill.control.cf;

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.jdbc.entity.QueryOrder;
import cn.hmsoft.skill.data.dao.school.SchoolAspectDao;
import cn.hmsoft.skill.data.dao.school.SchoolRegDao;
import cn.hmsoft.skill.data.model.school.SchoolReg;
import cn.hmsoft.skill.helper.SkillParamHelper;
import cn.hmsoft.skill.service.cf.SchoolRegService;

@RestController
public class CfAgentControl extends FrameControl {
	@Autowired
	private SchoolAspectDao schoolAspectDao;
	@Autowired
	private SchoolRegDao schoolRegDao;
	@Autowired
	private SchoolRegService schoolRegService;

	@RequestMapping("conf/agent/page")
	public Ajax page(String query, Integer limit, Integer start, String order, String type) {
		if (StringHelper.isEmpty(order))
			order = "school_code";
		//判断是否系统管理员  admin
		if(SkillParamHelper.ADMIN.equals(this.getFrameOptr().getLogin_name())) {
			return new Ajax(this.schoolRegDao.pageAllSchoolReg( start, limit, getQueryOrder(order, type)));
		} else {
			return new Ajax(this.schoolRegDao.pageSchoolReg(this.getFrameOptr().getOrg_id(), start, limit, 
				query, getQueryOrder(order, type)));
		}
	}

	@RequestMapping("conf/agent/find")
	public Ajax find(int agent_id) {
		return new Ajax(this.schoolRegDao.find(agent_id));
	}

	@RequestMapping("conf/agent/all")
	public Ajax all() {
		return new Ajax(this.schoolRegDao.all(new QueryOrder("school_id")));
	}

	@RequestMapping("conf/agent/add")
	public Ajax add(SchoolReg agent) {
		this.schoolRegService.addSchoolReg(agent, this.getFrameOptr());
		return new Ajax(agent);
	}

	@RequestMapping("conf/agent/edit")
	public Ajax edit(SchoolReg agent) {
		this.schoolRegService.editSchoolReg(agent, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("conf/agent/delete")
	public Ajax delete(int agent_id) {
		this.schoolRegService.deleteSchoolReg(agent_id, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("conf/agent/aspect/list")
	public Ajax listAspect(int agent_id) {
		return new Ajax(this.schoolAspectDao.list("school_id", agent_id));
	}


}
