package cn.hmsoft.frame.service;

import java.time.LocalDateTime;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hmsoft.application.web.BrowserAgent;
import cn.hmsoft.frame.data.dao.FrameOptrLoginDao;
import cn.hmsoft.frame.data.model.FrameOptr;
import cn.hmsoft.frame.data.model.FrameOptrLogin;
import cn.hmsoft.frame.util.FrameAgentUtil;

@Service
public class FrameLoginService extends FrameService {

	@Autowired
	private FrameOptrLoginDao daoOptrLogin;

	/********************
	 * 操作员登录
	 * 
	 * @param optr
	 * @param request
	 */
	public void optrLogin(final FrameOptr optr, HttpServletRequest request) {
		BrowserAgent agent = FrameAgentUtil.getBrowserAgent(request);
		FrameOptrLogin login = new FrameOptrLogin();
		login.setLogin_time(LocalDateTime.now());
		login.setLogin_name(optr.getLogin_name());
		login.setOptr_id(optr.getOptr_id());
		if (agent != null) {
			login.setBrowser_type(agent.getBrowserType());
			login.setBrowser_version(agent.getBrowserVersion());
			login.setLogin_addr(agent.getUserAddr());
			login.setPlatform_series(agent.getPlatformSeries());
			login.setPlatform_type(agent.getPlatformType());
			login.setPlatform_version(agent.getPlatformVersion());
		} else {
			login.setBrowser_type("Unknow");
			login.setBrowser_version("Unknow");
			login.setLogin_addr("Unknow");
			login.setPlatform_series("Unknow");
			login.setPlatform_type("Unknow");
			login.setPlatform_version("Unknow");
		}
		this.daoOptrLogin.insert(login);
		final FrameOptr optrModify = new FrameOptr();
		optrModify.setOptr_id(optr.getOptr_id());
	}
}
