feat/multi-channel-framework [AC-INIT]合并功能代码 #12

Merged
MerCry merged 37 commits from feat/multi-channel-framework into main 2026-02-24 03:55:00 +00:00
4 changed files with 34 additions and 4 deletions
Showing only changes of commit a8d7474338 - Show all commits

View File

@ -166,15 +166,15 @@ last_updated: "2026-02-24"
- [x] 幂等性检查 - [x] 幂等性检查
### TASK-022: 重构 MessageProcessService ### TASK-022: 重构 MessageProcessService
- **状态**: ⏳ 待开始 - **状态**: ✅ 已完成
- **优先级**: P0 - **优先级**: P0
- **关联 AC**: AC-MCA-08 - **关联 AC**: AC-MCA-08
- **描述**: 将现有 MessageProcessService 逻辑迁移到 MessageRouterServiceImpl - **描述**: 将现有 MessageProcessService 逻辑迁移到 MessageRouterServiceImpl
- **产出物**: - **产出物**:
- `src/main/java/com/wecom/robot/service/MessageProcessService.java` 更新或删除 - `src/main/java/com/wecom/robot/service/MessageProcessService.java` 更新或删除
- **验收标准**: - **验收标准**:
- [ ] 现有功能保持兼容 - [x] 现有功能保持兼容
- [ ] 微信专属逻辑移至 WeChatAdapter - [x] 微信专属逻辑移至 WeChatAdapter
### TASK-023: 更新 SessionManagerService ### TASK-023: 更新 SessionManagerService
- **状态**: ⏳ 待开始 - **状态**: ⏳ 待开始

View File

@ -22,6 +22,8 @@ public class Session implements Serializable {
private String kfId; private String kfId;
private String channelType;
private String status; private String status;
private Integer wxServiceState; private Integer wxServiceState;
@ -39,4 +41,8 @@ public class Session implements Serializable {
public static final String STATUS_PENDING = "PENDING"; public static final String STATUS_PENDING = "PENDING";
public static final String STATUS_MANUAL = "MANUAL"; public static final String STATUS_MANUAL = "MANUAL";
public static final String STATUS_CLOSED = "CLOSED"; public static final String STATUS_CLOSED = "CLOSED";
public static final String CHANNEL_WECHAT = "wechat";
public static final String CHANNEL_DOUYIN = "douyin";
public static final String CHANNEL_JD = "jd";
} }

View File

@ -17,6 +17,11 @@ import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/**
* 会话管理服务
*
* <p>关联 AC: [AC-MCA-11] 会话管理, [AC-MCA-12] 渠道类型支持
*/
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@ -31,6 +36,10 @@ public class SessionManagerService {
private final StringRedisTemplate redisTemplate; private final StringRedisTemplate redisTemplate;
public Session getOrCreateSession(String customerId, String kfId) { public Session getOrCreateSession(String customerId, String kfId) {
return getOrCreateSession(customerId, kfId, Session.CHANNEL_WECHAT);
}
public Session getOrCreateSession(String customerId, String kfId, String channelType) {
LambdaQueryWrapper<Session> query = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Session> query = new LambdaQueryWrapper<>();
query.eq(Session::getCustomerId, customerId) query.eq(Session::getCustomerId, customerId)
.eq(Session::getKfId, kfId) .eq(Session::getKfId, kfId)
@ -44,6 +53,7 @@ public class SessionManagerService {
session.setSessionId(generateSessionId(customerId, kfId)); session.setSessionId(generateSessionId(customerId, kfId));
session.setCustomerId(customerId); session.setCustomerId(customerId);
session.setKfId(kfId); session.setKfId(kfId);
session.setChannelType(channelType != null ? channelType : Session.CHANNEL_WECHAT);
session.setStatus(Session.STATUS_AI); session.setStatus(Session.STATUS_AI);
session.setWxServiceState(0); session.setWxServiceState(0);
session.setCreatedAt(LocalDateTime.now()); session.setCreatedAt(LocalDateTime.now());
@ -51,6 +61,8 @@ public class SessionManagerService {
sessionMapper.insert(session); sessionMapper.insert(session);
cacheSessionStatus(session.getSessionId(), Session.STATUS_AI); cacheSessionStatus(session.getSessionId(), Session.STATUS_AI);
log.info("[AC-MCA-11] 创建新会话: sessionId={}, channelType={}",
session.getSessionId(), session.getChannelType());
} }
return session; return session;
@ -199,6 +211,17 @@ public class SessionManagerService {
return sessionMapper.selectList(query); return sessionMapper.selectList(query);
} }
public List<Session> getSessionsByChannelType(String channelType, String status, int limit) {
LambdaQueryWrapper<Session> query = new LambdaQueryWrapper<>();
query.eq(Session::getChannelType, channelType);
if (status != null && !status.isEmpty() && !"all".equals(status)) {
query.eq(Session::getStatus, status);
}
query.orderByDesc(Session::getUpdatedAt);
query.last("LIMIT " + limit);
return sessionMapper.selectList(query);
}
public List<Session> getAllSessions(int limit) { public List<Session> getAllSessions(int limit) {
LambdaQueryWrapper<Session> query = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Session> query = new LambdaQueryWrapper<>();
query.orderByDesc(Session::getUpdatedAt); query.orderByDesc(Session::getUpdatedAt);

View File

@ -160,7 +160,8 @@ public class MessageRouterServiceImpl implements MessageRouterService {
private Session getOrCreateSession(InboundMessage message) { private Session getOrCreateSession(InboundMessage message) {
return sessionManagerService.getOrCreateSession( return sessionManagerService.getOrCreateSession(
message.getCustomerId(), message.getCustomerId(),
message.getKfId() message.getKfId(),
message.getChannelType()
); );
} }