1
This commit is contained in:
@@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.jarvis.domain.WeComInboundTrace;
|
||||
import com.ruoyi.jarvis.domain.dto.WeComTestDataCleanRequest;
|
||||
import com.ruoyi.jarvis.service.IWeComInboundTraceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -43,4 +44,14 @@ public class WeComInboundTraceController extends BaseController {
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(weComInboundTraceService.deleteWeComInboundTraceByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理联调/测试数据:追踪表 + 可选 Redis 企微会话与 adhoc 队列
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:wecom:inboundTrace:remove')")
|
||||
@Log(title = "企微消息测试数据清理", businessType = BusinessType.CLEAN)
|
||||
@PostMapping("/cleanTestData")
|
||||
public AjaxResult cleanTestData(@RequestBody(required = false) WeComTestDataCleanRequest body) {
|
||||
return success(weComInboundTraceService.cleanTestData(body));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.ruoyi.jarvis.domain.dto;
|
||||
|
||||
/**
|
||||
* 企微联调/测试数据清理选项(默认全选)
|
||||
*/
|
||||
public class WeComTestDataCleanRequest {
|
||||
|
||||
private Boolean clearTraceTable = true;
|
||||
private Boolean clearWecomSessions = true;
|
||||
private Boolean clearAdhocQueue = true;
|
||||
|
||||
public Boolean getClearTraceTable() {
|
||||
return clearTraceTable;
|
||||
}
|
||||
|
||||
public void setClearTraceTable(Boolean clearTraceTable) {
|
||||
this.clearTraceTable = clearTraceTable;
|
||||
}
|
||||
|
||||
public Boolean getClearWecomSessions() {
|
||||
return clearWecomSessions;
|
||||
}
|
||||
|
||||
public void setClearWecomSessions(Boolean clearWecomSessions) {
|
||||
this.clearWecomSessions = clearWecomSessions;
|
||||
}
|
||||
|
||||
public Boolean getClearAdhocQueue() {
|
||||
return clearAdhocQueue;
|
||||
}
|
||||
|
||||
public void setClearAdhocQueue(Boolean clearAdhocQueue) {
|
||||
this.clearAdhocQueue = clearAdhocQueue;
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,6 @@ public interface WeComInboundTraceMapper {
|
||||
List<WeComInboundTrace> selectWeComInboundTraceList(WeComInboundTrace query);
|
||||
|
||||
int deleteWeComInboundTraceByIds(Long[] ids);
|
||||
|
||||
int deleteAllWeComInboundTrace();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ public interface ILogisticsService {
|
||||
* 定时任务内:依次弹出队列并调用 {@link #fetchLogisticsByShareLinkAndPush}。
|
||||
*/
|
||||
void drainPendingShareLinkQueue();
|
||||
|
||||
/** 测试清理:删除分享链待扫描队列键 */
|
||||
void clearAdhocPendingQueue();
|
||||
|
||||
/**
|
||||
* 检查订单是否已处理过(Redis中是否有运单号)
|
||||
|
||||
@@ -17,4 +17,7 @@ public interface IWeComChatSessionService {
|
||||
|
||||
/** @param wecomUserId 成员 UserID,同 FromUserName */
|
||||
void delete(String wecomUserId);
|
||||
|
||||
/** 测试清理:删除所有 interaction_state:wecom:* */
|
||||
int deleteAllWecomSessionsForTest();
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.ruoyi.jarvis.service;
|
||||
|
||||
import com.ruoyi.jarvis.domain.WeComInboundTrace;
|
||||
import com.ruoyi.jarvis.domain.dto.WeComInboundRequest;
|
||||
import com.ruoyi.jarvis.domain.dto.WeComTestDataCleanRequest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IWeComInboundTraceService {
|
||||
|
||||
@@ -14,4 +16,9 @@ public interface IWeComInboundTraceService {
|
||||
List<WeComInboundTrace> selectWeComInboundTraceList(WeComInboundTrace query);
|
||||
|
||||
int deleteWeComInboundTraceByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 清理联调/测试数据,选项见 {@link WeComTestDataCleanRequest}
|
||||
*/
|
||||
Map<String, Object> cleanTestData(WeComTestDataCleanRequest options);
|
||||
}
|
||||
|
||||
@@ -465,6 +465,12 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAdhocPendingQueue() {
|
||||
Boolean deleted = stringRedisTemplate.delete(REDIS_ADHOC_PENDING_QUEUE);
|
||||
logger.info("adhoc 待扫描队列已清理 key={} existed={}", REDIS_ADHOC_PENDING_QUEUE, Boolean.TRUE.equals(deleted));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fetchLogisticsByShareLinkAndPush(String trackingUrl, String remark, String touser) {
|
||||
if (!StringUtils.hasText(trackingUrl)) {
|
||||
|
||||
@@ -87,6 +87,22 @@ public class WeComChatSessionServiceImpl implements IWeComChatSessionService {
|
||||
stringRedisTemplate.delete(WeComConvention.sessionRedisKey(wecomUserId.trim()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteAllWecomSessionsForTest() {
|
||||
Set<String> keys = stringRedisTemplate.keys(WeComConvention.SESSION_REDIS_KEY_PREFIX + "*");
|
||||
if (keys == null || keys.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int n = 0;
|
||||
for (String key : keys) {
|
||||
if (key != null && stringRedisTemplate.delete(key)) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
log.info("企微会话测试清理完成 prefix={} deletedKeys={}", WeComConvention.SESSION_REDIS_KEY_PREFIX, n);
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参考 JDUtil#cleanUpTimeoutStates:按 lastInteractionTime 清理超长空闲会话(Redis TTL 与业务空闲均可生效)
|
||||
*/
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.ruoyi.jarvis.service.impl;
|
||||
import com.ruoyi.jarvis.domain.WeComInboundTrace;
|
||||
import com.ruoyi.jarvis.domain.dto.WeComChatSession;
|
||||
import com.ruoyi.jarvis.domain.dto.WeComInboundRequest;
|
||||
import com.ruoyi.jarvis.domain.dto.WeComTestDataCleanRequest;
|
||||
import com.ruoyi.jarvis.mapper.WeComInboundTraceMapper;
|
||||
import com.ruoyi.jarvis.service.IWeComChatSessionService;
|
||||
import com.ruoyi.jarvis.service.ILogisticsService;
|
||||
import com.ruoyi.jarvis.service.IWeComInboundTraceService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -13,7 +15,9 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class WeComInboundTraceServiceImpl implements IWeComInboundTraceService {
|
||||
@@ -70,4 +74,29 @@ public class WeComInboundTraceServiceImpl implements IWeComInboundTraceService {
|
||||
public int deleteWeComInboundTraceByIds(Long[] ids) {
|
||||
return weComInboundTraceMapper.deleteWeComInboundTraceByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> cleanTestData(WeComTestDataCleanRequest options) {
|
||||
if (options == null) {
|
||||
options = new WeComTestDataCleanRequest();
|
||||
}
|
||||
boolean trace = options.getClearTraceTable() == null || options.getClearTraceTable();
|
||||
boolean sessions = options.getClearWecomSessions() == null || options.getClearWecomSessions();
|
||||
boolean adhoc = options.getClearAdhocQueue() == null || options.getClearAdhocQueue();
|
||||
Map<String, Object> r = new LinkedHashMap<>();
|
||||
if (trace) {
|
||||
int n = weComInboundTraceMapper.deleteAllWeComInboundTrace();
|
||||
r.put("traceRowsDeleted", n);
|
||||
log.info("企微消息追踪表已清空 deletedRows={}", n);
|
||||
}
|
||||
if (sessions) {
|
||||
int n = weComChatSessionService.deleteAllWecomSessionsForTest();
|
||||
r.put("wecomSessionKeysDeleted", n);
|
||||
}
|
||||
if (adhoc) {
|
||||
logisticsService.clearAdhocPendingQueue();
|
||||
r.put("adhocQueueCleared", Boolean.TRUE);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,8 @@
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteAllWeComInboundTrace">
|
||||
delete from wecom_inbound_trace
|
||||
</delete>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user