Commit 6c0eab53f2c552a66a6dceda5901fde9a6e8ea7b
Merge remote-tracking branch 'origin/test'
Showing
5 changed files
with
88 additions
and
2 deletions
fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/CustomerInitClueMapper.kt
... | ... | @@ -2,6 +2,8 @@ package cn.fw.valhalla.dao.mapper |
2 | 2 | |
3 | 3 | import cn.fw.valhalla.domain.db.ipt.CustomerInitClue |
4 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper |
5 | +import org.apache.ibatis.annotations.Param | |
6 | +import org.apache.ibatis.annotations.Select | |
5 | 7 | import org.springframework.stereotype.Repository |
6 | 8 | |
7 | 9 | /** |
... | ... | @@ -13,4 +15,13 @@ import org.springframework.stereotype.Repository |
13 | 15 | * @date : 2024-03-27 17:01 |
14 | 16 | */ |
15 | 17 | @Repository |
16 | -interface CustomerInitClueMapper : BaseMapper<CustomerInitClue> | |
17 | 18 | \ No newline at end of file |
19 | +interface CustomerInitClueMapper : BaseMapper<CustomerInitClue> { | |
20 | + @Select( | |
21 | + "SELECT t1.id FROM customer_init_clue t1" + | |
22 | + " inner join customer t2 on t1.vin = t2.frame_no " + | |
23 | + " where t2.group_id=#{groupId}" + | |
24 | + " and t1.group_id=#{groupId}" + | |
25 | + " and t1.yn=1 and t2.yn=1" | |
26 | + ) | |
27 | + fun queryTransferredCustomer(@Param("groupId") groupId: Long): List<Long> | |
28 | +} | |
18 | 29 | \ No newline at end of file | ... | ... |
fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/CallHistoryTask.kt
... | ... | @@ -106,4 +106,15 @@ class CallHistoryTask( |
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
109 | + | |
110 | + | |
111 | + @Scheduled(initialDelay = 1000 * 30, fixedRate = 1000 * 60 * 5) | |
112 | + fun cacheTransferInitClue() { | |
113 | + customerInitClueBizService.queryTransferredCustomer() | |
114 | + } | |
115 | + | |
116 | + @Scheduled(initialDelay = 1000 * 30, fixedRate = 1000 * 60) | |
117 | + fun dealTransferInitClue() { | |
118 | + customerInitClueBizService.dealClue() | |
119 | + } | |
109 | 120 | } |
110 | 121 | \ No newline at end of file | ... | ... |
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/ipt/CustomerInitClueBizService.kt
... | ... | @@ -15,6 +15,10 @@ import cn.fw.valhalla.rpc.pstn.PstnRpcService |
15 | 15 | import cn.fw.valhalla.service.data.CustomerInitClueCallLogService |
16 | 16 | import cn.fw.valhalla.service.data.CustomerInitClueService |
17 | 17 | import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper |
18 | +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper | |
19 | +import kotlinx.coroutines.* | |
20 | +import org.springframework.beans.factory.annotation.Value | |
21 | +import org.springframework.data.redis.core.StringRedisTemplate | |
18 | 22 | import org.springframework.stereotype.Service |
19 | 23 | import org.springframework.transaction.annotation.Transactional |
20 | 24 | import java.util.* |
... | ... | @@ -34,7 +38,10 @@ class CustomerInitClueBizService( |
34 | 38 | private val customerInitClueCallLogService: CustomerInitClueCallLogService, |
35 | 39 | private val oopService: OopService, |
36 | 40 | private val memberRpcService: MemberRpcService, |
37 | - private val pstnRpcService: PstnRpcService | |
41 | + private val pstnRpcService: PstnRpcService, | |
42 | + private val stringRedisTemplate: StringRedisTemplate, | |
43 | + @Value("\${spring.cache.custom.global-prefix}:init-clue:transferred") | |
44 | + private val initTransferredKey: String | |
38 | 45 | ) { |
39 | 46 | /** |
40 | 47 | * 查询池子数据 |
... | ... | @@ -135,6 +142,51 @@ class CustomerInitClueBizService( |
135 | 142 | customerInitClueCallLogService.updateById(callLog.copy(recording = it)) |
136 | 143 | } |
137 | 144 | } |
145 | + | |
146 | + /** | |
147 | + * 缓存已转移线索id | |
148 | + */ | |
149 | + fun queryTransferredCustomer() { | |
150 | + val groupIds = oopService.allGroup() | |
151 | + if (groupIds.isNullOrEmpty()) { | |
152 | + return | |
153 | + } | |
154 | + groupIds.forEach { | |
155 | + CoroutineScope(Dispatchers.IO).launch { | |
156 | + val clueIds = customerInitClueService.queryTransferredCustomer(it.id) | |
157 | + if (clueIds.isNotEmpty()) { | |
158 | + val key = "$initTransferredKey:${it.id}" | |
159 | + stringRedisTemplate.opsForSet().add(key, *clueIds.map { c -> c.toString() }.toTypedArray()) | |
160 | + } | |
161 | + } | |
162 | + } | |
163 | + } | |
164 | + | |
165 | + fun dealClue() { | |
166 | + val groupIds = oopService.allGroup() | |
167 | + if (groupIds.isNullOrEmpty()) { | |
168 | + return | |
169 | + } | |
170 | + groupIds.forEach { | |
171 | + CoroutineScope(Dispatchers.IO).launch { | |
172 | + val key = "$initTransferredKey:${it.id}" | |
173 | + val idList = mutableSetOf<Long>() | |
174 | + var idStr = stringRedisTemplate.opsForSet().pop(key) | |
175 | + while (idStr != null) { | |
176 | + idList.add(idStr.toLong()) | |
177 | + idStr = stringRedisTemplate.opsForSet().pop(key) | |
178 | + } | |
179 | + if (idList.isNotEmpty()) { | |
180 | + customerInitClueService.update( | |
181 | + KtUpdateWrapper(CustomerInitClue::class.java) | |
182 | + .set(CustomerInitClue::yn, false) | |
183 | + .eq(CustomerInitClue::yn, true) | |
184 | + .`in`(CustomerInitClue::id, idList) | |
185 | + ) | |
186 | + } | |
187 | + } | |
188 | + } | |
189 | + } | |
138 | 190 | } |
139 | 191 | |
140 | 192 | ... | ... |
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/CustomerInitClueService.kt
... | ... | @@ -12,4 +12,8 @@ import com.baomidou.mybatisplus.extension.service.IService |
12 | 12 | * @date : 2024-03-27 17:03 |
13 | 13 | */ |
14 | 14 | interface CustomerInitClueService : IService<CustomerInitClue> { |
15 | + /** | |
16 | + * 查询已转移线索 | |
17 | + */ | |
18 | + fun queryTransferredCustomer(groupId: Long?): List<Long> | |
15 | 19 | } |
16 | 20 | \ No newline at end of file | ... | ... |
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/CustomerInitClueServiceImpl.kt
... | ... | @@ -16,4 +16,12 @@ import org.springframework.stereotype.Service |
16 | 16 | */ |
17 | 17 | @Service |
18 | 18 | class CustomerInitClueServiceImpl : ServiceImpl<CustomerInitClueMapper, CustomerInitClue>(), CustomerInitClueService { |
19 | + /** | |
20 | + * 查询已转移线索 | |
21 | + */ | |
22 | + override fun queryTransferredCustomer(groupId: Long?): List<Long> { | |
23 | + return groupId?.let { | |
24 | + baseMapper.queryTransferredCustomer(groupId) | |
25 | + } ?: listOf() | |
26 | + } | |
19 | 27 | } |
20 | 28 | \ No newline at end of file | ... | ... |