1.udpate journal tag from attribute

main
Gary 10 months ago
parent af51520fdf
commit 7ec1a49b79

@ -91,21 +91,16 @@ public class JournalController {
if(StringTools.isEmpty(queryReq.getCategoryId())&&StringTools.isEmpty(queryReq.getJournalNoRange())) { if(StringTools.isEmpty(queryReq.getCategoryId())&&StringTools.isEmpty(queryReq.getJournalNoRange())) {
List<JournalRespDTO> cacheList = getPagableJournalRespDTO(queryReq,journalCollectSet); List<JournalRespDTO> cacheList = getPagableJournalRespDTO(queryReq,journalCollectSet);
List<String> ids=cacheList.stream().map(JournalRespDTO::getId).collect(Collectors.toList()); List<JournalRespDTO> list = cacheList.stream().map(j->updateCollectAndTag(j,journalCollectSet)).collect(Collectors.toList());
Map<String,List<String>> tagMap=tagService.getTagMap(ids);
List<JournalRespDTO> list = cacheList.stream().map(j->updateCollectAndTag(j,journalCollectSet,tagMap)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list)); return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
} }
List<Journal> pageList = journalService.queryPage(queryReq); List<Journal> pageList = journalService.queryPage(queryReq);
List<String> ids=pageList.stream().map(Journal::getId).collect(Collectors.toList()); List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)).collect(Collectors.toList());
Map<String,List<String>> tagMap=tagService.getTagMap(ids);
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet,tagMap)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list)); return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
} }
private JournalRespDTO updateCollectAndTag(JournalRespDTO journalRespDTO,Set<String> journalCollectSet, Map<String, List<String>> tagMap) { private JournalRespDTO updateCollectAndTag(JournalRespDTO journalRespDTO,Set<String> journalCollectSet) {
journalRespDTO.setTags(tagMap.getOrDefault(journalRespDTO.getId(), Collections.emptyList()));
journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId()));
return journalRespDTO; return journalRespDTO;
} }
@ -115,10 +110,7 @@ public class JournalController {
List<JournalRespDTO> journalRespDTOs = (List<JournalRespDTO>)redisTemplate.opsForValue().get(redisPageJournalResponseDtoKey); List<JournalRespDTO> journalRespDTOs = (List<JournalRespDTO>)redisTemplate.opsForValue().get(redisPageJournalResponseDtoKey);
if(null==journalRespDTOs) { if(null==journalRespDTOs) {
List<Journal> pageList = journalService.queryPage(queryReq); List<Journal> pageList = journalService.queryPage(queryReq);
List<String> ids=pageList.stream().map(Journal::getId).collect(Collectors.toList()); journalRespDTOs = pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal, journalCollectSet,mongoTemplate,redisTemplate,commentDao)).collect(Collectors.toList());
Map<String,List<String>> tagMap=tagService.getTagMap(ids);
journalRespDTOs = pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal, journalCollectSet,mongoTemplate,redisTemplate,commentDao,tagMap)).collect(Collectors.toList());
redisTemplate.opsForValue().set(redisPageJournalResponseDtoKey,journalRespDTOs); redisTemplate.opsForValue().set(redisPageJournalResponseDtoKey,journalRespDTOs);
} }
return journalRespDTOs; return journalRespDTOs;
@ -150,8 +142,7 @@ public class JournalController {
} }
List<Journal> pageList = journalService.orderByField(objectIds); List<Journal> pageList = journalService.orderByField(objectIds);
Set<String> journalCollectSet = new HashSet<>(objectIds); Set<String> journalCollectSet = new HashSet<>(objectIds);
Map<String,List<String>> tagMap=tagService.getTagMap(objectIds); List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet,tagMap))
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list)); return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
} }
@ -167,8 +158,7 @@ public class JournalController {
return Result.unauthorized(null); return Result.unauthorized(null);
} }
Journal journal = journalService.findById(id); Journal journal = journalService.findById(id);
Map<String,List<String>> tagMap=tagService.getTagMap(Arrays.asList(id)); JournalRespDTO journalRespDTO=JournalMapper.getJournalRespDTO(journal, Collections.emptySet(),mongoTemplate,redisTemplate,commentDao);
JournalRespDTO journalRespDTO=JournalMapper.getJournalRespDTO(journal, Collections.emptySet(),mongoTemplate,redisTemplate,commentDao,tagMap);
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL); boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL);
journalRespDTO.setHaveCollect(isCollect); journalRespDTO.setHaveCollect(isCollect);
return Result.success(journalRespDTO); return Result.success(journalRespDTO);
@ -215,8 +205,7 @@ public class JournalController {
List<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList()); List<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList());
Set<String> journalCollectSet = null == user ? Collections.emptySet() Set<String> journalCollectSet = null == user ? Collections.emptySet()
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL); : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL);
Map<String,List<String>> tagMap=tagService.getTagMap(ids); List<JournalRespDTO> list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
List<JournalRespDTO> list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet,tagMap))
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(list); return Result.success(list);

@ -101,10 +101,7 @@ public class SearchController {
SearchResultDTO searchResultDTO = new SearchResultDTO(); SearchResultDTO searchResultDTO = new SearchResultDTO();
List<Journal> journals = journalService.fuzzySearch(keyword); List<Journal> journals = journalService.fuzzySearch(keyword);
List<JournalSong> songs = journalSongService.fuzzySearch(keyword); List<JournalSong> songs = journalSongService.fuzzySearch(keyword);
List<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList()); searchResultDTO.setJournals(journals.stream().map(j->JournalMapper.getJournalRespDTO(j)).collect(Collectors.toList()));
Map<String,List<String>> tagMap=tagService.getTagMap(ids);
searchResultDTO.setJournals(journals.stream().map(j->JournalMapper.getJournalRespDTO(j,tagMap)).collect(Collectors.toList()));
searchResultDTO.setSongs(songs.stream().map(SongMapper::getSongRespDTO).collect(Collectors.toList())); searchResultDTO.setSongs(songs.stream().map(SongMapper::getSongRespDTO).collect(Collectors.toList()));
return Result.success(searchResultDTO); return Result.success(searchResultDTO);
} }

