Commit 07a5b650 by 苗权威

2.17

parent fa1dfaf3
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<module name="open" options="-parameters" /> <module name="open" options="-parameters" />
<module name="rokid" options="-parameters" /> <module name="rokid" options="-parameters" />
<module name="ruoqi" options="-parameters" /> <module name="ruoqi" options="-parameters" />
<module name="spirit" options="-parameters -extdirs /usr/local/intellij/workplace/smartbox/spirit/src/main/resources/lib" /> <module name="spirit" options="-parameters -extdirs $PROJECT_DIR$/spirit/src/main/resources/lib" />
<module name="third_party_load" options="-parameters" /> <module name="third_party_load" options="-parameters" />
<module name="tts_offline" options="-parameters" /> <module name="tts_offline" options="-parameters" />
<module name="tts_service" options="-parameters" /> <module name="tts_service" options="-parameters" />
......
package ai.qiwu.tmall.spirit.service;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
/**
* @author 苗权威
* @dateTime 20-1-10 下午1:29
*/
public class Test {
private static void testTts(String path) throws IOException {
List<String> lines = Files.readAllLines(Paths.get(path));
List<String> postList = new ArrayList<>();
List<String> getDuList = new ArrayList<>();
List<String> getAiList = new ArrayList<>();
// lines.forEach(s -> {
// String time = s.substring(s.indexOf("bytes")+6, s.indexOf(" ms"));
// if (!s.contains("444920673") && Integer.parseInt(time) > 1000) {
// System.out.println(s);
// }
// });
String s;
for (int i = 0; i < lines.size(); i++) {
s = lines.get(i);
if (s.contains("POST /api/audio")) {
for (int j=i+1; j < lines.size(); j++) {
s = lines.get(j);
if (lines.get(j).contains("GET /api/audio/get")) {
break;
} else if (s.contains("POST /api/audio")) {
getDuList.add(s);
break;
}
}
}
}
getDuList.forEach(System.out::println);
// System.out.println(postList.size());
// System.out.println("du:"+getDuList.size());
// System.out.println("ai:"+getAiList.size());
}
public static void main(String[] args) throws IOException {
testTts("/home/yf01/下载/SpiritAudioCsv/ttsLog/access_log.2020-01-05.log");
}
}
...@@ -50,9 +50,9 @@ public class SpiritAudioUpload { ...@@ -50,9 +50,9 @@ public class SpiritAudioUpload {
@Value("${csvDicForBotChange}") @Value("${csvDicForBotChange}")
private String csvDicForBotChange; private String csvDicForBotChange;
private volatile String cookie = "cna=qsWIFY5RHlMCAXeJN3DsHj3O; isg=BISEdD_3hmKO7DG5UmXTs1qBVgu2NamassKvzp4kp88kySaTxK3xlqOrCaG0SuBf; CNZZDATA1261708326=1797143004-1560414985-%7C1578471815; _cnzz_CV1261708326=52463%7C%F0%9F%8C%8E%20skill-audio%2F%E9%9F%B3%E9%A2%91%E5%88%97%E8%A1%A8%E4%BF%A1%E6%81%AF%7Cp; enc=GlWCH0jde0teESrXYo%2BHF75NARTOPv7uKzyscUHesjr8NqyYTkHf%2BD6PG2iP4gPoGIsaO8aq%2BG41Q6kPPhYpvw%3D%3D; UM_distinctid=16ef9e5d343206-06ea6f889716618-76256753-1fa400-16ef9e5d344241; uc1=pas=0&cookie21=UtASsssme%2BBq&tag=8&cookie14=UoTbmEnmIFxXUw%3D%3D&existShop=false&cookie15=Vq8l%2BKCLz3%2F65A%3D%3D&lng=zh_CN&cookie16=VFC%2FuZ9az08KUQ56dCrZDlbNdA%3D%3D; t=925ffaa4a0ded6c2dc567c2eedd425f0; _tb_token_=3a3eeb3e68337; cookie2=145c78f447bf6a4cafb894c15072214f; dnk=tb13503054; tracknick=tb13503054; _l_g_=Ug%3D%3D; unb=1038446007; cookie1=UNMubI1eQ0gVOzLdxFCJj7hzIKFouglcA%2BlE1IYgcZQ%3D; login=true; cookie17=UoH8Vd06g9TEfA%3D%3D; _nk_=tb13503054; sg=47f; csg=f8c7b18a; ctoken=xWUW4TnhPzTyPnCGVcBbhyoc; EGG_SESS=OG910qv3Q3gsrSK4yqRmX3-1-P_ARlUIzlqweqLqnRF5dKELPTe4hiVT80Slz3WPDCsXS99IeB9EJ08mKe1fnB-ky5BqlihGxghSrDaTuitC4LiUArU9fvgELyGofw_TmBaNcyEfrWqC-x_N6rsy8fAw2Pnp69phx2I3tEHsYh8UPT0miVV8Iz9v1Gp1EBu-x7IkCs02BFaNjygAZj4yG5Q0XFHJIVNHemQrHeuxJonSTlJkY2dqCYo_wOLIM5KLVZFHGxoxDIPcuXi37C_MOfK9Sac-zJndlvITiVSRplldFUDbSnyGTHbkxO76r76v-8Pr05wfiN1zzWuCXeZ-ATYX0IDdKpdESz--8JEeGAA-CKkMaOU0K7eXljgXRjsiDcx7bszIDb68PlwlPJV_Ehu3_D2KxVdU_wzX2bzcl-wNpjjmLFUzhoA8YzGs_JsJ2t6rSnRnegg7T0ge7PayU5pvqzfy3hUlevZmqDjZsg2hhW0kAbxkakAlZo7pCAZ-eRFZP_B2VO1qF5N95H2FSGa6CZnH9Rqe1uvQH63cnoppDsHsTis8SMxgvkYBurwjdwjbCqu_DeDR5N_XCsTFRf5Q1Idgcn38mMvfA1PT1Nk2Ye9iWTshl4PD9e3kWc2o3RTKdJNlFkjGb1AUObOobAv1XUXhX0Lx4Ypm6JQIN-2LKqOO4yoqPThj2nfiL6-FVqgNOK0IAHr0EYZS-QXMIBPP5sTUOjOjPPPHc3hJWu0yytS19l7OrV6r5UPVflEJ6_nK_1la9e6AJuDlxI_-mx_qjLXU4cEGYWTF56qcmzXyIRWh0d-rud90Ags2e17C6bzH4ijeY3vQTR9Jezzz_CjiDaT43KLQ_71bHgRYF3DL0xn-HR6QzD0HFtIUHpW_dkeC4l7Lev5zvnXeGKEUE4H-aemCRcmnTW5Rso4-_m2uW6RfUEQ0RlfpFzixKujRu9qZkWDgDTCtEEmSErJ561-mO6PDKLgTifklbRkWLc0oNBuqO0gFdkb58O8lSNum8dwGslDo-eRzKrdB-D8B1-TISMLZm1tL2Aecn9MlXkZUPc62doJjHugczHRbNONrqKkcb0d-HVmOscGgnvl9unbt-fD0wm7225k0ZJ65jESe1LipeVth8W_6hQr2IFktNRqjrN_J8IEgY7NyTauVMDRfhlK1kJ75IPWfqomMQyi30wr2R0_k8rDunfbqf726gZTdKZ109dIsXcxpWsj4v9LGolfXDQQTEFURIXI-lsn1DFkz_LL51K5R9FAIAX00-c5weol75Jgdp1auJfGYuxMlApg8QpbyxL2jReOorI5ioYN76VpQ7RRvHxO1ZMRjNvYUjdHygMcvIqeNArccASaH4Qt5RQ1jrNUFcJ84KPd709GBLt8kxgtEttev9YFHdL3YwLeEJo70Q03BXA7acYQtSQ6iUMoVrR8chjwUJ10zpzcY8QucfrA6p4DdbotQq_n2dFQlWeGGVQUZc11Qr39fekHEc68vjl9TlqSOTqjgASSzg67U6vi3s6LbS1AYMATWzTd0AC281UkjEIkmsLbdinnBtddW5bHZhGeLF01AkvwtUW9oebboJY-4onsMwNivqv6Al7QaWehDeG7kdzWLrU-g9s-ZKa3bwhuMC3VOpgC1y5Vepe9xQilNube431z6JGGW484fbkPcqHG2lrg9uPW-faND328H16PwsihwptEE14JlvxPGLDAZnldYh3RBfhJ2JBR8uhyw7ll7qjAIEud0oOA9EXQg6ppi-KeA0Jvuu5g8a_DbWrg06oV_ZZEl9BUtA_3oCD6rV4Y8PeQqPgiv9cAAUz5c2d40Mmb4GOlJnFzmXxGMa9wZ7X6exvktUmqOrxU7dHEsiFS8XHPIAtBhV7naaoIHLGVxZXHv5Wgy0wPkZMRBJa1l4ipqptNfdz6wGD_M3Nf8feP0UrBOau7VQtqc01R4eXmScY9xoBubyfajp9xkMqJsptAUbE7wZuYNRGq8CwWw8zaDRSpSf3EKEh-THO5tESoXc12mIUn5wBT8kUtE2O828HMeGcJ3PI89QRNcYQeaTmikpzqQf0MiNIaJjsD1PdPC9pVjPQ-9HXWQLylSmgAEHvcqe-s1pCk-g03koACUqKUBnCxIjBaI_By_kMkg1-kuM7TVHTLXzaWGR0cWC6RifnJPC4TBDc7KX-QUsg9GzvDibKY-ZiKULXYQCZTr_p0nKpDqSDZTuEzD14S9m9zMxJXBYI4De-FwMlWjePQkyOME4omwfDrovY33_Hbch8-aOTleVR5BfsOyVhEUdN3Dqs5ARG6AQznfH-pmHLvERYC3-Q==; accountType=TB; accountId=52463; token=+yKlBN44OA/SyckKeOJUlJVzFRetm5fqY9FVaEzSRPE=; confirmProtocolVersion=1"; private volatile String cookie = "cna=qsWIFY5RHlMCAXeJN3DsHj3O; isg=BNvaVmpjAXQDU34UoTi0hnnkaTaFGO4vMccg480nj1B7rE6P6IAnA6zqRsyHl0eq; CNZZDATA1261708326=1797143004-1560414985-%7C1578545339; _cnzz_CV1261708326=52463%7C%F0%9F%8C%8E%20skill%2F%E6%9F%A5%E8%AF%A2%E6%8A%80%E8%83%BD%7C0; enc=GlWCH0jde0teESrXYo%2BHF75NARTOPv7uKzyscUHesjr8NqyYTkHf%2BD6PG2iP4gPoGIsaO8aq%2BG41Q6kPPhYpvw%3D%3D; UM_distinctid=16ef9e5d343206-06ea6f889716618-76256753-1fa400-16ef9e5d344241; EGG_SESS=IdVWNkN2sAOQi1tLSNGnFK5nME5CTP2gTPH6kr89V-k6w6DhWzXgemwSZ-CtWPAe1Stlw2LZewllSuXxWuMyHGx_BNyTHR0DuqWpWr_t58VOdEaFO1qmpqmMOT0CSjxA5Rabb7w5lcyTHTy3w39hDbFqVW8sPjLq4KBzMvs1LcRawoGhgCaPLZ54bK7jJ41CgCLMRjekHPTq9HtHxzo2CEsmlBjYzt016HULppaaulo4FCE5d5IUGtVTmUeN3ufsxLeWrHSQFGz-s_XVflwSrlgtdjI3pKHw_fgunw-4bt8uFk8cG5dWYGacE6xkfq_KavlI2Ar_T61bhkdmvMFQhFRoqe_Qp8loplzIND3_jeoBHjQ25nmlzlYfsBHHIyOhbvwdPymLCcpmFkX2JpT5ovEHqUKV-lU45C93xsDPOY-9s2UrGPMRTAmGY84Kol57qfCNOXUl2wnfirzBKGeJEJo2o-v2T6qyeIFCc4WQqxOGKVYv30TvKQseKeLHFW0q31G-HzDYBoHAelres1yneHO_RLh61tsaYRvTAL4baQ2W5wKF2oxMf6pPtrP1gfmgCYdaW-Sf5WX3oAOTit-HBEGSS0tmQNX50yJprlGExPAPEMR2mzkyWaQhIIrcfXz4Cl8LgJasQZ12EbqbqxZA1x_G1_Bz7spmbOOAP6G97G_o2jQDNCh2_AtrIwFVA77nFIXPBru9FEjdGxyBk0xLqmsF5UClGg9ihLzZGEf8gF_-5BaRKhRXa0TPsYjLYkgUZVy9IHDmQLiMt7aSjZNtVdNJCbP8l5TNQ9wuKoslyb7sL--Jty-GiRWwQZEeqvMWois_KEqfsd3rLVrOUWDFeIPL_6hmvDxwYZgqOFWHjSeYc0bjntQRDpzG3oxMNBkHIM-rcy0eg1UiA1DvomfHYnyayFjqIXMxcOeH7v6l7_EGv9NKlUuHgvOjxwhl8MDfLWJ5jtEpjua6Idg8JH1FCth2icJTmwT9CfWWKWOYTYcwGKJuUiSA6T-Y2J-OHa4wmZwDU3bTggZDrSX_dmCFXbm_gxk2-FhunFJmZ9eWIl4_2YmPuAn7TKi8JBNxap5QGdpNF_XKN-78hyJR92_daoIv0IagZbvfdU1zGeNxpZeeudnraum8pNUXWtUWZlzuKs8OpjvY8JUuoK0Dx_mbZCQmY3-77ltZa5Z4PigPWMGMkYlGr1lusivSDqEW3fonRH5q79xvVIV2D61khPR2halgopkf87LBnnw53ym5i0Ne0q7oEbDzjgbsOliWWv6BUaCd6rg4lF3xWSM0vzvlAgu_R9cDy26h5t9ppxChHtzqw3sn-lFiOuuzgXwMh-uka3oLpvdgCHb2pXHBu-cU9ezQsSz5VA2jvDqbVHGpOFdK9YBoUNhNro4bwszvK_zWgPJiTTi1jx5VqQFWI61aIZnVrZUSVoq0kOuRK79-jTzOcsCqVY1gHCHPEvAw16BKQ584CW1QSFN52_ZsLlrP-SkkrjUJ7GZOMn_um9kbc-a68PKpBDVROG2rXvx8j5p66qY4vIFS9ayQJOeSQyHriQchweqHGeUEs4ngLcBdpeFk8JuAi-xJLUII3Rmt88vKax4SaZOg-9XKkvtef5jRE16NOPUXCiLD_0r9-Lbo0yKVSX3Wjim2gJXWvahilTtV8hBCw7VlQpbiwvAygEsrSFL9-B6dq-FS5cHbTqOZqTThxGdCRrAdMMVzPsfxR7UmSA8ykHRfmHgj3R6Xc1RyloPWr2JMKd9cf6wA03BV_XlpmfdoPzW8OH-cg0pcznY1dGmvkELbEI3RQk-2vDWhIBtcK6TR16wBTn955ZfI0tetTFMh9nD1i1E8qyDGqWJvC7WpikhlekHS3E_40Cvo-d5Kvs4oqrWLqWat-MNE61F-PCC7SDOiflXuf4agWpEWIeHwxaithtv0_32QWCzMGM_8lyGvRdazKMW_H4q7KiT0jtgTB4Tptjjtzs-DUeDXnuoVVNgIZ6evNQGi3QHGZgL3Okbhjn41elMxuu2COG3TgGfj-RfRc6Qlmj_da_Nzk54AkGkhCl_dS2XpmqCGdIrZg1PHjFaPvd_jktehC2kjN9IPdTt_9_BemwXUAJr2jRgcQKwMect1YMfehwG81w6Y3aLs4qXaPJXoEq8Tm03wuZ-uZBE6iGjNuIxe_gboReXulcdvWnxf-b7CoWpUgJBcO-h9bX3y6BS2RLVsPe-BJ0PLF1speq4GJlOYmkzjqt0caUtw83Bd5nXb-AP0jaEBxsdB0N0Nh23tFkjSGKbsCSS6WUOQ5jFDow9o7dld7NG-4g0UTU8fqiW5gjZ80gi8Vgh7kABVkypdeszxFUFdh06YsMe9pEJH8Su_vl4Rq6HL3ztMYA73Cq7SSh047A==; accountType=TB; confirmProtocolVersion=1; ctoken=hIPnBFZTxO70xYEKMWiVP5pJ; hng=CN%7Czh-CN%7CCNY%7C156; t=925ffaa4a0ded6c2dc567c2eedd425f0; tracknick=%5Cu9F50%5Cu609F%5Cu667A%5Cu80FD%5Cu8BED%5Cu97F3; lid=%E9%BD%90%E6%82%9F%E6%99%BA%E8%83%BD%E8%AF%AD%E9%9F%B3; _tb_token_=eebee77e7787e; cookie2=1bc42d8261746e9bfec4fbfb79e712fd; dnk=%5Cu9F50%5Cu609F%5Cu667A%5Cu80FD%5Cu8BED%5Cu97F3; uc1=lng=zh_CN&cookie16=VFC%2FuZ9az08KUQ56dCrZDlbNdA%3D%3D&pas=0&cookie15=V32FPkk%2Fw0dUvg%3D%3D&cookie21=V32FPkk%2FhSg%2F&existShop=false&cookie14=UoTbldffztSu3A%3D%3D&tag=8; _l_g_=Ug%3D%3D; unb=2201499686434; cookie1=BxSjQCQ6sp%2FKUbmJMrRM%2B%2FTeMnxnfP3Ky2LamSxw1u4%3D; login=true; cookie17=UUphy%2FZzlNvrKtsbCQ%3D%3D; _nk_=%5Cu9F50%5Cu609F%5Cu667A%5Cu80FD%5Cu8BED%5Cu97F3; sg=%E9%9F%B343; csg=04a77d7a; accountId=52463; token=t6PHfzW5l84NHrDFNmRRJVHclpUlndw3wDDsqNMRtbE=";
private volatile String token = "+yKlBN44OA/SyckKeOJUlJVzFRetm5fqY9FVaEzSRPE="; private volatile String token = "t6PHfzW5l84NHrDFNmRRJVHclpUlndw3wDDsqNMRtbE=";
private volatile String csrfToken = "xWUW4TnhPzTyPnCGVcBbhyoc"; private volatile String csrfToken = "hIPnBFZTxO70xYEKMWiVP5pJ";
public void updateCookie(String cookie) { public void updateCookie(String cookie) {
this.cookie = cookie; this.cookie = cookie;
...@@ -221,7 +221,7 @@ public class SpiritAudioUpload { ...@@ -221,7 +221,7 @@ public class SpiritAudioUpload {
ArrayList<DicUploadInfo> datas = new ArrayList<>(); ArrayList<DicUploadInfo> datas = new ArrayList<>();
List<DicUploadErrorInfo> errorDatas = new ArrayList<>(); List<DicUploadErrorInfo> errorDatas = new ArrayList<>();
int ln = 8; int ln = 9;
int count = 0; int count = 0;
// int errorCount = 0; // int errorCount = 0;
...@@ -651,7 +651,7 @@ public class SpiritAudioUpload { ...@@ -651,7 +651,7 @@ public class SpiritAudioUpload {
List<DicUploadErrorInfo> errorDatas = new ArrayList<>(); List<DicUploadErrorInfo> errorDatas = new ArrayList<>();
List<DicUploadInfo> datas = new ArrayList<>(); List<DicUploadInfo> datas = new ArrayList<>();
String description; String description;
int ln = 8; int ln = 9;
int count = 0; int count = 0;
if (Boolean.TRUE.equals(record)) { if (Boolean.TRUE.equals(record)) {
String root = "/root/TTS-service/audio/"+botAccount+"/record/"; String root = "/root/TTS-service/audio/"+botAccount+"/record/";
...@@ -848,7 +848,7 @@ public class SpiritAudioUpload { ...@@ -848,7 +848,7 @@ public class SpiritAudioUpload {
String mp3FileName = path.substring(path.lastIndexOf("/")+1); String mp3FileName = path.substring(path.lastIndexOf("/")+1);
String randomMp3Name; String randomMp3Name;
int i = 0; int i = 0;
int ln = 8; int ln = 9;
do { do {
if (i++ == 60) { if (i++ == 60) {
i = 0; i = 0;
......
...@@ -1173,7 +1173,7 @@ public class TTService { ...@@ -1173,7 +1173,7 @@ public class TTService {
String.valueOf(pitch), mp3FilePath); String.valueOf(pitch), mp3FilePath);
// log.info("CallPython.changeSoundByPython 耗时:{}",System.currentTimeMillis()-start); // log.info("CallPython.changeSoundByPython 耗时:{}",System.currentTimeMillis()-start);
if (!TTSUtils.doesFileExist(mp3FilePath)) { if (!TTSUtils.doesFileExist(mp3FilePath)) {
log.error("python代码出错,mp3文件没有创建成功"); log.error("python代码出错,mp3文件没有创建成功.{},{},{},{}", wavFilename, volume, speed, pitch);
res = new ResponseCodeWithData(555); res = new ResponseCodeWithData(555);
} }
//long changeSoundEndTime = System.currentTimeMillis(); //long changeSoundEndTime = System.currentTimeMillis();
...@@ -2120,10 +2120,12 @@ public class TTService { ...@@ -2120,10 +2120,12 @@ public class TTService {
if (xiaoAi) { if (xiaoAi) {
OkHttp3Utils.backPostAsync(audioUrl+type); OkHttp3Utils.backPostAsync(audioUrl+type);
} }
int count = 0;
if (Files.exists((pt = Paths.get(path)))) { if (Files.exists((pt = Paths.get(path)))) {
while (XIAOAI_MP3_MARK.contains(path)) { while (XIAOAI_MP3_MARK.contains(path) && count < 20) {
try { try {
Thread.sleep(500); Thread.sleep(500);
count++;
} catch (Exception e) {} } catch (Exception e) {}
} }
TTServiceUtil.buildMp3ResponseForAudioNoRange(response, path, xiaoAi); TTServiceUtil.buildMp3ResponseForAudioNoRange(response, path, xiaoAi);
...@@ -2132,9 +2134,10 @@ public class TTService { ...@@ -2132,9 +2134,10 @@ public class TTService {
Thread.sleep(1500); Thread.sleep(1500);
} catch (Exception e) {} } catch (Exception e) {}
if (Files.exists(pt)) { if (Files.exists(pt)) {
while (XIAOAI_MP3_MARK.contains(path)) { while (XIAOAI_MP3_MARK.contains(path) && count < 20) {
try { try {
Thread.sleep(300); Thread.sleep(300);
count++;
} catch (Exception e) {} } catch (Exception e) {}
} }
TTServiceUtil.buildMp3ResponseForAudioNoRange(response, path, xiaoAi); TTServiceUtil.buildMp3ResponseForAudioNoRange(response, path, xiaoAi);
...@@ -2316,9 +2319,9 @@ public class TTService { ...@@ -2316,9 +2319,9 @@ public class TTService {
} }
} }
public static void main(String[] args) { public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println(URLEncoder.encode("正常0c60f9484eaa35aa7a9e2879c574e8a3.mp3")); System.out.println(URLEncoder.encode("Ls69sFTjXN%2F6831N1VVdfw%3D%3D", "UTF-8"));
System.out.println(URLEncoder.encode("正常24f87c9e922d063260634941f5f75be2.mp3")); System.out.println(URLEncoder.encode("%2BnzkUO6JnLrmiWSlBQaZ9g%3D%3D", "UTF-8"));
System.out.println(URLEncoder.encode("正常d1a75129c54ef3037bd44e25ab6eeb9a.mp3")); System.out.println(URLEncoder.encode("EksNVVSieFTobNBZFEOeyw%3D%3D", "UTF-8"));
} }
} }
...@@ -280,6 +280,43 @@ public class Test { ...@@ -280,6 +280,43 @@ public class Test {
} }
} }
private static int changeHanToNum(String numStr) {
List<String> list = Arrays.asList("零", "一", "二", "三", "四", "五", "六", "七", "八", "九");
StringBuilder num = new StringBuilder();
boolean first = true;
for (String str: numStr.split("")) {
int i;
if (first) {
first = false;
if (str.equals("十")) num.append(1);
else if ((i = list.indexOf(str)) != -1) num.append(i);
}
else if ((i = list.indexOf(str)) != -1) num.append(i);
}
return Integer.parseInt(num.toString());
}
private static Integer extractNum(String numStr) {
int num;
try {
num = Integer.parseInt(numStr);
return num;
} catch (Exception e) {
int i;
if ((i=numStr.indexOf("第")) != -1) {
String str = numStr.substring(i+1, numStr.length()-1);
try {
num = Integer.parseInt(str);
} catch (Exception e1) {
num = changeHanToNum(str);
}
} else {
num = changeHanToNum(numStr);
}
}
return num;
}
public static void main(String[] args) { public static void main(String[] args) {
Date date = new Date(1572522571234L); Date date = new Date(1572522571234L);
...@@ -291,6 +328,14 @@ public class Test { ...@@ -291,6 +328,14 @@ public class Test {
Pattern pattern = Pattern.compile(TTSUtils.getAbRegex()); Pattern pattern = Pattern.compile(TTSUtils.getAbRegex());
String[] notVariableTextArray = pattern.split("\uD83C\uDD70会数学的杰瑞的类型为:儿童、简单、益智、休闲、教育、学生、免费\uD83C\uDD71"); String[] notVariableTextArray = pattern.split("\uD83C\uDD70会数学的杰瑞的类型为:儿童、简单、益智、休闲、教育、学生、免费\uD83C\uDD71");
System.out.println(TTSUtils.buildMP3Filename("为您推荐以上作品:《妖刀异闻录》、《小太阳》、《遇见伽利略》,你可以说:打开某作品")); System.out.println(extractNum("27"));
System.out.println(extractNum("二十六"));
System.out.println(extractNum("十六"));
System.out.println(extractNum("六"));
System.out.println(extractNum("第五个"));
System.out.println(extractNum("第十五个"));
System.out.println(extractNum("第二十六个"));
System.out.println(extractNum("第7个"));
System.out.println(extractNum("第17个"));
} }
} }
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
<artifactId>spring-boot-starter-websocket</artifactId> <artifactId>spring-boot-starter-websocket</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
...@@ -144,7 +148,6 @@ ...@@ -144,7 +148,6 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.9</version> <version>3.9</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -11,10 +11,7 @@ import java.nio.charset.StandardCharsets; ...@@ -11,10 +11,7 @@ import java.nio.charset.StandardCharsets;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/** /**
* @author 苗权威 * @author 苗权威
...@@ -30,6 +27,9 @@ public class Utils { ...@@ -30,6 +27,9 @@ public class Utils {
private static final String REGEX_SEPERATE = "【(.+?)】"; private static final String REGEX_SEPERATE = "【(.+?)】";
private static final String[] s1 = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
// private static final String[] s2 = { "十", "百", "千"};
public static HttpServletRequest getHttpServletRequest() { public static HttpServletRequest getHttpServletRequest() {
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder
.getRequestAttributes())).getRequest(); .getRequestAttributes())).getRequest();
...@@ -252,13 +252,29 @@ public class Utils { ...@@ -252,13 +252,29 @@ public class Utils {
} }
} }
public static int changeHanToNum(String numStr) {
List<String> list = Arrays.asList(s1);
StringBuilder num = new StringBuilder();
boolean first = true;
for (String str: numStr.split("")) {
int i;
if (first) {
first = false;
if (str.equals("十")) num.append(1);
else if ((i = list.indexOf(str)) != -1) num.append(i);
}
else if ((i = list.indexOf(str)) != -1) num.append(i);
}
return Integer.parseInt(num.toString());
}
public static void main(String[] args) throws ParseException { public static void main(String[] args) throws ParseException {
String s = "[{\"type\": \"SendEvent\",\"componentId\":\"%s\"}]"; String s = "[{\"type\": \"SendEvent\",\"componentId\":\"%s\"}]";
//System.out.println(String.format(s, "gsagh")); //System.out.println(String.format(s, "gsagh"));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = format.format(System.currentTimeMillis()); String time = format.format(System.currentTimeMillis());
Timestamp timestamp = Timestamp.valueOf(time); Timestamp timestamp = Timestamp.valueOf(time);
System.out.println(timestamp);
System.out.println(format.format(new Date(System.currentTimeMillis())));
} }
} }
package ai.qiwu.com.xiaoduhome.common.config;
import ai.qiwu.com.xiaoduhome.pojo.OverTimeDetail;
import ai.qiwu.com.xiaoduhome.pojo.XiaoDuNoScreenStore;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @author 苗权威
* @dateTime 20-1-9 下午7:54
*/
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, XiaoDuNoScreenStore> xiaoduRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, XiaoDuNoScreenStore> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(XiaoDuNoScreenStore.class);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
serializer.setObjectMapper(objectMapper);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(serializer);
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(serializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
...@@ -17,6 +17,7 @@ import ai.qiwu.com.xiaoduhome.common.temple.recommand.RecommandPojo; ...@@ -17,6 +17,7 @@ import ai.qiwu.com.xiaoduhome.common.temple.recommand.RecommandPojo;
import ai.qiwu.com.xiaoduhome.entity.primary.GameProjectTb; import ai.qiwu.com.xiaoduhome.entity.primary.GameProjectTb;
import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail; import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
import ai.qiwu.com.xiaoduhome.entity.secondary.XiaoDuHistoryBotIdTime; import ai.qiwu.com.xiaoduhome.entity.secondary.XiaoDuHistoryBotIdTime;
import ai.qiwu.com.xiaoduhome.pojo.data.ProjectData;
import ai.qiwu.com.xiaoduhome.pojo.dpl.Item; import ai.qiwu.com.xiaoduhome.pojo.dpl.Item;
import ai.qiwu.com.xiaoduhome.pojo.dpl.MyDocument; import ai.qiwu.com.xiaoduhome.pojo.dpl.MyDocument;
import ai.qiwu.com.xiaoduhome.pojo.pageData.HistoryData; import ai.qiwu.com.xiaoduhome.pojo.pageData.HistoryData;
...@@ -254,9 +255,9 @@ public class TempleUtils { ...@@ -254,9 +255,9 @@ public class TempleUtils {
return collect; return collect;
} }
public static List<LunchBotData> buildDataList(List<GameProjectTb> list, int begin) { public static List<LunchBotData> buildDataList(List<ProjectData> list, int begin) {
ArrayList<LunchBotData> dataList = new ArrayList<>(); ArrayList<LunchBotData> dataList = new ArrayList<>();
for (GameProjectTb projectInfo : list) { for (ProjectData projectInfo : list) {
String productName = correctName(projectInfo.getName()); String productName = correctName(projectInfo.getName());
String imageId = new StringBuilder(Constants.PRE_PRODUCT_IMG).append(projectInfo.getName()).toString(); String imageId = new StringBuilder(Constants.PRE_PRODUCT_IMG).append(projectInfo.getName()).toString();
String src = new StringBuilder(IMG_PREFIX).append(projectInfo.getBannerImgUrl()).toString(); String src = new StringBuilder(IMG_PREFIX).append(projectInfo.getBannerImgUrl()).toString();
......
...@@ -3,6 +3,7 @@ package ai.qiwu.com.xiaoduhome.common.temple.onLunch; ...@@ -3,6 +3,7 @@ package ai.qiwu.com.xiaoduhome.common.temple.onLunch;
import ai.qiwu.com.xiaoduhome.common.temple.TempleUtils; import ai.qiwu.com.xiaoduhome.common.temple.TempleUtils;
import ai.qiwu.com.xiaoduhome.pojo.dpl.Event; import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
import ai.qiwu.com.xiaoduhome.service.ScheduleService; import ai.qiwu.com.xiaoduhome.service.ScheduleService;
import ai.qiwu.com.xiaoduhome.service.ScheduleServiceNew;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.*; import java.util.*;
...@@ -21,26 +22,53 @@ public class LunchUtils { ...@@ -21,26 +22,53 @@ public class LunchUtils {
private static final LunchPojo LUNCH_LOGO_IMG = buildLogoImage(); private static final LunchPojo LUNCH_LOGO_IMG = buildLogoImage();
private static final LunchPojo LUNCH_HSITORY_IMG = buildHistoryImg(); private static final LunchPojo LUNCH_HSITORY_IMG = buildHistoryImg();
private static final LunchPojo LUNCH_COLLECT_IMG = buildCollectImg(); private static final LunchPojo LUNCH_COLLECT_IMG = buildCollectImg();
private volatile static LunchDocument lunchDocument = buildLunchDocument(); private volatile static LunchDocument lunchDocument = buildLunchNewDocument();
public static LunchDocument buildLunchDocument() {
private static LunchDocument buildLunchNewDocument() {
LunchDocument document = new LunchDocument(); LunchDocument document = new LunchDocument();
document.setDuration(240000); document.setDuration(240000);
LunchMainTemplate mainTemplate = new LunchMainTemplate(); LunchMainTemplate mainTemplate = new LunchMainTemplate();
document.setMainTemplate(mainTemplate); document.setMainTemplate(mainTemplate);
LunchPojo conRecommend = buildLunchList(TempleUtils.buildDataList(ScheduleService.getRecommendList(),1)); int size = ScheduleServiceNew.allProjects.size();
conRecommend.setFirstItem(Collections.singletonList(TempleUtils.getFrameRecommand())); int rows = size/4 + (size%4 == 0?0:1);
conRecommend.setMarginTop("8dp"); int i = 0;
List<LunchPojo> list = new ArrayList<>();
LunchPojo rowCon;
int begin, end;
while (i < rows) {
begin = i*4;
end = begin+4 > size ? size : begin+4;
rowCon = buildLunchList(TempleUtils.buildDataList(ScheduleServiceNew.allProjects.subList(begin, end),begin+1));
list.add(rowCon);
i++;
}
LunchPojo scroll = buildLunchScroll();
scroll.setItems(list);
mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,LUNCH_LOGO_IMG,LUNCH_HSITORY_IMG,LUNCH_COLLECT_IMG,scroll));
return document;
}
public static LunchDocument buildLunchDocument() {
LunchDocument document = new LunchDocument();
document.setDuration(240000);
LunchMainTemplate mainTemplate = new LunchMainTemplate();
document.setMainTemplate(mainTemplate);
LunchPojo conRanking = buildLunchList(TempleUtils.buildDataList(ScheduleService.getRankingList(), 9)); // LunchPojo conRecommend = buildLunchList(TempleUtils.buildDataList(ScheduleService.getRecommendList(),1));
conRanking.setFirstItem(Collections.singletonList(TempleUtils.getFrameRakking())); // conRecommend.setFirstItem(Collections.singletonList(TempleUtils.getFrameRecommand()));
// conRecommend.setMarginTop("8dp");
//
// LunchPojo conRanking = buildLunchList(TempleUtils.buildDataList(ScheduleService.getRankingList(), 9));
// conRanking.setFirstItem(Collections.singletonList(TempleUtils.getFrameRakking()));
LunchPojo conCategory = buildLunchCategoryList(TempleUtils.buildCategoryDataList()); LunchPojo conCategory = buildLunchCategoryList(TempleUtils.buildCategoryDataList());
conCategory.setFirstItem(Collections.singletonList(TempleUtils.getFrameCategory())); conCategory.setFirstItem(Collections.singletonList(TempleUtils.getFrameCategory()));
LunchPojo scroll = buildLunchScroll(); LunchPojo scroll = buildLunchScroll();
scroll.setItems(Arrays.asList(conRecommend,conRanking,conCategory)); // scroll.setItems(Arrays.asList(conRecommend,conRanking,conCategory));
mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,LUNCH_LOGO_IMG,LUNCH_HSITORY_IMG,LUNCH_COLLECT_IMG,scroll)); mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,LUNCH_LOGO_IMG,LUNCH_HSITORY_IMG,LUNCH_COLLECT_IMG,scroll));
return document; return document;
......
package ai.qiwu.com.xiaoduhome.common.temple.play; package ai.qiwu.com.xiaoduhome.common.temple.play;
import ai.qiwu.com.xiaoduhome.pojo.ActorWithWord;
import ai.qiwu.com.xiaoduhome.pojo.dpl.Event; import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
import ai.qiwu.com.xiaoduhome.pojo.playAside.PlayPageData; import ai.qiwu.com.xiaoduhome.pojo.playAside.PlayPageData;
import ai.qiwu.com.xiaoduhome.service.ScheduleService; import ai.qiwu.com.xiaoduhome.service.ScheduleService;
import com.baidu.dueros.data.response.directive.audioplayer.Play;
import java.util.*; import java.util.*;
...@@ -22,7 +22,7 @@ public class PlayUtils { ...@@ -22,7 +22,7 @@ public class PlayUtils {
private static final PlayPojo PLAY_LIST_ITEM = buildContent(); private static final PlayPojo PLAY_LIST_ITEM = buildContent();
public static PlayDocument getPlayDocument(String headerName, List<String> actors, String[] actorWord, public static PlayDocument getPlayDocument(String headerName, List<ActorWithWord> aws,
String audio, String botAccount) { String audio, String botAccount) {
PlayDocument document = new PlayDocument(); PlayDocument document = new PlayDocument();
document.setDuration(110000); document.setDuration(110000);
...@@ -30,10 +30,9 @@ public class PlayUtils { ...@@ -30,10 +30,9 @@ public class PlayUtils {
document.setMainTemplate(mainTemplate); document.setMainTemplate(mainTemplate);
List<PlayPageData> dataList = new ArrayList<>(); List<PlayPageData> dataList = new ArrayList<>();
int i = 0; for (ActorWithWord aw: aws) {
for (String actor: actors) { PlayPageData data = new PlayPageData(aw.getActor(), ScheduleService.getAsideImgUrl(botAccount, aw.getActor()),
PlayPageData data = new PlayPageData(actor, ScheduleService.getAsideImgUrl(botAccount, actor), aw.getText().replaceAll("<br>","\n"));
actorWord[i++].replaceAll("<br>","\n"));
dataList.add(data); dataList.add(data);
} }
......
...@@ -8,6 +8,7 @@ import com.alibaba.da.coin.ide.spi.trans.MetaFormat; ...@@ -8,6 +8,7 @@ import com.alibaba.da.coin.ide.spi.trans.MetaFormat;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -27,6 +28,9 @@ public class SpiritController { ...@@ -27,6 +28,9 @@ public class SpiritController {
this.spiritService = spiritService; this.spiritService = spiritService;
} }
@Value("${num}")
private String num;
/** /**
* 利用天猫精灵打开发包解析请求并从构造响应数据返回 * 利用天猫精灵打开发包解析请求并从构造响应数据返回
* @param taskQuery 请求的参数信息 * @param taskQuery 请求的参数信息
...@@ -39,7 +43,7 @@ public class SpiritController { ...@@ -39,7 +43,7 @@ public class SpiritController {
// build response // build response
ResultModel<TaskResult> resultModel = new ResultModel<>(); ResultModel<TaskResult> resultModel = new ResultModel<>();
TaskResult taskResult = spiritService.getResponse(query, 1); TaskResult taskResult = spiritService.getResponse(query, 4);
resultModel.setReturnCode("0"); resultModel.setReturnCode("0");
resultModel.setReturnValue(taskResult); resultModel.setReturnValue(taskResult);
// log.info("天猫响应信息:"+ JSON.toJSONString(resultModel)); // log.info("天猫响应信息:"+ JSON.toJSONString(resultModel));
...@@ -107,4 +111,13 @@ public class SpiritController { ...@@ -107,4 +111,13 @@ public class SpiritController {
return resultModel; return resultModel;
} }
@PostMapping("/update/{one}")
public void updateCsvMap(@RequestBody String secId, @PathVariable String one) {
if ("qiwuAudioMqw123.".equals(secId)) {
if (one.equals(num)) {
spiritService.updateSpiritCsv();
}
}
}
} }
...@@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @author 苗权威 * @author 苗权威
* @dateTime 19-11-18 下午6:37 * @dateTime 19-11-18 下午6:37
*/ */
//@Controller @Controller
@Slf4j @Slf4j
public class WebSocketLogController { public class WebSocketLogController {
......
...@@ -6,6 +6,7 @@ import ai.qiwu.com.xiaoduhome.xiaoai.model.response.XiaoAiResponse; ...@@ -6,6 +6,7 @@ import ai.qiwu.com.xiaoduhome.xiaoai.model.response.XiaoAiResponse;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.Response; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.Response;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.toSpeak.ToSpeak; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.toSpeak.ToSpeak;
import ai.qiwu.com.xiaoduhome.xiaoai.service.XiaoAiService; import ai.qiwu.com.xiaoduhome.xiaoai.service.XiaoAiService;
import ai.qiwu.com.xiaoduhome.xiaoai.service.XiaoAiServiceRedis;
import ai.qiwu.com.xiaoduhome.xiaoai.service.XiaoAiTestService; import ai.qiwu.com.xiaoduhome.xiaoai.service.XiaoAiTestService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -34,6 +35,7 @@ public class XiaoAiController { ...@@ -34,6 +35,7 @@ public class XiaoAiController {
private final XiaoAiService xiaoAiService; private final XiaoAiService xiaoAiService;
private final XiaoAiTestService xiaoAiTestService; private final XiaoAiTestService xiaoAiTestService;
private final XiaoAiServiceRedis xiaoAiServiceRedis;
/** /**
* Controller控制器 * Controller控制器
...@@ -94,7 +96,7 @@ public class XiaoAiController { ...@@ -94,7 +96,7 @@ public class XiaoAiController {
log.info("请求:"+str); log.info("请求:"+str);
XiaoAiRequest request = JSON.parseObject(str, XiaoAiRequest.class); XiaoAiRequest request = JSON.parseObject(str, XiaoAiRequest.class);
request.setType(5); request.setType(5);
XiaoAiResponse response = xiaoAiTestService.getResponse(request); XiaoAiResponse response = xiaoAiServiceRedis.getResponse(request);
log.info("响应:"+response); log.info("响应:"+response);
return response; return response;
} catch (Exception e) { } catch (Exception e) {
...@@ -110,6 +112,33 @@ public class XiaoAiController { ...@@ -110,6 +112,33 @@ public class XiaoAiController {
// return xiaoAiService.getResponse(request); // return xiaoAiService.getResponse(request);
} }
@PostMapping("/phone") //互动故事
// @RequestBody XiaoAiRequest request,
public XiaoAiResponse xiaoaiPhoneStory(HttpServletRequest servletRequest) {
// long start = System.currentTimeMillis();
// if (!Utils.encry(3, servletRequest)) return null;
// log.info("encry:"+(System.currentTimeMillis()-start));
try (InputStream stream = servletRequest.getInputStream()){
StringBuilder sb = new StringBuilder();
byte[] b = new byte[4096];
for (int n; (n = stream.read(b)) != -1;)
{
sb.append(new String(b, 0, n));
}
String str = sb.toString();
log.info("请求:"+str);
XiaoAiRequest request = JSON.parseObject(str, XiaoAiRequest.class);
request.setType(5);
XiaoAiResponse response = xiaoAiTestService.getResponse(request);
log.info("响应:"+response);
return response;
} catch (Exception e) {
}
return null;
}
@PostMapping("/adult") @PostMapping("/adult")
public XiaoAiResponse xiaoaiAdult(@RequestBody XiaoAiRequest request, HttpServletRequest servletRequest) { // 智能小说 public XiaoAiResponse xiaoaiAdult(@RequestBody XiaoAiRequest request, HttpServletRequest servletRequest) { // 智能小说
//log.info("请求:"+request); //log.info("请求:"+request);
...@@ -141,8 +170,8 @@ public class XiaoAiController { ...@@ -141,8 +170,8 @@ public class XiaoAiController {
@GetMapping("/audio/play") @GetMapping("/audio/play")
public void xiaoaiPlayed(String userId) { public void xiaoaiPlayed(String userId) {
if (StringUtils.isNotBlank(userId)) { if (StringUtils.isNotBlank(userId)) {
// log.info("小爱确认音频播放:"+userId); log.info("小爱确认音频播放:"+userId);
// xiaoAiService.changeAudioPlayMark(userId); xiaoAiServiceRedis.theAudioAlreadyPlay(userId);
} }
else log.error("/xiaoai/audio/play userId is null"); else log.error("/xiaoai/audio/play userId is null");
} }
......
package ai.qiwu.com.xiaoduhome.controller; package ai.qiwu.com.xiaoduhome.controller;
import ai.qiwu.com.xiaoduhome.common.Utils; import ai.qiwu.com.xiaoduhome.common.Utils;
import ai.qiwu.com.xiaoduhome.pojo.OverTimeDetail;
import ai.qiwu.com.xiaoduhome.service.DplBotRedisService;
import ai.qiwu.com.xiaoduhome.service.DplBotService; import ai.qiwu.com.xiaoduhome.service.DplBotService;
import ai.qiwu.com.xiaoduhome.service.ResponseEncapsulation; import ai.qiwu.com.xiaoduhome.service.ResponseEncapsulation;
import ai.qiwu.com.xiaoduhome.spirit.SpiritService; import ai.qiwu.com.xiaoduhome.spirit.SpiritService;
...@@ -15,6 +17,8 @@ import com.fasterxml.jackson.databind.exc.MismatchedInputException; ...@@ -15,6 +17,8 @@ import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -41,6 +45,13 @@ public class XiaoDuHomeController { ...@@ -41,6 +45,13 @@ public class XiaoDuHomeController {
private int test = 0; private int test = 0;
private final StringRedisTemplate stringRedisTemplate;
@Autowired
public XiaoDuHomeController(StringRedisTemplate stringRedisTemplate) {
this.stringRedisTemplate = stringRedisTemplate;
}
@RequestMapping(value = "/chat", method = RequestMethod.HEAD) @RequestMapping(value = "/chat", method = RequestMethod.HEAD)
public void chatHead(HttpServletResponse response) { public void chatHead(HttpServletResponse response) {
// if (test++ < 5) { // if (test++ < 5) {
...@@ -104,16 +115,17 @@ public class XiaoDuHomeController { ...@@ -104,16 +115,17 @@ public class XiaoDuHomeController {
} }
@PostMapping("/story") //交互故事 @PostMapping("/story") //交互故事
public String story() { public String story(HttpServletRequest request) {
try { try {
//log.info("--------------分界线-------------------"); //log.info("--------------分界线-------------------");
DplBotService service = new DplBotService(Utils.getHttpServletRequest(), 5); // DplBotService service = new DplBotService(Utils.getHttpServletRequest(), 5);
// log.info("请求信息中的attributes:{}", service.getRequest().getSession().getAttributes()); // log.info("请求信息中的attributes:{}", service.getRequest().getSession().getAttributes());
log.info(service.getStrRequest()); DplBotRedisService service = new DplBotRedisService(request, 5, stringRedisTemplate);
// log.info(service.getStrRequest());
//service.disableVerify(); //service.disableVerify();
service.enableVerify(); service.enableVerify();
String str = service.run(); String str = service.run();
log.info("响应信息:{}", str); // log.info("响应信息:{}", str);
return str; return str;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
package ai.qiwu.com.xiaoduhome.pojo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author 苗权威
* @dateTime 20-1-17 下午2:40
*/
@Getter
@Setter
@ToString
public class ActorWithWord {
private String actor;
private String text;
}
...@@ -5,7 +5,9 @@ import com.baidu.dueros.model.Response; ...@@ -5,7 +5,9 @@ import com.baidu.dueros.model.Response;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -17,8 +19,11 @@ import java.util.Map; ...@@ -17,8 +19,11 @@ import java.util.Map;
*/ */
@Getter @Getter
@Setter @Setter
public class OverTimeDetail { @ToString
public class OverTimeDetail implements Serializable {
private static final long serialVersionUID = 1L;
private final List<Directive> directives = new ArrayList<>(); private final List<Directive> directives = new ArrayList<>();
private final Map<String, String> attributes = new HashMap<>(); private final Map<String, String> attributes = new HashMap<>();
private volatile Response response = new Response(); private volatile Response response;
} }
package ai.qiwu.com.xiaoduhome.pojo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author 苗权威
* @dateTime 20-1-17 下午7:45
*/
@Getter
@Setter
@ToString
public class SendFlowerVO {
private String botAccount;
private Long num;
private Double unitPrice;
private String userId;
private String name;
private String channelId;
private Long orderId;
}
...@@ -6,6 +6,7 @@ import lombok.ToString; ...@@ -6,6 +6,7 @@ import lombok.ToString;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author 苗权威 * @author 苗权威
...@@ -16,11 +17,11 @@ import java.util.List; ...@@ -16,11 +17,11 @@ import java.util.List;
@ToString @ToString
public class UserBehaviorData { public class UserBehaviorData {
// 用户浏览历史 // 用户浏览历史
private volatile HashMap<String, Long> userBotId2History = new HashMap<>(); private volatile Map<String, Long> userBotId2History = new HashMap<>();
// 用户对作品所送花的数目 // 用户对作品所送花的数目
private volatile HashMap<String, Long> userBotId2Flowers = new HashMap<>(); private volatile Map<String, Long> userBotId2Flowers = new HashMap<>();
// 用户是否收藏该作品 // 用户是否收藏该作品
private volatile HashMap<String, Long> userBotId2Collected = new HashMap<>(); private volatile Map<String, Long> userBotId2Collected = new HashMap<>();
// 标记清除,每半小时标记一次 // 标记清除,每半小时标记一次
private volatile Byte mark = 1; private volatile Byte mark = 1;
......
package ai.qiwu.com.xiaoduhome.pojo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author 苗权威
* @dateTime 20-1-13 下午1:35
*/
@Getter
@Setter
@ToString
public class XiaoDuNoScreenStore {
private volatile String audio;
private volatile String noPlay;
}
package ai.qiwu.com.xiaoduhome.pojo.data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.sql.Timestamp;
import java.util.List;
/**
* @author 苗权威
* @dateTime 20-1-15 下午8:30
*/
@Getter
@Setter
@ToString
public class ProjectData {
private String name;
private String intro;
private String authorName;
private Boolean free;
private String botAccount;
private String bannerImgUrl;
private Timestamp createTime;
private List<String> labels;
}
...@@ -24,6 +24,8 @@ public interface XiaoDuOrderTbRepository extends JpaRepository<XiaoDuOrderTB, Lo ...@@ -24,6 +24,8 @@ public interface XiaoDuOrderTbRepository extends JpaRepository<XiaoDuOrderTB, Lo
@Override @Override
<S extends XiaoDuOrderTB> S saveAndFlush(S s); <S extends XiaoDuOrderTB> S saveAndFlush(S s);
XiaoDuOrderTB getByChOrderId (String chOrderId);
@Modifying @Modifying
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Query(value = "UPDATE xiaodu_order_tb SET order_id=?1,status=1,update_time=now() WHERE ch_order_id=?2",nativeQuery = true) @Query(value = "UPDATE xiaodu_order_tb SET order_id=?1,status=1,update_time=now() WHERE ch_order_id=?2",nativeQuery = true)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,27 +2,15 @@ package ai.qiwu.com.xiaoduhome.service; ...@@ -2,27 +2,15 @@ package ai.qiwu.com.xiaoduhome.service;
import ai.qiwu.com.xiaoduhome.common.Constants; import ai.qiwu.com.xiaoduhome.common.Constants;
import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils; import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.common.Utils;
import ai.qiwu.com.xiaoduhome.pojo.QiWuRequest; import ai.qiwu.com.xiaoduhome.pojo.QiWuRequest;
import ai.qiwu.com.xiaoduhome.pojo.QiWuResponse; import ai.qiwu.com.xiaoduhome.pojo.QiWuResponse;
import ai.qiwu.com.xiaoduhome.pojo.playAside.AsideImageResponse; import ai.qiwu.com.xiaoduhome.pojo.playAside.AsideImageResponse;
import ai.qiwu.com.xiaoduhome.spirit.SpiritTerminateRequest; import ai.qiwu.com.xiaoduhome.spirit.SpiritTerminateRequest;
import ai.qiwu.com.xiaoduhome.xiaoai.common.XiaoAiConstants;
import ai.qiwu.com.xiaoduhome.xiaoai.service.XiaoAiService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random;
/** /**
* @author 苗权威 * @author 苗权威
...@@ -64,8 +52,8 @@ class RequestTerminal { ...@@ -64,8 +52,8 @@ class RequestTerminal {
// case 4 : headers.put("App-Channel-Id", "jiaoyou-audio-adult-test");break; // case 4 : headers.put("App-Channel-Id", "jiaoyou-audio-adult-test");break;
// default: headers.put("App-Channel-Id", "jiaoyou-audio-test"); // default: headers.put("App-Channel-Id", "jiaoyou-audio-test");
// } // }
return OkHttp3Utils.doPostJsonStr(Constants.QI_WU_INTERFACE, requestJsonStr, headers); // return OkHttp3Utils.doPostJsonStr(Constants.QI_WU_INTERFACE, requestJsonStr, headers);
// return OkHttp3Utils.doPostJsonStr("http://didi-gz5.jiaoyou365.com:8070/api/chat2", requestJsonStr, headers); return OkHttp3Utils.doPostJsonStr("http://didi-gz5.jiaoyou365.com:8070/api/chat2", requestJsonStr, headers);
} }
static QiWuResponse requestTerminate(String userWord, String userId, int type) throws IOException { static QiWuResponse requestTerminate(String userWord, String userId, int type) throws IOException {
...@@ -117,8 +105,8 @@ class RequestTerminal { ...@@ -117,8 +105,8 @@ class RequestTerminal {
requestPojo.setUid(userId); requestPojo.setUid(userId);
requestPojo.setMsg("退出"); requestPojo.setMsg("退出");
String requestJsonStr = JSON.toJSONString(requestPojo); String requestJsonStr = JSON.toJSONString(requestPojo);
// OkHttp3Utils.backPostAsync("http://didi-gz5.jiaoyou365.com:8070/api/chat2", requestJsonStr, type); OkHttp3Utils.backPostAsync("http://didi-gz5.jiaoyou365.com:8070/api/chat2", requestJsonStr, type);
OkHttp3Utils.backPostAsync(Constants.QI_WU_INTERFACE, requestJsonStr, type); // OkHttp3Utils.backPostAsync(Constants.QI_WU_INTERFACE, requestJsonStr, type);
} }
static void backRequestDU2(String userId, int type) { static void backRequestDU2(String userId, int type) {
......
...@@ -106,8 +106,36 @@ public class ScheduleService implements InitializingBean { ...@@ -106,8 +106,36 @@ public class ScheduleService implements InitializingBean {
// }); // });
// } // }
@Scheduled(cron = "0 */30 * * * ?") @Scheduled(cron = "0 0 17 * * ?")
public void cleatUserBehaviorData() { public void initAllOnTableProductInfo() {
new Thread(() -> {
ALL_ON_PRODUCT = allOnProductInfoRepository.findAllByApplyStatusAndScoreNot(1, 0f);
allProductCount = ALL_ON_PRODUCT.size();
rankPageSize = allProductCount / RE_RA_CA_PAGE_SIZE + (allProductCount%RE_RA_CA_PAGE_SIZE == 0 ? 0:1);
TreeMap<Long, OnProductDetail> rankOrder = new TreeMap<>((o1, o2) -> o1-o2 < 0 ? 1 :(o1.equals(o2) ? 0 : -1));
HashMap<String, OnProductDetail> nd = new HashMap<>();
HashMap<String, OnProductDetail> id = new HashMap<>();
for (OnProductDetail item : ALL_ON_PRODUCT) {
String productName = item.getName();
String botAccount = item.getBotAccount();
List<String> labels = projectLabelRepository.productLabels(item.getId());
//PRODUCT_LABELS.put(productName, labels);
item.setLabels(labels);
nd.put(productName, item);
id.put(botAccount, item);
rankOrder.put(item.getWatch(), item);
}
PRODUCT_NAME_DETAIL = nd;
PRODUCT_ID_DETAIL = id;
RANK_ORDER_IDs = new ArrayList<>(rankOrder.values());
RecommendUtil.setRankDocument(null);
//log.info("作品详细信息:{}", PRODUCT_NAME_DETAIL);
}).start();
//log.error("更新推荐页出错:{}", e.getMessage());
}
@Scheduled(cron = "0 * */1 * * ?")
public void clearUserBehaviorData() {
DplbotServiceUtil.POOL.submit(() -> { DplbotServiceUtil.POOL.submit(() -> {
List<String> needClear = new ArrayList<>(); List<String> needClear = new ArrayList<>();
for (String userId: DplbotServiceUtil.USER_HISTORY.keySet()) { for (String userId: DplbotServiceUtil.USER_HISTORY.keySet()) {
...@@ -116,25 +144,6 @@ public class ScheduleService implements InitializingBean { ...@@ -116,25 +144,6 @@ public class ScheduleService implements InitializingBean {
if (data.getMark() == 1) data.setMark((byte) 0); if (data.getMark() == 1) data.setMark((byte) 0);
else { else {
needClear.add(userId); needClear.add(userId);
XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
for (Map.Entry<String, Long> entry: data.getUserBotId2History().entrySet()) {
String botId = entry.getKey();
Long time = entry.getValue();
XiaoDuHistoryTB historyTB = repository.getByXiaoduUserIdAndBotId(userId, botId);
if (historyTB == null) {
historyTB = new XiaoDuHistoryTB();
historyTB.setLastTime(time);
historyTB.setBotId(botId);
historyTB.setXiaoduUserId(userId);
} else {
if (historyTB.getLastTime().equals(time)) continue;
historyTB.setLastTime(time);
}
repository.save(historyTB);
}
data.setUserBotId2Collected(null);
data.setUserBotId2Flowers(null);
data.setUserBotId2History(null);
} }
} }
} }
...@@ -142,12 +151,12 @@ public class ScheduleService implements InitializingBean { ...@@ -142,12 +151,12 @@ public class ScheduleService implements InitializingBean {
}); });
} }
// @Scheduled(cron = "*/10 * * * * ?") @Scheduled(cron = "*/30 * * * * ?")
public void updateTheCurTime() { public void updateTheCurTime() {
DplbotServiceUtil.POOL.submit(() -> curTime = System.currentTimeMillis()); DplbotServiceUtil.POOL.submit(() -> curTime = System.currentTimeMillis());
} }
@Scheduled(cron = "0 0 19 * * ?") // @Scheduled(cron = "0 0 19 * * ?")
public void initRankingList() { public void initRankingList() {
new Thread(() -> { new Thread(() -> {
RANKING_LIST = gameProjectTbRepository.findFirst8(); RANKING_LIST = gameProjectTbRepository.findFirst8();
...@@ -157,7 +166,7 @@ public class ScheduleService implements InitializingBean { ...@@ -157,7 +166,7 @@ public class ScheduleService implements InitializingBean {
//log.error("更新排行榜出错:{}", e.getMessage()); //log.error("更新排行榜出错:{}", e.getMessage());
} }
@Scheduled(cron = "0 0 */2 * * ?") // @Scheduled(cron = "0 0 */2 * * ?")
public void initRecommendList() { public void initRecommendList() {
new Thread(() -> { new Thread(() -> {
RECOMMEND_LIST = gameProjectTbRepository.recommendList(); RECOMMEND_LIST = gameProjectTbRepository.recommendList();
...@@ -167,34 +176,6 @@ public class ScheduleService implements InitializingBean { ...@@ -167,34 +176,6 @@ public class ScheduleService implements InitializingBean {
//log.error("更新推荐页出错:{}", e.getMessage()); //log.error("更新推荐页出错:{}", e.getMessage());
} }
@Scheduled(cron = "0 0 17 * * ?")
public void initAllOnTableProductInfo() {
new Thread(() -> {
ALL_ON_PRODUCT = allOnProductInfoRepository.findAllByApplyStatusAndScoreNot(1, 0f);
allProductCount = ALL_ON_PRODUCT.size();
rankPageSize = allProductCount / RE_RA_CA_PAGE_SIZE + (allProductCount%RE_RA_CA_PAGE_SIZE == 0 ? 0:1);
TreeMap<Long, OnProductDetail> rankOrder = new TreeMap<>((o1, o2) -> o1-o2 < 0 ? 1 :(o1.equals(o2) ? 0 : -1));
HashMap<String, OnProductDetail> nd = new HashMap<>();
HashMap<String, OnProductDetail> id = new HashMap<>();
for (OnProductDetail item : ALL_ON_PRODUCT) {
String productName = item.getName();
String botAccount = item.getBotAccount();
List<String> labels = projectLabelRepository.productLabels(item.getId());
//PRODUCT_LABELS.put(productName, labels);
item.setLabels(labels);
nd.put(productName, item);
id.put(botAccount, item);
rankOrder.put(item.getWatch(), item);
}
PRODUCT_NAME_DETAIL = nd;
PRODUCT_ID_DETAIL = id;
RANK_ORDER_IDs = new ArrayList<>(rankOrder.values());
RecommendUtil.setRankDocument(null);
//log.info("作品详细信息:{}", PRODUCT_NAME_DETAIL);
}).start();
//log.error("更新推荐页出错:{}", e.getMessage());
}
@Scheduled(cron = "0 0 1 * * ?") @Scheduled(cron = "0 0 1 * * ?")
public void initProductList() { public void initProductList() {
new Thread(() -> { new Thread(() -> {
......
package ai.qiwu.com.xiaoduhome.service;
import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.pojo.data.ProjectData;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author 苗权威
* @dateTime 20-1-15 下午8:24
*/
@Slf4j
@Component
public class ScheduleServiceNew implements InitializingBean {
public static volatile List<ProjectData> allProjects = new ArrayList<>();
private static volatile Map<String, ProjectData> botAccount2Project = new HashMap<>();
private static volatile Map<String, ProjectData> name2Project = new HashMap<>();
private static volatile Map<String, Map<String, Long>> channel2BotAccountList = new HashMap<>();
@Override
public void afterPropertiesSet() throws Exception {
getAllProjects();
}
private void getAllProjects() {
new Thread(() -> {
try {
String response = OkHttp3Utils.doGet(DplbotServiceUtil.HOST_UTL+"/audio_box/project");
if (StringUtils.isNotBlank(response)) {
JSONObject object = JSON.parseObject(response);
List<ProjectData> list = object.getObject("bots", List.class);
Map<String, Map<String, Long>> map = object.getObject("channelAcc", Map.class);
if (!CollectionUtils.isEmpty(list)) {
final Map<String, ProjectData> botAcc = new HashMap<>();
final Map<String, ProjectData> name = new HashMap<>();
list.forEach(projectData -> {
botAcc.put(projectData.getBotAccount(), projectData);
name.put(projectData.getName(), projectData);
});
botAccount2Project = botAcc;
name2Project = name;
allProjects = list;
}
if (!CollectionUtils.isEmpty(map)) {
channel2BotAccountList = map;
}
}
} catch (Exception e) {
log.warn("ScheduleServiceNew#getAllProjects获取所有作品信息失败:"+e);
}
}).start();
}
static ProjectData getProjectByName(String name) {
return name2Project.get(name);
}
static ProjectData getProjectByBotAccount(String botAccount) {
return botAccount2Project.get(botAccount);
}
public static List<ProjectData> getTheChannelAllProjectData(String channel) {
return channel2BotAccountList.get(channel).keySet().stream().map(s -> botAccount2Project.get(s)).collect(Collectors.toList());
}
public static List<ProjectData> getTheChannelProjectsByWatch(String channel) {
TreeMap<Long, String> order = new TreeMap<>(Comparator.reverseOrder());
channel2BotAccountList.get(channel).forEach((key, value) -> order.put(value, key));
List<ProjectData> datas = new ArrayList<>();
for (String botAcc: order.values()) {
datas.add(botAccount2Project.get(botAcc));
}
return datas;
}
}
...@@ -30,8 +30,13 @@ public class InitialData implements InitializingBean { ...@@ -30,8 +30,13 @@ public class InitialData implements InitializingBean {
@Value("${csvDic}") @Value("${csvDic}")
private String csvDic; private String csvDic;
private static volatile Map<String, Map<String, Map<String, String>>> recordMap; @Value("${csvChildDic}")
private static volatile Map<String, Map<String, Map<String, Map<String, String>>>> audioMap; private String csvChildDic;
static volatile Map<String, Map<String, Map<String, String>>> recordMap;
static volatile Map<String, Map<String, Map<String, String>>> childRecordMap;
static volatile Map<String, Map<String, Map<String, Map<String, String>>>> audioMap;
static volatile Map<String, Map<String, Map<String, Map<String, String>>>> childAudioMap;
static volatile Map<String, Boolean> botAccount2ItsCache; static volatile Map<String, Boolean> botAccount2ItsCache;
static { static {
...@@ -106,6 +111,71 @@ public class InitialData implements InitializingBean { ...@@ -106,6 +111,71 @@ public class InitialData implements InitializingBean {
} catch (Exception e) { } catch (Exception e) {
log.error(e.toString()); log.error(e.toString());
} }
try {
File[] csvFiles = new File(csvChildDic).listFiles((dir, name) -> StringUtils.endsWith(name, ".csv"));
if (csvFiles != null && csvFiles.length != 0) {
CSVParser reader;
for (File file: csvFiles) {
String fileName = file.getName();
int i = fileName.indexOf("_");
String botAccount = fileName.substring(0, i);
boolean record = Integer.valueOf(fileName.substring(i+1, i+2)) == 1;
reader = CSVFormat.EXCEL.parse(new BufferedReader(new InputStreamReader(
new FileInputStream(file), Charset.forName("UTF-8"))));
if (record) {
if (childRecordMap.containsKey(botAccount)) {
log.error("重复:{}",fileName);
continue;
}
Map<String, Map<String, String>> npcName2nameId = childRecordMap.computeIfAbsent(botAccount, s -> new HashMap<>());
int j = 0;
// "person", "mood", "md5", "id", "upUrl"
for (CSVRecord line: reader) {
if (j == 0) {
j++;
continue;
}
String npcName = line.get(0);
String md5 = line.get(2);
md5 = md5.substring(0, md5.indexOf("."));
String id = line.get(3);
Map<String, String> mp3Name2Id = npcName2nameId.computeIfAbsent(npcName, s -> new HashMap<>());
mp3Name2Id.put(md5, id);
}
botAccount2ItsCache.put(botAccount, true);
} else {
if (childAudioMap.containsKey(botAccount)) {
log.error("重复:{}",fileName);
continue;
}
Map<String, Map<String, Map<String, String>>> person2toneMd5Id = childAudioMap.computeIfAbsent(botAccount, s -> new HashMap<>());
int j = 0;
for (CSVRecord line: reader) {
if (j == 0) {
j++;
continue;
}
String person = line.get(0);
String mood = line.get(1);
String md5 = line.get(2);
if (StringUtils.endsWith(md5, ".wav")) continue;
md5 = md5.substring(0, md5.indexOf("."));
String id = line.get(3);
Map<String, Map<String, String>> tone2Md5Id = person2toneMd5Id.computeIfAbsent(person, s -> new HashMap<>());
Map<String, String> md52Id = tone2Md5Id.computeIfAbsent(mood, s -> new HashMap<>());
md52Id.put(md5, id);
}
botAccount2ItsCache.put(botAccount, false);
}
reader.close();
}
} else {
log.warn("没有数据文件");
}
} catch (Exception e) {
log.error(e.toString());
}
} }
static String getRecordId(String botAccount, String npcName, String text) { static String getRecordId(String botAccount, String npcName, String text) {
......
...@@ -54,7 +54,8 @@ public class RequestTerminal { ...@@ -54,7 +54,8 @@ public class RequestTerminal {
case 2: headers = ADULT_HEADERS; break; case 2: headers = ADULT_HEADERS; break;
default: headers = ALL_HEADERS; break; default: headers = ALL_HEADERS; break;
} }
String resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers);; // String resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers);;
String resStr = OkHttp3Utils.doPostJsonStr("http://didi-gz5.jiaoyou365.com:8070/api/chat2", requestJsonStr, headers);;
// if (userId.equals(XiaoAiService.deviceId)) { // if (userId.equals(XiaoAiService.deviceId)) {
// resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers); // resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers);
// }else { // }else {
......
...@@ -20,7 +20,7 @@ public interface XiaoAiConstants { ...@@ -20,7 +20,7 @@ public interface XiaoAiConstants {
interface ERROR_MSG { interface ERROR_MSG {
String SORRY_REPEAT = "不好意思,请再说一遍吧"; String SORRY_REPEAT = "不好意思,请再说一遍吧";
String TIME_OUT = "请稍等"; String TIME_OUT = "不好意思我没听清,请再说一遍吧";
String TERMINATE_IO_EXCEPTION = "请求终端接口时发生IO错误"; String TERMINATE_IO_EXCEPTION = "请求终端接口时发生IO错误";
String HTTP_CONNECTION_CLOSE_EXCEPTION = "关闭与终端接口链接时出错"; String HTTP_CONNECTION_CLOSE_EXCEPTION = "关闭与终端接口链接时出错";
} }
......
package ai.qiwu.com.xiaoduhome.xiaoai.model.response; package ai.qiwu.com.xiaoduhome.xiaoai.model.response;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.Response; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.Response;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
...@@ -14,6 +15,7 @@ import java.util.Map; ...@@ -14,6 +15,7 @@ import java.util.Map;
@Getter @Getter
@Setter @Setter
@ToString @ToString
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class XiaoAiResponse { public class XiaoAiResponse {
private String version; private String version;
private Map<String, String> session_attributes; private Map<String, String> session_attributes;
......
...@@ -5,6 +5,7 @@ import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.Dire ...@@ -5,6 +5,7 @@ import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.Dire
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.registerEvent.RegisterEvent; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.registerEvent.RegisterEvent;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.toDisplay.ToDisplay; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.toDisplay.ToDisplay;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.toSpeak.ToSpeak; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.toSpeak.ToSpeak;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
...@@ -18,6 +19,7 @@ import java.util.List; ...@@ -18,6 +19,7 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
@ToString @ToString
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class Response { public class Response {
private ToSpeak to_speak; private ToSpeak to_speak;
private ToDisplay to_display; private ToDisplay to_display;
......
package ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.actionProperty; package ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.actionProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
...@@ -13,6 +14,11 @@ import java.util.List; ...@@ -13,6 +14,11 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
@ToString @ToString
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class ActionProperty { public class ActionProperty {
private List<Long> file_id_list; private List<Long> file_id_list;
private AppIntentInfo app_intent_info;
private String app_h5_url;
private String quick_app_path;
} }
package ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.actionProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author 苗权威
* @dateTime 20-1-10 下午2:33
*/
@Getter
@Setter
@ToString
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class AppIntentInfo {
private String intent_type;
private String uri;
}
...@@ -18,6 +18,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -18,6 +18,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
...@@ -61,7 +63,7 @@ public class XiaoAiService { ...@@ -61,7 +63,7 @@ public class XiaoAiService {
private static final Byte OUTTIME_TYPE_1 = 1; private static final Byte OUTTIME_TYPE_1 = 1;
private static final Byte OUTTIME_TYPE_2 = 2; private static final Byte OUTTIME_TYPE_2 = 2;
public static final String deviceId = "XIAOAI_nbNGwoZIS8AmRGVqHog==";//XIAOAI_nbNGwoZIS8AmRGVqHog==,XIAOAI_oIOWfYEFbZGFHB5DzoMA== // public static final String deviceId = "XIAOAI_nbNGwoZIS8AmRGVqHog==";//XIAOAI_nbNGwoZIS8AmRGVqHog==,XIAOAI_oIOWfYEFbZGFHB5DzoMA==
/** /**
* 处理不同意图,type为0则说明是启动,为1则说明是会话进行中,为2则说明用户退出 * 处理不同意图,type为0则说明是启动,为1则说明是会话进行中,为2则说明用户退出
...@@ -410,10 +412,6 @@ public class XiaoAiService { ...@@ -410,10 +412,6 @@ public class XiaoAiService {
// return Utils.modifyDeviceId(userId); // return Utils.modifyDeviceId(userId);
} }
private XiaoAiResponse getLastResult(String userId) {
return LAST_OUTTIME_RESULT.remove(userId);
}
private void task(String userId, String userWord, Integer type) { private void task(String userId, String userWord, Integer type) {
XiaoAiResponse xiaoAiResponse; XiaoAiResponse xiaoAiResponse;
if (userWord == null) { if (userWord == null) {
......
...@@ -11,6 +11,8 @@ import ai.qiwu.com.xiaoduhome.xiaoai.common.XiaoAiConstants; ...@@ -11,6 +11,8 @@ import ai.qiwu.com.xiaoduhome.xiaoai.common.XiaoAiConstants;
import ai.qiwu.com.xiaoduhome.xiaoai.model.request.XiaoAiRequest; import ai.qiwu.com.xiaoduhome.xiaoai.model.request.XiaoAiRequest;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.XiaoAiResponse; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.XiaoAiResponse;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.Response; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.Response;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.actionProperty.ActionProperty;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.actionProperty.AppIntentInfo;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.AudioItem.AudioItem; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.AudioItem.AudioItem;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.AudioItem.AudioStream; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.AudioItem.AudioStream;
import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.Directive; import ai.qiwu.com.xiaoduhome.xiaoai.model.response.innerResponse.directive.Directive;
...@@ -72,6 +74,8 @@ public class XiaoAiTestService { ...@@ -72,6 +74,8 @@ public class XiaoAiTestService {
int type = request.getRequest().getType(); int type = request.getRequest().getType();
switch (type) { switch (type) {
case 0 : return dealWithLaunchRequest(request); case 0 : return dealWithLaunchRequest(request);
// case 0 : return dealWithLaunchRequestPhone();
// case 1 : return dealWithLaunchRequestPhone2();
case 1 : return dealWithIntentRequest(request, userId); case 1 : return dealWithIntentRequest(request, userId);
case 2 : return dealWithEndRequest(userId, request.getType()); case 2 : return dealWithEndRequest(userId, request.getType());
default: return buildTextResponse(SORRY_REPEAT); default: return buildTextResponse(SORRY_REPEAT);
...@@ -234,6 +238,70 @@ public class XiaoAiTestService { ...@@ -234,6 +238,70 @@ public class XiaoAiTestService {
return response; return response;
} }
private XiaoAiResponse dealWithLaunchRequestPhone() {
XiaoAiResponse response = new XiaoAiResponse();
response.setVersion("1.0");
response.setIs_session_end(true);
Response responseInfo = new Response();
// 这个字段很重要,他会在播放音频或是tts结束后,开麦收音,因为默认麦是关闭的,
// 若不主动打开则小爱在一次会话后退出技能。
responseInfo.setOpen_mic(false);
responseInfo.setAction("App.LaunchIntent");
ActionProperty actionProperty = new ActionProperty();
AppIntentInfo appIntentInfo = new AppIntentInfo();
appIntentInfo.setIntent_type("activity");
appIntentInfo.setUri("com.qiwu.life.ui.activity.LaunchActivity");
actionProperty.setApp_intent_info(appIntentInfo);
responseInfo.setAction_property(actionProperty);
ToDisplay toDisplay = new ToDisplay();
// toDisplay.setType(3);
toDisplay.setUi_type("phone");
PhoneTemplate phoneTemplate = new PhoneTemplate();
phoneTemplate.setTemplate_name("load");
toDisplay.setPhone_template(phoneTemplate);
responseInfo.setTo_display(toDisplay);
ToSpeak toSpeak = new ToSpeak();
toSpeak.setType(0);
toSpeak.setText("请下载app后体验");
responseInfo.setTo_speak(toSpeak);
response.setResponse(responseInfo);
return response;
}
private XiaoAiResponse dealWithLaunchRequestPhone2() {
XiaoAiResponse response = new XiaoAiResponse();
response.setVersion("1.0");
response.setIs_session_end(true);
Response responseInfo = new Response();
// 这个字段很重要,他会在播放音频或是tts结束后,开麦收音,因为默认麦是关闭的,
// 若不主动打开则小爱在一次会话后退出技能。
responseInfo.setOpen_mic(false);
responseInfo.setAction("App.LaunchIntent");
ActionProperty actionProperty = new ActionProperty();
AppIntentInfo appIntentInfo = new AppIntentInfo();
appIntentInfo.setUri("com.qiwu.life.ui.activity.LaunchActivity");
actionProperty.setApp_intent_info(appIntentInfo);
responseInfo.setAction_property(actionProperty);
ToSpeak toSpeak = new ToSpeak();
toSpeak.setType(0);
toSpeak.setText("请下载app后体验");
responseInfo.setTo_speak(toSpeak);
response.setResponse(responseInfo);
return response;
}
/** /**
* 处理启动意图,返回欢迎语 * 处理启动意图,返回欢迎语
* @param request 请求信息 * @param request 请求信息
......
...@@ -37,6 +37,11 @@ spring: ...@@ -37,6 +37,11 @@ spring:
enabled: detect enabled: detect
thymeleaf: thymeleaf:
cache: false cache: false
redis:
host: localhost
port: 6379
timeout: 1000
logging: logging:
path: /home/dc2-user/projects/audiobox/duai/logs path: /home/dc2-user/projects/audiobox/duai/logs
level: level:
...@@ -45,3 +50,5 @@ logging: ...@@ -45,3 +50,5 @@ logging:
OkHttpClient: FINE OkHttpClient: FINE
csvDic: /home/dc2-user/projects/audiobox/duai/csv/ csvDic: /home/dc2-user/projects/audiobox/duai/csv/
csvChildDic: /home/dc2-user/projects/audiobox/duai/childCsv/
num: 1
\ No newline at end of file
Jfc4Z4Ur15JwUBuvUQD5wg7Nu8+l+HscqYlfofbyJdZjy0poyKQz138bj7SDJK4P
\ No newline at end of file
unitPrice=1 unitPrice=1
requestHost=http://didi-gz4.jiaoyou365.com:18082/
\ No newline at end of file
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