Commit bd0298ef by 苗权威

1.19

parent f5bb9486
......@@ -25,8 +25,10 @@ import ai.qiwu.com.xiaoduhome.repository.primary.AppFavoriteTBRepository;
import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuHistoryBotTimeRepository;
import ai.qiwu.com.xiaoduhome.service.DplbotServiceUtil;
import ai.qiwu.com.xiaoduhome.service.ScheduleService;
import ai.qiwu.com.xiaoduhome.service.ScheduleServiceNew;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
......@@ -267,15 +269,17 @@ public class TempleUtils {
return dataList;
}
public static List<LunchBotData> buildCategoryDataList() {
public static List<LunchBotData> buildCategoryDataList(int row) {
ArrayList<LunchBotData> dataList = new ArrayList<>();
int i = 17;
for (String cateName : ScheduleService.getCATEGORY()) {
String imageId = new StringBuilder(PRE_CATEGORY).append(cateName).toString();
String imgSrc = new StringBuilder(IMG_CUSTOM_PREFIX)
.append(ScheduleService.getCategoryCharac()[i-17]).append(".png").toString();
LunchBotData data = new LunchBotData(imgSrc, imageId, cateName);
data.setNum(i++);
int begin = row*3;
String name, imgId, imgSrc;
for (int i = begin; i < begin+3; i++) {
name = ScheduleServiceNew.CATEGORY[i];
imgSrc = new StringBuilder(IMG_CUSTOM_PREFIX)
.append(ScheduleServiceNew.CATEGORY_CHARAC[i]).append(".png").toString();
imgId = ScheduleServiceNew.CATEGORY_CHARAC[i];
LunchBotData data = new LunchBotData(imgSrc, imgId, name);
data.setNum(i+1);
dataList.add(data);
}
return dataList;
......
package ai.qiwu.com.xiaoduhome.common.temple.onLunch;
import com.baidu.dueros.data.response.directive.dpl.Document;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
......
......@@ -21,6 +21,7 @@ public class LunchUtils {
private static final LunchPojo LUNCH_HEAD = buildLunchHead();
private static final LunchPojo LUNCH_BACK_IMG = buildLunchBackgroundImg();
private static final LunchPojo FOOTER = buildHomeFooter();
private static final LunchPojo CATEGORY_FOOTER = buildCategoryFooter();
// private static final LunchPojo LUNCH_LOGO_IMG = buildLogoImage();
// private static final LunchPojo LUNCH_HSITORY_IMG = buildHistoryImg();
// private static final LunchPojo LUNCH_COLLECT_IMG = buildCollectImg();
......@@ -67,7 +68,7 @@ public class LunchUtils {
// LunchPojo conRanking = buildLunchList(TempleUtils.buildDataList(ScheduleService.getRankingList(), 9));
// conRanking.setFirstItem(Collections.singletonList(TempleUtils.getFrameRakking()));
LunchPojo conCategory = buildLunchCategoryList(TempleUtils.buildCategoryDataList());
LunchPojo conCategory = buildLunchCategoryList(TempleUtils.buildCategoryDataList(0));
conCategory.setFirstItem(Collections.singletonList(TempleUtils.getFrameCategory()));
LunchPojo scroll = buildLunchScroll();
......@@ -77,6 +78,21 @@ public class LunchUtils {
return document;
}
public static LunchDocument buildCategoryDocument() {
LunchDocument document = new LunchDocument();
document.setDuration(90000);
LunchMainTemplate mainTemplate = new LunchMainTemplate();
document.setMainTemplate(mainTemplate);
LunchPojo firstRow = buildLunchCategoryList(TempleUtils.buildCategoryDataList(0));
LunchPojo secondRow = buildLunchCategoryList(TempleUtils.buildCategoryDataList(1));
LunchPojo scroll = buildLunchScroll();
scroll.setItems(Arrays.asList(firstRow,secondRow));
mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,scroll,CATEGORY_FOOTER));
return document;
}
private static LunchPojo buildLunchScroll() {
LunchPojo scroll = new LunchPojo();
scroll.setType("ScrollView");
......@@ -93,6 +109,8 @@ public class LunchUtils {
//container.setMarginTop("25dp");
container.setType("Container");
container.setWidth("100%");
container.setMarginTop("180dp");
container.setAlignItems("center");
LunchPojo list = new LunchPojo();
list.setType("List");
......@@ -241,6 +259,23 @@ public class LunchUtils {
return footerCon;
}
private static LunchPojo buildCategoryFooter() {
LunchPojo footerCon = new LunchPojo();
footerCon.setType("Container");
footerCon.setPosition("absolute");
footerCon.setWidth("100%");
footerCon.setLeft("0");
footerCon.setBottom("0");
LunchPojo footer = new LunchPojo();
footer.setType("Footer");
footer.setHints(Arrays.asList("打开第一个","返回"));
footerCon.setItems(Collections.singletonList(footer));
return footerCon;
}
private static LunchPojo buildLogoImage() {
LunchPojo logoCon = new LunchPojo();
logoCon.setType("Container");
......
......@@ -9,6 +9,7 @@ import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
import ai.qiwu.com.xiaoduhome.service.ScheduleService;
import ai.qiwu.com.xiaoduhome.service.ScheduleServiceNew;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.util.*;
......@@ -86,29 +87,25 @@ public class RecommendUtil {
List<RecommandPojo> scrollList = new ArrayList<>();
scrollView.setItems(scrollList);
List<String> categoryIdList = ScheduleService.getCategoryProductIdList().get(category);
if (categoryIdList == null || categoryIdList.size() == 0) return null;
int bound = categoryIdList.size();
List<ProjectData> dataList = ScheduleServiceNew.category2Bots.get(category);
if (CollectionUtils.isEmpty(dataList)) return null;
int bound = dataList.size();
int begin = num*RE_RA_CA_PAGE_SIZE;
int end;
if (begin >= bound) return null;
bound = begin+RE_RA_CA_PAGE_SIZE <= bound ? begin+RE_RA_CA_PAGE_SIZE : bound;
List<OnProductDetail> bots = new ArrayList<>();
for (int i = begin; i < bound; i++) {
String botId = categoryIdList.get(i);
bots.add((ScheduleService.getProductIdDetail().get(botId)));
}
//StringBuilder botIds = new StringBuilder();
int count = 0;
while (begin < bound) {
end = begin+4 <= bound ? begin+4 : bound;
scrollList.add(buildRecommendList(getListDataNoIds(count, begin, end, null)));
scrollList.add(buildRecommendList(getListDataNoIds(count, begin, end, dataList)));
count++;
begin = end;
}
int pageSize = categoryIdList.size() / RE_RA_CA_PAGE_SIZE + (categoryIdList.size()%RE_RA_CA_PAGE_SIZE == 0 ? 0:1);
int pageSize = dataList.size() / RE_RA_CA_PAGE_SIZE + (dataList.size()%RE_RA_CA_PAGE_SIZE == 0 ? 0:1);
mainTemplate.getItems().addAll(Arrays.asList(RECOM_BACK_IMG,buildRecommendCollectHead(category),
scrollView,buildPageButton(num+1, pageSize),RANK_CATEGORY_FOOTER));
......
package ai.qiwu.com.xiaoduhome.pojo.data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
......@@ -14,6 +15,7 @@ import java.util.List;
@Getter
@Setter
@ToString
@EqualsAndHashCode
public class ProjectData {
private String name;
private String intro;
......
......@@ -6,6 +6,7 @@ import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.common.Utils;
import ai.qiwu.com.xiaoduhome.common.temple.CollectHistoryDocument;
import ai.qiwu.com.xiaoduhome.common.temple.TempleUtils;
import ai.qiwu.com.xiaoduhome.common.temple.onLunch.LunchDocument;
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;
......@@ -822,6 +823,15 @@ public class DplBotServiceBoth extends BaseBot {
return new Response(outputSpeech);
}
private Response dealOpenCategory() {
LunchDocument document = LunchUtils.buildCategoryDocument();
if (document == null) return new Response();
RenderDocument render = new RenderDocument(document);
this.addDirective(render);
this.setSessionAttribute("trace","07");
return buildErrorResponse("正在为您打开分类页");
}
private Response dealOpenCollectClick() {
if (getAccessToken() == null) {
OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "该功能需要登录,请说小度小度,登录");
......@@ -1587,6 +1597,7 @@ public class DplBotServiceBoth extends BaseBot {
case '4':
case '6': response = dealOpenNumInRecommend(getSessionAttribute(PRE_COLLE), num, channelId); break;
case '5': response = dealOpenNumInCategory(channelId);break;
case '7': response = dealOpenNumInCategory(channelId);break;
default:{
response = buildErrorResponse("屏幕上的图标都是可以点击的哦");
}
......@@ -1870,6 +1881,7 @@ public class DplBotServiceBoth extends BaseBot {
case "store" : return dealCollectOrUnCollectIntent(userId, "collect");
case "unStore" : return dealCollectOrUnCollectIntent(userId, "unCollect");
case "flower" : return dealSendFlowerIntent(userId, txt.substring(end+1));
case "category" : return dealOpenCategory();
}
}
}
......@@ -1974,23 +1986,31 @@ public class DplBotServiceBoth extends BaseBot {
}
}
private Response dealOpenNumInCategory(String channelId) {
private Response dealOpenCategory(int num) {
if (num > ScheduleServiceNew.CATEGORY.length) return buildErrorResponse(num+"超出了范围");
String category = getSessionAttribute("category");
if (StringUtils.isBlank(category)) return buildErrorResponse("请直接点击进入");
RecommandDocument document = RecommendUtil.getCategory(num, category);
if (document == null) return new
}
private Response dealOpenNumInCategory(String channelId, int num) {
String count = getSessionAttribute("comCnt");
String category = getSessionAttribute("category");
if (StringUtils.isBlank(category)) return buildErrorResponse("请直接点击进入");
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<String> categoryBots = ScheduleService.getCategoryProductIdList().get(getSessionAttribute("category"));
num = pageIndex*RE_RA_CA_PAGE_SIZE+num-1;
List<ProjectData> categoryBots = ScheduleServiceNew.category2Bots.get(category);
if (num < 0 || num >= categoryBots.size()) {
return buildErrorResponse("这个数字超出了范围,作品的序号已显示在图片左上角");
}
String botId = categoryBots.get(num);
String name = ScheduleServiceNew.getProjectByBotAccount(botId).getName();
ProjectData bot = categoryBots.get(num);
Response response;
if (DplbotServiceUtil.doesUserPlayed(botId, getUserId(), getAccessToken())) response = directInProduct(correctName(name), botId);
else response = enterProductInfo(correctName(name), channelId);
if (DplbotServiceUtil.doesUserPlayed(bot.getBotAccount(), getUserId(), getAccessToken())) {
response = directInProduct(bot.getName(), bot.getBotAccount());
} else response = enterProductInfo(bot.getName(), channelId);
setSessionAttribute("category", category);
return response;
}
......
......@@ -495,10 +495,9 @@ public class DplbotServiceUtil {
String intro = productDetail.getIntro();
if (StringUtils.isBlank(intro)) intro = "作者太懒没写介绍";
String imgUrl = new StringBuilder(IMG_PREFIX).append(productDetail.getBannerImgUrl()).toString();
String botAccountId = new StringBuilder(Constants.PRE_PRODUCT_IMG).append(correctName(productDetail.getName())).toString();
String name = productDetail.getName();
HistoryData data = new HistoryData(botAccountId, j++, imgUrl, correctName(name), intro);
HistoryData data = new HistoryData(botAccountId, j++, productDetail.getBannerImgUrl(), correctName(name), intro);
data.setAuthorName(productDetail.getAuthorName());
projectInfoList.add(data);
}
......
......@@ -37,6 +37,11 @@ public class ScheduleServiceNew implements InitializingBean {
static volatile Long curTime = System.currentTimeMillis();
public static final String[] CATEGORY = {"古风", "言情", "灾难", "冒险", "武侠", "穿越"};
public static final String[] CATEGORY_CHARAC={"gufeng","yanqing","zainan","maoxian","wuxia", "chuanyue"};
public static volatile Map<String, List<ProjectData>> category2Bots = new HashMap<>();
@Override
public void afterPropertiesSet() throws Exception {
getAllProjects();
......@@ -58,6 +63,13 @@ public class ScheduleServiceNew implements InitializingBean {
list.forEach(projectData -> {
botAcc.put(projectData.getBotAccount(), projectData);
name.put(projectData.getName(), projectData);
List<ProjectData> bots;
for (int i = 0; i < CATEGORY.length; i++) {
if (projectData.getLabels().contains(CATEGORY[i])) {
bots = category2Bots.computeIfAbsent(CATEGORY_CHARAC[i], s -> new ArrayList<>());
bots.add(projectData);
}
}
});
botAccount2Project = botAcc;
name2Project = name;
......
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