diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index 111bd83..fe37a82 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -91,21 +91,16 @@ public class JournalController { if(StringTools.isEmpty(queryReq.getCategoryId())&&StringTools.isEmpty(queryReq.getJournalNoRange())) { List cacheList = getPagableJournalRespDTO(queryReq,journalCollectSet); - List ids=cacheList.stream().map(JournalRespDTO::getId).collect(Collectors.toList()); - Map> tagMap=tagService.getTagMap(ids); - List list = cacheList.stream().map(j->updateCollectAndTag(j,journalCollectSet,tagMap)).collect(Collectors.toList()); + List list = cacheList.stream().map(j->updateCollectAndTag(j,journalCollectSet)).collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } List pageList = journalService.queryPage(queryReq); - List ids=pageList.stream().map(Journal::getId).collect(Collectors.toList()); - Map> tagMap=tagService.getTagMap(ids); - List list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet,tagMap)).collect(Collectors.toList()); + List list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)).collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } - private JournalRespDTO updateCollectAndTag(JournalRespDTO journalRespDTO,Set journalCollectSet, Map> tagMap) { - journalRespDTO.setTags(tagMap.getOrDefault(journalRespDTO.getId(), Collections.emptyList())); + private JournalRespDTO updateCollectAndTag(JournalRespDTO journalRespDTO,Set journalCollectSet) { journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); return journalRespDTO; } @@ -115,10 +110,7 @@ public class JournalController { List journalRespDTOs = (List)redisTemplate.opsForValue().get(redisPageJournalResponseDtoKey); if(null==journalRespDTOs) { List pageList = journalService.queryPage(queryReq); - List ids=pageList.stream().map(Journal::getId).collect(Collectors.toList()); - Map> tagMap=tagService.getTagMap(ids); - - journalRespDTOs = pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal, journalCollectSet,mongoTemplate,redisTemplate,commentDao,tagMap)).collect(Collectors.toList()); + journalRespDTOs = pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal, journalCollectSet,mongoTemplate,redisTemplate,commentDao)).collect(Collectors.toList()); redisTemplate.opsForValue().set(redisPageJournalResponseDtoKey,journalRespDTOs); } return journalRespDTOs; @@ -150,8 +142,7 @@ public class JournalController { } List pageList = journalService.orderByField(objectIds); Set journalCollectSet = new HashSet<>(objectIds); - Map> tagMap=tagService.getTagMap(objectIds); - List list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet,tagMap)) + List list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } @@ -167,8 +158,7 @@ public class JournalController { return Result.unauthorized(null); } Journal journal = journalService.findById(id); - Map> tagMap=tagService.getTagMap(Arrays.asList(id)); - JournalRespDTO journalRespDTO=JournalMapper.getJournalRespDTO(journal, Collections.emptySet(),mongoTemplate,redisTemplate,commentDao,tagMap); + JournalRespDTO journalRespDTO=JournalMapper.getJournalRespDTO(journal, Collections.emptySet(),mongoTemplate,redisTemplate,commentDao); boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL); journalRespDTO.setHaveCollect(isCollect); return Result.success(journalRespDTO); @@ -215,8 +205,7 @@ public class JournalController { List ids=journals.stream().map(Journal::getId).collect(Collectors.toList()); Set journalCollectSet = null == user ? Collections.emptySet() : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL); - Map> tagMap=tagService.getTagMap(ids); - List list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet,tagMap)) + List list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); return Result.success(list); diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SearchController.java b/luoo_music/src/main/java/com/luoo/music/controller/SearchController.java index a9a5dd6..a3cfb7b 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SearchController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SearchController.java @@ -101,10 +101,7 @@ public class SearchController { SearchResultDTO searchResultDTO = new SearchResultDTO(); List journals = journalService.fuzzySearch(keyword); List songs = journalSongService.fuzzySearch(keyword); - List ids=journals.stream().map(Journal::getId).collect(Collectors.toList()); - Map> tagMap=tagService.getTagMap(ids); - - searchResultDTO.setJournals(journals.stream().map(j->JournalMapper.getJournalRespDTO(j,tagMap)).collect(Collectors.toList())); + searchResultDTO.setJournals(journals.stream().map(j->JournalMapper.getJournalRespDTO(j)).collect(Collectors.toList())); searchResultDTO.setSongs(songs.stream().map(SongMapper::getSongRespDTO).collect(Collectors.toList())); return Result.success(searchResultDTO); } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/mapper/JournalMapper.java b/luoo_music/src/main/java/com/luoo/music/dto/mapper/JournalMapper.java index ff93b45..ad5d3d7 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/mapper/JournalMapper.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/mapper/JournalMapper.java @@ -51,12 +51,11 @@ public class JournalMapper { return Collections.emptyList(); } - public static JournalRespDTO getJournalRespDTO(Journal journal, Map> tagMap) { - return getJournalRespDTO(journal, Collections.emptySet(), tagMap); + public static JournalRespDTO getJournalRespDTO(Journal journal) { + return getJournalRespDTO(journal, Collections.emptySet()); } - public static JournalRespDTO getJournalRespDTO(Journal journal, Set journalCollectSet, - Map> tagMap) { + public static JournalRespDTO getJournalRespDTO(Journal journal, Set journalCollectSet) { JournalRespDTO journalRespDTO = new JournalRespDTO(); journalRespDTO.setId(journal.getId()); journalRespDTO.setJournalNo(journal.getJournalNo()); @@ -66,7 +65,11 @@ public class JournalMapper { journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); journalRespDTO.setIpLocation("广东"); - journalRespDTO.setTags(tagMap.getOrDefault(journalRespDTO.getId(), getTags(journalRespDTO.getJournalNo()))); + String nameChTags=journal.getNameChTags(); + if(!StringTools.isEmpty(nameChTags)) { + List tags=Arrays.stream(nameChTags.split(",")).collect(Collectors.toList()); + journalRespDTO.setTags(tags); + } String content = journal.getContent(); if (StringTools.isEmpty(content)) { Poem poem = RandomSource.languageSource().randomTangPoem(); @@ -79,13 +82,9 @@ public class JournalMapper { } return journalRespDTO; } - public static List getTags(String journalId,String journalNo,Map> tagMap){ - return tagMap.getOrDefault(journalId, getTags(journalNo)); - } public static JournalRespDTO getJournalRespDTO(Journal journal, Set journalCollectSet, - MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao, - Map> tagMap) { - JournalRespDTO journalRespDTO = getJournalRespDTO(journal, journalCollectSet, tagMap); + MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao) { + JournalRespDTO journalRespDTO = getJournalRespDTO(journal, journalCollectSet); CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao, redisTemplate); journalRespDTO.setCommentList(commentDTO.getCommentList()); @@ -99,7 +98,7 @@ public class JournalMapper { : userName; } - private static List getTags(String journalNo) { + public static List getTags(String journalNo) { return journalTagMap.getOrDefault(journalNo, Collections.emptyList()); } diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java b/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java index b46980c..224b798 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java @@ -91,4 +91,9 @@ public class Journal implements Serializable{ * 用户类型 */ private String userType; + + /** + * 中文tag 名 + */ + private String nameChTags; } diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java index e26f970..dc97d22 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java @@ -292,6 +292,8 @@ public class CMSJournalService { journalTagList.add(journalTag); } journalTagDao.saveAll(journalTagList); + //save tag 中文名到 journal 中 + updateJouranlNameChTags(journalId); } // 歌曲信息 if (!CollectionUtils.isEmpty(param.getSongs())) { @@ -322,6 +324,19 @@ public class CMSJournalService { } } + private void updateJouranlNameChTags(String journalId) { + Optional optional=journalDao.findById(journalId); + if(optional.isPresent()) { + List tags=tagDao.getTagNameChByJournalId(journalId); + if(!tags.isEmpty()) { + String tagStr=tags.stream().distinct().sorted().collect(Collectors.joining(",")); + Journal journal=optional.get(); + journal.setNameChTags(tagStr); + journalDao.save(journal); + } + } + } + /** * 查询期刊详情 * @@ -408,6 +423,9 @@ public class CMSJournalService { List updatedJournalTags = updateTags.stream().map(t -> createJournalTag(t, journalId)) .collect(Collectors.toList()); journalTagDao.saveAll(updatedJournalTags); + + //update tag 中文名到 journal 中 + updateJouranlNameChTags(journalId); } // 歌曲信息 diff --git a/luoo_music/src/main/java/com/luoo/music/service/TagService.java b/luoo_music/src/main/java/com/luoo/music/service/TagService.java index 90b48d8..30efb6d 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/TagService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/TagService.java @@ -29,14 +29,17 @@ public class TagService { } public Map> getTagMap(List journalIds) { - if(journalIds.isEmpty()) { + + if (journalIds.isEmpty()) { return Collections.emptyMap(); } List pairs = tagDao.getJounralId2TagPairs(journalIds); return pairs.stream().collect(Collectors.groupingBy(s -> s[0].toString(), Collectors.mapping(s -> s[1].toString(), Collectors.toList()))); + } - public List getTagNameChByJournalId(String journalId){ + + public List getTagNameChByJournalId(String journalId) { return tagDao.getTagNameChByJournalId(journalId); }