Commit 95876de8d40b579f7b76aefdfa19cdf9973b85e3
1 parent
385010d7
feat(*): 重构发送消息
- 重构发送消息
Showing
11 changed files
with
185 additions
and
167 deletions
fw-hermes-common/src/main/java/cn/fw/hermes/common/constant/Constant.java
... | ... | @@ -2,24 +2,24 @@ package cn.fw.hermes.common.constant; |
2 | 2 | |
3 | 3 | import cn.hutool.core.util.StrUtil; |
4 | 4 | |
5 | -import java.util.function.Function; | |
5 | +import java.util.function.UnaryOperator; | |
6 | 6 | |
7 | 7 | /** |
8 | 8 | * @author 张志伟 |
9 | 9 | * @date 2018-03-29 11:40 |
10 | 10 | */ |
11 | 11 | public interface Constant { |
12 | - String SUCCESS_MSG = "OK"; | |
12 | + String SUCCESS_MSG = "OK"; | |
13 | 13 | String PLATFORM_KEY = "x-appid"; |
14 | 14 | String TOPIC_CACHE_KEY = "sys:topic"; |
15 | 15 | String PLATFORM_CACHE_KEY = "sys:platform"; |
16 | 16 | String ACCOUNT_CACHE_KEY = "account:info"; |
17 | 17 | String DISTURB_SETTING_CACHE_KEY = "setting:disturb"; |
18 | - Function<String, String> RPC_EHR_CACHE_KEY = r -> StrUtil.format("rpc:ehr:{}", r); | |
18 | + UnaryOperator<String> RPC_EHR_CACHE_KEY = r -> StrUtil.format("rpc:ehr:{}", r); | |
19 | 19 | /** |
20 | 20 | * 唯一id缓存key |
21 | 21 | */ |
22 | - Function<String, String> UNIQUE_ID_CACHE_KEY = r -> StrUtil.format("hermes:unique:id:{}", r); | |
22 | + UnaryOperator<String> UNIQUE_ID_CACHE_KEY = r -> StrUtil.format("hermes:unique:id:{}", r); | |
23 | 23 | /** |
24 | 24 | * 系统topic |
25 | 25 | */ |
... | ... | @@ -66,5 +66,5 @@ public interface Constant { |
66 | 66 | /** |
67 | 67 | * 无效信鸽token |
68 | 68 | */ |
69 | - String inValidToken = "#"; | |
69 | + String INVALID_TOKEN = "#"; | |
70 | 70 | } | ... | ... |
fw-hermes-common/src/main/java/cn/fw/hermes/common/utils/StringUtils.java
... | ... | @@ -305,8 +305,7 @@ public final class StringUtils { |
305 | 305 | return input; |
306 | 306 | } |
307 | 307 | buffer.append(tail); |
308 | - } catch (UnsupportedEncodingException e) { | |
309 | - e.printStackTrace(); | |
308 | + } catch (UnsupportedEncodingException ignored) { | |
310 | 309 | } |
311 | 310 | return buffer.toString(); |
312 | 311 | } |
... | ... | @@ -465,8 +464,7 @@ public final class StringUtils { |
465 | 464 | int len = text.length(); |
466 | 465 | try { |
467 | 466 | len = text.getBytes("GBK").length;//SQLServer数据库用的GBK编码 |
468 | - } catch (UnsupportedEncodingException e) { | |
469 | - e.printStackTrace(); | |
467 | + } catch (UnsupportedEncodingException ignored) { | |
470 | 468 | } |
471 | 469 | return len; |
472 | 470 | } |
... | ... | @@ -483,7 +481,7 @@ public final class StringUtils { |
483 | 481 | int pos = -1; |
484 | 482 | int i = 0; |
485 | 483 | while ((pos = data.indexOf(from, i)) != -1) { |
486 | - buf.append(data.substring(i, pos)).append(to); | |
484 | + buf.append(data, i, pos).append(to); | |
487 | 485 | i = pos + from.length(); |
488 | 486 | } |
489 | 487 | buf.append(data.substring(i)); |
... | ... | @@ -543,4 +541,4 @@ public final class StringUtils { |
543 | 541 | System.out.println(repeat("?", 10, ",")); |
544 | 542 | length("AAA中国()111222bb"); |
545 | 543 | } |
546 | -} | |
547 | 544 | \ No newline at end of file |
545 | +} | ... | ... |
fw-hermes-domain/src/main/java/cn/fw/hermes/domain/db/MessageHistory.java
... | ... | @@ -50,13 +50,13 @@ public class MessageHistory { |
50 | 50 | @TableField(typeHandler = StringListTypeHandler.class) |
51 | 51 | private List<String> msgTopic; |
52 | 52 | /** |
53 | - * 目标账号 | |
53 | + * 目标账号 [对应userId] | |
54 | 54 | */ |
55 | 55 | private String toAccount; |
56 | 56 | /** |
57 | - * 是否是待办消息 | |
57 | + * 是否是需要信鸽推送的待办消息 | |
58 | 58 | */ |
59 | - private Boolean td; | |
59 | + private Boolean xgTodo; | |
60 | 60 | /** |
61 | 61 | * 发送方账号 |
62 | 62 | */ | ... | ... |
fw-hermes-domain/src/main/java/cn/fw/hermes/domain/mqtt/Message.java
1 | 1 | package cn.fw.hermes.domain.mqtt; |
2 | 2 | |
3 | -import cn.fw.hermes.domain.db.MessageHistory; | |
4 | 3 | import cn.fw.hermes.domain.mqtt.msgbody.MsgElement; |
5 | 4 | import lombok.Getter; |
6 | 5 | |
7 | -import java.time.ZoneOffset; | |
8 | 6 | import java.util.List; |
9 | 7 | |
10 | 8 | /** |
... | ... | @@ -58,17 +56,6 @@ public class Message { |
58 | 56 | */ |
59 | 57 | private String remark; |
60 | 58 | |
61 | - public static Message with(MessageHistory history) { | |
62 | - Message msg = new Message(); | |
63 | - msg.setMsgId(history.getId()); | |
64 | - msg.setMsgSummary(history.getMsgSummary()); | |
65 | - msg.setSender(history.getFromAccount()); | |
66 | - msg.setReceiver(history.getToAccount()); | |
67 | - msg.setSendTimestamp(history.getSendTime().toInstant(ZoneOffset.of("+8")).toEpochMilli()); | |
68 | - msg.setMsgTimestamp(history.getCreateTime().getTime()); | |
69 | - return msg; | |
70 | - } | |
71 | - | |
72 | 59 | |
73 | 60 | public void setMsgId(Long msgId) { |
74 | 61 | this.msgId = msgId; | ... | ... |
fw-hermes-server/src/main/kotlin/cn/fw/hermes/controller/common/XinGeDebugController.kt
... | ... | @@ -32,7 +32,7 @@ class XinGeDebugController(private val xinGeProperty: XinGeProperty, private val |
32 | 32 | @ControllerMethod("信鸽推送测试消息") |
33 | 33 | @GetMapping("/send/msg") |
34 | 34 | fun sendMsg(@NotNull(message = "用户id不能为空") userId: Long?): Message<Void> { |
35 | - userId?.let { xgPushService.sendData(it, AccountTypeEnum.B_USER) } | |
35 | + userId?.let { xgPushService.sendDebugData(it, AccountTypeEnum.B_USER) } | |
36 | 36 | return success() |
37 | 37 | } |
38 | 38 | ... | ... |
fw-hermes-service/src/main/java/cn/fw/hermes/service/biz/BeanTransfer.java
... | ... | @@ -111,7 +111,7 @@ public final class BeanTransfer { |
111 | 111 | public static MessageHistory transform2MsgHistory(MessageConditionDTO dto) { |
112 | 112 | MessageHistory history = new MessageHistory(); |
113 | 113 | history.setId(dto.getId()); |
114 | - history.setTd(false); | |
114 | + history.setXgTodo(false); | |
115 | 115 | MessageBodyDTO firstMsgBody = dto.getMsgBodyList().get(0); |
116 | 116 | MsgTypeEnum msgTypeEnum = MsgTypeEnum.ofValue(firstMsgBody.getType()); |
117 | 117 | String format = "[%s]"; |
... | ... | @@ -138,8 +138,9 @@ public final class BeanTransfer { |
138 | 138 | history.setMsgSummary(String.format(format, "其他")); |
139 | 139 | String data = firstMsgBody.getData(); |
140 | 140 | boolean isBackLog = data.indexOf(Constant.BACKLOG_MSG) > 0; |
141 | - if (isBackLog) { | |
142 | - history.setTd(true); | |
141 | + boolean hasApp = dto.getPlatforms().stream().anyMatch(t -> t.equals(PlatformTypeEnum.APP.getValue())); | |
142 | + if (isBackLog && hasApp) { | |
143 | + history.setXgTodo(true); | |
143 | 144 | history.setMsgSummary(String.format(format, "待办")); |
144 | 145 | } |
145 | 146 | break; | ... | ... |
fw-hermes-service/src/main/java/cn/fw/hermes/service/biz/MessageSender.java deleted
1 | -package cn.fw.hermes.service.biz; | |
2 | - | |
3 | -import cn.fw.hermes.common.constant.Constant; | |
4 | -import cn.fw.hermes.common.utils.DateUtil; | |
5 | -import cn.fw.hermes.domain.db.MessageData; | |
6 | -import cn.fw.hermes.domain.db.MessageHistory; | |
7 | -import cn.fw.hermes.domain.enums.MsgStatusEnum; | |
8 | -import cn.fw.hermes.domain.enums.MsgTypeEnum; | |
9 | -import cn.fw.hermes.domain.mqtt.Message; | |
10 | -import cn.fw.hermes.domain.mqtt.msgbody.*; | |
11 | -import cn.fw.hermes.sdk.v2.enums.MsgState; | |
12 | -import cn.fw.hermes.sdk.v2.result.MessageV2Result; | |
13 | -import cn.fw.hermes.service.data.MessageDataService; | |
14 | -import cn.fw.hermes.service.data.MessageHistoryService; | |
15 | -import cn.fw.hermes.service.emqx.MqttService; | |
16 | -import cn.fw.hermes.service.mq.MessageProducer; | |
17 | -import lombok.RequiredArgsConstructor; | |
18 | -import lombok.extern.slf4j.Slf4j; | |
19 | -import org.apache.commons.lang3.tuple.Pair; | |
20 | -import org.springframework.stereotype.Service; | |
21 | -import org.springframework.transaction.annotation.Transactional; | |
22 | -import org.springframework.util.CollectionUtils; | |
23 | - | |
24 | -import java.time.LocalDate; | |
25 | -import java.time.LocalDateTime; | |
26 | -import java.util.Date; | |
27 | -import java.util.List; | |
28 | -import java.util.Objects; | |
29 | -import java.util.stream.Collectors; | |
30 | - | |
31 | -/** | |
32 | - * 消息发送服务 | |
33 | - * | |
34 | - * @author : kurisu | |
35 | - * @version : 2.0 | |
36 | - * @desc : 消息发送服务 | |
37 | - * @date : 2023-07-21 15:11 | |
38 | - */ | |
39 | -@RequiredArgsConstructor | |
40 | -@Service | |
41 | -@Slf4j | |
42 | -public class MessageSender { | |
43 | - private final MessageHistoryService messageHistoryService; | |
44 | - private final MessageDataService messageDataService; | |
45 | - private final MqttService mqttService; | |
46 | - private final MessageProducer messageProducer; | |
47 | - private final XgPushService xgPushService; | |
48 | - | |
49 | - @Transactional(rollbackFor = Exception.class) | |
50 | - public void sendMsg(Long messageId) { | |
51 | - MessageHistory history = messageHistoryService.getById(messageId); | |
52 | - if (Objects.isNull(history)) { | |
53 | - return; | |
54 | - } | |
55 | - if (!MsgStatusEnum.WAITING.equals(history.getMsgStatus())) { | |
56 | - return; | |
57 | - } | |
58 | - List<MessageData> dataList = messageDataService.queryDataByMsgId(history.getId()); | |
59 | - if (CollectionUtils.isEmpty(dataList)) { | |
60 | - return; | |
61 | - } | |
62 | - Pair<MsgStatusEnum, String> pair = sendMsg(history, dataList); | |
63 | - if (Objects.isNull(pair) || MsgStatusEnum.UPLOAD.equals(pair.getLeft())) { | |
64 | - return; | |
65 | - } | |
66 | - if (Boolean.TRUE.equals(history.getNeedResult())) { | |
67 | - MessageV2Result result = new MessageV2Result(); | |
68 | - result.setMessageId(history.getId()); | |
69 | - result.setMsgState(MsgState.FAIL.getValue()); | |
70 | - result.setMsgStateDesc(history.getMsgStatusDesc()); | |
71 | - result.setResultTime(DateUtil.toDate(LocalDateTime.now())); | |
72 | - messageProducer.send(result); | |
73 | - } | |
74 | - } | |
75 | - | |
76 | - @Transactional(rollbackFor = Exception.class) | |
77 | - public Pair<MsgStatusEnum, String> sendMsg(MessageHistory history, List<MessageData> dataList) { | |
78 | - history.setSendTime(LocalDateTime.now()); | |
79 | - history.setSendDay(LocalDate.now()); | |
80 | - history.setCreateTime(new Date()); | |
81 | - final Message msg = Message.with(history); | |
82 | - List<MsgElement> list = dataList.stream().map(r -> this.genElement(r, msg)).collect(Collectors.toList()); | |
83 | - msg.setMsgBody(list); | |
84 | - List<String> msgTopics = history.getMsgTopic(); | |
85 | - Pair<Boolean, String> pair = mqttService.senMsg(msgTopics, msg); | |
86 | - if (Objects.isNull(pair)) { | |
87 | - return null; | |
88 | - } | |
89 | - boolean isSuccess = Boolean.TRUE.equals(pair.getKey()); | |
90 | - String desc = pair.getValue(); | |
91 | - history.setMsgStatus(MsgStatusEnum.UPLOAD); | |
92 | - history.setMsgStatusDesc(desc); | |
93 | - if (!isSuccess) { | |
94 | - history.setMsgStatus(MsgStatusEnum.FAIL); | |
95 | - history.setSendSuccessTime(LocalDateTime.now()); | |
96 | - } | |
97 | - messageHistoryService.saveOrUpdate(history); | |
98 | - return Pair.of(history.getMsgStatus(), desc); | |
99 | - } | |
100 | - | |
101 | - private MsgElement genElement(MessageData msgData, Message msg) { | |
102 | - MsgTypeEnum msgTypeEnum = msgData.getType(); | |
103 | - switch (msgTypeEnum) { | |
104 | - case TEXT: | |
105 | - return TextMsg.generate(msgData.getMsgId(), msgData.getText()); | |
106 | - case IMAGE: | |
107 | - return ImageMsg.generate(msgData.getMsgId(), msgData.getImageUrl()); | |
108 | - case VOICE: | |
109 | - return VoiceMsg.generate(msgData.getMsgId(), msgData.getVoiceUrl(), msgData.getDuration()); | |
110 | - case VIDEO: | |
111 | - return VideoMsg.generate(msgData.getMsgId(), msgData.getDuration(), msgData.getVideoUrl()); | |
112 | - case EMOJI: | |
113 | - return EmojiMsg.generate(msgData.getMsgId(), msgData.getEmojiIndex()); | |
114 | - case LOCATION: | |
115 | - return LocationMsg.generate(msgData.getMsgId(), msgData.getText(), msgData.getLat(), msgData.getLng()); | |
116 | - case CUSTOM: | |
117 | - String data = msgData.getData(); | |
118 | - boolean isBackLog = data.indexOf(Constant.BACKLOG_MSG) > 0; | |
119 | - if (isBackLog) { | |
120 | - msg.setRemark(Constant.BACKLOG_MSG); | |
121 | - } | |
122 | - return CustomMsg.generate(msgData.getMsgId(), data); | |
123 | - default: | |
124 | - break; | |
125 | - } | |
126 | - return null; | |
127 | - } | |
128 | -} |
fw-hermes-service/src/main/kotlin/cn/fw/hermes/service/biz/MessageSender.kt
0 → 100644
1 | +package cn.fw.hermes.service.biz | |
2 | + | |
3 | +import cn.fw.hermes.common.constant.Constant | |
4 | +import cn.fw.hermes.common.utils.DateUtil | |
5 | +import cn.fw.hermes.domain.db.MessageData | |
6 | +import cn.fw.hermes.domain.db.MessageHistory | |
7 | +import cn.fw.hermes.domain.enums.AccountTypeEnum | |
8 | +import cn.fw.hermes.domain.enums.MsgStatusEnum | |
9 | +import cn.fw.hermes.domain.enums.MsgTypeEnum | |
10 | +import cn.fw.hermes.domain.enums.PlatformTypeEnum | |
11 | +import cn.fw.hermes.domain.mqtt.Message | |
12 | +import cn.fw.hermes.domain.mqtt.msgbody.* | |
13 | +import cn.fw.hermes.sdk.v2.enums.MsgState | |
14 | +import cn.fw.hermes.sdk.v2.result.MessageV2Result | |
15 | +import cn.fw.hermes.service.data.DisturbSettingService | |
16 | +import cn.fw.hermes.service.data.MessageDataService | |
17 | +import cn.fw.hermes.service.data.MessageHistoryService | |
18 | +import cn.fw.hermes.service.data.SysPlatformService | |
19 | +import cn.fw.hermes.service.emqx.MqttService | |
20 | +import cn.fw.hermes.service.mq.MessageProducer | |
21 | +import org.apache.commons.lang3.tuple.Pair | |
22 | +import org.springframework.stereotype.Service | |
23 | +import org.springframework.transaction.annotation.Transactional | |
24 | +import org.springframework.util.CollectionUtils | |
25 | +import java.time.LocalDate | |
26 | +import java.time.LocalDateTime | |
27 | +import java.time.LocalTime | |
28 | +import java.time.ZoneOffset | |
29 | +import java.util.* | |
30 | +import java.util.stream.Collectors | |
31 | + | |
32 | +/** | |
33 | + * 消息发送服务 | |
34 | + * | |
35 | + * @author : kurisu | |
36 | + * @version : 2.0 | |
37 | + * @desc : 消息发送服务 | |
38 | + * @date : 2023-07-21 15:11 | |
39 | + */ | |
40 | +@Service | |
41 | +class MessageSender( | |
42 | + private val messageHistoryService: MessageHistoryService, | |
43 | + private val messageDataService: MessageDataService, | |
44 | + private val mqttService: MqttService, | |
45 | + private val messageProducer: MessageProducer, | |
46 | + private val xgPushService: XgPushService, | |
47 | + private val sysPlatformService: SysPlatformService, | |
48 | + private val disturbSettingService: DisturbSettingService | |
49 | +) { | |
50 | + | |
51 | + @Transactional(rollbackFor = [Exception::class]) | |
52 | + fun sendMsg(messageId: Long?) { | |
53 | + val history = messageHistoryService.getById(messageId) | |
54 | + history?.takeIf { MsgStatusEnum.WAITING != it.msgStatus }?.run { | |
55 | + val dataList = messageDataService.queryDataByMsgId(history.id) | |
56 | + if (CollectionUtils.isEmpty(dataList)) { | |
57 | + return | |
58 | + } | |
59 | + val pair = sendMsg(history, dataList) | |
60 | + if (Objects.isNull(pair) || MsgStatusEnum.UPLOAD == pair?.left) { | |
61 | + return | |
62 | + } | |
63 | + if (history.needResult == true) { | |
64 | + val result = MessageV2Result() | |
65 | + result.setMessageId(history.id) | |
66 | + result.setMsgState(MsgState.FAIL.value) | |
67 | + result.setMsgStateDesc(history.msgStatusDesc) | |
68 | + result.setResultTime(DateUtil.toDate(LocalDateTime.now())) | |
69 | + messageProducer.send(result) | |
70 | + } | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + @Transactional(rollbackFor = [Exception::class]) | |
75 | + fun sendMsg(history: MessageHistory, dataList: List<MessageData>): Pair<MsgStatusEnum, String>? { | |
76 | + val xgTodo = history.xgTodo | |
77 | + val userId = history.toAccount.toLong() | |
78 | + val platformCode = sysPlatformService.queryPlatforms().find { it.platformType == PlatformTypeEnum.APP }?.run { platformCode } ?: Constant.INVALID_TOKEN | |
79 | + val userDisturb = disturbSettingService.queryByUserPlatform(userId, platformCode) | |
80 | + val useMqtt = userDisturb?.takeIf { it.enabled == true }?.run { this@MessageSender.isTimeInRange(startTime, endTime) } ?: false | |
81 | + history.setSendTime(LocalDateTime.now()) | |
82 | + history.setSendDay(LocalDate.now()) | |
83 | + history.setCreateTime(Date()) | |
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) { | |
96 | + history.setMsgStatus(MsgStatusEnum.FAIL) | |
97 | + history.setSendSuccessTime(LocalDateTime.now()) | |
98 | + } | |
99 | + messageHistoryService.saveOrUpdate(history) | |
100 | + Pair.of(history.msgStatus, desc) | |
101 | + } | |
102 | + } | |
103 | + | |
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 { | |
112 | + history.setMsgStatus(MsgStatusEnum.FAIL) | |
113 | + history.setMsgStatusDesc("$first:$second") | |
114 | + } | |
115 | + messageHistoryService.saveOrUpdate(history) | |
116 | + | |
117 | + Pair.of(history.msgStatus, history.msgStatusDesc) | |
118 | + } | |
119 | + } | |
120 | + | |
121 | + private fun genElement(msgData: MessageData, msg: Message): MsgElement? { | |
122 | + val msgTypeEnum = msgData.type | |
123 | + when (msgTypeEnum) { | |
124 | + MsgTypeEnum.TEXT -> return TextMsg.generate(msgData.msgId, msgData.text) | |
125 | + MsgTypeEnum.IMAGE -> return ImageMsg.generate(msgData.msgId, msgData.imageUrl) | |
126 | + MsgTypeEnum.VOICE -> return VoiceMsg.generate(msgData.msgId, msgData.voiceUrl, msgData.duration) | |
127 | + MsgTypeEnum.VIDEO -> return VideoMsg.generate(msgData.msgId, msgData.duration, msgData.videoUrl) | |
128 | + MsgTypeEnum.EMOJI -> return EmojiMsg.generate(msgData.msgId, msgData.emojiIndex) | |
129 | + MsgTypeEnum.LOCATION -> return LocationMsg.generate(msgData.msgId, msgData.text, msgData.lat, msgData.lng) | |
130 | + MsgTypeEnum.CUSTOM -> { | |
131 | + val data = msgData.data | |
132 | + val isBackLog = data.indexOf(Constant.BACKLOG_MSG) > 0 | |
133 | + if (isBackLog) { | |
134 | + msg.remark = Constant.BACKLOG_MSG | |
135 | + } | |
136 | + return CustomMsg.generate(msgData.msgId, data) | |
137 | + } | |
138 | + | |
139 | + else -> {} | |
140 | + } | |
141 | + return null | |
142 | + } | |
143 | + | |
144 | + private fun isTimeInRange(startTime: LocalTime, endTime: LocalTime): Boolean { | |
145 | + val currentTime = LocalTime.now() | |
146 | + if (endTime.isBefore(startTime)) { | |
147 | + return !currentTime.isBefore(startTime) || currentTime.isBefore(endTime) | |
148 | + } | |
149 | + return currentTime.isAfter(startTime) && currentTime.isBefore(endTime) | |
150 | + } | |
151 | + | |
152 | + private fun MessageHistory.toMsg(): Message { | |
153 | + val msg = Message() | |
154 | + msg.msgId = this.id | |
155 | + msg.msgSummary = this.msgSummary | |
156 | + msg.sender = this.fromAccount | |
157 | + msg.receiver = this.toAccount | |
158 | + msg.sendTimestamp = this.sendTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() | |
159 | + msg.msgTimestamp = this.createTime.time | |
160 | + return msg | |
161 | + } | |
162 | +} | ... | ... |
fw-hermes-service/src/main/kotlin/cn/fw/hermes/service/biz/MsgPrepareBizService.kt
... | ... | @@ -80,7 +80,7 @@ class MsgPrepareBizService( |
80 | 80 | } |
81 | 81 | val result = MessageV2Result() |
82 | 82 | result.setMessageId(dto.id) |
83 | - val msgState = BeanTransfer.trans2SdkMsgState(pair.left) | |
83 | + val msgState = BeanTransfer.trans2SdkMsgState(pair!!.left) | |
84 | 84 | result.setMsgState(msgState.value) |
85 | 85 | result.setMsgStateDesc(pair.value) |
86 | 86 | result.setResultTime(DateUtil.toDate(LocalDateTime.now())) | ... | ... |
fw-hermes-service/src/main/kotlin/cn/fw/hermes/service/biz/XgPushService.kt
... | ... | @@ -77,7 +77,7 @@ class XgPushService( |
77 | 77 | |
78 | 78 | fun sendMsg(userId: Long, accountType: AccountTypeEnum): Pair<Int, String> { |
79 | 79 | val xgToken = getUserToken(userId, accountType) |
80 | - if (Constant.inValidToken == xgToken) { | |
80 | + if (Constant.INVALID_TOKEN == xgToken) { | |
81 | 81 | return Pair(-1, "") |
82 | 82 | } |
83 | 83 | val pushAppRequest = PushAppRequest() |
... | ... | @@ -107,9 +107,9 @@ class XgPushService( |
107 | 107 | return Pair(code, if (code == 0) pushId else errMsg) |
108 | 108 | } |
109 | 109 | |
110 | - fun sendData(userId: Long, accountType: AccountTypeEnum) { | |
110 | + fun sendDebugData(userId: Long, accountType: AccountTypeEnum) { | |
111 | 111 | val xgToken = getUserToken(userId, accountType) |
112 | - BV.isFalse(Constant.inValidToken == xgToken) { | |
112 | + BV.isFalse(Constant.INVALID_TOKEN == xgToken) { | |
113 | 113 | "用户设备未找到" |
114 | 114 | } |
115 | 115 | val pushAppRequest = PushAppRequest() |
... | ... | @@ -135,7 +135,7 @@ class XgPushService( |
135 | 135 | private fun getUserToken(userId: Long, accountType: AccountTypeEnum): String { |
136 | 136 | val cacheKey = "${keyPrefix}:${accountType.name}" |
137 | 137 | val hashOps = stringRedisTemplate.boundHashOps<String, String>(cacheKey) |
138 | - return hashOps.get(userId.toString()) ?: hermesService.queryByUserId(userId, accountType)?.xgToken ?: Constant.inValidToken | |
138 | + return hashOps.get(userId.toString()) ?: hermesService.queryByUserId(userId, accountType)?.xgToken ?: Constant.INVALID_TOKEN | |
139 | 139 | } |
140 | 140 | |
141 | 141 | private fun clearTokenAccount(token: String, account: String) { |
... | ... | @@ -166,7 +166,7 @@ class XgPushService( |
166 | 166 | if (list.isNullOrEmpty()) { |
167 | 167 | return listOf() |
168 | 168 | } |
169 | - list.forEach { it.xgToken = Constant.inValidToken } | |
169 | + list.forEach { it.xgToken = Constant.INVALID_TOKEN } | |
170 | 170 | hermesService.updateBatchById(list) |
171 | 171 | return list.map(Hermes::getUserId) |
172 | 172 | } | ... | ... |
fw-hermes-service/src/main/java/cn/fw/hermes/service/emqx/MqttService.kt renamed to fw-hermes-service/src/main/kotlin/cn/fw/hermes/service/emqx/MqttService.kt
... | ... | @@ -10,7 +10,6 @@ import cn.fw.hermes.domain.mqtt.UpdateMessage |
10 | 10 | import cn.fw.hermes.service.data.MessageHistoryService |
11 | 11 | import cn.fw.hermes.service.property.MqttProperty |
12 | 12 | import cn.hutool.json.JSONUtil |
13 | -import lombok.extern.slf4j.Slf4j | |
14 | 13 | import org.apache.commons.lang3.tuple.MutablePair |
15 | 14 | import org.apache.commons.lang3.tuple.Pair |
16 | 15 | import org.eclipse.paho.client.mqttv3.* |
... | ... | @@ -28,7 +27,6 @@ import java.util.concurrent.atomic.AtomicBoolean |
28 | 27 | * @desc : mqtt服务 |
29 | 28 | * @date : 2023-07-20 17:46 |
30 | 29 | */ |
31 | -@Slf4j | |
32 | 30 | @Service |
33 | 31 | class MqttService( |
34 | 32 | private val mqttProperty: MqttProperty, | ... | ... |