package cn.hmsoft.skill.enrol.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.skill.data.dao.std.StdRegDao;
import cn.hmsoft.skill.data.model.school.SchoolReg;
import cn.hmsoft.skill.data.model.std.StdReg;
import cn.hmsoft.skill.enrol.service.EnrolStdInfoService;
import cn.hmsoft.skill.enrol.service.EnrolStdRegService;
import cn.hmsoft.skill.helper.SkillParamHelper;

@RestController
public class EnrolStdInfoControl extends EnrolAbstractControl {
	@Autowired
	private EnrolStdInfoService sStd;
	@Autowired
	private EnrolStdRegService sReg;
	@Autowired
	private StdRegDao daoStd;

	@RequestMapping("/enrol/std/info/save")
	public Ajax save(String std_mobile1, String std_mobile2, String std_email, String link_addr, String link_postal,
			Boolean confirm) {
		FrameAssertUtil.isNotEmpty(std_mobile1, "请输入考生联系电话！");
		StdReg std = new StdReg();
		std.setStd_id(this.getStdReg().getStd_id());
		std.setStd_mobile1(std_mobile1);
		std.setStd_mobile2(std_mobile2);
		std.setLink_addr(link_addr);
		this.sStd.save(this.getSchoolReg(), std, confirm);
		this.getSession().setAttribute(SkillParamHelper.SessionName_StdReg, this.daoStd.find(std.getStd_id()));
		return new Ajax(std.getConfirm_time());
	}

	@RequestMapping("/enrol/std/info/init")
	public Ajax init() {
		//StdReg std = this.daoStd.find(this.getStdReg().getStd_id());
		StdReg std = this.daoStd.findById(this.getStdReg().getStd_id());
		FrameAssertUtil.isNotNull(std, "未找到考生！");
		SchoolReg school = this.daoStd.find(SchoolReg.class,this.getSchoolReg().getSchool_id());
		school.setLogin_pass(null);
		school.setSocket_param(null);
		FrameAssertUtil.isNotNull(school, "基础信息错误，请联系系统管理员");
		this.sReg.transStdInfo(std);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("StdReg", std);
		map.put("SchoolReg", school);
		return new Ajax(map);
	}
}
