From 6f8712288eeae2fea779b80d46f4534e3ae82fd5 Mon Sep 17 00:00:00 2001
From: 苗权威 <1160292058@qq.com>
Date: Tue, 24 Sep 2019 20:59:52 +0800
Subject: [PATCH] 9.24
---
.idea/workspace.xml | 686 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java | 3 +--
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java | 2 +-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java | 8 ++++++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/TempleUtils.java | 10 +---------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoDocument.java | 3 ++-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/productInfo/ProductInfoUtils.java | 3 +++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java | 2 +-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFavoriteTB.java | 19 ++++++++++++-------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTB.java | 15 +++++++++------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppUserTB.java | 9 ++++++---
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/GameProjectTb.java | 5 +++--
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/OnProductDetail.java | 4 ++--
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/ProjectLabel.java | 6 +++---
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryBotIdTime.java | 7 +++++--
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryTB.java | 8 +++++---
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderIdTB.java | 5 ++++-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderTB.java | 16 +++++++++++-----
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/JYTUserResponse.java | 19 +++++++++++++++++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/Payload.java | 19 -------------------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/UserBehaviorData.java | 8 ++++----
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFavoriteTBRepository.java | 18 +++---------------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBRepository.java | 6 ------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBTintRepository.java | 5 +----
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/GameProjectTbRepository.java | 3 ---
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/ProjectLabelRepository.java | 2 +-
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuHistoryTBRepository.java | 3 ---
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuOrderTBIdRepository.java | 3 ---
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotService.java | 2113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java | 385 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java | 9 +++++----
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RunnableService.java | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleService.java | 32 ++++++++++++++++++++++++++++++--
33 files changed, 1728 insertions(+), 1808 deletions(-)
create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/JYTUserResponse.java
delete mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/Payload.java
create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RunnableService.java
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index e0e628c..be9c92b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,17 +3,35 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
@@ -57,89 +75,69 @@
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
+
+
+
+
+
-
-
+
+
-
-
-
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
-
-
-
-
+
+
@@ -158,11 +156,6 @@
- PERSON_MOODURL
- OFFLINE_SERVER
- successUpLoadFileIds
- data
- log.info
allRepeateName2Id
nameRepeats
allRepeateId2Info
@@ -188,6 +181,11 @@
T
userId
tts
+ getAccessToken
+ onBuyEvent
+ price
+ appUserId
+ asideText
OPENID_CACHE
@@ -203,25 +201,6 @@
@@ -271,11 +269,11 @@
-
+
-
+
@@ -286,8 +284,8 @@
-
-
+
+
@@ -299,6 +297,7 @@
+
@@ -360,6 +359,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -384,6 +394,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -418,6 +440,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -439,7 +503,8 @@
-
+
+
@@ -447,7 +512,9 @@
-
+
+
+
@@ -456,14 +523,12 @@
-
-
@@ -477,7 +542,7 @@
-
+
@@ -529,9 +594,9 @@
-
-
-
+
+
+
@@ -904,7 +969,6 @@
-
@@ -929,14 +993,15 @@
+
+
+
-
-
@@ -1039,7 +1104,8 @@
-
+
+
@@ -1049,7 +1115,7 @@
-
+
@@ -1061,27 +1127,26 @@
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
-
+
@@ -1110,419 +1175,364 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
+
+
-
+
-
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
-
-
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
-
-
-
-
+
+
-
+
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
@@ -1531,8 +1541,22 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java
index 6ba4273..edc2911 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java
@@ -8,9 +8,8 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
-//@EntityScan(basePackages = {"ai.qiwu.com.xiaoduhome.entity"})
-//@EnableJpaRepositories(basePackages = {"ai.qiwu.com.xiaoduhome.repository"})
@EnableScheduling
+@EnableJpaAuditing
public class XiaoduhomeApplication {
public static void main(String[] args) {
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java
index fbf799f..0dfca8f 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java
@@ -51,7 +51,7 @@ public interface Constants {
String COLLECTED_IMG_URL = "https://aliyun-hz1.chewrobot.com/xiaoduhome/image/collec.png";
String UN_COLLECTED_IMG_URL = "https://aliyun-hz1.chewrobot.com/xiaoduhome/image/uncollec.png";
- String DEFAULT_ASIDE_IMG_URL = "http://aws-nx2.chewrobot.com:8888/Editor/Editor/static/img/default.png";
+ String DEFAULT_ASIDE_IMG_URL = "http://aws-nx2.chewrobot.com:8888/Editor/upload/img/npc/2019/06/10100450218.png";
}
interface PRODUCT_INTRO {
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java
index 1d2be02..e55c89c 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java
@@ -116,6 +116,14 @@ public class Utils {
return botNames;
}
+ public static Timestamp getCurTime() {
+ return new Timestamp(new Date().getTime());
+ }
+
+ public static Timestamp getCurTime(long curTimeMills) {
+ return new Timestamp(new Date(curTimeMills).getTime());
+ }
+
public static void main(String[] args) throws ParseException {
String s = "[{\"type\": \"SendEvent\",\"componentId\":\"%s\"}]";
//System.out.println(String.format(s, "gsagh"));
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/TempleUtils.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/TempleUtils.java
index b6b92b6..14fb1ce 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/TempleUtils.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/TempleUtils.java
@@ -9,7 +9,6 @@ import ai.qiwu.com.xiaoduhome.common.temple.funny.FunnyUtil;
import ai.qiwu.com.xiaoduhome.common.temple.onLunch.LunchBotData;
import ai.qiwu.com.xiaoduhome.common.temple.playUpdate.PlayUpdateDocument;
import ai.qiwu.com.xiaoduhome.common.temple.playUpdate.PlayUpdatePojo;
-import ai.qiwu.com.xiaoduhome.common.temple.rank.RankBotInfo;
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.RecommandBotInfo;
@@ -18,7 +17,6 @@ import ai.qiwu.com.xiaoduhome.common.temple.recommand.RecommandPojo;
import ai.qiwu.com.xiaoduhome.entity.primary.GameProjectTb;
import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
import ai.qiwu.com.xiaoduhome.entity.secondary.XiaoDuHistoryBotIdTime;
-import ai.qiwu.com.xiaoduhome.pojo.dpl.Data;
import ai.qiwu.com.xiaoduhome.pojo.dpl.Item;
import ai.qiwu.com.xiaoduhome.pojo.dpl.MyDocument;
import ai.qiwu.com.xiaoduhome.pojo.pageData.HistoryData;
@@ -26,9 +24,6 @@ import ai.qiwu.com.xiaoduhome.repository.primary.AppFavoriteTBRepository;
import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuHistoryBotTimeRepository;
import ai.qiwu.com.xiaoduhome.service.ScheduleService;
import com.alibaba.fastjson.JSON;
-import com.baidu.dueros.data.response.directive.dpl.Document;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
@@ -40,14 +35,11 @@ import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
-import java.util.Date;
import java.util.List;
-import static ai.qiwu.com.xiaoduhome.common.Constants.CATEGORY_IMG_URL.GU_FENG;
import static ai.qiwu.com.xiaoduhome.common.Constants.DPL_COMPONENT_ID.PRE_CATEGORY;
import static ai.qiwu.com.xiaoduhome.common.Constants.IMG_CUSTOM_PREFIX;
import static ai.qiwu.com.xiaoduhome.common.Constants.IMG_PREFIX;
-import static ai.qiwu.com.xiaoduhome.common.temple.play.PlayUtils.getPlayDocument;
/**
* @author 苗权威
@@ -249,7 +241,7 @@ public class TempleUtils {
return historyDocument;
}
- public static CollectHistoryDocument getCollectPage(Integer userId) {
+ public static CollectHistoryDocument getCollectPage(Long userId) {
CollectHistoryDocument collectHistoryDocument = JSON.parseObject(getDPLTemple("static/json/collectPage.json"), CollectHistoryDocument.class);
AppFavoriteTBRepository favorite = BaseHolder.getBean("appFavoriteTBRepository");
List favoriteProducts = favorite.getFavoriteBotIds(userId);
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
index 548a108..f04dc1e 100644
--- 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
@@ -1,5 +1,6 @@
package ai.qiwu.com.xiaoduhome.common.temple.productInfo;
+import com.baidu.dueros.data.response.directive.dpl.Document;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
@@ -11,6 +12,6 @@ import lombok.Setter;
@Getter
@Setter
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-public class ProductInfoDocument {
+public class ProductInfoDocument extends Document {
private ProductInfoMainTemplate mainTemplate;
}
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
index 80b92b6..781bd2a 100644
--- 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
@@ -21,6 +21,7 @@ public class ProductInfoUtils {
ProductInfoDocument document = new ProductInfoDocument();
ProductInfoMainTemplate mainTemplate = new ProductInfoMainTemplate();
document.setMainTemplate(mainTemplate);
+ document.setDuration(120000);
mainTemplate.getItems().addAll(Arrays.asList(BACK_IMG, HEADER, buildLeftRightPart(src, productName, time,
author, labelText, introText, startComponId, flowerId, flowerText, collectId, collectSrc, collectText), FOOTER));
return document;
@@ -83,6 +84,7 @@ public class ProductInfoUtils {
name.setMarginTop("10dp");
name.setFontSize("38dp");
name.setMarginLeft("5%");
+ name.setText(productName);
return name;
}
@@ -210,6 +212,7 @@ public class ProductInfoUtils {
collectCon.setType("Container");
collectCon.setAlignItems("center");
collectCon.setMarginLeft("120dp");
+ collectCon.setComponentId(collectId);
collectCon.setOnClick(Collections.singletonList(new Event("SendEvent", collectId)));
ProductInfoPojo image = new ProductInfoPojo();
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java
index 9caca18..84f5bd6 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java
@@ -29,7 +29,7 @@ public class XiaoDuHomeController {
//service.disableVerify();
service.enableVerify();
String str = service.run();
- log.info("响应信息:{}", str);
+ //log.info("响应信息:{}", str);
return str;
} catch (Exception e) {
e.printStackTrace();
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFavoriteTB.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFavoriteTB.java
index 1db5038..06d6e11 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFavoriteTB.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFavoriteTB.java
@@ -10,6 +10,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.sql.Date;
+import java.sql.Timestamp;
/**
* @author 苗权威
@@ -17,24 +18,28 @@ import java.sql.Date;
*/
@Entity
@Table(name = "app_favorite_tb")
-@Data
+@EntityListeners(AuditingEntityListener.class)
+@Getter
+@Setter
public class AppFavoriteTB {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
+ private Long id;
@Column(name = "bot_username")
private String botId;
@Column(name = "user_id")
- private Integer userId;
+ private Long userId;
@Column
private Integer module;
- @Column(name = "gmt_create")
- private java.sql.Date createTime;
+ @CreatedDate
+ @Column(name = "gmt_create", updatable = false, nullable = false)
+ private Timestamp createTime;
- @Column(name = "gmt_modified")
- private Date updateTime;
+ @LastModifiedDate
+ @Column(name = "gmt_modified", nullable = false)
+ private Timestamp updateTime;
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTB.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTB.java
index 0d02cbd..39e5bbd 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTB.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppFlowerTB.java
@@ -18,11 +18,12 @@ import java.sql.Timestamp;
*/
@Entity
@Table(name = "app_flower_tb")
+@EntityListeners(AuditingEntityListener.class)
@Data
public class AppFlowerTB {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
+ private Long id;
@Column
private Integer module;
@@ -31,23 +32,25 @@ public class AppFlowerTB {
private String botName;
@Column(name = "user_id")
- private Integer userId;
+ private Long userId;
@Column(name = "unit_price")
private Double unitPrice;
@Column
- private Integer number;
+ private Long number;
@Column(name = "order_id")
- private Integer orderId;
+ private Long orderId;
@Column
private Integer status;
- @Column(name = "gmt_create")
+ @CreatedDate
+ @Column(name = "gmt_create", updatable = false, nullable = false)
private Timestamp createTime;
- @Column(name = "gmt_modified")
+ @LastModifiedDate
+ @Column(name = "gmt_modified", nullable = false)
private Timestamp updateTime;
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppUserTB.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppUserTB.java
index 174b422..d273217 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppUserTB.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/AppUserTB.java
@@ -3,6 +3,8 @@ package ai.qiwu.com.xiaoduhome.entity.primary;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
@@ -13,18 +15,19 @@ import java.util.Date;
*/
@Entity
@Table(name = "app_user_tb")
+@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
-@ToString
public class AppUserTB {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "info_id")
- private Integer infoId;
+ private Long infoId;
@Column(name = "user_phone")
private String phone;
- @Column(name = "gmt_create")
+ @CreatedDate
+ @Column(name = "gmt_create", updatable = false, nullable = false)
private Date createTime;
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/GameProjectTb.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/GameProjectTb.java
index e2f9334..7fb7ddf 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/GameProjectTb.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/GameProjectTb.java
@@ -3,6 +3,7 @@ package ai.qiwu.com.xiaoduhome.entity.primary;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
@@ -18,8 +19,8 @@ import java.util.Date;
@ToString
public class GameProjectTb {
@Id
- @GeneratedValue
- private Integer id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
@Column
private String intro;
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/OnProductDetail.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/OnProductDetail.java
index b9418f3..a47e122 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/OnProductDetail.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/OnProductDetail.java
@@ -19,8 +19,8 @@ import java.util.List;
@ToString
public class OnProductDetail {
@Id
- @GeneratedValue
- private Integer id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
@Column
private String intro;
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/ProjectLabel.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/ProjectLabel.java
index 01f51a6..a8733f4 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/ProjectLabel.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/primary/ProjectLabel.java
@@ -17,12 +17,12 @@ import javax.persistence.*;
@ToString
public class ProjectLabel {
@Id
- @GeneratedValue
- private Integer id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
@Column
private String name;
@Column(name = "project_id")
- private String productId;
+ private Long productId;
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryBotIdTime.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryBotIdTime.java
index 780663d..27c19b4 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryBotIdTime.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryBotIdTime.java
@@ -1,6 +1,8 @@
package ai.qiwu.com.xiaoduhome.entity.secondary;
import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
@@ -11,11 +13,12 @@ import javax.persistence.*;
*/
@Entity
@Table(name = "xiaodu_history_tb")
-@Data
+@Getter
+@Setter
public class XiaoDuHistoryBotIdTime {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
+ private Long id;
@Column(name = "bot_id")
private String botId;
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryTB.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryTB.java
index 87313d1..5861de4 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryTB.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuHistoryTB.java
@@ -18,13 +18,13 @@ import java.sql.Timestamp;
*/
@Getter
@Setter
-@ToString
@Entity
@Table(name = "xiaodu_history_tb")
+@EntityListeners(AuditingEntityListener.class)
public class XiaoDuHistoryTB {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
+ private Long id;
@Column(name = "bot_id")
private String botId;
@@ -35,9 +35,11 @@ public class XiaoDuHistoryTB {
@Column(name = "last_time")
private Long lastTime;
- @Column(name = "create_time")
+ @CreatedDate
+ @Column(name = "create_time", updatable = false, nullable = false)
private Timestamp createTime;
+ @LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderIdTB.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderIdTB.java
index d165ecf..22501df 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderIdTB.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderIdTB.java
@@ -1,6 +1,8 @@
package ai.qiwu.com.xiaoduhome.entity.secondary;
import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
@@ -11,7 +13,8 @@ import javax.persistence.*;
*/
@Entity
@Table(name = "xiaodu_order_tb")
-@Data
+@Getter
+@Setter
public class XiaoDuOrderIdTB {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderTB.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderTB.java
index cf372e7..72d5236 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderTB.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/entity/secondary/XiaoDuOrderTB.java
@@ -1,6 +1,8 @@
package ai.qiwu.com.xiaoduhome.entity.secondary;
import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.CreatedDate;
@@ -17,17 +19,19 @@ import java.util.Date;
*/
@Entity
@Table(name = "xiaodu_order_tb")
-@Data
+@EntityListeners(AuditingEntityListener.class)
+@Getter
+@Setter
public class XiaoDuOrderTB {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
+ private Long id;
@Column(name = "bot_id")
private String botId;
@Column(name = "app_user_id")
- private String appUserId;
+ private Long appUserId;
@Column(name = "xiaodu_user_id")
private String xiaoduUserId;
@@ -56,9 +60,11 @@ public class XiaoDuOrderTB {
@Column(name = "status")
private Boolean status;
- @Column(name = "create_time")
+ @CreatedDate
+ @Column(name = "create_time", updatable = false, nullable = false)
private Timestamp createTime;
- @Column(name = "update_time")
+ @LastModifiedDate
+ @Column(name = "update_time", nullable = false)
private Timestamp updateTime;
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/JYTUserResponse.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/JYTUserResponse.java
new file mode 100644
index 0000000..c3e2d5b
--- /dev/null
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/JYTUserResponse.java
@@ -0,0 +1,19 @@
+package ai.qiwu.com.xiaoduhome.pojo;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * @author 苗权威
+ * @dateTime 19-8-19 下午1:06
+ */
+@Getter
+@Setter
+@ToString
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class JYTUserResponse {
+ private String infoId;
+ private String userPhone;
+}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/Payload.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/Payload.java
deleted file mode 100644
index e9d1dc5..0000000
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/Payload.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package ai.qiwu.com.xiaoduhome.pojo;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-/**
- * @author 苗权威
- * @dateTime 19-8-19 下午1:06
- */
-@Getter
-@Setter
-@ToString
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class Payload {
- private String infoId;
- private String userPhone;
-}
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 b356a7b..34d896f 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
@@ -2,6 +2,7 @@ package ai.qiwu.com.xiaoduhome.pojo;
import lombok.Getter;
import lombok.Setter;
+import lombok.ToString;
import java.util.HashMap;
import java.util.List;
@@ -12,16 +13,15 @@ import java.util.List;
*/
@Getter
@Setter
+@ToString
public class UserBehaviorData {
// 用户浏览历史
- private volatile HashMap userBotId2History = new HashMap<>();
+ private volatile HashMap userBotId2History = 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/repository/primary/AppFavoriteTBRepository.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFavoriteTBRepository.java
index 27eb309..d94c34c 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
@@ -16,24 +16,12 @@ import java.util.List;
*/
@Repository
public interface AppFavoriteTBRepository extends JpaRepository {
-
- @Modifying
- @Transactional(rollbackFor = Exception.class)
- @Query(value = "INSERT INTO app_favorite_tb (bot_username,module,user_id,gmt_create,gmt_modified) VALUES (?1, 0, ?2, now(), now())",nativeQuery = true)
- void insertFavorite(String botId, Integer userId);
-
- @Modifying
- @Transactional(rollbackFor = Exception.class)
- @Query(value = "DELETE FROM app_favorite_tb WHERE bot_username=?1 AND user_id=?2",nativeQuery = true)
- void deleteFavorite(String botId, Integer userId);
-
@Override
boolean exists(Example example);
- @Override
- S save(S s);
-
- void deleteByBotIdAndUserId(String botId, Integer userId);
+ @Modifying
+ @Transactional
+ void deleteByBotIdAndUserId(String botId, Long userId);
@Query(value="SELECT bot_username from app_favorite_tb where user_id=?1", nativeQuery = true)
List getFavoriteBotIds(Long userId);
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBRepository.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBRepository.java
index 6053e7c..0f53741 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBRepository.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/AppFlowerTBRepository.java
@@ -16,12 +16,6 @@ import java.sql.Timestamp;
*/
@Repository
public interface AppFlowerTBRepository extends JpaRepository {
-
- @Modifying
- @Transactional(rollbackFor = Exception.class)
- @Query(value = "INSERT INTO app_flower_tb (module,bot_username,user_id,unit_price,number,order_id,status,gmt_create,gmt_modified) VALUES (0,?1,?2,1,1,?3,1,?4,?4)",nativeQuery = true)
- void insertOrder(String botId, String userId, String orderId, Timestamp time);
-
@Override
S save(S s);
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 3df7026..1fee658 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
@@ -13,10 +13,7 @@ import java.util.List;
*/
@Repository
public interface AppFlowerTBTintRepository extends JpaRepository {
-
- AppFlowerTBTiny getByUserIdAndBotIdAndUnitPrice(Integer userId, String botId, Double unitPrice);
-
- List getByUserIdAndBotId(Integer userId, String botId);
+ List getByUserIdAndBotId(Long 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/primary/GameProjectTbRepository.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/GameProjectTbRepository.java
index f1c86a1..35cfa7e 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/GameProjectTbRepository.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/GameProjectTbRepository.java
@@ -20,9 +20,6 @@ public interface GameProjectTbRepository extends JpaRepository= (select floor(RAND()*(select MAX(id) from game_project_tb))) order by id limit 10", nativeQuery = true)
List recommendList();
- @Query(value = "select p.id,p.intro,p.name,p.watch,p.banner_img_url,p.apply_status,p.bot_account,p.user_nickname from game_project_tb as p,game_project_label_tb as l where l.name= :category and p.id = l.project_id and p.apply_status=1", nativeQuery = true)
- List categoryProject(@Param("category") String category);
-
@Query(value = "select p.bot_account from game_project_tb as p,game_project_label_tb as l where l.name=?1 and p.apply_status=1 and p.id = l.project_id",nativeQuery = true)
List categoryProList(String category);
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/ProjectLabelRepository.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/ProjectLabelRepository.java
index 2d3d0da..4de4c56 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/ProjectLabelRepository.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/primary/ProjectLabelRepository.java
@@ -16,5 +16,5 @@ import java.util.List;
public interface ProjectLabelRepository extends JpaRepository {
@Query(value = "SELECT name FROM game_project_label_tb WHERE project_id = :productId", nativeQuery = true)
- List productLabels(@Param("productId") Integer productId);
+ List productLabels(@Param("productId") Long productId);
}
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 1113a52..0b54d4c 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
@@ -13,9 +13,6 @@ import java.util.List;
* @dateTime 19-8-26 下午2:21
*/
public interface XiaoDuHistoryTBRepository extends JpaRepository {
- @Query(value = "SELECT bot_id FROM xiaodu_history_tb WHERE xiaodu_user_id=?1 ORDER BY last_time LIMIT 15", nativeQuery = true)
- List getHistory(String xiaoduUserId);
-
@Query(value = "SELECT DISTINCT xiaodu_user_id FROM xiaodu_history_tb", nativeQuery = true)
List getAllUser();
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuOrderTBIdRepository.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuOrderTBIdRepository.java
index 41972d7..f00b894 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuOrderTBIdRepository.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/repository/secondary/XiaoDuOrderTBIdRepository.java
@@ -10,9 +10,6 @@ import org.springframework.transaction.annotation.Transactional;
* @dateTime 19-8-22 下午4:28
*/
public interface XiaoDuOrderTBIdRepository extends JpaRepository {
-
- XiaoDuOrderIdTB getByXiaoduUserIdAndBotIdAndUnitPrice(String xiaoduUserId, String botId, Integer unitPrice);
-
@Override
S save(S s);
}
\ No newline at end of file
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 d2a224a..52792ba 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.ProductInfoDocument;
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;
@@ -49,6 +50,7 @@ import com.baidu.dueros.data.response.directive.dpl.event.UserEvent;
import com.baidu.dueros.data.response.directive.pay.Buy;
import com.baidu.dueros.data.response.directive.pay.Charge;
import com.baidu.dueros.model.Response;
+import com.baidu.dueros.nlu.Intent;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -80,56 +82,14 @@ import static ai.qiwu.com.xiaoduhome.service.ScheduleService.*;
*/
@Slf4j
public class DplBotService extends BaseBot {
- //private static final MyDocument LOAD_DOCUMENT;
-
- private static final MyDocument PROD_INFO;
-
private static final MyDocument FIRST_PAGE;
-// private static final MyDocument CATEGORY_PROD;
-// private static final Item CATEGORY_PROD_LIST;
-// private static final Item CATEGORY_PROD_HEAD;
-
- 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());
-
- //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 final byte byteFill = 1;
-
static {
-// LOAD_DOCUMENT = JSON.parseObject(getDPLTemple("static/json/onLunch2.json"), MyDocument.class);
-// List- thirdRow = LOAD_DOCUMENT.getMainTemplate().getItems().get(1).getItems().get(1).getItems();
-// List l1 = new ArrayList<>();
-// l1.add(TempleUtils.getFrameRakking());
-// thirdRow.get(0).setFirstItem(l1);
-// thirdRow.get(0).getItems().get(0).setData(buildDataList(ScheduleService.RANKING_LIST, 1));
-//
-// List l2 = new ArrayList<>();
-// l2.add(TempleUtils.getFrameRecommand());
-// thirdRow.get(1).setFirstItem(l2);
-// thirdRow.get(1).getItems().get(0).setData(buildDataList(ScheduleService.RECOMMEND_LIST, 11));
-//
-// List l3 = new ArrayList<>();
-// l3.add(TempleUtils.getFrameCategory());
-// thirdRow.get(2).setFirstItem(l3);
-// thirdRow.get(2).getItems().get(0).setData(buildCategoryDataList());
-
-// CATEGORY_PROD = JSON.parseObject(getDPLTemple("static/json/categoryPro.json"), MyDocument.class);
-// 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(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 {
@@ -142,11 +102,9 @@ public class DplBotService extends BaseBot {
this.addDirective(renderDocument);
OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, Constants.WelcomeWord.WELCOME);
// 初次进入时创建用户的行为信息,包括历史记录,送花数,收藏记录
- // 历史记录
- DplbotServiceUtil.onLunchGetUserHistory(getUserId());
- String jytUserId;
- if (getAccessToken() != null) {
- // 收藏记录,送花数,郊游天下id
+ // 历史记录,收藏记录,送花数,郊游天下id
+ if (DplbotServiceUtil.USER_HISTORY.get(getUserId()) == null) {
+ log.info("onLunch:空");
DplbotServiceUtil.onLunchFillUserBehaviorData(getAccessToken(), getUserId());
}
return new Response(outputSpeech);
@@ -170,7 +128,7 @@ public class DplBotService extends BaseBot {
return detail.getResponse();
}
try {
- Future future = DplbotServiceUtil.getPOOL().submit(new Task(intentRequest, this));
+ Future future = DplbotServiceUtil.getPOOL().submit(new Task(intentRequest));
future.get(2200, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException e) {
log.error("获取任务执行结果出错:{}", e.toString());
@@ -249,6 +207,8 @@ public class DplBotService extends BaseBot {
else if (Constants.PRE_PRODUCT_IMG.equals((componentPrefix = componentId.substring(0, 5)))) {
// 作品图片点击事件
log.info("图片点击触发");
+ String accessToken = getAccessToken();
+ String userId = getUserId();
String productName = componentId.substring(5);
OnProductDetail productDetail = ScheduleService.PRODUCT_NAME_DETAIL.get(productName);
@@ -265,54 +225,42 @@ public class DplBotService extends BaseBot {
for (String label: productDetail.getLabels()) {
labels.append(Constants.PRODUCT_INTRO.SPACE).append(label);
}
- productDetail.getIntro();
- ProductInfoUtils.getProductINfoDocument(imgUrl, productName, );
-
- // "start product" container button
+ String intro = productDetail.getIntro();
String enterProName = new StringBuilder(Constants.PRE_ENTER_PRODUCT).append(productName).toString();
- icons.get(0).setComponentId(enterProName);
- icons.get(0).getOnClick().get(0).setComponentId(enterProName);
- String accessToken = getAccessToken();
+ // "start product" container button
+ String flowers, flowerReward,collectText, collectUrl, collectComId;
if (accessToken != null) {
// flower container button
- Integer count = getUserSendFlowerNum(productDetail.getBotAccount());
- Item flower = icons.get(1);
- flower.getItems().get(1).setText(USER_SEND_FLOWER+count);
- String flowerReward = new StringBuilder(FLOWE).append(productDetail.getBotAccount()).toString();
- flower.setComponentId(flowerReward);
- flower.getOnClick().get(0).setComponentId(flowerReward);
+ Long flowerCount = DplbotServiceUtil.getUserSendFlowerNum(productDetail.getBotAccount(), userId, accessToken);
+ flowers = USER_SEND_FLOWER+flowerCount;
+ flowerReward = new StringBuilder(FLOWE).append(productDetail.getBotAccount()).toString();
// collection container button
- boolean collec = didUserCollecThisProduct(productDetail.getBotAccount());
- Item collecButton = icons.get(2);
+ boolean collec = DplbotServiceUtil.didUserCollecThisProduct(productDetail.getBotAccount(), userId,
+ accessToken, getSessionAttribute("userId"));
if (collec) {
- collecButton.getItems().get(1).setText(COLLECED);
- collecButton.getItems().get(0).setSrc(COLLECTED_IMG_URL);
- String unCollecId = new StringBuilder(UN_COLLEC_ID).append(productDetail.getBotAccount()).toString();
- collecButton.setComponentId(unCollecId);
- collecButton.getOnClick().get(0).setComponentId(unCollecId);
+ collectText = COLLECED;
+ collectUrl = COLLECTED_IMG_URL;
+ collectComId = new StringBuilder(UN_COLLEC_ID).append(productDetail.getBotAccount()).toString();
} else {
- collecButton.getItems().get(1).setText(UN_COLLEC);
- collecButton.getItems().get(0).setSrc(UN_COLLECTED_IMG_URL);
- String collecId = new StringBuilder(COLLEC_ID).append(productDetail.getBotAccount()).toString();
- collecButton.setComponentId(collecId);
- collecButton.getOnClick().get(0).setComponentId(collecId);
+ collectText = UN_COLLEC;
+ collectUrl = UN_COLLECTED_IMG_URL;
+ collectComId = new StringBuilder(COLLEC_ID).append(productDetail.getBotAccount()).toString();
}
} else {
- Item flower = icons.get(1);
- flower.getItems().get(1).setText(FLOWER);
- flower.setComponentId(FLOWER_LOAD);
- flower.getOnClick().get(0).setComponentId(FLOWER_LOAD);
-
- Item collecButton = icons.get(2);
- collecButton.getItems().get(1).setText(UN_COLLEC);
- collecButton.getItems().get(0).setSrc(UN_COLLECTED_IMG_URL);
- collecButton.setComponentId(FLOWER_LOAD);
- collecButton.getOnClick().get(0).setComponentId(FLOWER_LOAD);
+ flowers = FLOWE;
+ flowerReward = FLOWER_LOAD;
+
+ collectText = UN_COLLEC;
+ collectUrl = UN_COLLECTED_IMG_URL;
+ collectComId = FLOWER_LOAD;
}
- RenderDocument renderDocument = new RenderDocument(PROD_INFO);
+ ProductInfoDocument document = ProductInfoUtils.getProductINfoDocument(imgUrl, productName, time, author, labels.toString(),
+ intro, enterProName, flowerReward, flowers, collectComId, collectUrl, collectText);
+
+ RenderDocument renderDocument = new RenderDocument(document);
this.addDirective(renderDocument);
//this.addDirective(new PushStack());
String trace = getSessionAttribute(BACK_TRACE);
@@ -337,7 +285,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());
}
@@ -345,10 +293,7 @@ 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);
@@ -356,7 +301,8 @@ public class DplBotService extends BaseBot {
if (keng.equals("清新传")) keng = "清新传{/zhuan4/}";
String botID = ScheduleService.getProductNameDetail().get(keng).getBotAccount();
PlayDocument document = PlayUtils.getPlayDocument(productName, aside, ScheduleService.getAsideImgUrl(botID, aside),
- data.getAudio(), text, doesUserCollectThisBot(botID));
+ data.getAudio(), text, DplbotServiceUtil.didUserCollecThisProduct(botID, getUserId(),
+ getAccessToken(), getSessionAttribute("userId")));
RenderDocument render = new RenderDocument(document);
this.setSessionAttribute(PRE_COLLE, null);
@@ -371,12 +317,19 @@ public class DplBotService extends BaseBot {
if (FLOWER_LOAD.equals(componentId)) {
return load();
} else {
- Buy buy = new Buy(FLOWER_PRODUCT_ID);
- String token = new String(Base64.getEncoder().encode(componentId.substring(5).getBytes()), StandardCharsets.UTF_8);
- buy.setToken(token);
- addDirective(buy);
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, REWARD_FLOWER);
- return new Response(outputSpeech);
+// Buy buy = new Buy(FLOWER_PRODUCT_ID);
+// String token = new String(Base64.getEncoder().encode(componentId.substring(5).getBytes()), StandardCharsets.UTF_8);
+// buy.setToken(token);
+// addDirective(buy);
+// OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, REWARD_FLOWER);
+// return new Response(outputSpeech);
+ Charge charge = DplbotServiceUtil.sendOneFlowerByCharge(getUserId(), getSessionAttribute("userId"),
+ getAccessToken(), getSessionAttribute("trace"));
+ if (charge != null) {
+ addDirective(charge);
+ return buildErrorResponse("扫描屏幕上的二维码完成支付");
+ }
+ return new Response();
}
} else if ("loadingPage".equals(componentId)) {
RenderDocument renderDocument = new RenderDocument(LunchUtils.getLunchDocument());
@@ -388,54 +341,16 @@ public class DplBotService extends BaseBot {
final String botId = componentId.substring(7);
if (isUnCollect) {
//取消收藏
- try {
- final String userId = getUsUserId();
- if (userId == null) throw new IllegalStateException("通过accessToken获取用户id失败");
-
- POOL.submit(new UnCollectThread(botId, userId));
- POOL.execute(() -> {
- UserBehaviorData data = USER_HISTORY.get(getUserId());
- if(data == null) getUserFavorite();
- else {
- data.getUserBotId2Collected().remove(botId);
- }
- });
-// QiWuResponse response = RequestTerminal.requestTerminate(CHAT_COLLECT, userId);
-// log.info("chat 取消收藏 的返回{}", response);
- } catch (Exception e) {
- log.info("取消收藏失败:{}", e.toString());
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, FAIL_COLLECT);
- return new Response(outputSpeech);
- }
+ DplbotServiceUtil.userUnCollectTheBotInPool(getUserId(), botId, getAccessToken());
changeIconIdTextAfterCollect(false, botId);
} else {
//收藏
- try {
- String userId = getUsUserId();
- if (userId == null) throw new IllegalStateException("通过accessToken获取用户id失败");
-
- POOL.submit(new CollectThread(botId, userId));
- POOL.execute(() -> {
- UserBehaviorData data = USER_HISTORY.get(getUserId());
- if(data == null) getUserFavorite();
- else {
- data.getUserBotId2Collected().put(botId, byteFill);
- }
- });
-// QiWuResponse response = RequestTerminal.requestTerminate(CHAT_COLLECT, userId);
-// log.info("chat 我要收藏 的返回{}", response);
- } catch (Exception e) {
- log.info("收藏失败:{}", e.toString());
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, FAIL_COLLECT);
- return new Response(outputSpeech);
- }
+ DplbotServiceUtil.userCollectTheBotInPool(getUserId(), botId, getAccessToken());
changeIconIdTextAfterCollect(true, botId);
}
} else if (PRE_CATEGORY.equals(componentPrefix)) {
String category = componentId.substring(5);
-// displayCategoryProd(category);
-// CATEGORY_PROD_HEAD.setHeaderTitle(category);
-// RenderDocument render = new RenderDocument(CATEGORY_PROD);
+ // 分类推荐页面相同
RecommandDocument document = RecommendUtil.getCategory(0, category);
if (document == null) return buildErrorResponse("不好意思该分类还没有作品");
RenderDocument render = new RenderDocument(document);
@@ -445,7 +360,7 @@ public class DplBotService extends BaseBot {
this.setSessionAttribute("pageSign","5");
this.setSessionAttribute("trace","05");
} else if ("playButton".equals(componentId)) {
- return buildErrorResponse("请直接对我下达语音指令,如:我要送花或者我要收藏或取消收藏");
+ return buildErrorResponse("您可以直接对我说我要送花或者我要收藏或取消收藏");
}
// else if ("funnyChange".equals(componentId)) {
// ExecuteCommands executeCommands = new ExecuteCommands();
@@ -460,108 +375,25 @@ public class DplBotService extends BaseBot {
@Override
protected Response onSessionEnded(SessionEndedRequest sessionEndedRequest) {
+ DplbotServiceUtil.writeTheUserHistoryInData(getUserId());
LAST_OUTTIME_RESULT.remove(getUserId());
return new Response();
}
- @Override
- protected Response onBuyEvent(BuyEvent buyEvent) {
- com.baidu.dueros.data.request.buy.event.Payload payload = buyEvent.getPayload();
- String result = payload.getPurchaseResult().getPurchaseResult();
- log.info("此次支付结果:"+result+";msg: "+payload.getMessage());
- if (result.equals("SUCCESS")) {
- log.info("支付成功");
- POOL.submit(new SendFlowerThread(buyEvent));
- POOL.submit(new SendFlowerBuyToXiaoduTB(buyEvent));
- return buildErrorResponse("感谢大人赏的花");
- }
- return buildErrorResponse("哎呀,没有支付成功");
- }
-
- class SendFlowerBuyToXiaoduTB implements Runnable {
- BuyEvent buyEvent;
-
- SendFlowerBuyToXiaoduTB(BuyEvent buyEvent) {
- this.buyEvent = buyEvent;
- }
- @Override
- public void run() {
- try {
- String baiduOrderReferenceId = buyEvent.getPayload().getBaiduOrderReferenceId();
- long timeStamp = Long.parseLong(buyEvent.getTimestamp())*1000;
- String botId = new String(Base64.getDecoder().decode(buyEvent.getToken()), StandardCharsets.UTF_8);
- String userId = getSessionAttribute("userId");
- Integer unitePrice = Integer.parseInt(Config.getProperty("unitPrice", Constants.UNIT_PRICE));
- if (userId == null) userId = getUserIdByToken(getAccessToken());
- if (userId == null) throw new Exception("未获取到用户id");
- XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
- XiaoDuOrderTB orderTB = new XiaoDuOrderTB();
- orderTB.setAppUserId(userId);
- orderTB.setBotId(botId);
- orderTB.setNumber(1);
- orderTB.setIsBuy(true);
- orderTB.setOrderId(baiduOrderReferenceId);
- orderTB.setTimeStamp(timeStamp);
- orderTB.setUnitPrice(unitePrice);
- orderTB.setXiaoduUserId(getUserId());
- Timestamp timestamp = new Timestamp(System.currentTimeMillis());
- orderTB.setCreateTime(timestamp);
- orderTB.setUpdateTime(timestamp);
- XiaoDuOrderTB response = repository.save(orderTB);
- if (response == null) throw new Exception("向interface_db中的xiaodu_order_tb插入数据失败");
- } catch (Exception e) {
- log.error("用户成功支付,xiaodu_order_tb操作出现错误:{}",e.toString());
- }
- }
- }
-
- class SendFlowerThread implements Runnable {
- BuyEvent buyEvent;
-
- SendFlowerThread(BuyEvent buyEvent) {
- this.buyEvent = buyEvent;
- }
+// @Override
+// protected Response onBuyEvent(BuyEvent buyEvent) {
+// com.baidu.dueros.data.request.buy.event.JYTUserResponse payload = buyEvent.getPayload();
+// String result = payload.getPurchaseResult().getPurchaseResult();
+// log.info("此次支付结果:"+result+";msg: "+payload.getMessage());
+// if (result.equals("SUCCESS")) {
+// log.info("支付成功");
+// POOL.submit(new SendFlowerThread(buyEvent));
+// POOL.submit(new SendFlowerBuyToXiaoduTB(buyEvent));
+// return buildErrorResponse("感谢大人赏的花");
+// }
+// return buildErrorResponse("哎呀,没有支付成功");
+// }
- @Override
- public void run() {
- //String baiduOrderReferenceId = buyEvent.getPayload().getBaiduOrderReferenceId();
- String timeStamp = buyEvent.getTimestamp();
- String botId = new String(Base64.getDecoder().decode(buyEvent.getToken()), StandardCharsets.UTF_8);
- String userId = getSessionAttribute("userId");
- int unitePrice = Integer.parseInt(Config.getProperty("unitPrice", Constants.UNIT_PRICE));
- try {
- if (userId == null) userId = getUserIdByToken(getAccessToken());
- if (userId == null) throw new Exception("未获取到用户id");
- //AppFlowerTBTintRepository tinyRepository = BaseHolder.getBean("appFlowerTBTintRepository");
- //AppFlowerTBTiny tiny = tinyRepository.getByUserIdAndBotIdAndUnitPrice(Integer.parseInt(userId), botId,unitePrice/100.0);
- AppFlowerTBRepository flowerRepository = BaseHolder.getBean("appFlowerTBRepository");
- AppFlowerTB flowerTB = new AppFlowerTB();
- flowerTB.setNumber(1);
- flowerTB.setModule(0);
- flowerTB.setBotName(botId);
- flowerTB.setUserId(Integer.parseInt(userId));
- flowerTB.setStatus(1);
- flowerTB.setUnitPrice(unitePrice/100.0);
- flowerTB.setCreateTime(new Timestamp(Long.parseLong(timeStamp)*1000));
- flowerTB.setOrderId(0);
- AppFlowerTB response = flowerRepository.save(flowerTB);
- if (response == null) throw new Exception("向app_flower_tb中插入数据失败");
-// if (tiny == null) {
-//
-// }else {
-// AppFlowerTBRepository flowerRepository = BaseHolder.getBean("appFlowerTBRepository");
-// AppFlowerTB flowerTB = new AppFlowerTB();
-// flowerTB.setId(tiny.getId());
-// int preNumber = tiny.getNumber();
-// flowerTB.setNumber(preNumber+1);
-// AppFlowerTB response = flowerRepository.save(flowerTB);
-// if (response == null || response.getNumber() == preNumber) throw new Exception("向app_flower_tb中更新数据失败");
-// }
- } catch (Exception e) {
- log.error("用户成功支付,game_flower_tb操作出现错误:{}",e.toString());
- }
- }
- }
private ExecuteCommands changeIconIdTextAfterCollect(boolean collect, String botId) {
ExecuteCommands executeCommands = new ExecuteCommands();
@@ -612,62 +444,6 @@ public class DplBotService extends BaseBot {
return response;
}
- private static List buildDataList(List list, int begin) {
- ArrayList dataList = new ArrayList<>();
- for (GameProjectTb projectInfo : list) {
- String productName = correctName(projectInfo.getName());
- String imageId = new StringBuilder(Constants.PRE_PRODUCT_IMG).append(projectInfo.getName()).toString();
- String src = new StringBuilder(Constants.IMG_PREFIX).append(projectInfo.getBannerImgUrl()).toString();
- Data data = new Data(src, productName, imageId);
- data.setNum(begin++);
- dataList.add(data);
- }
- return dataList;
- }
-
- private static List buildCategoryDataList() {
- ArrayList dataList = new ArrayList<>();
- int i = 21;
- for (String cateName : CATEGORY) {
- String imageId = new StringBuilder(PRE_CATEGORY).append(cateName).toString();
- Data data = new Data(GU_FENG, cateName, imageId);
- data.setNum(i++);
- dataList.add(data);
- }
- return dataList;
- }
-
-// private void displayCategoryProd(String categoryName) {
-// ArrayList dataList = new ArrayList<>();
-// for (GameProjectTb projectInfo : CATEGORY_PRODUCT_LIST.get(categoryName)) {
-// String productName = correctName(projectInfo.getName());
-// String imageId = new StringBuilder(Constants.PRE_PRODUCT_IMG).append(projectInfo.getName()).toString();
-// String src = new StringBuilder(Constants.IMG_PREFIX).append(projectInfo.getBannerImgUrl()).toString();
-// Data data = new Data(src, productName, imageId);
-// dataList.add(data);
-// }
-// CATEGORY_PROD_LIST.setData(dataList);
-// }
-
- private Integer getUserSendFlowerNum(String productId) {
- AppFlowerTBTintRepository repository = BaseHolder.getBean("appFlowerTBTintRepository");
- String userId = getSessionAttribute("userId");
- int count = 0;
- try {
- if (userId == null) userId = getUserIdByToken(getAccessToken());
- if (userId == null) throw new Exception("未获取到用户id");
- List tinies = repository.getByUserIdAndBotId(Integer.parseInt(userId), productId);
- if (tinies != null) {
- for (AppFlowerTBTiny tiny:tinies) {
- count += tiny.getNumber();
- }
- }
- } catch (Exception e) {
- log.error("获取用户送花数目失败:{}", e.toString());
- }
- return count;
- }
-
private Integer getUserSendFlowerNum(String productId, String accessToken) {
HashMap params = new HashMap<>();
params.put("module", "works");
@@ -688,23 +464,6 @@ public class DplBotService extends BaseBot {
return response.getData().getCount();
}
- private boolean didUserCollecThisProduct(String productId) {
- AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
- String userId = getSessionAttribute("userId");
- if (userId == null) {
- try {
- userId = getUserIdByToken(getAccessToken());
- } catch (IOException e) {
- return false;
- }
- if (userId == null) return false;
- }
- AppFavoriteTB favorite = new AppFavoriteTB();
- favorite.setUserId(Integer.parseInt(userId));
- favorite.setBotId(productId);
- Example example = Example.of(favorite);
- return repository.exists(example);
- }
private List getUserProductList(String accessToken) {
HashMap params = new HashMap<>();
@@ -737,8 +496,12 @@ public class DplBotService extends BaseBot {
protected Response onLinkAccountSucceededEvent(LinkAccountSucceededEvent linkAccountSucceededEvent) {
log.info("登录成功返回信息:{}",linkAccountSucceededEvent);
try {
- String userId = getUserIdByToken(getAccessToken());
- setSessionAttribute("userId", userId);
+ String userId = getUserId();
+ String accessToken = getAccessToken();
+ DplbotServiceUtil.onLunchFillUserBehaviorData(accessToken, userId);
+ String jytUserId = DplbotServiceUtil.getUsUserId(userId, accessToken);
+ if (jytUserId != null)
+ setSessionAttribute("userId", jytUserId);
return buildErrorResponse("您已登录成功");
} catch (Exception e) {
log.error("获取用户id失败:{}", e.toString());
@@ -764,173 +527,88 @@ public class DplBotService extends BaseBot {
return new Response(outputSpeech);
}
- private String getCustomerId() {
- String userId;
- try {
- userId = getUserId();
- } catch (NullPointerException e) {
- userId = Utils.useIPAsItsID();
- }
- return userId;
- }
-
- class CollectThread implements Runnable {
- final String botId;
- final String userId;
-
- CollectThread(String botId, String userId) {
- this.botId = botId;
- this.userId = userId;
- }
-
- @Override
- public void run() {
- int user_id = Integer.parseInt(userId);
- AppFavoriteTB entity = new AppFavoriteTB();
- entity.setBotId(botId);
- entity.setUserId(user_id);
- entity.setModule(0);
- java.sql.Date cur = new java.sql.Date(System.currentTimeMillis());
- entity.setCreateTime(cur);
- entity.setUpdateTime(cur);
- //Example example = Example.of(entity);
- AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
- repository.save(entity);
-// boolean exist = repository.exists(example);
-// log.info("2333:{}",exist);
-// if (!exist) {
-// entity.setModule(0);
-// repository.save(entity);
-// }
- }
- }
-
- class UnCollectThread implements Runnable {
- final String botId;
- final String userId;
-
- UnCollectThread(String botId, String userId) {
- this.botId = botId;
- this.userId = userId;
- }
-
- @Override
- public void run() {
-// AppFavoriteTB entity = new AppFavoriteTB();
-// entity.setBotId(botId);
-// entity.setUserId(Integer.parseInt(userId));
-
- AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
- repository.deleteByBotIdAndUserId(botId, Integer.parseInt(userId));
- //repository.deleteFavorite(userId, userid);
- }
- }
-
private void backToBotIntro(String botAccount, OverTimeDetail detail) {
OnProductDetail productDetail = ScheduleService.PRODUCT_ID_DETAIL.get(botAccount);
- 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);
+ String imgUrl = new StringBuilder(Constants.IMG_PREFIX).append(productDetail.getBannerImgUrl()).toString();
- // text content
- List
- contentText = content.get(1).getItems();
// product name
String productName = correctName(productDetail.getName());
- 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());
+ String createTime = 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());
+ String author = new StringBuilder(Constants.PRODUCT_INTRO.AUTHOR).append(productDetail.getAuthorName()).toString();
// product labels
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());
// product introduction
- contentText.get(3).getItems().get(0).setText(productDetail.getIntro());
+ String intro = 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);
- icons.get(0).getOnClick().get(0).setComponentId(enterProName);
String accessToken = getAccessToken();
+ String flowers, flowerReward,collectText, collectUrl, collectComId;
if (accessToken != null) {
// flower container button
- Integer count = getUserSendFlowerNum(productDetail.getBotAccount());
- Item flower = icons.get(1);
- flower.getItems().get(1).setText(USER_SEND_FLOWER+count);
- String flowerReward = new StringBuilder(FLOWE).append(productDetail.getBotAccount()).toString();
- flower.setComponentId(flowerReward);
- flower.getOnClick().get(0).setComponentId(flowerReward);
+ Long count = DplbotServiceUtil.getUserSendFlowerNum(botAccount, getUserId(), accessToken);
+ flowers = USER_SEND_FLOWER+count;
+ flowerReward = new StringBuilder(FLOWE).append(productDetail.getBotAccount()).toString();
// collection container button
- boolean collec = didUserCollecThisProduct(productDetail.getBotAccount());
- Item collecButton = icons.get(2);
+ boolean collec = DplbotServiceUtil.doesUserCollectThisBot(productDetail.getBotAccount(), accessToken, getUserId());
if (collec) {
- collecButton.getItems().get(1).setText(COLLECED);
- collecButton.getItems().get(0).setSrc(COLLECTED_IMG_URL);
- String unCollecId = new StringBuilder(UN_COLLEC_ID).append(productDetail.getBotAccount()).toString();
- collecButton.setComponentId(unCollecId);
- collecButton.getOnClick().get(0).setComponentId(unCollecId);
+ collectText = COLLECED;
+ collectUrl = COLLECTED_IMG_URL;
+ collectComId = new StringBuilder(UN_COLLEC_ID).append(productDetail.getBotAccount()).toString();
} else {
- collecButton.getItems().get(1).setText(UN_COLLEC);
- collecButton.getItems().get(0).setSrc(UN_COLLECTED_IMG_URL);
- String collecId = new StringBuilder(COLLEC_ID).append(productDetail.getBotAccount()).toString();
- collecButton.setComponentId(collecId);
- collecButton.getOnClick().get(0).setComponentId(collecId);
+ collectText = UN_COLLEC;
+ collectUrl = UN_COLLECTED_IMG_URL;
+ collectComId = new StringBuilder(COLLEC_ID).append(productDetail.getBotAccount()).toString();
}
} else {
- Item flower = icons.get(1);
- flower.getItems().get(1).setText(FLOWER);
- flower.setComponentId(FLOWER_LOAD);
- flower.getOnClick().get(0).setComponentId(FLOWER_LOAD);
-
- Item collecButton = icons.get(2);
- collecButton.getItems().get(1).setText(UN_COLLEC);
- collecButton.getItems().get(0).setSrc(UN_COLLECTED_IMG_URL);
- collecButton.setComponentId(FLOWER_LOAD);
- collecButton.getOnClick().get(0).setComponentId(FLOWER_LOAD);
+ flowers = FLOWER;
+ flowerReward = FLOWER_LOAD;
+
+ collectText = UN_COLLEC;
+ collectUrl = UN_COLLECTED_IMG_URL;
+ collectComId = FLOWER_LOAD; // 提示登录
}
- RenderDocument renderDocument = new RenderDocument(PROD_INFO);
+ ProductInfoDocument document = ProductInfoUtils.getProductINfoDocument(imgUrl, productName, createTime, author, labels.toString(),
+ intro, enterProName, flowerReward, flowers, collectComId, collectUrl, collectText);
+ RenderDocument renderDocument = new RenderDocument(document);
this.addDirective(renderDocument);
- this.addDirective(new PushStack());
detail.getDirectives().add(renderDocument);
- detail.getDirectives().add(new PushStack());
String trace = getSessionAttribute(BACK_TRACE);
trace = trace.substring(0, trace.length()-1);
this.setSessionAttribute(BACK_TRACE, trace);
detail.getAttributes().put(BACK_TRACE,trace);
}
+ // 异步发送“退出”给终端
private void sendCancellToTerminate(String userId){
RequestTerminal.backRequest(userId);
}
class Task implements Runnable{
IntentRequest intentRequest;
- DplBotService dplBotService;
- Task(IntentRequest intentRequest, DplBotService dplBotService) {
+ Task(IntentRequest intentRequest) {
this.intentRequest = intentRequest;
- this.dplBotService = dplBotService;
}
@Override
public void run() {
- final String userId = getCustomerId();
+ final String userId = getUserId();
String intentName = getIntent().getName();
OverTimeDetail detail = new OverTimeDetail();
log.info("Intent name:{}",intentName);
@@ -938,753 +616,673 @@ public class DplBotService extends BaseBot {
dealDefaultIntent(intentRequest, detail, userId, intentName, null);
return;
}
- if ("load".equals(intentName)) {
- detail.setResponse(load());
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- } else if ("back".equals(intentName)) {
- String trace = getSessionAttribute(BACK_TRACE);
- char second;
- if (trace == null || trace.length() <= 2 || getQuery().contains("首")) {
- // home page
- RenderDocument renderDocument = new RenderDocument(LunchUtils.getLunchDocument());
- dplBotService.addDirective(renderDocument);
- dplBotService.setSessionAttribute(BACK_TRACE,null);
- detail.getDirectives().add(renderDocument);
- detail.getAttributes().put(BACK_TRACE, null);
- if (trace != null && StringUtils.endsWith(trace,File.separator)) sendCancellToTerminate(userId);
- } else if (StringUtils.endsWith(trace,File.separator)){
- String botAccount = trace.substring(2, trace.length()-1);
- log.info("返回作品的id:{}", botAccount);
- backToBotIntro(botAccount, detail);
- sendCancellToTerminate(userId);
- //dplBotService.setSessionAttribute(BACK_TRACE,trace.substring(0, trace.length()-1));
- } else {
- second = trace.charAt(1);
- switch (second){
- case '0':{
- RenderDocument renderDocument = new RenderDocument(LunchUtils.getLunchDocument());
- dplBotService.addDirective(renderDocument);
- dplBotService.setSessionAttribute(BACK_TRACE,null);
- detail.getAttributes().put(BACK_TRACE,null);
- detail.getDirectives().add(renderDocument);
- break;
- }
- case '1': {
- //collect
- String appUserId = getSessionAttribute("userId");
- if (appUserId == null) {
- RenderDocument renderDocument = new RenderDocument(LunchUtils.getLunchDocument());
- dplBotService.addDirective(renderDocument);
- dplBotService.setSessionAttribute(BACK_TRACE,null);
- detail.getAttributes().put(BACK_TRACE,null);
- detail.getDirectives().add(renderDocument);
- break;
- }
- CollectHistoryDocument document = TempleUtils.getCollectPage(Integer.parseInt(appUserId));
- if (document == null) {
- detail.setResponse(buildErrorResponse("您还未收藏过任何作品,快去收藏吧"));
- break;
- }
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- dplBotService.setSessionAttribute(BACK_TRACE, "01");
- dplBotService.setSessionAttribute(PRE_COLLE,document.getIdToken());
- detail.getAttributes().put(BACK_TRACE,null);
- detail.getAttributes().put(PRE_COLLE,document.getIdToken());
- detail.getDirectives().add(render);
- break;
- }
- case '2': {
- //history
- CollectHistoryDocument document = TempleUtils.getHistory(getUserId());
- if (document == null) {
- detail.setResponse(buildErrorResponse("哎呀,可能是您太久没玩了,历史记录已被清空"));
- break;
- }
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- dplBotService.setSessionAttribute(PRE_COLLE,document.getIdToken());
- dplBotService.setSessionAttribute(BACK_TRACE, "02");
- detail.getAttributes().put(BACK_TRACE,"02");
- detail.getAttributes().put(PRE_COLLE,document.getIdToken());
- detail.getDirectives().add(render);
- break;
- }
- case '3': {
- //recommend
- String recommendNextCount = dplBotService.getSessionAttribute("comCnt");
- int count = 1;
- if (recommendNextCount != null) count = Integer.parseInt(recommendNextCount);
- RecommandDocument recommandDocument = RecommendUtil.getRecommendDocument(count-1);
- RenderDocument render = new RenderDocument();
- render.setDocument(recommandDocument);
- dplBotService.addDirective(render);
- String token = recommandDocument.getRecommendIdList();
- if (token != null) {
- dplBotService.setSessionAttribute("recommand", token);
- detail.getAttributes().put("recommand",token);
- }
- dplBotService.setSessionAttribute(BACK_TRACE, "03");
- detail.getAttributes().put(BACK_TRACE, "03");
- detail.getDirectives().add(render);
- detail.setResponse(buildErrorResponse(new StringBuilder("已为您返回到推荐页").toString()));
- break;
- }
- case '4': {
- //rank
- RankingDocument document = TempleUtils.getRanking();
- RenderDocument render = new RenderDocument();
- render.setDocument(document);
- dplBotService.addDirective(render);
- detail.getDirectives().add(render);
- String token = document.getRankBotIds();
- if (token != null) {
- dplBotService.setSessionAttribute("ranking", token);
- detail.getAttributes().put("ranking",token);
- }
- dplBotService.setSessionAttribute(BACK_TRACE, "04");
- detail.getAttributes().put(BACK_TRACE, "04");
- break;
- }
- case '5':{
- String category = getSessionAttribute("category");
- if (category == null) {
- RenderDocument renderDocument = new RenderDocument(LunchUtils.getLunchDocument());
- dplBotService.addDirective(renderDocument);
- dplBotService.setSessionAttribute(BACK_TRACE,null);
- detail.getDirectives().add(renderDocument);
- detail.getAttributes().put(BACK_TRACE, null);
- } else {
- String count = getSessionAttribute("comCnt");
- int pageIndex = 0;
- if (count != null) pageIndex = Integer.parseInt(count)-1;
- RecommandDocument document = RecommendUtil.getCategory(pageIndex, category);
- RenderDocument render = new RenderDocument(document);
- addDirective(render);
- detail.getDirectives().add(render);
- detail.setResponse(buildErrorResponse(new StringBuilder("已为您返回到")
- .append(category).append("分类第").append(pageIndex+1).append("页").toString()));
- }
- break;
- }
- }
- }
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- } else if ("openCollect".equals(intentName)) {
- if (getAccessToken() == null) {
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "该功能需要登录,请说小度小度,登录");
- detail.setResponse(new Response(outputSpeech));
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- } 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);
- //LAST_OUTTIME_RESULT.put(userId, new Response(outputSpeech));
- detail.setResponse(new Response(outputSpeech));
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- }
- if (appUserId == null) {
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, SORRY_UNCATCH);
- //LAST_OUTTIME_RESULT.put(userId, new Response(outputSpeech));
- detail.setResponse(new Response(outputSpeech));
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- }
- }
- CollectHistoryDocument document = TempleUtils.getCollectPage(Integer.parseInt(appUserId));
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- //dplBotService.addDirective(new PushStack());
- dplBotService.setSessionAttribute(PRE_COLLE,document.getIdToken());
- dplBotService.setSessionAttribute(BACK_TRACE, "01");
- detail.getAttributes().put(PRE_COLLE, document.getIdToken());
- detail.getAttributes().put(BACK_TRACE,"01");
- detail.getDirectives().add(render);
- //detail.getDirectives().add(new PushStack());
- //LAST_OUTTIME_RESULT.put(userId, new Response());
+ switch (intentName) {
+ case "load" : dealLoadIntent(detail, userId);break;
+ case "back" : dealBackIntent(detail, userId);break;
+ case "openCollect" : dealOpenCollectIntent(detail, userId);break;
+ case "openNum" : dealOpenNumIntent(detail, userId);break;
+ case "lastPage" : dealLastPageIntent(detail, userId, intentRequest);break;
+ case "nextPage" : dealNextPageIntent(detail, userId, intentRequest);break;
+ case "history" : dealHistoryIntent(detail, userId);break;
+ case "recommand" : dealRecommandIntent(detail, userId);break;
+ case "ranking" : dealRankIntent(detail, userId);break;
+ case "collect" :
+ case "unCollect" : dealCollectOrUnCollectIntent(detail, userId, intentName);break;
+ case "sendFlower" : dealSendFlowerIntent(detail, userId);break;
+ case "start" : dealStartIntent(detail, userId, intentRequest, intentName);break;
+ }
+ }
+ }
+
+ private void dealStartIntent(OverTimeDetail detail, String userId, IntentRequest intentRequest, String intentName) {
+ String trace = getSessionAttribute("trace");
+ if (trace != null && trace.length() > 2 && !StringUtils.endsWith(trace,File.separator)) {
+ String botId = trace.substring(2);
+ String enterName = new StringBuilder("我要玩")
+ .append(ScheduleService.getProductIdDetail().get(botId).getName()).toString();
+ dealDefaultIntent(intentRequest, detail, userId, intentName, enterName);
+ }else {
+ dealDefaultIntent(intentRequest, detail, userId, intentName, null);
+ }
+ }
+
+ private void dealSendFlowerIntent(OverTimeDetail detail, String userId) {
+ if (getAccessToken() == null) {
+ OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "该功能需要登录,请说小度小度,登录");
+ detail.setResponse(new Response(outputSpeech));
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ return;
+ }
+ String num = getSlot("sys.number");
+ OutputSpeech outputSpeech;
+ String confirmationStatus = getIntent().getConfirmationStatus().name();
+ log.info("槽位确认状态:{}",confirmationStatus);
+ if ("NONE".equals(confirmationStatus)) {
+ if (num == null) {
+ log.info("确认送花个数");
+ ask("sys.number");
+ outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "请问您要送几朵花");
+ setExpectSpeech(true);
+ } else {
+ log.info("确认最终送花意图");
+ setConfirmIntent();
+ outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText,
+ new StringBuilder("您要送").append(num).append("朵花是吗").toString());
+ setExpectSpeech(true);
+ }
+ detail.getResponse().setOutputSpeech(outputSpeech);
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ } else if ("CONFIRMED".equals(confirmationStatus)) {
+ log.info("确认");
+ int unitPrice = Integer.parseInt(ScheduleService.FLOWER_UNIT_PRICE);
+ String amount = String.valueOf(unitPrice*Integer.parseInt(num)/100.0);
+ String orderId = new StringBuilder(userId).append(System.currentTimeMillis()).toString();
+ String appUserId = getSessionAttribute("userId");
+ if (appUserId == null) {
+ appUserId = DplbotServiceUtil.getUsUserId(userId,getAccessToken());
+ if (appUserId == null) {
+ log.error("送花时获取用户app_user_id失败");
+ detail.setResponse(buildErrorResponse("不好意思出了点问题,请再说一遍吧"));
LAST_OUTTIME_RESULT.put(userId, detail);
return;
}
- } else if ("openNum".equals(intentName)) {
- String trace = dplBotService.getSessionAttribute("trace");
- if (trace == null || trace.charAt(1) == '0') {
- String numStr = getSlot("sys.number");
- int num = 1;
- if (numStr != null) num = Integer.parseInt(numStr);
- detail.setResponse(dealOpenNumInHome(num, detail));
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- } else if (trace.length() > 2) {
- detail.setResponse(buildErrorResponse("客官,您在这个页面想打开啥"));
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
+ }
+ String botId;
+ String trace = getSessionAttribute(BACK_TRACE);
+ if (trace != null && trace.length() > 2) {
+ if (StringUtils.endsWith(trace, File.separator)) {
+ botId = trace.substring(2, trace.length()-1);
+ }else {
+ botId = trace.substring(2);
}
- char page = trace.charAt(1);
- switch (page){
- case '1':
- case '2': detail.setResponse(dealOpenNum(getSessionAttribute(PRE_COLLE), detail)); break;
- case '3': detail.setResponse(dealOpenNumInRecommend(getSessionAttribute("recommand"),detail)); break;
- case '4': detail.setResponse(dealOpenNum(getSessionAttribute("ranking"),detail)); break;
- case '5': {
- String count = getSessionAttribute("comCnt");
- int pageIndex = 0;
- if (count != null) pageIndex = Integer.parseInt(count)-1;
- String numStr = getSlot("sys.number");
- int num = 1;
- if (numStr != null) num = Integer.parseInt(numStr);
- List categoryBots = ScheduleService.getCategoryProductIdList().get(getSessionAttribute("category"));
- if (num <= 0 || num > categoryBots.size()) {
- detail.setResponse(buildErrorResponse("这个数字超出了范围,作品的序号已显示在图片左上角"));
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- }
- String botId = categoryBots.get(pageIndex*16+num-1);
- String name = ScheduleService.getProductIdDetail().get(botId).getName();
- Response response;
- if (doesUserPlayed(botId)) response = directInProduct(correctName(name), botId, detail);
- else response = enterProductInfo(correctName(name), detail);
- detail.setResponse(response);
- break;
- }
- default:{
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "屏幕上的图标都是可以点击的哦");
- detail.getResponse().setOutputSpeech(outputSpeech);
- }
+ XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
+ XiaoDuOrderTB response = repository.save(buildBeforePayPojo(botId, appUserId, userId, unitPrice,
+ Integer.parseInt(num), orderId));
+
+ if (response != null && response.getId() != null) {
+ String desc = new StringBuilder("感谢您赏赐给该作品的").append(num).append("朵鲜花").toString();
+ String name = ScheduleService.PRODUCT_ID_DETAIL.get(botId).getName();
+ if (name != null) desc = new StringBuilder("感谢您赏赐给").append(name)
+ .append("的").append(num).append("朵鲜花").toString();
+ Charge charge = new Charge(amount, orderId, "鲜花", desc);
+ charge.setToken(new StringBuilder(botId).append(File.separator).append(num).toString());
+ addDirective(charge);
+ detail.getDirectives().add(charge);
+ detail.setResponse(buildErrorResponse("请扫描二维码完成支付"));
+ } else {
+ log.error("订单没有插入到xioadu_order_tb");
+ detail.setResponse(buildErrorResponse(ERROR_SEND_FLOWER));
}
-// String collectToken = getSessionAttribute(PRE_COLLE); //collect,history
-// String rankToken = getSessionAttribute("ranking");
-// String recommengToken = getSessionAttribute("recommand");
-// String category = getSessionAttribute("category");
-// log.info("openNum slot value:{}", getSlot("sys.number"));
-// if (collectToken != null) {
-// detail.setResponse(dealOpenNum(collectToken, detail));
-// //LAST_OUTTIME_RESULT.put(userId, dealOpenNum(collectToken));
-// } else if (rankToken != null){
-// detail.setResponse(dealOpenNum(rankToken,detail));
-// //LAST_OUTTIME_RESULT.put(userId, dealOpenNum(rankToken));
-// } else if (recommengToken != null) {
-// detail.setResponse(dealOpenNumInRecommend(recommengToken,detail));
-// //LAST_OUTTIME_RESULT.put(userId, dealOpenNum(recommengToken));
-// } else if (category != null) {
-// String count = getSessionAttribute("comCnt");
-// int pageIndex = 0;
-// if (count != null) pageIndex = Integer.parseInt(count)-1;
-// String numStr = getSlot("sys.number");
-// int num = 1;
-// if (numStr != null) num = Integer.parseInt(numStr);
-// if (num > 16) {
-// detail.setResponse(buildErrorResponse("这个数字超出了范围,你可以说下一页"));
-// }else {
-// String botId = ScheduleService.getCategoryProductIdList().get(category).get(pageIndex*16+num-1);
-// String name = ScheduleService.getProductIdDetail().get(botId).getName();
-// Response response;
-// if (doesUserPlayed(botId)) response = directInProduct(correctName(name), botId, detail);
-// else response = enterProductInfo(correctName(name), detail);
-// detail.setResponse(response);
-// }
-// }
-// else {
-// OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "屏幕上的图标都是可以点击的哦");
-// detail.getResponse().setOutputSpeech(outputSpeech);
-// //LAST_OUTTIME_RESULT.put(userId, new Response(outputSpeech));
-// }
+ }else {
+ log.error("无法获取到botID");
+ detail.setResponse(buildErrorResponse(ERROR_SEND_FLOWER));
+ }
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ } else {
+ log.info("否定");
+ detail.setResponse(buildErrorResponse("好的,已为您终止"));
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ }
+ }
+
+ private void dealCollectOrUnCollectIntent(OverTimeDetail detail, String userId, String intentName) {
+ if (getAccessToken() == null) {
+ OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "该功能需要登录,请说小度小度,登录");
+ detail.setResponse(new Response(outputSpeech));
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ return;
+ }
+ boolean collect = "collect".equals(intentName);
+ boolean inProductInfo = false;
+ boolean inPlayInfo = false;
+ String botAccount;
+ String trace = getSessionAttribute("trace");
+ if (trace == null || trace.length() <= 2) {
+ botAccount = getSessionAttribute("botAcc");
+ if(botAccount == null) {
+ String word = COLLECT_FAIL;
+ if (!collect) word = UN_COLLECT_FAIL;
+ detail.setResponse(buildErrorResponse(word));
LAST_OUTTIME_RESULT.put(userId, detail);
return;
}
- else if ("lastPage".equals(intentName)) {
- String signPage = getSessionAttribute("pageSign");
- if (signPage == null) {
- detail.setResponse(buildErrorResponse("不好意思,小悟累啦,滑不动了"));
- LAST_OUTTIME_RESULT.put(userId,detail);
- return;
- }
- String pageIndex = getSessionAttribute("pageIndex");
- int sign = Integer.parseInt(signPage);
- int index = 0;
- switch (sign) {
- case 6: {
- ExecuteCommands executeCommands = new ExecuteCommands();
- SetPageCommand setPage = new SetPageCommand();
- setPage.setComponentId("funnyPage");
- setPage.setPosition(SetPageCommand.Position.RELATIVE);
- setPage.setValue(-1);
- executeCommands.addCommand(setPage);
- dplBotService.addDirective(executeCommands);
- detail.getDirectives().add(executeCommands);
- break;
- }
- case 3: {
- String recommendNextCount = dplBotService.getSessionAttribute("comCnt");
- if (recommendNextCount == null || "1".equals(recommendNextCount)) {
- detail.setResponse(buildErrorResponse("客观,前面没啦,没法往前翻了"));
- break;
- }
- int count = Integer.parseInt(recommendNextCount);
- RecommandDocument document = RecommendUtil.getRecommendDocument(count-2);
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- detail.getDirectives().add(render);
- String token = document.getRecommendIdList();
- dplBotService.setSessionAttribute("recommand", token);
- detail.getAttributes().put("recommand",token);
- dplBotService.setSessionAttribute("comCnt",String.valueOf(count-1));
- detail.getAttributes().put("comCnt",String.valueOf(count-1));
- break;
- }
- case 4: {
- index = 0;
- if (pageIndex != null) index = Integer.parseInt(pageIndex);
- ExecuteCommands executeCommands = new ExecuteCommands();
- ScrollToIndexCommand scroll = new ScrollToIndexCommand();
- scroll.setComponentId("scrollToIndex");
- String updateCount = dplBotService.getSessionAttribute("updateCount");
- if (intentRequest.getQuery().getOriginal().contains("页") && updateCount != null && !"0".equals(updateCount)) {
- int update = Integer.valueOf(updateCount);
- RankingDocument document = RankUtil.updateRankDocument(update-1);
- if (document == null) {
- detail.setResponse(buildErrorResponse("排行榜已经被您翻到底啦,没有了"));
- break;
- }
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- detail.getDirectives().add(render);
- dplBotService.setSessionAttribute("pageIndex",null);
- detail.getAttributes().put("pageIndex",null);
- dplBotService.setSessionAttribute("count", document.getCount());
- detail.getAttributes().put("count", document.getCount());
- dplBotService.setSessionAttribute("updateCount", String.valueOf(update-1));
- detail.getAttributes().put("updateCount", String.valueOf(update-1));
- detail.setResponse(buildErrorResponse(new StringBuilder("为您刷新排行榜,下面是排行")
- .append(update*15).append("到").append(update*15+15).append("的作品").toString()));
- break;
+ } else {
+ if (StringUtils.endsWith(trace, File.separator)) {
+ botAccount = trace.substring(2, trace.length()-1);
+ inPlayInfo = true;
+ }
+ else {
+ inProductInfo = true;
+ botAccount = trace.substring(2);
+ }
+ }
+ try {
+ boolean alreadyCollected = DplbotServiceUtil.doesUserCollectThisBot(botAccount, getAccessToken(), userId);
+ String appUserId = getSessionAttribute("userId");
+ if (appUserId == null) appUserId = DplbotServiceUtil.getUsUserId(userId,getAccessToken());
+ if (appUserId != null) {
+ if (alreadyCollected) {
+ if (collect) detail.setResponse(buildErrorResponse("您之前就已经收藏过该作品啦,看来你真的很喜欢它"));
+ else {
+ DplbotServiceUtil.userUnCollectTheBotInPool(userId, botAccount, getAccessToken());
+ String botName = ScheduleService.PRODUCT_ID_DETAIL.get(botAccount).getName();
+ if (inProductInfo) {
+ ExecuteCommands commands = changeIconIdTextAfterCollect(false, botAccount);
+ addDirective(commands);
+ detail.getDirectives().add(commands);
+ } else if (inPlayInfo) {
+ changeCollectIconInPlay(false);
}
- index -= 4;
- if (index < 0) index = 0;
- scroll.setIndex(index);
- scroll.setAlign(ScrollToIndexCommand.AlignType.FIRST);
- executeCommands.addCommand(scroll);
- dplBotService.addDirective(executeCommands);
- detail.getDirectives().add(executeCommands);
- dplBotService.setSessionAttribute("pageIndex", String.valueOf(index));
- detail.getAttributes().put("pageIndex", String.valueOf(index));
- break;
+ if (botName == null) detail.setResponse(buildErrorResponse(UN_COLLECT_BOT_WORD));
+ else detail.setResponse(buildErrorResponse(String.format(UN_COLLECT_BOT_WORD_MG,botName)));
}
- case 5:{
- String category = dplBotService.getSessionAttribute("category");
- if (category == null) category = "古风";
- String recommendNextCount = dplBotService.getSessionAttribute("comCnt");
- if (recommendNextCount == null || "1".equals(recommendNextCount)) {
- detail.setResponse(buildErrorResponse("客观,前面没啦,没法往前翻了"));
- break;
+ } else {
+ if (collect) {
+ DplbotServiceUtil.userCollectTheBotInPool(userId, botAccount, getAccessToken());
+ String word = ScheduleService.PRODUCT_ID_DETAIL.get(botAccount).getName();
+ if (inProductInfo) {
+ ExecuteCommands commands = changeIconIdTextAfterCollect(true, botAccount);
+ addDirective(commands);
+ detail.getDirectives().add(commands);
+ } else if (inPlayInfo) {
+ changeCollectIconInPlay(true);
}
- int count = Integer.parseInt(recommendNextCount);
- RecommandDocument document = RecommendUtil.getCategory(count-2,category);
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- detail.getDirectives().add(render);
- dplBotService.setSessionAttribute("comCnt",String.valueOf(count-1));
- detail.getAttributes().put("comCnt",String.valueOf(count-1));
- break;
- }
- default:{
- detail.setResponse(buildErrorResponse("该功能还没实现"));
+ if (word == null) detail.setResponse(buildErrorResponse(COLLECT_BOT_WORD));
+ else detail.setResponse(buildErrorResponse(String.format(COLLECT_BOT_WORD_MG, correctName(word))));
+ }else {
+ detail.setResponse(buildErrorResponse("您还未收藏过该作品,它不在您的收藏列表内"));
}
}
- LAST_OUTTIME_RESULT.put(userId,detail);
- return;
+ }else {
+ detail.setResponse(buildErrorResponse(SORRY_UNCATCH));
}
- else if ("nextPage".equals(intentName)) {
- String signPage = getSessionAttribute("pageSign");
- if (signPage == null) {
- detail.setResponse(buildErrorResponse("哎呀,小悟累啦,滑不动了"));
- LAST_OUTTIME_RESULT.put(userId,detail);
- return;
+ } catch (Exception e) {
+ log.error("收藏/取消收藏出错:{}",e.toString());
+ detail.setResponse(buildErrorResponse(SORRY_UNCATCH));
+ }
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ }
+
+ private void dealRankIntent(OverTimeDetail detail, String userId) {
+ RankingDocument document = RankUtil.getRankDocument();
+ RenderDocument render = new RenderDocument();
+ render.setDocument(document);
+ addDirective(render);
+ detail.getDirectives().add(render);
+ String token = document.getRankBotIds();
+ if (token != null) {
+ setSessionAttribute("ranking", token);
+ setSessionAttribute("recommand", null);
+ setSessionAttribute(PRE_COLLE, null);
+
+ detail.getAttributes().put("ranking", token);
+ detail.getAttributes().put("recommand", null);
+ detail.getAttributes().put(PRE_COLLE, null);
+ }
+ setSessionAttribute("pageSign", "4");
+ detail.getAttributes().put("pageSign", "4");
+ setSessionAttribute(BACK_TRACE, "04");
+ detail.getAttributes().put(BACK_TRACE, "04");
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ }
+
+ private void dealRecommandIntent(OverTimeDetail detail, String userId) {
+ RecommandDocument recommandDocument = RecommendUtil.getRecommendDocument(0);
+ RenderDocument render = new RenderDocument();
+ render.setDocument(recommandDocument);
+ addDirective(render);
+ detail.getDirectives().add(render);
+ String token = recommandDocument.getRecommendIdList();
+ if (token != null) {
+ setSessionAttribute("recommand", token);
+ setSessionAttribute(PRE_COLLE, null);
+ setSessionAttribute("ranking", null);
+ setSessionAttribute("count", recommandDocument.getCount());
+
+ detail.getAttributes().put("ranking", null);
+ detail.getAttributes().put("recommand", token);
+ detail.getAttributes().put(PRE_COLLE, null);
+ detail.getAttributes().put("count", recommandDocument.getCount());
+ }
+ setSessionAttribute("pageSign", "3");
+ detail.getAttributes().put("pageSign", "3");
+ setSessionAttribute(BACK_TRACE, "03");
+ detail.getAttributes().put(BACK_TRACE,"03");
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ }
+
+ private void dealHistoryIntent(OverTimeDetail detail, String userId) {
+ CollectHistoryDocument document = TempleUtils.getHistory(getUserId());
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ //dplBotService.addDirective(new PushStack());
+ setSessionAttribute(PRE_COLLE,document.getIdToken());
+ setSessionAttribute("ranking", null);
+ setSessionAttribute("recommand", null);
+ setSessionAttribute(BACK_TRACE, "02");
+
+ detail.getDirectives().add(render);
+ detail.getAttributes().put("ranking", null);
+ detail.getAttributes().put("recommand", null);
+ detail.getAttributes().put(PRE_COLLE,document.getIdToken());
+ detail.getAttributes().put(BACK_TRACE, "02");
+
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ }
+
+ private void dealNextPageIntent(OverTimeDetail detail, String userId, IntentRequest intentRequest) {
+ String signPage = getSessionAttribute("pageSign");
+ if (signPage == null) {
+ detail.setResponse(buildErrorResponse("哎呀,小悟累啦,滑不动了"));
+ LAST_OUTTIME_RESULT.put(userId,detail);
+ return;
+ }
+ String pageIndex = getSessionAttribute("pageIndex");
+ int sign = Integer.parseInt(signPage);
+ int index = 0;
+ switch (sign) {
+ case 6: {
+ ExecuteCommands executeCommands = new ExecuteCommands();
+ SetPageCommand setPage = new SetPageCommand();
+ setPage.setComponentId("funnyPage");
+ setPage.setPosition(SetPageCommand.Position.RELATIVE);
+ setPage.setValue(1);
+ executeCommands.addCommand(setPage);
+ addDirective(executeCommands);
+ detail.getDirectives().add(executeCommands);
+ break;
+ }
+ case 3: {
+ String recommendNextCount = getSessionAttribute("comCnt");
+ int count = 1;
+ if (recommendNextCount != null) count = Integer.parseInt(recommendNextCount);
+ RecommandDocument document = RecommendUtil.getRecommendDocument(count);
+ if (document == null) {
+ detail.setResponse(buildErrorResponse("客观你已经翻到底了,没有更多了"));
+ break;
}
- String pageIndex = getSessionAttribute("pageIndex");
- int sign = Integer.parseInt(signPage);
- int index = 0;
- switch (sign) {
- case 6: {
- ExecuteCommands executeCommands = new ExecuteCommands();
- SetPageCommand setPage = new SetPageCommand();
- setPage.setComponentId("funnyPage");
- setPage.setPosition(SetPageCommand.Position.RELATIVE);
- setPage.setValue(1);
- executeCommands.addCommand(setPage);
- dplBotService.addDirective(executeCommands);
- detail.getDirectives().add(executeCommands);
- break;
- }
- case 3: {
- String recommendNextCount = dplBotService.getSessionAttribute("comCnt");
- int count = 1;
- if (recommendNextCount != null) count = Integer.parseInt(recommendNextCount);
- RecommandDocument document = RecommendUtil.getRecommendDocument(count);
- if (document == null) {
- detail.setResponse(buildErrorResponse("客观你已经翻到底了,没有更多了"));
- break;
- }
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- detail.getDirectives().add(render);
- String token = document.getRecommendIdList();
- dplBotService.setSessionAttribute("recommand", token);
- detail.getAttributes().put("recommand",token);
- dplBotService.setSessionAttribute("comCnt",String.valueOf(count+1));
- detail.getAttributes().put("comCnt",String.valueOf(count+1));
- break;
- }
- case 4: {
- int count = 15;
- String countStr = dplBotService.getSessionAttribute("count");
- if (countStr != null) count = Integer.parseInt(countStr);
- if (intentRequest.getQuery().getOriginal().contains("页")) {
- //update
- String updateCount = dplBotService.getSessionAttribute("updateCount");
- int update = 1;
- if (updateCount != null) update = Integer.valueOf(updateCount);
- RankingDocument document = RankUtil.updateRankDocument(update);
- if (document == null) {
- detail.setResponse(buildErrorResponse("排行榜已经被您翻到底啦,没有了"));
- break;
- }
- count = Integer.parseInt(document.getCount());
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- detail.getDirectives().add(render);
- dplBotService.setSessionAttribute("pageIndex",null);
- detail.getAttributes().put("pageIndex",null);
- dplBotService.setSessionAttribute("count", document.getCount());
- detail.getAttributes().put("count", document.getCount());
- dplBotService.setSessionAttribute("updateCount", String.valueOf(update+1));
- detail.getAttributes().put("updateCount", String.valueOf(update+1));
- detail.setResponse(buildErrorResponse(new StringBuilder("为您刷新排行榜,下面是排行")
- .append(update*15).append("到").append(update*15+count).append("的作品").toString()));
- break;
- }
- index = 0;
- if (pageIndex != null) index = Integer.parseInt(pageIndex);
- ExecuteCommands executeCommands = new ExecuteCommands();
- ScrollToIndexCommand scroll = new ScrollToIndexCommand();
- scroll.setComponentId("scrollToIndex");
- index += 4;
- if (index >= count) {
- detail.setResponse(buildErrorResponse("请说下一页刷新榜单"));
- break;
- }
- scroll.setIndex(index);
- scroll.setAlign(ScrollToIndexCommand.AlignType.FIRST);
- executeCommands.addCommand(scroll);
- dplBotService.addDirective(executeCommands);
- detail.getDirectives().add(executeCommands);
- dplBotService.setSessionAttribute("pageIndex", String.valueOf(index));
- detail.getAttributes().put("pageIndex", String.valueOf(index));
- break;
- }
- case 5:{
- String category = dplBotService.getSessionAttribute("category");
- if (category == null) category = "古风";
- String categoryNextCount = dplBotService.getSessionAttribute("comCnt");
- int count = 1;
- if (categoryNextCount != null) count = Integer.parseInt(categoryNextCount);
- RecommandDocument document = RecommendUtil.getCategory(count,category);
- if (document == null) {
- detail.setResponse(buildErrorResponse("客观你已经翻到底了,没有更多了"));
- break;
- }
- RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- detail.getDirectives().add(render);
- String countStr = String.valueOf(count+1);
- setSessionAttribute("comCnt",countStr);
- detail.getAttributes().put("comCnt",countStr);
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ detail.getDirectives().add(render);
+ String token = document.getRecommendIdList();
+ setSessionAttribute("recommand", token);
+ detail.getAttributes().put("recommand",token);
+ setSessionAttribute("comCnt",String.valueOf(count+1));
+ detail.getAttributes().put("comCnt",String.valueOf(count+1));
+ break;
+ }
+ case 4: {
+ int count = 15;
+ String countStr = getSessionAttribute("count");
+ if (countStr != null) count = Integer.parseInt(countStr);
+ if (intentRequest.getQuery().getOriginal().contains("页")) {
+ //update
+ String updateCount = getSessionAttribute("updateCount");
+ int update = 1;
+ if (updateCount != null) update = Integer.valueOf(updateCount);
+ RankingDocument document = RankUtil.updateRankDocument(update);
+ if (document == null) {
+ detail.setResponse(buildErrorResponse("排行榜已经被您翻到底啦,没有了"));
break;
}
- default:{
- detail.setResponse(buildErrorResponse("该功能还没实现"));
- }
+ count = Integer.parseInt(document.getCount());
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ detail.getDirectives().add(render);
+ setSessionAttribute("pageIndex",null);
+ detail.getAttributes().put("pageIndex",null);
+ setSessionAttribute("count", document.getCount());
+ detail.getAttributes().put("count", document.getCount());
+ setSessionAttribute("updateCount", String.valueOf(update+1));
+ detail.getAttributes().put("updateCount", String.valueOf(update+1));
+ detail.setResponse(buildErrorResponse(new StringBuilder("为您刷新排行榜,下面是排行")
+ .append(update*15).append("到").append(update*15+count).append("的作品").toString()));
+ break;
}
- LAST_OUTTIME_RESULT.put(userId,detail);
- return;
+ index = 0;
+ if (pageIndex != null) index = Integer.parseInt(pageIndex);
+ ExecuteCommands executeCommands = new ExecuteCommands();
+ ScrollToIndexCommand scroll = new ScrollToIndexCommand();
+ scroll.setComponentId("scrollToIndex");
+ index += 4;
+ if (index >= count) {
+ detail.setResponse(buildErrorResponse("请说下一页刷新榜单"));
+ break;
+ }
+ scroll.setIndex(index);
+ scroll.setAlign(ScrollToIndexCommand.AlignType.FIRST);
+ executeCommands.addCommand(scroll);
+ addDirective(executeCommands);
+ detail.getDirectives().add(executeCommands);
+ setSessionAttribute("pageIndex", String.valueOf(index));
+ detail.getAttributes().put("pageIndex", String.valueOf(index));
+ break;
}
- else if ("history".equals(intentName)) {
- CollectHistoryDocument document = TempleUtils.getHistory(getUserId());
+ case 5:{
+ String category = getSessionAttribute("category");
+ if (category == null) category = "古风";
+ String categoryNextCount = getSessionAttribute("comCnt");
+ int count = 1;
+ if (categoryNextCount != null) count = Integer.parseInt(categoryNextCount);
+ RecommandDocument document = RecommendUtil.getCategory(count,category);
+ if (document == null) {
+ detail.setResponse(buildErrorResponse("客观你已经翻到底了,没有更多了"));
+ break;
+ }
RenderDocument render = new RenderDocument(document);
- dplBotService.addDirective(render);
- //dplBotService.addDirective(new PushStack());
- dplBotService.setSessionAttribute(PRE_COLLE,document.getIdToken());
- dplBotService.setSessionAttribute("ranking", null);
- dplBotService.setSessionAttribute("recommand", null);
- dplBotService.setSessionAttribute(BACK_TRACE, "02");
-
+ addDirective(render);
detail.getDirectives().add(render);
- //detail.getDirectives().add(new PushStack());
- detail.getAttributes().put("ranking", null);
- detail.getAttributes().put("recommand", null);
- detail.getAttributes().put(PRE_COLLE,document.getIdToken());
- detail.getAttributes().put(BACK_TRACE, "02");
+ String countStr = String.valueOf(count+1);
+ setSessionAttribute("comCnt",countStr);
+ detail.getAttributes().put("comCnt",countStr);
+ break;
+ }
+ default:{
+ detail.setResponse(buildErrorResponse("该功能还没实现"));
+ }
+ }
+ LAST_OUTTIME_RESULT.put(userId,detail);
+ }
- //LAST_OUTTIME_RESULT.put(userId, new Response());
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- } else if ("recommand".equals(intentName)) {
- //RecommandDocument recommandDocument = TempleUtils.getRecommend(0);
- RecommandDocument recommandDocument = RecommendUtil.getRecommendDocument(0);
- RenderDocument render = new RenderDocument();
- render.setDocument(recommandDocument);
- dplBotService.addDirective(render);
- //dplBotService.addDirective(new PushStack());
- //detail.getDirectives().add(new PushStack());
- detail.getDirectives().add(render);
- String token = recommandDocument.getRecommendIdList();
- if (token != null) {
- dplBotService.setSessionAttribute("recommand", token);
- dplBotService.setSessionAttribute(PRE_COLLE, null);
- dplBotService.setSessionAttribute("ranking", null);
- dplBotService.setSessionAttribute("count", recommandDocument.getCount());
-
- detail.getAttributes().put("ranking", null);
- detail.getAttributes().put("recommand", token);
- detail.getAttributes().put(PRE_COLLE, null);
- detail.getAttributes().put("count", recommandDocument.getCount());
+ private void dealLastPageIntent(OverTimeDetail detail, String userId, IntentRequest intentRequest) {
+ String signPage = getSessionAttribute("pageSign");
+ if (signPage == null) {
+ detail.setResponse(buildErrorResponse("不好意思,小悟累啦,滑不动了"));
+ LAST_OUTTIME_RESULT.put(userId,detail);
+ return;
+ }
+ String pageIndex = getSessionAttribute("pageIndex");
+ int sign = Integer.parseInt(signPage);
+ int index;
+ switch (sign) {
+ case 6: {
+ ExecuteCommands executeCommands = new ExecuteCommands();
+ SetPageCommand setPage = new SetPageCommand();
+ setPage.setComponentId("funnyPage");
+ setPage.setPosition(SetPageCommand.Position.RELATIVE);
+ setPage.setValue(-1);
+ executeCommands.addCommand(setPage);
+ addDirective(executeCommands);
+ detail.getDirectives().add(executeCommands);
+ break;
+ }
+ case 3: {
+ String recommendNextCount = getSessionAttribute("comCnt");
+ if (recommendNextCount == null || "1".equals(recommendNextCount)) {
+ detail.setResponse(buildErrorResponse("客观,前面没啦,没法往前翻了"));
+ break;
}
- dplBotService.setSessionAttribute("pageSign", "3");
- detail.getAttributes().put("pageSign", "3");
- dplBotService.setSessionAttribute(BACK_TRACE, "03");
- detail.getAttributes().put(BACK_TRACE,"03");
- LAST_OUTTIME_RESULT.put(userId, detail);
- //LAST_OUTTIME_RESULT.put(userId, new Response());
- return;
- } else if ("ranking".equals(intentName)) {
- RankingDocument document = RankUtil.getRankDocument();
- RenderDocument render = new RenderDocument();
- render.setDocument(document);
- dplBotService.addDirective(render);
- //dplBotService.addDirective(new PushStack());
+ int count = Integer.parseInt(recommendNextCount);
+ RecommandDocument document = RecommendUtil.getRecommendDocument(count-2);
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
detail.getDirectives().add(render);
- //detail.getDirectives().add(new PushStack());
- String token = document.getRankBotIds();
- if (token != null) {
- dplBotService.setSessionAttribute("ranking", token);
- dplBotService.setSessionAttribute("recommand", null);
- dplBotService.setSessionAttribute(PRE_COLLE, null);
-
- detail.getAttributes().put("ranking", token);
- detail.getAttributes().put("recommand", null);
- detail.getAttributes().put(PRE_COLLE, null);
+ String token = document.getRecommendIdList();
+ setSessionAttribute("recommand", token);
+ detail.getAttributes().put("recommand",token);
+ setSessionAttribute("comCnt",String.valueOf(count-1));
+ detail.getAttributes().put("comCnt",String.valueOf(count-1));
+ break;
+ }
+ case 4: {
+ index = 0;
+ if (pageIndex != null) index = Integer.parseInt(pageIndex);
+ ExecuteCommands executeCommands = new ExecuteCommands();
+ ScrollToIndexCommand scroll = new ScrollToIndexCommand();
+ scroll.setComponentId("scrollToIndex");
+ String updateCount = getSessionAttribute("updateCount");
+ if (intentRequest.getQuery().getOriginal().contains("页") && updateCount != null && !"0".equals(updateCount)) {
+ int update = Integer.valueOf(updateCount);
+ RankingDocument document = RankUtil.updateRankDocument(update-1);
+ if (document == null) {
+ detail.setResponse(buildErrorResponse("排行榜已经被您翻到底啦,没有了"));
+ break;
+ }
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ detail.getDirectives().add(render);
+ setSessionAttribute("pageIndex",null);
+ detail.getAttributes().put("pageIndex",null);
+ setSessionAttribute("count", document.getCount());
+ detail.getAttributes().put("count", document.getCount());
+ setSessionAttribute("updateCount", String.valueOf(update-1));
+ detail.getAttributes().put("updateCount", String.valueOf(update-1));
+ detail.setResponse(buildErrorResponse(new StringBuilder("为您刷新排行榜,下面是排行")
+ .append(update*15).append("到").append(update*15+15).append("的作品").toString()));
+ break;
}
- dplBotService.setSessionAttribute("pageSign", "4");
- detail.getAttributes().put("pageSign", "4");
- dplBotService.setSessionAttribute(BACK_TRACE, "04");
- detail.getAttributes().put(BACK_TRACE, "04");
- LAST_OUTTIME_RESULT.put(userId, detail);
- //LAST_OUTTIME_RESULT.put(userId, new Response());
- return;
- } else if ("collect".equals(intentName) || "unCollect".equals(intentName)) {
- if (getAccessToken() == null) {
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "该功能需要登录,请说小度小度,登录");
+ index -= 4;
+ if (index < 0) index = 0;
+ scroll.setIndex(index);
+ scroll.setAlign(ScrollToIndexCommand.AlignType.FIRST);
+ executeCommands.addCommand(scroll);
+ addDirective(executeCommands);
+ detail.getDirectives().add(executeCommands);
+ setSessionAttribute("pageIndex", String.valueOf(index));
+ detail.getAttributes().put("pageIndex", String.valueOf(index));
+ break;
+ }
+ case 5:{
+ String category = getSessionAttribute("category");
+ if (category == null) category = "古风";
+ String recommendNextCount = getSessionAttribute("comCnt");
+ if (recommendNextCount == null || "1".equals(recommendNextCount)) {
+ detail.setResponse(buildErrorResponse("客观,前面没啦,没法往前翻了"));
+ break;
+ }
+ int count = Integer.parseInt(recommendNextCount);
+ RecommandDocument document = RecommendUtil.getCategory(count-2,category);
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ detail.getDirectives().add(render);
+ setSessionAttribute("comCnt",String.valueOf(count-1));
+ detail.getAttributes().put("comCnt",String.valueOf(count-1));
+ break;
+ }
+ default:{
+ detail.setResponse(buildErrorResponse("该功能还没实现"));
+ }
+ }
+ LAST_OUTTIME_RESULT.put(userId,detail);
+ }
+
+ private void dealOpenNumIntent(OverTimeDetail detail, String userId) {
+ String trace = getSessionAttribute("trace");
+ if (trace == null || trace.charAt(1) == '0') {
+ String numStr = getSlot("sys.number");
+ int num = 1;
+ if (numStr != null) num = Integer.parseInt(numStr);
+ detail.setResponse(dealOpenNumInHome(num, detail));
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ return;
+ } else if (trace.length() > 2) {
+ detail.setResponse(buildErrorResponse("客官,您在这个页面想打开啥"));
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ return;
+ }
+ char page = trace.charAt(1);
+ switch (page){
+ case '1':
+ case '2': detail.setResponse(dealOpenNum(getSessionAttribute(PRE_COLLE), detail)); break;
+ case '3': detail.setResponse(dealOpenNumInRecommend(getSessionAttribute("recommand"),detail)); break;
+ case '4': detail.setResponse(dealOpenNum(getSessionAttribute("ranking"),detail)); break;
+ case '5': detail.setResponse(dealOpenNumInCategory(userId, detail));break;
+ default:{
+ OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "屏幕上的图标都是可以点击的哦");
+ detail.getResponse().setOutputSpeech(outputSpeech);
+ }
+ }
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ }
+
+ private void dealOpenCollectIntent(OverTimeDetail detail, String userId) {
+ if (getAccessToken() == null) {
+ OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "该功能需要登录,请说小度小度,登录");
+ detail.setResponse(new Response(outputSpeech));
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ } else {
+ String appUserId = getSessionAttribute("userId");
+ if (appUserId == null) {
+ appUserId = DplbotServiceUtil.getUsUserId(userId, getAccessToken());
+ if (appUserId == null) {
+ OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, SORRY_UNCATCH);
detail.setResponse(new Response(outputSpeech));
LAST_OUTTIME_RESULT.put(userId, detail);
return;
}
- boolean collect = "collect".equals(intentName);
- boolean inProductInfo = false;
- boolean inPlayInfo = false;
- String botAccount;
- String trace = dplBotService.getSessionAttribute("trace");
- if (trace == null || trace.length() <= 2) {
- botAccount = dplBotService.getSessionAttribute("botAcc");
- if(botAccount == null) {
- String word = COLLECT_FAIL;
- if (!collect) word = UN_COLLECT_FAIL;
- detail.setResponse(buildErrorResponse(word));
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- }
- } else {
- if (StringUtils.endsWith(trace, File.separator)) {
- botAccount = trace.substring(2, trace.length()-1);
- inPlayInfo = true;
+ }
+ CollectHistoryDocument document = TempleUtils.getCollectPage(Long.parseLong(appUserId));
+ if (document == null) {
+ backToHome(detail);
+ detail.setResponse(buildErrorResponse("您还未收藏过任何作品,快去收藏吧"));
+ return;
+ }
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ setSessionAttribute(PRE_COLLE,document.getIdToken());
+ setSessionAttribute(BACK_TRACE, "01");
+ detail.getAttributes().put(PRE_COLLE, document.getIdToken());
+ detail.getAttributes().put(BACK_TRACE,"01");
+ detail.getDirectives().add(render);
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ }
+ }
+
+ private void dealLoadIntent(OverTimeDetail detail, String userId) {
+ detail.setResponse(load());
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ }
+
+ private void dealBackIntent(OverTimeDetail detail, String userId) {
+ String trace = getSessionAttribute(BACK_TRACE);
+ char second;
+ if (trace == null || trace.length() <= 2 || getQuery().contains("首")) {
+ // home page
+ backToHome(detail);
+ if (trace != null && StringUtils.endsWith(trace,File.separator)) sendCancellToTerminate(userId);
+ } else if (StringUtils.endsWith(trace,File.separator)){
+ String botAccount = trace.substring(2, trace.length()-1);
+ log.info("返回作品的id:{}", botAccount);
+ backToBotIntro(botAccount, detail);
+ sendCancellToTerminate(userId);
+ } else {
+ second = trace.charAt(1);
+ switch (second){
+ // home page
+ case '0':{
+ backToHome(detail);
+ break;
+ }
+ case '1': {
+ //collect
+ String appUserId = getSessionAttribute("userId");
+ if (appUserId == null) {
+ appUserId = DplbotServiceUtil.getUsUserId(userId, getAccessToken());
+ if (appUserId == null) {
+ backToHome(detail);
+ break;
+ }
}
- else {
- inProductInfo = true;
- botAccount = trace.substring(2);
+ CollectHistoryDocument document = TempleUtils.getCollectPage(Long.parseLong(appUserId));
+ if (document == null) {
+ backToHome(detail);
+ detail.setResponse(buildErrorResponse("您还未收藏过任何作品,快去收藏吧"));
+ break;
}
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ setSessionAttribute(BACK_TRACE, "01");
+ setSessionAttribute(PRE_COLLE,document.getIdToken());
+ detail.getAttributes().put(BACK_TRACE,"01");
+ detail.getAttributes().put(PRE_COLLE,document.getIdToken());
+ detail.getDirectives().add(render);
+ break;
}
- try {
- boolean alreadyCollected;
- final String botAccountFinal = botAccount;
- String appUserId = dplBotService.getSessionAttribute("userId");
- if (appUserId == null) appUserId = getUserIdByToken(getAccessToken());
- if (appUserId != null) {
- AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
- AppFavoriteTB entity = new AppFavoriteTB();
- entity.setBotId(botAccount);
- entity.setUserId(Integer.parseInt(appUserId));
- Example example = Example.of(entity);
- alreadyCollected = repository.exists(example);
- if (alreadyCollected) {
- if (collect) detail.setResponse(buildErrorResponse("您之前就已经收藏过该作品啦,看来你真的很喜欢它"));
- else {
- POOL.submit(new UnCollectThread(botAccountFinal, appUserId));
- POOL.execute(() -> {
- UserBehaviorData data = USER_HISTORY.get(getUserId());
- if(data == null) getUserFavorite();
- else {
- data.getUserBotId2Collected().remove(botAccountFinal);
- }
- });
- String botName = ScheduleService.PRODUCT_ID_DETAIL.get(botAccount).getName();
- if (inProductInfo) {
- ExecuteCommands commands = changeIconIdTextAfterCollect(false, botAccount);
- detail.getDirectives().add(commands);
- } else if (inPlayInfo) {
- changeCollectIconInPlay(false);
- }
- if (botName == null) detail.setResponse(buildErrorResponse(UN_COLLECT_BOT_WORD));
- else detail.setResponse(buildErrorResponse(String.format(UN_COLLECT_BOT_WORD_MG,botName)));
- }
- } else {
- if (collect) {
- POOL.submit(new CollectThread(botAccountFinal, appUserId));
- POOL.execute(() -> {
- UserBehaviorData data = USER_HISTORY.get(getUserId());
- if(data == null) getUserFavorite();
- else {
- data.getUserBotId2Collected().put(botAccountFinal, byteFill);
- }
- });
- String word = ScheduleService.PRODUCT_ID_DETAIL.get(botAccount).getName();
- if (inProductInfo) {
- ExecuteCommands commands = changeIconIdTextAfterCollect(true, botAccount);
- detail.getDirectives().add(commands);
- } else if (inPlayInfo) {
- changeCollectIconInPlay(true);
- }
- if (word == null) detail.setResponse(buildErrorResponse(COLLECT_BOT_WORD));
- else detail.setResponse(buildErrorResponse(String.format(COLLECT_BOT_WORD_MG, correctName(word))));
- }else {
- detail.setResponse(buildErrorResponse("您还未收藏过该作品,它不在您的收藏列表内"));
- }
- }
- }else {
- detail.setResponse(buildErrorResponse(SORRY_UNCATCH));
+ case '2': {
+ //history
+ CollectHistoryDocument document = TempleUtils.getHistory(getUserId());
+ if (document == null) {
+ backToHome(detail);
+ detail.setResponse(buildErrorResponse("哎呀,可能是您太久没玩了,历史记录已被清空"));
+ break;
}
- } catch (Exception e) {
- log.error("收藏/取消收藏出错:{}",e.toString());
- detail.setResponse(buildErrorResponse(SORRY_UNCATCH));
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ setSessionAttribute(PRE_COLLE,document.getIdToken());
+ setSessionAttribute(BACK_TRACE, "02");
+ detail.getAttributes().put(BACK_TRACE,"02");
+ detail.getAttributes().put(PRE_COLLE,document.getIdToken());
+ detail.getDirectives().add(render);
+ break;
}
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
- } else if ("sendFlower".equals(intentName)) {
- if (getAccessToken() == null) {
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "该功能需要登录,请说小度小度,登录");
- detail.setResponse(new Response(outputSpeech));
- LAST_OUTTIME_RESULT.put(userId, detail);
- return;
+ case '3': {
+ //recommend
+ String recommendNextCount = getSessionAttribute("comCnt");
+ int count = 1;
+ if (recommendNextCount != null) count = Integer.parseInt(recommendNextCount);
+ RecommandDocument recommandDocument = RecommendUtil.getRecommendDocument(count-1);
+ RenderDocument render = new RenderDocument();
+ render.setDocument(recommandDocument);
+ addDirective(render);
+ String token = recommandDocument.getRecommendIdList();
+ if (token != null) {
+ setSessionAttribute("recommand", token);
+ detail.getAttributes().put("recommand",token);
+ }
+ setSessionAttribute(BACK_TRACE, "03");
+ detail.getAttributes().put(BACK_TRACE, "03");
+ detail.getDirectives().add(render);
+ detail.setResponse(buildErrorResponse(new StringBuilder("已为您返回到推荐页").toString()));
+ break;
}
- String num = getSlot("sys.number");
- OutputSpeech outputSpeech;
- String confirmationStatus = dplBotService.getIntent().getConfirmationStatus().name();
- log.info("槽位确认状态:{}",confirmationStatus);
- if ("NONE".equals(confirmationStatus)) {
- if (num == null) {
- log.info("确认送花个数");
- dplBotService.ask("sys.number");
- outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "请问您要送几朵花");
- dplBotService.setExpectSpeech(true);
- } else {
- log.info("确认最终送花意图");
- dplBotService.setConfirmIntent();
- outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText,
- new StringBuilder("您要送").append(num).append("朵花是吗").toString());
- dplBotService.setExpectSpeech(true);
+ case '4': {
+ //rank
+ RankingDocument document = TempleUtils.getRanking();
+ RenderDocument render = new RenderDocument();
+ render.setDocument(document);
+ addDirective(render);
+ detail.getDirectives().add(render);
+ String token = document.getRankBotIds();
+ if (token != null) {
+ setSessionAttribute("ranking", token);
+ detail.getAttributes().put("ranking",token);
}
- detail.getResponse().setOutputSpeech(outputSpeech);
- LAST_OUTTIME_RESULT.put(userId, detail);
- } else if ("CONFIRMED".equals(confirmationStatus)) {
- log.info("确认");
- String price = Config.getProperty("unitPrice");
- if (price != null) {
- //log.info("num:{}",num);
- //log.info("slot:{}",dplBotService.getSlot("sys.number"));
- int unitPrice = Integer.parseInt(price);
- String amount = String.valueOf(unitPrice*Integer.parseInt(num)/100.0);
- String orderId = new StringBuilder(userId).append(System.currentTimeMillis()).toString();
- String appUserId = dplBotService.getSessionAttribute("userId");
- if (appUserId == null) {
- try {
- appUserId = getUserIdByToken(getAccessToken());
- } catch (Exception e) {
- log.error("送花时获取用户app_user_id失败");
- }
- }
- String botId;
- String trace = dplBotService.getSessionAttribute(BACK_TRACE);
- if (trace != null && trace.length() > 2) {
- if (StringUtils.endsWith(trace, File.separator)) {
- botId = trace.substring(2, trace.length()-1);
- }else {
- botId = trace.substring(2);
- }
- XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
- XiaoDuOrderTB response = repository.save(buildBeforePayPojo(botId, appUserId, userId, unitPrice, Integer.parseInt(num), orderId));
-
- //XiaoDuOrderTB check = new XiaoDuOrderTB();
- //check.setOrderId(orderId);
- //Example example = Example.of(check);
- if (response != null && response.getId() != null) {
- String desc = new StringBuilder("感谢您赏赐给该作品的").append(num).append("朵鲜花").toString();
- String name = ScheduleService.PRODUCT_ID_DETAIL.get(botId).getName();
- if (name != null) desc = new StringBuilder("感谢您赏赐给").append(name)
- .append("的").append(num).append("朵鲜花").toString();
- Charge charge = new Charge(amount, orderId, "鲜花", desc);
- charge.setToken(new StringBuilder(botId).append(File.separator).append(num).toString());
- dplBotService.addDirective(charge);
- detail.getDirectives().add(charge);
- detail.setResponse(buildErrorResponse("请扫描二维码完成支付"));
- } else {
- log.error("订单没有插入到xioadu_order_tb");
- detail.setResponse(buildErrorResponse(ERROR_SEND_FLOWER));
- }
- }else {
- log.error("无法获取到botID");
- detail.setResponse(buildErrorResponse(ERROR_SEND_FLOWER));
- }
+ setSessionAttribute(BACK_TRACE, "04");
+ detail.getAttributes().put(BACK_TRACE, "04");
+ break;
+ }
+ case '5':{
+ String category = getSessionAttribute("category");
+ if (category == null) {
+ backToHome(detail);
} else {
- log.error("无法从配置文件中获取到鲜花的单价");
- detail.setResponse(buildErrorResponse(ERROR_SEND_FLOWER));
+ String count = getSessionAttribute("comCnt");
+ int pageIndex = 0;
+ if (count != null) pageIndex = Integer.parseInt(count)-1;
+ RecommandDocument document = RecommendUtil.getCategory(pageIndex, category);
+ RenderDocument render = new RenderDocument(document);
+ addDirective(render);
+ detail.getDirectives().add(render);
+ detail.setResponse(buildErrorResponse(new StringBuilder("已为您返回到")
+ .append(category).append("分类第").append(pageIndex+1).append("页").toString()));
}
- LAST_OUTTIME_RESULT.put(userId, detail);
- } else {
- log.info("否定");
- detail.setResponse(buildErrorResponse("好的,已为您终止"));
- LAST_OUTTIME_RESULT.put(userId, detail);
- }
- return;
- } else if ("start".equals(intentName)) {
- String trace = getSessionAttribute("trace");
- if (trace != null && trace.length() > 2 && !StringUtils.endsWith(trace,File.separator)) {
- String botId = trace.substring(2);
- String enterName = new StringBuilder("我要玩")
- .append(ScheduleService.getProductIdDetail().get(botId).getName()).toString();
- dealDefaultIntent(intentRequest, detail, userId, intentName, enterName);
- }else {
- dealDefaultIntent(intentRequest, detail, userId, intentName, null);
+ break;
}
}
}
+ LAST_OUTTIME_RESULT.put(userId, detail);
}
- private void dealDefaultIntent(IntentRequest intentRequest, OverTimeDetail detail, String userId, String intentName,String word) {
+ private void backToHome(OverTimeDetail detail) {
+ RenderDocument renderDocument = new RenderDocument(LunchUtils.getLunchDocument());
+ addDirective(renderDocument);
+ setSessionAttribute(BACK_TRACE,null);
+ detail.getAttributes().put(BACK_TRACE,null);
+ detail.getDirectives().add(renderDocument);
+ }
+
+ private void dealDefaultIntent(IntentRequest intentRequest, OverTimeDetail detail, String userId,
+ String intentName,String word) {
if (word == null) {
Query query = intentRequest.getQuery();
if (query != null) word = query.getOriginal();
@@ -1692,7 +1290,6 @@ public class DplBotService extends BaseBot {
log.info("小度没有传来任何话语");
detail.setResponse(buildErrorResponse(SORRY_UNCATCH));
LAST_OUTTIME_RESULT.put(userId, detail);
- //LAST_OUTTIME_RESULT.put(userId, buildErrorResponse(SORRY_UNCATCH));
return;
}
}
@@ -1705,20 +1302,16 @@ public class DplBotService extends BaseBot {
if (data == null) {
detail.setResponse(buildErrorResponse(SORRY_UNCATCH));
LAST_OUTTIME_RESULT.put(userId, detail);
- //LAST_OUTTIME_RESULT.put(userId, buildErrorResponse(SORRY_UNCATCH));
return;
}
String text = data.getText();
- if ("funny".equals(intentName)) {
+ if ("funny".equals(intentName) || data.getAipioneerUsername().equals("4151097686")) {
FunnyDocument document = displayFunnyRecommandPage(text);
if (document != null) {
document.getMainTemplate().getItems().get(2).setSrc(data.getAudio());
FUNNY_DEFAULT_DOCUMENT = document;
RenderDocument render = new RenderDocument(document);
- addDirective(new PushStack());
- detail.getDirectives().add(new PushStack());
addDirective(render);
- //detail.getDirectives().add(render);
LAST_OUTTIME_RESULT.put(userId, detail);
setSessionAttribute("pageSign", "6");
detail.getAttributes().put("pageSign", "6");
@@ -1726,56 +1319,35 @@ public class DplBotService extends BaseBot {
}
log.info("funny出现问题");
}
- int i1 = text.indexOf("【");
- int i2 = text.indexOf("@");
- String aside = text.substring(i1+1, i2);
+ String aside = DplbotServiceUtil.getAsideText(text);
log.info("旁白名字:{}",aside);
//log.info("小悟返回:{}", text);
text = text.substring(text.indexOf("】")+1);
+
+ if (ScheduleService.getExceptBotAccount().contains(data.getAipioneerUsername())) {
+ OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, text.substring(text.indexOf("】")+1));
+ detail.getResponse().setOutputSpeech(outputSpeech);
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ return;
+ }
final String botAccount = ScheduleService.getNx2BotToHz1().get(data.getAipioneerUsername());
if (botAccount == null) {
detail.setResponse(buildErrorResponse("不支持该作品换一个吧"));
LAST_OUTTIME_RESULT.put(userId, detail);
- //LAST_OUTTIME_RESULT.put(userId, buildErrorResponse("不支持该作品换一个吧"));
return;
}
String beforeBotAccount = getSessionAttribute("botAcc");
- if (ScheduleService.getExceptBotAccount().contains(botAccount)) {
- OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, text.substring(text.indexOf("】")+1));
- detail.getResponse().setOutputSpeech(outputSpeech);
- LAST_OUTTIME_RESULT.put(userId, detail);
- //LAST_OUTTIME_RESULT.put(userId, new Response(outputSpeech));
- }
- else if (!botAccount.equals(beforeBotAccount)) {
-// List
- container = PLAY_DOCUMENT.getMainTemplate().getItems().get(2).getItems();
-// container.get(1).setSrc(data.getAudio());
-// container.get(0).getItems().get(0).setText(text);
+ if (!botAccount.equals(beforeBotAccount)) {
+ DplbotServiceUtil. updateTheUserBehaviorDataMark(userId);
String productName = ScheduleService.PRODUCT_ID_DETAIL.get(botAccount).getName();
PlayDocument document = PlayUtils.getPlayDocument(correctName(productName), aside,
ScheduleService.getAsideImgUrl(botAccount, aside),
- data.getAudio(), text,doesUserCollectThisBot(botAccount));
+ data.getAudio(), text,DplbotServiceUtil.doesUserCollectThisBot(botAccount, getAccessToken(), userId));
RenderDocument render = new RenderDocument(document);
addDirective(render);
detail.getDirectives().add(render);
- POOL.submit(() -> {
- 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);
- Timestamp timestamp = new Timestamp(System.currentTimeMillis());
- historyTB.setCreateTime(timestamp);
- historyTB.setUpdateTime(timestamp);
- log.info("插入历史数据:{}", botAccount);
- } else {
- historyTB.setLastTime(System.currentTimeMillis());
- log.info("更新历史数据:{}", botAccount);
- }
- repository.save(historyTB);
- });
+ DplbotServiceUtil.updateTheUserHistory(userId, botAccount, getAccessToken());
String trace = getSessionAttribute(BACK_TRACE);
if (trace == null || trace.length() != 2) trace = "00";
trace = new StringBuilder(trace).append(botAccount).append(File.separator).toString();
@@ -1784,7 +1356,6 @@ public class DplBotService extends BaseBot {
detail.getAttributes().put("botAcc", botAccount);
detail.getAttributes().put(BACK_TRACE,trace);
LAST_OUTTIME_RESULT.put(userId, detail);
- //LAST_OUTTIME_RESULT.put(userId, new Response());
} else {
ExecuteCommands executeCommands = new ExecuteCommands();
SetStateCommand audio = new SetStateCommand();
@@ -1808,6 +1379,8 @@ public class DplBotService extends BaseBot {
executeCommands.addCommand(audio);
executeCommands.addCommand(textState);
+ executeCommands.addCommand(asideImg);
+ executeCommands.addCommand(asideText);
// UpdateComponentCommand update = new UpdateComponentCommand();
// update.setComponentId("whole");
@@ -1831,7 +1404,7 @@ public class DplBotService extends BaseBot {
String[] tokenList = new String(Base64.getDecoder().decode(idsToken)).split(File.separator);
if (collectNum > tokenList.length || collectNum <= 0) return buildErrorResponse("这个数字超出了范围");
OnProductDetail detail = ScheduleService.PRODUCT_ID_DETAIL.get(tokenList[collectNum-1]);
- if (doesUserPlayed(detail.getBotAccount())) {
+ if (DplbotServiceUtil.doesUserPlayed(detail.getBotAccount(), getUserId(), getAccessToken())) {
String productName = correctName(detail.getName());
return directInProduct(productName, detail.getBotAccount(), overDetail);
} else {
@@ -1839,22 +1412,42 @@ public class DplBotService extends BaseBot {
}
}
+ private Response dealOpenNumInCategory(String userId, OverTimeDetail detail) {
+ String count = getSessionAttribute("comCnt");
+ int pageIndex = 0;
+ if (count != null) pageIndex = Integer.parseInt(count)-1;
+ String numStr = getSlot("sys.number");
+ int num = 1;
+ if (numStr != null) num = Integer.parseInt(numStr);
+ List categoryBots = ScheduleService.getCategoryProductIdList().get(getSessionAttribute("category"));
+ if (num <= 0 || num > categoryBots.size()) {
+ Response response = buildErrorResponse("这个数字超出了范围,作品的序号已显示在图片左上角");
+ detail.setResponse(response);
+ LAST_OUTTIME_RESULT.put(userId, detail);
+ return response;
+ }
+ String botId = categoryBots.get(pageIndex*16+num-1);
+ String name = ScheduleService.getProductIdDetail().get(botId).getName();
+ Response response;
+ if (DplbotServiceUtil.doesUserPlayed(botId, getUserId(), getAccessToken())) response = directInProduct(correctName(name), botId, detail);
+ else response = enterProductInfo(correctName(name), detail);
+ detail.setResponse(response);
+ return response;
+ }
+
private Response dealOpenNumInHome(int num, OverTimeDetail detail) {
if (num > 0 && num <= 10) {
GameProjectTb bot = ScheduleService.getRecommendList().get(num-1);
log.info("历史:作品id:{}",bot.getBotAccount());
- if (!doesUserPlayed(bot.getBotAccount())) return enterProductInfo(bot.getName(), detail);
+ if (!DplbotServiceUtil.doesUserPlayed(bot.getBotAccount(), getUserId(), getAccessToken())) return enterProductInfo(bot.getName(), detail);
else return directInProduct(bot.getName(), bot.getBotAccount(), detail);
} else if (num > 10 && num <= 20) {
GameProjectTb bot = ScheduleService.getRankingList().get(num-11);
log.info("历史:作品id:{}",bot.getBotAccount());
- if (!doesUserPlayed(bot.getBotAccount())) return enterProductInfo(bot.getName(), detail);
+ if (!DplbotServiceUtil.doesUserPlayed(bot.getBotAccount(), getUserId(), getAccessToken())) return enterProductInfo(bot.getName(), detail);
else return directInProduct(bot.getName(), bot.getBotAccount(), detail);
} else if (num > 20 && num <= 30) {
String categoryName = ScheduleService.CATEGORY[num-21];
-// displayCategoryProd(categoryName);
-// CATEGORY_PROD_HEAD.setHeaderTitle(categoryName);
-// RenderDocument render = new RenderDocument(CATEGORY_PROD);
RecommandDocument document = RecommendUtil.getCategory(0, categoryName);
if (document == null) return buildErrorResponse("不好意思该分类还没有作品");
RenderDocument render = new RenderDocument(document);
@@ -1867,8 +1460,6 @@ public class DplBotService extends BaseBot {
this.setSessionAttribute("pageSign","5");
detail.getAttributes().put("pageSign","5");
return buildErrorResponse(new StringBuilder("为您打开").append(categoryName).append("类作品").toString());
-// this.addDirective(new PushStack());
-// detail.getDirectives().add(new PushStack());
}
else {
return buildErrorResponse("这数字超出我的范围了");
@@ -1881,7 +1472,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());
}
@@ -1889,11 +1480,10 @@ 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);
- PlayDocument document = PlayUtils.getPlayDocument(productName, aside,ScheduleService.getAsideImgUrl(botId, aside),data.getAudio(), text,doesUserCollectThisBot(botId));
+ PlayDocument document = PlayUtils.getPlayDocument(productName, aside,ScheduleService.getAsideImgUrl(botId, aside),
+ data.getAudio(), text,DplbotServiceUtil.doesUserCollectThisBot(botId, getAccessToken(), getUserId()));
RenderDocument render = new RenderDocument(document);
this.setSessionAttribute(PRE_COLLE, null);
@@ -1908,98 +1498,65 @@ public class DplBotService extends BaseBot {
return new Response();
}
- private boolean doesUserPlayed(String botAccount) {
- UserBehaviorData data = USER_HISTORY.get(getUserId());
- if (data != null) return data.getUserBotId2History().containsKey(botAccount);
- return false;
- }
-
private Response enterProductInfo(String productName, OverTimeDetail detail) {
OnProductDetail productDetail = ScheduleService.PRODUCT_NAME_DETAIL.get(productName);
- if (productDetail == null && !productName.equals("清新传")) {
- return buildErrorResponse("目前不支持该作品");
- }
- 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);
+ String imgUrl = new StringBuilder(Constants.IMG_PREFIX).append(productDetail.getBannerImgUrl()).toString();
// 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());
+ String createTime = 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());
+ String author = new StringBuilder(Constants.PRODUCT_INTRO.AUTHOR).append(productDetail.getAuthorName()).toString();
// product labels
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());
// product introduction
- contentText.get(3).getItems().get(0).setText(productDetail.getIntro());
+ String intro = 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);
- icons.get(0).getOnClick().get(0).setComponentId(enterProName);
String accessToken = getAccessToken();
+ String flowers, flowerReward,collectText, collectUrl, collectComId;
if (accessToken != null) {
// flower container button
- Integer count = getUserSendFlowerNum(productDetail.getBotAccount());
- Item flower = icons.get(1);
- flower.getItems().get(1).setText(USER_SEND_FLOWER+count);
- String flowerReward = new StringBuilder(FLOWE).append(productDetail.getBotAccount()).toString();
- flower.setComponentId(flowerReward);
- flower.getOnClick().get(0).setComponentId(flowerReward);
+ Long count = DplbotServiceUtil.getUserSendFlowerNum(productDetail.getBotAccount(), getUserId(), accessToken);
+ flowers = USER_SEND_FLOWER+count;
+ flowerReward = new StringBuilder(FLOWE).append(productDetail.getBotAccount()).toString();
// collection container button
- boolean collec = didUserCollecThisProduct(productDetail.getBotAccount());
- Item collecButton = icons.get(2);
+ boolean collec = DplbotServiceUtil.doesUserCollectThisBot(productDetail.getBotAccount(), accessToken, getUserId());
if (collec) {
- collecButton.getItems().get(1).setText(COLLECED);
- collecButton.getItems().get(0).setSrc(COLLECTED_IMG_URL);
- String unCollecId = new StringBuilder(UN_COLLEC_ID).append(productDetail.getBotAccount()).toString();
- collecButton.setComponentId(unCollecId);
- collecButton.getOnClick().get(0).setComponentId(unCollecId);
+ collectText = COLLECED;
+ collectUrl = COLLECTED_IMG_URL;
+ collectComId = new StringBuilder(UN_COLLEC_ID).append(productDetail.getBotAccount()).toString();
} else {
- collecButton.getItems().get(1).setText(UN_COLLEC);
- collecButton.getItems().get(0).setSrc(UN_COLLECTED_IMG_URL);
- String collecId = new StringBuilder(COLLEC_ID).append(productDetail.getBotAccount()).toString();
- collecButton.setComponentId(collecId);
- collecButton.getOnClick().get(0).setComponentId(collecId);
+ collectText = UN_COLLEC;
+ collectUrl = UN_COLLECTED_IMG_URL;
+ collectComId = new StringBuilder(COLLEC_ID).append(productDetail.getBotAccount()).toString();
}
} else {
- Item flower = icons.get(1);
- flower.getItems().get(1).setText(FLOWER);
- flower.setComponentId(FLOWER_LOAD);
- flower.getOnClick().get(0).setComponentId(FLOWER_LOAD);
-
- Item collecButton = icons.get(2);
- collecButton.getItems().get(1).setText(UN_COLLEC);
- collecButton.getItems().get(0).setSrc(UN_COLLECTED_IMG_URL);
- collecButton.setComponentId(FLOWER_LOAD);
- collecButton.getOnClick().get(0).setComponentId(FLOWER_LOAD);
+ flowers = FLOWER;
+ flowerReward = FLOWER_LOAD;
+
+ collectText = UN_COLLEC;
+ collectUrl = UN_COLLECTED_IMG_URL;
+ collectComId = FLOWER_LOAD; // 提示登录
}
- RenderDocument renderDocument = new RenderDocument(PROD_INFO);
+ ProductInfoDocument document = ProductInfoUtils.getProductINfoDocument(imgUrl, productName, createTime, author, labels.toString(),
+ intro, enterProName, flowerReward, flowers, collectComId, collectUrl, collectText);
+
+ RenderDocument renderDocument = new RenderDocument(document);
this.addDirective(renderDocument);
- this.addDirective(new PushStack());
detail.getDirectives().add(renderDocument);
- detail.getDirectives().add(new PushStack());
String trace = getSessionAttribute(BACK_TRACE);
log.info("before trace------------:{}",trace);
StringBuilder builder = new StringBuilder();
@@ -2042,93 +1599,21 @@ public class DplBotService extends BaseBot {
int number, String orderId) {
XiaoDuOrderTB xiaoDuOrderTB = new XiaoDuOrderTB();
xiaoDuOrderTB.setBotId(botAccount);
- xiaoDuOrderTB.setAppUserId(appUserId);
+ xiaoDuOrderTB.setAppUserId(Long.parseLong(appUserId));
xiaoDuOrderTB.setXiaoduUserId(userId);
xiaoDuOrderTB.setUnitPrice(unitPrice);
xiaoDuOrderTB.setNumber(number);
xiaoDuOrderTB.setIsBuy(false);
xiaoDuOrderTB.setStatus(false);
xiaoDuOrderTB.setChOrderId(orderId);
- long timeStamp = System.currentTimeMillis();
- xiaoDuOrderTB.setTimeStamp(timeStamp);
- Timestamp stamp = new Timestamp(timeStamp);
- xiaoDuOrderTB.setCreateTime(stamp);
- xiaoDuOrderTB.setUpdateTime(stamp);
+ xiaoDuOrderTB.setTimeStamp(System.currentTimeMillis());
return xiaoDuOrderTB;
}
@Override
protected Response onChargeEvent(ChargeEvent chargeEvent) {
- com.baidu.dueros.data.request.pay.event.Payload payload = chargeEvent.getPayload();
- final String chOrderId = chargeEvent.getSellerOrderId();
- final String userId = getUserId();
- String token = chargeEvent.getToken();
- int sepIndex = token.indexOf(File.separator);
- final String botAccount = token.substring(0, sepIndex);
- if (payload.getPurchaseResult().equals("SUCCESS")) {
- // createTimestamp字段与baiduOrderReferenceId字段与之后百度方进行结算使用,
- // 现在createTimestamp由于百度方的bug需等到九月份才能获取到
- final String baiduOrderReferenceId = payload.getBaiduOrderReferenceId();
- final String createTimestamp = "";
- final String num = token.substring(sepIndex+1);
- POOL.submit(() -> {
- XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
- try {
- repository.updateAterSeccessPayed(baiduOrderReferenceId,chOrderId);
- } catch (Exception e) {
-// StringWriter writer = new StringWriter();
-// e.printStackTrace(new PrintWriter(writer,true));
- log.error("更新用户{}的支付状态出错:{},订单信息:订单号:{}.baiduOrderId:{},createTime:{}",
- e.toString(),userId, chOrderId, baiduOrderReferenceId, createTimestamp);
- }
- });
- POOL.submit(() -> {
- try {
- String appUserId = getUserIdByToken(getAccessToken());
- if (appUserId == null) {
- log.error("像app_flower_tb中添加数据失败因为无法获取到用户的id,数据信息:botAccount:{},num:{},xiaoduUserId:{}",
- botAccount,num,getUserId());
- return;
- }
- AppFlowerTBRepository flower = BaseHolder.getBean("appFlowerTBRepository");
- AppFlowerTB flowerTB = new AppFlowerTB();
- flowerTB.setBotName(botAccount);
- flowerTB.setModule(0);
- flowerTB.setNumber(Integer.parseInt(num));
- flowerTB.setOrderId(0);
- flowerTB.setStatus(1);
- flowerTB.setUnitPrice(Double.parseDouble(Config.getProperty("unitPrice", Constants.UNIT_PRICE))/100);
- flowerTB.setUserId(Integer.parseInt(appUserId));
- Timestamp timestamp = new Timestamp(System.currentTimeMillis());
- flowerTB.setCreateTime(timestamp);
- flowerTB.setUpdateTime(timestamp);
- flower.save(flowerTB);
- } catch (Exception e) {
- log.error("像app_flower_tb中添加数据失败,{},数据信息:botAccount:{},num:{},xiaoduUserId:{}",
- e.toString(),botAccount,num,getUserId());
- }
- });
- return buildErrorResponse("恭喜您支付成功,开始体验吧");
- }else {
- log.info("支付发生错误,"+payload.getMessage());
- POOL.submit(() -> {
- XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
- XiaoDuOrderTB pojo = new XiaoDuOrderTB();
- pojo.setChOrderId(chOrderId);
- try {
- repository.delete(pojo);
- } catch (Exception e) {
- log.error("删除用户:{}支付失败的记录失败,订单信息:订单号:{}",userId,chOrderId);
- }
- });
- return buildErrorResponse("很抱歉,您没有支付成功");
- }
- }
-
-
-
- public static void main(String[] args) throws IOException, InterruptedException, ExecutionException, TimeoutException {
- String s = "NDM4MTU1MzY3NDU3NzIwMTM2NDY0MDIxNjQ3NTMzODk5NzYxODgxMTAyOTU1ODY4ODc5MDc3MjA4NjIyMTM5NjM1NjU3Mjc3MDA5MjgzOTM2OTQ5MzQ4Mjk3Mjc0MzI0MjY5ODI4MTM3MzkwNDczMTc3OTM2NTY1NTkwNTMzMTk2MTI1MzU0NTU3NjY3MzkxOTY=";
- String[] tokenList = new String(Base64.getDecoder().decode(s)).split(File.separator);
+ String response = DplbotServiceUtil.dealChargeCallback(chargeEvent, getUserId(), getAccessToken(),
+ getSessionAttribute("userId"));
+ return buildErrorResponse(response);
}
}
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
index 216f9b1..e06fe95 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java
@@ -1,32 +1,47 @@
package ai.qiwu.com.xiaoduhome.service;
import ai.qiwu.com.xiaoduhome.common.BaseHolder;
+import ai.qiwu.com.xiaoduhome.common.Config;
+import ai.qiwu.com.xiaoduhome.common.Constants;
import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.entity.primary.AppFavoriteTB;
+import ai.qiwu.com.xiaoduhome.entity.primary.AppFlowerTB;
+import ai.qiwu.com.xiaoduhome.entity.primary.AppFlowerTBTiny;
import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
-import ai.qiwu.com.xiaoduhome.pojo.Payload;
+import ai.qiwu.com.xiaoduhome.entity.secondary.XiaoDuHistoryTB;
+import ai.qiwu.com.xiaoduhome.entity.secondary.XiaoDuOrderTB;
+import ai.qiwu.com.xiaoduhome.pojo.JYTUserResponse;
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.AppFlowerTBRepository;
import ai.qiwu.com.xiaoduhome.repository.primary.AppFlowerTBTintRepository;
import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuHistoryTBRepository;
+import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuOrderTbRepository;
import com.alibaba.fastjson.JSON;
+import com.baidu.dueros.data.request.pay.event.ChargeEvent;
+import com.baidu.dueros.data.request.pay.event.Payload;
+import com.baidu.dueros.data.response.directive.pay.Charge;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.data.domain.Example;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
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;
+import static ai.qiwu.com.xiaoduhome.common.Constants.XIAOWU_API.*;
+import static ai.qiwu.com.xiaoduhome.service.ScheduleService.curTime;
/**
* @author 苗权威
@@ -35,54 +50,50 @@ import static ai.qiwu.com.xiaoduhome.common.Constants.XIAOWU_API.USER_ID_BY_TOKE
@Slf4j
public class DplbotServiceUtil {
- private static final byte byteFill = 1;
+ private static final byte BYTE_FILL = 1;
private static final int CORE = Runtime.getRuntime().availableProcessors();
- private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(CORE+1, 1500,
+ 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 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 getUserFavorite(String userId, String usUserId) {
+ 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, BYTE_FILL);
}
- });
+ } 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);
- }
- });
+ private static void getUserSendFlowerInfo(String userId, String jytUserId) {
+ 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(jytUserId), 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);
+ usId = getUserIdByToken(accessToken);
data.setJytUserId(usId);
}
return usId;
}
- static String getUserIdByToken(String accessToken, String userId) {
+ private static String getUserIdByToken(String accessToken) {
try {
HashMap headers = new HashMap<>();
headers.put("App-Channel-Id", "JIAOYOUTIANXIA");
@@ -91,11 +102,11 @@ public class DplbotServiceUtil {
log.info("getUserIdByToken:{}",str);
UserInfoByTokenResult info = JSON.parseObject(str, UserInfoByTokenResult.class);
if (info.getRetcode() == 0) {
- Payload payload = JSON.parseObject(info.getPayload(), Payload.class);
+ JYTUserResponse payload = JSON.parseObject(info.getPayload(), JYTUserResponse.class);
String jytUserId = payload.getInfoId();
- log.info("通过Token获取的用户在app端的id:{}", userId);
- UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
- data.setJytUserId(jytUserId);
+ log.info("通过Token获取的用户在app端的id:{}", jytUserId);
+// UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+// data.setJytUserId(jytUserId);
return jytUserId;
}
} catch (Exception e) {
@@ -105,12 +116,12 @@ public class DplbotServiceUtil {
}
static void onLunchGetUserHistory(final String userId) {
- DplbotServiceUtil.getPOOL().submit(() -> {
+ POOL.submit(() -> {
XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
- HashMap userBotId2History = data.getUserBotId2History();
+ HashMap userBotId2History = data.getUserBotId2History();
for (String botId: repository.getUserHostory(userId)) {
- userBotId2History.put(botId, byteFill);
+ userBotId2History.put(botId, ScheduleService.curTime);
}
//log.info("用户历史记录:{}",USER_HISTORY);
});
@@ -118,12 +129,19 @@ public class DplbotServiceUtil {
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);
+ 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, ScheduleService.curTime);
+ }
+ if (accessToken != null) {
+ String jytUserId = DplbotServiceUtil.getUserIdByToken(accessToken);
+ if (jytUserId != null) {
+ data.setJytUserId(jytUserId);
+ getUserFavorite(userId, jytUserId);
+ getUserSendFlowerInfo(userId,jytUserId);
+ }
}
});
}
@@ -162,14 +180,17 @@ public class DplbotServiceUtil {
if (userData != null) {
collected = userData.getUserBotId2Collected().containsKey(botID);
} else {
- getUserFavorite(userId, getUsUserId(userId, accessToken));
+ POOL.submit(() -> 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);
+ String jytUserId = getUsUserId(userId, accessToken);
+ if (jytUserId != null) {
+ AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
+ AppFavoriteTB tb = new AppFavoriteTB();
+ tb.setBotId(botID);
+ tb.setUserId(Long.parseLong(jytUserId));
+ Example example = Example.of(tb);
+ collected = repository.exists(example);
+ }
} catch (Exception e) {
}
}
@@ -182,4 +203,266 @@ public class DplbotServiceUtil {
int i2 = text.indexOf("@");
return text.substring(i1+1, i2);
}
+
+ static Long getUserSendFlowerNum(String botAccount, String userID, String accessToken) {
+ UserBehaviorData data = USER_HISTORY.get(userID);
+ if (data != null) {
+ Long count = data.getUserBotId2Flowers().get(botAccount);
+ if (count == null) count = 0L;
+ return count;
+ } else {
+ onLunchFillUserBehaviorData(accessToken, userID);
+ AppFlowerTBTintRepository repository = BaseHolder.getBean("appFlowerTBTintRepository");
+ List tinies = repository.getByUserIdAndBotId(Long.parseLong(userID), botAccount);
+ if (tinies != null) {
+ long sum = 0;
+ for (AppFlowerTBTiny tiny:tinies) {
+ sum += tiny.getNumber();
+ }
+ return sum;
+ }
+ }
+ return 0L;
+ }
+
+ static boolean didUserCollecThisProduct(String botAccount, String userID, String accessToken, String jytUserId) {
+ UserBehaviorData data = USER_HISTORY.get(userID);
+ if (data != null) {
+ Byte count = data.getUserBotId2Collected().get(botAccount);
+ return count != null;
+ } else {
+ onLunchFillUserBehaviorData(accessToken, userID);
+ if (jytUserId == null) jytUserId = getUserIdByToken(accessToken);
+ if (jytUserId == null) return false;
+ AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
+ AppFavoriteTB favorite = new AppFavoriteTB();
+ favorite.setUserId(Long.parseLong(jytUserId));
+ favorite.setBotId(botAccount);
+ Example example = Example.of(favorite);
+ return repository.exists(example);
+ }
+ }
+
+ static void userUnCollectTheBotInPool(final String userId, final String botAccount, final String accessToken) {
+ POOL.submit(() -> userUnCollectTheBot(userId, botAccount, accessToken));
+ }
+
+ static void userUnCollectTheBot(String userId, String botAccount, String accessToken) {
+ String jytUserId = getUsUserId(userId, accessToken);
+ if (jytUserId != null) {
+ AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
+ repository.deleteByBotIdAndUserId(botAccount, Long.parseLong(jytUserId));
+ }
+
+ UserBehaviorData behaviorData = USER_HISTORY.get(userId);
+ if (behaviorData != null) {
+ behaviorData.getUserBotId2Collected().remove(botAccount);
+ } else {
+ if (jytUserId != null) {
+ UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+ data.setJytUserId(jytUserId);
+ getUserFavorite(userId, jytUserId);
+ getUserSendFlowerInfo(userId, jytUserId);
+ }
+ }
+ }
+
+ static void userCollectTheBotInPool(final String userId, final String botAccount, final String accessToken) {
+ POOL.submit(() -> userCollectTheBot(userId, botAccount, accessToken));
+ }
+
+ static void userCollectTheBot(String userId, String botAccount, String accessToken) {
+ String jytUserId = getUsUserId(userId, accessToken);
+ if (jytUserId != null) {
+ AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
+ AppFavoriteTB entity = new AppFavoriteTB();
+ entity.setBotId(botAccount);
+ entity.setUserId(Long.parseLong(jytUserId));
+ entity.setModule(0);
+ repository.save(entity);
+ }
+ UserBehaviorData behaviorData = USER_HISTORY.get(userId);
+ if (behaviorData != null) {
+ behaviorData.getUserBotId2Collected().put(botAccount, BYTE_FILL);
+ } else {
+ if (jytUserId != null) {
+ UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
+ data.setJytUserId(jytUserId);
+ getUserFavorite(userId, jytUserId);
+ getUserSendFlowerInfo(userId, jytUserId);
+ }
+ }
+ }
+
+ static Charge sendOneFlowerByCharge(String userId, String jytUserId, String accessToken, String trace) {
+ String price = ScheduleService.FLOWER_UNIT_PRICE;
+ int unitPrice = Integer.parseInt(price);
+ String amount = String.valueOf(unitPrice/100.0);
+ String orderId = new StringBuilder(userId).append(System.currentTimeMillis()).toString();
+ if (jytUserId == null) {
+ jytUserId = getUsUserId(userId, accessToken);
+ if (jytUserId == null) return null;
+ }
+ String botId;
+ if (trace != null && trace.length() > 2) {
+ if (StringUtils.endsWith(trace, File.separator)) {
+ botId = trace.substring(2, trace.length()-1);
+ }else {
+ botId = trace.substring(2);
+ }
+ XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
+ XiaoDuOrderTB response = repository.save(buildBeforePayPojo(botId, jytUserId, userId, unitPrice, orderId));
+
+ if (response != null && response.getId() != null) {
+ String desc = new StringBuilder("感谢您赏赐给该作品的").append(1).append("朵鲜花").toString();
+ String name = ScheduleService.PRODUCT_ID_DETAIL.get(botId).getName();
+ if (name != null) desc = new StringBuilder("感谢您赏赐给").append(name)
+ .append("的").append(1).append("朵鲜花").toString();
+ Charge charge = new Charge(amount, orderId, "鲜花", desc);
+ charge.setToken(new StringBuilder(botId).append(File.separator).append(1).toString());
+ return charge;
+ } else {
+ log.error("订单没有插入到xioadu_order_tb");
+ }
+ }else {
+ log.error("无法获取到botID");
+ }
+ return null;
+ }
+
+ private static XiaoDuOrderTB buildBeforePayPojo(String botAccount, String appUserId, String userId, int unitPrice,
+ String orderId) {
+ XiaoDuOrderTB xiaoDuOrderTB = new XiaoDuOrderTB();
+ xiaoDuOrderTB.setBotId(botAccount);
+ xiaoDuOrderTB.setAppUserId(Long.parseLong(appUserId));
+ xiaoDuOrderTB.setXiaoduUserId(userId);
+ xiaoDuOrderTB.setUnitPrice(unitPrice);
+ xiaoDuOrderTB.setNumber(1);
+ xiaoDuOrderTB.setIsBuy(false);
+ xiaoDuOrderTB.setStatus(false);
+ xiaoDuOrderTB.setChOrderId(orderId);
+ xiaoDuOrderTB.setTimeStamp(System.currentTimeMillis());
+ return xiaoDuOrderTB;
+ }
+
+ static boolean doesUserPlayed(String botAccount, String userId, String accessToken) {
+ UserBehaviorData data = USER_HISTORY.get(userId);
+ if (data != null) return data.getUserBotId2History().containsKey(botAccount);
+ onLunchFillUserBehaviorData(accessToken, userId);
+ return false;
+ }
+
+ static void updateTheUserHistory(final String userId,final String botAccount, final String accessToken) {
+ POOL.submit(() -> {
+ UserBehaviorData data = USER_HISTORY.get(userId);
+ if (data == null) {
+ XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
+ XiaoDuHistoryTB historyTB = repository.getByXiaoduUserIdAndBotId(userId, botAccount);
+ if (historyTB == null) {
+ historyTB = new XiaoDuHistoryTB();
+ historyTB.setLastTime(curTime);
+ historyTB.setBotId(botAccount);
+ historyTB.setXiaoduUserId(userId);
+ } else {
+ historyTB.setLastTime(curTime);
+ }
+ repository.saveAndFlush(historyTB);
+ onLunchFillUserBehaviorData(accessToken, userId);
+ } else {
+ data.getUserBotId2History().put(botAccount, curTime);
+ }
+ });
+ }
+
+ static void writeTheUserHistoryInData(final String userId) {
+ POOL.submit(() -> {
+ UserBehaviorData data = USER_HISTORY.remove(userId);
+ if (data != null) {
+ XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
+ for (Map.Entry 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 {
+ historyTB.setLastTime(time);
+ }
+ repository.saveAndFlush(historyTB);
+ }
+ }
+ });
+ }
+
+ static String dealChargeCallback(ChargeEvent chargeEvent, final String userId, final String accessToken, final String jytUserId) {
+ Payload payload = chargeEvent.getPayload();
+ final String chOrderId = chargeEvent.getSellerOrderId();
+ String token = chargeEvent.getToken();
+ int sepIndex = token.indexOf(File.separator);
+ final String botAccount = token.substring(0, sepIndex);
+ if (payload.getPurchaseResult().equals("SUCCESS")) {
+ // createTimestamp字段与baiduOrderReferenceId字段与之后百度方进行结算使用,
+ // 现在createTimestamp由于百度方的bug需等到九月份才能获取到
+ final String baiduOrderReferenceId = payload.getBaiduOrderReferenceId();
+ final String createTimestamp = "";
+ final String num = token.substring(sepIndex+1);
+ POOL.submit(() -> {
+ XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
+ try {
+ repository.updateAterSeccessPayed(baiduOrderReferenceId,chOrderId);
+ } catch (Exception e) {
+// StringWriter writer = new StringWriter();
+// e.printStackTrace(new PrintWriter(writer,true));
+ log.error("更新用户{}的支付状态出错:{},订单信息:订单号:{}.baiduOrderId:{},createTime:{}",
+ e.toString(),userId, chOrderId, baiduOrderReferenceId, createTimestamp);
+ }
+ try {
+ String appUserId = jytUserId;
+ if (appUserId == null) appUserId = getUsUserId(userId,accessToken);
+ if (appUserId == null) {
+ log.error("像app_flower_tb中添加数据失败因为无法获取到用户的id,数据信息:botAccount:{},num:{},xiaoduUserId:{}",
+ botAccount,num,userId);
+ return;
+ }
+ AppFlowerTBRepository flower = BaseHolder.getBean("appFlowerTBRepository");
+ AppFlowerTB flowerTB = new AppFlowerTB();
+ flowerTB.setBotName(botAccount);
+ flowerTB.setModule(0);
+ flowerTB.setNumber(Long.parseLong(num));
+ flowerTB.setOrderId(0L);
+ flowerTB.setStatus(1);
+ flowerTB.setUnitPrice(Double.parseDouble(Config.getProperty("unitPrice", Constants.UNIT_PRICE))/100);
+ flowerTB.setUserId(Long.parseLong(appUserId));
+ Timestamp timestamp = new Timestamp(System.currentTimeMillis());
+ flowerTB.setCreateTime(timestamp);
+ flowerTB.setUpdateTime(timestamp);
+ flower.save(flowerTB);
+ } catch (Exception e) {
+ log.error("像app_flower_tb中添加数据失败,{},数据信息:botAccount:{},num:{},xiaoduUserId:{}",
+ e.toString(),botAccount,num,userId);
+ }
+ });
+ return "恭喜您支付成功,开始体验吧";
+ }else {
+ log.info("支付发生错误,"+payload.getMessage());
+ POOL.submit(() -> {
+ XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
+ XiaoDuOrderTB pojo = new XiaoDuOrderTB();
+ pojo.setBotId(botAccount);
+ pojo.setChOrderId(chOrderId);
+ repository.delete(pojo);
+ });
+ return "很抱歉,您没有支付成功";
+ }
+ }
+
+ static void updateTheUserBehaviorDataMark(final String userId) {
+ POOL.submit(() -> {
+ UserBehaviorData data = USER_HISTORY.get(userId);
+ if (data != null) data.setMark((byte) 1);
+ });
+ }
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java
index 0898047..101668a 100644
--- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java
@@ -48,9 +48,10 @@ class RequestTerminal {
String url = "http://aws-nx2.chewrobot.com:18082/api/works";
HashMap params = new HashMap<>();
params.put("include", "npcHeadImgUrl");
- params.put("aipioneerUsername","1814141710");
- String str = OkHttp3Utils.doGet(url, params);
- AsideImageResponse response = JSON.parseObject(str, AsideImageResponse.class);
- System.out.println(response.getData().getNpcHeadImgUrl());
+ params.put("aipioneerUsername","8343905461");
+// String str = OkHttp3Utils.doGet(url, params);
+// AsideImageResponse response = JSON.parseObject(str, AsideImageResponse.class);
+// System.out.println(response.getData().getNpcHeadImgUrl());
+ requestTerminate("有科幻类的吗", "2352521agag");
}
}
diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RunnableService.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RunnableService.java
new file mode 100644
index 0000000..54a3ef8
--- /dev/null
+++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RunnableService.java
@@ -0,0 +1,100 @@
+package ai.qiwu.com.xiaoduhome.service;
+
+import ai.qiwu.com.xiaoduhome.common.BaseHolder;
+import ai.qiwu.com.xiaoduhome.repository.primary.AppFavoriteTBRepository;
+
+
+/**
+ * 存储之前留存的代码,以备后用
+ * @author 苗权威
+ * @dateTime 19-9-24 上午10:49
+ */
+public class RunnableService {
+ static class UnCollectThread implements Runnable {
+ final String botId;
+ final String userId;
+
+ UnCollectThread(String botId, String userId) {
+ this.botId = botId;
+ this.userId = userId;
+ }
+
+ @Override
+ public void run() {
+ AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
+ repository.deleteByBotIdAndUserId(botId, Long.parseLong(userId));
+ }
+ }
+
+// class SendFlowerBuyToXiaoduTB implements Runnable {
+// BuyEvent buyEvent;
+//
+// SendFlowerBuyToXiaoduTB(BuyEvent buyEvent) {
+// this.buyEvent = buyEvent;
+// }
+// @Override
+// public void run() {
+// try {
+// String baiduOrderReferenceId = buyEvent.getPayload().getBaiduOrderReferenceId();
+// long timeStamp = Long.parseLong(buyEvent.getTimestamp())*1000;
+// String botId = new String(Base64.getDecoder().decode(buyEvent.getToken()), StandardCharsets.UTF_8);
+// String userId = getSessionAttribute("userId");
+// Integer unitePrice = Integer.parseInt(Config.getProperty("unitPrice", Constants.UNIT_PRICE));
+// if (userId == null) userId = getUserIdByToken(getAccessToken());
+// if (userId == null) throw new Exception("未获取到用户id");
+// XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
+// XiaoDuOrderTB orderTB = new XiaoDuOrderTB();
+// orderTB.setAppUserId(userId);
+// orderTB.setBotId(botId);
+// orderTB.setNumber(1);
+// orderTB.setIsBuy(true);
+// orderTB.setOrderId(baiduOrderReferenceId);
+// orderTB.setTimeStamp(timeStamp);
+// orderTB.setUnitPrice(unitePrice);
+// orderTB.setXiaoduUserId(getUserId());
+// Timestamp timestamp = new Timestamp(System.currentTimeMillis());
+// orderTB.setCreateTime(timestamp);
+// orderTB.setUpdateTime(timestamp);
+// XiaoDuOrderTB response = repository.save(orderTB);
+// if (response == null) throw new Exception("向interface_db中的xiaodu_order_tb插入数据失败");
+// } catch (Exception e) {
+// log.error("用户成功支付,xiaodu_order_tb操作出现错误:{}",e.toString());
+// }
+// }
+// }
+//
+// class SendFlowerThread implements Runnable {
+// BuyEvent buyEvent;
+//
+// SendFlowerThread(BuyEvent buyEvent) {
+// this.buyEvent = buyEvent;
+// }
+//
+// @Override
+// public void run() {
+// //String baiduOrderReferenceId = buyEvent.getPayload().getBaiduOrderReferenceId();
+// String timeStamp = buyEvent.getTimestamp();
+// String botId = new String(Base64.getDecoder().decode(buyEvent.getToken()), StandardCharsets.UTF_8);
+// String userId = getSessionAttribute("userId");
+// int unitePrice = Integer.parseInt(Config.getProperty("unitPrice", Constants.UNIT_PRICE));
+// try {
+// if (userId == null) userId = getUserIdByToken(getAccessToken());
+// if (userId == null) throw new Exception("未获取到用户id");
+// AppFlowerTBRepository flowerRepository = BaseHolder.getBean("appFlowerTBRepository");
+// AppFlowerTB flowerTB = new AppFlowerTB();
+// flowerTB.setNumber(1);
+// flowerTB.setModule(0);
+// flowerTB.setBotName(botId);
+// flowerTB.setUserId(Integer.parseInt(userId));
+// flowerTB.setStatus(1);
+// flowerTB.setUnitPrice(unitePrice/100.0);
+// flowerTB.setCreateTime(new Timestamp(Long.parseLong(timeStamp)*1000));
+// flowerTB.setOrderId(0);
+// AppFlowerTB response = flowerRepository.save(flowerTB);
+// if (response == null) throw new Exception("向app_flower_tb中插入数据失败");
+// } catch (Exception e) {
+// log.error("用户成功支付,game_flower_tb操作出现错误:{}",e.toString());
+// }
+// }
+// }
+}
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 eac603b..d6807f1 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
@@ -1,9 +1,11 @@
package ai.qiwu.com.xiaoduhome.service;
+import ai.qiwu.com.xiaoduhome.common.Config;
import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.common.temple.onLunch.LunchUtils;
import ai.qiwu.com.xiaoduhome.entity.primary.GameProjectTb;
import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
+import ai.qiwu.com.xiaoduhome.pojo.UserBehaviorData;
import ai.qiwu.com.xiaoduhome.pojo.playAside.AsideImageResponse;
import ai.qiwu.com.xiaoduhome.repository.primary.AllOnProductInfoRepository;
import ai.qiwu.com.xiaoduhome.repository.primary.GameProjectTbRepository;
@@ -25,6 +27,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import static ai.qiwu.com.xiaoduhome.common.Constants.DPL_COMPONENT_ID.DEFAULT_ASIDE_IMG_URL;
+import static ai.qiwu.com.xiaoduhome.common.Constants.UNIT_PRICE;
import static ai.qiwu.com.xiaoduhome.common.Constants.XIAOWU_API.ASIDE_IMG_URL;
/**
@@ -62,6 +65,10 @@ public class ScheduleService implements InitializingBean {
private final XiaoDuOrderTbRepository xiaoDuOrderTbRepository;
+ static final String FLOWER_UNIT_PRICE = Config.getProperty("unitPrice", UNIT_PRICE);
+
+ static volatile Long curTime = System.currentTimeMillis();
+
@Autowired
public ScheduleService(GameProjectTbRepository gameProjectTbRepository,
ProjectLabelRepository projectLabelRepository,
@@ -75,6 +82,26 @@ public class ScheduleService implements InitializingBean {
this.xiaoDuOrderTbRepository = xiaoDuOrderTbRepository;
}
+ @Scheduled(cron = "0 */30 * * * ?")
+ public void cleatUserBehaviorData() {
+ DplbotServiceUtil.POOL.submit(() -> {
+ List needClear = new ArrayList<>();
+ for (String userId: DplbotServiceUtil.USER_HISTORY.keySet()) {
+ UserBehaviorData data = DplbotServiceUtil.USER_HISTORY.get(userId);
+ if (data != null) {
+ if (data.getMark() == 1) data.setMark((byte) 0);
+ else needClear.add(userId);
+ }
+ }
+ for (String userId: needClear) DplbotServiceUtil.USER_HISTORY.remove(userId);
+ });
+ }
+
+ @Scheduled(cron = "*/10 * * * * ?")
+ public void updateTheCurTime() {
+ DplbotServiceUtil.POOL.submit(() -> curTime = System.currentTimeMillis());
+ }
+
@Scheduled(cron = "0 0 19 * * ?")
public void initRankingList() {
new Thread(() -> {
@@ -200,17 +227,19 @@ public class ScheduleService implements InitializingBean {
NX2_BOT_TO_HZ1.put("5741775745", "1586892647");
NX2_BOT_TO_HZ1.put("9159908109", "3899761881");
NX2_BOT_TO_HZ1.put("6035298742", "6559053319");
+
NX2_BOT_TO_HZ1.put("4366487183", "6402164753");
NX2_BOT_TO_HZ1.put("236055939", "6569120969");
NX2_BOT_TO_HZ1.put("9965361790", "9727432426");
NX2_BOT_TO_HZ1.put("2428131253", "9369493482");
NX2_BOT_TO_HZ1.put("8343905461", "7667391968");
+
NX2_BOT_TO_HZ1.put("2675579304", "2167984446");
NX2_BOT_TO_HZ1.put("6259213309", "438155367");
-
NX2_BOT_TO_HZ1.put("4707303948", "2139635657");
NX2_BOT_TO_HZ1.put("2090828382", "4731779365");
NX2_BOT_TO_HZ1.put("8907881060", "4577201364");
+
NX2_BOT_TO_HZ1.put("7051119238", "7907720862");
NX2_BOT_TO_HZ1.put("7414315062", "1029558688");
}
@@ -242,7 +271,6 @@ public class ScheduleService implements InitializingBean {
EXCEPT_BOT_ACCOUNT.add("9256014607");
EXCEPT_BOT_ACCOUNT.add("1778815830");
EXCEPT_BOT_ACCOUNT.add("6823941516");
- EXCEPT_BOT_ACCOUNT.add("4151097686");
}
public static HashMap getProductIdDetail() {
--
libgit2 0.27.1