1.add latest 2 collect journal images

main
Gary 10 months ago
parent 5a0e460890
commit 2128ac25b8

@ -17,4 +17,6 @@ public interface UserCollectInfoDao extends MongoRepository<UserCollectInfo, Str
List<String> objectIds);
UserCollectInfo findFirstByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType);
List<UserCollectInfo> findTop2ByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType);
}

@ -424,4 +424,9 @@ public class JournalService {
tagDTO.setId(tag.getId());
return tagDTO;
}
public List<String> findImageByIds(List<String> objectIds) {
return objectIds.stream().map(this::queryJournalById).filter(Objects::nonNull).map(JournalRespDTO::getImage).collect(Collectors.toList());
}
}

@ -13,6 +13,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import com.luoo.music.dao.UserCollectInfoDao;
import com.luoo.music.pojo.UserCollectInfo;
@ -25,8 +26,9 @@ public class UserCollectInfoService {
private MongoTemplate mongoTemplate;
public List<String> findByUserIdAndCollectType(String userId, CollectTypeEnum collectTypeEnum, Pageable pageable) {
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId,
collectTypeEnum.getType(), pageable).stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList());
return userCollectInfoDao
.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, collectTypeEnum.getType(), pageable).stream()
.map(UserCollectInfo::getObjectId).collect(Collectors.toList());
}
public Set<String> getCollectSet(String userId, List<String> objectIds, CollectTypeEnum collectTypeEnum) {
@ -34,17 +36,18 @@ public class UserCollectInfoService {
.is(collectTypeEnum.getType());
Query query = new Query(criteria);
List<UserCollectInfo> userCollectInfos = mongoTemplate.find(query, UserCollectInfo.class);
return userCollectInfos.isEmpty() ? Collections.emptySet() : userCollectInfos.stream().map(UserCollectInfo::getObjectId).collect(Collectors.toSet());
return userCollectInfos.isEmpty() ? Collections.emptySet()
: userCollectInfos.stream().map(UserCollectInfo::getObjectId).collect(Collectors.toSet());
}
public Set<String> getCollectSet(String userId, CollectTypeEnum collectTypeEnum) {
Criteria criteria = Criteria.where("userId").is(userId).and("collectType")
.is(collectTypeEnum.getType());
Criteria criteria = Criteria.where("userId").is(userId).and("collectType").is(collectTypeEnum.getType());
Query query = new Query(criteria);
List<UserCollectInfo> userCollectInfos = mongoTemplate.find(query, UserCollectInfo.class);
return userCollectInfos.isEmpty() ? Collections.emptySet() : userCollectInfos.stream().map(UserCollectInfo::getObjectId).collect(Collectors.toSet());
return userCollectInfos.isEmpty() ? Collections.emptySet()
: userCollectInfos.stream().map(UserCollectInfo::getObjectId).collect(Collectors.toSet());
}
public boolean isCollect(String userId, String objectId, CollectTypeEnum collectTypeEnum) {
Criteria criteria = Criteria.where("userId").is(userId).and("objectId").is(objectId).and("collectType")
.is(collectTypeEnum.getType());
@ -53,18 +56,26 @@ public class UserCollectInfoService {
}
public List<String> findByUserIdAndCollectType(String userId, CollectTypeEnum collectTypeEnum) {
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId,
collectTypeEnum.getType()).stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList());
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, 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());
return userCollectInfoDao.findByUserIdAndCollectTypeAndObjectIdIn(userId, collectTypeEnum.getType(), objectIds)
.stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList());
}
public String getCollectLatest(String userId, CollectTypeEnum collectTypeEnum) {
UserCollectInfo userCollectInfo=userCollectInfoDao.findFirstByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, collectTypeEnum.getType());
return null==userCollectInfo?null:userCollectInfo.getObjectId();
UserCollectInfo userCollectInfo = userCollectInfoDao
.findFirstByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, collectTypeEnum.getType());
return null == userCollectInfo ? null : userCollectInfo.getObjectId();
}
public List<String> getCollectLatest2(String userId, CollectTypeEnum collectTypeEnum) {
List<UserCollectInfo> userCollectInfos = userCollectInfoDao
.findTop2ByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, collectTypeEnum.getType());
return CollectionUtils.isEmpty(userCollectInfos) ? Collections.emptyList()
: userCollectInfos.stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList());
}
}

Loading…
Cancel
Save