package flow;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * A basic servlet which allows a user to define their code, generate any
 * output, and to select where to transition to next. Last generated by
 * Orchestration Designer at: 2021年5月25日 上午08时36分26秒
 */
public class ser_init extends com.avaya.sce.runtime.BasicServlet {

	// {{START:CLASS:FIELDS
	// }}END:CLASS:FIELDS

	/**
	 * Default constructor Last generated by Orchestration Designer at:
	 * 2021年5月25日 上午08时36分26秒
	 */
	public ser_init() {
		// {{START:CLASS:CONSTRUCTOR
		super();
		// }}END:CLASS:CONSTRUCTOR
	}

//	public static HashMap<Integer, CMenuConfig> hMapParent = new HashMap<Integer, CMenuConfig>();
//	public static HashMap<Integer, ArrayList<CMenuItemConfig>> hMapChild = new HashMap<Integer, ArrayList<CMenuItemConfig>>();
//	public static HashMap<Integer, Object> hMapAll = new HashMap<Integer, Object>();

	/**
	 * This method allows for custom integration with other Java components. You
	 * may use Java for sophisticated logic or to integrate with custom
	 * connectors (i.e. JMS, custom web services, sockets, XML, JAXB, etc.)
	 * 
	 * Any custom code added here should work as efficiently as possible to
	 * prevent delays. It's important to design your callflow so that the voice
	 * browser (Voice Portal/IR) is not waiting too long for a response as this
	 * can lead to a poor caller experience. Additionally, if the response to
	 * the client voice browser exceeds the configured timeout, the platform may
	 * throw an "error.badfetch".
	 * 
	 * Using this method, you have access to all session variables through the
	 * SCESession object.
	 * 
	 * The code generator will *** NOT *** overwrite this method in the future.
	 * Last generated by Orchestration Designer at: 2021年5月25日 上午08时36分26秒
	 */
	public void servletImplementation(
			com.avaya.sce.runtimecommon.SCESession mySession) {
		try {
			HashMap<String, CMenuConfig> hMapParent = new HashMap<String, CMenuConfig>();
			HashMap<String, ArrayList<CMenuItemConfig>> hMapChild = new HashMap<String, ArrayList<CMenuItemConfig>>();
			HashMap<String, Object> hMapAll = new HashMap<String, Object>();
			mySession.getVariableField(IProjectVariables.MENU_ALL).setValue(hMapAll);
			mySession.getVariableField(IProjectVariables.MENU_PARENT).setValue(hMapParent);
			mySession.getVariableField(IProjectVariables.MENU_CHILD).setValue(hMapChild);
			Util.InitMenu(mySession);
			//GetVIP getVIP = new GetVIP();
			//getVIP.getVIP(mySession);
			//initialization(mySession);
			ivrLogFoundatin(mySession);
			//查看主目录表，副目录表 ， 是否有值 有值  正常走流程 ， 其中任意表无值 强制转人工
			//SpareType变量值  ， 1（强转人工），0（正常流程）
			if (hMapParent.size()==0||hMapParent.size()==0) {
				mySession.getVariableField(IProjectVariables.SPARE_TYPE).setValue(1);
			}
			if (hMapAll.containsKey("0")) {
				CMenuConfig CMenuConfig = (CMenuConfig) hMapAll.get("0");
//				System.out.println(CMenuConfig);
				String NexMenu=CMenuConfig.getNextMenu();
				mySession.getVariableField(IProjectVariables.NEXT_MENU).setValue(NexMenu);
			}
			else {
				mySession.getVariableField(IProjectVariables.NEXT_MENU).setValue(999999);
			}

		} catch (Exception e) {
			// TODO: handle exception
		}

	}
	/**
	 * initialization方法主要是 nodeRecordIncomingBeginTime （用户进线时间）, nodeRecordList （初始化所有节点集合）
	 * @ClassName: ser_init
	 * @Description: seven
	 * @author nodeRecordIncomingBeginTime变量参数样例："yyyy-MM-dd HH:mm:ss.SSS"，缩写名nriBeginTime;   nodeRecordList变量参数是ArrayList<IVR_NodeRecord>的集合变量体;
	 * @date 2022年2月17日 下午2:30
	 *  
	 */
	public void initialization(com.avaya.sce.runtimecommon.SCESession mySession){
		//初始化流程开始时间
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String nriBeginTime = sdf.format(new Date());
		mySession.getVariableField(IProjectVariables.NODE_RECORD_INCOMING_BEGIN_TIME).setValue(nriBeginTime);
		//节点记录集合
		ArrayList<IVR_NodeRecord> arrayList = new ArrayList<IVR_NodeRecord>();
		mySession.getVariableField(IProjectVariables.NODE_RECORD_LIST).setValue(arrayList);
		
	}
	
