package cn.hmsoft.skill.enrol.service;

import java.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.hmsoft.application.web.BrowserAgent;
import cn.hmsoft.frame.util.FrameAssertUtil;
import cn.hmsoft.skill.data.dao.std.StdLogDao;
import cn.hmsoft.skill.data.model.school.SchoolReg;
import cn.hmsoft.skill.data.model.std.StdLogin;
import cn.hmsoft.skill.data.model.std.StdReg;

@Service
public class EnrolStdLoginService {

	@Autowired
	private StdLogDao daoLog;
	public StdReg login(SchoolReg school,StdReg std, BrowserAgent agent) {
		FrameAssertUtil.isNotNull(std.getStd_id(), "非法提交，请重试！");
		// 更新最后登录时间
		if (agent != null) {
			StdLogin log = new StdLogin();
			log.setBrowser_type(agent.getBrowserType());
			log.setBrowser_version(agent.getBrowserVersion());
			log.setLogin_addr(agent.getUserAddr());
			log.setLogin_time(LocalDateTime.now());
			log.setPlatform_type(agent.getPlatformType());
			log.setPlatform_series(agent.getPlatformSeries());
			log.setPlatform_version(agent.getPlatformVersion());
			log.setStd_id(std.getStd_id());
			log.setSchool_id(school.getSchool_id());
			this.daoLog.insert(log);
		}
		return std;
	}

	public String checkLoginTime(BrowserAgent agent) {
		// TODO Auto-generated method stub
		return null;
	}

}
