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

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

Loading…
Cancel
Save