package cn.hmsoft.skill.school.control;

import java.util.HashMap;
import java.util.Map;

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.util.FrameAssertUtil;
import cn.hmsoft.helper.StringHelper;
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.school.service.SchoolInfoService;

@RestController
public class SchoolInfoControl extends SchoolAbstractControl {

	@Autowired
	private SchoolInfoService sInfo;
	@Autowired
	private SchoolRegDao daoSchool;
	@Autowired
	private SchoolAspectDao daoAspect;

	@RequestMapping("/school/school/info/init")
	public Ajax init() {
		SchoolReg school = this.daoSchool.find(this.getSchool().getSchool_id());
		FrameAssertUtil.isNotNull(school, "基础数据错误，请联系系统管理员");
		school.setLogin_pass(null);
		school.setSocket_param(null);
		school.setSchool_type(null);
		Map<String, Object> map = new HashMap<String, Object>();
		// if (StringHelper.isNotEmpty(school.getSchool_short_img()))
		// school.setSchool_short_img(SkillParamHelper.MateialWebPath + "/school/" +
		// school.getSchool_short_img());
		map.put("SchoolReg", school);
		map.put("AspectArray", this.daoAspect.totalAspect(school.getSchool_id()));
		map.put("TotalFee", this.daoAspect.totalFee(school.getSchool_id()));
		
		return new Ajax(map);

	}

	@RequestMapping("/school/school/info/find")
	public Ajax find() {
		SchoolReg school = this.daoSchool.find(this.getSchool().getSchool_id());
		FrameAssertUtil.isNotNull(school, "基础数据错误，请联系系统管理员");
		school.setLogin_pass(null);
		school.setSocket_param(null);
		school.setSchool_type(null);
		if (StringHelper.isNotEmpty(school.getSchool_short_img()))
			school.setSchool_short_img(SkillParamHelper.MateialWebPath + "/school/" + school.getSchool_short_img());
		return new Ajax(school);

	}

	@RequestMapping("/school/school/info/edit")
	public Ajax edit(SchoolReg school) {
		school.setSchool_id(this.getSchool().getSchool_id());
		school.setSocket_param(null);
		school.setSchool_code(null);
		school.setSchool_short_img(null);
		school.setSchool_code(null);
		school.setLogin_pass(null);
		this.sInfo.save(school);
		return new Ajax(school);

	}
	
	@RequestMapping("/school/school/info/passwd")
	public Ajax passwd(String old_pass,String new_pass) {
		FrameAssertUtil.checkParam(old_pass,new_pass);
		FrameAssertUtil.isNotEqual(old_pass, new_pass, "新旧密码不能相同！");
		this.sInfo.pass(this.getSchool().getSchool_id(), old_pass,new_pass);
		return new Ajax();

	}
}
