1.fix collect status when check others

main
Gary 9 months ago
parent 301df9908e
commit 9557714213

@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag; import com.luoo.music.pojo.Tag;
@ -135,12 +136,23 @@ public class JournalController {
return Result.success(new PageResult<JournalRespDTO>(0L, Collections.emptyList())); return Result.success(new PageResult<JournalRespDTO>(0L, Collections.emptyList()));
} }
List<Journal> pageList = journalService.orderByField(objectIds); List<Journal> pageList = journalService.orderByField(objectIds);
Set<String> journalCollectSet = new HashSet<>(objectIds); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Set<String> journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds);
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
.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));
} }
private Set<String> getMyCollectSet(String loginUser, String checkUser, List<String> objectIds) {
if(loginUser.equals(checkUser)) {
return new HashSet<>(objectIds);
}
List<String> myObjectIds=userCollectInfoService.findByUserIdAndCollectTypeAndObjectIdIn(loginUser,CollectTypeEnum.JOURNAL,objectIds);
if(CollectionUtils.isEmpty(myObjectIds)) {
return Collections.emptySet();
}
return new HashSet<>(myObjectIds);
}
private List<String> getObjectIds(CollectQueryReq queryReq) { private List<String> getObjectIds(CollectQueryReq queryReq) {
if(null==queryReq.getPageNum()||queryReq.getPageNum()<1||null==queryReq.getPageSize()||queryReq.getPageSize()<1) { if(null==queryReq.getPageNum()||queryReq.getPageNum()<1||null==queryReq.getPageSize()||queryReq.getPageSize()<1) {
return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL); return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL);

@ -25,6 +25,7 @@ import util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Collections; import java.util.Collections;
@ -94,12 +95,22 @@ public class SongController {
} }
List<SongInfo> songs = songInfoService.orderByField(objectIds); List<SongInfo> songs = songInfoService.orderByField(objectIds);
Set<String> songCollectSet = new HashSet<>(objectIds); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Set<String> songCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds);
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(new PageResult<SongRespDTO>(Long.valueOf(results.size()), results)); return Result.success(new PageResult<SongRespDTO>(Long.valueOf(results.size()), results));
} }
private Set<String> getMyCollectSet(String loginUser, String checkUser, List<String> objectIds) {
if(loginUser.equals(checkUser)) {
return new HashSet<>(objectIds);
}
List<String> myObjectIds=userCollectInfoService.findByUserIdAndCollectTypeAndObjectIdIn(loginUser,CollectTypeEnum.SONG,objectIds);
if(CollectionUtils.isEmpty(myObjectIds)) {
return Collections.emptySet();
}
return new HashSet<>(myObjectIds);
}
private List<String> getSongIds(CollectQueryReq queryReq) { private List<String> getSongIds(CollectQueryReq queryReq) {
if(null==queryReq.getPageNum()||queryReq.getPageNum()<1||null==queryReq.getPageSize()||queryReq.getPageSize()<1) { if(null==queryReq.getPageNum()||queryReq.getPageNum()<1||null==queryReq.getPageSize()||queryReq.getPageSize()<1) {
return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.SONG); return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.SONG);

@ -1,6 +1,5 @@
package com.luoo.music.dao; package com.luoo.music.dao;
import java.util.List; import java.util.List;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -11,5 +10,9 @@ import com.luoo.music.pojo.UserCollectInfo;
public interface UserCollectInfoDao extends MongoRepository<UserCollectInfo, String> { public interface UserCollectInfoDao extends MongoRepository<UserCollectInfo, String> {
List<UserCollectInfo> findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType, List<UserCollectInfo> findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType,
Pageable pageable); Pageable pageable);
List<UserCollectInfo> findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType); List<UserCollectInfo> findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType);
List<UserCollectInfo> findByUserIdAndCollectTypeAndObjectIdIn(String userId, Integer collectType,
List<String> objectIds);
} }

@ -56,4 +56,10 @@ public class UserCollectInfoService {
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId,
collectTypeEnum.getType()).stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList()); collectTypeEnum.getType()).stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList());
} }
public List<String> findByUserIdAndCollectTypeAndObjectIdIn(String userId, CollectTypeEnum collectTypeEnum,
List<String> objectIds) {
return userCollectInfoDao.findByUserIdAndCollectTypeAndObjectIdIn(userId,
collectTypeEnum.getType(),objectIds).stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList());
}
} }

Loading…
Cancel
Save