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",
|
|
|
|
|
|
"""
|
|
|
|
|
|
学员联系数据暂时无法获取,不影响身份信息查询。
|
|
|
|
|
|
|
|
|
|
|
|
学员总数:暂未获取
|
|
|
|
|
|
今日新增:暂未获取
|
|
|
|
|
|
跟进成员数:暂未获取
|
2026-06-12 10:55:46 +08:00
|
|
|
|
统计管理:暂未获取
|
2026-06-12 10:51:54 +08:00
|
|
|
|
今日收款:暂未接入
|
|
|
|
|
|
""".trim(),
|
2026-06-12 10:55:46 +08:00
|
|
|
|
List.of("企业微信学员联系 API", "企业微信统计管理 API"),
|
2026-06-12 10:51:54 +08:00
|
|
|
|
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
|
2026-06-12 10:55:46 +08:00
|
|
|
|
今日咨询数:%d
|
2026-06-12 13:07:06 +08:00
|
|
|
|
今日沟通客户数:%d
|
|
|
|
|
|
今日沟通消息条数:%d
|
2026-06-12 10:55:46 +08:00
|
|
|
|
今日回复率:%s
|
|
|
|
|
|
平均首次回复时长:%s
|
|
|
|
|
|
今日负反馈数:%d
|
2026-06-12 10:40:13 +08:00
|
|
|
|
今日收款:暂未接入
|
2026-06-12 10:55:46 +08:00
|
|
|
|
""".formatted(
|
|
|
|
|
|
stats.totalStudents(),
|
|
|
|
|
|
stats.todayNewStudents(),
|
|
|
|
|
|
stats.followUserCount(),
|
|
|
|
|
|
stats.todayNewApplyCount(),
|
|
|
|
|
|
stats.todayChatCount(),
|
|
|
|
|
|
stats.todayMessageCount(),
|
|
|
|
|
|
percent(stats.todayReplyPercentage()),
|
|
|
|
|
|
seconds(stats.todayAvgReplySeconds()),
|
|
|
|
|
|
stats.todayNegativeFeedbackCount()
|
|
|
|
|
|
).trim(),
|
|
|
|
|
|
List.of("企业微信学员联系 API", "企业微信统计管理 API"),
|
2026-06-12 10:40:13 +08:00
|
|
|
|
Map.of(
|
|
|
|
|
|
"totalStudents", stats.totalStudents(),
|
|
|
|
|
|
"todayNewStudents", stats.todayNewStudents(),
|
2026-06-12 10:55:46 +08:00
|
|
|
|
"followUserCount", stats.followUserCount(),
|
|
|
|
|
|
"todayNewApplyCount", stats.todayNewApplyCount(),
|
|
|
|
|
|
"todayChatCount", stats.todayChatCount(),
|
|
|
|
|
|
"todayMessageCount", stats.todayMessageCount(),
|
|
|
|
|
|
"todayNegativeFeedbackCount", stats.todayNegativeFeedbackCount()
|
2026-06-12 10:40:13 +08:00
|
|
|
|
),
|
|
|
|
|
|
Instant.now()
|
2026-06-08 18:29:56 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-06-12 10:55:46 +08:00
|
|
|
|
|
|
|
|
|
|
private String percent(Integer value) {
|
|
|
|
|
|
return value == null ? "暂无数据" : value + "%";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String seconds(Integer value) {
|
|
|
|
|
|
return value == null ? "暂无数据" : value + "秒";
|
|
|
|
|
|
}
|
2026-06-08 18:29:56 +08:00
|
|
|
|
}
|