|
|
|
@ -42,16 +42,16 @@ public class UserCollectInfoService {
|
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
|
|
|
|
|
|
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 void saveCollect(String userId, String objectId, Integer collectType) {
|
|
|
|
|
//自己不关注自己,自己不把自己列入黑名单
|
|
|
|
|
if(objectId.equals(userId)) {
|
|
|
|
|
// 自己不关注自己,自己不把自己列入黑名单
|
|
|
|
|
if (objectId.equals(userId)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CollectTypeEnum collectTypeEnum = CollectTypeEnum.getByType(collectType);
|
|
|
|
@ -73,14 +73,14 @@ public class UserCollectInfoService {
|
|
|
|
|
if (CollectTypeEnum.FOLLOWS.equals(collectTypeEnum)) {
|
|
|
|
|
// 构建黑名单查询条件
|
|
|
|
|
// 我的黑名单
|
|
|
|
|
Criteria blackListCriteria=new Criteria();
|
|
|
|
|
Criteria blackListCriteria = new Criteria();
|
|
|
|
|
Criteria myBlackListCriteria = Criteria.where("userId").is(userId).and("objectId").is(objectId)
|
|
|
|
|
.and("collectType").is(CollectTypeEnum.BLACK_LIST.getType());
|
|
|
|
|
// 他人黑名单
|
|
|
|
|
Criteria otherBlackListCriteria = Criteria.where("userId").is(objectId).and("objectId").is(userId)
|
|
|
|
|
.and("collectType").is(CollectTypeEnum.BLACK_LIST.getType());
|
|
|
|
|
|
|
|
|
|
blackListCriteria.orOperator(myBlackListCriteria,otherBlackListCriteria);
|
|
|
|
|
blackListCriteria.orOperator(myBlackListCriteria, otherBlackListCriteria);
|
|
|
|
|
// 创建查询对象并应用查询条件
|
|
|
|
|
Query blackListQuery = new Query(blackListCriteria);
|
|
|
|
|
boolean isExistsBlackList = mongoTemplate.exists(blackListQuery, UserCollectInfo.class);
|
|
|
|
@ -103,7 +103,7 @@ public class UserCollectInfoService {
|
|
|
|
|
Query fanQuery = new Query(fanCriteria);
|
|
|
|
|
if (mongoTemplate.exists(fanQuery, UserCollectInfo.class)) {
|
|
|
|
|
userCollectInfo.setIsMutualFans(true);
|
|
|
|
|
//更新他人与我 由粉丝 变为互关
|
|
|
|
|
// 更新他人与我 由粉丝 变为互关
|
|
|
|
|
Update update = new Update().set("isMutualFans", true);
|
|
|
|
|
mongoTemplate.updateFirst(fanQuery, update, UserCollectInfo.class);
|
|
|
|
|
}
|
|
|
|
@ -188,6 +188,17 @@ public class UserCollectInfoService {
|
|
|
|
|
// 他人关注-1
|
|
|
|
|
other.setFollowCount(other.getFollowCount() - 1);
|
|
|
|
|
userInfoDao.save(other);
|
|
|
|
|
|
|
|
|
|
// 若为我的关注,且与他人为互关状态,则更新我的关注状态 为 仅关注,而非互关
|
|
|
|
|
// 我的关注
|
|
|
|
|
Criteria myFollowCriteria = Criteria.where("userId").is(user.getId()).and("objectId").is(objectId)
|
|
|
|
|
.and("collectType").is(CollectTypeEnum.FOLLOWS.getType()).and("isMutualFans").is(true);
|
|
|
|
|
Query myFollowQuery = new Query(myFollowCriteria);
|
|
|
|
|
boolean isMyFollow = mongoTemplate.exists(myFollowQuery, UserCollectInfo.class);
|
|
|
|
|
if (isMyFollow) {
|
|
|
|
|
Update update = new Update().set("isMutualFans", false);
|
|
|
|
|
mongoTemplate.updateFirst(myFollowQuery, update, UserCollectInfo.class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reduceFollowCount(UserInfo user, String objectId) {
|
|
|
|
@ -201,6 +212,17 @@ public class UserCollectInfoService {
|
|
|
|
|
// 他人粉丝-1
|
|
|
|
|
other.setFansCount(other.getFansCount() - 1);
|
|
|
|
|
userInfoDao.save(other);
|
|
|
|
|
|
|
|
|
|
// 若为我的粉丝,且与他人为互关状态,则更新他人的关注状态 为 仅关注,而非互关
|
|
|
|
|
// 他人的关注
|
|
|
|
|
Criteria otherFollowCriteria = Criteria.where("userId").is(objectId).and("objectId").is(user.getId())
|
|
|
|
|
.and("collectType").is(CollectTypeEnum.FOLLOWS.getType()).and("isMutualFans").is(true);
|
|
|
|
|
Query otherFollowQuery = new Query(otherFollowCriteria);
|
|
|
|
|
boolean isOtherFollow = mongoTemplate.exists(otherFollowQuery, UserCollectInfo.class);
|
|
|
|
|
if (isOtherFollow) {
|
|
|
|
|
Update update = new Update().set("isMutualFans", false);
|
|
|
|
|
mongoTemplate.updateFirst(otherFollowQuery, update, UserCollectInfo.class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void adjustFollowFanCount(UserInfo user, String objectId) {
|
|
|
|
@ -254,7 +276,7 @@ public class UserCollectInfoService {
|
|
|
|
|
other.setFansCount(other.getFansCount() + 1);
|
|
|
|
|
userInfoDao.save(other);
|
|
|
|
|
|
|
|
|
|
//向他人发送 新粉丝 消息
|
|
|
|
|
// 向他人发送 新粉丝 消息
|
|
|
|
|
sendMessageToFollows(user, objectId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -273,8 +295,9 @@ public class UserCollectInfoService {
|
|
|
|
|
private void addJournalCount(UserInfo user) {
|
|
|
|
|
user.setJournalCount(user.getJournalCount() + 1);
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
|
//更新redis 中的缓存
|
|
|
|
|
redisTemplate.opsForValue().set(Constants.REDIS_KEY_USER_COLLECT_JOURNAL+user.getId(),getCollectSet(user.getId(), CollectTypeEnum.JOURNAL));
|
|
|
|
|
// 更新redis 中的缓存
|
|
|
|
|
redisTemplate.opsForValue().set(Constants.REDIS_KEY_USER_COLLECT_JOURNAL + user.getId(),
|
|
|
|
|
getCollectSet(user.getId(), CollectTypeEnum.JOURNAL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addSongCount(UserInfo user) {
|
|
|
|
@ -285,8 +308,9 @@ public class UserCollectInfoService {
|
|
|
|
|
private void reduceJournalCount(UserInfo user) {
|
|
|
|
|
user.setJournalCount(user.getJournalCount() - 1);
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
|
//更新redis 中的缓存
|
|
|
|
|
redisTemplate.opsForValue().set(Constants.REDIS_KEY_USER_COLLECT_JOURNAL+user.getId(),getCollectSet(user.getId(), CollectTypeEnum.JOURNAL));
|
|
|
|
|
// 更新redis 中的缓存
|
|
|
|
|
redisTemplate.opsForValue().set(Constants.REDIS_KEY_USER_COLLECT_JOURNAL + user.getId(),
|
|
|
|
|
getCollectSet(user.getId(), CollectTypeEnum.JOURNAL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reduceSongCount(UserInfo user) {
|
|
|
|
@ -295,38 +319,43 @@ public class UserCollectInfoService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserRelationEnum getRelation(String userId, String otherId) {
|
|
|
|
|
List<UserCollectInfo> myCollectList=userCollectInfoDao.findByUserIdAndObjectId(userId, otherId);
|
|
|
|
|
if(null!=myCollectList) {
|
|
|
|
|
Map<Integer, UserCollectInfo> myCollectTypeMap=myCollectList.stream().collect(Collectors.toMap(UserCollectInfo::getCollectType, Function.identity()));
|
|
|
|
|
//他人是否在自己黑名单中
|
|
|
|
|
if(myCollectTypeMap.containsKey(CollectTypeEnum.BLACK_LIST.getType())) {
|
|
|
|
|
List<UserCollectInfo> myCollectList = userCollectInfoDao.findByUserIdAndObjectId(userId, otherId);
|
|
|
|
|
if (null != myCollectList) {
|
|
|
|
|
Map<Integer, UserCollectInfo> myCollectTypeMap = myCollectList.stream()
|
|
|
|
|
.collect(Collectors.toMap(UserCollectInfo::getCollectType, Function.identity()));
|
|
|
|
|
// 他人是否在自己黑名单中
|
|
|
|
|
if (myCollectTypeMap.containsKey(CollectTypeEnum.BLACK_LIST.getType())) {
|
|
|
|
|
return UserRelationEnum.SELF_BLACK_LIST;
|
|
|
|
|
}
|
|
|
|
|
//是否互关/仅关注
|
|
|
|
|
UserCollectInfo followCollectInfo=myCollectTypeMap.get(CollectTypeEnum.FOLLOWS.getType());
|
|
|
|
|
if(null!=followCollectInfo&&Boolean.TRUE.equals(followCollectInfo.getIsMutualFans())) {
|
|
|
|
|
// 是否互关/仅关注
|
|
|
|
|
UserCollectInfo followCollectInfo = myCollectTypeMap.get(CollectTypeEnum.FOLLOWS.getType());
|
|
|
|
|
if (null != followCollectInfo && Boolean.TRUE.equals(followCollectInfo.getIsMutualFans())) {
|
|
|
|
|
return UserRelationEnum.BOTH_FOLLOW;
|
|
|
|
|
}else if(null!=followCollectInfo) {
|
|
|
|
|
} else if (null != followCollectInfo) {
|
|
|
|
|
return UserRelationEnum.FOLLOW;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<UserCollectInfo> otherCollectList=userCollectInfoDao.findByUserIdAndObjectId(otherId, userId);
|
|
|
|
|
if(null!=otherCollectList) {
|
|
|
|
|
Map<Integer, UserCollectInfo> otherCollectTypeMap=otherCollectList.stream().collect(Collectors.toMap(UserCollectInfo::getCollectType, Function.identity()));
|
|
|
|
|
//自己是否在他人黑名单中
|
|
|
|
|
if(otherCollectTypeMap.containsKey(CollectTypeEnum.BLACK_LIST.getType())) {
|
|
|
|
|
List<UserCollectInfo> otherCollectList = userCollectInfoDao.findByUserIdAndObjectId(otherId, userId);
|
|
|
|
|
if (null != otherCollectList) {
|
|
|
|
|
Map<Integer, UserCollectInfo> otherCollectTypeMap = otherCollectList.stream()
|
|
|
|
|
.collect(Collectors.toMap(UserCollectInfo::getCollectType, Function.identity()));
|
|
|
|
|
// 自己是否在他人黑名单中
|
|
|
|
|
if (otherCollectTypeMap.containsKey(CollectTypeEnum.BLACK_LIST.getType())) {
|
|
|
|
|
return UserRelationEnum.OTHER_BLACK_LIST;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return UserRelationEnum.NOT_FOLLOW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<UserCollectInfo> findByUserIdAndCollectType(String userId, CollectTypeEnum collectTypeEnum, Pageable pageable) {
|
|
|
|
|
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId,collectTypeEnum.getType(),pageable);
|
|
|
|
|
public Page<UserCollectInfo> findByUserIdAndCollectType(String userId, CollectTypeEnum collectTypeEnum,
|
|
|
|
|
Pageable pageable) {
|
|
|
|
|
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, collectTypeEnum.getType(),
|
|
|
|
|
pageable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<UserCollectInfo> findByObjectIdAndCollectType(String objectId, CollectTypeEnum collectTypeEnum,
|
|
|
|
|
Pageable pageable) {
|
|
|
|
|
return userCollectInfoDao.findByObjectIdAndCollectTypeOrderByCreateTimeDesc(objectId,collectTypeEnum.getType(),pageable);
|
|
|
|
|
return userCollectInfoDao.findByObjectIdAndCollectTypeOrderByCreateTimeDesc(objectId, collectTypeEnum.getType(),
|
|
|
|
|
pageable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|