diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4485c42..3a81d04 100755 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -11,28 +11,14 @@ - - - - - - - + - - - - + - - - - - @@ -75,11 +61,11 @@ - + - - + + @@ -90,20 +76,11 @@ - - - - - - - - - - - + + @@ -112,13 +89,10 @@ - + - - - - - + + @@ -126,46 +100,29 @@ - - + + - - - - - - - - - - - - + - - + + - + - - - - - - - - + + @@ -185,10 +142,6 @@ - onInte - requestTerminate - lunchDocument - Task StringRedisTemplate HttpServletRequest IOException @@ -215,6 +168,10 @@ ScheduleService dealCollectHistoryJump load + recommend + category + dealOpenNumInCategory + getCategory OPENID_CACHE @@ -234,7 +191,6 @@ @@ -316,9 +273,9 @@ - - @@ -1178,7 +1135,7 @@ - @@ -1190,7 +1147,7 @@ - + @@ -1201,7 +1158,7 @@ - + @@ -1241,34 +1198,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1428,27 +1357,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -1490,16 +1398,6 @@ - - - - - - - - - - @@ -1558,13 +1456,6 @@ - - - - - - - @@ -1586,79 +1477,134 @@ - + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + - - - - + - + - - + + - + - - + + - + - - + + - - - + - + + + + + + + + - - - - + - - + + + + + + + + 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 abd9b89..36671bc 100755 --- 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 @@ -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 buildCategoryDataList() { + public static List buildCategoryDataList(int row) { ArrayList 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; diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/onLunch/LunchDocument.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/onLunch/LunchDocument.java index 49ad14d..05a937d 100755 --- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/onLunch/LunchDocument.java +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/onLunch/LunchDocument.java @@ -1,6 +1,7 @@ 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; diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/onLunch/LunchUtils.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/onLunch/LunchUtils.java index f152523..add843e 100755 --- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/onLunch/LunchUtils.java +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/onLunch/LunchUtils.java @@ -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"); diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/recommand/RecommendUtil.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/recommand/RecommendUtil.java index 90f0c15..e7e6079 100755 --- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/recommand/RecommendUtil.java +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/temple/recommand/RecommendUtil.java @@ -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 scrollList = new ArrayList<>(); scrollView.setItems(scrollList); - List categoryIdList = ScheduleService.getCategoryProductIdList().get(category); - if (categoryIdList == null || categoryIdList.size() == 0) return null; - int bound = categoryIdList.size(); + List 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 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)); diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/data/ProjectData.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/data/ProjectData.java index 3af799e..07f4b7a 100644 --- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/data/ProjectData.java +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/data/ProjectData.java @@ -1,5 +1,6 @@ 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; diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotServiceBoth.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotServiceBoth.java index d881041..92ed2a8 100644 --- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotServiceBoth.java +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplBotServiceBoth.java @@ -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 categoryBots = ScheduleService.getCategoryProductIdList().get(getSessionAttribute("category")); num = pageIndex*RE_RA_CA_PAGE_SIZE+num-1; + List 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; } 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 2662255..9aa0a24 100755 --- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/DplbotServiceUtil.java @@ -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); } diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleServiceNew.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleServiceNew.java index 49a50f6..99a4176 100644 --- a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleServiceNew.java +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ScheduleServiceNew.java @@ -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> 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 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;