Commit 75bae4da by 苗权威

9.5

parent 8af81657
...@@ -20,6 +20,9 @@ public interface TTSConstants { ...@@ -20,6 +20,9 @@ public interface TTSConstants {
String DELETE_FAIL = "删除文件失败"; String DELETE_FAIL = "删除文件失败";
String DELETE_OFFLINE_FAIL = "对线下测试服务器的删除指令调用失败"; String DELETE_OFFLINE_FAIL = "对线下测试服务器的删除指令调用失败";
String TTS_REMOTE_ADDR = "127.0.0.1";
String TTS_REMOTE_LOCALHOST = "localhost";
interface BAI_DU { interface BAI_DU {
String APP_ID = "16998411"; String APP_ID = "16998411";
String API_KEY = "bHlKRYe9d5o7Ad2z2D5aGiVw"; String API_KEY = "bHlKRYe9d5o7Ad2z2D5aGiVw";
......
...@@ -7,8 +7,11 @@ import lombok.extern.slf4j.Slf4j; ...@@ -7,8 +7,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import static ai.qiwu.com.tts_service.common.TTSConstants.TTS_REMOTE_ADDR;
/** /**
* @author 苗权威 * @author 苗权威
...@@ -38,16 +41,18 @@ public class TTSController { ...@@ -38,16 +41,18 @@ public class TTSController {
@GetMapping("/api/tts") @GetMapping("/api/tts")
public void tts_get(@RequestParam(required = false) String person, @RequestParam(required = false) String tone, public void tts_get(@RequestParam(required = false) String person, @RequestParam(required = false) String tone,
@RequestParam(required = false) String text, @RequestParam(required = false) String botname, @RequestParam(required = false) String text, @RequestParam(required = false) String botname,
@RequestParam(required = false) String _type, @RequestParam(required = false) String volume, @RequestParam(required = false) String _type, @RequestParam(required = false) String volume,
@RequestParam(required = false) String pitch, @RequestParam(required = false) String speed, @RequestParam(required = false) String pitch, @RequestParam(required = false) String speed,
HttpServletResponse servletResponse) { @RequestParam(required = false) String get_online, HttpServletResponse servletResponse) {
TTSRequest ttsRequest = new TTSRequest(person, text, _type, pitch, tone, botname, volume, speed); TTSRequest ttsRequest = new TTSRequest(person, text, _type, pitch, tone, botname, volume, speed,get_online);
ttService.tts(ttsRequest, "GET", servletResponse); ttService.tts(ttsRequest, "GET", servletResponse);
} }
@PostMapping("/api/tts") @PostMapping("/api/tts")
public void tts_post(@RequestBody TTSRequest ttsRequest, HttpServletResponse response) { public void tts_post(@RequestBody TTSRequest ttsRequest, HttpServletResponse response) {
// String remoteAddr = request.getRemoteAddr();
// if (!TTS_REMOTE_ADDR.equals(remoteAddr) && !TTS_REMOTE_ADDR.equals(remoteAddr))
ttService.tts(ttsRequest, "POST", response); ttService.tts(ttsRequest, "POST", response);
} }
......
...@@ -22,9 +22,10 @@ public class TTSRequest { ...@@ -22,9 +22,10 @@ public class TTSRequest {
private String botname; private String botname;
private String volume; private String volume;
private String speed; private String speed;
private String get_online;
public TTSRequest(String person, String text, String _type, String pitch, public TTSRequest(String person, String text, String _type, String pitch,
String tone, String botname, String volume, String speed) { String tone, String botname, String volume, String speed,String get_online) {
this.person = person; this.person = person;
this.text = text; this.text = text;
this._type = _type; this._type = _type;
...@@ -33,5 +34,6 @@ public class TTSRequest { ...@@ -33,5 +34,6 @@ public class TTSRequest {
this.botname = botname; this.botname = botname;
this.volume = volume; this.volume = volume;
this.speed = speed; this.speed = speed;
this.get_online = get_online;
} }
} }
...@@ -36,7 +36,7 @@ public class Initialize implements InitializingBean { ...@@ -36,7 +36,7 @@ public class Initialize implements InitializingBean {
private static final String SERVER_NAME; private static final String SERVER_NAME;
private static final String SERVER_URL; private static final String SERVER_URL;
private static final String AUDIO_DIR; private static final String AUDIO_DIR;
private static final String ONLINE_SERVER; private static final Map<Integer, String> ONLINE_SERVER = new HashMap<>();
private static final String OFFLINE_SERVER; private static final String OFFLINE_SERVER;
private static final String THIRD_PARTY; private static final String THIRD_PARTY;
private static final String CHANGE_SOUND; private static final String CHANGE_SOUND;
...@@ -53,7 +53,14 @@ public class Initialize implements InitializingBean { ...@@ -53,7 +53,14 @@ public class Initialize implements InitializingBean {
SERVER_NAME = Config.getProperty("server_name"); SERVER_NAME = Config.getProperty("server_name");
SERVER_URL = Config.getProperty("server_url"); SERVER_URL = Config.getProperty("server_url");
AUDIO_DIR = Config.getProperty("audio_dir"); AUDIO_DIR = Config.getProperty("audio_dir");
ONLINE_SERVER = Config.getProperty("online_sever");
String[] online_sever_list = Config.getProperty("online_sever").split(",");
for (String serverAdd: online_sever_list) {
int key = Integer.parseInt(serverAdd.substring(0,1));
String value = serverAdd.substring(2);
ONLINE_SERVER.put(key, value);
}
OFFLINE_SERVER = Config.getProperty("offline_server"); OFFLINE_SERVER = Config.getProperty("offline_server");
THIRD_PARTY = Config.getProperty("third_party_tts_text"); THIRD_PARTY = Config.getProperty("third_party_tts_text");
CHANGE_SOUND = Config.getProperty("change_sound_path"); CHANGE_SOUND = Config.getProperty("change_sound_path");
...@@ -93,7 +100,7 @@ public class Initialize implements InitializingBean { ...@@ -93,7 +100,7 @@ public class Initialize implements InitializingBean {
return; return;
} }
if (withOnLine != null && withOnLine != 0) { if (withOnLine != null && withOnLine != 0) {
String url = String.format("%s:9%03d/synthesize", Initialize.getOnlineServer(), speakerInfo.getId()); String url = String.format("%s:9%03d/synthesize", Initialize.getOnlineServer(withOnLine), speakerInfo.getId());
URL_LS.add(url); URL_LS.add(url);
if (StringUtils.isBlank(init_person)) { if (StringUtils.isBlank(init_person)) {
init_person = person; init_person = person;
...@@ -201,8 +208,8 @@ public class Initialize implements InitializingBean { ...@@ -201,8 +208,8 @@ public class Initialize implements InitializingBean {
return AUDIO_DIR; return AUDIO_DIR;
} }
private static String getOnlineServer() { private static String getOnlineServer(int withOnline) {
return ONLINE_SERVER; return ONLINE_SERVER.get(withOnline);
} }
static String getOfflineServer() { static String getOfflineServer() {
......
...@@ -4,7 +4,7 @@ server_url=http://aws-nx2.chewrobot.com:9663 ...@@ -4,7 +4,7 @@ server_url=http://aws-nx2.chewrobot.com:9663
#server_url=http://aliyun-hz1.chewrobot.com:9663 #server_url=http://aliyun-hz1.chewrobot.com:9663
audio_dir=/root/TTS-service/audio audio_dir=/root/TTS-service/audio
#audio_dir=/root/GameEditor/mqw/project/tts/audio #audio_dir=/root/GameEditor/mqw/project/tts/audio
online_sever=http://dev01.centaurstech.com online_sever=1:http://dev01.centaurstech.com,2:http://dev01.centaurstech.com
offline_server=http://dev01.centaurstech.com:9001 offline_server=http://dev01.centaurstech.com:9001
#offline_server=http://aliyun-hz1.chewrobot.com:9001 #offline_server=http://aliyun-hz1.chewrobot.com:9001
#第三方tts标记 #第三方tts标记
......
...@@ -24,6 +24,7 @@ public interface Constants { ...@@ -24,6 +24,7 @@ public interface Constants {
"9AWUhbas+LG9mds="; "9AWUhbas+LG9mds=";
Integer GET_PRODUCT_TOKEN_FAIL_STATUS = 10086; Integer GET_PRODUCT_TOKEN_FAIL_STATUS = 10086;
String IMG_PREFIX = "https://aliyun-hz1.chewrobot.com"; String IMG_PREFIX = "https://aliyun-hz1.chewrobot.com";
String IMG_CUSTOM_PREFIX = "https://aliyun-hz1.chewrobot.com/xiaoduhome/image/";
String PRE_PRODUCT_IMG = "prod:"; String PRE_PRODUCT_IMG = "prod:";
String PRE_ENTER_PRODUCT = "enter"; String PRE_ENTER_PRODUCT = "enter";
String PRE_PRODUCT_PLAY = "我要玩"; String PRE_PRODUCT_PLAY = "我要玩";
......
...@@ -53,4 +53,5 @@ public class FrameTemple implements Agent{ ...@@ -53,4 +53,5 @@ public class FrameTemple implements Agent{
@JsonProperty("background-color") @JsonProperty("background-color")
private String backgroundColor; private String backgroundColor;
private String color; private String color;
private String position;
} }
...@@ -3,6 +3,8 @@ package ai.qiwu.com.xiaoduhome.common.temple.funny; ...@@ -3,6 +3,8 @@ package ai.qiwu.com.xiaoduhome.common.temple.funny;
import ai.qiwu.com.xiaoduhome.common.temple.rank.RankingPojo; import ai.qiwu.com.xiaoduhome.common.temple.rank.RankingPojo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data; import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -11,7 +13,8 @@ import java.util.List; ...@@ -11,7 +13,8 @@ import java.util.List;
* @author 苗权威 * @author 苗权威
* @dateTime 19-8-30 上午11:28 * @dateTime 19-8-30 上午11:28
*/ */
@Data @Getter
@Setter
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class FunnyMainTemplate { public class FunnyMainTemplate {
private List<String> parameters = new ArrayList<>(); private List<String> parameters = new ArrayList<>();
......
...@@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; ...@@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data; import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.List; import java.util.List;
...@@ -12,7 +14,8 @@ import java.util.List; ...@@ -12,7 +14,8 @@ import java.util.List;
* @author 苗权威 * @author 苗权威
* @dateTime 19-8-30 上午11:18 * @dateTime 19-8-30 上午11:18
*/ */
@Data @Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class FunnyPojo { public class FunnyPojo {
......
package ai.qiwu.com.xiaoduhome.common.temple.onLunch;
import lombok.Getter;
import lombok.Setter;
/**
* @author 苗权威
* @dateTime 19-9-5 下午5:05
*/
@Getter
@Setter
public class LunchBotData {
private String imageSrc;
private String imageId;
private String imageName;
private Integer num;
public LunchBotData(String imageSrc, String imageId, String imageName) {
this.imageSrc = imageSrc;
this.imageId = imageId;
this.imageName = imageName;
}
}
package ai.qiwu.com.xiaoduhome.common.temple.onLunch;
import com.baidu.dueros.data.response.directive.dpl.Document;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author 苗权威
* @dateTime 19-9-5 下午4:32
*/
@Getter
@Setter
@ToString
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class LunchDocument extends Document {
private LunchMainTemplate mainTemplate;
}
package ai.qiwu.com.xiaoduhome.common.temple.onLunch;
import ai.qiwu.com.xiaoduhome.common.temple.funny.FunnyPojo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
/**
* @author 苗权威
* @dateTime 19-9-5 下午4:33
*/
@Getter
@Setter
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class LunchMainTemplate {
private List<String> parameters = new ArrayList<>();
private List<LunchPojo> items;
public LunchMainTemplate() {
this.parameters.add("payload");
this.items = new ArrayList<>();
}
}
package ai.qiwu.com.xiaoduhome.common.temple.onLunch;
import ai.qiwu.com.xiaoduhome.common.temple.FrameTemple;
import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author 苗权威
* @dateTime 19-9-5 下午4:34
*/
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class LunchPojo {
private String type;
private String position;
private String height;
private String width;
private String left;
private String top;
private String src;
private List<LunchPojo> items;
@JsonProperty("padding-right")
private String paddingRight;
private String componentId;
private String headerTitle;
private Boolean hasBackIcon;
private String direction;
@JsonProperty("margin-bottom")
private String marginBottom;
@JsonProperty("margin-left")
private String marginLeft;
@JsonProperty("margin-right")
private String marginRight;
@JsonProperty("margin-top")
private String marginTop;
@JsonProperty("border-radius")
private String borderRadius;
@JsonProperty("scale-type")
private String scaleType;
private List<Event> onClick;
@JsonProperty("background-color")
private String backgroundColor;
@JsonProperty("align-items")
private String alignItems;
private String text;
@JsonProperty("font-size")
private String fontSize;
private List<LunchBotData> data;
private List<FrameTemple> firstItem;
}
package ai.qiwu.com.xiaoduhome.common.temple.onLunch;
import ai.qiwu.com.xiaoduhome.common.temple.TempleUtils;
import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
import ai.qiwu.com.xiaoduhome.service.ScheduleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @author 苗权威
* @dateTime 19-9-5 下午4:48
*/
@Slf4j
public class LunchUtils {
private static final LunchPojo LUNCH_LIST_CON = buildImgFrmTxtContainer();
private static final LunchPojo LUNCH_LIST_CATEGORY_CON = buildCategoryList();
private static final LunchPojo LUNCH_HEAD = buildLunchHead();
private static final LunchPojo LUNCH_BACK_IMG = buildLunchBackgroundImg();
private volatile static LunchDocument lunchDocument = buildLunchDocument();
public static LunchDocument buildLunchDocument() {
LunchDocument document = new LunchDocument();
LunchMainTemplate mainTemplate = new LunchMainTemplate();
document.setMainTemplate(mainTemplate);
LunchPojo conRecommend = buildLunchList(TempleUtils.buildDataList(ScheduleService.getRecommendList(),1));
conRecommend.setFirstItem(Collections.singletonList(TempleUtils.getFrameRecommand()));
LunchPojo conRanking = buildLunchList(TempleUtils.buildDataList(ScheduleService.getRankingList(), 11));
conRanking.setFirstItem(Collections.singletonList(TempleUtils.getFrameRakking()));
LunchPojo conCategory = buildLunchCategoryList(TempleUtils.buildCategoryDataList());
conCategory.setFirstItem(Collections.singletonList(TempleUtils.getFrameCategory()));
LunchPojo scroll = buildLunchScroll();
scroll.setItems(Arrays.asList(conRecommend,conRanking,conCategory));
mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,scroll));
return document;
}
private static LunchPojo buildLunchScroll() {
LunchPojo scroll = new LunchPojo();
scroll.setType("ScrollView");
scroll.setDirection("vertical");
scroll.setWidth("100%");
scroll.setMarginBottom("80dp");
return scroll;
}
private static LunchPojo buildLunchCategoryList(List<LunchBotData> data) {
LunchPojo container = new LunchPojo();
container.setType("Container");
container.setWidth("100%");
LunchPojo list = new LunchPojo();
list.setType("List");
list.setHeight("310dp");
list.setMarginLeft("15dp");
list.setMarginRight("15dp");
list.setDirection("horizontal");
list.setData(data);
list.setItems(Collections.singletonList(LUNCH_LIST_CATEGORY_CON));
container.setItems(Collections.singletonList(list));
return container;
}
private static LunchPojo buildLunchList(List<LunchBotData> data) {
LunchPojo container = new LunchPojo();
container.setType("Container");
container.setWidth("100%");
LunchPojo list = new LunchPojo();
list.setType("List");
list.setMarginLeft("15dp");
list.setMarginRight("15dp");
list.setMarginBottom("70dp");
list.setDirection("horizontal");
list.setData(data);
list.setItems(Collections.singletonList(LUNCH_LIST_CON));
container.setItems(Collections.singletonList(list));
return container;
}
private static LunchPojo buildCategoryList() {
LunchPojo category = buildImgFrmTxtContainer();
category.getItems().remove(2);
return category;
}
private static LunchPojo buildImgFrmTxtContainer() {
LunchPojo container = new LunchPojo();
container.setType("Container");
container.setMarginTop("40dp");
container.setWidth("200dp");
container.setMarginLeft("20dp");
//image
LunchPojo image = new LunchPojo();
image.setType("Image");
image.setWidth("190dp");
image.setHeight("190dp");
image.setMarginLeft("7dp");
image.setMarginTop("7dp");
image.setPosition("absolute");
image.setScaleType("fitXY");
image.setBorderRadius("22dp");
image.setSrc("${data.imageSrc}");
image.setOnClick(Collections.singletonList(new Event("SendEvent", "${data.imageId}")));
//frame
LunchPojo frame = new LunchPojo();
frame.setType("Frame");
frame.setWidth("35dp");
frame.setHeight("35dp");
frame.setBackgroundColor("rgba(0,0,0,0.9)");
frame.setBorderRadius("13dp");
LunchPojo frmCon = new LunchPojo();
frmCon.setType("Container");
frmCon.setWidth("100%");
frmCon.setHeight("100%");
frmCon.setAlignItems("center");
LunchPojo frmText = new LunchPojo();
frmText.setType("Text");
frmText.setText("${data.num}");
frmText.setFontSize("22dp");
frmCon.setItems(Collections.singletonList(frmText));
frame.setItems(Collections.singletonList(frmCon));
//text
LunchPojo text = new LunchPojo();
text.setType("Text");
text.setFontSize("23dp");
text.setMarginTop("160dp");
text.setMarginLeft("7dp");
text.setText("${data.imageName}");
List<LunchPojo> list = new ArrayList<>();
list.add(image);
list.add(frame);
list.add(text);
container.setItems(list);
return container;
}
private static LunchPojo buildLunchBackgroundImg() {
LunchPojo backGroundImg = new LunchPojo();
backGroundImg.setType("Image");
backGroundImg.setPosition("absolute");
backGroundImg.setTop("0dp");
backGroundImg.setLeft("0dp");
backGroundImg.setSrc("https://aliyun-hz1.chewrobot.com/xiaoduhome/image/backend.jpg");
backGroundImg.setHeight("100%");
backGroundImg.setWidth("100%");
return backGroundImg;
}
private static LunchPojo buildLunchHead() {
LunchPojo head = new LunchPojo();
head.setType("Header");
head.setHeaderTitle("交游天下");
head.setHasBackIcon(false);
return head;
}
public static LunchDocument getLunchDocument() {
return lunchDocument;
}
public static void setLunchDocument(LunchDocument lunchDocument) {
LunchUtils.lunchDocument = lunchDocument;
}
}
...@@ -77,18 +77,18 @@ public class RankUtil { ...@@ -77,18 +77,18 @@ public class RankUtil {
StringBuilder botIds = new StringBuilder(); StringBuilder botIds = new StringBuilder();
List<RankBotInfo> dataFirst = new ArrayList<>(); List<RankBotInfo> dataFirst = new ArrayList<>();
List<RankBotInfo> dataSec = new ArrayList<>(); List<RankBotInfo> dataSec = new ArrayList<>();
int i = 0; int i = 1;
for (GameProjectTb bot: bots) { for (GameProjectTb bot: bots) {
botIds.append(bot.getBotAccount()).append(File.separator); botIds.append(bot.getBotAccount()).append(File.separator);
String imgSrc = new StringBuilder(Constants.IMG_PREFIX).append(bot.getBannerImgUrl()).toString(); String imgSrc = new StringBuilder(Constants.IMG_PREFIX).append(bot.getBannerImgUrl()).toString();
String imageId = new StringBuilder(Constants.PRE_PRODUCT_IMG).append(bot.getName()).toString(); String imageId = new StringBuilder(Constants.PRE_PRODUCT_IMG).append(bot.getName()).toString();
RankBotInfo rankBotInfo = new RankBotInfo(imgSrc, imageId, correctName(bot.getName())); RankBotInfo rankBotInfo = new RankBotInfo(imgSrc, imageId, correctName(bot.getName()));
if (i < 3) { rankBotInfo.setNum(i);
rankBotInfo.setNum(); if (i < 4) {
dataFirst.add(rankBotInfo); dataFirst.add(rankBotInfo);
} else if (i == 4) { } else if (i == 4) {
dataFirst.add(rankBotInfo); dataFirst.add(rankBotInfo);
} else if (i < 8) { } else if (i < 9) {
dataSec.add(rankBotInfo); dataSec.add(rankBotInfo);
} else { } else {
break; break;
......
package ai.qiwu.com.xiaoduhome.common.temple.recommand; package ai.qiwu.com.xiaoduhome.common.temple.recommand;
import lombok.Data; import lombok.Data;
import lombok.Getter;
import lombok.Setter;
/** /**
* @author 苗权威 * @author 苗权威
* @dateTime 19-8-27 上午10:52 * @dateTime 19-8-27 上午10:52
*/ */
@Data @Getter
@Setter
public class RecommandBotInfo { public class RecommandBotInfo {
private String imageSrc; private String imageSrc;
private String imageId; private String imageId;
......
package ai.qiwu.com.xiaoduhome.common.temple.recommand;
import ai.qiwu.com.xiaoduhome.common.Constants;
import ai.qiwu.com.xiaoduhome.common.temple.TempleUtils;
import ai.qiwu.com.xiaoduhome.entity.primary.GameProjectTb;
import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
import ai.qiwu.com.xiaoduhome.service.ScheduleService;
import java.io.File;
import java.util.*;
/**
* @author 苗权威
* @dateTime 19-9-5 上午11:25
*/
public class RecommendUtil {
private static final RecommandPojo RECOM_BACK_IMG = buildRecomendBackgroundImg();
private static final RecommandPojo RECOM_HEAD = buildRecommendHead();
private static final RecommandPojo RECOM_FOOTER = buildRecommendFooter();
private static final RecommandPojo RECOM_LIST_CON = buildImgFrmTxtContainer();
public static RecommandDocument getRecommendDocument(int num) {
RecommandDocument document = new RecommandDocument();
RecommandMainTemplate mainTemplate = new RecommandMainTemplate();
document.setMainTemplate(mainTemplate);
RecommandPojo scrollView = new RecommandPojo();
scrollView.setType("ScrollView");
scrollView.setWidth("100%");
scrollView.setMarginBottom("93dp");
scrollView.setDirection("vertical");
List<RecommandPojo> scrollList = new ArrayList<>();
scrollView.setItems(scrollList);
int bound = ScheduleService.getAllProductCount();
List<OnProductDetail> bots = ScheduleService.getAllOnProduct();
StringBuilder botIds = new StringBuilder();
int begin = num*16;
int end;
if (begin >= bound) return null;
bound = begin+16 <= bound ? begin+16 : bound;
int count = 0;
while (begin < bound) {
end = begin+4 <= bound ? begin+4 : bound;
scrollList.add(buildRecommendList(getListData(count,begin, end, bots, botIds)));
count++;
begin = end;
}
mainTemplate.getItems().addAll(Arrays.asList(RECOM_BACK_IMG,RECOM_HEAD,scrollView,RECOM_FOOTER));
botIds.deleteCharAt(botIds.length()-1);
String idToken = Base64.getEncoder().encodeToString(botIds.toString().getBytes());
document.setRecommendIdList(idToken);
return document;
}
private static List<RecommandBotInfo> getListData(int row,int begin, int end, List<OnProductDetail> bots, StringBuilder botIds) {
List<RecommandBotInfo> data = new ArrayList<>();
int n = 1+row*4;
for (int i = begin; i < end; i++) {
OnProductDetail bot = bots.get(i);
botIds.append(bot.getBotAccount()).append(File.separator);
String imgSrc = new StringBuilder(Constants.IMG_PREFIX).append(bot.getBannerImgUrl()).toString();
String imageId = new StringBuilder(Constants.PRE_PRODUCT_IMG).append(bot.getName()).toString();
RecommandBotInfo detail = new RecommandBotInfo(imgSrc,imageId, TempleUtils.correctName(bot.getName()));
detail.setNum(i-begin+n);
data.add(detail);
}
return data;
}
private static RecommandPojo buildRecommendList(List<RecommandBotInfo> data) {
RecommandPojo list = new RecommandPojo();
list.setType("List");
list.setWidth("100%");
list.setHeight("240dp");
list.setMarginLeft("20dp");
list.setMarginBottom("35dp");
list.setDirection("horizontal");
list.setData(data);
list.setItems(Collections.singletonList(RECOM_LIST_CON));
return list;
}
private static RecommandPojo buildImgFrmTxtContainer() {
RecommandPojo container = new RecommandPojo();
container.setType("Container");
container.setWidth("220dp");
container.setMarginLeft("15dp");
//image
RecommandPojo image = new RecommandPojo();
image.setType("Image");
image.setWidth("190dp");
image.setHeight("190dp");
image.setMarginLeft("7dp");
image.setMarginTop("7dp");
image.setPosition("absolute");
image.setScaleType("fitXY");
image.setBorderRadius("15dp");
image.setSrc("${data.imageSrc}");
image.setOnClick(Collections.singletonList(new Event("SendEvent", "${data.imageId}")));
//frame
RecommandPojo frame = new RecommandPojo();
frame.setType("Frame");
frame.setWidth("40dp");
frame.setHeight("40dp");
frame.setBackgroundColor("rgba(0,0,0,0.9)");
frame.setBorderRadius("12dp");
RecommandPojo frmCon = new RecommandPojo();
frmCon.setType("Container");
frmCon.setWidth("100%");
frmCon.setHeight("100%");
frmCon.setAlignItems("center");
RecommandPojo frmText = new RecommandPojo();
frmText.setType("Text");
frmText.setText("${data.num}");
frmText.setFontSize("28dp");
frmCon.setItems(Collections.singletonList(frmText));
frame.setItems(Collections.singletonList(frmCon));
//text
RecommandPojo text = new RecommandPojo();
text.setType("Text");
text.setFontSize("25dp");
text.setMarginTop("160dp");
text.setMarginLeft("7dp");
text.setText("${data.imageName}");
container.setItems(Arrays.asList(image,frame,text));
return container;
}
private static RecommandPojo buildRecommendFooter() {
RecommandPojo footerCon = new RecommandPojo();
footerCon.setType("Container");
footerCon.setPosition("absolute");
footerCon.setWidth("100%");
footerCon.setLeft("0");
footerCon.setBottom("0");
RecommandPojo footer = new RecommandPojo();
footer.setType("Footer");
footer.setHints(Arrays.asList("打开第一个","下一页","上一页","返回"));
footerCon.setItems(Collections.singletonList(footer));
return footerCon;
}
private static RecommandPojo buildRecomendBackgroundImg() {
RecommandPojo backGroundImg = new RecommandPojo();
backGroundImg.setType("Image");
backGroundImg.setPosition("absolute");
backGroundImg.setTop("0dp");
backGroundImg.setLeft("0dp");
backGroundImg.setSrc("https://aliyun-hz1.chewrobot.com/xiaoduhome/image/backend.jpg");
backGroundImg.setHeight("100%");
backGroundImg.setWidth("100%");
return backGroundImg;
}
private static RecommandPojo buildRecommendHead() {
RecommandPojo head = new RecommandPojo();
head.setType("Header");
head.setHeaderTitle("推荐页");
head.setHasBackIcon(false);
return head;
}
}
...@@ -21,7 +21,7 @@ public interface XiaoDuHistoryTBRepository extends JpaRepository<XiaoDuHistoryTB ...@@ -21,7 +21,7 @@ public interface XiaoDuHistoryTBRepository extends JpaRepository<XiaoDuHistoryTB
@Modifying @Modifying
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Query(value = "delete from xiaodu_history_tb where xiaodu_user_id=?1 and last_time < (select last_time from (select last_time from xiaodu_history_tb where xiaodu_user_id=?1 order by last_time limit 14,1) t1)", nativeQuery = true) @Query(value = "delete from xiaodu_history_tb where xiaodu_user_id=?1 and last_time < (select last_time from (select last_time from xiaodu_history_tb where xiaodu_user_id=?1 order by last_time limit 15,1) t1)", nativeQuery = true)
void deleteOverTime(String userId); void deleteOverTime(String userId);
@Modifying @Modifying
...@@ -34,4 +34,7 @@ public interface XiaoDuHistoryTBRepository extends JpaRepository<XiaoDuHistoryTB ...@@ -34,4 +34,7 @@ public interface XiaoDuHistoryTBRepository extends JpaRepository<XiaoDuHistoryTB
<S extends XiaoDuHistoryTB> S save(S s); <S extends XiaoDuHistoryTB> S save(S s);
XiaoDuHistoryTB getByXiaoduUserIdAndBotId(String xiaoduUserId, String botId); XiaoDuHistoryTB getByXiaoduUserIdAndBotId(String xiaoduUserId, String botId);
@Query(value = "select distinct bot_id from xiaodu_history_tb where xiaodu_user_id=?1",nativeQuery = true)
List<String> getUserHostory(String userId);
} }
package ai.qiwu.com.xiaoduhome.service; package ai.qiwu.com.xiaoduhome.service;
import ai.qiwu.com.xiaoduhome.common.temple.onLunch.LunchUtils;
import ai.qiwu.com.xiaoduhome.entity.primary.GameProjectTb; import ai.qiwu.com.xiaoduhome.entity.primary.GameProjectTb;
import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail; import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
import ai.qiwu.com.xiaoduhome.repository.primary.AllOnProductInfoRepository; import ai.qiwu.com.xiaoduhome.repository.primary.AllOnProductInfoRepository;
...@@ -8,16 +9,19 @@ import ai.qiwu.com.xiaoduhome.repository.primary.ProjectLabelRepository; ...@@ -8,16 +9,19 @@ import ai.qiwu.com.xiaoduhome.repository.primary.ProjectLabelRepository;
import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuHistoryTBRepository; import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuHistoryTBRepository;
import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuOrderTbRepository; import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuOrderTbRepository;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* @author 苗权威 * @author 苗权威
...@@ -32,11 +36,12 @@ public class ScheduleService implements InitializingBean { ...@@ -32,11 +36,12 @@ public class ScheduleService implements InitializingBean {
static volatile List<OnProductDetail> ALL_ON_PRODUCT = new ArrayList<>(); static volatile List<OnProductDetail> ALL_ON_PRODUCT = new ArrayList<>();
static final HashMap<String, OnProductDetail> PRODUCT_NAME_DETAIL = new HashMap<>(); static final HashMap<String, OnProductDetail> PRODUCT_NAME_DETAIL = new HashMap<>();
static final HashMap<String, OnProductDetail> PRODUCT_ID_DETAIL = new HashMap<>(); static final HashMap<String, OnProductDetail> PRODUCT_ID_DETAIL = new HashMap<>();
static final HashMap<String, String> NX2_BOT_TO_HZ1 = new HashMap<>();
static final HashMap<String, String> NX2_BOT_TO_HZ1 = new HashMap<>();
static final List<String> EXCEPT_BOT_ACCOUNT = new ArrayList<>(); static final List<String> EXCEPT_BOT_ACCOUNT = new ArrayList<>();
static final String[] CATEGORY = {"古风", "科幻", "占星", "恋爱", "灾难", "架空", "儿童", "经营", "冒险", "武侠"}; static final String[] CATEGORY = {"古风", "儿童", "科幻", "占星", "恋爱", "灾难", "架空", "经营", "冒险", "武侠"};
static final String[] CATEGORY_CHARAC={"gufeng","child","kehuan","zhanxing","lianai","zainan","jiakong","jingying","maoxian","wuxia"};
static final ConcurrentHashMap<String, List<GameProjectTb>> CATEGORY_PRODUCT_LIST = new ConcurrentHashMap<>(); static final ConcurrentHashMap<String, List<GameProjectTb>> CATEGORY_PRODUCT_LIST = new ConcurrentHashMap<>();
private final GameProjectTbRepository gameProjectTbRepository; private final GameProjectTbRepository gameProjectTbRepository;
...@@ -71,7 +76,7 @@ public class ScheduleService implements InitializingBean { ...@@ -71,7 +76,7 @@ public class ScheduleService implements InitializingBean {
//log.error("更新排行榜出错:{}", e.getMessage()); //log.error("更新排行榜出错:{}", e.getMessage());
} }
@Scheduled(cron = "0 0 18 * * ?") @Scheduled(cron = "0 0 */1 * * ?")
public void initRecommendList() { public void initRecommendList() {
new Thread(() -> { new Thread(() -> {
RECOMMEND_LIST = gameProjectTbRepository.recommendList(); RECOMMEND_LIST = gameProjectTbRepository.recommendList();
...@@ -132,6 +137,14 @@ public class ScheduleService implements InitializingBean { ...@@ -132,6 +137,14 @@ public class ScheduleService implements InitializingBean {
}).start(); }).start();
} }
@Scheduled(cron = "0 0 */1 * * ?")
public void shuffleAllProList() {
new Thread(() -> {
Collections.shuffle(ALL_ON_PRODUCT);
LunchUtils.setLunchDocument(LunchUtils.buildLunchDocument());
}).start();
}
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
initAllOnTableProductInfo(); initAllOnTableProductInfo();
...@@ -142,6 +155,7 @@ public class ScheduleService implements InitializingBean { ...@@ -142,6 +155,7 @@ public class ScheduleService implements InitializingBean {
deleteUnPayedOrder(); deleteUnPayedOrder();
tian(); tian();
keng(); keng();
Logger.getLogger(OkHttpClient.class.getName()).setLevel(Level.FINE);
} }
private void keng() { private void keng() {
...@@ -200,4 +214,12 @@ public class ScheduleService implements InitializingBean { ...@@ -200,4 +214,12 @@ public class ScheduleService implements InitializingBean {
public static int getAllProductCount() { public static int getAllProductCount() {
return allProductCount; return allProductCount;
} }
public static String[] getCATEGORY() {
return CATEGORY;
}
public static String[] getCategoryCharac() {
return CATEGORY_CHARAC;
}
} }
{ {
"type": "Container", "type": "Container",
"flex-direction": "row", "flex-direction": "row",
"margin-bottom": "15dp", "height": "50dp",
"margin-top": "30dp",
"items": [ "items": [
{ {
"type": "Text", "type": "Text",
"text": "排行榜", "font-size": "31dp",
"font-size": "34dp",
"margin-left": "30dp" "margin-left": "30dp"
}, },
{ {
"type": "Frame", "type": "Frame",
"margin-left": "15dp", "margin-left": "15dp",
"border-top-left-radius": "25dp", "border-top-left-radius": "25dp",
"border-top-right-radius": "15dp", "border-top-right-radius": "18dp",
"border-bottom-right-radius": "15dp", "border-bottom-right-radius": "18dp",
"padding-vertical": "8dp", "padding-vertical": "8dp",
"padding-horizontal": "15dp", "padding-horizontal": "15dp",
"background-color": "rgba(0,0,0,0.2)", "background-color": "rgba(0,0,0,0.3)",
"items": [ "items": [
{ {
"type": "Text", "type": "Text",
"font-size": "24dp", "font-size": "23dp",
"color": "rgb(255,255,255)" "color": "rgb(255,255,255)"
} }
] ]
......
...@@ -21,110 +21,98 @@ ...@@ -21,110 +21,98 @@
"hasBackIcon": false "hasBackIcon": false
}, },
{ {
"type": "List", "type": "Container",
"width": "100%",
"height": "100%", "height": "100%",
"direction": "vertical", "width": "100%",
"items": [ "items": [
{ {
"type": "Container", "type": "Container",
"flex-direction": "row", "width": "100%",
"margin-left": "15dp",
"direction": "horizontal",
"items": [
]
},
{
"type": "List",
"width": "100%",
"margin-left": "15dp",
"direction": "horizontal",
"items": [ "items": [
{
"type": "Image",
"width": "230dp",
"height": "230dp",
"src": "${data.imageSrc}",
"position": "absolute",
"border-radius": "15dp",
"onClick": [
{
"type": "SendEvent",
"componentId": "${data.imageId}"
}
]
},
{
"type": "Image",
"src": "${data.logo}",
"width": "30dp",
"height": "30dp",
"border-radius": "5dp"
},
{ {
"type": "Container", "type": "Container",
"margin-left": "250dp", "width":"220dp",
"flex-direction": "column", "margin-bottom": "35dp",
"margin-left": "15dp",
"items": [ "items": [
{ {
"type": "Text", "type": "Image",
"margin-top": "10dp", "width": "170dp",
"text": "${data.imageName}", "height": "170dp",
"font-size": "38dp", "margin-left": "7dp",
"margin-left": "5%" "margin-top": "7dp",
}, "position": "absolute",
{ "componentId": "${data.imageId}",
"type": "Text", "scale-type": "fitXY",
"text": "${data.watches}", "border-radius": "10dp",
"margin-top": "10dp", "src": "${data.imageSrc}",
"font-size": "25dp", "onClick": [
"margin-left": "5%"
},
{
"type": "Container",
"margin-top": "10dp",
"flex-direction":"row",
"items":[
{ {
"type": "Text", "type": "SendEvent",
"text": "${data.time}", "componentId": "${data.imageId}"
"font-size": "22dp",
"margin-left": "5%"
},
{
"type": "Text",
"text": "${data.auth}",
"font-size": "22dp",
"margin-left": "10%"
} }
] ]
}, },
{ {
"type": "Container", "type": "Frame",
"margin-top": "6dp", "width": "40dp",
"flex-direction":"row", "height": "40dp",
"items":[ "background-color": "rgba(0,0,0,0.9)",
"border-radius": "12dp",
"items": [
{ {
"type": "Text", "type": "Container",
"max-lines": 1, "width": "100%",
"text": "${data.label}", "height": "100%",
"font-size": "22dp", "align-items":"center",
"margin-left": "5%" "items": [
{
"type": "Text",
"text": "${data.num}",
"font-size": "25dp"
}
]
} }
] ]
}, },
{ {
"type": "Container", "type": "Text",
"margin-top": "9dp", "font-size": "25dp",
"margin-right": "26dp", "margin-top": "140dp",
"items": [ "margin-left": "7dp",
{ "text": "${data.imageName}"
"type": "Text",
"font-size": "25dp",
"line-height": "20dp",
"text": "${data.intro}",
"margin-top": "30dp",
"max-lines": 3,
"text-overflow": "ellipsis",
"margin-left": "5%"
}
]
} }
] ]
} }
] ]
} }
] ]
},
{
"type": "Container",
"position": "absolute",
"width": "100%",
"left": "0",
"bottom": "0",
"items": [
{
"type": "Footer",
"hints": [
"打开第一个","下一页","上一页","返回"
]
}
]
} }
] ]
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"hasBackIcon": false "hasBackIcon": false
}, },
{ {
"type": "Container", "type": "ScrollView",
"height": "100%", "height": "100%",
"width": "100%", "width": "100%",
"items": [ "items": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment