From 7b2df62c78e4b95a58839019ce087d8b9f0e666e Mon Sep 17 00:00:00 2001
From: 苗权威 <1160292058@qq.com>
Date: Mon, 23 Sep 2019 21:02:43 +0800
Subject: [PATCH] 9.23
---
.idea/workspace.xml | 641 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tts_service/src/main/java/ai/qiwu/com/tts_service/common/Config.java | 4 ++--
tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java | 16 +++++++++++++---
tts_service/src/main/resources/application.yml | 8 ++++----
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoDocument.java | 16 ++++++++++++++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoMainTemplate.java | 25 +++++++++++++++++++++++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoPojo.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoUtils.java | 271 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTBTiny.java | 6 +++---
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java | 3 ++-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/UserBehaviorData.java | 10 +++++++++-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/dpl/Event.java | 1 +
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFavoriteTBRepository.java | 2 +-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBTintRepository.java | 4 ++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuHistoryTBRepository.java | 2 +-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotService.java | 362 +++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleService.java | 22 +++++++++++++---------
18 files changed, 992 insertions(+), 642 deletions(-)
create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoDocument.java
create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoMainTemplate.java
create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoPojo.java
create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoUtils.java
create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7969a07..e0e628c 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,18 +5,16 @@
-
-
-
+
+
-
+
-
-
+
@@ -59,11 +57,20 @@
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
@@ -71,61 +78,55 @@
-
-
+
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
+
+
-
+
-
-
-
-
-
-
+
+
@@ -133,8 +134,12 @@
-
-
+
+
+
+
+
+
@@ -153,10 +158,6 @@
- HZ1_BOT_TO_NX2
- PlayUtils
- res
- botName
PERSON_MOODURL
OFFLINE_SERVER
successUpLoadFileIds
@@ -174,7 +175,6 @@
url
folder
allOldname2Id
- tts
id2Info
allRepeateName2Info
repeateName2Ids
@@ -183,6 +183,11 @@
buildMp3Response
HttpServletResponse
check
+ USER_HISTORY
+ getJsonFromName
+ T
+ userId
+ tts
OPENID_CACHE
@@ -198,21 +203,11 @@
@@ -281,8 +286,8 @@
-
-
+
+
@@ -304,76 +309,106 @@
-
+
+
+
+
+
+
+
-
+
+
-
+
+
-
+
+
-
+
-
+
+
-
+
-
+
+
-
+
-
-
+
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -381,6 +416,9 @@
+
+
+
@@ -389,6 +427,9 @@
+
+
+
@@ -398,6 +439,15 @@
+
+
+
+
+
+
+
+
+
@@ -406,13 +456,14 @@
+
-
+
@@ -426,7 +477,7 @@
-
+
@@ -478,7 +529,7 @@
-
+
@@ -881,8 +932,8 @@
-
+
@@ -987,7 +1038,8 @@
-
+
+
@@ -997,7 +1049,7 @@
-
+
@@ -1009,9 +1061,10 @@
-
+
+
-
+
@@ -1019,7 +1072,7 @@
-
+
@@ -1042,7 +1095,7 @@
-
+
@@ -1057,413 +1110,429 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
-
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
-
+
-
-
+
+
-
-
+
-
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/common/Config.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/common/Config.java
index 2ec4f7d..85ab670 100644
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/common/Config.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/common/Config.java
@@ -20,8 +20,8 @@ public class Config {
private static Properties properties;
static {
-// String filename = "tts.properties";
- String filename = "ttsTest.properties";
+ String filename = "tts.properties";
+// String filename = "ttsTest.properties";
properties = new Properties();
try {
properties.load(new InputStreamReader(Config.class.getClassLoader().getResourceAsStream(filename), StandardCharsets.UTF_8));
diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
index 0789788..6b7901e 100644
--- a/tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
+++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/common/TTSUtils.java
@@ -17,6 +17,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer;
import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -437,8 +439,16 @@ public class TTSUtils {
}
public static void main(String[] args) {
- String v1 = "/home/yf01/下载/齐齐-人工配音关系对于表(1).csv";
- String v2 = "/home/yf01/下载/%E6%B0%B4%E5%BF%83%E6%B9%96.csv";
- test(v1, v2);
+ String s = "好的。苏琪家好像是住北城,我家乡刚好在北城隔壁,顺路。";
+ Pattern pattern = Pattern.compile("\uD83C\uDD70(.*?)\uD83C\uDD71");
+ Matcher matcher = pattern.matcher(s);
+ System.out.println(matcher.find());
+ System.out.println(s);
+// while (matcher.find()) {
+// String variableText = matcher.group(1);
+// System.out.println(variableText);
+// }
+ String ss = "他们循{/xun2/}声{/sheng1/}来到一颗大榕树后{/hou4/}的一座^木{/mu4/}屋{/wu1/}旁,见到音乐家捧{/peng3/}着{/zhe/}一个像笛子一样的乐器正在入{/ru4/}神地吹奏{/zou4/}着{/zhe/}。后来,音乐家很高兴接纳了他们,并{/bing4/}在^木{/mu4/}屋{/wu1/}旁边给他们^安{/an1/}了新家,四个小伙伴和善良的音乐家开心地住在水{/shui3/}心{/xin1/}湖{/hu2/}边,再{/zai4/}也{/ye3/}不用担惊受怕了。每天和{/he2/}音乐家一起弹{/tan2/}奏{/zou4/}唱跳,认识他们的人都亲切地称他们为{/wei2/}“水{/shui3/}心{/xin1/}湖{/hu2/}的音乐家”。";
+ System.out.println(buildMP3Filename(ss));
}
}
diff --git a/tts_service/src/main/resources/application.yml b/tts_service/src/main/resources/application.yml
index 85f868b..d9dfcb5 100644
--- a/tts_service/src/main/resources/application.yml
+++ b/tts_service/src/main/resources/application.yml
@@ -24,12 +24,12 @@ logging:
level:
root: info
server:
-# port: 9663
- port: 8188
+ port: 9663
+# port: 8188
tomcat:
accesslog:
enabled: true
pattern: '%h %l %u %t "%r" %s %b bytes %D ms'
-# directory: /home/ubuntu/project/tts/tomcat
- directory: /root/GameEditor/mqw/project/ttsTest/tomcat
+ directory: /home/ubuntu/project/tts/tomcat
+# directory: /root/GameEditor/mqw/project/ttsTest/tomcat
connection-timeout: 240000
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoDocument.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoDocument.java
new file mode 100644
index 0000000..548a108
--- /dev/null
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoDocument.java
@@ -0,0 +1,16 @@
+package ai.qiwu.com.xiaoduhome.common.temple.productInfo;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @author 苗权威
+ * @dateTime 19-9-23 下午5:22
+ */
+@Getter
+@Setter
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class ProductInfoDocument {
+ private ProductInfoMainTemplate mainTemplate;
+}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoMainTemplate.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoMainTemplate.java
new file mode 100644
index 0000000..2e2abbc
--- /dev/null
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoMainTemplate.java
@@ -0,0 +1,25 @@
+package ai.qiwu.com.xiaoduhome.common.temple.productInfo;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author 苗权威
+ * @dateTime 19-9-23 下午5:23
+ */
+@Getter
+@Setter
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class ProductInfoMainTemplate {
+ private List parameters = new ArrayList<>();
+ private List items;
+
+ public ProductInfoMainTemplate() {
+ this.parameters.add("payload");
+ this.items = new ArrayList<>();
+ }
+}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoPojo.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoPojo.java
new file mode 100644
index 0000000..341d18c
--- /dev/null
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoPojo.java
@@ -0,0 +1,56 @@
+package ai.qiwu.com.xiaoduhome.common.temple.productInfo;
+
+import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * @author 苗权威
+ * @dateTime 19-9-23 下午5:24
+ */
+@Getter
+@Setter
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+public class ProductInfoPojo {
+ private String type;
+ private String position;
+ private String top;
+ private String bottom;
+ private String left;
+ private String src;
+ private String height;
+ private String width;
+ private String headerTitle;
+ private Boolean hasBackIcon;
+ private String componentId;
+ private List items;
+ @JsonProperty("flex-direction")
+ private String flexDirection;
+ @JsonProperty("border-radius")
+ private String borderRadius;
+ @JsonProperty("scale-type")
+ private String scaleType;
+ @JsonProperty("margin-left")
+ private String marginLeft;
+ @JsonProperty("margin-top")
+ private String marginTop;
+ private List onClick;
+ @JsonProperty("font-size")
+ private String fontSize;
+ private String text;
+ @JsonProperty("max-lines")
+ private Integer maxLines;
+ @JsonProperty("margin-right")
+ private String marginRight;
+ @JsonProperty("line-height")
+ private String lineHeight;
+ @JsonProperty("text-overflow")
+ private String textOverflow;
+ @JsonProperty("align-items")
+ private String alignItems;
+ private List hints;
+}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoUtils.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoUtils.java
new file mode 100644
index 0000000..80b92b6
--- /dev/null
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoUtils.java
@@ -0,0 +1,271 @@
+package ai.qiwu.com.xiaoduhome.common.temple.productInfo;
+
+import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author 苗权威
+ * @dateTime 19-9-23 下午5:37
+ */
+public class ProductInfoUtils {
+
+ private static final ProductInfoPojo BACK_IMG = buildProductInfoBackgroundImg();
+ private static final ProductInfoPojo HEADER = buildProductInfoHead();
+ private static final ProductInfoPojo FOOTER = buildProductInfoFooter();
+
+ public static ProductInfoDocument getProductINfoDocument(String src, String productName, String time, String author, String labelText,
+ String introText,String startComponId, String flowerId, String flowerText,
+ String collectId, String collectSrc, String collectText) {
+ ProductInfoDocument document = new ProductInfoDocument();
+ ProductInfoMainTemplate mainTemplate = new ProductInfoMainTemplate();
+ document.setMainTemplate(mainTemplate);
+ mainTemplate.getItems().addAll(Arrays.asList(BACK_IMG, HEADER, buildLeftRightPart(src, productName, time,
+ author, labelText, introText, startComponId, flowerId, flowerText, collectId, collectSrc, collectText), FOOTER));
+ return document;
+ }
+
+ private static ProductInfoPojo buildLeftRightPart(String src, String productName, String time, String author, String labelText,
+ String introText,String startComponId, String flowerId, String flowerText,
+ String collectId, String collectSrc, String collectText) {
+ ProductInfoPojo lrCon = new ProductInfoPojo();
+ lrCon.setType("Container");
+ lrCon.setFlexDirection("row");
+ lrCon.setWidth("100%");
+ lrCon.setHeight("100%");
+ lrCon.setItems(Arrays.asList(buildLeftCoverImage(src), buildRightPart(productName, time, author, labelText,
+ introText, startComponId, flowerId, flowerText, collectId, collectSrc, collectText)));
+ return lrCon;
+ }
+
+ private static ProductInfoPojo buildLeftCoverImage(String src) {
+ ProductInfoPojo coverImage = new ProductInfoPojo();
+ coverImage.setType("Image");
+ coverImage.setWidth("280dp");
+ coverImage.setHeight("280dp");
+ coverImage.setBorderRadius("30dp");
+ coverImage.setScaleType("fitCenter");
+ coverImage.setMarginLeft("50dp");
+ coverImage.setMarginTop("12dp");
+ coverImage.setComponentId("imgPro");
+ coverImage.setSrc(src);
+
+ Event rotateAnimation = new Event("Animation", "imgPro");
+ rotateAnimation.setFrom("0");
+ rotateAnimation.setTo("360");
+ rotateAnimation.setEasing("ease-out");
+ rotateAnimation.setAttribute("rotation");
+ rotateAnimation.setDuration(2000L);
+ rotateAnimation.setRepeatCount("1");
+ rotateAnimation.setRepeatMode("reverse");
+
+ coverImage.setOnClick(Collections.singletonList(rotateAnimation));
+ return coverImage;
+ }
+
+ private static ProductInfoPojo buildRightPart(String productName, String time, String author, String labelText,
+ String introText,String startComponId, String flowerId, String flowerText,
+ String collectId, String collectSrc, String collectText) {
+ ProductInfoPojo rightPartCon = new ProductInfoPojo();
+ rightPartCon.setType("Container");
+ rightPartCon.setFlexDirection("column");
+ rightPartCon.setWidth("600dp");
+ rightPartCon.setHeight("100%");
+ rightPartCon.setItems(Arrays.asList(buildProductName(productName), buildTimeAuthor(time, author), buildLabel(labelText),
+ buildIntro(introText), buildIconCon(startComponId, flowerId, flowerText, collectId, collectSrc, collectText)));
+ return rightPartCon;
+ }
+
+ private static ProductInfoPojo buildProductName(String productName) {
+ ProductInfoPojo name = new ProductInfoPojo();
+ name.setType("Text");
+ name.setMarginTop("10dp");
+ name.setFontSize("38dp");
+ name.setMarginLeft("5%");
+ return name;
+ }
+
+ private static ProductInfoPojo buildTimeAuthor(String time, String author) {
+ ProductInfoPojo timeAuthorCon = new ProductInfoPojo();
+ timeAuthorCon.setType("Container");
+ timeAuthorCon.setMarginTop("10dp");
+ timeAuthorCon.setFlexDirection("row");
+
+ ProductInfoPojo timePojo = new ProductInfoPojo();
+ timePojo.setType("Text");
+ timePojo.setMarginLeft("5%");
+ timePojo.setFontSize("22dp");
+ timePojo.setText(time);
+
+ ProductInfoPojo authorPojo = new ProductInfoPojo();
+ authorPojo.setType("Text");
+ authorPojo.setMarginLeft("10%");
+ authorPojo.setFontSize("22dp");
+ authorPojo.setText(author);
+
+ timeAuthorCon.setItems(Arrays.asList(timePojo, authorPojo));
+ return timeAuthorCon;
+ }
+
+ private static ProductInfoPojo buildLabel(String labelText) {
+ ProductInfoPojo labelCon = new ProductInfoPojo();
+ labelCon.setType("Container");
+ labelCon.setMarginTop("6dp");
+ labelCon.setFlexDirection("row");
+
+ ProductInfoPojo label = new ProductInfoPojo();
+ label.setType("Text");
+ label.setMarginLeft("5%");
+ label.setFontSize("22dp");
+ label.setMaxLines(1);
+ label.setText(labelText);
+
+ labelCon.setItems(Collections.singletonList(label));
+ return labelCon;
+ }
+
+ private static ProductInfoPojo buildIntro(String introText) {
+ ProductInfoPojo introCon = new ProductInfoPojo();
+ introCon.setType("Container");
+ introCon.setMarginTop("9dp");
+ introCon.setMarginRight("26dp");
+
+ ProductInfoPojo intro = new ProductInfoPojo();
+ intro.setType("Text");
+ intro.setMarginLeft("5%");
+ intro.setFontSize("25dp");
+ intro.setLineHeight("20dp");
+ intro.setMarginTop("30dp");
+ intro.setMaxLines(3);
+ intro.setTextOverflow("ellipsis");
+ intro.setText(introText);
+
+ introCon.setItems(Collections.singletonList(intro));
+ return introCon;
+ }
+
+ private static ProductInfoPojo buildIconCon(String startComponId, String flowerId, String flowerText,
+ String collectId, String collectSrc, String collectText) {
+ ProductInfoPojo iconCon = new ProductInfoPojo();
+ iconCon.setType("Container");
+ iconCon.setPosition("absolute");
+ iconCon.setFlexDirection("row");
+ iconCon.setBottom("160dp");
+ iconCon.setItems(Arrays.asList(buildStart(startComponId), buildFlower(flowerId, flowerText),
+ buildCollect(collectId, collectSrc, collectText)));
+ return iconCon;
+ }
+
+ private static ProductInfoPojo buildStart(String startComponId) {
+ ProductInfoPojo startCon = new ProductInfoPojo();
+ startCon.setType("Container");
+ startCon.setAlignItems("center");
+ startCon.setMarginLeft("50dp");
+ startCon.setOnClick(Collections.singletonList(new Event("SendEvent", startComponId)));
+
+ ProductInfoPojo image = new ProductInfoPojo();
+ image.setType("Image");
+ image.setHeight("60dp");
+ image.setWidth("60dp");
+ image.setSrc("https://aliyun-hz1.chewrobot.com/xiaoduhome/image/feel.png");
+ image.setScaleType("fitCenter");
+
+ ProductInfoPojo startText = new ProductInfoPojo();
+ startText.setType("Text");
+ startText.setText("开始体验");
+ startText.setMarginTop("10dp");
+ startText.setFontSize("20dp");
+
+ startCon.setItems(Arrays.asList(image, startText));
+ return startCon;
+ }
+
+ private static ProductInfoPojo buildFlower(String flowerId, String flowerText) {
+ ProductInfoPojo flowerCon = new ProductInfoPojo();
+ flowerCon.setType("Container");
+ flowerCon.setAlignItems("center");
+ flowerCon.setMarginLeft("130dp");
+ flowerCon.setOnClick(Collections.singletonList(new Event("SendEvent", flowerId)));
+
+ ProductInfoPojo image = new ProductInfoPojo();
+ image.setType("Image");
+ image.setHeight("60dp");
+ image.setWidth("60dp");
+ image.setSrc("https://aliyun-hz1.chewrobot.com/xiaoduhome/image/flower.png");
+ image.setScaleType("fitCenter");
+
+ ProductInfoPojo flower = new ProductInfoPojo();
+ flower.setType("Text");
+ flower.setText(flowerText);
+ flower.setMarginTop("10dp");
+ flower.setFontSize("20dp");
+
+ flowerCon.setItems(Arrays.asList(image, flower));
+ return flowerCon;
+ }
+
+ private static ProductInfoPojo buildCollect(String collectId, String collectSrc, String collectText) {
+ ProductInfoPojo collectCon = new ProductInfoPojo();
+ collectCon.setType("Container");
+ collectCon.setAlignItems("center");
+ collectCon.setMarginLeft("120dp");
+ collectCon.setOnClick(Collections.singletonList(new Event("SendEvent", collectId)));
+
+ ProductInfoPojo image = new ProductInfoPojo();
+ image.setType("Image");
+ image.setHeight("60dp");
+ image.setWidth("60dp");
+ image.setComponentId("collectImage");
+ image.setSrc(collectSrc);
+ image.setScaleType("fitCenter");
+
+ ProductInfoPojo collect = new ProductInfoPojo();
+ collect.setType("Text");
+ collect.setComponentId("collectText");
+ collect.setText(collectText);
+ collect.setMarginTop("10dp");
+ collect.setFontSize("20dp");
+
+ collectCon.setItems(Arrays.asList(image, collect));
+ return collectCon;
+ }
+
+ private static ProductInfoPojo buildProductInfoFooter() {
+ ProductInfoPojo footerCon = new ProductInfoPojo();
+ footerCon.setType("Container");
+ footerCon.setPosition("absolute");
+ footerCon.setWidth("100%");
+ footerCon.setLeft("0");
+ footerCon.setBottom("0");
+
+ ProductInfoPojo footer = new ProductInfoPojo();
+ footer.setType("Footer");
+ footer.setHints(Arrays.asList("开始","我要送花","收藏作品","回到首页","返回"));
+
+ footerCon.setItems(Collections.singletonList(footer));
+
+ return footerCon;
+ }
+
+ private static ProductInfoPojo buildProductInfoBackgroundImg() {
+ ProductInfoPojo backGroundImg = new ProductInfoPojo();
+ backGroundImg.setType("Image");
+ backGroundImg.setPosition("absolute");
+ backGroundImg.setTop("0dp");
+ backGroundImg.setLeft("0dp");
+ backGroundImg.setSrc("https://aliyun-hz1.chewrobot.com/xiaoduhome/image/backend.jpg");
+ backGroundImg.setHeight("100%");
+ backGroundImg.setWidth("100%");
+
+ return backGroundImg;
+ }
+
+ private static ProductInfoPojo buildProductInfoHead() {
+ ProductInfoPojo head = new ProductInfoPojo();
+ head.setType("Header");
+ head.setHeaderTitle("交游天下");
+ head.setHasBackIcon(false);
+ return head;
+ }
+}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTBTiny.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTBTiny.java
index 89e38e9..eafa249 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTBTiny.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTBTiny.java
@@ -14,10 +14,10 @@ import javax.persistence.*;
public class AppFlowerTBTiny {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
+ private Long id;
@Column(name = "user_id")
- private Integer userId;
+ private Long userId;
@Column(name = "unit_price")
private Double unitPrice;
@@ -26,5 +26,5 @@ public class AppFlowerTBTiny {
private String botId;
@Column
- private Integer number;
+ private Long number;
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java
index 232aad8..345c523 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/TestBuild.java
@@ -6,6 +6,7 @@ import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;
import com.eclipsesource.json.JsonObject;
import lombok.*;
+import org.apache.commons.lang3.StringUtils;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -195,6 +196,6 @@ public class TestBuild {
String v2 = "/home/yf01/下载/齐齐-人工配音关系对于表.csv";
//csvUtil(target, src, srcModify, v2);
- check(src, srcModify, target);
+ //check(src, srcModify, target);
}
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/UserBehaviorData.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/UserBehaviorData.java
index 78454c7..b356a7b 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/UserBehaviorData.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/UserBehaviorData.java
@@ -13,8 +13,16 @@ import java.util.List;
@Getter
@Setter
public class UserBehaviorData {
+ // 用户浏览历史
private volatile HashMap userBotId2History = new HashMap<>();
- private volatile HashMap userBotId2Flowers = new HashMap<>();
+ // 用户对作品所送花的数目
+ private volatile HashMap userBotId2Flowers = new HashMap<>();
+ // 用户是否收藏该作品
private volatile HashMap userBotId2Collected = new HashMap<>();
+ // timestamp与mark之间的关系:清扫线程每五分钟更新缓存中所有mark为1的对象的timestamp并将mark改为0,
+ // 若发现mark为0的timestamp五分钟之前的则删除缓存
private volatile Long timeStamp = System.currentTimeMillis();
+ private volatile Byte mark = 1;
+
+ private volatile String jytUserId;
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/dpl/Event.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/dpl/Event.java
index 31c04df..7103339 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/dpl/Event.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/dpl/Event.java
@@ -30,6 +30,7 @@ public class Event {
private String repeatCount;
private String position;
private String value;
+ private String repeatMode;
public Event() {
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFavoriteTBRepository.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFavoriteTBRepository.java
index 61f7534..27eb309 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFavoriteTBRepository.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFavoriteTBRepository.java
@@ -36,7 +36,7 @@ public interface AppFavoriteTBRepository extends JpaRepository getFavoriteBotIds(Integer userId);
+ List getFavoriteBotIds(Long userId);
@Override
long count(Example example);
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBTintRepository.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBTintRepository.java
index 9b080f6..3df7026 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBTintRepository.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBTintRepository.java
@@ -2,6 +2,7 @@ package ai.qiwu.com.xiaoduhome.repository.primary;
import ai.qiwu.com.xiaoduhome.entity.primary.AppFlowerTBTiny;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@@ -16,4 +17,7 @@ public interface AppFlowerTBTintRepository extends JpaRepository getByUserIdAndBotId(Integer userId, String botId);
+
+ @Query(value = "select number from app_flower_tb where user_id=?1 and bot_username=?2", nativeQuery = true)
+ List getFlowerNumByUserIdAndBotAccount(Long userId, String botAccount);
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuHistoryTBRepository.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuHistoryTBRepository.java
index 9c4e6ee..1113a52 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuHistoryTBRepository.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuHistoryTBRepository.java
@@ -34,6 +34,6 @@ public interface XiaoDuHistoryTBRepository extends JpaRepository getUserHostory(String userId);
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotService.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotService.java
index f8eec2a..d2a224a 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotService.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotService.java
@@ -8,6 +8,7 @@ import ai.qiwu.com.xiaoduhome.common.temple.funny.FunnyDocument;
import ai.qiwu.com.xiaoduhome.common.temple.onLunch.LunchUtils;
import ai.qiwu.com.xiaoduhome.common.temple.play.PlayDocument;
import ai.qiwu.com.xiaoduhome.common.temple.play.PlayUtils;
+import ai.qiwu.com.xiaoduhome.common.temple.productInfo.ProductInfoUtils;
import ai.qiwu.com.xiaoduhome.common.temple.rank.RankUtil;
import ai.qiwu.com.xiaoduhome.common.temple.rank.RankingDocument;
import ai.qiwu.com.xiaoduhome.common.temple.recommand.RecommandDocument;
@@ -91,16 +92,16 @@ public class DplBotService extends BaseBot {
private static final int CORE = Runtime.getRuntime().availableProcessors();
- public static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(CORE+1, 1500,
- 2500, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(CORE), new ThreadPoolExecutor.CallerRunsPolicy());
+// public static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(CORE+1, 1500,
+// 2500, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(CORE), new ThreadPoolExecutor.CallerRunsPolicy());
- private static final ConcurrentHashMap DU_ID_2_US_ID;
+ //private static final ConcurrentHashMap DU_ID_2_US_ID;
private static final ConcurrentHashMap LAST_OUTTIME_RESULT = new ConcurrentHashMap<>();
private static volatile FunnyDocument FUNNY_DEFAULT_DOCUMENT;
- private static final ConcurrentHashMap USER_HISTORY = new ConcurrentHashMap<>();
+// private static final ConcurrentHashMap USER_HISTORY = new ConcurrentHashMap<>();
private final byte byteFill = 1;
@@ -126,9 +127,9 @@ public class DplBotService extends BaseBot {
// List- container = CATEGORY_PROD.getMainTemplate().getItems().get(0).getItems();
// CATEGORY_PROD_LIST = container.get(2).getItems().get(0);
// CATEGORY_PROD_HEAD = container.get(1);
- PROD_INFO = JSON.parseObject(getDPLTemple("static/json/productInfo.json"), MyDocument.class);
- FIRST_PAGE = JSON.parseObject(getDPLTemple("static/json/firstPage.json"), MyDocument.class);
- DU_ID_2_US_ID = new ConcurrentHashMap<>();
+ PROD_INFO = JSON.parseObject(DplbotServiceUtil.getDPLTemple("static/json/productInfo.json"), MyDocument.class);
+ FIRST_PAGE = JSON.parseObject(DplbotServiceUtil.getDPLTemple("static/json/firstPage.json"), MyDocument.class);
+// DU_ID_2_US_ID = new ConcurrentHashMap<>();
}
public DplBotService(HttpServletRequest request) throws IOException {
@@ -140,222 +141,21 @@ public class DplBotService extends BaseBot {
RenderDocument renderDocument = new RenderDocument(FIRST_PAGE);
this.addDirective(renderDocument);
OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, Constants.WelcomeWord.WELCOME);
-
- POOL.submit(() -> {
- XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
- String userId = getUserId();
- UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
- HashMap userBotId2History = data.getUserBotId2History();
- for (String botId: repository.getUserHostory(getUserId())) {
- userBotId2History.put(botId, byteFill);
- }
- //log.info("用户历史记录:{}",USER_HISTORY);
- });
+ // 初次进入时创建用户的行为信息,包括历史记录,送花数,收藏记录
+ // 历史记录
+ DplbotServiceUtil.onLunchGetUserHistory(getUserId());
+ String jytUserId;
if (getAccessToken() != null) {
- getUserFavorite();
+ // 收藏记录,送花数,郊游天下id
+ DplbotServiceUtil.onLunchFillUserBehaviorData(getAccessToken(), getUserId());
}
return new Response(outputSpeech);
}
- private void getUserFavorite() {
- POOL.submit(() -> {
- AppFavoriteTBRepository favoriteTBRepository = BaseHolder.getBean("appFavoriteTBRepository");
- try {
- String userId = getUserId();
- UserBehaviorData data = USER_HISTORY.get(userId);
- if (data == null) {
- data = new UserBehaviorData();
- USER_HISTORY.put(userId, data);
- }
- String usUserId = getUsUserId();
- List favoriteBotIDS = favoriteTBRepository.getFavoriteBotIds(Integer.valueOf(usUserId));
- for(String botId : favoriteBotIDS) {
- data.getUserBotId2Collected().put(botId, byteFill);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
- }
+
@Override
protected Response onInent(IntentRequest intentRequest) {
-//
-// final String userId = getCustomerId();
-// String intentName = getIntent().getName();
-// log.info("Intent name:{}",intentName);
-// if ("load".equals(intentName)) {
-// return load();
-// } else if ("openCollect".equals(intentName)) {
-// if (getAccessToken() == null) {
-// OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "该功能需要登录,请说小度小度,登录");
-// return new Response(outputSpeech);
-// } else {
-// String appUserId = getSessionAttribute("userId");
-// if (appUserId == null) {
-// try {
-// appUserId = getUserIdByToken(getAccessToken());
-// } catch (IOException e) {
-// log.error("打开收藏页时获取用户的郊游天下端id出错:{}", e.toString());
-// OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, SORRY_UNCATCH);
-// return new Response(outputSpeech);
-// }
-// if (appUserId == null) {
-// OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, SORRY_UNCATCH);
-// return new Response(outputSpeech);
-// }
-// }
-// CollectHistoryDocument document = TempleUtils.getCollectPage(Integer.parseInt(appUserId));
-// RenderDocument render = new RenderDocument(document);
-// this.addDirective(render);
-// this.setSessionAttribute(PRE_COLLE,document.getIdToken());
-// return new Response();
-// }
-// } else if ("openNum".equals(intentName)) {
-// String collectToken = getSessionAttribute(PRE_COLLE);
-// String rankToken = getSessionAttribute("ranking");
-// String recommengToken = getSessionAttribute("recommand");
-// log.info("openNum slot value:{}", getSlot("sys.number"));
-// if (collectToken != null) {
-// return dealOpenNum(collectToken);
-// } else if (rankToken != null){
-// return dealOpenNum(rankToken);
-// } else if (recommengToken != null) {
-// return dealOpenNum(recommengToken);
-// } else {
-// OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "似乎出了什么问题,请点击屏幕吧");
-// return new Response(outputSpeech);
-// }
-// } else if ("history".equals(intentName)) {
-// CollectHistoryDocument document = TempleUtils.getHistory(getUserId());
-// RenderDocument render = new RenderDocument(document);
-// this.addDirective(render);
-// this.setSessionAttribute(PRE_COLLE,document.getIdToken());
-// this.setSessionAttribute("ranking", null);
-// this.setSessionAttribute("recommand", null);
-// return new Response();
-// } else if ("recommand".equals(intentName)) {
-// RecommandDocument recommandDocument = TempleUtils.getRecommend();
-// RenderDocument render = new RenderDocument();
-// render.setDocument(recommandDocument);
-// this.addDirective(render);
-// this.addDirective(new PushStack());
-// String token = recommandDocument.getRecommendIdList();
-// if (token != null) {
-// this.setSessionAttribute("recommand", token);
-// this.setSessionAttribute(PRE_COLLE, null);
-// this.setSessionAttribute("ranking", null);
-// }
-// return new Response();
-// } else if ("ranking".equals(intentName)) {
-// RankingDocument document = TempleUtils.getRanking();
-// RenderDocument render = new RenderDocument();
-// render.setDocument(document);
-// this.addDirective(render);
-// this.addDirective(new PushStack());
-// String token = document.getRankBotIds();
-// if (token != null) {
-// this.setSessionAttribute("ranking", token);
-// this.setSessionAttribute("recommand", null);
-// this.setSessionAttribute(PRE_COLLE, null);
-// }
-// return new Response();
-// }
-// Query query = intentRequest.getQuery();
-// String userWord = null;
-// if (query != null) userWord = query.getOriginal();
-// if (userWord == null){
-// log.info("小度没有传来任何话语");
-// return buildErrorResponse(SORRY_UNCATCH);
-// }
-// QiWuResponse data = null;
-// try {
-// data = RequestTerminal.requestTerminate(userWord, userId);
-// } catch (Exception e) {
-// log.error("请求终端接口出错:", e.toString());
-// }
-// if (data == null) {
-// return buildErrorResponse(SORRY_UNCATCH);
-// }
-// String text = data.getText();
-// log.info("小悟返回:{}", text);
-// final String botAccount = ScheduleService.getNx2BotToHz1().get(data.getAipioneerUsername());
-// String beforeBotAccount = getSessionAttribute("botAcc");
-// if (botAccount == null || ScheduleService.getExceptBotAccount().contains(botAccount)) {
-// OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, text.substring(text.indexOf("】")+1));
-// return new Response(outputSpeech);
-// }
-// else if (!botAccount.equals(beforeBotAccount)) {
-// List
- container = PLAY_DOCUMENT.getMainTemplate().getItems().get(2).getItems();
-// container.get(1).setSrc(data.getAudio());
-// text = text.substring(text.indexOf("】")+1);
-// container.get(0).getItems().get(0).setText(text);
-// RenderDocument render = new RenderDocument(PLAY_DOCUMENT);
-// this.addDirective(render);
-// new Thread(() -> {
-// XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
-// XiaoDuHistoryTB historyTB = repository.getByXiaoduUserIdAndBotId(userId, botAccount);
-// if (historyTB == null) {
-// historyTB = new XiaoDuHistoryTB();
-// historyTB.setLastTime(System.currentTimeMillis());
-// historyTB.setBotId(botAccount);
-// historyTB.setXiaoduUserId(userId);
-// log.info("插入历史数据:{}", botAccount);
-// } else {
-// historyTB.setLastTime(System.currentTimeMillis());
-// log.info("更新历史数据:{}", botAccount);
-// }
-// repository.save(historyTB);
-// }).start();
-// return new Response();
-// } else {
-// ExecuteCommands executeCommands = new ExecuteCommands();
-// SetStateCommand audio = new SetStateCommand();
-// SetStateCommand textState = new SetStateCommand();
-// audio.setComponentId("audio");
-// audio.setState("src");
-// audio.setValue(data.getAudio());
-// textState.setComponentId("text");
-// textState.setState("text");
-// textState.setValue(text);
-//
-// executeCommands.addCommand(audio);
-// executeCommands.addCommand(textState);
-// this.addDirective(executeCommands);
-// this.setSessionAttribute("botAcc", botAccount);
-// return new Response();
-// }
-
-// if ("测试".equals(intentRequest.getQuery().getOriginal())) {
-// try {
-// Document document = Document.getDocumentFromString(getDPLTemple("static/json/textComponent.json"));
-// RenderDocument render = new RenderDocument(document);
-// this.addDirective(render);
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-// return new Response();
-// }else if ("旋转".equals(intentRequest.getQuery().getOriginal())) {
-// try {
-// Document document = Document.getDocumentFromString(getDPLTemple("static/json/textRota.json"));
-// RenderDocument render = new RenderDocument(document);
-// this.addDirective(render);
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-// return new Response();
-// }else if ("拉伸".equals(intentRequest.getQuery().getOriginal()) ||
-// "增加".equals(intentRequest.getQuery().getOriginal())) {
-// try {
-// Document document = Document.getDocumentFromString(getDPLTemple("static/json/testScale.json"));
-// RenderDocument render = new RenderDocument(document);
-// this.addDirective(render);
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-// return new Response();
-// }
-
String userId = getUserId();
OverTimeDetail detail;
if ((detail = LAST_OUTTIME_RESULT.remove(userId)) != null) {
@@ -370,7 +170,7 @@ public class DplBotService extends BaseBot {
return detail.getResponse();
}
try {
- Future future = POOL.submit(new Task(intentRequest, this));
+ Future future = DplbotServiceUtil.getPOOL().submit(new Task(intentRequest, this));
future.get(2200, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException e) {
log.error("获取任务执行结果出错:{}", e.toString());
@@ -391,6 +191,12 @@ public class DplBotService extends BaseBot {
return LAST_OUTTIME_RESULT.remove(getUserId()).getResponse();
}
+ /**
+ *
+ * @param idsToken 当前页面作品的id集合
+ * @param overDetail
+ * @return
+ */
private Response dealOpenNum(String idsToken, OverTimeDetail overDetail) {
int collectNum = Integer.parseInt(getSlot("sys.number"));
String[] tokenList = new String(Base64.getDecoder().decode(idsToken)).split(File.separator);
@@ -401,7 +207,7 @@ public class DplBotService extends BaseBot {
log.info("进入作品语句:{}", enterProductWord);
QiWuResponse data = null;
try {
- data = RequestTerminal.requestTerminate(enterProductWord, getCustomerId());
+ data = RequestTerminal.requestTerminate(enterProductWord, getUserId());
} catch (IOException e) {
log.error("请求终端接口出错:", e.toString());
}
@@ -409,13 +215,11 @@ public class DplBotService extends BaseBot {
return buildErrorResponse(SORRY_UNCATCH);
}
String text = data.getText();
- int i1 = text.indexOf("【");
- int i2 = text.indexOf("@");
- String aside = text.substring(i1+1, i2);
+ String aside = DplbotServiceUtil.getAsideText(text);
text = text.substring(text.indexOf("】")+1);
log.info("旁白名字:{}",aside);
PlayDocument document = PlayUtils.getPlayDocument(productName, aside, ScheduleService.getAsideImgUrl(botID, aside),
- data.getAudio(), text, doesUserCollectThisBot(botID));
+ data.getAudio(), text, DplbotServiceUtil.doesUserCollectThisBot(botID, getAccessToken(), getUserId()));
RenderDocument render = new RenderDocument(document);
this.setSessionAttribute(PRE_COLLE, null);
@@ -430,39 +234,15 @@ public class DplBotService extends BaseBot {
return new Response();
}
- private static String getDPLTemple(String path) {
- String temple = null;
- try {
- temple = getJsonFromName(path);
- } catch (IOException e) {
- log.error("没有获取到json字符串:{}", e.toString());
- }
- return temple;
- }
-
@Override
protected Response onUserEvent(UserEvent userEvent) {
log.info("onUserEvent事件触发,token:{}, componentId:{}",userEvent.getToken(),userEvent.getPayload().getComponentId());
if (getAccessToken() != null && getSessionAttribute("userId") == null) {
- try {
- String userId = getUserIdByToken(getAccessToken());
- setSessionAttribute("userId", userId);
- } catch (Exception e) {
- log.error("新会话设置userId信息失败:{}",e.toString());
- }
+ String userId = DplbotServiceUtil.getUsUserId(getAccessToken(), getUserId());
+ setSessionAttribute("userId", userId);
}
String componentId = userEvent.getPayload().getComponentId();
String componentPrefix;
-// if ("frameTxtOver".equals(componentId)) {
-// ExecuteCommands commands = new ExecuteCommands();
-// SetStateCommand setState = new SetStateCommand();
-// setState.setComponentId("frameTxt");
-// setState.setState("text");
-// setState.setValue("233333333333333333333");
-// commands.addCommand(setState);
-// this.addDirective(commands);
-// return new Response();
-// }
if ("audio".equals(componentId)){
setExpectSpeech(true);
}
@@ -477,36 +257,17 @@ public class DplBotService extends BaseBot {
}
String imgUrl = new StringBuilder(Constants.IMG_PREFIX).append(productDetail.getBannerImgUrl()).toString();
- List
- content = PROD_INFO.getMainTemplate().getItems().get(2).getItems().get(0).getItems().get(0).getItems();
-
- // product picture
- content.get(0).setSrc(imgUrl);
-
- // text content
- List
- contentText = content.get(1).getItems();
- // product name
- productName = correctName(productName);
- contentText.get(0).setText(productName);
-
- // product create time
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(productDetail.getCreateTime());
- contentText.get(1).getItems().get(0).setText(new StringBuilder(Constants.PRODUCT_INTRO.CREATE_TIME).append(dateString).toString());
-
- // product author
- contentText.get(1).getItems().get(1).setText(new StringBuilder(Constants.PRODUCT_INTRO.AUTHOR).append(productDetail.getAuthorName()).toString());
-
- // product labels
+ String time = new StringBuilder(Constants.PRODUCT_INTRO.CREATE_TIME).append(dateString).toString();
+ String author = new StringBuilder(Constants.PRODUCT_INTRO.AUTHOR).append(productDetail.getAuthorName()).toString();
StringBuilder labels = new StringBuilder(Constants.PRODUCT_INTRO.LABEL);
for (String label: productDetail.getLabels()) {
labels.append(Constants.PRODUCT_INTRO.SPACE).append(label);
}
- contentText.get(2).getItems().get(0).setText(labels.toString());
+ productDetail.getIntro();
+ ProductInfoUtils.getProductINfoDocument(imgUrl, productName, );
- // product introduction
- contentText.get(3).getItems().get(0).setText(productDetail.getIntro());
-
- List
- icons = contentText.get(4).getItems();
// "start product" container button
String enterProName = new StringBuilder(Constants.PRE_ENTER_PRODUCT).append(productName).toString();
icons.get(0).setComponentId(enterProName);
@@ -844,32 +605,6 @@ public class DplBotService extends BaseBot {
return executeCommands;
}
- private String getUsUserId() throws IOException {
- String usId = DU_ID_2_US_ID.get(getCustomerId());
- if (usId == null) usId = getUserIdByToken(getAccessToken());
- return usId;
- }
-
- private String getUserIdByToken(String accessToken) throws IOException {
- HashMap headers = new HashMap<>();
- headers.put("App-Channel-Id", "JIAOYOUTIANXIA");
- headers.put("Authorization", new StringBuilder(BEARER).append(accessToken).toString());
- String str = OkHttp3Utils.doGet(USER_ID_BY_TOKEN, new HashMap<>(), headers);
- log.info("getUserIdByToken:{}",str);
- UserInfoByTokenResult info = JSON.parseObject(str, UserInfoByTokenResult.class);
- if (info.getRetcode() == 0) {
- Payload payload = JSON.parseObject(info.getPayload(), Payload.class);
- String userId = payload.getInfoId();
- log.info("通过Token获取的用户在app端的id:{}", userId);
- DU_ID_2_US_ID.put(getCustomerId(), userId);
- return userId;
- }
- else {
- log.error("通过accessToken获取用户id出错:{}",str);
- return null;
- }
- }
-
private Response load() {
Card card = new LinkAccountCard();
Response response = buildErrorResponse(LOAD_INTRO);
@@ -1039,20 +774,6 @@ public class DplBotService extends BaseBot {
return userId;
}
-
- private static String getJsonFromName(String filename) throws IOException {
- InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
- InputStreamReader reader = new InputStreamReader(inputStream);
- char[] buffer = new char[512];
- int ln;
- StringBuilder builder = new StringBuilder();
- while ((ln = reader.read(buffer)) != -1) {
- builder.append(buffer, 0, ln);
- }
- return builder.toString();
- }
-
-
class CollectThread implements Runnable {
final String botId;
final String userId;
@@ -2404,28 +2125,7 @@ public class DplBotService extends BaseBot {
}
}
- private boolean doesUserCollectThisBot(String botID) {
- boolean collected = false;
- if (getAccessToken() != null) {
- UserBehaviorData userData = USER_HISTORY.get(getUserId());
- if (userData != null) {
- collected = userData.getUserBotId2Collected().containsKey(botID);
- } else {
- getUserFavorite();
- try {
- AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
- AppFavoriteTB tb = new AppFavoriteTB();
- tb.setBotId(botID);
- tb.setUserId(Integer.valueOf(getUsUserId()));
- Example example = Example.of(tb);
- collected = repository.exists(example);
- } catch (Exception e) {
- }
- }
- }
- return collected;
- }
public static void main(String[] args) throws IOException, InterruptedException, ExecutionException, TimeoutException {
String s = "NDM4MTU1MzY3NDU3NzIwMTM2NDY0MDIxNjQ3NTMzODk5NzYxODgxMTAyOTU1ODY4ODc5MDc3MjA4NjIyMTM5NjM1NjU3Mjc3MDA5MjgzOTM2OTQ5MzQ4Mjk3Mjc0MzI0MjY5ODI4MTM3MzkwNDczMTc3OTM2NTY1NTkwNTMzMTk2MTI1MzU0NTU3NjY3MzkxOTY=";
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java
new file mode 100644
index 0000000..216f9b1
--- /dev/null
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java
@@ -0,0 +1,185 @@
+package ai.qiwu.com.xiaoduhome.service;
+
+import ai.qiwu.com.xiaoduhome.common.BaseHolder;
+import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
+import ai.qiwu.com.xiaoduhome.entity.primary.AppFavoriteTB;
+import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
+import ai.qiwu.com.xiaoduhome.pojo.Payload;
+import ai.qiwu.com.xiaoduhome.pojo.UserBehaviorData;
+import ai.qiwu.com.xiaoduhome.pojo.UserInfoByTokenResult;
+import ai.qiwu.com.xiaoduhome.repository.primary.AppFavoriteTBRepository;
+import ai.qiwu.com.xiaoduhome.repository.primary.AppFlowerTBTintRepository;
+import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuHistoryTBRepository;
+import com.alibaba.fastjson.JSON;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.springframework.data.domain.Example;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static ai.qiwu.com.xiaoduhome.common.Constants.XIAOWU_API.BEARER;
+import static ai.qiwu.com.xiaoduhome.common.Constants.XIAOWU_API.USER_ID_BY_TOKEN;
+
+/**
+ * @author 苗权威
+ * @dateTime 19-9-23 上午10:26
+ */
+@Slf4j
+public class DplbotServiceUtil {
+
+ private static final byte byteFill = 1;
+
+ private static final int CORE = Runtime.getRuntime().availableProcessors();
+
+ private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(CORE+1, 1500,
+ 2500, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(CORE), new ThreadPoolExecutor.CallerRunsPolicy());
+
+ private static final ConcurrentHashMap USER_HISTORY = new ConcurrentHashMap<>();
+
+ static void getUserFavorite(final String userId, final String usUserId) {
+ POOL.submit(() -> {
+ AppFavoriteTBRepository favoriteTBRepository = BaseHolder.getBean("appFavoriteTBRepository");
+ try {
+ UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+ List favoriteBotIDS = favoriteTBRepository.getFavoriteBotIds(Long.valueOf(usUserId));
+ for(String botId : favoriteBotIDS) {
+ data.getUserBotId2Collected().put(botId, byteFill);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+ }
+
+ static void getUserSendFlowerInfo(final String userId) {
+ POOL.submit(() -> {
+ UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+ AppFlowerTBTintRepository repository = BaseHolder.getBean("appFlowerTBTintRepository");
+ for (OnProductDetail detail: ScheduleService.getAllOnProduct()) {
+ long sum = 0;
+ List nums = repository.getFlowerNumByUserIdAndBotAccount(Long.parseLong(userId), detail.getBotAccount());
+ for (Long num: nums) sum += num;
+ data.getUserBotId2Flowers().put(detail.getBotAccount(), sum);
+ }
+ });
+ }
+
+ static String getUsUserId(String userId, String accessToken) {
+ UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+ String usId = data.getJytUserId();
+ if (usId == null) {
+ usId = getUserIdByToken(accessToken, userId);
+ data.setJytUserId(usId);
+ }
+ return usId;
+ }
+
+ static String getUserIdByToken(String accessToken, String userId) {
+ try {
+ HashMap headers = new HashMap<>();
+ headers.put("App-Channel-Id", "JIAOYOUTIANXIA");
+ headers.put("Authorization", new StringBuilder(BEARER).append(accessToken).toString());
+ String str = OkHttp3Utils.doGet(USER_ID_BY_TOKEN, new HashMap<>(), headers);
+ log.info("getUserIdByToken:{}",str);
+ UserInfoByTokenResult info = JSON.parseObject(str, UserInfoByTokenResult.class);
+ if (info.getRetcode() == 0) {
+ Payload payload = JSON.parseObject(info.getPayload(), Payload.class);
+ String jytUserId = payload.getInfoId();
+ log.info("通过Token获取的用户在app端的id:{}", userId);
+ UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+ data.setJytUserId(jytUserId);
+ return jytUserId;
+ }
+ } catch (Exception e) {
+ log.error("获取郊游天下用户id出错:{}", ExceptionUtils.getStackTrace(e));
+ }
+ return null;
+ }
+
+ static void onLunchGetUserHistory(final String userId) {
+ DplbotServiceUtil.getPOOL().submit(() -> {
+ XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
+ UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+ HashMap userBotId2History = data.getUserBotId2History();
+ for (String botId: repository.getUserHostory(userId)) {
+ userBotId2History.put(botId, byteFill);
+ }
+ //log.info("用户历史记录:{}",USER_HISTORY);
+ });
+ }
+
+ static void onLunchFillUserBehaviorData(final String accessToken, final String userId) {
+ POOL.submit(() -> {
+ String jytUserId = DplbotServiceUtil.getUserIdByToken(accessToken, userId);
+ if (jytUserId != null) {
+ UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+ data.setJytUserId(jytUserId);
+ getUserFavorite(userId, jytUserId);
+ getUserSendFlowerInfo(userId);
+ }
+ });
+ }
+
+
+ public static ThreadPoolExecutor getPOOL() {
+ return POOL;
+ }
+
+ static String getDPLTemple(String path) {
+ String temple = null;
+ try {
+ temple = getJsonFromName(path);
+ } catch (IOException e) {
+ log.error("没有获取到json字符串:{}", e.toString());
+ }
+ return temple;
+ }
+
+ private static String getJsonFromName(String filename) throws IOException {
+ InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
+ InputStreamReader reader = new InputStreamReader(inputStream);
+ char[] buffer = new char[512];
+ int ln;
+ StringBuilder builder = new StringBuilder();
+ while ((ln = reader.read(buffer)) != -1) {
+ builder.append(buffer, 0, ln);
+ }
+ return builder.toString();
+ }
+
+ static boolean doesUserCollectThisBot(String botID, String accessToken, String userId) {
+ boolean collected = false;
+ if (accessToken != null) {
+ UserBehaviorData userData = USER_HISTORY.get(userId);
+ if (userData != null) {
+ collected = userData.getUserBotId2Collected().containsKey(botID);
+ } else {
+ getUserFavorite(userId, getUsUserId(userId, accessToken));
+ try {
+ AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
+ AppFavoriteTB tb = new AppFavoriteTB();
+ tb.setBotId(botID);
+ tb.setUserId(Integer.valueOf(getUsUserId(userId, accessToken)));
+ Example example = Example.of(tb);
+ collected = repository.exists(example);
+ } catch (Exception e) {
+ }
+ }
+ }
+ return collected;
+ }
+
+ static String getAsideText(String text) {
+ int i1 = text.indexOf("【");
+ int i2 = text.indexOf("@");
+ return text.substring(i1+1, i2);
+ }
+}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleService.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleService.java
index 3f8f680..eac603b 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleService.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleService.java
@@ -157,11 +157,15 @@ public class ScheduleService implements InitializingBean {
}
private void getAsideImg() {
- DplBotService.POOL.submit(() -> {
+ DplbotServiceUtil.getPOOL().submit(() -> {
List botIds = gameProjectTbRepository.getAllOnTableProductIds();
for (String botId: botIds) {
try {
botId = HZ1_BOT_TO_NX2.get(botId);
+ if (botId == null) {
+ log.info("找不到对应关系:{}",botId);
+ continue;
+ }
HashMap params = new HashMap<>();
params.put("include", "npcHeadImgUrl");
params.put("aipioneerUsername",botId);
@@ -286,14 +290,14 @@ public class ScheduleService implements InitializingBean {
}
public static String getAsideImgUrl(String botId, String name) {
- String url = DEFAULT_ASIDE_IMG_URL;
+ String url;
+ Map imgs = ASIDE_IMG.get(botId);
+ if (imgs == null) {
+ url = DEFAULT_ASIDE_IMG_URL;
+ } else {
+ url = imgs.get(name);
+ }
+ if (url == null) url = DEFAULT_ASIDE_IMG_URL;
return url;
-// Map imgs = ASIDE_IMG.get(botId);
-// if (imgs == null) {
-// url = DEFAULT_ASIDE_IMG_URL
-// }
-// String url = ASIDE_IMG.get(botId).get(name);
-// if (url == null) url = DEFAULT_ASIDE_IMG_URL;
-// return url;
}
}
--
libgit2 0.27.1