Commit 9ae235a84c567c72f38d007310422e28bdb96842
1 parent
a1a63535
feat(*): 重构消息中心
- 重构消息中心
Showing
3 changed files
with
13 additions
and
22 deletions
fw-hestia-server/src/main/java/cn/fw/hestia/server/task/SendMessageTask.kt
... | ... | @@ -6,7 +6,6 @@ import cn.fw.hestia.domain.db.MessageHistory |
6 | 6 | import cn.fw.hestia.domain.enums.MessageStateEnum |
7 | 7 | import cn.fw.hestia.service.buz.MessageCenterBizService |
8 | 8 | import cn.fw.hestia.service.data.MessageHistoryService |
9 | -import com.baomidou.mybatisplus.core.toolkit.Wrappers | |
10 | 9 | import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper |
11 | 10 | import org.springframework.beans.factory.annotation.Value |
12 | 11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty |
... | ... | @@ -14,14 +13,9 @@ import org.springframework.data.redis.core.StringRedisTemplate |
14 | 13 | import org.springframework.scheduling.annotation.Scheduled |
15 | 14 | import org.springframework.stereotype.Component |
16 | 15 | import org.springframework.util.CollectionUtils |
17 | -import java.lang.Boolean | |
18 | 16 | import java.time.LocalDateTime |
19 | 17 | import java.util.* |
20 | 18 | import java.util.concurrent.CompletableFuture |
21 | -import kotlin.Long | |
22 | -import kotlin.String | |
23 | -import kotlin.also | |
24 | -import kotlin.let | |
25 | 19 | |
26 | 20 | /** |
27 | 21 | * @author : kurisu |
... | ... | @@ -34,10 +28,9 @@ import kotlin.let |
34 | 28 | class SendMessageTask( |
35 | 29 | private val messageCenterBizService: MessageCenterBizService, |
36 | 30 | private val messageHistoryService: MessageHistoryService, |
37 | - private val stringRedisTemplate: StringRedisTemplate | |
31 | + private val stringRedisTemplate: StringRedisTemplate, | |
32 | + @Value("\${spring.cache.custom.global-prefix}:data:clear") private val dataClearKey: String | |
38 | 33 | ) { |
39 | - @Value("\${spring.cache.custom.global-prefix}:data:clear") | |
40 | - private var dataClearKey: String? = null | |
41 | 34 | |
42 | 35 | /** |
43 | 36 | * 发送模板消息 |
... | ... | @@ -47,7 +40,7 @@ class SendMessageTask( |
47 | 40 | val list = messageHistoryService.list( |
48 | 41 | KtQueryWrapper(MessageHistory::class.java) |
49 | 42 | .eq(MessageHistory::state, MessageStateEnum.MADA) |
50 | - .eq(MessageHistory::yn, Boolean.TRUE) | |
43 | + .eq(MessageHistory::yn, true) | |
51 | 44 | .lt(MessageHistory::frequency, MessageConstant.MAX_FREQUENCY) |
52 | 45 | .lt(MessageHistory::sendTime, Date()) |
53 | 46 | .last("limit 1000") |
... | ... | @@ -65,7 +58,7 @@ class SendMessageTask( |
65 | 58 | */ |
66 | 59 | @Scheduled(initialDelay = 1000 * 10, fixedRate = 1000 * 10) |
67 | 60 | fun cacheOldData() { |
68 | - val key: String = dataClearKey ?: "hestia:global:data:clear" | |
61 | + val key: String = dataClearKey | |
69 | 62 | val setOps = stringRedisTemplate.boundSetOps(key) |
70 | 63 | val list = messageHistoryService.list( |
71 | 64 | KtQueryWrapper(MessageHistory::class.java) |
... | ... | @@ -83,7 +76,7 @@ class SendMessageTask( |
83 | 76 | */ |
84 | 77 | @Scheduled(initialDelay = 1000 * 10, fixedRate = 1000 * 15) |
85 | 78 | fun clearOldData() { |
86 | - val key: String = dataClearKey ?: "hestia:global:data:clear" | |
79 | + val key: String = dataClearKey | |
87 | 80 | val setOps = stringRedisTemplate.boundSetOps(key) |
88 | 81 | var idStr: String? |
89 | 82 | while ((setOps.pop().also { idStr = it }) != null) { | ... | ... |
fw-hestia-service/src/main/java/cn/fw/hestia/component/SendMsgProducer.kt
... | ... | @@ -22,7 +22,7 @@ class SendMsgProducer(private val rocketMQTemplate: RocketMQTemplate) { |
22 | 22 | log.info("模板消息发送成功mq: body:[{}]", messageSendMq) |
23 | 23 | rocketMQTemplate.syncSend(MessageSendMq.TOPIC + ":*", messageSendMq) |
24 | 24 | } catch (e: Exception) { |
25 | - e.printStackTrace() | |
25 | + log.error("模板消息发送成功mq生成失败", e) | |
26 | 26 | } |
27 | 27 | } |
28 | 28 | } |
29 | 29 | \ No newline at end of file | ... | ... |
fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.kt
... | ... | @@ -24,7 +24,6 @@ import com.alibaba.fastjson.JSON |
24 | 24 | import com.alibaba.fastjson.JSONArray |
25 | 25 | import com.baomidou.mybatisplus.core.toolkit.Wrappers |
26 | 26 | import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper |
27 | -import lombok.Getter | |
28 | 27 | import org.springframework.beans.factory.annotation.Value |
29 | 28 | import org.springframework.cache.annotation.Cacheable |
30 | 29 | import org.springframework.data.redis.core.StringRedisTemplate |
... | ... | @@ -50,17 +49,16 @@ class MessageCenterBizService( |
50 | 49 | private val sendLogService: SendLogService, |
51 | 50 | private val sendMsgProducer: SendMsgProducer, |
52 | 51 | private val redisTemplate: StringRedisTemplate, |
53 | - private val settingProperty: SettingProperty | |
52 | + private val settingProperty: SettingProperty, | |
53 | + @Value("\${spring.cache.custom.global-prefix}:template:code") private val keyPrefix: String, | |
54 | + @Value("\${spring.cache.custom.global-prefix}:template:send:scene:") | |
55 | + private val prefix: String | |
54 | 56 | ) { |
55 | - @Value("\${spring.cache.custom.global-prefix}:template:code") | |
56 | - @Getter | |
57 | - private val keyPrefix: String? = null | |
58 | 57 | |
59 | - @Value("\${spring.cache.custom.global-prefix}:template:send:scene:") | |
60 | - private val sendDataPrefix: String? = null | |
58 | + private val sendDataPrefix: String | |
61 | 59 | get() { |
62 | 60 | val today = LocalDate.now().toString() |
63 | - return field + today | |
61 | + return prefix + today | |
64 | 62 | } |
65 | 63 | |
66 | 64 | /** |
... | ... | @@ -101,7 +99,7 @@ class MessageCenterBizService( |
101 | 99 | */ |
102 | 100 | @Transactional(rollbackFor = [Exception::class]) |
103 | 101 | fun sendMessage(history: MessageHistory) { |
104 | - val key = sendDataPrefix ?: return | |
102 | + val key = sendDataPrefix | |
105 | 103 | val setOps = redisTemplate.boundSetOps(key) |
106 | 104 | val seanceToken = history.id.toString() |
107 | 105 | if (java.lang.Boolean.TRUE == setOps.isMember(seanceToken)) { | ... | ... |