Selaa lähdekoodia

曲目首页查询优化

liujunchi 2 vuotta sitten
vanhempi
commit
78a8dee54b

+ 68 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/MusicSheetServiceImpl.java

@@ -2,6 +2,7 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.service.additional.update.impl.LambdaUpdateChainWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
@@ -381,6 +382,73 @@ public class MusicSheetServiceImpl extends ServiceImpl<MusicSheetDao, MusicSheet
 
             // 统计单曲归属专辑数
             updateMusicAlbumNumInfo(records);
+
+            // 声部
+
+            List<Long> collect = records.stream().map(MusicSheetVo::getMusicSubject)
+                                          .filter(StringUtils::isNotEmpty)
+                                            .map(Long::parseLong)
+                                          .collect(Collectors.toList());
+
+            List<Subject> subjectList = subjectService.findBySubjectByIdList(collect);
+            if (CollectionUtils.isNotEmpty(subjectList)) {
+                Map<Long, String> subjectMap = subjectList.stream()
+                                                        .collect(Collectors.toMap(Subject::getId, Subject::getName));
+                for (MusicSheetVo record : records) {
+                    if (StringUtils.isNotEmpty(record.getMusicSubject())) {
+                        record.setSubjectNames(subjectMap.get(Long.parseLong(record.getMusicSubject())));
+                    }
+                }
+            }
+
+            // 标签
+
+            collect = records.stream().map(MusicSheetVo::getMusicTag)
+                             .filter(StringUtils::isNotEmpty)
+                             .flatMap(s -> Arrays.stream(s.split(",")))
+                             .filter(StringUtils::isNotEmpty)
+                             .map(Long::parseLong)
+                             .collect(Collectors.toList());
+
+            List<MusicTag> list = musicTagService.lambdaQuery()
+                                                 .in(MusicTag::getId, collect)
+                                                 .eq(MusicTag::getDelFlag, 0)
+                                                 .eq(MusicTag::getState, 1)
+                                                 .list();
+            if (CollectionUtils.isNotEmpty(list)) {
+                Map<Long, String> tagMap = list.stream()
+                                                          .collect(Collectors.toMap(MusicTag::getId, MusicTag::getName));
+                for (MusicSheetVo record : records) {
+                    if (StringUtils.isNotEmpty(record.getMusicTag())) {
+
+                        List<Long> tagIdList = Arrays.stream(record.getMusicTag().split(","))
+                                                    .filter(StringUtils::isNotEmpty)
+                                                    .map(Long::parseLong)
+                                                    .collect(Collectors.toList());
+                        String tagNames = tagIdList.stream().map(tagMap::get).collect(Collectors.joining(","));
+                        record.setSubjectNames(tagNames);
+                    }
+                }
+            }
+
+            // 是否关注
+            if (query.getStudentId() != null) {
+                List<Long> musicIdList = records.stream().map(MusicSheetVo::getId).collect(Collectors.toList());
+                List<MusicFavorite> musicFavoriteList = musicFavoriteService.lambdaQuery()
+                                                                .eq(MusicFavorite::getUserId, query.getStudentId())
+                                                                .eq(MusicFavorite::getClientType, query.getClientType())
+                                                                .in(MusicFavorite::getMusicSheetId, musicIdList)
+                                                                .list();
+                if (CollectionUtils.isNotEmpty(musicFavoriteList)) {
+                    Set<Long> set = musicFavoriteList.stream()
+                                                          .map(MusicFavorite::getMusicSheetId)
+                                                          .collect(Collectors.toSet());
+                    for (MusicSheetVo record : records) {
+                        record.setFavorite(set.contains(record.getId())?YesOrNoEnum.YES:YesOrNoEnum.NO);
+                    }
+                }
+            }
+
         }
     	
     	/*if(query.getMyself() != null && query.getMyself() == false){//首页

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/MusicSheetVo.java

@@ -27,7 +27,7 @@ public class MusicSheetVo extends MusicSheet {
     private String subjectNames;
 
     @ApiModelProperty("收藏 0:否,1:是")
-    private YesOrNoEnum favorite;
+    private YesOrNoEnum favorite = YesOrNoEnum.NO;
 
     @ApiModelProperty("是否购买/VIP(0:否,1:是) ")
     private YesOrNoEnum play;

+ 0 - 10
cooleshow-user/user-biz/src/main/resources/config/mybatis/MusicSheetMapper.xml

@@ -317,18 +317,8 @@
         select <include refid="Base_Column_List"/>
         ,su.username_ as addName
         ,su.avatar_ as addUserAvatar
-        ,(select group_concat(mt.name_) from music_tag mt
-        where find_in_set(mt.id_,t.music_tag_) and mt.del_flag_ = 0  and mt.state_ = 1) as musicTagNames
-        ,(select group_concat(s.name_) from subject s
-        where find_in_set(s.id_,t.music_subject_)  and s.del_flag_ = 0) as subjectNames
-        <if test="param.studentId != null">
-            ,if(mf.id_ is not null,1,0) as favorite
-        </if>
         from music_sheet t
         left join sys_user su on t.create_by_ = su.id_
-        <if test="param.studentId != null">
-            left join music_favorite mf on (t.id_ = mf.music_sheet_id_ and mf.user_id_ = #{param.studentId} <if test="clientType != null"> AND mf.client_type_ = #{clientType}</if> )
-        </if>
         <where>
             su.del_flag_ = 0
             <include refid="QueryInfo"/>