package com.engine.kq.cmd.importlog;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class SaveImportLogCmd extends AbstractCommonCommand<Map<String, Object>>{
	
	HttpServletRequest request;
	
	public SaveImportLogCmd(Map<String, Object> params, HttpServletRequest request, User user) {
		this.user = user;
		this.params = params;
		this.request = request;
	}
	
	@Override
	public Map<String, Object> execute(CommandContext commandContext) {
		Map<String, Object> retmap = new HashMap<String, Object>();
		String sql = "";
		RecordSet rs = new RecordSet();
		try {
			String importType = Util.null2String(params.get("importType"));
			String operateType = Util.null2String(params.get("operateType"));
			
			sql = "	insert into  hrmimporthistory (operator,operatetime,operatetype,importtype,sourcefrom,clientaddress,status) " +
						"	values("+this.user.getUID()+",'"+DateUtil.getFullDate()+"','"+operateType+"','"+importType+"','excel','"+Util.getIpAddr(request)+"','importing')";
			rs.executeSql(sql);
			
			rs.executeSql(" select max(id) from hrmimporthistory ");
			if(rs.next()) {
				retmap.put("pId", rs.getInt(1));
			}
			retmap.put("status", "1");
		} catch (Exception e) {
			retmap.put("status", "-1");
			retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
			writeLog(e);
		}
		return retmap;
	}
	
	@Override
	public BizLogContext getLogContext() {
		// TODO Auto-generated method stub
		return null;
	}
}
