Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SmartBox
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
苗权威
SmartBox
Commits
c44f1797
Commit
c44f1797
authored
Jul 10, 2020
by
苗权威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
7.10
parent
f6c638bc
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
356 additions
and
182 deletions
+356
-182
workspace.xml
.idea/workspace.xml
+0
-0
ApachHttpUtils.java
...n/java/ai/qiwu/com/tts_service/common/ApachHttpUtils.java
+19
-0
CallPython.java
.../main/java/ai/qiwu/com/tts_service/common/CallPython.java
+1
-1
OkHttp3Utils.java
...ain/java/ai/qiwu/com/tts_service/common/OkHttp3Utils.java
+16
-4
TTSUtils.java
...rc/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
+35
-0
DeployController.java
.../ai/qiwu/com/tts_service/controller/DeployController.java
+1
-0
Initialize.java
...main/java/ai/qiwu/com/tts_service/service/Initialize.java
+16
-6
TTService.java
.../main/java/ai/qiwu/com/tts_service/service/TTService.java
+5
-2
TTServiceEdition2.java
...va/ai/qiwu/com/tts_service/service/TTServiceEdition2.java
+0
-0
ThirdPartyService.java
...qiwu/com/tts_service/service/baidu/ThirdPartyService.java
+30
-3
SpiritController.java
...a/ai/qiwu/com/xiaoduhome/controller/SpiritController.java
+1
-1
XiaoAiController.java
...a/ai/qiwu/com/xiaoduhome/controller/XiaoAiController.java
+1
-1
XiaoDuHomeController.java
.../qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java
+82
-61
OutSideCache.java
...ain/java/ai/qiwu/com/xiaoduhome/outside/OutSideCache.java
+1
-1
BaseHostData.java
...n/java/ai/qiwu/com/xiaoduhome/pojo/data/BaseHostData.java
+2
-0
DplBotServiceBoth.java
...ava/ai/qiwu/com/xiaoduhome/service/DplBotServiceBoth.java
+44
-31
ScheduleServiceNew.java
...va/ai/qiwu/com/xiaoduhome/service/ScheduleServiceNew.java
+25
-12
SpiritRedisService.java
...ava/ai/qiwu/com/xiaoduhome/spirit/SpiritRedisService.java
+38
-29
XiaoAiServiceRedis.java
...iwu/com/xiaoduhome/xiaoai/service/XiaoAiServiceRedis.java
+39
-30
No files found.
.idea/workspace.xml
View file @
c44f1797
This diff is collapsed.
Click to expand it.
tts_service/src/main/java/ai/qiwu/com/tts_service/common/ApachHttpUtils.java
View file @
c44f1797
...
...
@@ -660,4 +660,23 @@ public class ApachHttpUtils {
return
super
.
retryRequest
(
exception
,
executionCount
,
context
);
}
}
public
static
void
main
(
String
[]
args
)
{
String
s
=
"你现在的身份是江湖,二十七岁,乌托邦大学毕业三年,目前在喜来公司做策划。在情人节这天,你打算今晚就跟相恋五年的女朋友梅子求婚,看到她微笑的样子,你抓住时机进行求婚,于是你开口说"
;
s
+=
"你看啊,月球并不是大家以为的那样光滑,那上面像地球上一样有高山,山谷和裂痕。木星的周围有4颗卫星在围着它公转,这就是太阳系的缩影啊。而且我还发现太阳里面有黑点,黑点的位置不断的在变动,你知道\n"
+
"这些说明了什么吗?"
;
s
+=
"这些现象说明地球在围着太阳转,而太阳也是一个普通的恒星,所有的恒星都是像太阳那样的巨大天体。宇宙间的一切天体,包括太阳那样的恒星和地球这样的行星,都在运动之中。你说这是不是证明了哥白尼的学>说是正确的啊?"
;
s
+=
"据报道,朴元淳市长取消了9日当天的全部日程,上午10点44分左右从家中背着背包离开,随后失联。朴元淳的女儿在当天下午5点17分报案,她向警方表示:父亲四五个小时前留下类似遗言的话之后离家,手机也关机了。另据韩国SBS电视台报道,警方确实在朴元淳官邸发现了遗书。\n"
+
"\n"
+
"随后展开搜寻,通过手机定位找到了尸体。\n"
+
"\n"
+
"朴元淳1956年出生,2011年起担任首尔市长一职,隶属韩国执政党共同民主党。2017年韩国总统选举期间,朴元淳一度被视为潜在竞选人。但是,与文在寅等党内热门竞选人相比,朴元淳支持率较低,最终放弃参与竞选。"
;
s
+=
"当地时间10日凌晨,韩国政坛传出令人震惊的消息,首尔市长朴元淳在失踪十几小时后被发现身亡。其女儿9日下午曾报案称,父亲留下类似遗言的信息后离家并失联。\n"
+
"\n"
+
"朴元淳的遗书10日被公布,“向所有人致歉,感谢所有在我人生中一起度过的人”,“对一直只给予了痛苦的家人表示十分抱歉”,“请将我火葬后撒在父母的墓地”。\n"
+
"\n"
+
"在遗书的最后一行,他写道,“所有人,再见”。"
;
System
.
out
.
println
(
s
.
length
());
System
.
out
.
println
(
s
.
replaceAll
(
"\n"
,
""
));
}
}
tts_service/src/main/java/ai/qiwu/com/tts_service/common/CallPython.java
View file @
c44f1797
...
...
@@ -65,7 +65,7 @@ public class CallPython {
*/
public
static
String
changeSoundByPython
(
String
wav_filename
,
String
volume
,
String
speed
,
String
pitch
,
String
filename
)
throws
IOException
{
String
[]
args
=
{
INTERPRETER
,
Initialize
.
getChangeSound
(),
wav_filename
,
volume
,
speed
,
pitch
,
filename
};
String
[]
args
=
{
INTERPRETER
,
Initialize
.
getChangeSound
(),
wav_filename
,
filename
,
volume
,
speed
,
pitch
};
// log.info("wav file:{}, vlo:{},speed:{}, pitch:{}", wav_filename, volume, speed, pitch);
// return processUtil(args);
String
s
=
execute
(
args
);
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/common/OkHttp3Utils.java
View file @
c44f1797
...
...
@@ -7,6 +7,7 @@ import okio.BufferedSink;
import
okio.Okio
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
import
org.jetbrains.annotations.NotNull
;
import
org.springframework.util.CollectionUtils
;
import
java.io.File
;
import
java.io.IOException
;
...
...
@@ -421,20 +422,31 @@ public class OkHttp3Utils {
* put请求实现类,返回状态码
* @param url 请求地址
* @param headers 请求头参数
* @param jsonStr json数据
* @return json信息
* @throws IOException
*/
public
static
Integer
doDeleteReturnCode
(
String
url
,
Map
<
String
,
String
>
headers
,
String
jsonStr
)
throws
IOException
{
public
static
Integer
doDeleteReturnCode
(
String
url
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
params
,
String
jsonStr
)
throws
IOException
{
Request
.
Builder
builder
=
new
Request
.
Builder
();
Request
request
=
builder
.
url
(
url
).
build
();
Headers
.
Builder
headBuilder
=
request
.
headers
().
newBuilder
();
if
(!
CollectionUtils
.
isEmpty
(
headers
))
{
Iterator
<
Map
.
Entry
<
String
,
String
>>
headIterator
=
headers
.
entrySet
().
iterator
();
headIterator
.
forEachRemaining
(
e
->
headBuilder
.
add
(
e
.
getKey
(),
e
.
getValue
()));
}
HttpUrl
.
Builder
urlBuild
=
request
.
url
().
newBuilder
();
if
(!
CollectionUtils
.
isEmpty
(
params
))
{
Iterator
<
Map
.
Entry
<
String
,
String
>>
paramsIterator
=
params
.
entrySet
().
iterator
();
paramsIterator
.
forEachRemaining
(
e
->
urlBuild
.
addQueryParameter
(
e
.
getKey
(),
e
.
getValue
()));
}
builder
.
headers
(
headBuilder
.
build
()).
delete
(
RequestBody
.
create
(
MediaType
.
parse
(
"application/json;charset=utf-8"
),
jsonStr
));
MediaType
mediaType
=
MediaType
.
Companion
.
parse
(
"application/json;charset=utf-8"
);
RequestBody
stringBody
=
RequestBody
.
Companion
.
create
(
jsonStr
,
mediaType
);
builder
.
url
(
urlBuild
.
build
())
.
headers
(
headBuilder
.
build
())
.
delete
(
stringBody
);
// .delete(RequestBody.create(MediaType.parse("application/json;charset=utf-8"), jsonStr));
Response
response
=
client
.
newCall
(
builder
.
build
()).
execute
();
try
(
ResponseBody
body
=
response
.
body
()){
body
.
string
();
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
View file @
c44f1797
...
...
@@ -57,6 +57,41 @@ public class TTSUtils {
return
AB_REGEX
;
}
public
static
ArrayDeque
<
String
>
splitLongText
(
int
bound
,
String
text
)
{
String
[]
splitArr
=
text
.
split
(
"[,,。!!;::??]"
);
ArrayDeque
<
String
>
deque
=
new
ArrayDeque
<>();
if
(
splitArr
.
length
==
1
)
{
dealOneWholeTooLongText
(
text
,
deque
,
bound
);
}
else
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
item:
splitArr
)
{
if
(
builder
.
length
()
+
item
.
length
()
>
bound
)
{
deque
.
addLast
(
builder
.
toString
());
builder
=
new
StringBuilder
();
if
(
item
.
length
()
>
bound
)
{
dealOneWholeTooLongText
(
item
,
deque
,
bound
);
if
(
deque
.
peekLast
().
length
()
<
bound
)
{
builder
.
append
(
deque
.
pollLast
());
}
}
else
builder
.
append
(
item
);
}
else
{
builder
.
append
(
item
);
}
}
}
return
deque
;
}
private
static
void
dealOneWholeTooLongText
(
String
text
,
ArrayDeque
<
String
>
deque
,
int
bound
)
{
int
length
=
text
.
length
();
int
i
=
0
;
while
(
i
<
length
)
{
deque
.
addLast
(
StringUtils
.
truncate
(
text
,
i
,
bound
));
i
+=
bound
;
}
}
/**
* 判断文件的编码
* @param file 文件
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java
View file @
c44f1797
...
...
@@ -56,6 +56,7 @@ public class DeployController {
Files
.
createFile
(
pt
);
}
catch
(
IOException
e
)
{
log
.
error
(
"mark file create fail:{}, botAccount:{},path:{}"
,
e
,
botAccount
,
path
);
new
File
(
markPath
).
delete
();
return
"failure"
;
}
TTService
.
POOL
.
submit
(()
->
synSysImgTargetServerDown
(
length
,
path
,
sourceServer
,
zipDir
,
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/service/Initialize.java
View file @
c44f1797
...
...
@@ -68,7 +68,7 @@ public class Initialize implements InitializingBean {
/**
* 第三方person列表
*/
private
static
volatile
Lis
t
<
String
>
THIRD_PARTY_TTS
;
private
static
volatile
Se
t
<
String
>
THIRD_PARTY_TTS
;
/**
* 第三方person及其角色识别标识
...
...
@@ -144,14 +144,20 @@ public class Initialize implements InitializingBean {
*/
private
final
SpeakerInfoRepository
speakerInfoRepository
;
public
static
final
String
AUDIO_GENERATE_SERVER
;
static
final
String
AUDIO_GENERATE_SERVER
;
public
static
final
int
XIAODU_TEXT_SIZE_LIMIT
;
public
static
final
int
LIEHU_TEXT_SIZE_LIMIT
;
public
static
final
int
US_TEXT_SIZE_LIMIT
;
/**
* 静态代码块
*/
static
{
URL_LS
=
new
ArrayList
<>();
THIRD_PARTY_TTS
=
new
ArrayLis
t
<>();
THIRD_PARTY_TTS
=
new
HashSe
t
<>();
ONLINE_ID_2_URL
=
new
HashMap
<>();
ONLINE_ID_2_PERSON_TON
=
new
HashMap
<>();
URL_2_PERSON_TON
=
new
HashMap
<>();
...
...
@@ -171,6 +177,10 @@ public class Initialize implements InitializingBean {
record_callback_url
=
Config
.
getProperty
(
"record_callback_url"
);
AUDIO_GENERATE_SERVER
=
Config
.
getProperty
(
"audio_generate_server"
);
XIAODU_TEXT_SIZE_LIMIT
=
Integer
.
parseInt
(
Config
.
getProperty
(
"xiaodu_text_size_limit"
,
"2040"
));
LIEHU_TEXT_SIZE_LIMIT
=
Integer
.
parseInt
(
Config
.
getProperty
(
"xiaoai_text_size_limit"
,
"1500"
));
US_TEXT_SIZE_LIMIT
=
Integer
.
parseInt
(
Config
.
getProperty
(
"us_text_size_limit"
,
"495"
));
// 根据数据库表中get_online字段的值来抉择不同的服务器
String
[]
online_sever_list
=
Config
.
getProperty
(
"online_sever"
).
split
(
","
);
for
(
String
serverAdd:
online_sever_list
)
{
...
...
@@ -287,7 +297,7 @@ public class Initialize implements InitializingBean {
void
updateCache
()
{
Map
<
String
,
PersonInfo
>
PERSON_INFO_ONLINE_TEMP
=
new
HashMap
<>();
List
<
String
>
THIRD_PARTY_TTS_TEMP
=
new
ArrayLis
t
<>();
Set
<
String
>
THIRD_PARTY_TTS_TEMP
=
new
HashSe
t
<>();
List
<
String
>
URL_LS_TEMP
=
new
ArrayList
<>();
Map
<
Integer
,
String
>
ONLINE_ID_2_URL_TEMP
=
new
HashMap
<>();
Map
<
String
,
List
<
String
>>
URL_2_PERSON_TON_TEMP
=
new
HashMap
<>();
...
...
@@ -329,7 +339,7 @@ public class Initialize implements InitializingBean {
init_url
=
PERSON_MOODURL
.
get
(
init_person
).
get
(
init_tone
);
}
private
void
refreshData
(
SpeakersInfo
speakerInfo
,
Map
<
String
,
PersonInfo
>
PERSON_INFO_ONLINE
,
Lis
t
<
String
>
THIRD_PARTY_TTS
,
private
void
refreshData
(
SpeakersInfo
speakerInfo
,
Map
<
String
,
PersonInfo
>
PERSON_INFO_ONLINE
,
Se
t
<
String
>
THIRD_PARTY_TTS
,
List
<
String
>
URL_LS
,
Map
<
Integer
,
String
>
ONLINE_ID_2_URL
,
Map
<
String
,
List
<
String
>>
URL_2_PERSON_TON
,
Map
<
String
,
Map
<
String
,
String
>>
PERSON_MOODURL
,
Map
<
String
,
PersonInfo
>
PERSON_INFO_OFFLINE
,
Map
<
String
,
Map
<
String
,
Integer
>>
OFFLINE_2_ONLINE
,
Map
<
Integer
,
List
<
String
>>
ONLINE_ID_2_PERSON_MOOD
)
{
...
...
@@ -417,7 +427,7 @@ public class Initialize implements InitializingBean {
return
init_url
;
}
static
Lis
t
<
String
>
getThirdPartyTts
()
{
static
Se
t
<
String
>
getThirdPartyTts
()
{
return
THIRD_PARTY_TTS
;
}
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTService.java
View file @
c44f1797
...
...
@@ -147,7 +147,10 @@ public class TTService {
try
{
//String url = String.format("%s/online_cache", Initialize.getOfflineServer());
// String url = new StringBuilder(Initialize.getOfflineServer()).append(File.separator).append("online_cache").toString();
deleteOfflineResCode
=
OkHttp3Utils
.
doDeleteReturnCode
(
Initialize
.
ONLINE_CACHE_URL
,
new
HashMap
<>(),
offlineStr
);
// Map<String, String> params = new HashMap<>();
// params.put("botname",onlineCache.getBotname());
// params.put("server",onlineCache.getServer());
deleteOfflineResCode
=
OkHttp3Utils
.
doDeleteReturnCode
(
Initialize
.
ONLINE_CACHE_URL
,
null
,
null
,
offlineStr
);
if
(
deleteOfflineResCode
!=
200
)
{
log
.
error
(
"对:{} 地址的delete请求失败,响应码:{}"
,
Initialize
.
ONLINE_CACHE_URL
,
deleteOfflineResCode
);
result
=
TTSConstants
.
DELETE_OFFLINE_FAIL
;
...
...
@@ -160,7 +163,7 @@ public class TTService {
if
(
deleteOfflineResCode
==
null
)
deleteOfflineResCode
=
556
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"删除offline地址的bot请求出错:{},offlineStr:{}"
,
e
.
toString
(),
o
fflineStr
);
log
.
error
(
"删除offline地址的bot请求出错:{},offlineStr:{}"
,
e
.
toString
(),
o
nlineCache
);
result
=
TTSConstants
.
DELETE_FAIL
;
deleteOfflineResCode
=
555
;
}
...
...
tts_service/src/main/java/ai/qiwu/com/tts_service/service/TTServiceEdition2.java
View file @
c44f1797
This diff is collapsed.
Click to expand it.
tts_service/src/main/java/ai/qiwu/com/tts_service/service/baidu/ThirdPartyService.java
View file @
c44f1797
...
...
@@ -2,10 +2,13 @@ package ai.qiwu.com.tts_service.service.baidu;
import
ai.qiwu.com.tts_service.common.ErrorMsgEnum
;
import
ai.qiwu.com.tts_service.common.OkHttp3Utils
;
import
ai.qiwu.com.tts_service.common.TTSUtils
;
import
ai.qiwu.com.tts_service.common.pcm.Pcm2Wav
;
import
ai.qiwu.com.tts_service.common.TTSConstants
;
import
ai.qiwu.com.tts_service.common.TTSConstants.BAI_DU
;
import
ai.qiwu.com.tts_service.service.Initialize
;
import
ai.qiwu.com.tts_service.service.LieHuSchedule
;
import
ai.qiwu.com.tts_service.service.TTService
;
import
com.alibaba.fastjson.JSON
;
import
com.baidu.aip.speech.AipSpeech
;
import
com.baidu.aip.speech.TtsResponse
;
...
...
@@ -13,8 +16,9 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.commons.lang3.RandomStringUtils
;
import
java.io.*
;
import
java.util.HashMap
;
import
java.util.UUID
;
import
java.util.*
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
/**
* 第三方请求实现
...
...
@@ -39,6 +43,10 @@ public class ThirdPartyService {
public
static
boolean
thirdPartyCall
(
String
text
,
String
per
,
String
filepath
,
String
person
)
{
person
=
getThirdPartyName
(
person
);
if
(
"Baidu"
.
equals
(
person
))
{
// if (text.length() > Initialize.XIAODU_TEXT_SIZE_LIMIT) {
// ArrayDeque<String> deque = TTSUtils.splitLongText(Initialize.XIAODU_TEXT_SIZE_LIMIT, text);
//
// }
return
synthesis
(
text
,
Integer
.
parseInt
(
per
),
filepath
);
}
else
if
(
"Liehu"
.
equals
(
person
))
{
return
lieHuTTS
(
text
,
per
,
filepath
);
...
...
@@ -48,6 +56,25 @@ public class ThirdPartyService {
return
false
;
}
private
static
void
sliceRequestThird
(
ArrayDeque
<
String
>
deque
,
int
per
,
String
filepath
)
{
List
<
Future
<
Boolean
>>
results
=
new
ArrayList
<>();
String
pre
=
filepath
.
substring
(
0
,
filepath
.
lastIndexOf
(
"."
));
for
(
int
i
=
0
;
i
<
deque
.
size
();
i
++)
{
String
text
=
deque
.
pollFirst
();
String
slice
=
pre
+
"_slice"
+
i
+
".wav"
;
results
.
add
(
TTService
.
POOL
.
submit
(()
->
synthesis
(
text
,
per
,
slice
)));
}
String
path
;
for
(
Future
<
Boolean
>
future:
results
)
{
try
{
future
.
get
(
30
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
log
.
error
(
"分片下载第三方出错:{}, path:{}"
,
deque
,
filepath
);
}
}
}
/**
* 获取第三方的标识
* @param person 角色标识
...
...
@@ -164,6 +191,6 @@ public class ThirdPartyService {
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
correctSoundParams
(
"73.436"
,
false
)
);
synthesis
(
"佳人微醺,现在的她充满活力,要夸夸她吗?"
,
106
,
"/home/yf01/testttt.wav"
);
}
}
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/SpiritController.java
View file @
c44f1797
...
...
@@ -51,7 +51,7 @@ public class SpiritController {
*/
@PostMapping
(
value
=
"/"
)
//智能小说
public
ResultModel
<
TaskResult
>
getResponse
(
@RequestBody
String
taskQuery
)
{
log
.
info
(
"=========================="
);
//
log.info("==========================");
// log.info("TaskQuery:{}",taskQuery);
TaskQuery
query
=
MetaFormat
.
parseToQuery
(
taskQuery
);
...
...
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoAiController.java
View file @
c44f1797
...
...
@@ -102,7 +102,7 @@ public class XiaoAiController {
@PostMapping
(
"/adult"
)
public
XiaoAiResponse
xiaoaiAdult
(
@RequestBody
XiaoAiRequest
request
,
HttpServletRequest
servletRequest
)
{
// 智能小说
//log.info("请求:"+request);
log
.
info
(
"================================"
);
//
log.info("================================");
try
{
if
(!
Utils
.
encry
(
2
,
servletRequest
))
{
log
.
error
(
"验证没通过:2"
);
...
...
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java
View file @
c44f1797
...
...
@@ -24,6 +24,7 @@ import java.io.File;
import
java.io.InputStreamReader
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Enumeration
;
import
java.util.concurrent.TimeUnit
;
/**
* @author 苗权威
...
...
@@ -156,68 +157,88 @@ public class XiaoDuHomeController {
return
null
;
}
// @PostMapping("/change/host")
// public void changeBaseHost(@RequestBody BaseHostData data) {
// if (StringUtils.startsWith(data.getSecretKey(), "mqw")
// && StringUtils.endsWith(data.getSecretKey(),"#") && data.getSecretKey().length() == 8) {
// if (ScheduleServiceNew.THE_PROCESS_IS_MASTER) {
// for (String slaveProcessUrl : ScheduleServiceNew.serverAddresses) {
// OkHttp3Utils.serverChangeCallOtherSalve(slaveProcessUrl+"xiaoduhome/change/host", JSON.toJSONString(data));
// }
// }
// ScheduleServiceNew.OLD_BASE_HOST_URL = ScheduleServiceNew.BASE_HOST_URL;
// ScheduleServiceNew.BASE_HOST_URL = data.getHost();
// stringRedisTemplate.opsForValue().setIfAbsent(Constants.SERVER_CHANGE_KEY, "1", 4, TimeUnit.MINUTES);
// ScheduleServiceNew.SERVER_CHANGE = true;
// }
// log.info("BASE_HOST_URL:"+ScheduleServiceNew.BASE_HOST_URL);
// log.info("OLD_BASE_HOST_URL:"+ScheduleServiceNew.OLD_BASE_HOST_URL);
// }
@PostMapping
(
"/change/host"
)
public
void
changeBaseHost
(
@RequestBody
BaseHostData
data
)
{
if
(
StringUtils
.
startsWith
(
data
.
getSecretKey
(),
"mqw"
)
&&
StringUtils
.
endsWith
(
data
.
getSecretKey
(),
"#"
)
&&
data
.
getSecretKey
().
length
()
==
8
)
{
if
(
ScheduleServiceNew
.
THE_PROCESS_IS_MASTER
)
{
for
(
String
slaveProcessUrl
:
ScheduleServiceNew
.
serverAddresses
)
{
OkHttp3Utils
.
serverChangeCallOtherSalve
(
slaveProcessUrl
+
"xiaoduhome/change/host"
,
JSON
.
toJSONString
(
data
));
}
}
ScheduleServiceNew
.
OLD_BASE_HOST_URL
=
ScheduleServiceNew
.
BASE_HOST_URL
;
ScheduleServiceNew
.
OLD_BASE_AUDIO_URL
=
ScheduleServiceNew
.
BASE_AUDIO_URL
;
ScheduleServiceNew
.
OLD_CDN_HOST_URL
=
ScheduleServiceNew
.
CDN_HOST_URL
;
ScheduleServiceNew
.
BASE_HOST_URL
=
data
.
getHost
();
ScheduleServiceNew
.
BASE_AUDIO_URL
=
data
.
getAudio
();
ScheduleServiceNew
.
CDN_HOST_URL
=
data
.
getCdn
();
// @PostMapping("/change/host/getInOldServerNum")
// public String getOldServerUserNum(@RequestBody BaseHostData data) {
// if (StringUtils.startsWith(data.getSecretKey(), "mqw")
// && StringUtils.endsWith(data.getSecretKey(),"#") && data.getSecretKey().length() == 8) {
// if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(Constants.SERVER_CHANGE_KEY))) {
// Cursor<byte[]> scan = stringRedisTemplate.getConnectionFactory().getConnection()
// .scan(ScanOptions.scanOptions().match(Constants.CAN_NOT_MOVE_USER_KEY+"*").build());
// int staynUM = 0;
// while (scan.hasNext()) {
// scan.next();
// staynUM++;
// }
// String s = new StringBuilder("正在切换服务器,剩余时间(s):")
// .append(stringRedisTemplate.getExpire(Constants.SERVER_CHANGE_KEY)).append(",停留在旧服务器人数:")
// .append(staynUM).append(",新BASE_HOST地址:")
// .append(ScheduleServiceNew.BASE_HOST_URL).append(",旧BASE_HOST地址:").append(ScheduleServiceNew.OLD_BASE_HOST_URL)
// .append(",标志为值:").append(ScheduleServiceNew.SERVER_CHANGE).toString();
//
// log.info(s);
// return s;
// }
// Cursor<byte[]> scan = stringRedisTemplate.getConnectionFactory().getConnection()
// .scan(ScanOptions.scanOptions().match(Constants.CAN_NOT_MOVE_USER_KEY+"*").build());
// if (!scan.hasNext()) {
// ScheduleServiceNew.SERVER_CHANGE = false;
// if (ScheduleServiceNew.THE_PROCESS_IS_MASTER) {
// for (String slaveProcessUrl : ScheduleServiceNew.serverAddresses) {
// OkHttp3Utils.serverChangeCallOtherSalve(slaveProcessUrl+"xiaoduhome/change/host/getInOldServerNum", JSON.toJSONString(data));
// }
// }
// log.info("There is no one in old server,标志为值:"+ScheduleServiceNew.SERVER_CHANGE+",新BASE_HOST地址:"+ScheduleServiceNew.BASE_HOST_URL);
// return "There is no one in old server";
// } else {
// int staynUM = 0;
// while (scan.hasNext()) {
// scan.next();
// staynUM++;
// }
// log.info(staynUM+" users in oldServer,标志为值:"+ScheduleServiceNew.SERVER_CHANGE+",新BASE_HOST地址:"+ScheduleServiceNew.BASE_HOST_URL);
// return staynUM+" users in oldServer";
// }
// }
// return "secret wrong";
// }
stringRedisTemplate
.
opsForValue
().
setIfAbsent
(
Constants
.
SERVER_CHANGE_KEY
,
"1"
,
4
,
TimeUnit
.
MINUTES
);
ScheduleServiceNew
.
SERVER_CHANGE
=
true
;
}
log
.
info
(
"BASE_HOST_URL:"
+
ScheduleServiceNew
.
BASE_HOST_URL
);
log
.
info
(
"BASE_AUDIO_URL:"
+
ScheduleServiceNew
.
BASE_AUDIO_URL
);
log
.
info
(
"CDN_HOST_URL:"
+
ScheduleServiceNew
.
CDN_HOST_URL
);
log
.
info
(
"OLD_BASE_HOST_URL:"
+
ScheduleServiceNew
.
OLD_BASE_HOST_URL
);
log
.
info
(
"OLD_BASE_AUDIO_URL:"
+
ScheduleServiceNew
.
OLD_BASE_AUDIO_URL
);
log
.
info
(
"OLD_CDN_HOST_URL:"
+
ScheduleServiceNew
.
OLD_CDN_HOST_URL
);
}
@PostMapping
(
"/change/host/getInOldServerNum"
)
public
String
getOldServerUserNum
(
@RequestBody
BaseHostData
data
)
{
if
(
StringUtils
.
startsWith
(
data
.
getSecretKey
(),
"mqw"
)
&&
StringUtils
.
endsWith
(
data
.
getSecretKey
(),
"#"
)
&&
data
.
getSecretKey
().
length
()
==
8
)
{
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
hasKey
(
Constants
.
SERVER_CHANGE_KEY
)))
{
Cursor
<
byte
[]>
scan
=
stringRedisTemplate
.
getConnectionFactory
().
getConnection
()
.
scan
(
ScanOptions
.
scanOptions
().
match
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
"*"
).
build
());
int
staynUM
=
0
;
while
(
scan
.
hasNext
())
{
scan
.
next
();
staynUM
++;
}
String
s
=
new
StringBuilder
(
"正在切换服务器,剩余时间(s):"
)
.
append
(
stringRedisTemplate
.
getExpire
(
Constants
.
SERVER_CHANGE_KEY
)).
append
(
",停留在旧服务器人数:"
)
.
append
(
staynUM
).
append
(
",新BASE_HOST地址:"
).
append
(
ScheduleServiceNew
.
BASE_HOST_URL
)
.
append
(
",旧BASE_HOST地址:"
).
append
(
ScheduleServiceNew
.
OLD_BASE_HOST_URL
)
.
append
(
",标志为值:"
).
append
(
ScheduleServiceNew
.
SERVER_CHANGE
).
toString
();
log
.
info
(
s
);
return
s
;
}
Cursor
<
byte
[]>
scan
=
stringRedisTemplate
.
getConnectionFactory
().
getConnection
()
.
scan
(
ScanOptions
.
scanOptions
().
match
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
"*"
).
build
());
if
(!
scan
.
hasNext
())
{
ScheduleServiceNew
.
SERVER_CHANGE
=
false
;
if
(
ScheduleServiceNew
.
THE_PROCESS_IS_MASTER
)
{
for
(
String
slaveProcessUrl
:
ScheduleServiceNew
.
serverAddresses
)
{
OkHttp3Utils
.
serverChangeCallOtherSalve
(
slaveProcessUrl
+
"xiaoduhome/change/host/getInOldServerNum"
,
JSON
.
toJSONString
(
data
));
}
}
log
.
info
(
"There is no one in old server,标志为值:"
+
ScheduleServiceNew
.
SERVER_CHANGE
+
",新BASE_HOST地址:"
+
ScheduleServiceNew
.
BASE_HOST_URL
);
return
"There is no one in old server"
;
}
else
{
int
staynUM
=
0
;
while
(
scan
.
hasNext
())
{
scan
.
next
();
staynUM
++;
}
log
.
info
(
staynUM
+
" users in oldServer,标志为值:"
+
ScheduleServiceNew
.
SERVER_CHANGE
+
",新BASE_HOST地址:"
+
ScheduleServiceNew
.
BASE_HOST_URL
);
return
staynUM
+
" users in oldServer"
;
}
}
return
"secret wrong"
;
}
@GetMapping
(
"/check/url/info"
)
public
void
checkUrlInfo
(
@RequestParam
String
psd
)
{
if
(
StringUtils
.
startsWith
(
psd
,
"mqw"
)
&&
StringUtils
.
endsWith
(
psd
,
"#"
)
&&
psd
.
length
()
==
8
)
{
log
.
info
(
"BASE_HOST_URL:"
+
ScheduleServiceNew
.
BASE_HOST_URL
);
log
.
info
(
"BASE_AUDIO_URL:"
+
ScheduleServiceNew
.
BASE_AUDIO_URL
);
log
.
info
(
"CDN_HOST_URL:"
+
ScheduleServiceNew
.
CDN_HOST_URL
);
}
}
@PostMapping
(
"/notice"
)
public
void
receiveOtherServerNotice
(
@RequestBody
NoticeReceiveData
data
)
{
...
...
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/outside/OutSideCache.java
View file @
c44f1797
...
...
@@ -38,7 +38,7 @@ public class OutSideCache implements InitializingBean {
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
initFillCacheData
();
//
initFillCacheData();
}
private
void
initFillCacheData
()
{
...
...
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/data/BaseHostData.java
View file @
c44f1797
...
...
@@ -10,4 +10,6 @@ import lombok.ToString;
public
class
BaseHostData
{
private
String
secretKey
;
private
String
host
;
private
String
audio
;
private
String
cdn
;
}
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotServiceBoth.java
View file @
c44f1797
This diff is collapsed.
Click to expand it.
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleServiceNew.java
View file @
c44f1797
...
...
@@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -49,19 +50,23 @@ public class ScheduleServiceNew implements InitializingBean {
private
static
volatile
Map
<
String
,
String
>
channelId2RecommendBotAcc
=
new
HashMap
<>();
public
static
volatile
String
BASE_HOST_URL
=
"http://didi-gz3.jiaoyou365.com:"
;
public
static
volatile
String
XIAO_AI_ENCRY_HOST
;
public
static
volatile
String
BASE_AUDIO_URL
=
"http://didi-gz3.jiaoyou365.com:"
;
// public static volatile String OLD_BASE_HOST_URL = "http://didi-gz3.jiaoyou365.com:";
public
static
volatile
boolean
SERVER_CHANGE
=
false
;
public
static
volatile
String
CDN_HOST_URL
=
"http://didi-gz2-cdn.jiaoyou365.com"
;
public
static
boolean
THE_PROCESS_IS_MASTER
=
false
;
public
static
volatile
String
XIAO_AI_ENCRY_HOST
=
"didi-gz4.jiaoyou365.com"
;
////////////////////
public
static
volatile
String
BASE_HOST_URL
;
public
static
volatile
String
OLD_BASE_HOST_URL
;
public
static
volatile
String
BASE_AUDIO_URL
;
public
static
volatile
String
OLD_BASE_AUDIO_URL
;
public
static
volatile
String
CDN_HOST_URL
;
public
static
volatile
String
OLD_CDN_HOST_URL
;
public
static
volatile
boolean
SERVER_CHANGE
=
false
;
static
{
private
static
Boolean
THE_PROCESS_IS_MASTER
=
false
;
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
...
...
@@ -70,9 +75,12 @@ public class ScheduleServiceNew implements InitializingBean {
getJiaoYouChannelRecordBots
();
BASE_HOST_URL
=
Config
.
getProperty
(
"baseHostUrl"
);
BASE_AUDIO_URL
=
Config
.
getProperty
(
"baseAudioUrl"
);
// OLD_BASE_HOST_URL = BASE_HOST_URL;
CDN_HOST_URL
=
Config
.
getProperty
(
"cdnHostUrl"
,
"http://didi-gz2-cdn.jiaoyou365.com"
);
XIAO_AI_ENCRY_HOST
=
Config
.
getProperty
(
"host"
,
"didi-gz3.jiaoyou365.com"
);
CDN_HOST_URL
=
Config
.
getProperty
(
"cdnHostUrl"
);
OLD_BASE_HOST_URL
=
BASE_HOST_URL
;
OLD_BASE_AUDIO_URL
=
BASE_AUDIO_URL
;
OLD_CDN_HOST_URL
=
CDN_HOST_URL
;
XIAO_AI_ENCRY_HOST
=
Config
.
getProperty
(
"host"
);
THE_PROCESS_IS_MASTER
=
Config
.
getProperty
(
"masterSlave"
,
"slave"
).
equals
(
"master"
);
log
.
info
(
"BASE_HOST_URL:{},CDN_HOST_URL:{}, xiaoai encry host:{}, masterSlave:{}"
,
BASE_HOST_URL
,
CDN_HOST_URL
,
...
...
@@ -198,7 +206,7 @@ public class ScheduleServiceNew implements InitializingBean {
boolean
success
=
false
;
do
{
try
{
response
=
OkHttp3Utils
.
doGet
(
ScheduleServiceNew
.
BASE_HOST_URL
+
"
18082/api/data/audio/list/jiaoyou"
);
response
=
OkHttp3Utils
.
doGet
(
"http://192.168.0.148:
18082/api/data/audio/list/jiaoyou"
);
jsonObject
=
JSON
.
parseObject
(
response
).
getJSONObject
(
"data"
);
Map
<
String
,
List
<
String
>>
map
=
jsonObject
.
toJavaObject
(
Map
.
class
);
if
(
map
!=
null
&&
map
.
size
()
!=
0
)
{
...
...
@@ -277,4 +285,9 @@ public class ScheduleServiceNew implements InitializingBean {
public
static
String
getTheChannelBotAccount
(
String
channel
)
{
return
channelId2RecommendBotAcc
.
get
(
channel
);
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
res
=
OkHttp3Utils
.
doGet
(
"http://hw-gz19.heyqiwu.cn:18082/api/data/audio/list/jiaoyou"
);
System
.
out
.
println
(
res
);
}
}
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/spirit/SpiritRedisService.java
View file @
c44f1797
...
...
@@ -122,20 +122,26 @@ public class SpiritRedisService {
return
buildTextTaskResult
(
WELCOME_SMART
,
intentId
);
}
// String baseHostUrl = ScheduleServiceNew.BASE_HOST_URL;
// if (ScheduleServiceNew.SERVER_CHANGE) {
// if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(Constants.SERVER_CHANGE_KEY))) {
// if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(Constants.CAN_NOT_MOVE_USER_KEY+userId))) {
// stringRedisTemplate.expire(Constants.CAN_NOT_MOVE_USER_KEY+userId, 4, TimeUnit.MINUTES);
// } else {
// stringRedisTemplate.opsForValue().set(Constants.CAN_NOT_MOVE_USER_KEY+userId, "1", 4, TimeUnit.MINUTES);
// }
// baseHostUrl = ScheduleServiceNew.OLD_BASE_HOST_URL;
// } else if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(Constants.CAN_NOT_MOVE_USER_KEY+userId))){
// stringRedisTemplate.expire(Constants.CAN_NOT_MOVE_USER_KEY+userId, 4, TimeUnit.MINUTES);
// baseHostUrl = ScheduleServiceNew.OLD_BASE_HOST_URL;
// }
// }
String
baseHostUrl
=
ScheduleServiceNew
.
BASE_HOST_URL
;
String
audioUrl
=
ScheduleServiceNew
.
BASE_AUDIO_URL
;
String
cdnUrl
=
ScheduleServiceNew
.
CDN_HOST_URL
;
if
(
ScheduleServiceNew
.
SERVER_CHANGE
)
{
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
hasKey
(
Constants
.
SERVER_CHANGE_KEY
)))
{
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
hasKey
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
)))
{
stringRedisTemplate
.
expire
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
,
4
,
TimeUnit
.
MINUTES
);
}
else
{
stringRedisTemplate
.
opsForValue
().
set
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
,
"1"
,
4
,
TimeUnit
.
MINUTES
);
}
baseHostUrl
=
ScheduleServiceNew
.
OLD_BASE_HOST_URL
;
audioUrl
=
ScheduleServiceNew
.
OLD_BASE_AUDIO_URL
;
cdnUrl
=
ScheduleServiceNew
.
OLD_CDN_HOST_URL
;
}
else
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
hasKey
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
))){
stringRedisTemplate
.
expire
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
,
4
,
TimeUnit
.
MINUTES
);
baseHostUrl
=
ScheduleServiceNew
.
OLD_BASE_HOST_URL
;
audioUrl
=
ScheduleServiceNew
.
OLD_BASE_AUDIO_URL
;
cdnUrl
=
ScheduleServiceNew
.
OLD_CDN_HOST_URL
;
}
}
try
{
// long start = System.currentTimeMillis();
...
...
@@ -168,9 +174,9 @@ public class SpiritRedisService {
}
else
if
(
data
!=
null
){
stringRedisTemplate
.
delete
(
redisId
);
stringRedisTemplate
.
delete
(
redisIdleId
);
String
botAccount
=
getBotAccountFromPath
(
data
);
return
buildAudioUrlResult
(
intentId
,
changeAudioUrlTemp
(
data
,
botAccount
)
);
// return buildAudio
TaskResult(Arrays.asList(data.split(",")), intentId
);
return
buildAudioUrlResult
(
intentId
,
data
);
// String botAccount = getBotAccountFromPath(data
);
// return buildAudio
UrlResult(intentId, changeAudioUrlTemp(data, botAccount, cdnUrl)
);
}
}
}
catch
(
Exception
e
)
{
...
...
@@ -178,8 +184,11 @@ public class SpiritRedisService {
}
// log.info("天猫精灵用户说的话:"+userWord);
try
{
// final String finalBaseHost = baseHostUrl;
Future
<
TaskResult
>
future
=
DplbotServiceUtil
.
getPOOL
().
submit
(()
->
requestTerminate
(
userId
,
userWord
,
type
,
intentId
));
final
String
finalBaseHost
=
baseHostUrl
;
final
String
finalAudioUrl
=
audioUrl
;
final
String
finalCdnUrl
=
cdnUrl
;
Future
<
TaskResult
>
future
=
DplbotServiceUtil
.
getPOOL
().
submit
(()
->
requestTerminate
(
userId
,
userWord
,
type
,
intentId
,
finalBaseHost
,
finalAudioUrl
,
finalCdnUrl
));
return
future
.
get
(
1700
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
log
.
error
(
"天猫精灵出现问题:{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
...
...
@@ -205,12 +214,13 @@ public class SpiritRedisService {
return
null
;
}
private
TaskResult
requestTerminate
(
String
userId
,
String
userWord
,
Integer
type
,
Long
intentId
)
throws
IOException
{
private
TaskResult
requestTerminate
(
String
userId
,
String
userWord
,
Integer
type
,
Long
intentId
,
String
baseHostUrl
,
String
audioUrl
,
String
cdnUrl
)
throws
IOException
{
SpiritTerminateRequest
requestPojo
=
new
SpiritTerminateRequest
();
requestPojo
.
setUid
(
userId
);
// requestPojo.setAccess(XiaoAiConstants.DEVICE_NAME);
requestPojo
.
setMsg
(
userWord
);
log
.
info
(
"天猫用户话:{}"
,
userWord
);
//
log.info("天猫用户话:{}", userWord);
String
requestJsonStr
=
JSON
.
toJSONString
(
requestPojo
);
// log.info("向终端发出请求的参数信息:{}", requestJsonStr);
...
...
@@ -224,7 +234,7 @@ public class SpiritRedisService {
}
// String resStr= OkHttp3Utils.doPostJsonStr(ScheduleServiceNew.BASE_HOST_URL, requestJsonStr, headers);
String
resStr
=
OkHttp3Utils
.
doPostJsonStrForCentralWithUidParam
(
ScheduleServiceNew
.
BASE_HOST_URL
,
requestJsonStr
,
headers
,
userId
);
String
resStr
=
OkHttp3Utils
.
doPostJsonStrForCentralWithUidParam
(
baseHostUrl
,
requestJsonStr
,
headers
,
userId
);
if
(
resStr
==
null
)
{
return
null
;
}
...
...
@@ -314,7 +324,7 @@ public class SpiritRedisService {
// }
// }
// }
String
path
=
OkHttp3Utils
.
doPostJsonStr
(
ScheduleServiceNew
.
BASE_AUDIO_URL
+
"/api/audio"
,
resStr
);
String
path
=
OkHttp3Utils
.
doPostJsonStr
(
audioUrl
+
"/api/audio"
,
resStr
);
if
(
StringUtils
.
isBlank
(
path
)
||
path
.
equals
(
"null"
))
{
log
.
error
(
"没有获取到TTS返回的路径path"
);
return
buildTextTaskResult
(
SORRY_REPEAT
,
intentId
);
...
...
@@ -324,9 +334,8 @@ public class SpiritRedisService {
log
.
warn
(
"没有获取到aipioneerUsername"
);
botAccount
=
"empty"
;
}
String
s
;
taskResult
=
buildAudioUrlResult
(
intentId
,
(
s
=
changeAudioUrlTemp
(
path
,
botAccount
)));
log
.
info
(
"天猫音频地址:"
+
s
);
taskResult
=
buildAudioUrlResult
(
intentId
,
(
path
=
changeAudioUrlTemp
(
path
,
botAccount
,
cdnUrl
)));
// log.info("天猫音频地址:"+path);
stringRedisTemplate
.
opsForValue
().
setIfPresent
(
PREFIX_REDIS
+
userId
,
path
,
20
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
toString
());
...
...
@@ -353,11 +362,11 @@ public class SpiritRedisService {
return
result
;
}
private
String
changeAudioUrlTemp
(
String
path
,
String
botAccount
)
{
private
String
changeAudioUrlTemp
(
String
path
,
String
botAccount
,
String
cdnUrl
)
{
if
(
path
.
startsWith
(
"a"
))
{
return
new
StringBuilder
(
ScheduleServiceNew
.
CDN_HOST_URL
).
append
(
"/api/audio/cache/"
).
append
(
botAccount
).
append
(
"/?filename="
).
append
(
path
.
substring
(
1
)).
append
(
"&exist=1"
).
toString
();
return
new
StringBuilder
(
cdnUrl
).
append
(
"/api/audio/cache/"
).
append
(
botAccount
).
append
(
"/?filename="
).
append
(
path
.
substring
(
1
)).
append
(
"&exist=1"
).
toString
();
}
else
{
return
new
StringBuilder
(
ScheduleServiceNew
.
CDN_HOST_URL
).
append
(
"/api/audio/cache/"
).
append
(
botAccount
).
append
(
"/?filename="
).
append
(
path
).
toString
();
return
new
StringBuilder
(
cdnUrl
).
append
(
"/api/audio/cache/"
).
append
(
botAccount
).
append
(
"/?filename="
).
append
(
path
).
toString
();
}
}
...
...
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/xiaoai/service/XiaoAiServiceRedis.java
View file @
c44f1797
...
...
@@ -229,20 +229,27 @@ public class XiaoAiServiceRedis {
private
XiaoAiResponse
dealWithIntentRequest
(
final
XiaoAiRequest
request
,
final
String
userId
)
{
Boolean
idle
=
request
.
getRequest
().
getNo_response
();
String
redisId
=
SpiritRedisService
.
PREFIX_REDIS
+
userId
;
// String baseHostUrl = ScheduleServiceNew.BASE_HOST_URL;
// if (ScheduleServiceNew.SERVER_CHANGE) {
// if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(Constants.SERVER_CHANGE_KEY))) {
// if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(Constants.CAN_NOT_MOVE_USER_KEY+userId))) {
// stringRedisTemplate.expire(Constants.CAN_NOT_MOVE_USER_KEY+userId, 4, TimeUnit.MINUTES);
// } else {
// stringRedisTemplate.opsForValue().set(Constants.CAN_NOT_MOVE_USER_KEY+userId, "1", 4, TimeUnit.MINUTES);
// }
// baseHostUrl = ScheduleServiceNew.OLD_BASE_HOST_URL;
// } else if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(Constants.CAN_NOT_MOVE_USER_KEY+userId))){
// stringRedisTemplate.expire(Constants.CAN_NOT_MOVE_USER_KEY+userId, 4, TimeUnit.MINUTES);
// baseHostUrl = ScheduleServiceNew.OLD_BASE_HOST_URL;
// }
// }
String
baseHostUrl
=
ScheduleServiceNew
.
BASE_HOST_URL
;
String
audioUrl
=
ScheduleServiceNew
.
BASE_AUDIO_URL
;
String
cdnUrl
=
ScheduleServiceNew
.
CDN_HOST_URL
;
if
(
ScheduleServiceNew
.
SERVER_CHANGE
)
{
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
hasKey
(
Constants
.
SERVER_CHANGE_KEY
)))
{
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
hasKey
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
)))
{
stringRedisTemplate
.
expire
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
,
4
,
TimeUnit
.
MINUTES
);
}
else
{
stringRedisTemplate
.
opsForValue
().
set
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
,
"1"
,
4
,
TimeUnit
.
MINUTES
);
}
baseHostUrl
=
ScheduleServiceNew
.
OLD_BASE_HOST_URL
;
audioUrl
=
ScheduleServiceNew
.
OLD_BASE_AUDIO_URL
;
cdnUrl
=
ScheduleServiceNew
.
OLD_CDN_HOST_URL
;
}
else
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
hasKey
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
))){
stringRedisTemplate
.
expire
(
Constants
.
CAN_NOT_MOVE_USER_KEY
+
userId
,
4
,
TimeUnit
.
MINUTES
);
baseHostUrl
=
ScheduleServiceNew
.
OLD_BASE_HOST_URL
;
audioUrl
=
ScheduleServiceNew
.
OLD_BASE_AUDIO_URL
;
cdnUrl
=
ScheduleServiceNew
.
OLD_CDN_HOST_URL
;
}
}
try
{
// long start = System.currentTimeMillis();
// log.info("redis get cost:"+(System.currentTimeMillis()-start));
...
...
@@ -276,9 +283,9 @@ public class XiaoAiServiceRedis {
}
else
{
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
hasKey
(
redisIdleId
)))
stringRedisTemplate
.
delete
(
redisIdleId
);
stringRedisTemplate
.
delete
(
redisId
);
// return buildAudioResponse(changeAudioUrl(data, userId)
);
String
botAccount
=
getBotAccountFromPath
(
data
);
if
(
StringUtils
.
isNotBlank
(
botAccount
))
return
buildAudioResponse
(
changeAudioUrlTemp
(
data
,
botAccount
));
return
buildAudioResponse
(
data
);
//
String botAccount = getBotAccountFromPath(data);
// if (StringUtils.isNotBlank(botAccount)) return buildAudioResponse(changeAudioUrlTemp(data, botAccount, baseHostUrl
));
}
}
}
...
...
@@ -297,9 +304,12 @@ public class XiaoAiServiceRedis {
XiaoAiConstants
.
TTS
.
ANOTHER_USER_IDLE
);
}
try
{
// final String finalBaseHost = baseHostUrl;
final
String
finalBaseHost
=
baseHostUrl
;
final
String
finalAudioUrl
=
audioUrl
;
final
String
finalCdnUrl
=
cdnUrl
;
// log.info("XIAOAI_BASE_HOST_URL:"+finalBaseHost);
Future
<
XiaoAiResponse
>
future
=
DplbotServiceUtil
.
getPool
().
submit
(()
->
task
(
userId
,
request
.
getQuery
(),
request
.
getType
()));
Future
<
XiaoAiResponse
>
future
=
DplbotServiceUtil
.
getPool
().
submit
(()
->
task
(
userId
,
request
.
getQuery
(),
request
.
getType
(),
finalBaseHost
,
finalAudioUrl
,
finalCdnUrl
));
return
future
.
get
(
2000
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
log
.
error
(
"获取任务执行结果出错:{}"
,
e
.
toString
());
...
...
@@ -372,7 +382,7 @@ public class XiaoAiServiceRedis {
}
}
private
XiaoAiResponse
task
(
String
userId
,
String
userWord
,
Integer
type
)
{
private
XiaoAiResponse
task
(
String
userId
,
String
userWord
,
Integer
type
,
String
baseUrl
,
String
audioUrl
,
String
cdnUrl
)
{
XiaoAiResponse
xiaoAiResponse
;
if
(
userWord
==
null
)
{
log
.
warn
(
"请求中没有带有用户的话"
);
...
...
@@ -380,9 +390,9 @@ public class XiaoAiServiceRedis {
}
String
response
;
try
{
log
.
info
(
"小爱,用户话:{}"
,
userWord
);
response
=
RequestTerminal
.
requestTerminate
(
userId
,
userWord
,
type
,
ScheduleServiceNew
.
BASE_HOST_URL
);
log
.
info
(
"小爱,小悟返回:{}"
,
response
);
//
log.info("小爱,用户话:{}", userWord);
response
=
RequestTerminal
.
requestTerminate
(
userId
,
userWord
,
type
,
baseUrl
);
//
log.info("小爱,小悟返回:{}", response);
}
catch
(
Exception
e
)
{
log
.
error
(
"向终端发出的请求信息失败:{}"
,
e
.
toString
());
return
buildTextResponse
(
SORRY_REPEAT
);
...
...
@@ -444,7 +454,7 @@ public class XiaoAiServiceRedis {
String
path
;
try
{
path
=
OkHttp3Utils
.
doPostJsonStr
(
ScheduleServiceNew
.
BASE_AUDIO_URL
+
"/api/audio"
,
response
);
path
=
OkHttp3Utils
.
doPostJsonStr
(
audioUrl
+
"/api/audio"
,
response
);
if
(
StringUtils
.
isBlank
(
path
)
||
path
.
equals
(
"null"
))
{
log
.
error
(
"没有获取到TTS返回的路径path"
);
return
buildTextResponse
(
SORRY_REPEAT
);
...
...
@@ -454,9 +464,8 @@ public class XiaoAiServiceRedis {
log
.
warn
(
"没有获取到aipioneerUsername"
);
botAccount
=
"empty"
;
}
String
s
;
xiaoAiResponse
=
buildAudioResponse
((
s
=
changeAudioUrlTemp
(
path
,
botAccount
)));
log
.
info
(
"音频地址:"
+
s
);
xiaoAiResponse
=
buildAudioResponse
((
path
=
changeAudioUrlTemp
(
path
,
botAccount
,
cdnUrl
)));
// log.info("音频地址:"+path);
if
(
Boolean
.
TRUE
.
equals
(
stringRedisTemplate
.
opsForValue
()
.
setIfPresent
(
SpiritRedisService
.
PREFIX_REDIS
+
userId
,
path
,
15
,
TimeUnit
.
SECONDS
)))
{
log
.
info
(
"xiaoai 超时redis存储成功"
);
...
...
@@ -476,11 +485,11 @@ public class XiaoAiServiceRedis {
return
new
StringBuilder
(
ScheduleServiceNew
.
BASE_HOST_URL
).
append
(
"9663/api/audio/get?type="
).
append
(
userId
).
append
(
"&path="
).
append
(
path
).
toString
();
}
private
String
changeAudioUrlTemp
(
String
path
,
String
botAccount
)
{
private
String
changeAudioUrlTemp
(
String
path
,
String
botAccount
,
String
cdnHost
)
{
if
(
path
.
startsWith
(
"a"
))
{
return
new
StringBuilder
(
ScheduleServiceNew
.
CDN_HOST_URL
).
append
(
"/api/audio/cache/"
).
append
(
botAccount
).
append
(
"/?filename="
).
append
(
path
.
substring
(
1
)).
append
(
"&exist=1"
).
toString
();
return
new
StringBuilder
(
cdnHost
).
append
(
"/api/audio/cache/"
).
append
(
botAccount
).
append
(
"/?filename="
).
append
(
path
.
substring
(
1
)).
append
(
"&exist=1"
).
toString
();
}
else
{
return
new
StringBuilder
(
ScheduleServiceNew
.
CDN_HOST_URL
).
append
(
"/api/audio/cache/"
).
append
(
botAccount
).
append
(
"/?filename="
).
append
(
path
).
toString
();
return
new
StringBuilder
(
cdnHost
).
append
(
"/api/audio/cache/"
).
append
(
botAccount
).
append
(
"/?filename="
).
append
(
path
).
toString
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment