From b2dfffe3b575466f4422011589e159a0220dd2fb Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期五, 08 八月 2025 17:37:09 +0800
Subject: [PATCH] 排序调整
---
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java | 105 ++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 93 insertions(+), 12 deletions(-)
diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
index 04a8b16..6d4fea0 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
@@ -19,6 +19,8 @@
import cn.lili.modules.member.entity.dos.Member;
import cn.lili.modules.member.service.FootprintService;
import cn.lili.modules.member.service.MemberService;
+import cn.lili.modules.permission.entity.dos.AdminUser;
+import cn.lili.modules.permission.service.AdminUserService;
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
import cn.lili.rocketmq.tags.CommentTagsEnum;
@@ -85,7 +87,7 @@
private final VideoGoodsService videoGoodsService;
private final KitchenTypeService kitchenTypeService;
private final Cache cache;
-
+ private final AdminUserService adminUserService;
private final RocketmqCustomProperties rocketmqCustomProperties;
private final RocketMQTemplate rocketMQTemplate;
private final ThumbsUpRecordService thumbsUpRecordService;
@@ -251,7 +253,9 @@
String destination = rocketmqCustomProperties.getVideoTopic() + ":" + VideoTagsEnum.ES_DOC_ADD_OR_UPDATE.name();
rocketMQTemplate.asyncSend(destination, JSON.toJSONString(videoIndex), RocketmqSendCallbackBuilder.commonCallback());
return Result.ok("鍙戝竷鎴愬姛锛岃棰戝鏍镐腑~");
- } @Override
+ }
+
+ @Override
@Transactional(rollbackFor = Exception.class)
public Result systemPublish(WxVideoForm form) {
// 1.淇濆瓨瑙嗛
@@ -426,7 +430,16 @@
// 3. 鑾峰彇瑙嗛涓存椂璁块棶鍦板潃銆佽缃棰戞爣绛�
page.getRecords().forEach(v -> {
v.setTagList(tagMap.get(v.getId()));
- v.setCoverUrl(cosUtil.getPreviewUrl(v.getCoverUrl()));
+ String coverUrl = v.getCoverUrl();
+ if (StringUtils.isNotBlank(coverUrl)&&!coverUrl.contains("http")) {
+ v.setCoverUrl(cosUtil.getPreviewUrl(v.getCoverUrl()));
+ }
+ v.getGoodsList().forEach(goods ->{
+ if (StringUtils.isNotBlank(goods.getThumbnail())&&!goods.getThumbnail().contains("http")) {
+ goods.setThumbnail(cosUtil.getPreviewUrl(goods.getThumbnail()));
+ }
+
+ });
});
}
return Result.ok().data(page.getRecords()).total(page.getTotal());
@@ -552,8 +565,16 @@
case "recommend":// 鍔犺浇鎺ㄨ崘瑙嗛
baseMapper.recommendVideo(page, query);
//鎺ㄨ崘瑙嗛閲嶆柊鎺掑簭
- List<WxVideoVO> records = page.getRecords();
- Collections.shuffle(records);
+ buildRecommendVideoList(page, query.getVideoId());
+// WxVideoVO wxVideoVO = null;
+// if (StringUtils.isNotBlank(query.getVideoId())) {
+// wxVideoVO = baseMapper.recommendVideoByVideoId(query);
+// }
+// List<WxVideoVO> records = page.getRecords();
+// Collections.shuffle(records);
+// if (wxVideoVO!=null) {
+// records.set(0, wxVideoVO);
+// }
break;
case "author": // 鍔犺浇瑙嗛涓婚〉鎴戝彂甯冪殑瑙嗛
AuthorVideoQuery query1 = new AuthorVideoQuery();
@@ -613,7 +634,10 @@
v.setCommentNum(this.getCommentNum(v.getId(), v.getCommentNum()));
v.setCollectNum(this.getCollectNum(v.getId(), v.getCollectNum()));
v.setThumbsUpNum(this.getThumbsUpNum(v.getId(), v.getThumbsUpNum()));
- v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
+ String authorAvatar = v.getAuthorAvatar();
+ if (StringUtils.isNotBlank(authorAvatar)&&!authorAvatar.contains("http")) {
+ v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
+ }
if (VideoContentTypeEnum.VIDEO.getValue().equals(v.getVideoContentType())) {
v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
v.setCoverUrl(cosUtil.getPreviewUrl(v.getCoverFileKey()));
@@ -638,7 +662,7 @@
* @param mysqlNum
* @return
*/
- private Integer getCommentNum(String videoId, Integer mysqlNum) {
+ public Integer getCommentNum(String videoId, Integer mysqlNum) {
Object redisNum = cache.get(CachePrefix.VIDEO_COMMENT_NUM.getPrefixWithId(videoId));
if (Objects.isNull(redisNum)) {
// redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
@@ -655,7 +679,7 @@
* @param mysqlNum
* @return
*/
- private Integer getCollectNum(String videoId, Integer mysqlNum) {
+ public Integer getCollectNum(String videoId, Integer mysqlNum) {
Object redisNum = cache.get(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(videoId));
if (Objects.isNull(redisNum)) {
// redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
@@ -672,7 +696,7 @@
* @param mysqlNum
* @return
*/
- private Integer getThumbsUpNum(String videoId, Integer mysqlNum) {
+ public Integer getThumbsUpNum(String videoId, Integer mysqlNum) {
Object redisNum = cache.get(CachePrefix.VIDEO_THUMBS_UP_NUM.getPrefixWithId(videoId));
if (Objects.isNull(redisNum)) {
// redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
@@ -686,7 +710,10 @@
public Result healthRecommendVideo(WxHealthVideoQuery query) {
IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
//鑾峰彇澶у仴搴疯棰戝垪琛�
+
baseMapper.recommendHealthVideo(page,query);
+ buildRecommendVideoList(page, query.getVideoId());
+
if (page.getTotal() > 0) {
page.getRecords().forEach(v -> {
v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
@@ -710,8 +737,11 @@
@Override
public Result kitchenRecommendVideo(WxKitchenVideoQuery query) {
IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
- baseMapper.wxKitchenVideoQuery(page, query);
- page.getRecords().forEach(v -> {
+ baseMapper.wxKitchenVideoQuery(page, query);
+
+ buildRecommendVideoList(page, query.getVideoId());
+
+ page.getRecords().forEach(v -> {
v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
if (VideoContentTypeEnum.VIDEO.getValue().equals(v.getVideoContentType())) {
v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
@@ -719,6 +749,51 @@
}
});
return Result.ok().data(page.getRecords()).total(page.getTotal());
+ }
+
+ /**
+ *
+ * @param page
+ * @param videoId videoId鎺ㄨ崘鐨勮棰慽d
+ */
+ private void buildRecommendVideoList(IPage<WxVideoVO> page, String videoId) {
+ //鏌ヨ鍒版湁瑙嗛鍒楄〃
+
+ if(org.apache.commons.collections.CollectionUtils.isNotEmpty(page.getRecords())){
+ //鐜板皢瑙嗛椤哄簭鎵撲贡
+ Collections.shuffle(page.getRecords());
+
+ WxVideoVO wxVideoVO = null;
+ if (StringUtils.isNotBlank(videoId)){
+ VideoQuery videoQuery = new VideoQuery();
+ videoQuery.setVideoId(videoId);
+ wxVideoVO = baseMapper.recommendVideoByVideoId(videoQuery);
+
+ boolean found = false;
+ int foundIndex = -1;
+
+ List<WxVideoVO> records = page.getRecords();
+ //鍒ゆ柇浜岀淮鐮佽繃鏉ョ殑videoId鏄惁瀛樺湪涓巔age.getRecords閲嶅 璁板綍涓嬫爣
+ for (int i = 0; i < records.size(); i++) {
+ if (wxVideoVO.getId().equals(records.get(i).getId())) {
+ found = true;
+ foundIndex = i;
+ break;
+ }
+ }
+ if (found){
+ WxVideoVO matchedRecord = records.remove(foundIndex);
+ records.add(0, matchedRecord);
+ }else {
+ // 濡傛灉娌℃壘鍒帮紝鏇挎崲棣栦綅
+ records.set(0, wxVideoVO);
+
+ }
+
+
+ }
+ }
+
}
@Override
@@ -786,7 +861,13 @@
@Override
public Result getAuthorInfo(String authorId) {
- VideoAccountVO vo = baseMapper.getAuthorInfo(authorId, UserContext.getCurrentUserId());
+ AdminUser adminUser = adminUserService.getById(authorId);
+ VideoAccountVO vo;
+ if (Objects.isNull(adminUser)) {
+ vo = baseMapper.getAuthorInfo(authorId, UserContext.getCurrentUserId());
+ }else {
+ vo = baseMapper.getAuthorInfoAdmin(authorId, UserContext.getCurrentUserId());
+ }
vo.setSelf(authorId.equals(UserContext.getCurrentUserId()));
// 鏌ヨ鑾疯禐鏁�
List<String> videoIds = baseMapper.getVideoIdsByAuthor(authorId);
--
Gitblit v1.8.0