1.fix my fans status after cancel follow

main
Gary 9 months ago
parent 811513efe9
commit 301df9908e

@ -36,7 +36,7 @@ public class UserRespDTO {
@ApiModelProperty(value = "生日,格式为: yyyy.MM.dd")
private String birthDay;
@ApiModelProperty(value = "与他人关系1未关注2 已关注3互相关注 4他人在自己黑名单5自己在他人黑名单", example = "1")
private int relation;
private int relation=1;
@ApiModelProperty(value = "IP 归属地,精确到省份", example = "北京")
private String ipLocation;
}

@ -42,11 +42,11 @@ 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) {
@ -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) {
@ -274,7 +296,8 @@ public class UserCollectInfoService {
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));
redisTemplate.opsForValue().set(Constants.REDIS_KEY_USER_COLLECT_JOURNAL + user.getId(),
getCollectSet(user.getId(), CollectTypeEnum.JOURNAL));
}
private void addSongCount(UserInfo user) {
@ -286,7 +309,8 @@ public class UserCollectInfoService {
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));
redisTemplate.opsForValue().set(Constants.REDIS_KEY_USER_COLLECT_JOURNAL + user.getId(),
getCollectSet(user.getId(), CollectTypeEnum.JOURNAL));
}
private void reduceSongCount(UserInfo user) {
@ -297,7 +321,8 @@ 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()));
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;
@ -312,7 +337,8 @@ public class UserCollectInfoService {
}
List<UserCollectInfo> otherCollectList = userCollectInfoDao.findByUserIdAndObjectId(otherId, userId);
if (null != otherCollectList) {
Map<Integer, UserCollectInfo> otherCollectTypeMap=otherCollectList.stream().collect(Collectors.toMap(UserCollectInfo::getCollectType, Function.identity()));
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;
@ -321,12 +347,15 @@ public class UserCollectInfoService {
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);
}
}

Loading…
Cancel
Save