|
|
@ -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
|
|
|
|
|
|
|
|
private UserCollectInfoDao userCollectInfoDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建查询条件
|
|
|
|
|
|
|
|
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.setUserId(userId);
|
|
|
|
|
|
|
|
userCollectInfo.setObjectId(objectId);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新mysql 中的count
|
|
|
|
|
|
|
|
UserInfo user = userInfoDao.getById(userId);
|
|
|
|
|
|
|
|
if (null == user) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (collectTypeEnum) {
|
|
|
|
|
|
|
|
case SONG:
|
|
|
|
|
|
|
|
addSongCount(user);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JOURNAL:
|
|
|
|
|
|
|
|
addJournalCount(user);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建查询条件
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void reduceFollowCount(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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void adjustFollowFanCount(UserInfo user, String objectId) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//向他人发送 新粉丝 消息
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addJournalCount(UserInfo user) {
|
|
|
|
|
|
|
|
user.setJournalCount(user.getJournalCount() + 1);
|
|
|
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addSongCount(UserInfo user) {
|
|
|
|
|
|
|
|
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 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())) {
|
|
|
|
|
|
|
|
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 Page<UserCollectInfo> findByUserIdAndCollectType(String userId, CollectTypeEnum collectTypeEnum, Pageable pageable) {
|
|
|
|
|
|
|
|
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId,collectTypeEnum.getType(),pageable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public Page<UserCollectInfo> findByObjectIdAndCollectType(String objectId, CollectTypeEnum collectTypeEnum,
|
|
|
|
private UserCollectInfoDao userCollectInfoDao;
|
|
|
|
Pageable pageable) {
|
|
|
|
|
|
|
|
return userCollectInfoDao.findByObjectIdAndCollectTypeOrderByCreateTimeDesc(objectId,collectTypeEnum.getType(),pageable);
|
|
|
|
@Autowired
|
|
|
|
}
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserCollectInfo userCollectInfo = new UserCollectInfo();
|
|
|
|
|
|
|
|
UserCollectSongDto userCollectSongDto = new UserCollectSongDto();
|
|
|
|
|
|
|
|
userCollectSongDto.setName("smell like teensprit");
|
|
|
|
|
|
|
|
userCollectSongDto.setArtist("Nirvana");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserCollectSongDto userCollectSongDto1 = new UserCollectSongDto();
|
|
|
|
|
|
|
|
userCollectSongDto1.setName("the unforgiven");
|
|
|
|
|
|
|
|
userCollectSongDto1.setArtist("Metallica");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List list = new ArrayList();
|
|
|
|
|
|
|
|
list.add(userCollectSongDto);
|
|
|
|
|
|
|
|
list.add(userCollectSongDto1);
|
|
|
|
|
|
|
|
// userCollectInfo.setSongList(list);
|
|
|
|
|
|
|
|
userCollectInfo.setCollectId(idWorker.nextId()+"");
|
|
|
|
|
|
|
|
userCollectInfo.setUserId("111222");
|
|
|
|
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserCollectInfo findByUserId(String userId){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return userCollectInfoDao.findUserCollectInfoByUserId(userId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void collectSong(String userid, String id) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
|
|
|
|
|
|
|
|
if (null == userCollectInfo) {
|
|
|
|
|
|
|
|
userCollectInfo = new UserCollectInfo();
|
|
|
|
|
|
|
|
userCollectInfo.setUserId(userid);
|
|
|
|
|
|
|
|
Set songSet = new HashSet();
|
|
|
|
|
|
|
|
songSet.add(id);
|
|
|
|
|
|
|
|
userCollectInfo.setSongSet(songSet);
|
|
|
|
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Set songSet = userCollectInfo.getSongSet();
|
|
|
|
|
|
|
|
if(null == songSet) {
|
|
|
|
|
|
|
|
songSet = new HashSet<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
songSet.add(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userCollectInfo.setSongSet(songSet);
|
|
|
|
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void collectJournal(String userid, String id) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
|
|
|
|
|
|
|
|
if (null == userCollectInfo) {
|
|
|
|
|
|
|
|
userCollectInfo = new UserCollectInfo();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 方法过期
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
|
|
|
|
|
|
|
|
userCollectInfo.getJournalSet().remove(id);
|
|
|
|
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void unCollectSong(String userid, String id) {
|
|
|
|
|
|
|
|
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
|
|
|
|
|
|
|
|
userCollectInfo.getSongSet().remove(id);
|
|
|
|
|
|
|
|
userCollectInfoDao.save(userCollectInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|