@ -51,12 +51,11 @@ public class JournalMapper {
return Collections.emptyList(); return Collections.emptyList();
} }
public static JournalRespDTO getJournalRespDTO(Journal journal, Map<String, List<String>> tagMap) { public static JournalRespDTO getJournalRespDTO(Journal journal) {
return getJournalRespDTO(journal, Collections.emptySet(), tagMap); return getJournalRespDTO(journal, Collections.emptySet());
} }
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet, public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
Map<String, List<String>> tagMap) {
JournalRespDTO journalRespDTO = new JournalRespDTO(); JournalRespDTO journalRespDTO = new JournalRespDTO();
journalRespDTO.setId(journal.getId()); journalRespDTO.setId(journal.getId());
journalRespDTO.setJournalNo(journal.getJournalNo()); journalRespDTO.setJournalNo(journal.getJournalNo());
@ -66,7 +65,11 @@ public class JournalMapper {
journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId()));
journalRespDTO.setIpLocation("广东"); journalRespDTO.setIpLocation("广东");
journalRespDTO.setTags(tagMap.getOrDefault(journalRespDTO.getId(), getTags(journalRespDTO.getJournalNo()))); String nameChTags=journal.getNameChTags();
if(!StringTools.isEmpty(nameChTags)) {
List<String> tags=Arrays.stream(nameChTags.split(",")).collect(Collectors.toList());
journalRespDTO.setTags(tags);
}
String content = journal.getContent(); String content = journal.getContent();
if (StringTools.isEmpty(content)) { if (StringTools.isEmpty(content)) {
Poem poem = RandomSource.languageSource().randomTangPoem(); Poem poem = RandomSource.languageSource().randomTangPoem();
@ -79,13 +82,9 @@ public class JournalMapper {
} }
return journalRespDTO; return journalRespDTO;
} }
public static List<String> getTags(String journalId,String journalNo,Map<String, List<String>> tagMap){
return tagMap.getOrDefault(journalId, getTags(journalNo));
}
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet, public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet,
MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao, MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao) {
Map<String, List<String>> tagMap) { JournalRespDTO journalRespDTO = getJournalRespDTO(journal, journalCollectSet);
JournalRespDTO journalRespDTO = getJournalRespDTO(journal, journalCollectSet, tagMap);
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao, CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao,
redisTemplate); redisTemplate);
journalRespDTO.setCommentList(commentDTO.getCommentList()); journalRespDTO.setCommentList(commentDTO.getCommentList());
@ -99,7 +98,7 @@ public class JournalMapper {
: userName; : userName;
} }
private static List<String> getTags(String journalNo) { public static List<String> getTags(String journalNo) {
return journalTagMap.getOrDefault(journalNo, Collections.emptyList()); return journalTagMap.getOrDefault(journalNo, Collections.emptyList());
} }

@ -91,4 +91,9 @@ public class Journal implements Serializable{
* *
*/ */
private String userType; private String userType;
/**
* tag
*/
private String nameChTags;
} }

@ -292,6 +292,8 @@ public class CMSJournalService {
journalTagList.add(journalTag); journalTagList.add(journalTag);
} }
journalTagDao.saveAll(journalTagList); journalTagDao.saveAll(journalTagList);
//save tag 中文名到 journal 中
updateJouranlNameChTags(journalId);
} }
// 歌曲信息 // 歌曲信息
if (!CollectionUtils.isEmpty(param.getSongs())) { if (!CollectionUtils.isEmpty(param.getSongs())) {
@ -322,6 +324,19 @@ public class CMSJournalService {
} }
} }
private void updateJouranlNameChTags(String journalId) {
Optional<Journal> optional=journalDao.findById(journalId);
if(optional.isPresent()) {
List<String> 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<JournalTag> updatedJournalTags = updateTags.stream().map(t -> createJournalTag(t, journalId)) List<JournalTag> updatedJournalTags = updateTags.stream().map(t -> createJournalTag(t, journalId))
.collect(Collectors.toList()); .collect(Collectors.toList());
journalTagDao.saveAll(updatedJournalTags); journalTagDao.saveAll(updatedJournalTags);
//update tag 中文名到 journal 中
updateJouranlNameChTags(journalId);
} }
// 歌曲信息 // 歌曲信息

@ -29,14 +29,17 @@ public class TagService {
} }
public Map<String, List<String>> getTagMap(List<String> journalIds) { public Map<String, List<String>> getTagMap(List<String> journalIds) {
if(journalIds.isEmpty()) {
if (journalIds.isEmpty()) {
return Collections.emptyMap(); return Collections.emptyMap();
} }
List<Object[]> pairs = tagDao.getJounralId2TagPairs(journalIds); List<Object[]> pairs = tagDao.getJounralId2TagPairs(journalIds);
return pairs.stream().collect(Collectors.groupingBy(s -> s[0].toString(), return pairs.stream().collect(Collectors.groupingBy(s -> s[0].toString(),
Collectors.mapping(s -> s[1].toString(), Collectors.toList()))); Collectors.mapping(s -> s[1].toString(), Collectors.toList())));
} }
public List<String> getTagNameChByJournalId(String journalId){
public List<String> getTagNameChByJournalId(String journalId) {
return tagDao.getTagNameChByJournalId(journalId); return tagDao.getTagNameChByJournalId(journalId);
} }

Loading…
Cancel
Save