	/**
	 * ivrLogFoundatin方法主要是 初始化日志记录 
	 * @ClassName: ser_init
	 * @Description: seven
	 * @author LogEntity 为类对象; 存入系统变量mySession中 LogEntity变量
	 * @date 2022年6月13日 下午4:14
	 *  
	 */
	public void ivrLogFoundatin(com.avaya.sce.runtimecommon.SCESession mySession){
		try {
			LogEntity logEntity = new LogEntity();
			mySession.getVariableField(IProjectVariables.SESSION,IProjectVariables.SESSION_FIELD_ANI).setValue(mySession.getVariableField(IProjectVariables.VDU,IProjectVariables.VDU_FIELD_PRIMARY__ANI).getStringValue());
			mySession.getVariableField(IProjectVariables.SESSION,IProjectVariables.SESSION_FIELD_DNIS).setValue(mySession.getVariableField(IProjectVariables.VDU,IProjectVariables.VDU_FIELD_PRIMARY__DNIS).getStringValue());
			mySession.getVariableField(IProjectVariables.SESSION,IProjectVariables.SESSION_FIELD_UCID).setValue(mySession.getVariableField(IProjectVariables.VDU,IProjectVariables.VDU_FIELD_UCID).getStringValue());
			logEntity.setLOG_ID(mySession.getVariableField(IProjectVariables.VDU,IProjectVariables.VDU_FIELD_UCID).getStringValue());
			logEntity.setCALL_ID(mySession.getVariableField(IProjectVariables.VDU,IProjectVariables.VDU_FIELD_UCID).getStringValue());
			logEntity.setANI(mySession.getVariableField(IProjectVariables.VDU,IProjectVariables.VDU_FIELD_PRIMARY__ANI).getStringValue());
			logEntity.setDNIS(mySession.getVariableField(IProjectVariables.VDU,IProjectVariables.VDU_FIELD_PRIMARY__DNIS).getStringValue());
			
			//logEntity.setCLNT_ID("NULL");
			//logEntity.setCLNT_TYPE("NULL");
			//mySession.getVariableField(IProjectVariables.SESSION,IProjectVariables.SESSION_FIELD_ANI).setValue("13845180380");
			//logEntity.setLOG_ID("12345678901234567890");
			Date currentDateTime2 = new Date();
			SimpleDateFormat formatter1 = new SimpleDateFormat ("yyyyMMdd");
			logEntity.setSTART_DATE(formatter1.format(currentDateTime2));
			SimpleDateFormat formatter2 = new SimpleDateFormat ("HHmmssS");
			logEntity.setSTART_TIME(formatter2.format(currentDateTime2));
			SimpleDateFormat formatter3 = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
			logEntity.setSTART_TIME_STR(formatter3.format(currentDateTime2));
			logEntity.setTO_AGENT_IF("0");
			logEntity.setLEAVEWORD_IF("0");
			logEntity.setCHANNEL("0");
			
			logEntity.setTRACE("A0");
			logEntity.setTO_AGENT_IF_SUCCESS("0");
			logEntity.setFAIL_IF_DEAL("0");
			mySession.getVariableField(IProjectVariables.IVR__LOG__FOUNDATION).setValue(logEntity);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		
	}
	/**
	 * Builds the list of branches that are defined for this servlet object.
	 * This list is built automatically by defining Goto nodes in the call flow editor.
	 * It is the programmer's responsibilty to provide at least one enabled Goto.<BR>
	 *
	 * The user should override updateBranches() to determine which Goto that the
	 * framework will activate.  If there is not at least one enabled Goto item, 
	 * the framework will throw a runtime exception.<BR>
	 *
	 * This method is generated automatically and changes to it may
	 * be overwritten next time code is generated.  To modify the list
	 * of branches for the flow item, override:
	 *     <code>updateBranches(Collection branches, SCESession mySession)</code>
	 *
	 * @return a Collection of <code>com.avaya.sce.runtime.Goto</code>
	 * objects that will be evaluated at runtime.  If there are no gotos
	 * defined in the Servlet node, then this returns null.
	 * Last generated by Orchestration Designer at: 2023年4月14日 下午05时14分30秒
	 */
	public java.util.Collection getBranches(com.avaya.sce.runtimecommon.SCESession mySession) {
		java.util.List list = null;
		com.avaya.sce.runtime.Goto aGoto = null;
		list = new java.util.ArrayList(1);

		aGoto = new com.avaya.sce.runtime.Goto("SpareData", 0, true, "Default");
		list.add(aGoto);

		return list;
	}
}
