diff --git a/config.properties b/config.properties index aa9d2b4..35064ca 100644 --- a/config.properties +++ b/config.properties @@ -8,20 +8,25 @@ cc_url=http://localhost:8070/api/update/data # condition后台url condition_backend_url=http://192.168.1.82:6636/api -# 数据模型url -automatch_url=http://dev01.centaurstech.com:5700/mermaid/?model=auto-train - # action生成指定的后台地址 service_url=http://192.168.1.178:8081/bot/dialog -# + + + #qa_url=http://localhost:59100/game #cc_url=http://localhost:8070/api/update/data #condition_backend_url=http://localhost:6636/api -#automatch_url=http://dev01.centaurstech.com:5700/mermaid/?model=auto-train #service_url=http://localhost:8081/bot/dialog +chatcache_time_out=300000 + + +# 数据模型url +automatch_url=http://dev01.centaurstech.com:5700/mermaid/?model=auto-train +condition_backend_error=语义关系后台异常 +keyword_dir=keywords.txt bot_backup_dir=tmp/ config_dir=config/ @@ -29,8 +34,10 @@ unknown_text=不好意思,我没听懂你刚才说的话,请换个别的问é location_hint=请到%s -game_start_hint=请说开始剧情或者继续剧情 -game_welcome_text=欢迎来到%s,请说继续剧情或者重新开始 +no_one_can_reply_unknown=此地点没人可以回答unknown + +game_start_hint=【旁白@%正常】请说开始剧情或者继续剧情 +game_welcome_text=【旁白@正常】欢迎来到%s,请说继续剧情或者重新开始 game_module_error=游戏模块出错 program_error=程序出现异常 @@ -56,6 +63,8 @@ star_plot_not_exist=开始剧情不存在,请到剧情列表设置 助手对应的变量 assistant=globalVariable_智能助手 +unknown_counter_name=globalVariable_无匹配次数 + # ------------------------助手情绪-------------- assistant_emotion=正常 talker_pattern=【%s@%s】 @@ -71,6 +80,7 @@ plot_status=剧情%s状态 plot_generation_error=剧情接口处理出现异常 action_text_generate_error=action生成失败 +qa_fetch_error=QA处理中发生异常 默认condition default_condition=yaobuyao @@ -165,3 +175,7 @@ variable_update_format=%s---%s # ---------------------------数据库连接获取失败-------------------------------- sql_connection_error=数据库连接获取失败 + + +# -------------------------备份-------------------------------------- +backup_error=备份失败 diff --git a/keywords.txt b/keywords.txt index 6645063..9e58eab 100644 --- a/keywords.txt +++ b/keywords.txt @@ -6,96 +6,99 @@ # name表示可以替换的名字,如物品名、角色名 # attrName是属性名 # qiwu就是玩家“我” +# botname是"你" # ------------------------------------------------------------------------------ # 我在哪里 -WHERE_I_AM|zainali|+在:哪里+在:哪儿+在:哪+在:位置+在:地点+在:地方+到:哪里+到:地点+到:地方 -WHERE_I_AM|wenzainali|+哪:qiwu+地方:qiwu+位置:qiwu+地点:qiwu+哪里:qiwu+哪儿:qiwu+哪:landey+地方:landey+位置:landey+地点:landey+哪里:landey+哪儿:landey - +WHERE_I_AM|at_where|+在:哪里+在:哪儿+在:哪+在:位置+在:地点+在:地方+到:哪里+到:地点+到:地方 +WHERE_I_AM|something_where|+哪:qiwu+哪儿:qiwu+哪里:qiwu+地方:qiwu+位置:qiwu+地点:qiwu # 我能去哪里 -WHERE_CAN_I_GO|choose_gowhere|+哪里:qiwu+哪:qiwu+哪儿:qiwu+地方:qiwu+哪里:去+哪:能去+哪里:能去+哪儿:能去+地方:能去+地方:去+地方:能去+哪里:能去+哪:去+哪:能去+哪儿:去+哪:qiwu+哪:到+哪儿:到+哪里:到 +WHERE_CAN_I_GO|choose_gowhere_1|+能去:哪里+能去:哪+能去:哪儿+去:哪+去:哪里+去:哪儿+能到:哪里+能到:哪儿+能到:哪+到:哪+到:哪儿+到:哪里+能到:地方+能到:地点+能到:位置+能去:地方+能去:地点+能去:位置 +WHERE_CAN_I_GO|choose_gowhere_33|+qiwu:哪+qiwu:哪儿+qiwu:哪里 + +# 周围有什么 +AROUND_THINGS|havewhat_thing|+旁边:吗+旁边:呢+这里:呢+这里:吗+附近:吗+周围:吗+地方:啊+地点:啊+周围:呀 +AROUND_THINGS|place_have_something|+这里:什么 # 周围有什么人 -AROUND_NPC|know_exist_what|+周围:人+旁边:人+附近:人+周围:谁+这里:谁+这里:人+有什么:人+里面:人+里面:谁+哪些:人+qiwu:人+qiwu:谁+有:谁+有:人+附近:谁+有:附近+旁边:谁 -AROUND_NPC|zhiwen|+这里:谁+这里:谁+谁:在 +AROUND_NPC|place_have_something|+这里:谁+里面:人+里面:谁+附近:人+附近:谁+qiwu:附近+周围:谁+周围:人+旁边:人+旁边:谁+qiwu:周围+谁:那 -# 周围有什么npc类别 -AROUND_NPC_CLASS|know_exist_what|+周围:name+附近:name - -# 周围有什么 -AROUND_THINGS|know_exist_what_mohu|+有什么:周围+有什么:附近+有什么:这里+有:哪些:这里+有谁:周围+有什么:里面+有什么:旁边+qiwu:旁边+有什么:这里+有:哪些 # 周围有什么物品 -AROUND_ITEM|know_exist_what|+周围:物品+旁边:物品+旁边:东西+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+有什么:东西+有什么:物品+哪些:物品+哪些:东西+有:东西+里面:物品 -AROUND_ITEM|nums|+有:哪些 -# AROUND_ITEM|zhiwen|+附近:who+周围:who+旁边:who +AROUND_ITEM|place_have_something|+周围:物品+旁边:物品+旁边:东西+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+qiwu:物品+里面:物品+里面:东西+里面:什么 +AROUND_ITEM|havewhat_thing|+周围:物品+旁边:物品+旁边:东西+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+qiwu:物品+里面:物品+里面:东西+里面:什么 + # 周围有什么地方 -AROUND_PLACE|know_exist_what|+周围:地点+周围:地方+哪些:地方+哪些:地点+旁边:地方+旁边:地点+附近:地方+附近:地点 +AROUND_PLACE|havewhat_thing|+周围:地点+周围:地方+哪些:地方+哪些:地点+旁边:地方+旁边:地点+附近:地方+附近:地点 +AROUND_PLACE|place_have_something|+周围:地点+周围:地方+哪些:地方+哪些:地点+旁边:地方+旁边:地点+附近:地方+附近:地点 -# 周围有什么物品类别 -AROUND_ITEM_CLASS|know_exist_what|+周围:name+附近:name +# 周围有什么npc类别 +AROUND_NPC_CLASS|havewhat_thing|+周围:name+附近:name+旁边:name -# 我有什么 -WHAT_ITEM_I_HAVE|know_exist_what_mohu|+有什么:qiwu+什么:qiwu+qiwu:东西+qiwu:地方 -WHAT_ITEM_I_HAVE|know_exist_what|有什么:东西 -WHAT_ITEM_I_HAVE|zhiwen|+qiwu:带 +# 周围有什么物品类别 +AROUND_ITEM_CLASS|havewhat_thing|+周围:name+附近:name+旁边:name -# 里面有谁 -WHO_IN_THERE|shishui|+谁:里面+里面:人 -# 去xx -GO_TO|yaobuyao|+去:name+到:name -# 怎么找到NPC -HOW_TO_FIND_NPC|xxx|+找到:name +# 我有什么 +WHAT_ITEM_I_HAVE|place_have_something|+qiwu:什么+qiwu:东西+qiwu:物品+qiwu:装备+qiwu:补给 -# 你是谁 -WHO_YOU_ARE|zhiwen|+botname:谁+botname:干嘛+那个人:谁+人:谁+botname:是+人:是 +# 去xx +GO_TO|do_what_vn|+去:name+到:name -# 任务是什么 -TASK_IS_WHAT|shishenme|+是什么:任务+qiwu:任务 -TASK_IS_WHAT|zhiwen|+qiwu:要去 # npc在哪里 -NPC_LOCATION|wenzainali|+哪里:name+哪:name+地方:name+地点:name +NPC_LOCATION|something_where|+哪里:name+哪:name+地方:name+地点:name+位置:name+哪儿:name+位置:name # 物品在哪里 -ITEM_LOCATION|wenzainali|+哪里:name+哪:name+地方:name+地点:name+位置:name+哪儿:name+位置:name +ITEM_LOCATION|something_where|+哪里:name+哪:name+地方:name+地点:name+位置:name+哪儿:name+位置:name # 怎么找到npc -HOW_FIND_NPC|want_know_zenmezuo|+找到:name +HOW_FIND_NPC|want_known_zenmezuo_vn|+找到:name #怎么找到物品 -HOW_FIND_ITEM|want_know_zenmezuo|+找到:name +HOW_FIND_ITEM|want_known_zenmezuo_vn|+找到:name + +# 怎么去XXX +HOW_TO_THERE|want_known_zenmezuo_vn|默认 + + # 沙滩上有什么人 -WHAT_NPC_IN_LOCATION|xxx|地点 +WHAT_NPC_IN_LOCATION|havewhat_thing|+name:人 +WHAT_NPC_IN_LOCATION|place_have_something|+name:谁+name:人 # xx上有什么东西 -WAHT_ITEM_IN_LOCATION|xxx|地点 +WAHT_ITEM_IN_LOCATION|havewhat_thing|+name:物品+name:东西+name:地方+name:位置 # 地点上有什么 -WHAT_THINGS_IN_LOCATION|xxx|地点 +WHAT_THINGS_IN_LOCATION|have_what_thing|地点 + + + + +# 你是谁 +WHO_YOU_ARE|zhiwen|+botname:谁+botname:干嘛+那个人:谁+人:谁+botname:是+人:是 + +# 任务是什么 +TASK_IS_WHAT|something_iswhat|+什么:任务 +TASK_IS_WHAT|shenme_shi_shenme|+qiwu:任务 + # npc的属性是多少 -NPC_ATTR|nums|+name:attrName -NPC_ATTR|shishenme|+name:attrName +NPC_ATTR|shuliang_1|+name:attrName # 物品的属性是多少 -ITEM_ATTR|nums|+name:attrName -ITEM_ATTR|shishenme|+name:attrName +ITEM_ATTR|shuliang_1|+name:attrName + -# 周围有什么物品类别 -AOURND_NPC_CLASS|know_exist_what|+周围:name+附近:name -# 怎么去XXX -HOW_TO_THERE|want_know_zenmezuo|+去:name diff --git a/keywords2.txt b/keywords2.txt index c42da21..6645063 100644 --- a/keywords2.txt +++ b/keywords2.txt @@ -1,118 +1,6 @@ # ------------------------------------------------------------------------------ -# 第一块,意图|相关的语义关系名 -意图语义关系名 - -# 第二块, 意图|语义关系名|关键词 - - -# ------------------------------------------------------------------------------ -WHERE_I_AM|zainali|+在:哪里+在:哪儿+在:哪+在:位置+在:地点+在:地方+到:哪里+到:地点+到:地方 -WHERE_I_AM|wenzainali|+哪:qiwu+地方:qiwu+位置:qiwu+地点:qiwu+哪里:qiwu+哪儿:qiwu - -WHERE_CAN_I_GO|choose_gowhere|+哪里:qiwu+哪:qiwu+哪儿:qiwu+地方:qiwu+哪里:去+哪:能去+哪里:能去+哪儿:能去+地方:能去+地方:去+地方:能去+哪里:能去+哪:去+哪:能去+哪儿:去+哪:qiwu - -SURROUNDING_NPC|know_exist_what|+周围:人+附近:人+周围:谁+这里:谁+这里:人+有什么:人+里面:人+里面:谁+哪些:人+qiwu:人+qiwu:谁+有:谁+有:人 -SURROUNDING_THINGS|know_exist_what_mohu|+有什么:周围+有什么:附近+有什么:这里+有:哪些:这里+有谁:周围+有什么:里面 -SURROUNDING_NPC_CLASS|know_exist_what|+周围:name+附近:name -SURROUNDING_ITEM|know_exist_what|+周围:name+附近:name -SURROUNDING_PLACE|know_exist_what|+周围:地点+周围:地方+哪些:地方+哪些:地点 -SURROUNDING_ITEM_CLASS|know_exist_what|+周围:name+附近:name - -WHAT_ITEM_I_HAVE|know_exist_what_mohu|+有什么:qiwu+什么:qiwu+qiwu:东西+qiwu:地方 -WHO_IN_THERE|shishui|+谁:里面+里面:人 - -GO_TO|yaobuyao|+去:name+到:name - -WHO_TO_FIND_NPC|xxx|+找到:name - -WHO_ARE_YOU|zhiwen|+botname:谁+botname:干嘛+那个人:谁+人:谁+botname:是+人:是 -TASK_IS_WHAT|shishenme|+是什么:任务+qiwu:任务 - -FIND_NPC_LOCATION|xxx|+哪里:name+哪:name+地方:name+地点:name -FIND_ITEM_LOCATION|xxx|+哪里:name+哪:name+地方:name+地点:name+位置:name+哪儿:name - -WHAT_NPC_IN_LOCATION|xxx|地点 -WAHT_ITEM_IN_LOCATION|xxx|地点 -WHAT_THINGS_IN_LOCATION|xxx|地点 - - - - - -# -------------------------------------------------------------------------- -# 地图在哪里 -map_zainali|+在:哪里+在:哪儿+在:哪+在:位置+在:地点+在:地方+到:哪里+到:地点+到:地方 -map_wenzainali|+哪:qiwu+地方:qiwu+位置:qiwu+地点:qiwu+哪里:qiwu+哪儿:qiwu - - -# 能去哪里 -map_choose_gowhere|+哪里:qiwu+哪:qiwu+哪儿:qiwu+地方:qiwu+哪里:去+哪:能去+哪里:能去+哪儿:能去+地方:能去+地方:去+地方:能去+哪里:能去+哪:去+哪:能去+哪儿:去+哪:qiwu - -# 周围有什么人 -people_know_exist_what|+周围:人+附近:人+周围:谁+这里:谁+这里:人+有什么:人+里面:人+里面:谁+哪些:人+qiwu:人+qiwu:谁+有:谁+有:人 - -# 周围有什么物品 -item_know_exist_what|+周围:物品+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+有什么:东西+有什么:物品+哪些:物品+哪些:东西 - -# 我有什么东西 -item_rencheng|+qiwu:东西 - -# 我有什么 -we_have_know_exist_what_mohu|+有什么:qiwu+什么:qiwu+qiwu:东西+qiwu:地方 - -# 里面的是谁 -inner_shishui|+谁:里面+里面:人 - -# 去某个地方 -map_yaobuyao|+去:name+到:name - -# 你是谁 -talker_zhiwen|+botname:谁+botname:干嘛+那个人:谁+人:谁+botname:是+人:是 - -# 任务是什么 -task_shishenme|+是什么:任务+qiwu:任务 - -# 周围有什么 -things|know_exist_what_mohu|+有什么:周围+有什么:附近+有什么:这里+有:哪些:这里+有谁:周围+有什么:里面 - -# 周围有什么地方 -place_know_exist_what|+周围:地点+周围:地方+哪些:地方+哪些:地点 - -# 周围有什么npc类名 -npc_class_pattern|+周围:name+附近:name - -# 周围有什么item类名 -item_class_pattern|+周围:name+附近:name - -# 怎么找到xxx -find_pattern|+找到:name - -# npc在哪里 -npc_location_pattern|+哪里:name+哪:name+地方:name+地点:name - -# 物品在哪里 -item_location_pattern|+哪里:name+哪:name+地方:name+地点:name+位置:name+哪儿:name - -# 某地点有什么 -things_in_place_xxxx|+地点:什么 - -# 地点有什么人 -NPC_in_place_xxx|+地点:什么 - -# 地点有什么物品 -items_in_place_xxx|+地点:什么 - -# =====================================new add============================================ -people_rencheng|+机器人:谁+那个人:谁+人:谁+机器人:干嘛 - - - - - - -# ------------------------------------------------------------------------------ # 格式 # 意图|语义关系名字|关键词 # name表示可以替换的名字,如物品名、角色名 @@ -124,31 +12,39 @@ people_rencheng|+机器人:谁+那个人:谁+人:谁+机器人:干嘛 # ------------------------------------------------------------------------------ # 我在哪里 WHERE_I_AM|zainali|+在:哪里+在:哪儿+在:哪+在:位置+在:地点+在:地方+到:哪里+到:地点+到:地方 -WHERE_I_AM|wenzainali|+哪:qiwu+地方:qiwu+位置:qiwu+地点:qiwu+哪里:qiwu+哪儿:qiwu +WHERE_I_AM|wenzainali|+哪:qiwu+地方:qiwu+位置:qiwu+地点:qiwu+哪里:qiwu+哪儿:qiwu+哪:landey+地方:landey+位置:landey+地点:landey+哪里:landey+哪儿:landey + + + # 我能去哪里 -WHERE_CAN_I_GO|choose_gowhere|+哪里:qiwu+哪:qiwu+哪儿:qiwu+地方:qiwu+哪里:去+哪:能去+哪里:能去+哪儿:能去+地方:能去+地方:去+地方:能去+哪里:能去+哪:去+哪:能去+哪儿:去+哪:qiwu +WHERE_CAN_I_GO|choose_gowhere|+哪里:qiwu+哪:qiwu+哪儿:qiwu+地方:qiwu+哪里:去+哪:能去+哪里:能去+哪儿:能去+地方:能去+地方:去+地方:能去+哪里:能去+哪:去+哪:能去+哪儿:去+哪:qiwu+哪:到+哪儿:到+哪里:到 # 周围有什么人 -AROUND_NPC|know_exist_what|+周围:人+附近:人+周围:谁+这里:谁+这里:人+有什么:人+里面:人+里面:谁+哪些:人+qiwu:人+qiwu:谁+有:谁+有:人 +AROUND_NPC|know_exist_what|+周围:人+旁边:人+附近:人+周围:谁+这里:谁+这里:人+有什么:人+里面:人+里面:谁+哪些:人+qiwu:人+qiwu:谁+有:谁+有:人+附近:谁+有:附近+旁边:谁 +AROUND_NPC|zhiwen|+这里:谁+这里:谁+谁:在 # 周围有什么npc类别 AROUND_NPC_CLASS|know_exist_what|+周围:name+附近:name # 周围有什么 -AROUND_THINGS|know_exist_what_mohu|+有什么:周围+有什么:附近+有什么:这里+有:哪些:这里+有谁:周围+有什么:里面 +AROUND_THINGS|know_exist_what_mohu|+有什么:周围+有什么:附近+有什么:这里+有:哪些:这里+有谁:周围+有什么:里面+有什么:旁边+qiwu:旁边+有什么:这里+有:哪些 # 周围有什么物品 -AROUND_ITEM|know_exist_what|+周围:物品+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+有什么:东西+有什么:物品+哪些:物品+哪些:东西 +AROUND_ITEM|know_exist_what|+周围:物品+旁边:物品+旁边:东西+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+有什么:东西+有什么:物品+哪些:物品+哪些:东西+有:东西+里面:物品 +AROUND_ITEM|nums|+有:哪些 +# AROUND_ITEM|zhiwen|+附近:who+周围:who+旁边:who # 周围有什么地方 -AROUND_PLACE|know_exist_what|+周围:地点+周围:地方+哪些:地方+哪些:地点 +AROUND_PLACE|know_exist_what|+周围:地点+周围:地方+哪些:地方+哪些:地点+旁边:地方+旁边:地点+附近:地方+附近:地点 # 周围有什么物品类别 AROUND_ITEM_CLASS|know_exist_what|+周围:name+附近:name # 我有什么 WHAT_ITEM_I_HAVE|know_exist_what_mohu|+有什么:qiwu+什么:qiwu+qiwu:东西+qiwu:地方 +WHAT_ITEM_I_HAVE|know_exist_what|有什么:东西 +WHAT_ITEM_I_HAVE|zhiwen|+qiwu:带 # 里面有谁 WHO_IN_THERE|shishui|+谁:里面+里面:人 @@ -165,12 +61,14 @@ WHO_YOU_ARE|zhiwen|+botname:谁+botname:干嘛+那个人:谁+人:谁+botname:是 # 任务是什么 TASK_IS_WHAT|shishenme|+是什么:任务+qiwu:任务 +TASK_IS_WHAT|zhiwen|+qiwu:要去 # npc在哪里 NPC_LOCATION|wenzainali|+哪里:name+哪:name+地方:name+地点:name # 物品在哪里 -ITEM_LOCATION|wenzainali|+哪里:name+哪:name+地方:name+地点:name+位置:name+哪儿:name +ITEM_LOCATION|wenzainali|+哪里:name+哪:name+地方:name+地点:name+位置:name+哪儿:name+位置:name + # 怎么找到npc HOW_FIND_NPC|want_know_zenmezuo|+找到:name @@ -198,5 +96,6 @@ ITEM_ATTR|shishenme|+name:attrName AOURND_NPC_CLASS|know_exist_what|+周围:name+附近:name # 怎么去XXX -HOW_TO_THERE|want_know_zenmezuo|默认 +HOW_TO_THERE|want_know_zenmezuo|+去:name + diff --git a/src/main/java/com/qiwu/chatbotbackend/Config/Config.java b/src/main/java/com/qiwu/chatbotbackend/Config/Config.java index 172e7b8..7fbc9ba 100644 --- a/src/main/java/com/qiwu/chatbotbackend/Config/Config.java +++ b/src/main/java/com/qiwu/chatbotbackend/Config/Config.java @@ -10,6 +10,10 @@ public class Config { public static String QA_URL = null; public static String CC_URL = null; + public static String NO_ONE_CAN_REPLY_UNKNOWN; + + public static String KEYWORD_DIR = null; + //名字,地址 public static String GAME_BOT_CATEGORY = null; @@ -167,6 +171,15 @@ public class Config { public static String BACKUP_PATH = null; + public static String UNKNOWN_COUNTER_NAME = null; + + public static String BACKUP_ERROR = null; + + public static String QA_FETCH_ERROR = null; + + public static long CHATCACHE_TIME_OUT; + + } diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/DB/PlatformUtils.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/DB/PlatformUtils.java index 8cd2e5d..a3e7ad6 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/DB/PlatformUtils.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/DB/PlatformUtils.java @@ -32,12 +32,11 @@ public class PlatformUtils { } public List queryConditionIdByTypetreeId(List typetreeIdList){ - String sql = "select conditionId from typetreeNcondition where typetreeId in (?)"; + String sql = "select conditionId from typetreeNcondition where typetreeId in (" + Joiner.on(",").join(typetreeIdList) + ")"; String keywordText = ""; List idList = new ArrayList(); try{ PreparedStatement ps = conn.prepareStatement(sql); - ps.setString(1,Joiner.on(",").join(typetreeIdList)); ResultSet rs = ps.executeQuery(); while(rs.next()){ idList.add(rs.getInt("conditionId")); diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/entity/BotInfo.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/entity/BotInfo.java index 27a2ee7..160d093 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/entity/BotInfo.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/entity/BotInfo.java @@ -1,11 +1,11 @@ package com.qiwu.chatbotbackend.actiongenerate.entity; public class BotInfo { - Integer botId; - String welcomeText; - String goodbyeText; - String postURL; - String defaultConfigCategory; + Integer botId = 0; + String welcomeText = ""; + String goodbyeText = ""; + String postURL = ""; + String defaultConfigCategory = ""; String bothValue; String queryTextTransfer; diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/ActionServlet.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/ActionServlet.java index 188fc27..8b7ac9b 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/ActionServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/ActionServlet.java @@ -28,6 +28,8 @@ public class ActionServlet extends HttpServlet { JSONObject responseJSONObject = new JSONObject(); Boolean flag = true; Integer botId; + EngineUtils engine = null; + SqlHelper helper = null; @@ -47,8 +49,8 @@ public class ActionServlet extends HttpServlet { try { - EngineUtils engine = new EngineUtils(); - SqlHelper helper = new SqlHelper(); + engine = new EngineUtils(); + helper = new SqlHelper(); ActionUtils actionUtils = new ActionUtils(engine, helper); @@ -68,9 +70,6 @@ public class ActionServlet extends HttpServlet { case "update_condition_display_order": actionUtils.updateConditionDisplayOrder(receiveParameters); break; - case "update_bot_info": - actionUtils.updateBotInfo(receiveParameters); - break; case "update_goodbye": actionUtils.updateGoodbye(receiveParameters); break; @@ -98,6 +97,9 @@ public class ActionServlet extends HttpServlet { case "update_condition_name": actionUtils.updateConditionName(receiveParameters); break; + case "update_bot_info": + actionUtils.updateBotInfo(receiveParameters); + break; } if(actionUtils.intervalStatus.getStatus() == 1) actionUtils.query4post(receiveParameters); @@ -105,8 +107,7 @@ public class ActionServlet extends HttpServlet { } - helper.destroy(); - engine.destroy(); + switch (actionUtils.intervalStatus.getStatus()){ case 1: @@ -121,6 +122,9 @@ public class ActionServlet extends HttpServlet { } catch (SQLException e) { e.printStackTrace(); + } finally{ + helper.destroy(); + engine.destroy(); } }else{ diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/BackupServlet.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/BackupServlet.java index 1cf3a7f..b188a50 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/BackupServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/BackupServlet.java @@ -23,6 +23,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import static com.qiwu.chatbotbackend.Config.Config.BACKUP_ERROR; import static com.qiwu.chatbotbackend.Config.Config.BOT_BACKUP_DIR; import static com.qiwu.chatbotbackend.Config.Config.SQL_CONNECTION_ERROR; @@ -40,6 +41,8 @@ public class BackupServlet extends HttpServlet { JSONObject responseJSONObject = new JSONObject(); Boolean flag = true; Integer botId = 0, categoryIndex; + EngineUtils engine = null; + SqlHelper helper = null; if (jsonStr != null && !jsonStr.equals("")) { @@ -56,8 +59,8 @@ public class BackupServlet extends HttpServlet { botCategoryName = receiveParameters.getString("catName"); - EngineUtils engine = new EngineUtils(); - SqlHelper helper = new SqlHelper(); + engine = new EngineUtils(); + helper = new SqlHelper(); BotInfo botInfo = null; List conditionList = new ArrayList(); List configTermList = new ArrayList(); @@ -71,12 +74,12 @@ public class BackupServlet extends HttpServlet { //actionUtils. //如果需要保存condition,查询所有condition - if (receiveParameters.containsKey("saveCondition") && receiveParameters.getBoolean("saveCondition")){ + if (receiveParameters.containsKey("saveCondition") && receiveParameters.getBoolean("saveCondition")) { conditionList = helper.queryConditionAll(botId); } //如果需要保存配置文件,则从根目录开始保存配置文件 - if(receiveParameters.containsKey("saveConfig") && receiveParameters.getBoolean("saveConfig")){ + if (receiveParameters.containsKey("saveConfig") && receiveParameters.getBoolean("saveConfig")) { categoryIndex = receiveParameters.getInteger("indexCategory"); //查询某个类别下的所有类别 @@ -86,7 +89,7 @@ public class BackupServlet extends HttpServlet { } - if(!receiveParameters.containsKey("saveVariable") || receiveParameters.getBoolean("saveVariable")){ + if (!receiveParameters.containsKey("saveVariable") || receiveParameters.getBoolean("saveVariable")) { variablesList = helper.queryVariableAll(botId); } @@ -98,21 +101,22 @@ public class BackupServlet extends HttpServlet { //backupFile.put("botId"); - try { - writeFile(BOT_BACKUP_DIR + botId + ".backup",JSON.toJSONString(backup)); + writeFile(BOT_BACKUP_DIR + botId + ".backup", JSON.toJSONString(backup)); // ReadFile("D:\\8.json"); System.out.println(); } catch (IOException e) { e.printStackTrace(); } - helper.destroy(); - engine.destroy(); - + } catch(IOException e){ + intervalStatus = new IntervalStatus(0, BACKUP_ERROR); } catch (SQLException e) { intervalStatus = new IntervalStatus(0, SQL_CONNECTION_ERROR); + } finally{ + helper.destroy(); + engine.destroy(); } } diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/ConfigTermServlet.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/ConfigTermServlet.java index 4db6edc..1b7c8da 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/ConfigTermServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/ConfigTermServlet.java @@ -16,7 +16,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; -import java.sql.SQLException; import static com.qiwu.chatbotbackend.Config.Config.JSON_FORMAT_ERROR; @@ -42,12 +41,15 @@ public class ConfigTermServlet extends HttpServlet { operationType = receiveParaneters.getString("type"); botId = receiveParaneters.getInteger("botId"); + EngineUtils engine = null; + ConfigTermUtils configUtils = null; + SqlHelper helper = null; + try { //EngineUtils engine = new EngineUtils(); - SqlHelper helper = new SqlHelper(); - EngineUtils engine = null; - ConfigTermUtils configUtils = null; + helper = new SqlHelper(); + IntervalStatus intervalStatus = null; @@ -67,23 +69,28 @@ public class ConfigTermServlet extends HttpServlet { } else if(operationType.endsWith("config")){ - engine = new EngineUtils(); - botAccount = engine.queryBotAccountByBotId(botId); - System.out.println("botAccount" + botAccount); - configUtils = new ConfigTermUtils(botAccount, helper, context); - switch (operationType){ - case "insert_config": - configUtils.insertConfigTerm(receiveParaneters); - break; - case "update_config": - configUtils.updateConfig(receiveParaneters); - break; - case "delete_config": - configUtils.deleteConfig(receiveParaneters); - break; + try { + engine = new EngineUtils(); + botAccount = engine.queryBotAccountByBotId(botId); + System.out.println("botAccount" + botAccount); + configUtils = new ConfigTermUtils(botAccount, helper, context); + switch (operationType) { + case "insert_config": + configUtils.insertConfigTerm(receiveParaneters); + break; + case "update_config": + configUtils.updateConfig(receiveParaneters); + break; + case "delete_config": + configUtils.deleteConfig(receiveParaneters); + break; + } + intervalStatus = configUtils.intervalStatus; + engine.destroy(); + }catch(Exception e ){ + engine.destroy(); + throw(new Exception()); } - intervalStatus = configUtils.intervalStatus; - engine.destroy(); }else{ categoryUtils = new CategoryUtils(helper); switch(operationType) { @@ -103,7 +110,6 @@ public class ConfigTermServlet extends HttpServlet { } intervalStatus = categoryUtils.intervalStatus; } - helper.destroy(); @@ -118,10 +124,13 @@ public class ConfigTermServlet extends HttpServlet { break; } - - } catch (SQLException e) { - + } catch (Exception e){ + System.out.println(e.getMessage()); e.printStackTrace(); + responseJSONObject.put("status", 0); + responseJSONObject.put("parameter", e.getMessage()); + }finally { + helper.destroy(); } diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/MacroServlet.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/MacroServlet.java index 28764c7..d3551e2 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/MacroServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/MacroServlet.java @@ -43,10 +43,13 @@ public class MacroServlet extends HttpServlet { operationType = receiveParameters.getString("type"); botId = receiveParameters.getInteger("botId"); + SqlHelper helper = null; + EngineUtils engine = null; + try { - SqlHelper helper = new SqlHelper(); - EngineUtils engine = new EngineUtils(); + helper = new SqlHelper(); + engine = new EngineUtils(); botAccount = engine.queryBotAccountByBotId(botId); VariableUtils variableUtils = null; @@ -66,6 +69,9 @@ public class MacroServlet extends HttpServlet { } catch (SQLException e) { e.printStackTrace(); + } finally{ + helper.destroy(); + engine.destroy(); } diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/RecoveryServlet.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/RecoveryServlet.java index 22a41d7..3cd4346 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/RecoveryServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/RecoveryServlet.java @@ -56,7 +56,8 @@ public class RecoveryServlet extends HttpServlet { botAccount = receiveParameters.getString("botName"); botName = receiveParameters.getString("botName_yhm"); - + SqlHelper helper = null; + EngineUtils engine = null; @@ -75,8 +76,8 @@ public class RecoveryServlet extends HttpServlet { List originVariableList, variableList = data.getJSONArray("variablesList").toJavaList(Variable.class); BotInfo botInfo = data.getJSONObject("botInfo").toJavaObject(BotInfo.class); - SqlHelper helper = new SqlHelper(); - EngineUtils engine = new EngineUtils(); + helper = new SqlHelper(); + engine = new EngineUtils(); ActionUtils actionUtils = new ActionUtils(engine, helper); VariableUtils variableUtils = new VariableUtils(helper); @@ -172,13 +173,13 @@ public class RecoveryServlet extends HttpServlet { intervalStatus = actionUtils.intervalStatus; - } - engine.destroy(); - helper.destroy(); }catch (SQLException e){ intervalStatus = new IntervalStatus(0, SQL_CONNECTION_ERROR); + } finally{ + engine.destroy(); + helper.destroy(); } } diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/VariableServlet.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/VariableServlet.java index 2b60693..d2a4517 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/VariableServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/servlet/VariableServlet.java @@ -43,10 +43,14 @@ public class VariableServlet extends HttpServlet { operationType = receiveParameters.getString("type"); botId = receiveParameters.getInteger("botId"); + SqlHelper helper = null; + EngineUtils engine = null; + try { - SqlHelper helper = new SqlHelper(); - EngineUtils engine = new EngineUtils(); + helper = new SqlHelper(); + engine = new EngineUtils(); + botAccount = engine.queryBotAccountByBotId(botId); VariableUtils variableUtils = null; @@ -90,12 +94,12 @@ public class VariableServlet extends HttpServlet { break; } - helper.destroy(); - engine.destroy(); - } catch (SQLException e) { e.printStackTrace(); + } finally { + helper.destroy(); + engine.destroy(); } diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java index 157eede..d0a3543 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ActionUtils.java @@ -390,9 +390,17 @@ public class ActionUtils { relationHead = condition.getString("relationHead"); if(relationHead.equals("")) relationHead = "#visitorname"; + //不是问号,没有加号,且不是星号,则添加问号 + else if(!relationHead.equals("?") && !relationHead.startsWith("+") && !relationHead.equals("*")) + relationHead = "+" + relationHead; + + relationTail = condition.getString("relationTail"); if(relationTail.equals("")) relationTail = "#visitorname"; + else if(!relationTail.equals("?") && !relationTail.startsWith("+") && !relationHead.equals("*")) + relationTail = "+" + relationTail; + relationName = condition.getString("relationName"); //condition的属性 number、string、location @@ -429,7 +437,7 @@ public class ActionUtils { repeatElem = repeatList.getJSONObject(i); - if(!repeatElem.getString("repeatKeywords").startsWith("+")) + if(!repeatElem.getString("repeatKeywords").startsWith("+") && !repeatElem.getString("repeatKeywords").equals("")) repeatElem.put("repeatKeywords", "+" + repeatElem.getString("repeatKeywords")); repeatText.append(repeatElem.getString("repeatString")).append("=").append(repeatElem.getString("repeatKeywords")); @@ -743,6 +751,8 @@ public class ActionUtils { case 401: intervalStatus = new IntervalStatus(0, TOKEN_TIME_OUT); break; + case 500: + intervalStatus = new IntervalStatus(0, CONDITION_BACKEND_ERROR); default: intervalStatus = new IntervalStatus(0, CONDITION_BACKEND_ERROR); } @@ -765,7 +775,7 @@ public class ActionUtils { try{ platformUtils = new PlatformUtils(); - helper.deleteUserData(botId); + //helper.deleteUserData(botId); idList = platformUtils.queryConditionIdByTypetreeId(parameters.getJSONArray("conditionCategories")); @@ -778,6 +788,8 @@ public class ActionUtils { patternConditionJson.put("active", false); patternConditionJson.put("conditionCategory", "0:默认"); relationName = patternConditionJson.getString("relationName").replace("0", "a0").replace("-", "b0"); + conditionExtraKeywords.putIfAbsent(DEFAULT_CONDITION + "_head", new HashSet()); + conditionExtraKeywords.putIfAbsent(DEFAULT_CONDITION + "_tail", new HashSet()); for(int i = 1;i < 10;i++){ //给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样 @@ -850,12 +862,12 @@ public class ActionUtils { } } - platformUtils.destroy(); - }catch (SQLException e){ intervalStatus = new IntervalStatus(0, ACTION_TEXT_GENERATE_ERROR); System.out.println(e.getMessage()); + }finally { + platformUtils.destroy(); } } diff --git a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ConfigTermUtils.java b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ConfigTermUtils.java index ccc932e..f7ec951 100644 --- a/src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ConfigTermUtils.java +++ b/src/main/java/com/qiwu/chatbotbackend/actiongenerate/utils/ConfigTermUtils.java @@ -14,10 +14,7 @@ import com.qiwu.chatbotbackend.processing.UserInfoController; import javax.servlet.ServletContext; import java.io.IOException; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static com.qiwu.chatbotbackend.Config.Config.CONFIG_INSERT_ERROR; @@ -90,15 +87,12 @@ public class ConfigTermUtils { List curPremiseList = new ArrayList(); List hisPremiseList = new ArrayList(); Map updateKnowledge = new HashMap(); - Map punctReplaceMap = new HashMap(){ - { - put(",", ","); - put("|", ""); - put("\r\n", ""); - put("\n", ""); - put("\t", ""); - } - }; + Map punctReplaceMap = new LinkedHashMap(); + punctReplaceMap.put(",", ","); + punctReplaceMap.put("|", ""); + punctReplaceMap.put("\r\n", ""); + punctReplaceMap.put("\n", ""); + punctReplaceMap.put("\t", ""); //解析当前信息的前置条件 @@ -307,7 +301,7 @@ public class ConfigTermUtils { * @param replaceMap * @return */ - public String textReplace(String text, Map replaceMap){ + public static String textReplace(String text, Map replaceMap){ for(String key:replaceMap.keySet()){ text = text.replace(key, replaceMap.get(key)); } diff --git a/src/main/java/com/qiwu/chatbotbackend/db/SqlHelper.java b/src/main/java/com/qiwu/chatbotbackend/db/SqlHelper.java index 9ec475d..b8b8fbd 100644 --- a/src/main/java/com/qiwu/chatbotbackend/db/SqlHelper.java +++ b/src/main/java/com/qiwu/chatbotbackend/db/SqlHelper.java @@ -798,14 +798,15 @@ public class SqlHelper { boolean b; try { - String sql = "update chatbot_condition set conditionData = ?, actionText = ?, categoryInfo = ?, active = ? where botId = ? and conditionId=?"; + String sql = "update chatbot_condition set conditionData = ?, actionText = ?, categoryInfo = ?, active = ?, displayOrder = ? where botId = ? and conditionId=?"; PreparedStatement ps1 = conn.prepareStatement(sql); ps1.setString(1, condition.getConditionJsonText()); ps1.setString(2, condition.getActionText()); ps1.setString(3, condition.getCategory()); ps1.setString(4, condition.getActive()); - ps1.setInt(5, condition.getBotId()); - ps1.setInt(6, condition.getConditionId()); + ps1.setInt(5, condition.getDisplayOrder()); + ps1.setInt(6, condition.getBotId()); + ps1.setInt(7, condition.getConditionId()); b = ps1.executeUpdate() == 1; ps1.close(); @@ -1085,6 +1086,29 @@ public class SqlHelper { } } + + public boolean deleteConditionByBotId(int botId) { + String sql = "delete from chatbot_condition where botId= ?"; + boolean b; + + try { + PreparedStatement ps = conn.prepareStatement(sql); + ps.setString(1, String.valueOf(botId)); + b = ps.executeUpdate() == 1; + + ps.close(); + + return b; + + } catch (SQLException e) { + System.out.println(DELETE_OLD_CATEGORY_ERROR); + e.printStackTrace(); + return false; + } + } + + + public boolean batchInsertVariableByBotId(int botId, ElementConstructor constructor) { int count[]; @@ -1103,6 +1127,10 @@ public class SqlHelper { while (iit.hasNext()) { varName = iit.next(); varValue = constructor.getVarInitialMap().get(varName); + + //unknown文本可能特别长,就不插入数据库了 + if(varValue.length() > 8000) + continue; if (constructor.getConditionDescription().get(varName) == null) description = ""; else @@ -1303,7 +1331,7 @@ public class SqlHelper { varName = iit.next(); nameList.add(varName); - ps.setString(1, String.valueOf(botId)); + ps.setInt(1, botId); ps.setString(2, varName); ps.addBatch(); } @@ -1348,7 +1376,7 @@ public class SqlHelper { } - public JSONObject queryGameElementsByBotId(int id) { + public JSONObject queryGameElementsByProjectId(int id) { String sql = "select * from generate_json_tb where project_id = ?"; String userName = ""; String result = "{}"; diff --git a/src/main/java/com/qiwu/chatbotbackend/entity/ChatCache.java b/src/main/java/com/qiwu/chatbotbackend/entity/ChatCache.java index 0bb4e75..83afe11 100644 --- a/src/main/java/com/qiwu/chatbotbackend/entity/ChatCache.java +++ b/src/main/java/com/qiwu/chatbotbackend/entity/ChatCache.java @@ -93,6 +93,10 @@ public class ChatCache implements DisposableBean { } public ChatCache(UserInfo userInfo, String userKey, String randKey, String botType) throws Exception { + String k; + this.botAccount = userInfo.botAccount; + this.infoPoint = new HashMap(); + if(botType.equals("game")) { try { @@ -100,15 +104,12 @@ public class ChatCache implements DisposableBean { System.out.println("初始化时:" + this.gameEnv); } catch (Exception e) { System.out.println(ENV_ERROR); - this.infoPoint.put("error_message", ENV_ERROR); e.printStackTrace(); } } - String k; - this.botAccount = userInfo.botAccount; - this.infoPoint = new HashMap(); + Iterator iit = userInfo.varInitialMap.keySet().iterator(); while (iit.hasNext()) { k = iit.next(); diff --git a/src/main/java/com/qiwu/chatbotbackend/gameDesign/CharacterConstructor.java b/src/main/java/com/qiwu/chatbotbackend/gameDesign/CharacterConstructor.java index 178b608..e93701d 100644 --- a/src/main/java/com/qiwu/chatbotbackend/gameDesign/CharacterConstructor.java +++ b/src/main/java/com/qiwu/chatbotbackend/gameDesign/CharacterConstructor.java @@ -3,10 +3,12 @@ package com.qiwu.chatbotbackend.gameDesign; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.qiwu.chatbotbackend.db.SqlHelper; -import com.qiwu.chatbotbackend.entity.ConfigTermText; import com.qiwu.chatbotbackend.entity.UserInfo; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; public class CharacterConstructor extends ElementConstructor { @@ -39,7 +41,7 @@ public class CharacterConstructor extends ElementConstructor { copyPattern("HOW_FIND_NPC"); copyPattern("NPC_LOCATION"); - copyPattern("AOURND_NPC_CLASS"); + copyPattern("AROUND_NPC_CLASS"); copyPattern("NPC_ATTR"); copyPattern("WHO_YOU_ARE"); @@ -94,7 +96,7 @@ public class CharacterConstructor extends ElementConstructor { classSet.add(className); //替换后的名字改为类名 replaceList.get(0)[1] = className; - appendReplacedKeyword("AOURND_NPC_CLASS", replaceList); + appendReplacedKeyword("AROUND_NPC_CLASS", replaceList); } @@ -129,13 +131,13 @@ public class CharacterConstructor extends ElementConstructor { - //同时识别zainali和wenzainali - configTermText = new ConfigTermText( - "zainali::match-Include=" + keywordMap.get("WHERE_I_AM_zainali") + "," + - "wenzainali::match-Keyword=" + keywordMap.get("NPC_LOCATION_wenzainali").toString(), " ", - "match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:wenzainali" - ); - ConfigTermText.activateCopy(configTermText, configTermTextList, "npc"); +// //同时识别zainali和wenzainali +// configTermText = new ConfigTermText( +// "zainali::match-Include=" + keywordMap.get("WHERE_I_AM_zainali") + "," + +// "wenzainali::match-Keyword=" + keywordMap.get("NPC_LOCATION_wenzainali").toString(), " ", +// "match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:wenzainali" +// ); +// ConfigTermText.activateCopy(configTermText, configTermTextList, "npc"); //根据根据NPC的名字查询地点 queryTypeConfigTermGenerate(keywordMap, "NPC_LOCATION", "npc", "queryLocationByConditionName"); @@ -145,7 +147,7 @@ public class CharacterConstructor extends ElementConstructor { //根据根据NPC类别和地点属性查询所有NPC实例 - queryTypeConfigTermGenerate(keywordMap, "AOURND_NPC_CLASS", "npc", "queryAroundNpcByClassName"); + queryTypeConfigTermGenerate(keywordMap, "AROUND_NPC_CLASS", "npc", "queryAroundNpcByClassName"); //根据类名查询周围所有实例 diff --git a/src/main/java/com/qiwu/chatbotbackend/gameDesign/ItemConstructor.java b/src/main/java/com/qiwu/chatbotbackend/gameDesign/ItemConstructor.java index b5a01ba..f44de07 100644 --- a/src/main/java/com/qiwu/chatbotbackend/gameDesign/ItemConstructor.java +++ b/src/main/java/com/qiwu/chatbotbackend/gameDesign/ItemConstructor.java @@ -3,7 +3,6 @@ package com.qiwu.chatbotbackend.gameDesign; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.qiwu.chatbotbackend.db.SqlHelper; -import com.qiwu.chatbotbackend.entity.ConfigTermText; import com.qiwu.chatbotbackend.entity.UserInfo; import java.util.*; @@ -100,12 +99,12 @@ public class ItemConstructor extends ElementConstructor { } - configTermText = new ConfigTermText( - "zainali::match-Include=" + keywordMap.get("WHERE_I_AM_zainali") + "," + - "wenzainali::match-Keyword=" + keywordMap.get("ITEM_LOCATION_wenzainali").toString(), " ", - "match,return-0", "", "yaobuyao", "goods_query:queryLocationByConditionName:wenzainali" - ); - ConfigTermText.activateCopy(configTermText, configTermTextList, "item"); +// configTermText = new ConfigTermText( +// "zainali::match-Include=" + keywordMap.get("WHERE_I_AM_zainali") + "," + +// "wenzainali::match-Keyword=" + keywordMap.get("ITEM_LOCATION_wenzainali").toString(), " ", +// "match,return-0", "", "yaobuyao", "goods_query:queryLocationByConditionName:wenzainali" +// ); +// ConfigTermText.activateCopy(configTermText, configTermTextList, "item"); queryTypeConfigTermGenerate(keywordMap, "ITEM_LOCATION", "goods", "queryLocationByConditionName"); diff --git a/src/main/java/com/qiwu/chatbotbackend/gameDesign/MapConstructor.java b/src/main/java/com/qiwu/chatbotbackend/gameDesign/MapConstructor.java index b610e65..a9b5993 100644 --- a/src/main/java/com/qiwu/chatbotbackend/gameDesign/MapConstructor.java +++ b/src/main/java/com/qiwu/chatbotbackend/gameDesign/MapConstructor.java @@ -141,7 +141,7 @@ public class MapConstructor extends ElementConstructor { queryTypeConfigTermGenerate(keywordMap, "AROUND_THINGS", "map", "queryAroundAllBySite"); queryTypeConfigTermGenerate(keywordMap, "AROUND_PLACE", "map", "queryAroundPlace"); - queryTypeConfigTermGenerate(keywordMap, "WHO_IN_THERE", "map", "queryInnerNpcBySite"); + // queryTypeConfigTermGenerate(keywordMap, "WHO_IN_THERE", "map", "queryInnerNpcBySite"); queryTypeConfigTermGenerate(keywordMap, "TASK_IS_WHAT", "map", "queryTaskDescription"); queryTypeConfigTermGenerate(keywordMap, "WHAT_THINGS_IN_LOCATION", "map", "queryItemsInPlace"); diff --git a/src/main/java/com/qiwu/chatbotbackend/gameDesign/PlotConstructor2.java b/src/main/java/com/qiwu/chatbotbackend/gameDesign/PlotConstructor2.java index 557d929..8c28468 100644 --- a/src/main/java/com/qiwu/chatbotbackend/gameDesign/PlotConstructor2.java +++ b/src/main/java/com/qiwu/chatbotbackend/gameDesign/PlotConstructor2.java @@ -13,6 +13,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.qiwu.chatbotbackend.Config.Config.*; +import static com.qiwu.chatbotbackend.actiongenerate.utils.ConfigTermUtils.textReplace; public class PlotConstructor2 extends ElementConstructor { @@ -28,6 +29,12 @@ public class PlotConstructor2 extends ElementConstructor { return plotIndex; } + static Map replaceMap = new LinkedHashMap(){ + { + + } + }; + public PlotConstructor2(SqlHelper helper, int botId, String botAccount, Map keywordMap, HashSet exceptRelation, StringBuffer POS) { super(); @@ -37,6 +44,12 @@ public class PlotConstructor2 extends ElementConstructor { this.exceptRelation = exceptRelation; this.keywordMap = keywordMap; this.POS = POS; + + replaceMap.put("\r\n", ""); + replaceMap.put("\n", ""); + replaceMap.put("\t", ""); + replaceMap.put("\\|", ""); + replaceMap.put("~", "~"); } public void construct(JSONObject jsonObject, UserInfo userinfo) { @@ -131,6 +144,7 @@ public class PlotConstructor2 extends ElementConstructor { revAdjList.get(nextPlotId).add(id); } + plot.put("plotText", textReplace(plot.getString("plotText"), replaceMap)); plotIndex.put(id, plot); } } @@ -146,7 +160,8 @@ public class PlotConstructor2 extends ElementConstructor { int size = premiseList.size(); for(int i = 0;i < size;i++){ premise = premiseList.getJSONObject(i); - premise.put("keyword", premise.getString("keyword").replace("\r\n", "").replace("\n", "").replace("\r", "")); + premise.put("keyword", textReplace(premise.getString("keyword"), replaceMap)); + //premise.put("keyword", premise.getString("keyword").replace("\r\n", "").replace("\n", "").replace("\r", "")); premiseList.set(i, premise); } @@ -332,6 +347,7 @@ public class PlotConstructor2 extends ElementConstructor { appendKnowledge(extraUK, id, "+1"); //当前剧情状态加一 appendKnowledge(extraUK, nextId, "1"); //下一步设为1 appendKnowledge(extraUK, nTaskLineName, nextGameStep); + appendKnowledge(extraUK, UNKNOWN_COUNTER_NAME, "0"); @@ -480,8 +496,8 @@ public class PlotConstructor2 extends ElementConstructor { configTermText.setConfigName("plot_" + id, false); - //当剧情没有条件限制时的操作 ,额外要求上一步剧情不是自动跳转,因为自动跳转的标识放在了上一部剧情的分支里,所以是上上个分支是否存在自动跳转 - if (curPremiseList.size() == 0 && historyPremiseList.size() == 0 && !prevAutoJump){ + //当剧情没有条件限制时的操作 需要顺便激活qa、地图、物品的查询配置文件, 额外要求当前剧情不是自动跳转 + if (curPremiseList.size() == 0 && historyPremiseList.size() == 0 && !curAutoJump){ Boolean activateFlag = false; if(extraFT.indexOf("activate") != -1) activateFlag = true; @@ -522,40 +538,50 @@ public class PlotConstructor2 extends ElementConstructor { /** * ---------------------------------------------------------------------------------------------------- - * 不设剧情不设条件时的处理 + * 剧情不设条件时的处理 * 1. 如果qa返回大于90则回答common_answer+ 剧情回答,并进入下一步剧情,这里的下一步condition是从激活之前保存的临时变量中读取出来的 * 2. 如果qa返回小于90则只回答剧情文本 * 3. 如果qa返回not_found则只回答剧情文本 * 4. 无论哪种情况都会跳下一步剧情 */ - configTermText = new ConfigTermText( - " ", "qa_status::match-Include=OK,qa_score::number-Smaller=90", "match", - "{临时变量reply-2}", " ", "process-nextStep:var={临时变量condition-2}" - ); - configTermText.setStatus("sleeping"); - configTermText.setConfigName("queryskip1",false); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); - - - configTermText = new ConfigTermText( - " ", "qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=90", "match", - "{临时变量reply-2}", " ", "process-nextStep:var={临时变量condition-2}" - ); - configTermText.setStatus("sleeping"); - configTermText.setConfigName("queryskip2",false); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); - - configTermText = new ConfigTermText( - " ", "qa_status::match-Include=not_found", "match", - "{临时变量reply-2}", " ", "process-nextStep:var={临时变量condition-2}" - ); - configTermText.setStatus("sleeping"); - configTermText.setConfigName("queryskip3",false); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); + unknownTypeConfigTermGenerate("sleeping", "queryskip1","qa_status::match-Include=OK,qa_score::number-Smaller=90", + "match", "{临时变量reply-2}", "process-nextStep:var={临时变量condition-2}"); +// +// configTermText = new ConfigTermText( +// " ", "qa_status::match-Include=OK,qa_score::number-Smaller=90", "match", +// "{临时变量reply-2}", " ", "process-nextStep:var={临时变量condition-2}" +// ); +// configTermText.setStatus("sleeping"); +// configTermText.setConfigName("queryskip1",false); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); + + unknownTypeConfigTermGenerate("sleeping", "queryskip2","qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=90", + "match", "{临时变量reply-2}", "process-nextStep:var={临时变量condition-2}"); +// +// configTermText = new ConfigTermText( +// " ", "qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=90", "match", +// "{临时变量reply-2}", " ", "process-nextStep:var={临时变量condition-2}" +// ); +// configTermText.setStatus("sleeping"); +// configTermText.setConfigName("queryskip2",false); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); + + + unknownTypeConfigTermGenerate("sleeping", "queryskip3","qa_status::match-Include=not_found", + "match", "{临时变量reply-2}", "process-nextStep:var={临时变量condition-2}"); + +// +// configTermText = new ConfigTermText( +// " ", "qa_status::match-Include=not_found", "match", +// "{临时变量reply-2}", " ", "process-nextStep:var={临时变量condition-2}" +// ); +// configTermText.setStatus("sleeping"); +// configTermText.setConfigName("queryskip3",false); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); @@ -566,65 +592,91 @@ public class PlotConstructor2 extends ElementConstructor { */ //处于激活状态,其他的属于待激活状态,jStatus这一条不设为1,而是0 - configTermText = new ConfigTermText(" ", " ", "activate,post::gameQA(" + QA_URL + ")", - "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); - configTermText.setNextStepStatus("active"); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); + unknownTypeConfigTermGenerate("waiting", "unknownStart","", + "activate,post::gameQA(" + QA_URL + ")", "{unknownText-2}", ""); + unknownTypeConfigTermGenerate("sleeping", "unknown1","qa_status::match-Include=not_found", - configTermText = new ConfigTermText( - " ", "qa_status::match-Include=not_found", "match,return-0", - "{unknownText-2}", " ", "" - ); - configTermText.setStatus("sleeping"); - configTermText.setConfigName("unknown1",false); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); + "match,return-0", "{unknownText-2}", ""); - - configTermText = new ConfigTermText( - " ", "qa_status::match-Include=not_found,unknownText::match-Include=null", "match,return-0", - UNKNOWN_TEXT, - " ", "" - ); - configTermText.setStatus("sleeping"); - configTermText.setConfigName("unknown2",false); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); + unknownTypeConfigTermGenerate("sleeping", "unknown2","qa_status::match-Include=not_found,unknownText::match-Include=null", + "match,return-0", UNKNOWN_TEXT, ""); - configTermText = new ConfigTermText( - " ", "qa_status::match-Include=OK,qa_score::number-Smaller=90,unknownText::match-Include=null", "match,return-0", - UNKNOWN_TEXT, - " ", "" - ); - configTermText.setStatus("sleeping"); - configTermText.setConfigName("unknown3",false); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); + unknownTypeConfigTermGenerate("sleeping", "unknown3","qa_status::match-Include=OK,qa_score::number-Smaller=90,unknownText::match-Include=null", + "match,return-0", UNKNOWN_TEXT, ""); - configTermText = new ConfigTermText( - " ", "qa_status::match-Include=OK,qa_score::number-Smaller=90", "match,return-0", - "{unknownText-2}", " ", "" - ); - configTermText.setStatus("sleeping"); - configTermText.setConfigName("unknown4",false); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); + unknownTypeConfigTermGenerate("sleeping", "unknown4","qa_status::match-Include=OK,qa_score::number-Smaller=90", + "match,return-0", "{unknownText-2}", ""); //由于剧情跳转时地点可能发生变化, qa问答的句子可能因为npc不再同一位置而被过滤掉,所以将common_answer的字符串合并放在postprocessing中 - configTermText = new ConfigTermText( - " ", "qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=90", "match,return-0", - "" ," ", "" - ); - configTermText.setStatus("sleeping"); - configTermText.setConfigName("common_answer",false); - configTermText.setAuxiliaryPriority("0"); - configTermTextList.add(configTermText); + unknownTypeConfigTermGenerate("sleeping", "common_answer","qa_status::match-Include=OK,qa_score::number-BiggerOrEqual=90", + "match,return-0", "", ""); + + // configTermText = new ConfigTermText(" ", " ", "activate,post::gameQA(" + QA_URL + ")", +// "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); +// configTermText.setNextStepStatus("active"); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); + +// configTermText = new ConfigTermText( +// " ", "qa_status::match-Include=not_found", "match,return-0", +// "{unknownText-2}", " ", "" +// ); +// configTermText.setStatus("sleeping"); +// configTermText.setConfigName("unknown1",false); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); + + + + // configTermText = new ConfigTermText( +// " ", "qa_status::match-Include=not_found,unknownText::match-Include=null", "match,return-0", +// UNKNOWN_TEXT, +// " ", "" +// ); +// configTermText.setStatus("sleeping"); +// configTermText.setConfigName("unknown2",false); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); + + + + // configTermText = new ConfigTermText( +// " ", "qa_status::match-Include=OK,qa_score::number-Smaller=90,unknownText::match-Include=null", "match,return-0", +// UNKNOWN_TEXT, +// " ", "" +// ); +// configTermText.setStatus("sleeping"); +// configTermText.setConfigName("unknown3",false); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); + + + + // configTermText = new ConfigTermText( +// " ", "qa_status::match-Include=OK,qa_score::number-Smaller=90", "match,return-0", +// "{unknownText-2}", " ", "" +// ); +// configTermText.setStatus("sleeping"); +// configTermText.setConfigName("unknown4",false); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); + + + + +// configTermText = new ConfigTermText( +// " ", , "match,return-0", +// "" ," ", "" +// ); +// configTermText.setStatus("sleeping"); +// configTermText.setConfigName("common_answer",false); +// configTermText.setAuxiliaryPriority("0"); +// configTermTextList.add(configTermText); //--------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------- @@ -644,6 +696,27 @@ public class PlotConstructor2 extends ElementConstructor { } + public void unknownTypeConfigTermGenerate(String configStatus, String configName, String historyPremise, String feature, String reply, String updateKnowledge){ + + + configTermText = new ConfigTermText( + " ", historyPremise, feature, + reply ," ", UNKNOWN_COUNTER_NAME + ":+1" + ); + configTermText.setStatus(configStatus); + configTermText.setConfigName(configName,false); + configTermText.setAuxiliaryPriority("0"); + + if(!updateKnowledge.equals("")) + configTermText.setUpdateKnowledge(configTermText.getUpdateKnowledge() + "-<-" + updateKnowledge); + + if(configStatus.equals("waiting")){ + configTermText.setNextStep("unknown4,unknown3,unknown2,unknown1,common_answer"); + } + configTermTextList.add(configTermText); + } + + /** * 新建一个剧情结点 * @param node @@ -816,7 +889,6 @@ public class PlotConstructor2 extends ElementConstructor { appendKnowledge(newUK, taskLine, String.format(GAME_STEP_FORMAT, botAccount, plotId)); appendKnowledge(newUK, plotId, "1"); - } } @@ -860,6 +932,8 @@ public class PlotConstructor2 extends ElementConstructor { hisPremiseList.add(new Premise("isNeighbour:" + GOTO_CONDITION, "match", "Include", "1+3+4")); + updateKnowledge.put(UNKNOWN_COUNTER_NAME, "0"); + JSONObject listeningConfig = new JSONObject(); listeningConfig.put("curPremise", curPremiseList); @@ -880,6 +954,17 @@ public class PlotConstructor2 extends ElementConstructor { return nextAutoJump && (location.equals(nextLocation) || moveWithPlot); } +// public void premiseTextFilt(JSONArray premiseList){ +// int size = premiseList.size(); +// JSONObject premise = null; +// +// for(int i = 0;i < size;i++){ +// premise = premiseList.getJSONObject(i); +// +// premise.put("keyword", textReplace(premise.getString("keyword"), replaceMap)); +// } +// } + diff --git a/src/main/java/com/qiwu/chatbotbackend/processing/ActionMatcher.java b/src/main/java/com/qiwu/chatbotbackend/processing/ActionMatcher.java index 17339d5..33d7b50 100644 --- a/src/main/java/com/qiwu/chatbotbackend/processing/ActionMatcher.java +++ b/src/main/java/com/qiwu/chatbotbackend/processing/ActionMatcher.java @@ -19,10 +19,6 @@ public class ActionMatcher { Map activatedMap = new HashMap(); - static String POST_DATA_ERROR = "post数据有误"; - static String POST_ERROR = "数据post时出错了"; - static String API_ERROR = "api处理过程中出错了"; - public LogWriter logWriter = null; public UserInfo userinfo = null; diff --git a/src/main/java/com/qiwu/chatbotbackend/processing/ChatCacheController.java b/src/main/java/com/qiwu/chatbotbackend/processing/ChatCacheController.java index 7d84210..c109b35 100644 --- a/src/main/java/com/qiwu/chatbotbackend/processing/ChatCacheController.java +++ b/src/main/java/com/qiwu/chatbotbackend/processing/ChatCacheController.java @@ -17,9 +17,10 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import static com.qiwu.chatbotbackend.Config.Config.CHATCACHE_TIME_OUT; + public class ChatCacheController { - public static long TIME_OUT = 300000; public static String CHAT_CACHE_DIR = "ChatCache/"; @@ -198,7 +199,7 @@ public class ChatCacheController { history = chatCacheMap.get(sessionKey).getInfoPoint(); lastChatTime = Long.valueOf(history.get("lastUpdateTime")); now = System.currentTimeMillis(); - if (now - lastChatTime > ChatCacheController.TIME_OUT) { + if (now - lastChatTime > CHATCACHE_TIME_OUT) { chatCache = chatCacheMap.get(sessionKey); if(chatCache != null && !chatCache.getRandKey().equals(chatCache.getUserKey()) && chatCache.isGameStart()) { diff --git a/src/main/java/com/qiwu/chatbotbackend/processing/FormsPoster.java b/src/main/java/com/qiwu/chatbotbackend/processing/FormsPoster.java index 21b52be..cd8ab68 100644 --- a/src/main/java/com/qiwu/chatbotbackend/processing/FormsPoster.java +++ b/src/main/java/com/qiwu/chatbotbackend/processing/FormsPoster.java @@ -16,6 +16,8 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.qiwu.chatbotbackend.Config.Config.QA_FETCH_ERROR; + public class FormsPoster { @@ -63,7 +65,6 @@ public class FormsPoster { while (k_iter.hasNext()) { key = k_iter.next(); if (curInfoPoint.get(key) != null && !curInfoPoint.get(key).equals("")) - //infoMap.put(key + "_cur", curInfoPoint.get(key)[0]); pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); } @@ -217,29 +218,34 @@ public class FormsPoster { String text,score, site = historyInfoPoint.get("site"), npc; System.out.println(jobj.toJSONString()); if((Integer)jobj.get("post_status") == 1){ - if(jobj.getJSONArray("qa_candidates") != null && jobj.get("qa_status").equals("OK")){ + if(jobj.getJSONArray("qa_candidates") != null && jobj.get("qa_status").equals("OK")) { List candidates = JSON.toJavaObject(jobj.getJSONArray("qa_candidates"), List.class); - for(JSONArray pair:candidates){ - List textscore = JSON.toJavaObject(pair, List.class); + try { + for (JSONArray pair : candidates) { + List textscore = JSON.toJavaObject(pair, List.class); - Pattern findTalker = Pattern.compile(TALKER); + Pattern findTalker = Pattern.compile(TALKER); - if((Integer)textscore.get(1) > 90) { - Matcher m = findTalker.matcher((String)textscore.get(0)); - if (m.find()) { - npc = m.group(1); + if ((Integer) textscore.get(1) > 90) { + Matcher m = findTalker.matcher((String) textscore.get(0)); + if (m.find()) { + npc = m.group(1); - if ((GameBotUtil.sameLocation((String)textscore.get(0), curInfoPoint, historyInfoPoint, gameEnv, historyInfoPoint.get("site"), logWriter) == 1)) { - historyInfoPoint.put("common_answer", (String)textscore.get(0)); - historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1))); - break; + if ((GameBotUtil.sameLocation((String) textscore.get(0), curInfoPoint, historyInfoPoint, gameEnv, historyInfoPoint.get("site"), logWriter) == 1)) { + historyInfoPoint.put("common_answer", (String) textscore.get(0)); + historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1))); + break; + } } } } + }catch(Exception e){ + historyInfoPoint.put("common_answer", QA_FETCH_ERROR); + historyInfoPoint.put("qa_score", "99"); } } }else { diff --git a/src/main/java/com/qiwu/chatbotbackend/servlet/FindCacheServlet.java b/src/main/java/com/qiwu/chatbotbackend/servlet/FindCacheServlet.java index e261b5a..611df9b 100644 --- a/src/main/java/com/qiwu/chatbotbackend/servlet/FindCacheServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/servlet/FindCacheServlet.java @@ -28,6 +28,7 @@ public class FindCacheServlet extends HttpServlet { exist = ChatCacheController.findChatCache(userKey, context); } catch (Exception e) { e.printStackTrace(); + exist = false; } JSONObject responseJSONObject = new JSONObject(); diff --git a/src/main/java/com/qiwu/chatbotbackend/servlet/GameDesignServlet.java b/src/main/java/com/qiwu/chatbotbackend/servlet/GameDesignServlet.java index 2b0e3c2..9862183 100644 --- a/src/main/java/com/qiwu/chatbotbackend/servlet/GameDesignServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/servlet/GameDesignServlet.java @@ -27,13 +27,12 @@ import java.util.*; import static com.qiwu.chatbotbackend.Config.Config.GAME_CONDITION_CATEGORY; import static com.qiwu.chatbotbackend.Config.Config.GAME_WELCOME_TEXT; +import static com.qiwu.chatbotbackend.Config.Config.KEYWORD_DIR; @WebServlet(name = "GameDesignServlet", urlPatterns = {"/gameDesign"}) public class GameDesignServlet extends HttpServlet { - String POST_URL = "http://localhost:1111/conditionProcess"; - String KEYWORD_DIR = "keywords.txt"; //分组及其相应的id,id初始化为0, 新建分组成功后id会更新。 HashMap categoryMap = new HashMap(){ { @@ -89,7 +88,7 @@ public class GameDesignServlet extends HttpServlet { JSONObject receiveParaneters = JSONObject.parseObject(jsonStr); dataId = (Integer) receiveParaneters.get("id"); - JSONObject gameElements = helper.queryGameElementsByBotId(dataId); + JSONObject gameElements = helper.queryGameElementsByProjectId(dataId); gameElements.put("auth", request.getHeader("authorization")); //System.out.println(gameElements.toJSONString()); @@ -172,6 +171,8 @@ public class GameDesignServlet extends HttpServlet { } + + helper.batchInsertConfigByBotId(botId, jsonList, idList, categoryMap.get(moduleName2)); constructor.postProcessing(idList, categoryMap.get(moduleName2)); constructor.generateConfigText(idList); @@ -214,10 +215,6 @@ public class GameDesignServlet extends HttpServlet { } } - helper.destroy(); - - - }else { returnStatus = 0; @@ -225,6 +222,8 @@ public class GameDesignServlet extends HttpServlet { } } catch (SQLException e) { e.printStackTrace(); + } finally{ + helper.destroy(); } @@ -261,8 +260,10 @@ public class GameDesignServlet extends HttpServlet { public boolean botInit(int botId, String botAccount, UserInfo userInfo, SqlHelper helper) throws SQLException, IOException { boolean deleteConfigFlag = helper.deleteConfigByBotId(botId); boolean deleteVariableFlag = helper.deleteVariableByBotId(botId); + boolean deleteCategoryFlag = helper.deleteCategoryByBotId(botId); - boolean batchInsertCategoryFlag = helper.batchInsertCategoryByBotId(botId, categoryMap); + boolean insertCategoryFlag = helper.batchInsertCategoryByBotId(botId, categoryMap); + boolean deteteConditionFlag = helper.deleteConditionByBotId(botId); boolean deleteArchiveFlag = ChatCacheController.deleteChatCache(helper, botAccount); @@ -295,8 +296,8 @@ public class GameDesignServlet extends HttpServlet { actionPostData.put("relationKeywords", additionalKeywords); actionPostData.put("botId", gameElements.getInteger("botId")); - if(gameElements.getJSONArray("conditionCategoryIdList") != null){ - actionPostData.put("conditionCategories", gameElements.getJSONArray("conditionCategoryIdList")); + if(gameElements.getJSONArray("conditionCategories") != null){ + actionPostData.put("conditionCategories", gameElements.getJSONArray("conditionCategories")); }else{ actionPostData.put("conditionCategories", new JSONArray(){ { diff --git a/src/main/java/com/qiwu/chatbotbackend/servlet/GetAnswerServlet.java b/src/main/java/com/qiwu/chatbotbackend/servlet/GetAnswerServlet.java index 58d9609..b2fa601 100644 --- a/src/main/java/com/qiwu/chatbotbackend/servlet/GetAnswerServlet.java +++ b/src/main/java/com/qiwu/chatbotbackend/servlet/GetAnswerServlet.java @@ -154,8 +154,6 @@ public class GetAnswerServlet extends HttpServlet { matcher.appendDebugInfo(bestMatch, context); } - - //if(userinfo.varInitialMap.get("infoTransferTime") != null && userinfo.varInitialMap.get("infoTransferTime").equals("after")) matcher.infoTransfer(bestMatch, context, debugFlag); @@ -163,7 +161,7 @@ public class GetAnswerServlet extends HttpServlet { //清理超时的用户数据 if (context.getAttribute("cacheUpdateTime") == null) context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); - if (System.currentTimeMillis() - (long) context.getAttribute("cacheUpdateTime") > ChatCacheController.TIME_OUT) { + if (System.currentTimeMillis() - (long) context.getAttribute("cacheUpdateTime") > CHATCACHE_TIME_OUT) { ChatCacheController.updateChatCache4Delete(chatKey, context, userinfo); context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); } diff --git a/src/main/java/com/qiwu/chatbotbackend/task/utils/GameBotUtil.java b/src/main/java/com/qiwu/chatbotbackend/task/utils/GameBotUtil.java index 81ed988..706cf4b 100644 --- a/src/main/java/com/qiwu/chatbotbackend/task/utils/GameBotUtil.java +++ b/src/main/java/com/qiwu/chatbotbackend/task/utils/GameBotUtil.java @@ -156,9 +156,10 @@ public class GameBotUtil extends BasicBotUtil{ if(nameSeries.length == 4){ keyword = chatCache.getGameEnv().queryNpcAttrByNpcName(nameSeries[2], nameSeries[3]); }else if (nameSeries.length == 3){ - if(nameSeries[1].equals("玩家") && nameSeries[2].equals("物品栏")) { + if(nameSeries[2].equals("物品栏")) { + //如果是物品栏就调用专门的函数查询物品栏的所有数据 StringBuffer sb = new StringBuffer(); - List goods = chatCache.getGameEnv().queryGoodsByNpcName("玩家"); + List goods = chatCache.getGameEnv().queryGoodsByNpcName(nameSeries[1]); for (String good : goods) { sb.append("+").append(good); } @@ -415,6 +416,7 @@ public class GameBotUtil extends BasicBotUtil{ public static Matcher findTalker(String reply){ + System.out.println(reply); Pattern findTalker = Pattern.compile(TALKER); Matcher m = findTalker.matcher(reply); @@ -542,6 +544,7 @@ public class GameBotUtil extends BasicBotUtil{ case "less_talker": return appendTalker(findRelateTalkers(false).get(0), reply, chatCache.getInfoPoint(), chatCache.getGameEnv()); case "to_unknown": + returnText = NO_ONE_CAN_REPLY_UNKNOWN; Set candidates = new HashSet(); Map> npcTextMap = null; String unknownList = "", foundNPC; diff --git a/src/main/resources/pro/c3p0-config.xml b/src/main/resources/pro/c3p0-config.xml index f6916a5..233771a 100644 --- a/src/main/resources/pro/c3p0-config.xml +++ b/src/main/resources/pro/c3p0-config.xml @@ -50,8 +50,8 @@ 3g9^pWQs#ft7 3 30 - 10 - 3 + 15 + 5 200