|
|
|
@ -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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|