Commit 21a106ae by hxw

上传完整文件夹

parent dff6f518
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
<facet type="web" name="Web">
<configuration>
<webroots />
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
<root url="file://$MODULE_DIR$/src/main/resources" />
</sourceRoots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.11.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.11.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.23" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.7" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.7" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.7" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.7" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.7" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.12" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.12" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.12" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.13.Final" level="project" />
<orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.4.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.1.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.1.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.2.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.1.0.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.1.0.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.1.0.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.4.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:5.0.4" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.11.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.23.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.9.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.9.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.2.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.1.2.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.6.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.51" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.10" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-dbcp:9.0.12" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-juli:9.0.12" level="project" />
<orderEntry type="library" name="Maven: c3p0:c3p0:0.9.1.2" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.0.7" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-thymeleaf:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf-spring5:3.0.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf:3.0.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.attoparser:attoparser:2.0.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.unbescape:unbescape:1.1.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.1.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-actuator:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator-autoconfigure:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator:2.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: io.micrometer:micrometer-core:1.1.0" level="project" />
<orderEntry type="library" name="Maven: org.hdrhistogram:HdrHistogram:2.1.9" level="project" />
<orderEntry type="library" name="Maven: org.latencyutils:LatencyUtils:2.0.3" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
<orderEntry type="library" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" />
<orderEntry type="library" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
</component>
</module>
\ No newline at end of file
test_var=1111
# qa问答地址
qa_url=http://192.168.1.78:59000/game qa_url=http://192.168.1.78:59000/game
# 中控url
cc_url=http://localhost:8070/api/update/data cc_url=http://localhost:8070/api/update/data
//condition_backend=http://192.168.1.82 # 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
bot_backup_dir=tmp/
config_dir=config/
unknown_text=不好意思,我没听懂你刚才说的话,请换个别的问题试试吧~哎呀,刚才开了小差,没理解你的意思,请换个问题吧~请根据上文信息,认真回答吧,谢谢~我们好像不在一个频道上,换个问题试试,希望我们能够接轨上吧 unknown_text=不好意思,我没听懂你刚才说的话,请换个别的问题试试吧~哎呀,刚才开了小差,没理解你的意思,请换个问题吧~请根据上文信息,认真回答吧,谢谢~我们好像不在一个频道上,换个问题试试,希望我们能够接轨上吧
location_hint=请到%s location_hint=请到%s
game_start_hint=请说开始剧情或者继续剧情 game_start_hint=请说开始剧情或者继续剧情
game_welcome_text=欢迎来到%s,请说继续剧情或者重新开始
game_module_error=游戏模块出错 game_module_error=游戏模块出错
program_error=程序出现异常
intent_not_understand=我不理解
# -------------------------------游戏生成--------------------------- # -------------------------------游戏生成---------------------------
token_time_out=token超时了
game_bot_category=游戏
delete_old_config_term_error=删除旧数据config失败 delete_old_config_term_error=删除旧数据config失败
delete_old_variable_error=删除旧变量失败 delete_old_variable_error=删除旧变量失败
delete_old_category_error=删除旧类别失败 delete_old_category_error=删除旧类别失败
# ----------------------------------------------------------------
name_mission_error=没找到bot名?
log_path=/var/www/html/logs/
# ----------------------------------------------------------------
unknown_text_description=对于无法识别的问题做出的回答 unknown_text_description=对于无法识别的问题做出的回答
game_step_description=QA问答游戏进度 game_step_description=QA问答游戏进度
...@@ -41,6 +70,7 @@ plot_status=剧情%s状态 ...@@ -41,6 +70,7 @@ plot_status=剧情%s状态
# --------------------------------------------------- # ---------------------------------------------------
plot_generation_error=剧情接口处理出现异常 plot_generation_error=剧情接口处理出现异常
action_text_generate_error=action生成失败
默认condition 默认condition
default_condition=yaobuyao default_condition=yaobuyao
...@@ -74,26 +104,64 @@ task_description_slot=[任务描述]" ...@@ -74,26 +104,64 @@ task_description_slot=[任务描述]"
find_item_owner=[物品名]在[人名]身上 find_item_owner=[物品名]在[人名]身上
#---------------------------------------------- #----------------------------------------------
# ---------------------文本解析--------------------- #--------------------condition文本默认配置--------------------------
text_parse_error=文本解析出错
automatch_threshold=0.5
game_condition_category=97
service_url=http://192.168.1.178:8081/bot/dialog
options=disable_knowledge_qa,fast_understanding,pattern_cover,no_repeat options=disable_knowledge_qa,fast_understanding,pattern_cover,no_repeat
automatch_url=http://dev01.centaurstech.com:5700/mermaid/?model=auto-train
idlelimit=180000 idle_limit=180000
condition_generate_url=http://192.168.1.178:1111/conditionProcess condition_fellow=pivot_httppost
condition_backend_url=http://192.168.1.82:6636/api automatch_threshold=0.5
style=interrupt,multimatchvalues,bothvalue default_style=style=interrupt,bothvalue,multimatchvalues
fellow=pivot_httppost
post_style1=style=httppost,bothvalue,multimatchvalues post_style1=style=httppost,bothvalue,multimatchvalues
post_style2=style=httppost,multimatchvalues post_style2=style=httppost,multimatchvalues
post_action_head=#actions\r\nname=pivot_httppost\r\nstatus=waiting\r\n%s\r\nserviceURL=%s # ---------------------condition解析生成---------------------
bot_info_not_exist=bot信息不存在
conditon_backend_error=condition后台报错
text_parse_error=文本解析出错
game_condition_category=97
# ----------------------condition增删改查异常---------------------------- post_action_head=#actions\r\nname=pivot_httppost\r\nstatus=waiting\r\n%s\r\nserviceURL=%s\r\n
update_keyword_error=更新关键词单元失败 update_keyword_error=更新关键词单元失败
delete_user_data_error=删除用户数据失败 delete_user_data_error=删除用户数据失败
game_condition_category_id=123 platform_sql_init_error=新平台获取sql连接失败
platform_sql_init_error=新平台获取sql连接失败
\ No newline at end of file json_format_error=json格式有误
condition_insert_error=condition插入失败
condition_update_error=condition更新失败
condition_name_dumplicate=condition名字重复
update_error=更新失败
# --------------------------配置文件增删改查-----------------------------------
config_pattern=%s|%s|%s|=>|%s|nextStep=%s|status=%s|configId=%s
config_delete_error=删除配置文件失败
condition_name_update_error=更新语义关系名字失败
config_insert_error=插入配置文件失败
config_file_not_found=没有找到配置文件
# -------------------------配置文件类别操作-------------------------------------
category_update_conflict="不可将父分组设为了当前分组的子分组"
category_update_error="类别更新失败"
category_insert_error="新建类别失败"
category_delete_error="类别删除失败"
category_query_error="类别查询失败"
# -------------------------变量操作------------------------------------------
variable_name_dumplicate=变量名重复
varibale_insert_error=变量插入失败
variable_delete_error=变量删除失败
variable_update_error=变量更新失败
variable_sql_delete_error=从数据库删除变量失败
variable_save_format=-varInitial-|%s|%s\n
extra_info_format=-extraInfo-|%s|%s\n
variable_update_format=%s---%s
# ---------------------------数据库连接获取失败--------------------------------
sql_connection_error=数据库连接获取失败
# ------------------------------------------------------------------------------
# 第一块,意图|相关的语义关系名
意图语义关系名
# 第二块, 意图|语义关系名|关键词
# ------------------------------------------------------------------------------
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表示可以替换的名字,如物品名、角色名
# attrName是属性名
# qiwu就是玩家“我”
# ------------------------------------------------------------------------------
# 我在哪里
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
# 周围有什么人
AROUND_NPC|know_exist_what|+周围:人+附近:人+周围:谁+这里:谁+这里:人+有什么:人+里面:人+里面:谁+哪些:人+qiwu:人+qiwu:谁+有:谁+有:人
# 周围有什么npc类别
AROUND_NPC_CLASS|know_exist_what|+周围:name+附近:name
# 周围有什么
AROUND_THINGS|know_exist_what_mohu|+有什么:周围+有什么:附近+有什么:这里+有:哪些:这里+有谁:周围+有什么:里面
# 周围有什么物品
AROUND_ITEM|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:地方
# 里面有谁
WHO_IN_THERE|shishui|+谁:里面+里面:人
# 去xx
GO_TO|yaobuyao|+去:name+到:name
# 怎么找到NPC
HOW_TO_FIND_NPC|xxx|+找到:name
# 你是谁
WHO_YOU_ARE|zhiwen|+botname:谁+botname:干嘛+那个人:谁+人:谁+botname:是+人:是
# 任务是什么
TASK_IS_WHAT|shishenme|+是什么:任务+qiwu:任务
# npc在哪里
NPC_LOCATION|wenzainali|+哪里:name+哪:name+地方:name+地点:name
# 物品在哪里
ITEM_LOCATION|wenzainali|+哪里:name+哪:name+地方:name+地点:name+位置:name+哪儿:name
# 怎么找到npc
HOW_FIND_NPC|want_know_zenmezuo|+找到:name
#怎么找到物品
HOW_FIND_ITEM|want_know_zenmezuo|+找到:name
# 沙滩上有什么人
WHAT_NPC_IN_LOCATION|xxx|地点
# xx上有什么东西
WAHT_ITEM_IN_LOCATION|xxx|地点
# 地点上有什么
WHAT_THINGS_IN_LOCATION|xxx|地点
# npc的属性是多少
NPC_ATTR|nums|+name:attrName
NPC_ATTR|shishenme|+name:attrName
# 物品的属性是多少
ITEM_ATTR|nums|+name:attrName
ITEM_ATTR|shishenme|+name:attrName
# 周围有什么物品类别
AOURND_NPC_CLASS|know_exist_what|+周围:name+附近:name
# 怎么去XXX
HOW_TO_THERE|want_know_zenmezuo|默认
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
wget "$jarUrl" -O "$wrapperJarPath"
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
curl -o "$wrapperJarPath" "$jarUrl"
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
echo Found %WRAPPER_JAR%
) else (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
echo Finished downloading %WRAPPER_JAR%
)
@REM End of extension
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
...@@ -98,6 +98,12 @@ ...@@ -98,6 +98,12 @@
<version>1.5.0</version> <version>1.5.0</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies> </dependencies>
......
package com.qiwu.chatbotbackend.db;
import org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory;
import javax.sql.DataSource;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class DBCPUtils {
private static DataSource ds;//定义一个连接池对象
static {
try {
Properties pro = new Properties();
File file = new File("dbcpconfig.properties");
pro.load(DBCPUtils.class.getClassLoader().getResourceAsStream("dbcpconfig.properties"));
ds = BasicDataSourceFactory.createDataSource(pro);//得到一个连接池对象
} catch (Exception e) {
e.printStackTrace();
//throw new ExceptionInInitializerError("初始化连接错误,请检查配置文件!");
}
}
//从池中获取一个连接
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
public static void closeAll(ResultSet rs, Statement stmt, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();//关闭
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
\ No newline at end of file
package com.qiwu.chatbotbackend.db;
public class DBUtils {
}
package entity;
/**
* 包含后台返回数据的实体类。
*/
public class AnswerNextStep {
int status = 0;
String answer;
String next;
public String getAnswer() {
return answer;
}
public int getStatus() {
return status;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public void setStatus(int status) {
this.status = status;
}
public String getNext() {
return next;
}
public void setNext(String next) {
this.next = next;
}
public AnswerNextStep(int status, String answers, String next){
this.answer = answers;
this.next = next;
this.status = status;
}
public AnswerNextStep(){}
}
package com.qiwu.chatbotbackend.entity;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.processing.ChatCacheController;
import org.springframework.beans.factory.DisposableBean;
import javax.annotation.PreDestroy;
public class ChatCache3 implements DisposableBean {
// private String chatKey = "不知道";
private String chatKey = "";
private String botAccount = "";
private Map<String, String> infoPoint = null;
private GameEnv gameEnv = null;
private boolean reloading = false;
public String getBotAccount() {
return botAccount;
}
public void setBotAccount(String botAccount) {
this.botAccount = botAccount;
}
public boolean isReloading() {
return reloading;
}
public void setReloading(boolean reloading) {
this.reloading = reloading;
}
public Map<String, String> getInfoPoint() {
return infoPoint;
}
public void setInfoPoint(Map<String, String> infoPoint) {
this.infoPoint = infoPoint;
}
public GameEnv getGameEnv() {
return gameEnv;
}
public void setGameEnv(GameEnv gameEnv) {
this.gameEnv = gameEnv;
}
public ChatCache3(String chatKey, GameEnv gameEnv, Map<String, String> infoPoint) {
this.chatKey = chatKey;
this.gameEnv = gameEnv;
this.infoPoint = infoPoint;
}
@Override
public void destroy() throws IOException {
}
public ChatCache3(UserInfo userInfo) throws Exception {
try {
gameEnv = new GameEnv(userInfo.botAccount);
} catch (Exception e) {
System.out.println("游戏平台初始化失败");
e.printStackTrace();
}
String k;
this.botAccount = userInfo.botAccount;
infoPoint = new HashMap<String, String>();
Iterator<String> iit = userInfo.varInitialMap.keySet().iterator();
while (iit.hasNext()) {
k = iit.next();
infoPoint.put(k, userInfo.varInitialMap.get(k));
}
infoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis()));
}
}
package com.qiwu.chatbotbackend.entity;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
/**
* 保存配置文件每一行(单行)解析后的信息的实体类。
* 独立于引擎的另一种condition
*/
public class Condition {
public int priority = -1;
public int activePriority = 0; //如果本condition被其他condition激活
public int auxiliaryPriority = 0; //用于priority一样时人为设置的辅助优先级
public HashSet<String> keywordSet = new HashSet<String>();
public HashMap<String, HashSet<String>> historyPremise = new HashMap<String, HashSet<String>>();
public HashMap<String, HashSet<String>> currentPremise = new HashMap<String, HashSet<String>>();
public HashMap<String, String> updateKnowledge = new LinkedHashMap<String, String>();
public String[] answer = {"",};
public String nextStep = "";
public HashMap<String, String> featureMap = new HashMap<String, String>();
public String indexName = "";
public int id = 0;
public String configName = "";
public String status = "waiting";
//public ArrayList<String> indexName = new ArrayList<String>();
public Condition(int priority) {
this.priority = priority;
this.activePriority = priority;
}
public Condition(Condition originCondition, int basePriority, int baseAuxiliaryPriority) {
this.priority = originCondition.priority;
this.keywordSet = originCondition.keywordSet;
this.historyPremise = originCondition.historyPremise;
this.currentPremise = originCondition.currentPremise;
this.answer = originCondition.answer;
this.nextStep = originCondition.nextStep;
this.featureMap = originCondition.featureMap;
this.updateKnowledge = originCondition.updateKnowledge;
this.indexName = originCondition.indexName;
this.id = originCondition.id;
this.configName = originCondition.configName;
this.status = originCondition.status;
this.activePriority = originCondition.activePriority + basePriority;
this.auxiliaryPriority = originCondition.auxiliaryPriority + baseAuxiliaryPriority;
}
public Condition() {
}
}
package entity;
public class ConfigurationItem {
}
package entity;
public class Goods {
}
package entity;
public class Npc {
}
package com.qiwu.chatbotbackend.entity;
/**
* 暂时没用
*/
public class QuestionKeyWord {
private String actionName;
private String chatKey;
private String keyWord;
public String getActionName() {
return actionName;
}
public String getChatKey() {
return chatKey;
}
public String getKeyWord() {
return keyWord;
}
public void setActionName(String actionName) {
this.actionName = actionName;
}
public void setChatKey(String chatKey) {
this.chatKey = chatKey;
}
public void setKeyWord(String keyWord) {
this.keyWord = keyWord;
}
}
package entity;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class World {
public List<String> queryAroundAllBySite(String site){ return new ArrayList<>();}; // 返回所有模块下的实例名称列表
public List<String> queryAroundNpcBySite(String site){ return new ArrayList<>();}; // 返回npcname 字符串列表
public List<String> queryAroundGoodsBySite(String site){ return new ArrayList<>();}; // 返回goodsname 字符串列表
public List<String> queryCanGoBySite(String site){ return new ArrayList<>();}; //地点名称的列表
public List<String> queryPathBySite(String start, String destination){ return new ArrayList<>();}; // 返回一条,地点名称的列表
public boolean addGoodsBase(String categoryName, String instanceName, String goodsIntro){ return true;};; // 添加成功为 true,否则false
public boolean deleteGoods(String categoryName, String instanceName){ return true;};; // 删除成功为 true,否则false
public boolean updateGoodsBase(String categoryName, String instanceName, String goodsIntro){ return true;};; // 更新成功为 true,否则false
public String queryGoodsIntro(String name, String site){ return "";};; // 返回一个物品简介
public String queryAttrByGoodsName(String name, String attrName, String site){ return "";}; //
public List<String> queryAllAttrByGoodsName(String name, String site){ return new ArrayList<>();}; // 获得所有属性名称列表
public boolean updateAttrByGoodsName(String categoryName, String instanceName, String attrName, String value){ return true;}; // 更新成功为 true,否则false
public boolean addAttrByGoodsName(String categoryName, String instanceName, String attrName, String value){ return true;}; // 添加成功为 true,否则false
public boolean deleteAttrByGoodsName(String categoryName, String instanceName, String attrName){ return true;}; // 删除成功为 true,否则false
public boolean addNpc(String categoryName, String instanceName, String npcIntro){ return true;}; // 添加成功为 true,否则false
public boolean deleteNpc(String categoryName, String instanceName){ return true;}; // 删除成功为 true,否则false
public boolean updateNpc(String categoryName, String instanceName, String npcIntro){ return true;}; // 更新成功为 true,否则false
public String queryNpcIntro(String categoryName, String instanceName){ return "";}; // 返回一个npc简介
public String queryAttrByNPCName(String categoryName, String instanceName, String attrName){ return "沙滩";}; // 返回npc属性值
public boolean updateLocationByNPCName(String categoryName, String instanceName, String attrName, String value){ return true;}; // 更新成功为 true,否则false
public boolean addAttrByNPCName(String categoryName, String instanceName, String attrName,String value){ return true;}; // 添加成功为 true,否则false
public boolean deleteAttrByNPCName(String categoryName, String instanceName, String attrName){ return true;}; // 删除成功为 true,否则false
}
package com.qiwu.chatbotbackend.gameDesign;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.processing.LogWriter;
import com.qiwu.chatbotbackend.processing.WorldController;
import java.util.Map;
public class GameUtil {
public GameEnv gameEnv = null;
public Map<String ,String> curInfoPoint = null;
public Map<String ,String> historyInfoPoint = null;
public WorldController worldController = null;
public GameUtil(GameEnv gameEnv, WorldController worldController, Map<String, String> curInfoPoint, Map<String, String> historyInfoPoint) {
this.gameEnv = gameEnv;
this.curInfoPoint = curInfoPoint;
this.historyInfoPoint = historyInfoPoint;
this.worldController = worldController;
}
public void gamePreprocessing(LogWriter logWriter){
}
public void gamePostprocessing(LogWriter logWriter){
}
}
package gameDesign;
public class Scene {
}
package gameDesign;
public class SceneConstructor {
}
Manifest-Version: 1.0
Main-Class: com.qiwu.chatbotbackend.ChatbotBackendApplication
...@@ -3,9 +3,11 @@ package com.qiwu.chatbotbackend; ...@@ -3,9 +3,11 @@ package com.qiwu.chatbotbackend;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication @SpringBootApplication
@ServletComponentScan @ServletComponentScan
@ComponentScan
public class ChatbotBackendApplication { public class ChatbotBackendApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -5,19 +5,38 @@ import org.springframework.stereotype.Component; ...@@ -5,19 +5,38 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Config { public class Config {
public static String TEXT_PARSE_ERROR = null; //url
public static String CONDITION_URL = null; public static String CONDITION_URL = null;
public static String TEST_VAR = null;
public static String QA_URL = null; public static String QA_URL = null;
public static String CC_URL = null; public static String CC_URL = null;
public static String UNKNOWN_TEXT = null;
public static String LOCATION_HINT = null; //名字,地址
public static String GAME_START_HINT = null; public static String GAME_BOT_CATEGORY = null;
//错误信息
public static String UPDATE_ERROR = null;
//游戏生成
public static String BOT_INFO_NOT_EXIST = null;
public static String INTENT_NOT_UNDERSTAND = null;
public static String PROGRAM_ERROR = null;
public static String NAME_MISSING_ERROR = null;
public static String LOG_PATH = null;
public static String TEXT_PARSE_ERROR = null;
public static String GAME_MODULE_ERROR = null; public static String GAME_MODULE_ERROR = null;
public static String DELETE_OLD_CONFIG_TERM_ERROR = null; public static String DELETE_OLD_CONFIG_TERM_ERROR = null;
public static String DELETE_OLD_VARIABLE_ERROR = null; public static String DELETE_OLD_VARIABLE_ERROR = null;
public static String DELETE_OLD_CATEGORY_ERROR = null; public static String DELETE_OLD_CATEGORY_ERROR = null;
public static String UNKNOWN_TEXT = null;
public static String LOCATION_HINT = null;
public static String GAME_START_HINT = null;
public static String GAME_WELCOME_TEXT = null;
public static String UNKNOWN_TEXT_DESCRIPTION = null; public static String UNKNOWN_TEXT_DESCRIPTION = null;
public static String GAME_STEP_DESCRIPTION = null; public static String GAME_STEP_DESCRIPTION = null;
public static String START_PLOT_NOT_EXIST = null; public static String START_PLOT_NOT_EXIST = null;
...@@ -50,8 +69,11 @@ public class Config { ...@@ -50,8 +69,11 @@ public class Config {
public static int SIZE = 12; public static int SIZE = 12;
}; };
//condition增删改查
public static String CONDITION_UPDATE_ERROR = null;
public static String CONDITION_INSERT_ERROR = null;
public static String POST_ACTION_ERROR = null; public static String CONDITION_BACKEND_ERROR = null;
public static String TOKEN_TIME_OUT = null; public static String TOKEN_TIME_OUT = null;
public static String ENCODE_ERROR = null; public static String ENCODE_ERROR = null;
...@@ -84,14 +106,15 @@ public class Config { ...@@ -84,14 +106,15 @@ public class Config {
//生成action //生成action
public static String ACTION_TEXT_GENERATE_ERROR = null;
public static String CONDITION_NAME_DUMPLICATE = null;
public static String CONDITION_NAME_UPDATE_ERROR = null;
public static String GAME_CONDITION_CATEGORY = null; public static String GAME_CONDITION_CATEGORY = null;
public static String AUTOMATCH_THRESHOLD = null; public static String AUTOMATCH_THRESHOLD = null;
public static String IDLE_LIMIT = null; public static String IDLE_LIMIT = null;
public static String CONDITION_BACKEND_URL = null; public static String CONDITION_BACKEND_URL = null;
public static String CONDITION_GENERATE_URL= null;
public static String OPTIONS = null; public static String OPTIONS = null;
public static String STYLE = null; public static String DEFAULT_STYLE = null;
public static String AUTOMATCH_URL = null;
public static String SERVICE_URL = null; public static String SERVICE_URL = null;
public static String FELLOW = null; public static String FELLOW = null;
...@@ -108,4 +131,42 @@ public class Config { ...@@ -108,4 +131,42 @@ public class Config {
public static String DELETE_USER_DATA_ERROR = null; public static String DELETE_USER_DATA_ERROR = null;
public static String PLATFORM_SQL_INIT_ERROR = null;
public static String CATEGORY_UPDATE_CONFLICT = null;
public static String CATEGORY_UPDATE_ERROR = null;
public static String CATEGORY_DELETE_ERROR = null;
public static String CATEGORY_INSERT_ERROR = null;
public static String CATEGORY_QUERY_ERROR = null;
public static String JSON_FORMAT_ERROR = null;
//配置文件增删改查异常
public static String CONFIG_FILE_NOT_FOUND = null;
public static String CONFIG_DELETE_ERROR = null;
public static String CONFIG_INSERT_ERROR = null;
//变量
public static String VARIABLE_NAME_DUMPLICATE = null;
public static String VARIABLE_INSERT_ERROR = null;
public static String VARIABLE_SAVE_FORMAT = null;
public static String VARIABLE_UPDATE_FORMAT = null;
public static String EXTRA_INFO_FORMAT = null;
public static String VARIABLE_DELETE_ERROR = null;
public static String VARIABLE_SQL_DELETE_ERROR = null;
public static String VARIABLE_UPDATE_ERROR = null;
public static String SQL_CONNECTION_ERROR = null;
public static String BOT_BACKUP_DIR = null;
public static String CONFIG_DIR = null;
public static String BACKUP_PATH = null;
} }
package com.qiwu.chatbotbackend.GameEnvironment.bean;
import java.io.Serializable;
public class Attr implements Serializable{
private static final long serialVersionUID = 1L;
private String name;
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return "Attr [name=" + name + ", value=" + value + "]";
}
}
package com.qiwu.chatbotbackend.GameEnvironment.bean;
import java.io.Serializable;
import java.util.List;
public class SuperClass implements Serializable{
private static final long serialVersionUID = 1L;
private String name;
private String intro;
private List<Attr> attrs;
private List<GoodsInstance> goodsInstances;
private List<NpcInstance> npcInstances;
public List<GoodsInstance> getGoodsInstances() {
return goodsInstances;
}
public void setGoodsInstances(List<GoodsInstance> goodsInstances) {
this.goodsInstances = goodsInstances;
}
public List<NpcInstance> getNpcInstances() {
return npcInstances;
}
public void setNpcInstances(List<NpcInstance> npcInstances) {
this.npcInstances = npcInstances;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIntro() {
return intro;
}
public void setIntro(String intro) {
this.intro = intro;
}
public List<Attr> getAttrs() {
return attrs;
}
public void setAttrs(List<Attr> attrs) {
this.attrs = attrs;
}
@Override
public String toString() {
int goodsInstanceSize = 0;
if(goodsInstances!=null) {
goodsInstanceSize = goodsInstances.size();
}
return "SuperClass [name=" + name + ", intro=" + intro + "goodsInstancesSize="+goodsInstanceSize+", attrs=" + attrs + "]";
}
}
package com.qiwu.chatbotbackend.actiongenerate.DB;
import com.google.common.base.Joiner;
import com.qiwu.chatbotbackend.actiongenerate.entity.EngineUnit;
import com.qiwu.chatbotbackend.db.C3p0Utils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class EngineUtils {
private Connection conn = null;
public EngineUtils() throws SQLException {
conn = C3p0Utils.getEngineConnection();
}
public void destroy() {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public String queryKeywordUnitText(int botId){
String sql = "select text from units where user_id = ? and name = 'keywords'";
String keywordText = "";
try{
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1,botId);
ResultSet rs = ps.executeQuery();
if(rs.next()){
keywordText = (rs.getString("text"));
}
ps.close();
}catch(Exception e){
e.printStackTrace();
}
return keywordText;
}
public Boolean updateKeywordUnitText(int botId, String keywordText){
Boolean b = true;
String sql = "update units set text = ? where user_id = ? and name = 'keywords'";
try{
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, keywordText);
ps.setInt(2,botId);
b = ps.executeUpdate() == 1;
ps.close();
}catch(Exception e){
e.printStackTrace();
}
return b;
}
public Boolean updateWelcomeText(int botId, String welcome){
boolean b;
try {
String sql = "update users set welcome = ? where id=?";
PreparedStatement ps1 = conn.prepareStatement(sql);
ps1.setString(1, welcome + "#welcome");
ps1.setInt(2, botId);
b = ps1.executeUpdate() == 1;
ps1.close();
return b;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
public Map<Integer, String> queryConditionPatternText(int botId, List<String> patternRelationList){
String sql = "select user_id, text from `users` join `units` on users.id = units.user_id where users.username in ('" + Joiner.on("','").join(patternRelationList)+ "') and units.name = 'actions'";
String keywordText = "";
Map<Integer, String> patternTextMap = new HashMap<Integer, String>();
try{
PreparedStatement ps = conn.prepareStatement(sql);
//ps.setString(1, Joiner.on(",").join(patternRelationList));
ResultSet rs = ps.executeQuery();
while(rs.next()){
patternTextMap.put(rs.getInt("user_id"), rs.getString("text"));
}
ps.close();
rs.close();
}catch(Exception e){
e.printStackTrace();
}
return patternTextMap;
}
public Map<Integer, EngineUnit> queryUnitsByIdList(List<Integer> idList){
String sql = "select user_id, name, text from units where user_id in (" + Joiner.on(",").join(idList) + ") and name in ('actions','keywords')";
Integer id;
Map<Integer, EngineUnit> id2unit= new HashMap<Integer, EngineUnit>();
try{
PreparedStatement ps = conn.prepareStatement(sql);
//ps.setArray(1, idList.toArray());
ResultSet rs = ps.executeQuery();
while(rs.next()){
id = rs.getInt("user_id");
if(id2unit.get(id) == null){
id2unit.put(id, new EngineUnit());
}
switch(rs.getString("name")){
case "actions":
id2unit.get(id).setActions(rs.getString("text"));
break;
case "keywords":
id2unit.get(id).setKeywords(rs.getString("text"));
break;
}
}
ps.close();
rs.close();
}catch(Exception e){
e.printStackTrace();
}
return id2unit;
}
public String queryBotAccountByBotId(int botId){
String sql = "select username from users where id= ?";
String botAccount = "";
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, botId);
ResultSet rs = ps.executeQuery();
if (rs.next())
botAccount = rs.getString("username");
ps.close();
rs.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return botAccount;
}
}
package com.qiwu.chatbotbackend.actiongenerate.DB;
import com.google.common.base.Joiner;
import com.qiwu.chatbotbackend.db.C3p0Utils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class PlatformUtils {
private Connection conn = null;
public PlatformUtils() throws SQLException {
conn = C3p0Utils.getPlatformConnection();
}
public void destroy() {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public List<Integer> queryConditionIdByTypetreeId(List typetreeIdList){
String sql = "select conditionId from typetreeNcondition where typetreeId in (?)";
String keywordText = "";
List<Integer> idList = new ArrayList<Integer>();
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"));
}
ps.close();
rs.close();
}catch(Exception e){
e.printStackTrace();
}
return idList;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
import com.alibaba.fastjson.JSONArray;
public class ActionPostElem {
String botName = "";
String actionText = "";
String authorization = "";
Integer botId = 0;
String categoryName = "";
JSONArray conditionIdPair = new JSONArray();
String botType = "";
public ActionPostElem(String actionText, Integer botId, String botName, String categoryName, String authorization) {
this.botId = botId;
this.botName = botName;
this.actionText = actionText;
this.categoryName = categoryName;
this.authorization = authorization;
}
public ActionPostElem(String actionText, Integer botId, String botName, String categoryName, String authorization, String botType) {
this.botId = botId;
this.botName = botName;
this.actionText = actionText;
this.categoryName = categoryName;
this.authorization = authorization;
if(botType != null)
this.botType = botType;
}
public ActionPostElem(Integer botId, String botName, String authorization) {
this.authorization = authorization;
this.botId = botId;
this.botName = botName;
}
public ActionPostElem(Integer botId, String botName, String actionText, String authorization, String categoryName, JSONArray conditionIdPair) {
this.botName = botName;
this.actionText = actionText;
this.authorization = authorization;
this.botId = botId;
this.categoryName = categoryName;
this.conditionIdPair = conditionIdPair;
}
public String getBotName() {
return botName;
}
public void setBotName(String botName) {
this.botName = botName;
}
public String getActionText() {
return actionText;
}
public void setActionText(String actionText) {
this.actionText = actionText;
}
public String getAuthorization() {
return authorization;
}
public void setAuthorization(String authorization) {
this.authorization = authorization;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public Integer getBotId() {
return botId;
}
public void setBotId(Integer botId) {
this.botId = botId;
}
public JSONArray getConditionIdPair() {
return conditionIdPair;
}
public void setConditionIdPair(JSONArray conditionIdPair) {
this.conditionIdPair = conditionIdPair;
}
public String getBotType() {
return botType;
}
public void setBotType(String botType) {
this.botType = botType;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
import java.util.List;
public class Backup {
int botId;
String botName;
String botCategoryName;
List<Condition> conditionList =null;
List<ConfigTerm> configTermList = null;
List<Category> categoryList = null;
List<Variable> variableList = null;
BotInfo botInfo = null;
public Backup(int botId, String botName, String botCategoryName,
List<Condition> conditionList, List<ConfigTerm> configTermList, List<Category> categoryList, List<Variable> variableList, BotInfo botInfo) {
this.botId = botId;
this.botName = botName;
this.botCategoryName = botCategoryName;
this.conditionList = conditionList;
this.configTermList = configTermList;
this.categoryList = categoryList;
this.variableList = variableList;
this.botInfo = botInfo;
}
public int getBotId() {
return botId;
}
public void setBotId(int botId) {
this.botId = botId;
}
public String getBotName() {
return botName;
}
public void setBotName(String botName) {
this.botName = botName;
}
public String getBotCategoryName() {
return botCategoryName;
}
public void setBotCategoryName(String botCategoryName) {
this.botCategoryName = botCategoryName;
}
public List<Condition> getConditionList() {
return conditionList;
}
public void setConditionList(List<Condition> conditionList) {
this.conditionList = conditionList;
}
public List<ConfigTerm> getConfigTermList() {
return configTermList;
}
public void setConfigTermList(List<ConfigTerm> configTermList) {
this.configTermList = configTermList;
}
public List<Category> getCategoryList() {
return categoryList;
}
public void setCategoryList(List<Category> categoryList) {
this.categoryList = categoryList;
}
public List<Variable> getVariablesList() {
return variableList;
}
public void setVariablesList(List<Variable> variableList) {
this.variableList = variableList;
}
public BotInfo getBotInfo() {
return botInfo;
}
public void setBotInfo(BotInfo botInfo) {
this.botInfo = botInfo;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
public class BotInfo {
Integer botId;
String welcomeText;
String goodbyeText;
String postURL;
String defaultConfigCategory;
String bothValue;
String queryTextTransfer;
public BotInfo(Integer botId, String welcomeText, String goodbyeText,
String postURL, String defaultConfigCategory,
String bothValue, String queryTextTransfer) {
this.botId = botId;
this.welcomeText = welcomeText;
this.goodbyeText = goodbyeText;
this.postURL = postURL;
this.defaultConfigCategory = defaultConfigCategory;
this.bothValue = bothValue;
this.queryTextTransfer = queryTextTransfer;
}
public Integer getBotId() {
return botId;
}
public String getWelcomeText() {
return welcomeText;
}
public String getGoodbyeText() {
return goodbyeText;
}
public String getPostURL() {
return postURL;
}
public String getDefaultConfigCategory() {
return defaultConfigCategory;
}
public String getBothValue() {
return bothValue;
}
public String getQueryTextTransfer() {
return queryTextTransfer;
}
public void setBotId(Integer botId) {
this.botId = botId;
}
public void setWelcomeText(String welcomeText) {
this.welcomeText = welcomeText;
}
public void setGoodbyeText(String goodbyeText) {
this.goodbyeText = goodbyeText;
}
public void setPostURL(String postURL) {
this.postURL = postURL;
}
public void setDefaultConfigCategory(String defaultConfigCategory) {
this.defaultConfigCategory = defaultConfigCategory;
}
public void setBothValue(String bothValue) {
this.bothValue = bothValue;
}
public void setQueryTextTransfer(String queryTextTransfer) {
this.queryTextTransfer = queryTextTransfer;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
public class Category {
int botId;
int categoryId;
int parentId;
String name;
String status = "avaliable";
public Category(int botId, int categoryId, int parentId, String name) {
this.botId = botId;
this.categoryId = categoryId;
this.parentId = parentId;
this.name = name;
}
public Category(int botId, int parentId, String name) {
this.botId = botId;
this.parentId = parentId;
this.name = name;
}
public int getBotId() {
return botId;
}
public void setBotId(int botId) {
this.botId = botId;
}
public int getCategoryId() {
return categoryId;
}
public void setCategoryId(int categoryId) {
this.categoryId = categoryId;
}
public int getParentId() {
return parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
public class Condition {
int botId;
int conditionId;
String conditionJsonText;
String actionText;
String category;
String active;
Integer displayOrder = 999;
public Condition(int botId, int conditionId, String conditionJsonText, String actionText, String category, String active, Integer displayOrder) {
this.botId = botId;
this.conditionId = conditionId;
this.conditionJsonText = conditionJsonText;
this.actionText = actionText;
this.category = category;
this.active = active;
this.displayOrder = displayOrder;
}
public Condition(int botId, String conditionJsonText, String actionText, String category, String active) {
this.botId = botId;
this.conditionJsonText = conditionJsonText;
this.actionText = actionText;
this.category = category;
this.active = active;
}
public int getBotId() {
return botId;
}
public void setBotId(int botId) {
this.botId = botId;
}
public int getConditionId() {
return conditionId;
}
public void setConditionId(int conditionId) {
this.conditionId = conditionId;
}
public String getConditionJsonText() {
return conditionJsonText;
}
public void setConditionJsonText(String conditionJsonText) {
this.conditionJsonText = conditionJsonText;
}
public String getActionText() {
return actionText;
}
public void setActionText(String actionText) {
this.actionText = actionText;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getActive() {
return active;
}
public void setActive(String active) {
this.active = active;
}
public Integer getDisplayOrder() {
return displayOrder;
}
public void setDisplayOrder(Integer displayOrder) {
this.displayOrder = displayOrder;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
import com.alibaba.fastjson.JSONObject;
public class ConfigTerm {
int botId;
int configId;
int categoryId;
String configJsonText;
String configName = "";
String configTerm = "waiting";
public ConfigTerm(int botId, int configId,
int categoryId, String configJsonText, String configName) {
this.botId = botId;
this.configId = configId;
this.categoryId = categoryId;
this.configJsonText = configJsonText;
this.configName = configName;
}
public ConfigTerm(int botId, int configId, int categoryId, JSONObject configData) {
this.botId = botId;
this.configId = configId;
this.categoryId = categoryId;
this.configJsonText = configData.toJSONString();
if(configData.containsKey("configName")){
this.configName = configData.getString("configName");
}
}
public int getBotId() {
return botId;
}
public void setBotId(int botId) {
this.botId = botId;
}
public int getConfigId() {
return configId;
}
public void setConfigId(int configId) {
this.configId = configId;
}
public int getCategoryId() {
return categoryId;
}
public void setCategoryId(int categoryId) {
this.categoryId = categoryId;
}
public String getConfigJsonText() {
return configJsonText;
}
public void setConfigJsonText(String configJsonText) {
this.configJsonText = configJsonText;
}
public String getConfigName() {
return configName;
}
public void setConfigName(String configName) {
this.configName = configName;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
public class EngineUnit {
Integer conditionid;
String keywords;
String actions;
public EngineUnit() {
}
public Integer getConditionid() {
return conditionid;
}
public void setConditionid(Integer conditionid) {
this.conditionid = conditionid;
}
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
public String getActions() {
return actions;
}
public void setActions(String actions) {
this.actions = actions;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
public class IntervalStatus {
int status = 1;
String message = "";
Object extraData = null;
public IntervalStatus(int status, String message, Object extraData) {
this.status = status;
this.message = message;
this.extraData = extraData;
}
public IntervalStatus(int status, String message) {
this.status = status;
this.message = message;
}
public int getStatus() {
return status;
}
public String getMessage() {
return message;
}
public Object getExtraData() {
return extraData;
}
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
import com.alibaba.fastjson.JSONObject;
public class Solution {
int status = 0;
JSONObject payload = null;
}
package com.qiwu.chatbotbackend.actiongenerate.entity;
public class Variable {
Integer botId;
Integer variableId;
Integer categoryId = 0;
String description;
String name;
String value;
public Variable(Integer botId, Integer categoryId, String name, String description, String value) {
this.botId = botId;
if(categoryId != null)
this.categoryId = categoryId;
this.description = description;
this.name = name;
this.value = value;
}
public Variable(Integer botId, Integer variableId, Integer categoryId, String name, String description, String value) {
this.botId = botId;
this.variableId = variableId;
if(categoryId != null)
this.categoryId = categoryId;
this.description = description;
this.name = name;
this.value = value;
}
public void setBotId(Integer botId) {
this.botId = botId;
}
public void setVariableId(Integer variableId) {
this.variableId = variableId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
public void setDescription(String description) {
this.description = description;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
public Integer getBotId() {
return botId;
}
public Integer getVariableId() {
return variableId;
}
public Integer getCategoryId() {
return categoryId;
}
public String getDescription() {
return description;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
}
package com.qiwu.chatbotbackend.actiongenerate.servlet;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.DB.EngineUtils;
import com.qiwu.chatbotbackend.actiongenerate.utils.ActionUtils;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.processing.SimpleUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
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;
@WebServlet(name = "ActionServlet", urlPatterns = {"/condition"})
public class ActionServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//读取并解析json数据
String operationType = "", botName = "";
String jsonStr = SimpleUtil.readJSONString(request);
String auth = request.getHeader("authorization");
JSONObject responseJSONObject = new JSONObject();
Boolean flag = true;
Integer botId;
if (jsonStr != null && !jsonStr.equals("")) {
System.out.println(jsonStr);
JSONObject receiveParameters = JSONObject.parseObject(jsonStr);
receiveParameters.put("Authorization", auth);
operationType = receiveParameters.getString("type");
if(receiveParameters.getString("botId").equals("undefined"))
botId = -1;
else
botId = receiveParameters.getInteger("botId");
botName = receiveParameters.getString("botName_yhm");
try {
EngineUtils engine = new EngineUtils();
SqlHelper helper = new SqlHelper();
ActionUtils actionUtils = new ActionUtils(engine, helper);
switch(operationType) {
case "query_bot_info":
actionUtils.queryBotInfo(receiveParameters);
break;
case "bot_init":
actionUtils.createBot(receiveParameters, auth);
break;
case "query_category":
actionUtils.queryCategory(receiveParameters);
break;
case "query_condition":
actionUtils.queryCondition(receiveParameters);
break;
case "update_condition_display_order":
actionUtils.updateConditionDisplayOrder(receiveParameters);
break;
case "update_bot_info":
actionUtils.updateBotInfo(receiveParameters);
break;
case "update_goodbye":
actionUtils.updateGoodbye(receiveParameters);
break;
default:
//condition的增删改都需要先查询condition的信息
actionUtils.getBotConditionInfo(botId, botName, auth);
switch(operationType) {
case "insert_condition":
actionUtils.insertCondition(receiveParameters);
break;
case "delete_condition":
actionUtils.deleteCondition(receiveParameters, auth);
break;
case "update_condition":
actionUtils.updateCondition(receiveParameters);
break;
case "change_active":
actionUtils.changeActive(receiveParameters);
break;
case "detect_template_update":
actionUtils.updateRelation(receiveParameters);
break;
case "update_condition_name":
actionUtils.updateConditionName(receiveParameters);
break;
}
if(actionUtils.intervalStatus.getStatus() == 1)
actionUtils.query4post(receiveParameters);
}
helper.destroy();
engine.destroy();
switch (actionUtils.intervalStatus.getStatus()){
case 1:
responseJSONObject.put("status", 1);
responseJSONObject.put("parameter", actionUtils.intervalStatus.getExtraData());
break;
case 0:
responseJSONObject.put("status", 0);
responseJSONObject.put("parameter", actionUtils.intervalStatus.getMessage());
}
} catch (SQLException e) {
e.printStackTrace();
}
}else{
responseJSONObject.put("status", 0);
responseJSONObject.put("parameter", JSON_FORMAT_ERROR);
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
//System.out.println("xx:" + responseJSONObject.toJSONString());
PrintWriter out = response.getWriter();
out.append(responseJSONObject.toString());
out.flush();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.qiwu.chatbotbackend.actiongenerate.servlet;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.DB.EngineUtils;
import com.qiwu.chatbotbackend.actiongenerate.entity.*;
import com.qiwu.chatbotbackend.actiongenerate.utils.ActionUtils;
import com.qiwu.chatbotbackend.actiongenerate.utils.CategoryUtils;
import com.qiwu.chatbotbackend.actiongenerate.utils.ConfigTermUtils;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.processing.SimpleUtil;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import static com.qiwu.chatbotbackend.Config.Config.BOT_BACKUP_DIR;
import static com.qiwu.chatbotbackend.Config.Config.SQL_CONNECTION_ERROR;
@WebServlet(name = "BackupServlet", urlPatterns = {"/save2file"})
public class BackupServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
IntervalStatus intervalStatus = new IntervalStatus(1, "");
ServletContext context = request.getServletContext();
//读取并解析json数据
String operationType = "", botName = "", botCategoryName;
String jsonStr = SimpleUtil.readJSONString(request), fileData;
String auth = request.getHeader("authorization");
JSONObject responseJSONObject = new JSONObject();
Boolean flag = true;
Integer botId = 0, categoryIndex;
if (jsonStr != null && !jsonStr.equals("")) {
System.out.println(jsonStr);
try {
JSONObject receiveParameters = JSONObject.parseObject(jsonStr);
JSONObject backupFile = new JSONObject();
receiveParameters.put("Authorization", auth);
operationType = receiveParameters.getString("type");
botId = receiveParameters.getInteger("botId");
botName = receiveParameters.getString("botName_yhm");
botCategoryName = receiveParameters.getString("catName");
EngineUtils engine = new EngineUtils();
SqlHelper helper = new SqlHelper();
BotInfo botInfo = null;
List<Condition> conditionList = new ArrayList<Condition>();
List<ConfigTerm> configTermList = new ArrayList<ConfigTerm>();
List<Integer> childCategoryIds = new ArrayList<Integer>();
List<Category> childCategories = new ArrayList<Category>();
List<Variable> variablesList = new ArrayList<Variable>();
ActionUtils actionUtils = new ActionUtils(engine, helper);
CategoryUtils categoryUtils = new CategoryUtils(helper);
ConfigTermUtils configUtils = new ConfigTermUtils(botName, helper, context);
//actionUtils.
//如果需要保存condition,查询所有condition
if (receiveParameters.containsKey("saveCondition") && receiveParameters.getBoolean("saveCondition")){
conditionList = helper.queryConditionAll(botId);
}
//如果需要保存配置文件,则从根目录开始保存配置文件
if(receiveParameters.containsKey("saveConfig") && receiveParameters.getBoolean("saveConfig")){
categoryIndex = receiveParameters.getInteger("indexCategory");
//查询某个类别下的所有类别
childCategoryIds = categoryUtils.findChildCategoryIds(botId, categoryIndex, childCategories);
//查询属于以上类别列表的所有配置条目
configTermList = helper.queryConfigByCategoryIdList(botId, childCategoryIds);
}
if(!receiveParameters.containsKey("saveVariable") || receiveParameters.getBoolean("saveVariable")){
variablesList = helper.queryVariableAll(botId);
}
botInfo = helper.queryBotInfo(botId);
Backup backup = new Backup(botId, botName, botCategoryName, conditionList, configTermList, childCategories, variablesList, botInfo);
//;
//backupFile.put("botId");
try {
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 (SQLException e) {
intervalStatus = new IntervalStatus(0, SQL_CONNECTION_ERROR);
}
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
//System.out.println("xx:" + responseJSONObject.toJSONString());
PrintWriter out = response.getWriter();
out.append( + botId + ".backup");
out.flush();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
/**
* 写文件到.Json
* @param filePath
* @param sets
* @throws IOException
*/
public static void writeFile(String filePath, String sets)
throws IOException {
FileWriter fw = new FileWriter(filePath);
PrintWriter out = new PrintWriter(fw);
out.write(sets);
out.println();
fw.close();
out.close();
}
}
package com.qiwu.chatbotbackend.actiongenerate.servlet;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.DB.EngineUtils;
import com.qiwu.chatbotbackend.actiongenerate.entity.IntervalStatus;
import com.qiwu.chatbotbackend.actiongenerate.utils.CategoryUtils;
import com.qiwu.chatbotbackend.actiongenerate.utils.ConfigTermUtils;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.processing.SimpleUtil;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
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;
@WebServlet(name = "ConfigTermServlet", urlPatterns = {"/config"})
public class ConfigTermServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//读取并解析json数据
String botAccount = "", operationType = "",auth = request.getHeader("authorization");
ServletContext context = request.getServletContext();
String jsonStr = SimpleUtil.readJSONString(request);
System.out.println(jsonStr);
Integer botId;
CategoryUtils categoryUtils = null;
JSONObject responseJSONObject = new JSONObject();
if (jsonStr != null && !jsonStr.equals("")) {
JSONObject receiveParaneters = JSONObject.parseObject(jsonStr);
receiveParaneters.put("Authorization", auth);
operationType = receiveParaneters.getString("type");
botId = receiveParaneters.getInteger("botId");
try {
//EngineUtils engine = new EngineUtils();
SqlHelper helper = new SqlHelper();
EngineUtils engine = null;
ConfigTermUtils configUtils = null;
IntervalStatus intervalStatus = null;
if(operationType.equals("query_config") || operationType.equals("query_sleeping_config")){
configUtils = new ConfigTermUtils(helper);
switch(operationType){
case "query_config":
configUtils.queryConfig(receiveParaneters);
intervalStatus = configUtils.intervalStatus;
break;
case "query_sleeping_config":
configUtils.querySleepingConfig(receiveParaneters);
break;
}
intervalStatus = configUtils.intervalStatus;
}
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;
}
intervalStatus = configUtils.intervalStatus;
engine.destroy();
}else{
categoryUtils = new CategoryUtils(helper);
switch(operationType) {
case "query_category":
categoryUtils.queryCategory(receiveParaneters);
break;
case "insert_category":
categoryUtils.insertCategory(receiveParaneters);
break;
case "update_category":
categoryUtils.updateCategory(receiveParaneters);
break;
case "delete_category":
categoryUtils.deleteCategory(receiveParaneters);
break;
}
intervalStatus = categoryUtils.intervalStatus;
}
helper.destroy();
switch (intervalStatus.getStatus()){
case 1:
responseJSONObject.put("status", 1);
responseJSONObject.put("parameter", intervalStatus.getExtraData());
break;
case 0:
responseJSONObject.put("status", 0);
responseJSONObject.put("parameter", intervalStatus.getMessage());
break;
}
} catch (SQLException e) {
e.printStackTrace();
}
}else{
responseJSONObject.put("status", "0");
responseJSONObject.put("parameter", JSON_FORMAT_ERROR);
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
System.out.println("xx:" + responseJSONObject.toJSONString());
PrintWriter out = response.getWriter();
out.append(responseJSONObject.toString());
out.flush();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.qiwu.chatbotbackend.actiongenerate.servlet;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
public class CorsFilter implements Filter {
//解决跨域问题
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
HttpServletRequest reqs = (HttpServletRequest) req;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "authorization, content-type, Content-Type, x-requested-with, X-Custom-Header, HaiYi-Access-Token");
chain.doFilter(req, res);
}
public void init(FilterConfig filterConfig) {
}
public void destroy() {
}
}
\ No newline at end of file
package com.qiwu.chatbotbackend.actiongenerate.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import static com.qiwu.chatbotbackend.Config.Config.BOT_BACKUP_DIR;
@WebServlet(name = "GetBackupServlet", urlPatterns = {"/download"})
public class GetBackupServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String filename = request.getParameter("filename");
try{
response.reset();// 清空输出流
String resultFileName = filename;
resultFileName = URLEncoder.encode(resultFileName,"UTF-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment; filename=" + resultFileName);// 设定输出文件头
response.setContentType("application/msexcel");// 定义输出类型
//输入流:本地文件路径
DataInputStream in = new DataInputStream(
new FileInputStream(new File(BOT_BACKUP_DIR + filename)));
//输出流
OutputStream out = response.getOutputStream();
//输出文件
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
out.close();
in.close();
} catch(Exception e){
e.printStackTrace();
response.reset();
try {
OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8");
String data = "<script language='javascript'>alert(\"\\u64cd\\u4f5c\\u5f02\\u5e38\\uff01\");</script>";
writer.write(data);
writer.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
}
package com.qiwu.chatbotbackend.servlet; package com.qiwu.chatbotbackend.actiongenerate.servlet;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebServlet;
...@@ -6,14 +6,22 @@ import javax.servlet.http.HttpServlet; ...@@ -6,14 +6,22 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "ReloadChatCacheServlet", urlPatterns = {"/reloadChatCache"}) @WebServlet(name = "GetNextstepExceptionServlet", urlPatterns = {"/getNextStepException"})
public class ReloadChatCacheServlet extends HttpServlet { public class GetNextstepExceptionServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
} }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
response.setHeader("Access-Control-Allow-Origin", "*");
PrintWriter out = response.getWriter();
out.append("active known"); //在有多个下一步时,可以选择已被激活跳过或者是答案已知跳过
out.flush();
} }
} }
package com.qiwu.chatbotbackend.actiongenerate.servlet;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.DB.EngineUtils;
import com.qiwu.chatbotbackend.actiongenerate.utils.VariableUtils;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.processing.SimpleUtil;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
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;
@WebServlet(name = "MacroServlet", urlPatterns = {"/macro"})
public class MacroServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//读取并解析json数据
String operationType = "", botAccount = "";
ServletContext context = request.getServletContext();
String jsonStr = SimpleUtil.readJSONString(request);
String auth = request.getHeader("authorization");
JSONObject responseJSONObject = new JSONObject();
Boolean flag = true;
Integer botId;
System.out.println("xxx");
if (jsonStr != null && !jsonStr.equals("")) {
System.out.println(jsonStr);
JSONObject receiveParameters = JSONObject.parseObject(jsonStr);
receiveParameters.put("Authorization", auth);
operationType = receiveParameters.getString("type");
botId = receiveParameters.getInteger("botId");
try {
SqlHelper helper = new SqlHelper();
EngineUtils engine = new EngineUtils();
botAccount = engine.queryBotAccountByBotId(botId);
VariableUtils variableUtils = null;
helper.destroy();
switch (variableUtils.intervalStatus.getStatus()){
case 1:
responseJSONObject.put("status", 1);
responseJSONObject.put("parameter", variableUtils.intervalStatus.getExtraData());
break;
case 0:
responseJSONObject.put("status", 0);
responseJSONObject.put("parameter", variableUtils.intervalStatus.getMessage());
break;
}
} catch (SQLException e) {
e.printStackTrace();
}
}else{
responseJSONObject.put("status", 0);
responseJSONObject.put("parameter", JSON_FORMAT_ERROR);
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
//System.out.println("xx:" + responseJSONObject.toJSONString());
PrintWriter out = response.getWriter();
out.append(responseJSONObject.toString());
out.flush();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.qiwu.chatbotbackend.actiongenerate.servlet;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.DB.EngineUtils;
import com.qiwu.chatbotbackend.actiongenerate.utils.VariableUtils;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.processing.SimpleUtil;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
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;
@WebServlet(name = "VariableServlet", urlPatterns = {"/variable"})
public class VariableServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//读取并解析json数据
String operationType = "", botAccount = "";
ServletContext context = request.getServletContext();
String jsonStr = SimpleUtil.readJSONString(request);
String auth = request.getHeader("authorization");
JSONObject responseJSONObject = new JSONObject();
Boolean flag = true;
Integer botId;
System.out.println("xxx");
if (jsonStr != null && !jsonStr.equals("")) {
System.out.println(jsonStr);
JSONObject receiveParameters = JSONObject.parseObject(jsonStr);
receiveParameters.put("Authorization", auth);
operationType = receiveParameters.getString("type");
botId = receiveParameters.getInteger("botId");
try {
SqlHelper helper = new SqlHelper();
EngineUtils engine = new EngineUtils();
botAccount = engine.queryBotAccountByBotId(botId);
VariableUtils variableUtils = null;
if(operationType.equals("query_variable")){
variableUtils = new VariableUtils(helper);
variableUtils.queryVariable(receiveParameters);
}else{
variableUtils = new VariableUtils(botAccount, helper, context);
switch (operationType){
case "insert_variable":
variableUtils.insertVariable(receiveParameters);
break;
case "delete_variable":
variableUtils.deleteVairiable(receiveParameters);
break;
case "update_variable":
variableUtils.updateVariable(receiveParameters);
break;
}
}
switch(operationType) {
case "query_variable":
variableUtils.queryVariable(receiveParameters);
break;
}
switch (variableUtils.intervalStatus.getStatus()){
case 1:
responseJSONObject.put("status", 1);
responseJSONObject.put("parameter", variableUtils.intervalStatus.getExtraData());
break;
case 0:
responseJSONObject.put("status", 0);
responseJSONObject.put("parameter", variableUtils.intervalStatus.getMessage());
break;
}
helper.destroy();
engine.destroy();
} catch (SQLException e) {
e.printStackTrace();
}
}else{
responseJSONObject.put("status", 0);
responseJSONObject.put("parameter", JSON_FORMAT_ERROR);
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
//System.out.println("xx:" + responseJSONObject.toJSONString());
PrintWriter out = response.getWriter();
out.append(responseJSONObject.toString());
out.flush();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.qiwu.chatbotbackend.actiongenerate.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
public class ActionParser {
public static JSONObject parse(String actionText){
String name;
JSONObject action = new JSONObject();
for(String line:actionText.split("\r\n")){
name = line.trim().split("=")[0];
if(name.equals("") || name.equals("#actions")){
//
}else{
switch(name) {
case "name":
//parseName(line, action);
break;
case "status":
parseStatus(line, action);
break;
case "condition":
parseCondition(line, action);
break;
case "style":
parseStyle(line, action);
break;
case "action":
parseAction(line, action);
break;
case "conflict":
break;
case "process":
break;
default:
;
}
}
}
if(!action.containsKey("styleList")){
action.put("styleList", new JSONArray());
}
return action;
}
public static void parseName(String text, JSONObject action){
String elem[] = text.split("=");
action.put("actionName", elem[1]);
}
public static void parseAction(String text, JSONObject action){
String elem[] = text.split("=");
action.put("actionType", elem[1]);
}
public static void parseStatus(String text, JSONObject action){
String elem[] = text.split("=");
action.put("status", elem[1]);
}
public static void parseStyle(String text, JSONObject action){
String elem[] = text.split("=");
String subElem[] = elem[1].split(",");
action.put("styleList", new JSONArray(Arrays.asList(subElem)));
}
public static void parseConflict(String text, JSONObject action){
//
}
public static void parseCondition(String text, JSONObject action){
String elem[] = text.split("\\|", 4);
String condition = elem[0];
String relation = elem[1];
String questionText = elem[2];
String repeatStr = elem[3];
String conditionName = "", relationList[], questionElem[];
JSONArray questionList = new JSONArray();
JSONArray repeatList = new JSONArray();
String conditionElem[] = condition.split("=");
conditionElem = conditionElem[1].split(":");
action.put("conditionName", conditionElem[0]);
if(conditionElem.length >=2)
action.put("dataType", conditionElem[1]);
relationList = relation.split(",");
action.put("relationHead", relationList[0]);
action.put("relationName", relationList[1]);
action.put("relationTail", relationList[2]);
for(String question:questionText.split("~")){
questionElem = question.split(":");
JSONObject iterDict = new JSONObject();
iterDict.put("que_start_time",questionElem[0]);
iterDict.put("que_stop_time" ,questionElem[1]);
iterDict.put("que_sen" ,questionElem[2]);
if(questionElem.length == 4 && questionElem[3].equals("base"))
iterDict.put("base", 1);
else
iterDict.put("base", 0);
questionList.add(iterDict);
}
action.put("questionList", questionList);
for(String repeat:repeatStr.split("~")){
JSONObject repeatDict = new JSONObject();
elem = repeat.split("=", 2);
repeatDict.put("repeatString", elem[0]);
repeatDict.put("repeatKeywords", elem[1]);
repeatList.add(repeatDict);
}
action.put("repeatList", repeatList);
}
}
package com.qiwu.chatbotbackend.actiongenerate.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.entity.BotInfo;
import com.qiwu.chatbotbackend.actiongenerate.entity.Category;
import com.qiwu.chatbotbackend.actiongenerate.entity.IntervalStatus;
import com.qiwu.chatbotbackend.db.SqlHelper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.qiwu.chatbotbackend.Config.Config.*;
public class CategoryUtils {
SqlHelper helper = null;
public IntervalStatus intervalStatus = new IntervalStatus(1, "");
public CategoryUtils(SqlHelper helper){
this.helper = helper;
}
public void insertCategory(JSONObject parameters){
int id = 0;
Category category = new Category(parameters.getInteger("botId"), parameters.getInteger("categoryParentId"), parameters.getString("categoryName"));
id = helper.insertCategoryByBotId(category);
if(id != 0)
intervalStatus = new IntervalStatus(1, "");
else
intervalStatus = new IntervalStatus(0, CATEGORY_INSERT_ERROR);
}
public void updateCategory(JSONObject parameters){
Boolean updateFlag = true;
List<Integer> childIds = null;
Category category = new Category(parameters.getInteger("botId"), parameters.getInteger("categoryId"),
parameters.getInteger("newParentId"), parameters.getString("newCategoryName"));
childIds = findChildCategoryIds(category.getBotId(), category.getCategoryId());
if(childIds.contains(category.getParentId())){
intervalStatus = new IntervalStatus(0, CATEGORY_UPDATE_CONFLICT);
}else{
updateFlag = helper.updateCategory(category);
if(updateFlag)
intervalStatus = new IntervalStatus(1, "");
else
intervalStatus = new IntervalStatus(0, CATEGORY_UPDATE_ERROR);
}
}
public List<Integer> findChildCategoryIds(int botId, int rootId){
List<Category> categories = helper.queryCategoryAll(botId);
List<Integer> idList = new ArrayList<Integer>(){
{
add(rootId);
}
};
if(rootId == -1) //0和-1表示所有类别
idList.add(0);
for(Category category:categories){
if(idList.contains(category.getParentId())){
idList.add(category.getCategoryId());
}
}
return idList;
}
public List<Integer> findChildCategoryIds(int botId, int rootId, List<Category> childCategories){
List<Category> categories = helper.queryCategoryAll(botId);
List<Integer> idList = new ArrayList<Integer>(){
{
add(rootId);
}
};
if(rootId == -1) //0和-1表示所有类别
idList.add(0);
for(Category category:categories){
if(idList.contains(category.getParentId())){
idList.add(category.getCategoryId());
}
if(idList.contains(category.getCategoryId())){
childCategories.add(category);
}
}
return idList;
}
public void queryCategory(JSONObject parameters){
int botId = parameters.getInteger("botId");
String categoryId, parentId, defaultCategoryName = "默认";
List<Integer> defaultCategoryPath = new ArrayList<Integer>();
List<Category> categories = helper.queryCategoryAll(botId);
Map<Integer, Category> categoryMap = new HashMap<Integer, Category>();
BotInfo botInfo = helper.queryBotInfo(botId);
JSONObject finalJson = new JSONObject();
/**
* 结构是
* {
* |--- -1 (根目录)
* | |----0 默认类别
* | |----其他用户新建类别
* }
*/
JSONObject categoryTree = new JSONObject();
categoryTree.put("0", new JSONObject(){{
put("value", 0);
put("label", "默认");
put("children", new JSONArray());
}}
);
categoryTree.put("-1", new JSONObject(){{
put("value", -1);
put("label", "root");
put("children", new JSONArray());
}}
);
categoryTree.getJSONObject("-1").getJSONArray("children").add(categoryTree.getJSONObject("0"));
for(Category category:categories){
categoryMap.put(category.getBotId(), category);
}
//默认类别路径格式:"[一级类别,二级类别, 三级类别..]"
if(botInfo.getDefaultConfigCategory().equals("") || !botInfo.getDefaultConfigCategory().startsWith("[")){
//默认路径是从0开始
defaultCategoryPath.add(0);
}else{
defaultCategoryPath = JSONArray.parseArray(botInfo.getDefaultConfigCategory(), Integer.class);
}
for(Category category:categories){
categoryId = String.valueOf(category.getCategoryId());
parentId = String.valueOf(category.getParentId());
categoryTree.put(categoryId, new JSONObject(){
{
put("value", category.getCategoryId());
put("label", category.getName());
}
});
categoryTree.putIfAbsent(parentId, new JSONObject());
if(categoryTree.getJSONObject(parentId).getJSONArray("children") == null){
categoryTree.getJSONObject(parentId).put("children", new JSONArray());
}
//将当年类别id的引用放在父id下
categoryTree.getJSONObject(parentId).getJSONArray("children").add(categoryTree.getJSONObject(categoryId));
if(category.getCategoryId() == defaultCategoryPath.get(defaultCategoryPath.size()-1)){
defaultCategoryName = category.getName();
}
}
finalJson.put("category", categoryTree.getJSONObject("-1").getJSONArray("children"));
finalJson.put("defaultId", JSONArray.parseArray(JSON.toJSONString(defaultCategoryPath)));
finalJson.put("defaultIdName", defaultCategoryName);
intervalStatus = new IntervalStatus(1, "", finalJson);
}
public void deleteCategory(JSONObject parameters){
Boolean flag1, flag2;
int botId = parameters.getInteger("botId");
int categoryId = parameters.getInteger("categoryId");
List<Integer>idList = findChildCategoryIds(botId, categoryId);
flag1 = helper.deleteCategoryByCategoryIds(botId, idList);
if(flag1) {
helper.deleteConfigByCategories(botId, idList);
intervalStatus = new IntervalStatus(1, "");
}else{
intervalStatus = new IntervalStatus(0, CATEGORY_DELETE_ERROR);
}
}
}
package com.qiwu.chatbotbackend.actiongenerate.utils;
public class MacroUtils {
}
package com.qiwu.chatbotbackend.actiongenerate.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.entity.IntervalStatus;
import com.qiwu.chatbotbackend.actiongenerate.entity.Variable;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.processing.UserInfoController;
import javax.servlet.ServletContext;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.qiwu.chatbotbackend.Config.Config.*;
public class VariableUtils {
SqlHelper helper = null;
public IntervalStatus intervalStatus = new IntervalStatus(1, "");
String botAccount = "";
ServletContext context = null;
UserInfo userInfo = null;
public VariableUtils(String botAccount, SqlHelper helper, ServletContext context) throws IOException, SQLException {
this.helper = helper;
this.context = context;
this.botAccount = botAccount;
UserInfoController uiController = new UserInfoController();
this.userInfo = uiController.userInfoQuery(botAccount, context);
}
public VariableUtils(SqlHelper helper) {
this.helper = helper;
}
public void queryVariable(JSONObject parameters){
int botId = parameters.getInteger("botId");
List<Variable> variables = null;
JSONArray varList = new JSONArray();
variables = helper.queryVariableAll(botId);
for(Variable variable:variables){
varList.add(new JSONObject(){
{
put("id", variable.getVariableId());
put("categoryId", variable.getCategoryId());
put("name", variable.getName());
put("description", variable.getDescription());
put("default", variable.getValue());
}
});
}
intervalStatus = new IntervalStatus(1, "", varList);
}
public void insertVariable(JSONObject parameters) throws IOException {
int botId = parameters.getInteger("botId");
int variableId = 0;
Variable variable = new Variable(parameters.getInteger("botId"), parameters.getInteger("categoryId"),
parameters.getString("varName"), parameters.getString("varDescription"),
parameters.getString("varDefaultValue"));
if(helper.queryVariableByName(variable.getBotId(), variable.getName()) != null){
intervalStatus = new IntervalStatus(0, VARIABLE_NAME_DUMPLICATE);
}else{
variableId = helper.insertVariable(variable);
if(variableId != 0){
UserInfoController.updateVariable(botAccount, "", String.format(VARIABLE_UPDATE_FORMAT, variable.getName(), variable.getValue()), context);
UserInfoController.writeConfigText(botAccount, userInfo);
//修改配置文件
}else{
intervalStatus = new IntervalStatus(0, VARIABLE_INSERT_ERROR);
}
}
}
public void deleteVairiable(JSONObject parameters) throws IOException {
int botId = parameters.getInteger("botId");
int variableId = parameters.getInteger("varId");
Boolean deleteFalg = true;
//从delete
//deleteFalg =
Variable variable = helper.queryVariableByVariableId(botId, variableId);
if(deleteFalg) {
deleteFalg = helper.deleteVariable(botId, variableId);
System.out.println("deleteFlag" + deleteFalg);
if(deleteFalg){
intervalStatus = new IntervalStatus(1, "");
UserInfoController.deleteVariable(botAccount, "", variable.getName(), context);
UserInfoController.writeConfigText(botAccount, userInfo);
}else{
intervalStatus = new IntervalStatus(0, VARIABLE_SQL_DELETE_ERROR);
}
}else{
intervalStatus = new IntervalStatus(0, VARIABLE_DELETE_ERROR);
}
}
public void updateVariable(JSONObject parameters) throws IOException {
Boolean updateFlag = true;
Variable variable = new Variable(parameters.getInteger("botId"), parameters.getInteger("varId"),
parameters.getInteger("categoryId"), parameters.getString("varName"),
parameters.getString("varDescription"), parameters.getString("varDefaultValue"));
Variable variable2 = helper.queryVariableByName(variable.getBotId(), variable.getName());
if(variable2 != null && variable.getVariableId() == variable2.getVariableId()){
intervalStatus = new IntervalStatus(0, VARIABLE_NAME_DUMPLICATE);
}else{
updateFlag = helper.updateVariable(variable);
if(updateFlag){
intervalStatus = new IntervalStatus(1, "");
UserInfoController.updateVariable(botAccount, "", String.format(VARIABLE_UPDATE_FORMAT, variable.getName(), variable.getValue()), context);
UserInfoController.writeConfigText(botAccount, userInfo);
}else{
if(variable.getCategoryId() == variable2.getCategoryId() && variable.getBotId() == variable2.getBotId()
&& variable.getValue().equals(variable2.getValue()) && variable.getName().equals(variable2.getValue())
&& variable.getDescription().equals(variable2.getDescription())){
UserInfoController.updateVariable(botAccount, "", String.format(VARIABLE_UPDATE_FORMAT, variable.getName(), variable.getValue()), context);
UserInfoController.writeConfigText(botAccount, userInfo);
intervalStatus = new IntervalStatus(1, "");
}else {
intervalStatus = new IntervalStatus(0, VARIABLE_UPDATE_ERROR);
}
}
}
}
public Set<String> getVariableNameSet(List<Variable> variableList){
Set<String> variableNameSet = new HashSet<String>();
for(Variable variable:variableList){
variableNameSet.add(variable.getName());
}
return variableNameSet;
}
}
package com.qiwu.chatbotbackend.controller;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import static com.qiwu.chatbotbackend.Config.Config.BOT_BACKUP_DIR;
@RestController
@ResponseBody
public class BackupController {
@Autowired
ResourceLoader loader;
@GetMapping("/sayhi2")
public ResponseEntity<byte[]> getFile(@PathVariable("name") String name){
System.out.println("---" + name);
String filePath = BOT_BACKUP_DIR + name;
byte[] body = null;
try {
body = IOUtils.toByteArray(loader.getResource("file:" + filePath).getInputStream());
}catch (Exception e){
e.printStackTrace();
}
String fileName = filePath.substring(filePath.lastIndexOf('/')+1, filePath.length());
HttpHeaders headers=new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename="+fileName);
return new ResponseEntity(body, headers, HttpStatus.OK);
}
@RequestMapping("/sayhi1")
public ResponseEntity<byte[]> getFile2(){
System.out.println("---");
String filePath = BOT_BACKUP_DIR;
byte[] body = null;
try {
body = IOUtils.toByteArray(loader.getResource("file:" + filePath).getInputStream());
}catch (Exception e){
e.printStackTrace();
}
String fileName = filePath.substring(filePath.lastIndexOf('/')+1, filePath.length());
HttpHeaders headers=new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename="+fileName);
return new ResponseEntity(body, headers, HttpStatus.OK);
}
}
package com.qiwu.chatbotbackend.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Hello {
@RequestMapping("/sayhi")
public String sayHi() {
return "hello: ";
}
}
...@@ -15,7 +15,8 @@ public class C3p0Utils { ...@@ -15,7 +15,8 @@ public class C3p0Utils {
//通过标识名来创建相应连接池 //通过标识名来创建相应连接池
static ComboPooledDataSource dataSource = new ComboPooledDataSource("mysql"); static ComboPooledDataSource dataSource = new ComboPooledDataSource("mysql");
//通过标识名来创建相应连接池 //通过标识名来创建相应连接池
static ComboPooledDataSource dataSource2 = new ComboPooledDataSource("mysql2"); static ComboPooledDataSource dataSource2 = new ComboPooledDataSource("engine");
static ComboPooledDataSource dataSource3 = new ComboPooledDataSource("platform");
//从连接池中取用一个连接 //从连接池中取用一个连接
public static Connection getConnection() throws SQLException { public static Connection getConnection() throws SQLException {
...@@ -39,6 +40,17 @@ public class C3p0Utils { ...@@ -39,6 +40,17 @@ public class C3p0Utils {
} }
} }
//从连接池中取用一个连接
public static Connection getPlatformConnection() throws SQLException {
try {
return dataSource3.getConnection();
} catch (Exception e) {
logger.error("Exception in C3p0Utils!", e);
throw e;
}
}
//释放连接回连接池 //释放连接回连接池
public static void close(Connection conn, PreparedStatement pst, ResultSet rs) throws SQLException { public static void close(Connection conn, PreparedStatement pst, ResultSet rs) throws SQLException {
if (rs != null) { if (rs != null) {
......
...@@ -16,18 +16,7 @@ public class ConfigTermText implements Cloneable{ ...@@ -16,18 +16,7 @@ public class ConfigTermText implements Cloneable{
} }
}; };
private int id = 0; private int id = 0;
private String jCurPremise = "";
private String jHisPremise = "";
private String jFeature = "";
private String jNextStep = "";
private String jReply = "";
private String jAuxiliaryPriority = "0";
private int jStatus = 0;
private String curPremise = ""; private String curPremise = "";
private String hisPremise = ""; private String hisPremise = "";
...@@ -40,10 +29,14 @@ public class ConfigTermText implements Cloneable{ ...@@ -40,10 +29,14 @@ public class ConfigTermText implements Cloneable{
private String auxiliaryPriority = "1"; private String auxiliaryPriority = "1";
private String status = "waiting"; private String status = "waiting";
static HashMap<String, Integer> StatusMap = new HashMap<String, Integer>(){
{
put("waiting", 0);
put("sleeping", 1);
}
};
public void setjStatus(int jStatus) {
this.jStatus = jStatus;
}
public String getFeature() { public String getFeature() {
return feature; return feature;
} }
...@@ -73,8 +66,6 @@ public class ConfigTermText implements Cloneable{ ...@@ -73,8 +66,6 @@ public class ConfigTermText implements Cloneable{
iterNum.set(iterNum.get() + 1); iterNum.set(iterNum.get() + 1);
System.out.println("iterNum:" + iterNum.get());
//iterNum++;
this.configName = configName + "_" + iterNum.get(); this.configName = configName + "_" + iterNum.get();
}else{ }else{
this.configName = configName; this.configName = configName;
...@@ -90,58 +81,6 @@ public class ConfigTermText implements Cloneable{ ...@@ -90,58 +81,6 @@ public class ConfigTermText implements Cloneable{
} }
public String getjCurPremise() {
return jCurPremise;
}
public void setjCurPremise(String jCurPremise) {
this.jCurPremise = jCurPremise;
}
public String getjHisPremise() {
return jHisPremise;
}
public void setjHisPremise(String jHisPremise) {
this.jHisPremise = jHisPremise;
}
public String getjFeature() {
return jFeature;
}
public void setjFeature(String jFeature) {
this.jFeature = jFeature;
}
public String getjNextStep() {
return jNextStep;
}
public void setjNextStep(String jNextStep) {
this.jNextStep = jNextStep;
}
public String getjReply() {
return jReply;
}
public void setjReply(String jReply) {
this.jReply = jReply;
}
public String getjAuxiliaryPriority() {
return jAuxiliaryPriority;
}
public void setjAuxiliaryPriority(String jAuxiliaryPriority) {
this.jAuxiliaryPriority = jAuxiliaryPriority;
}
public int getjStatus() {
return jStatus;
}
public void setCurPremise(String curPremise) { public void setCurPremise(String curPremise) {
this.curPremise = curPremise; this.curPremise = curPremise;
} }
...@@ -414,7 +353,7 @@ public class ConfigTermText implements Cloneable{ ...@@ -414,7 +353,7 @@ public class ConfigTermText implements Cloneable{
data.put("configName", configName); data.put("configName", configName);
//添加config状态 //添加config状态
data.put("configStatus", jStatus); data.put("configStatus", statusMap.get(status));
boolean doPost = false; boolean doPost = false;
......
package com.qiwu.chatbotbackend.entity;
public class Macro {
int botId;
int macroId;
String name;
String value;
public Macro(int botId, int macroId, String name, String value) {
this.botId = botId;
this.macroId = macroId;
this.name = name;
this.value = value;
}
public Macro(int botId, String name, String value) {
this.botId = botId;
this.name = name;
this.value = value;
}
public int getBotId() {
return botId;
}
public void setBotId(int botId) {
this.botId = botId;
}
public int getMacroId() {
return macroId;
}
public void setMacroId(int macroId) {
this.macroId = macroId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
...@@ -7,10 +7,26 @@ public class Premise { ...@@ -7,10 +7,26 @@ public class Premise {
private String keyword = ""; private String keyword = "";
public Premise(String conditionName, String cmpType, String operator, String keyword) { public Premise(String conditionName, String cmpType, String operator, String keyword) {
this.conditionName = conditionName; this.conditionName = conditionName;
this.cmpType = cmpType; this.cmpType = cmpType;
this.operator = operator; this.operator = operator;
this.keyword = keyword; this.keyword = keyword;
if(cmpType == null){
this.cmpType = "match";
}else{
this.cmpType = cmpType;
}
if(operator == null){
this.operator = "Include";
}else{
this.operator = operator;
}
if(cmpType.equals("any")){
this.operator = "Include";
}
} }
public String getConditionName() { public String getConditionName() {
......
...@@ -315,7 +315,6 @@ public class MapConstructor extends ElementConstructor { ...@@ -315,7 +315,6 @@ public class MapConstructor extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("plot_" + placeA + "_doudi", false); configTermText.setConfigName("plot_" + placeA + "_doudi", false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
...@@ -327,7 +326,6 @@ public class MapConstructor extends ElementConstructor { ...@@ -327,7 +326,6 @@ public class MapConstructor extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("plot_" + placeA + "_doudi2", false); configTermText.setConfigName("plot_" + placeA + "_doudi2", false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
......
...@@ -284,14 +284,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -284,14 +284,6 @@ public class PlotConstructor2 extends ElementConstructor {
/**
* 自动跳转到下一个剧情,因为有可能存在多步自动跳转,所以要用一个while来处理,
* 如果下一步剧情是自动跳转,那么把下一步剧情的更新答案(属性)移到当前剧情,并将下一步剧情id改为下下步剧情id
*/
if(reply.equals("")) if(reply.equals(""))
reply = curUnknownText; reply = curUnknownText;
...@@ -543,7 +535,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -543,7 +535,6 @@ public class PlotConstructor2 extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("queryskip1",false); configTermText.setConfigName("queryskip1",false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
...@@ -554,7 +545,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -554,7 +545,6 @@ public class PlotConstructor2 extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("queryskip2",false); configTermText.setConfigName("queryskip2",false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
...@@ -564,7 +554,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -564,7 +554,6 @@ public class PlotConstructor2 extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("queryskip3",false); configTermText.setConfigName("queryskip3",false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
...@@ -591,7 +580,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -591,7 +580,6 @@ public class PlotConstructor2 extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("unknown1",false); configTermText.setConfigName("unknown1",false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
...@@ -603,7 +591,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -603,7 +591,6 @@ public class PlotConstructor2 extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("unknown2",false); configTermText.setConfigName("unknown2",false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
...@@ -615,7 +602,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -615,7 +602,6 @@ public class PlotConstructor2 extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("unknown3",false); configTermText.setConfigName("unknown3",false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
...@@ -626,7 +612,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -626,7 +612,6 @@ public class PlotConstructor2 extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("unknown4",false); configTermText.setConfigName("unknown4",false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
...@@ -638,7 +623,6 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -638,7 +623,6 @@ public class PlotConstructor2 extends ElementConstructor {
); );
configTermText.setStatus("sleeping"); configTermText.setStatus("sleeping");
configTermText.setConfigName("common_answer",false); configTermText.setConfigName("common_answer",false);
configTermText.setjStatus(1);
configTermText.setAuxiliaryPriority("0"); configTermText.setAuxiliaryPriority("0");
configTermTextList.add(configTermText); configTermTextList.add(configTermText);
//--------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------
......
...@@ -54,33 +54,23 @@ public class ChatCacheController { ...@@ -54,33 +54,23 @@ public class ChatCacheController {
try { chatCache = chatCacheMap.get(userKey);
chatCache = chatCacheMap.get(userKey);
//如果用户之前没有玩过或者有一段时间没有玩 //如果用户之前没有玩过或者有一段时间没有玩
if(chatCache == null){ if(chatCache == null){
chatCache = new ChatCache(userinfo, userKey, randKey, botType);
chatCacheMap.put(userKey, chatCache);
//用户几分钟前还在玩
} else {
if( !chatCache.getRandKey().equals(randKey)) { //同一个用户的不同一次会话, 保存上一次会话
//当用户id和随机对话id不同时,表示用户为登录状态,用户登录且开始游戏,则可以存档
if(chatCache != null && !chatCache.getRandKey().equals(chatCache.getUserKey()) && chatCache.isGameStart()) {
ChatCacheController.saveChatCache(chatCache, null);
}
chatCache = new ChatCache(userinfo, userKey, randKey, botType); chatCache = new ChatCache(userinfo, userKey, randKey, botType);
chatCacheMap.put(userKey, chatCache); chatCacheMap.put(userKey, chatCache);
//用户几分钟前还在玩
} else {
if( !chatCache.getRandKey().equals(randKey)) { //同一个用户的不同一次会话, 保存上一次会话
//当用户id和随机对话id不同时,表示用户为登录状态,用户登录且开始游戏,则可以存档
if(chatCache != null && !chatCache.getRandKey().equals(chatCache.getUserKey()) && chatCache.isGameStart()) {
ChatCacheController.saveChatCache(chatCache, null);
}
chatCache = new ChatCache(userinfo, userKey, randKey, botType);
chatCacheMap.put(userKey, chatCache);
}
} }
//historyInfoPoint = (Map<String, String>) context.getAttribute("chat_key+"+userinfo.userName);
} catch (Exception e) {
//可整合
e.printStackTrace();
//chatCache = new ChatCache(userinfo, userKey, randKey);
//chatCacheMap.put(userKey, chatCache);
} }
System.out.println(chatCache.getGameEnv()); System.out.println(chatCache.getGameEnv());
...@@ -138,7 +128,6 @@ public class ChatCacheController { ...@@ -138,7 +128,6 @@ public class ChatCacheController {
} catch (Exception e) { } catch (Exception e) {
System.out.println("游戏存档时发生异常"); System.out.println("游戏存档时发生异常");
e.printStackTrace();
opFlag = false; opFlag = false;
} }
...@@ -158,33 +147,27 @@ public class ChatCacheController { ...@@ -158,33 +147,27 @@ public class ChatCacheController {
String fileDir = System.getProperty("user.dir") + "/ChatCache"; String fileDir = System.getProperty("user.dir") + "/ChatCache";
String line, pair[]; String line, pair[];
Map<String, String> infoPoints = new HashMap<String, String>(); Map<String, String> infoPoints = new HashMap<String, String>();
try {
File file = new File(CHAT_CACHE_DIR + archiveInfo.getArchiveId() + ENV_POSTFIX);
if (file.exists()){
gameEnv = (GameEnv) ObjectFileUtil.readObjectFromFile(CHAT_CACHE_DIR + archiveInfo.getArchiveId() + ENV_POSTFIX);
}else{
throw new IOException("环境存档不存在");
}
File file = new File(CHAT_CACHE_DIR + archiveInfo.getArchiveId() + ENV_POSTFIX);
if (file.exists()){
gameEnv = (GameEnv) ObjectFileUtil.readObjectFromFile(CHAT_CACHE_DIR + archiveInfo.getArchiveId() + ENV_POSTFIX);
}else{
throw new IOException("环境存档不存在");
}
file = new File(CHAT_CACHE_DIR + archiveInfo.getArchiveId() + INFO_POSTFIX);
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String jsonStr = br.readLine();
infoPoint = (Map)JSON.parseObject(jsonStr);
chatCache = new ChatCache(keys[0], keys[1], gameEnv, infoPoint);
chatCache.setGameStart(true);
br.close();
fr.close();
file = new File(CHAT_CACHE_DIR + archiveInfo.getArchiveId() + INFO_POSTFIX);
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String jsonStr = br.readLine();
infoPoint = (Map)JSON.parseObject(jsonStr);
chatCache = new ChatCache(keys[0], keys[1], gameEnv, infoPoint);
chatCache.setGameStart(true);
br.close();
fr.close();
} catch (IOException e) {
System.out.println(e.toString());
}
return chatCache; return chatCache;
} }
...@@ -194,7 +177,7 @@ public class ChatCacheController { ...@@ -194,7 +177,7 @@ public class ChatCacheController {
/** /**
* chatChche中每个chatkey都有对应的最后更新时间,如果最后更新时间已经是x分钟前(超时),就清除该chatKey的数据 * chatChche中每个chatkey都有对应的最后更新时间,如果最后更新时间已经是x分钟前(超时),就清除该chatKey的数据
*/ */
public static synchronized void updateChatCache4Delete(String userKey, ServletContext context, UserInfo userInfo) throws IOException { public static synchronized void updateChatCache4Delete(String userKey, ServletContext context, UserInfo userInfo){
String sessionKey; String sessionKey;
ChatCache chatCache = null; ChatCache chatCache = null;
SqlHelper helper = null; SqlHelper helper = null;
...@@ -289,7 +272,7 @@ public class ChatCacheController { ...@@ -289,7 +272,7 @@ public class ChatCacheController {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; findFlag = false;
} }
return findFlag; return findFlag;
......
...@@ -6,6 +6,8 @@ import com.qiwu.chatbotbackend.entity.Solution; ...@@ -6,6 +6,8 @@ import com.qiwu.chatbotbackend.entity.Solution;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
...@@ -23,7 +25,7 @@ import java.util.Date; ...@@ -23,7 +25,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
public class MyFunc { public class SimpleUtil {
/** /**
* 将后台返回的数据转成json格式 * 将后台返回的数据转成json格式
...@@ -64,6 +66,57 @@ public class MyFunc { ...@@ -64,6 +66,57 @@ public class MyFunc {
return json.toString(); return json.toString();
} }
public static JSONObject getMethod(String url, String auth){
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse resp = null;
String respContent = null;
String keyName = null;
JSONObject jobj = new JSONObject();
try {
HttpGet httpGet = new HttpGet(url);
if(auth != null){
httpGet.setHeader("Authorization", auth);
}
resp = client.execute(httpGet);
if (resp.getStatusLine().getStatusCode() == 200) {
HttpEntity he = resp.getEntity();
respContent = EntityUtils.toString(he, "UTF-8");
jobj = JSONObject.parseObject(respContent);
jobj.put("get_status", 1);
jobj.put("status_code", 200);
} else {
jobj.put("get_status", 0);
jobj.put("status_code", resp.getStatusLine().getStatusCode());
jobj.put("parameter", "接收请求的程序出现异常");
}
} catch (Exception e) {
e.printStackTrace();
jobj.put("status_code", 0);
jobj.put("get_status", 0);
}finally {
try {
if (resp != null) {
resp.close();
}
if (client != null) {
client.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
return jobj;
}
/** /**
* 通过get方法传递参数时需要对参数的编码进行转换 * 通过get方法传递参数时需要对参数的编码进行转换
*/ */
...@@ -134,18 +187,22 @@ public class MyFunc { ...@@ -134,18 +187,22 @@ public class MyFunc {
try { try {
HttpResponse resp = client.execute(httpPost); HttpResponse resp = client.execute(httpPost);
jobj.put("status_code", resp.getStatusLine().getStatusCode());
if (resp.getStatusLine().getStatusCode() == 200) { if (resp.getStatusLine().getStatusCode() == 200) {
HttpEntity he = resp.getEntity(); HttpEntity he = resp.getEntity();
respContent = EntityUtils.toString(he, "UTF-8"); respContent = EntityUtils.toString(he, "UTF-8");
jobj = JSONObject.parseObject(respContent); jobj = JSONObject.parseObject(respContent);
jobj.put("post_status", 1); jobj.put("post_status", 1);
jobj.put("status_code", 200);
} else { } else {
jobj.put("post_status", 0); jobj.put("post_status", 0);
jobj.put("parameter", "接收请求的程序出现异常"); jobj.put("status_code", resp.getStatusLine().getStatusCode());
jobj.put("parameter", "接收请求的程序出现异常:" + resp.getStatusLine().getReasonPhrase());
} }
} catch (Exception e) { } catch (Exception e) {
jobj.put("status_code", 0);
jobj.put("post_status", 0);
e.printStackTrace(); e.printStackTrace();
} }
...@@ -181,12 +238,11 @@ public class MyFunc { ...@@ -181,12 +238,11 @@ public class MyFunc {
} else { } else {
jobj.put("post_status", 0); jobj.put("post_status", 0);
jobj.put("parameter", "接收请求的程序出现异常"); jobj.put("error_message", "目标程序处理失败:" + url + ", 错误码:" + resp.getStatusLine().getStatusCode());
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); jobj.put("error_message", "提交表单时出错:" + e.getMessage());
jobj.put("post_status", 0); jobj.put("post_status", 0);
} }
return jobj; return jobj;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment