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())) {
List<JournalRespDTO> cacheList = getPagableJournalRespDTO(queryReq,journalCollectSet);
List<String> ids=cacheList.stream().map(JournalRespDTO::getId).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());
List<JournalRespDTO> list = cacheList.stream().map(j->updateCollectAndTag(j,journalCollectSet)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
}
List<Journal> pageList = journalService.queryPage(queryReq);
List<String> ids=pageList.stream().map(Journal::getId).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());
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
}
private JournalRespDTO updateCollectAndTag(JournalRespDTO journalRespDTO,Set<String> journalCollectSet, Map<String, List<String>> tagMap) {
journalRespDTO.setTags(tagMap.getOrDefault(journalRespDTO.getId(), Collections.emptyList()));
private JournalRespDTO updateCollectAndTag(JournalRespDTO journalRespDTO,Set<String> journalCollectSet) {
journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId()));
return journalRespDTO;
}
@ -115,10 +110,7 @@ public class JournalController {
List<JournalRespDTO> journalRespDTOs = (List<JournalRespDTO>)redisTemplate.opsForValue().get(redisPageJournalResponseDtoKey);
if(null==journalRespDTOs) {
List<Journal> pageList = journalService.queryPage(queryReq);
List<String> ids=pageList.stream().map(Journal::getId).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());
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<Journal> pageList = journalService.orderByField(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,tagMap))
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
.collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
}
@ -167,8 +158,7 @@ public class JournalController {
return Result.unauthorized(null);
}
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,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<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList());
Set<String> journalCollectSet = null == user ? Collections.emptySet()
: 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,tagMap))
List<JournalRespDTO> list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
.collect(Collectors.toList());
return Result.success(list);

@ -101,10 +101,7 @@ public class SearchController {
SearchResultDTO searchResultDTO = new SearchResultDTO();
List<Journal> journals = journalService.fuzzySearch(keyword);
List<JournalSong> songs = journalSongService.fuzzySearch(keyword);
List<String> ids=journals.stream().map(Journal::getId).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.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);
}

@ -51,12 +51,11 @@ public class JournalMapper {
return Collections.emptyList();
}
public static JournalRespDTO getJournalRespDTO(Journal journal, Map<String, List<String>> 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<String> journalCollectSet,
Map<String, List<String>> tagMap) {
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> 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<String> 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<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,
MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao,
Map<String, List<String>> 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<String> getTags(String journalNo) {
public static List<String> getTags(String journalNo) {
return journalTagMap.getOrDefault(journalNo, Collections.emptyList());
}

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

@ -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<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))
.collect(Collectors.toList());
journalTagDao.saveAll(updatedJournalTags);
//update tag 中文名到 journal 中
updateJouranlNameChTags(journalId);
}
// 歌曲信息

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

Loading…
Cancel
Save