Commit 0265dd0cd511400781ac4e1139cd592943cc333f
1 parent
151be176
feat(*): 兼容信鸽token未注册的情况
- 兼容信鸽token未注册的情况
Showing
2 changed files
with
37 additions
and
26 deletions
fw-hermes-service/src/main/kotlin/cn/fw/hermes/service/biz/MessageSender.kt
... | ... | @@ -51,7 +51,7 @@ class MessageSender( |
51 | 51 | @Transactional(rollbackFor = [Exception::class]) |
52 | 52 | fun sendMsg(messageId: Long?) { |
53 | 53 | val history = messageHistoryService.getById(messageId) |
54 | - history?.takeIf { MsgStatusEnum.WAITING != it.msgStatus }?.run { | |
54 | + history?.takeIf { MsgStatusEnum.WAITING == it.msgStatus }?.run { | |
55 | 55 | val dataList = messageDataService.queryDataByMsgId(history.id) |
56 | 56 | if (CollectionUtils.isEmpty(dataList)) { |
57 | 57 | return |
... | ... | @@ -82,39 +82,50 @@ class MessageSender( |
82 | 82 | history.setSendDay(LocalDate.now()) |
83 | 83 | history.setCreateTime(Date()) |
84 | 84 | if (useMqtt || !xgTodo) { |
85 | - val msg = history.toMsg() | |
86 | - val list = dataList.stream().map { r: MessageData -> this.genElement(r, msg) }.collect(Collectors.toList()) | |
87 | - msg.msgBody = list | |
88 | - val msgTopics = history.msgTopic | |
89 | - val pair = mqttService.senMsg(msgTopics, msg) | |
90 | - return pair?.let { | |
91 | - val isSuccess = true == it.key | |
92 | - val desc = it.value | |
93 | - history.setMsgStatus(MsgStatusEnum.UPLOAD) | |
94 | - history.setMsgStatusDesc(desc) | |
95 | - if (!isSuccess) { | |
85 | + return mqtSend(history, dataList) | |
86 | + } | |
87 | + | |
88 | + return xgPushService.sendMsg(userId, AccountTypeEnum.B_USER).run { | |
89 | + if (first == -1) { | |
90 | + mqtSend(history, dataList) | |
91 | + } else { | |
92 | + val sendSuccess = first == 0 | |
93 | + history.setSendSuccessTime(LocalDateTime.now()) | |
94 | + if (sendSuccess) { | |
95 | + history.setMsgStatus(MsgStatusEnum.SUCCESS) | |
96 | + history.setMsgStatusDesc(Constant.SUCCESS_MSG) | |
97 | + history.setXgId(second) | |
98 | + } else { | |
96 | 99 | history.setMsgStatus(MsgStatusEnum.FAIL) |
97 | - history.setSendSuccessTime(LocalDateTime.now()) | |
100 | + history.setMsgStatusDesc("$first:$second") | |
98 | 101 | } |
99 | 102 | messageHistoryService.saveOrUpdate(history) |
100 | - Pair.of(history.msgStatus, desc) | |
103 | + | |
104 | + Pair.of(history.msgStatus, history.msgStatusDesc) | |
101 | 105 | } |
102 | 106 | } |
107 | + } | |
103 | 108 | |
104 | - return xgPushService.sendMsg(userId, AccountTypeEnum.B_USER).run { | |
105 | - val sendSuccess = first == 0 | |
106 | - history.setSendSuccessTime(LocalDateTime.now()) | |
107 | - if (sendSuccess) { | |
108 | - history.setMsgStatus(MsgStatusEnum.SUCCESS) | |
109 | - history.setMsgStatusDesc(Constant.SUCCESS_MSG) | |
110 | - history.setXgId(second) | |
111 | - } else { | |
109 | + private fun mqtSend( | |
110 | + history: MessageHistory, | |
111 | + dataList: List<MessageData> | |
112 | + ): Pair<MsgStatusEnum, String>? { | |
113 | + val msg = history.toMsg() | |
114 | + val list = dataList.stream().map { r: MessageData -> this.genElement(r, msg) }.collect(Collectors.toList()) | |
115 | + msg.msgBody = list | |
116 | + val msgTopics = history.msgTopic | |
117 | + val pair = mqttService.senMsg(msgTopics, msg) | |
118 | + return pair?.let { | |
119 | + val isSuccess = true == it.key | |
120 | + val desc = it.value | |
121 | + history.setMsgStatus(MsgStatusEnum.UPLOAD) | |
122 | + history.setMsgStatusDesc(desc) | |
123 | + if (!isSuccess) { | |
112 | 124 | history.setMsgStatus(MsgStatusEnum.FAIL) |
113 | - history.setMsgStatusDesc("$first:$second") | |
125 | + history.setSendSuccessTime(LocalDateTime.now()) | |
114 | 126 | } |
115 | 127 | messageHistoryService.saveOrUpdate(history) |
116 | - | |
117 | - Pair.of(history.msgStatus, history.msgStatusDesc) | |
128 | + Pair.of(history.msgStatus, desc) | |
118 | 129 | } |
119 | 130 | } |
120 | 131 | ... | ... |
fw-hermes-service/src/main/kotlin/cn/fw/hermes/service/biz/XgPushService.kt
... | ... | @@ -108,7 +108,7 @@ class XgPushService( |
108 | 108 | fun sendMsg(userId: Long, accountType: AccountTypeEnum): Pair<Int, String> { |
109 | 109 | val xgToken = getUserToken(userId, accountType) |
110 | 110 | if (Constant.INVALID_TOKEN == xgToken) { |
111 | - return Pair(-1, "") | |
111 | + return Pair(-1, "INVALID_TOKEN") | |
112 | 112 | } |
113 | 113 | val pushAppRequest = PushAppRequest() |
114 | 114 | pushAppRequest.audience_type = AudienceType.token | ... | ... |