1.remove unsed method and add sendMessageToFollows

main
Gary 12 months ago
parent 0ca110f4df
commit 77e539ffb1

@ -1,8 +1,6 @@
package com.luoo.user.service;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@ -11,23 +9,29 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.luoo.user.dao.UserCollectDao;
import com.luoo.user.dto.UserCollectCount;
import com.luoo.user.pojo.UserCollect;
import com.luoo.user.pojo.UserInfo;
import api.StatusCode;
import constants.Constants;
import dto.UserMessageDto;
import enums.CollectTypeEnum;
import enums.CollectTypeEnum.*;
import enums.MessageTypeEnum;
import exception.BizException;
@Service
public class UserCollectService {
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private UserCollectDao userCollectDao;
@Autowired
private UserInfoService userInfoService;
public void saveCollect(String userId, String objectId, Integer collectType) {
addOrRemove(userId, objectId, collectType, true);
}
@ -48,9 +52,13 @@ public class UserCollectService {
break;
case FOLLOWS:
Optional<UserCollect> followsDbCollect = userCollectDao.findById(objectId);
UserCollect followsUserCollect=followsDbCollect.isPresent()?followsDbCollect.get():createUserCollect(objectId);
UserCollect followsUserCollect = followsDbCollect.isPresent() ? followsDbCollect.get()
: createUserCollect(objectId);
addOrRemove(isAdd, userCollect.getFollows(), objectId, followsUserCollect.getFans(), userId);
userCollectDao.save(followsUserCollect);
if (isAdd) {
sendMessageToFollows(userId, objectId);
}
break;
case FANS:
Optional<UserCollect> fansDbCollect = userCollectDao.findById(objectId);
@ -67,6 +75,19 @@ public class UserCollectService {
userCollectDao.save(userCollect);
}
private void sendMessageToFollows(String userId, String followId) {
UserInfo userInfo = userInfoService.findById(userId);
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(userId);
userMessageDto.setSendUserNickName(userInfo.getNickName());
rabbitTemplate.convertAndSend("userMessage", userMessageDto);
}
private void addOrRemove(boolean isAdd, LinkedList<String> follows, String objectId, LinkedList<String> fans,
String userId) {
if (isAdd) {
@ -97,8 +118,7 @@ public class UserCollectService {
}
}
public void deleteByUserIdAndObjectIdAndCollectType(String userId, String objectId,
Integer collectType) {
public void deleteByUserIdAndObjectIdAndCollectType(String userId, String objectId, Integer collectType) {
addOrRemove(userId, objectId, collectType, false);
}
@ -106,27 +126,6 @@ public class UserCollectService {
return userCollectDao.findById(userId);
}
public List<String> getCollectList(String userId, Integer pageNum, Integer pageSize,
CollectTypeEnum collectTypeEnum) {
if (null == userId) {
return Collections.emptyList();
}
Optional<UserCollect> optional = userCollectDao.findById(userId);
if (!optional.isPresent()) {
return Collections.emptyList();
}
UserCollect userCollect = optional.get();
switch (collectTypeEnum) {
case FOLLOWS:
return getPageResult(pageNum, pageSize, userCollect.getFollows());
case FANS:
return getPageResult(pageNum, pageSize, userCollect.getFans());
case BLACK_LIST:
return getPageResult(pageNum, pageSize, userCollect.getBlackList());
default:
return Collections.emptyList();
}
}
private List<String> getPageResult(Integer pageNum, Integer pageSize, LinkedList<String> objectIds) {
int end = pageNum * pageSize;
if (null != pageNum && null != pageSize && pageNum > 0 && pageSize > 0 && end <= objectIds.size()) {
@ -135,8 +134,8 @@ public class UserCollectService {
return objectIds;
}
public Pair<List<String>, Set<String>> getCollectListWithBothFollowSet(String userId, Integer pageNum, Integer pageSize,
CollectTypeEnum collectTypeEnum) {
public Pair<List<String>, Set<String>> getCollectListWithBothFollowSet(String userId, Integer pageNum,
Integer pageSize, CollectTypeEnum collectTypeEnum) {
if (null == userId) {
return Pair.of(Collections.emptyList(), Collections.emptySet());
}

Loading…
Cancel
Save