|
|
@@ -10,6 +10,7 @@ import com.usoftchina.uu.open.sdk.util.UuBeanMapper;
|
|
|
import io.grpc.StatusRuntimeException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -34,8 +35,9 @@ public class UuMessageService {
|
|
|
* @param code 消息类
|
|
|
* @param body 消息内容
|
|
|
* @param accountId 接收账号
|
|
|
+ * @return 消息ID
|
|
|
*/
|
|
|
- public void send(String code, String body, Long accountId) {
|
|
|
+ public Long send(String code, String body, Long accountId) {
|
|
|
SendMessageRequest.Builder builder = SendMessageRequest.newBuilder();
|
|
|
try {
|
|
|
builder.setCode(code)
|
|
|
@@ -43,7 +45,35 @@ public class UuMessageService {
|
|
|
.setAccountId(accountId);
|
|
|
SendMessageResponse response = messageServiceBlockingStub.send(builder.build());
|
|
|
ResponseHeader header = response.getResponseHeader();
|
|
|
- if (!header.getSuccess()) {
|
|
|
+ if (header.getSuccess()) {
|
|
|
+ return response.getMessageId();
|
|
|
+ } else {
|
|
|
+ throw new UuException(header);
|
|
|
+ }
|
|
|
+ } catch (StatusRuntimeException e) {
|
|
|
+ throw new UuException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送多人消息
|
|
|
+ *
|
|
|
+ * @param code 消息类
|
|
|
+ * @param body 消息内容
|
|
|
+ * @param accountIds 接收账号集合
|
|
|
+ * @return 消息ID集合
|
|
|
+ */
|
|
|
+ public List<Long> send(String code, String body, List<Long> accountIds) {
|
|
|
+ Assert.notEmpty(accountIds, "空账号集");
|
|
|
+ BatchSendMessageRequest.Builder builder = BatchSendMessageRequest.newBuilder();
|
|
|
+ try {
|
|
|
+ builder.setCode(code).setMessage(body);
|
|
|
+ accountIds.forEach(builder::addAccountId);
|
|
|
+ BatchSendMessageResponse response = messageServiceBlockingStub.batchSend(builder.build());
|
|
|
+ ResponseHeader header = response.getResponseHeader();
|
|
|
+ if (header.getSuccess()) {
|
|
|
+ return response.getMessageIdList();
|
|
|
+ } else {
|
|
|
throw new UuException(header);
|
|
|
}
|
|
|
} catch (StatusRuntimeException e) {
|