package com.qiwu.chatbotbackend.gameDesign; import com.alibaba.fastjson.JSONObject; import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.entity.UserInfo; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import static com.qiwu.chatbotbackend.Config.Config.CC_URL; public class GlobalVariableConstructor extends ElementConstructor { public GlobalVariableConstructor(SqlHelper helper, int botId, String botAccount, Map keywordMap, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; this.botAccount = botAccount; this.exceptRelation = exceptRelation; this.keywordMap = keywordMap; this.POS = POS; } public void construct(JSONObject gameElements, UserInfo userinfo) { try { String category, name, description, attrValue; JSONObject globalVariable = gameElements.getJSONObject("globalVariable"); Map attribute = null; Iterator attrIter = null; for(String attrName:globalVariable.keySet()) { attrValue = (String)globalVariable.get(attrName); varInitialMap.put("globalVariable_" + attrName, attrValue); } varInitialMap.put("botType", "game"); varInitialMap.put("unknownTextList", (String)gameElements.get("unknownTextList")); varInitialMap.put("finalUnknownText", (String)gameElements.get("finalUnknownText")); varInitialMap.put("CC_URL", CC_URL); JSONObject script = gameElements.getJSONObject("speechcraft"); for(String key:script.keySet()){ //attrValue = (String)script.get(key); attrValue = script.getJSONObject(key).getString("text"); varInitialMap.put(key, attrValue); } Boolean postActive = gameElements.getBoolean("postActive"); if(postActive != null && postActive == true) { String postURL = gameElements.getString("postURL"); if(postURL != null & !postURL.equals("")) { varInitialMap.put("postURL", postURL); } } }catch (Exception e){ operationStatus = 0; message = "全局变量处理出现异常"; e.printStackTrace(); return; } } }