Commit 80457b73b2abd3464a31511958a9df8254c1f3f4

Authored by 张志伟
1 parent 6362192b

:fire: feat(*): 新增每次推送记录xgToken

- 新增每次推送记录xgToken
fw-hermes-domain/src/main/java/cn/fw/hermes/domain/db/MessageHistory.java
... ... @@ -45,6 +45,10 @@ public class MessageHistory {
45 45 */
46 46 private String xgId;
47 47 /**
  48 + * 本条消息推送的设备token
  49 + */
  50 + private String xgToken;
  51 + /**
48 52 * 消息的topic列表
49 53 */
50 54 @TableField(typeHandler = StringListTypeHandler.class)
... ...
fw-hermes-service/src/main/kotlin/cn/fw/hermes/service/biz/MessageSender.kt
... ... @@ -78,29 +78,28 @@ class MessageSender(
78 78 val platformCode = sysPlatformService.queryPlatforms().find { it.platformType == PlatformTypeEnum.APP }?.run { platformCode } ?: Constant.INVALID_TOKEN
79 79 val userDisturb = disturbSettingService.queryByUserPlatform(userId, platformCode)
80 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())
  81 + history.sendTime = LocalDateTime.now()
  82 + history.sendDay = LocalDate.now()
  83 + history.createTime = Date()
84 84 if (useMqtt || !xgTodo) {
85 85 return mqtSend(history, dataList)
86 86 }
87   -
88 87 return xgPushService.sendMsg(userId, AccountTypeEnum.B_USER).run {
89 88 if (first == -1) {
90 89 mqtSend(history, dataList)
91 90 } else {
92 91 val sendSuccess = first == 0
93   - history.setSendSuccessTime(LocalDateTime.now())
  92 + history.sendSuccessTime = LocalDateTime.now()
  93 + history.xgToken = second
94 94 if (sendSuccess) {
95   - history.setMsgStatus(MsgStatusEnum.SUCCESS)
96   - history.setMsgStatusDesc(Constant.SUCCESS_MSG)
97   - history.setXgId(second)
  95 + history.msgStatus = MsgStatusEnum.SUCCESS
  96 + history.msgStatusDesc = Constant.SUCCESS_MSG
  97 + history.xgId = third
98 98 } else {
99   - history.setMsgStatus(MsgStatusEnum.FAIL)
100   - history.setMsgStatusDesc("$first:$second")
  99 + history.msgStatus = MsgStatusEnum.FAIL
  100 + history.msgStatusDesc = "$first: $third"
101 101 }
102 102 messageHistoryService.saveOrUpdate(history)
103   -
104 103 Pair.of(history.msgStatus, history.msgStatusDesc)
105 104 }
106 105 }
... ... @@ -118,11 +117,13 @@ class MessageSender(
118 117 return pair?.let {
119 118 val isSuccess = true == it.key
120 119 val desc = it.value
121   - history.setMsgStatus(MsgStatusEnum.UPLOAD)
122   - history.setMsgStatusDesc(desc)
  120 + history.xgId = Constant.INVALID_TOKEN
  121 + history.xgToken = Constant.INVALID_TOKEN
  122 + history.msgStatus = MsgStatusEnum.UPLOAD
  123 + history.msgStatusDesc = desc
123 124 if (!isSuccess) {
124   - history.setMsgStatus(MsgStatusEnum.FAIL)
125   - history.setSendSuccessTime(LocalDateTime.now())
  125 + history.msgStatus = MsgStatusEnum.FAIL
  126 + history.sendSuccessTime = LocalDateTime.now()
126 127 }
127 128 messageHistoryService.saveOrUpdate(history)
128 129 Pair.of(history.msgStatus, desc)
... ...
fw-hermes-service/src/main/kotlin/cn/fw/hermes/service/biz/XgPushService.kt
... ... @@ -105,10 +105,10 @@ class XgPushService(
105 105 }
106 106 }
107 107  
108   - fun sendMsg(userId: Long, accountType: AccountTypeEnum): Pair<Int, String> {
  108 + fun sendMsg(userId: Long, accountType: AccountTypeEnum): Triple<Int, String, String> {
109 109 val xgToken = getUserToken(userId, accountType)
110 110 if (Constant.INVALID_TOKEN == xgToken) {
111   - return Pair(-1, "INVALID_TOKEN")
  111 + return Triple(-1, xgToken, "INVALID_TOKEN")
112 112 }
113 113 val pushAppRequest = PushAppRequest()
114 114 pushAppRequest.audience_type = AudienceType.token
... ... @@ -134,9 +134,8 @@ class XgPushService(
134 134 val pushRes = this.xingeApp.pushApp(pushAppRequest)
135 135 logInfo("给账号[{}]推送消息, 结果: {}", userId, pushRes)
136 136 val code = pushRes.getInt("ret_code")
137   - val pushId = pushRes.getString("push_id")
138   - val errMsg = pushRes.getString("err_msg")
139   - return Pair(code, if (code == 0) pushId else errMsg)
  137 + val third = if (code == 0) pushRes.getString("push_id") else pushRes.getString("err_msg")
  138 + return Triple(code, xgToken, third)
140 139 }
141 140  
142 141 private fun getUserToken(userId: Long, accountType: AccountTypeEnum): String {
... ...