2026-06-08 18:29:56 +08:00
|
|
|
|
package com.company.agentfoundation.agent.capability;
|
|
|
|
|
|
|
2026-06-12 10:40:13 +08:00
|
|
|
|
import com.company.agentfoundation.agent.AgentCapabilityResponse;
|
2026-06-08 18:29:56 +08:00
|
|
|
|
import com.company.agentfoundation.agent.AgentIntent;
|
2026-06-12 10:40:13 +08:00
|
|
|
|
import com.company.agentfoundation.agent.AgentRequestContext;
|
|
|
|
|
|
import com.company.agentfoundation.integration.wecom.WecomStudentContactStats;
|
|
|
|
|
|
import com.company.agentfoundation.integration.wecom.WecomStudentContactStatsService;
|
2026-06-08 18:29:56 +08:00
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
2026-06-12 10:40:13 +08:00
|
|
|
|
import java.time.Instant;
|
2026-06-08 18:29:56 +08:00
|
|
|
|
import java.util.List;
|
2026-06-12 10:40:13 +08:00
|
|
|
|
import java.util.Map;
|
2026-06-08 18:29:56 +08:00
|
|
|
|
|
|
|
|
|
|
@Component
|
2026-06-12 10:40:13 +08:00
|
|
|
|
public class CustomerDashboardDailyCapabilityHandler implements AgentCapabilityHandler {
|
|
|
|
|
|
private final WecomStudentContactStatsService studentContactStatsService;
|
|
|
|
|
|
|
|
|
|
|
|
public CustomerDashboardDailyCapabilityHandler(WecomStudentContactStatsService studentContactStatsService) {
|
|
|
|
|
|
this.studentContactStatsService = studentContactStatsService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public AgentIntent intent() {
|
|
|
|
|
|
return AgentIntent.CUSTOMER_DASHBOARD_DAILY;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public AgentCapabilityResponse handle(AgentRequestContext context) {
|
2026-06-12 10:51:54 +08:00
|
|
|
|
WecomStudentContactStats stats;
|
|
|
|
|
|
try {
|
|
|
|
|
|
stats = studentContactStatsService.fetchTodayStats();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
return new AgentCapabilityResponse(
|
|
|
|
|
|
intent().code(),
|
|
|
|
|
|
intent().title(),
|
|
|
|
|
|
intent().mcpGroup(),
|
|
|
|
|
|
"degraded",
|
|
|
|
|
|
"""
|
|
|
|
|
|
学员联系数据暂时无法获取,不影响身份信息查询。
|
|
|
|
|
|
|
|
|
|
|
|
学员总数:暂未获取
|
|
|
|
|
|
今日新增:暂未获取
|
|
|
|
|
|
跟进成员数:暂未获取
|
|
|
|
|
|
今日收款:暂未接入
|
|
|
|
|
|
""".trim(),
|
|
|
|
|
|
List.of("企业微信学员联系 API"),
|
|
|
|
|
|
Map.of("error", e.getMessage() == null ? "api forbidden" : e.getMessage()),
|
|
|
|
|
|
Instant.now()
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-12 10:40:13 +08:00
|
|
|
|
return new AgentCapabilityResponse(
|
|
|
|
|
|
intent().code(),
|
|
|
|
|
|
intent().title(),
|
|
|
|
|
|
intent().mcpGroup(),
|
|
|
|
|
|
"ready",
|
|
|
|
|
|
"""
|
|
|
|
|
|
学员联系数据已从企业微信实时获取。
|
|
|
|
|
|
|
|
|
|
|
|
学员总数:%d
|
|
|
|
|
|
今日新增:%d
|
|
|
|
|
|
跟进成员数:%d
|
|
|
|
|
|
今日收款:暂未接入
|
|
|
|
|
|
""".formatted(stats.totalStudents(), stats.todayNewStudents(), stats.followUserCount()).trim(),
|
|
|
|
|
|
List.of("企业微信学员联系 API"),
|
|
|
|
|
|
Map.of(
|
|
|
|
|
|
"totalStudents", stats.totalStudents(),
|
|
|
|
|
|
"todayNewStudents", stats.todayNewStudents(),
|
|
|
|
|
|
"followUserCount", stats.followUserCount()
|
|
|
|
|
|
),
|
|
|
|
|
|
Instant.now()
|
2026-06-08 18:29:56 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|