package flow;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONObject;

/**
 * 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: 2020年3月23日 上午05时27分20秒
 */
public class OUTDataServlet extends com.avaya.sce.runtime.BasicServlet {
	private static final boolean List = false;
	private static Logger log = Logger.getLogger(OUTDataServlet.class);
	//{{START:CLASS:FIELDS
	//}}END:CLASS:FIELDS

	/**
	 * Default constructor
	 * Last generated by Orchestration Designer at: 2020年3月23日 上午05时27分20秒
	 */
	public OUTDataServlet() {
		//{{START:CLASS:CONSTRUCTOR
		super();
		//}}END:CLASS:CONSTRUCTOR
	}

	/**
	 * 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: 2020年3月23日 上午05时27分20秒
	 */
	public void servletImplementation(com.avaya.sce.runtimecommon.SCESession mySession) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
		
		log.info("OUTDataServlet开始时间=======" + df.format(new Date()));
		
		String ani = mySession.getVariableField(IProjectVariables.SESSION,
				IProjectVariables.SESSION_FIELD_ANI).getStringValue();
		log.info("OUTDataServlet   来电号码=======" + ani);
		
		String zcd_menu = mySession.getVariableField(IProjectVariables.ZCD_MENU,IProjectVariables.ZCD_MENU_FIELD_VALUE).getStringValue();
		
		String jszc_menu = mySession.getVariableField(IProjectVariables.JSZC_MENU,IProjectVariables.JSZC_MENU_FIELD_VALUE).getStringValue();
		String isvip = mySession.getVariableField(IProjectVariables.IS_VIP).getStringValue();
		if(jszc_menu.equals("")||jszc_menu==null){
			jszc_menu="0";
		}
		String data=null;
		if (isvip.equals("1")) {
			data="key1="+0+"|key2="+0;
			mySession.getVariableField(IProjectVariables.UUI).setValue(data);
			mySession.getVariableField(IProjectVariables.PHONE).setValue("1068");
			String phone = mySession.getVariableField(IProjectVariables.PHONE).getStringValue();
			log.info("OUTDataServlet   呼出号码是=======" + phone);
		}else {
			data="key1="+zcd_menu+"|key2="+jszc_menu;
			mySession.getVariableField(IProjectVariables.UUI).setValue(data);
			if(zcd_menu.equals("1")){
				mySession.getVariableField(IProjectVariables.PHONE).setValue("1002");
				String phone = mySession.getVariableField(IProjectVariables.PHONE).getStringValue();
				log.info("OUTDataServlet   呼出号码是=======" + phone);
				
			}else if (zcd_menu.equals("2")) {
				if (jszc_menu.equals("1")) {
					mySession.getVariableField(IProjectVariables.PHONE).setValue("1004");
					String phone = mySession.getVariableField(IProjectVariables.PHONE).getStringValue();
					log.info("OUTDataServlet   呼出号码是=======" + phone);
					
				}else if(jszc_menu.equals("2")){
					mySession.getVariableField(IProjectVariables.PHONE).setValue("1006");
					String phone = mySession.getVariableField(IProjectVariables.PHONE).getStringValue();
					log.info("OUTDataServlet   呼出号码是=======" + phone);
					
				}else {
					mySession.getVariableField(IProjectVariables.PHONE).setValue("1013");
					String phone = mySession.getVariableField(IProjectVariables.PHONE).getStringValue();
					log.info("OUTDataServlet   呼出号码是=======" + phone);
					
				}
			}else if (zcd_menu.equals("3")) {
				mySession.getVariableField(IProjectVariables.PHONE).setValue("1008");
				String phone = mySession.getVariableField(IProjectVariables.PHONE).getStringValue();
				log.info("OUTDataServlet   呼出号码是=======" + phone);
				
			}else{
				mySession.getVariableField(IProjectVariables.PHONE).setValue("1010");
				String phone = mySession.getVariableField(IProjectVariables.PHONE).getStringValue();
				log.info("OUTDataServlet   呼出号码是=======" + phone);
				
			}
		}
		
		
		log.info("OUTDataServlet  UCID 是    ："+mySession.getVariableField(IProjectVariables.SESSION,IProjectVariables.SESSION_FIELD_UCID).getStringValue()+"  来电号码是     ："+mySession.getVariableField(IProjectVariables.SESSION,IProjectVariables.SESSION_FIELD_ANI).getStringValue()+"传输参数======="+data);
		// TODO: Add your code here!

	}
	/**
	 * 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: 2021年12月20日 下午09时59分54秒
	 */
	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("ZxjyAnnounce", 0, true, "Default");
		list.add(aGoto);

		return list;
	}
}
