|
|
@ -1,122 +1,318 @@
|
|
|
|
package com.luoo.user.service;
|
|
|
|
package com.luoo.user.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.luoo.user.dao.UserCollectInfoDao;
|
|
|
|
import com.luoo.user.dao.UserCollectInfoDao;
|
|
|
|
import com.luoo.user.dto.UserCollectSongDto;
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
import com.luoo.user.pojo.UserCollectInfo;
|
|
|
|
import com.luoo.user.pojo.UserCollectInfo;
|
|
|
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import api.StatusCode;
|
|
|
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
|
|
|
import dto.UserMessageDto;
|
|
|
|
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
|
|
|
|
import enums.MessageTypeEnum;
|
|
|
|
|
|
|
|
import enums.UserRelationEnum;
|
|
|
|
|
|
|
|
import exception.BizException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
|
|
|
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.data.mongodb.core.query.Update;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import util.IdWorker;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class UserCollectInfoService {
|
|
|
|
public class UserCollectInfoService {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserCollectInfoDao userCollectInfoDao;
|
|
|
|
private UserCollectInfoDao userCollectInfoDao;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IdWorker idWorker;
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void saveCollect(String userId, String objectId, Integer collectType) {
|
|
|
|
|
|
|
|
//自己不关注自己,自己不把自己列入黑名单
|
|
|
|
|
|
|
|
if(objectId.equals(userId)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectTypeEnum collectTypeEnum = CollectTypeEnum.getByType(collectType);
|
|
|
|
|
|
|
|
if (null == collectTypeEnum) {
|
|
|
|
|
|
|
|
throw new BizException(StatusCode.VALIDATE_FAILED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
// 构建查询条件
|
|
|
|
|
|
|
|
Criteria criteria = Criteria.where("userId").is(userId).and("objectId").is(objectId).and("collectType")
|
|
|
|
|
|
|
|
.is(collectType);
|
|
|
|
|
|
|
|
// 创建查询对象并应用查询条件
|
|
|
|
|
|
|
|
Query query = new Query(criteria);
|
|
|
|
|
|
|
|
boolean isExists = mongoTemplate.exists(query, UserCollectInfo.class);
|
|
|
|
|
|
|
|
// 重复保存,此处不报错
|
|
|
|
|
|
|
|
if (isExists) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 特殊处理,若为关注,查看用户是否在我的/他人 黑名单中
|
|
|
|
|
|
|
|
if (CollectTypeEnum.FOLLOWS.equals(collectTypeEnum)) {
|
|
|
|
|
|
|
|
// 构建黑名单查询条件
|
|
|
|
|
|
|
|
// 我的黑名单
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// 创建查询对象并应用查询条件
|
|
|
|
|
|
|
|
Query blackListQuery = new Query(blackListCriteria);
|
|
|
|
|
|
|
|
boolean isExistsBlackList = mongoTemplate.exists(blackListQuery, UserCollectInfo.class);
|
|
|
|
|
|
|
|
// 在我的/他人黑名单中,无法关注
|
|
|
|
|
|
|
|
if (isExistsBlackList) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 存入mongodb
|
|
|
|
UserCollectInfo userCollectInfo = new UserCollectInfo();
|
|
|
|
UserCollectInfo userCollectInfo = new UserCollectInfo();
|
|
|
|
UserCollectSongDto userCollectSongDto = new UserCollectSongDto();
|
|
|
|
userCollectInfo.setUserId(userId);
|
|
|
|
userCollectSongDto.setName("smell like teensprit");
|
|
|
|
userCollectInfo.setObjectId(objectId);
|
|
|
|
userCollectSongDto.setArtist("Nirvana");
|
|
|
|
userCollectInfo.setCollectType(collectType);
|
|
|
|
|
|
|
|
userCollectInfo.setCreateTime(new Date());
|
|
|
|
|
|
|
|
// 特殊处理,若为关注,查看他人是否为我的粉丝,是否为互粉关系
|
|
|
|
|
|
|
|
if (CollectTypeEnum.FOLLOWS.equals(collectTypeEnum)) {
|
|
|
|
|
|
|
|
Criteria fanCriteria = Criteria.where("userId").is(objectId).and("objectId").is(userId).and("collectType")
|
|
|
|
|
|
|
|
.is(collectType);
|
|
|
|
|
|
|
|
// 创建查询对象并应用查询条件
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mongoTemplate.save(userCollectInfo);
|
|
|
|
|
|
|
|
|
|
|
|
UserCollectSongDto userCollectSongDto1 = new UserCollectSongDto();
|
|
|
|
// 更新mysql 中的count
|
|
|
|
userCollectSongDto1.setName("the unforgiven");
|
|
|
|
UserInfo user = userInfoDao.getById(userId);
|
|
|
|
userCollectSongDto1.setArtist("Metallica");
|
|
|
|
if (null == user) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List list = new ArrayList();
|
|
|
|
switch (collectTypeEnum) {
|
|
|
|
list.add(userCollectSongDto);
|
|
|
|
case SONG:
|
|
|
|
list.add(userCollectSongDto1);
|
|
|
|
addSongCount(user);
|
|
|
|
// userCollectInfo.setSongList(list);
|
|
|
|
break;
|
|
|
|
userCollectInfo.setCollectId(idWorker.nextId()+"");
|
|
|
|
case JOURNAL:
|
|
|
|
userCollectInfo.setUserId("111222");
|
|
|
|
addJournalCount(user);
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FOLLOWS:
|
|
|
|
|
|
|
|
addFollowCount(user, objectId);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLACK_LIST:
|
|
|
|
|
|
|
|
adjustFollowFanCount(user, objectId);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void cancelCollect(String userId, String objectId, Integer collectType) {
|
|
|
|
|
|
|
|
CollectTypeEnum collectTypeEnum = CollectTypeEnum.getByType(collectType);
|
|
|
|
|
|
|
|
if (null == collectTypeEnum) {
|
|
|
|
|
|
|
|
throw new BizException(StatusCode.VALIDATE_FAILED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public UserCollectInfo findByUserId(String userId){
|
|
|
|
// 构建查询条件
|
|
|
|
|
|
|
|
Criteria criteria = Criteria.where("userId").is(userId).and("objectId").is(objectId).and("collectType")
|
|
|
|
|
|
|
|
.is(collectType);
|
|
|
|
|
|
|
|
// 创建查询对象并应用查询条件
|
|
|
|
|
|
|
|
Query query = new Query(criteria);
|
|
|
|
|
|
|
|
boolean isExists = mongoTemplate.exists(query, UserCollectInfo.class);
|
|
|
|
|
|
|
|
// 未保存,无法取消
|
|
|
|
|
|
|
|
if (!isExists) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 在mongodb 中 删除
|
|
|
|
|
|
|
|
mongoTemplate.remove(query, UserCollectInfo.class);
|
|
|
|
|
|
|
|
|
|
|
|
return userCollectInfoDao.findUserCollectInfoByUserId(userId);
|
|
|
|
// 更新mysql 中的count
|
|
|
|
|
|
|
|
UserInfo user = userInfoDao.getById(userId);
|
|
|
|
|
|
|
|
if (null == user) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (collectTypeEnum) {
|
|
|
|
|
|
|
|
case SONG:
|
|
|
|
|
|
|
|
reduceSongCount(user);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JOURNAL:
|
|
|
|
|
|
|
|
reduceJournalCount(user);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FOLLOWS:
|
|
|
|
|
|
|
|
reduceFollowCount(user, objectId);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FANS:
|
|
|
|
|
|
|
|
reduceFanCount(user, objectId);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void collectSong(String userid, String id) {
|
|
|
|
private void reduceFanCount(UserInfo user, String objectId) {
|
|
|
|
|
|
|
|
UserInfo other = userInfoDao.getById(objectId);
|
|
|
|
|
|
|
|
if (null == other) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 我的粉丝-1
|
|
|
|
|
|
|
|
user.setFansCount(user.getFansCount() - 1);
|
|
|
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
|
|
|
|
// 他人关注-1
|
|
|
|
|
|
|
|
other.setFollowCount(other.getFollowCount() - 1);
|
|
|
|
|
|
|
|
userInfoDao.save(other);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
|
|
|
|
private void reduceFollowCount(UserInfo user, String objectId) {
|
|
|
|
if (null == userCollectInfo) {
|
|
|
|
UserInfo other = userInfoDao.getById(objectId);
|
|
|
|
userCollectInfo = new UserCollectInfo();
|
|
|
|
if (null == other) {
|
|
|
|
userCollectInfo.setUserId(userid);
|
|
|
|
return;
|
|
|
|
Set songSet = new HashSet();
|
|
|
|
}
|
|
|
|
songSet.add(id);
|
|
|
|
// 我的关注-1
|
|
|
|
userCollectInfo.setSongSet(songSet);
|
|
|
|
user.setFollowCount(user.getFollowCount() - 1);
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
userInfoDao.save(user);
|
|
|
|
} else {
|
|
|
|
// 他人粉丝-1
|
|
|
|
Set songSet = userCollectInfo.getSongSet();
|
|
|
|
other.setFansCount(other.getFansCount() - 1);
|
|
|
|
if(null == songSet) {
|
|
|
|
userInfoDao.save(other);
|
|
|
|
songSet = new HashSet<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
songSet.add(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userCollectInfo.setSongSet(songSet);
|
|
|
|
private void adjustFollowFanCount(UserInfo user, String objectId) {
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
UserInfo other = userInfoDao.getById(objectId);
|
|
|
|
|
|
|
|
if (null == other) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 若为我的关注,删除关注关系,我的关注数-1,他人粉丝数-1
|
|
|
|
|
|
|
|
// 我的关注
|
|
|
|
|
|
|
|
Criteria myFollowCriteria = Criteria.where("userId").is(user.getId()).and("objectId").is(objectId)
|
|
|
|
|
|
|
|
.and("collectType").is(CollectTypeEnum.FOLLOWS.getType());
|
|
|
|
|
|
|
|
Query myFollowQuery = new Query(myFollowCriteria);
|
|
|
|
|
|
|
|
boolean isMyFollow = mongoTemplate.exists(myFollowQuery, UserCollectInfo.class);
|
|
|
|
|
|
|
|
if (isMyFollow) {
|
|
|
|
|
|
|
|
mongoTemplate.remove(myFollowQuery, UserCollectInfo.class);
|
|
|
|
|
|
|
|
// 我的关注-1
|
|
|
|
|
|
|
|
user.setFollowCount(user.getFollowCount() - 1);
|
|
|
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
|
|
|
|
// 他人粉丝-1
|
|
|
|
|
|
|
|
other.setFansCount(other.getFansCount() - 1);
|
|
|
|
|
|
|
|
userInfoDao.save(other);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 若为我的粉丝,删除粉丝关系,我的粉丝数-1,他人关注数-1
|
|
|
|
|
|
|
|
// 我的粉丝
|
|
|
|
|
|
|
|
Criteria myFanCriteria = Criteria.where("userId").is(objectId).and("objectId").is(user.getId())
|
|
|
|
|
|
|
|
.and("collectType").is(CollectTypeEnum.FOLLOWS.getType());
|
|
|
|
|
|
|
|
Query myFanQuery = new Query(myFanCriteria);
|
|
|
|
|
|
|
|
boolean isMyFan = mongoTemplate.exists(myFanQuery, UserCollectInfo.class);
|
|
|
|
|
|
|
|
if (isMyFan) {
|
|
|
|
|
|
|
|
mongoTemplate.remove(myFanQuery, UserCollectInfo.class);
|
|
|
|
|
|
|
|
// 我的粉丝-1
|
|
|
|
|
|
|
|
user.setFansCount(user.getFansCount() - 1);
|
|
|
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
|
|
|
|
// 他人关注-1
|
|
|
|
|
|
|
|
other.setFollowCount(other.getFollowCount() - 1);
|
|
|
|
|
|
|
|
userInfoDao.save(other);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addFollowCount(UserInfo user, String objectId) {
|
|
|
|
|
|
|
|
// 查询我的和他人的黑名单,如果在黑名单中,无法关注
|
|
|
|
|
|
|
|
UserInfo other = userInfoDao.getById(objectId);
|
|
|
|
|
|
|
|
if (null == other) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 我的关注+1
|
|
|
|
|
|
|
|
user.setFollowCount(user.getFollowCount() + 1);
|
|
|
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
|
|
|
|
// 他人粉丝+1
|
|
|
|
|
|
|
|
other.setFansCount(other.getFansCount() + 1);
|
|
|
|
|
|
|
|
userInfoDao.save(other);
|
|
|
|
|
|
|
|
|
|
|
|
public void collectJournal(String userid, String id) {
|
|
|
|
//向他人发送 新粉丝 消息
|
|
|
|
|
|
|
|
sendMessageToFollows(user, objectId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void sendMessageToFollows(UserInfo userInfo, String followId) {
|
|
|
|
|
|
|
|
UserMessageDto userMessageDto = new UserMessageDto();
|
|
|
|
|
|
|
|
userMessageDto.setType(MessageTypeEnum.FOLLOW.getType()); // 消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息
|
|
|
|
|
|
|
|
userMessageDto.setUserId(followId);
|
|
|
|
|
|
|
|
userMessageDto.setContent(userInfo.getNickName() + " 关注了你");
|
|
|
|
|
|
|
|
userMessageDto.setTitle("您有新的粉丝");
|
|
|
|
|
|
|
|
userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
|
|
|
|
|
|
|
|
userMessageDto.setSendUserId(userInfo.getId());
|
|
|
|
|
|
|
|
userMessageDto.setSendUserNickName(userInfo.getNickName());
|
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend("userMessage", userMessageDto);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
|
|
|
|
private void addJournalCount(UserInfo user) {
|
|
|
|
if (null == userCollectInfo) {
|
|
|
|
user.setJournalCount(user.getJournalCount() + 1);
|
|
|
|
userCollectInfo = new UserCollectInfo();
|
|
|
|
userInfoDao.save(user);
|
|
|
|
userCollectInfo.setUserId(userid);
|
|
|
|
|
|
|
|
Set journalSet = new HashSet();
|
|
|
|
|
|
|
|
journalSet.add(id);
|
|
|
|
|
|
|
|
userCollectInfo.setJournalSet(journalSet);
|
|
|
|
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Set journalSet =userCollectInfo.getJournalSet();
|
|
|
|
|
|
|
|
if(null== journalSet) {
|
|
|
|
|
|
|
|
journalSet = new HashSet();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
journalSet.add(id);
|
|
|
|
|
|
|
|
userCollectInfo.setJournalSet(journalSet);
|
|
|
|
private void addSongCount(UserInfo user) {
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
user.setSongCount(user.getSongCount() + 1);
|
|
|
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void reduceJournalCount(UserInfo user) {
|
|
|
|
|
|
|
|
user.setJournalCount(user.getJournalCount() - 1);
|
|
|
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
private void reduceSongCount(UserInfo user) {
|
|
|
|
* 方法过期
|
|
|
|
user.setSongCount(user.getSongCount() - 1);
|
|
|
|
*/
|
|
|
|
userInfoDao.save(user);
|
|
|
|
public void unCollect(){
|
|
|
|
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId("111222");
|
|
|
|
|
|
|
|
UserCollectSongDto userCollectSongDto = new UserCollectSongDto();
|
|
|
|
|
|
|
|
userCollectSongDto.setName("smell like teensprit");
|
|
|
|
|
|
|
|
userCollectSongDto.setArtist("Nirvana");
|
|
|
|
|
|
|
|
// userCollectInfo.getSongList().remove(userCollectSongDto);
|
|
|
|
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void unCollectJournal(String userid, String id) {
|
|
|
|
public UserRelationEnum getRelation(String userId, String otherId) {
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
|
|
|
|
List<UserCollectInfo> myCollectList=userCollectInfoDao.findByUserIdAndObjectId(userId, otherId);
|
|
|
|
userCollectInfo.getJournalSet().remove(id);
|
|
|
|
if(null!=myCollectList) {
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
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())) {
|
|
|
|
|
|
|
|
return UserRelationEnum.BOTH_FOLLOW;
|
|
|
|
|
|
|
|
}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())) {
|
|
|
|
|
|
|
|
return UserRelationEnum.OTHER_BLACK_LIST;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return UserRelationEnum.NOT_FOLLOW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void unCollectSong(String userid, String id) {
|
|
|
|
public Page<UserCollectInfo> findByUserIdAndCollectType(String userId, CollectTypeEnum collectTypeEnum, Pageable pageable) {
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
|
|
|
|
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId,collectTypeEnum.getType(),pageable);
|
|
|
|
userCollectInfo.getSongSet().remove(id);
|
|
|
|
}
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Page<UserCollectInfo> findByObjectIdAndCollectType(String objectId, CollectTypeEnum collectTypeEnum,
|
|
|
|
|
|
|
|
Pageable pageable) {
|
|
|
|
|
|
|
|
return userCollectInfoDao.findByObjectIdAndCollectTypeOrderByCreateTimeDesc(objectId,collectTypeEnum.getType(),pageable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|