|
@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author sean
|
|
* @author sean
|
|
@@ -36,7 +37,9 @@ public class MessageLogicImpl implements MessageLogic {
|
|
|
@Override
|
|
@Override
|
|
|
public List<MessageVO> sendMessageToGroup(Long id, String message, Long groupId) {
|
|
public List<MessageVO> sendMessageToGroup(Long id, String message, Long groupId) {
|
|
|
Group group = groupService.getGroup(groupId);
|
|
Group group = groupService.getGroup(groupId);
|
|
|
-
|
|
|
|
|
|
|
+ if (group == null){
|
|
|
|
|
+ throw new HttpBadRequestException("group not exist");
|
|
|
|
|
+ }
|
|
|
List<User> userList = groupService.getUserByGroupId(groupId);
|
|
List<User> userList = groupService.getUserByGroupId(groupId);
|
|
|
List<MessageVO> messageVOs = new ArrayList<>();
|
|
List<MessageVO> messageVOs = new ArrayList<>();
|
|
|
|
|
|
|
@@ -47,7 +50,6 @@ public class MessageLogicImpl implements MessageLogic {
|
|
|
m.setParticipantId(user.getId());
|
|
m.setParticipantId(user.getId());
|
|
|
m.setPushed(Boolean.FALSE);
|
|
m.setPushed(Boolean.FALSE);
|
|
|
m.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
m.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
- m.setGroupId(groupId);
|
|
|
|
|
m = messageService.updateMessage(m);
|
|
m = messageService.updateMessage(m);
|
|
|
messageVOs.add(messageVOWrapper.wrap(m));
|
|
messageVOs.add(messageVOWrapper.wrap(m));
|
|
|
}
|
|
}
|
|
@@ -58,6 +60,9 @@ public class MessageLogicImpl implements MessageLogic {
|
|
|
@Override
|
|
@Override
|
|
|
public MessageVO sendMessageToGroupMember(Long ownerId, Long participantId, Long groupId, String message) {
|
|
public MessageVO sendMessageToGroupMember(Long ownerId, Long participantId, Long groupId, String message) {
|
|
|
Group group = groupService.getGroup(groupId);
|
|
Group group = groupService.getGroup(groupId);
|
|
|
|
|
+ if (group == null) {
|
|
|
|
|
+ throw new HttpBadRequestException("group not exist");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (!groupService.checkUserExist(participantId, groupId)) {
|
|
if (!groupService.checkUserExist(participantId, groupId)) {
|
|
|
throw new UnauthorizedException("Unauthorized");
|
|
throw new UnauthorizedException("Unauthorized");
|
|
@@ -69,7 +74,6 @@ public class MessageLogicImpl implements MessageLogic {
|
|
|
m.setOwnerId(ownerId);
|
|
m.setOwnerId(ownerId);
|
|
|
m.setPushed(Boolean.FALSE);
|
|
m.setPushed(Boolean.FALSE);
|
|
|
m.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
m.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
- m.setGroupId(groupId);
|
|
|
|
|
m = messageService.updateMessage(m);
|
|
m = messageService.updateMessage(m);
|
|
|
|
|
|
|
|
return messageVOWrapper.wrap(m);
|
|
return messageVOWrapper.wrap(m);
|
|
@@ -108,4 +112,29 @@ public class MessageLogicImpl implements MessageLogic {
|
|
|
});
|
|
});
|
|
|
return messageVOWrapper.wrap(messages);
|
|
return messageVOWrapper.wrap(messages);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<MessageVO> sendMultiMessage(Long id, List<MessageVO> messageVOs) {
|
|
|
|
|
+ List<Group> groupList = groupService.getGroupsByOwnerId(id);
|
|
|
|
|
+ List<Long> participantIds = messageVOs.stream().map(messageVO -> messageVO.getParticipantId()).collect(Collectors.toList());
|
|
|
|
|
+ List<MessageVO> messageVOList = new ArrayList<>();
|
|
|
|
|
+ for (Group group : groupList) {
|
|
|
|
|
+ if (participantIds.stream().allMatch(participantId ->
|
|
|
|
|
+ groupService.checkUserExist(participantId, group.getId()))) {
|
|
|
|
|
+ participantIds.stream().forEach(userid -> {
|
|
|
|
|
+ Message message = new Message();
|
|
|
|
|
+ message.setParticipantId(userid);
|
|
|
|
|
+ message.setOwnerId(id);
|
|
|
|
|
+ message.setMessage(messageVOs.get(1).getMessage());
|
|
|
|
|
+ message = messageService.updateMessage(message);
|
|
|
|
|
+ messageVOList.add(messageVOWrapper.wrap(message));
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (messageVOList.size() == 0) {
|
|
|
|
|
+ throw new UnauthorizedException("Authorized! user not in your group");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return messageVOList;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|