2026-07-22 14:56:59 +08:00
|
|
|
|
package com.company.agentfoundation.semantic.handler;
|
|
|
|
|
|
|
|
|
|
|
|
import com.company.agentfoundation.semantic.SemanticDateRangeResolver;
|
|
|
|
|
|
import com.company.agentfoundation.semantic.SemanticIntentHandler;
|
|
|
|
|
|
import com.company.agentfoundation.semantic.SemanticRecognition;
|
|
|
|
|
|
import com.company.agentfoundation.semantic.SemanticRequestContext;
|
|
|
|
|
|
import com.company.agentfoundation.teaching.report.LowHoursWarningPushService;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import org.springframework.web.server.ResponseStatusException;
|
|
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
|
public class FrequentAbsenceWarningPushIntentHandler implements SemanticIntentHandler {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(FrequentAbsenceWarningPushIntentHandler.class);
|
|
|
|
|
|
private final LowHoursWarningPushService service;
|
|
|
|
|
|
private final SemanticDateRangeResolver dateRangeResolver;
|
|
|
|
|
|
|
|
|
|
|
|
public FrequentAbsenceWarningPushIntentHandler(
|
|
|
|
|
|
LowHoursWarningPushService service,
|
|
|
|
|
|
SemanticDateRangeResolver dateRangeResolver
|
|
|
|
|
|
) {
|
|
|
|
|
|
this.service = service;
|
|
|
|
|
|
this.dateRangeResolver = dateRangeResolver;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public String intent() { return "PUSH_FREQUENT_ABSENCE_WARNING"; }
|
|
|
|
|
|
@Override public String description() { return "生成排课3次以上且缺勤2次以上的高频缺勤名单,并推送给场馆馆长"; }
|
|
|
|
|
|
@Override public String example() { return "推送本月高频缺勤名单"; }
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String handle(SemanticRequestContext context, SemanticRecognition recognition) {
|
|
|
|
|
|
SemanticDateRangeResolver.DateRange range = dateRangeResolver.resolve(context, recognition);
|
|
|
|
|
|
try {
|
|
|
|
|
|
LowHoursWarningPushService.PushSummary result = service.push(
|
|
|
|
|
|
context.wecomUserId(), range.startDate(), range.endDate(), false, true);
|
2026-07-28 16:24:50 +08:00
|
|
|
|
String reply = "### ✅ 高频缺勤名单推送完成\n"
|
2026-07-22 14:56:59 +08:00
|
|
|
|
+ "> 日期:**" + range.startDate()
|
|
|
|
|
|
+ (range.startDate().equals(range.endDate()) ? "" : " 至 " + range.endDate()) + "**\n"
|
|
|
|
|
|
+ "> 范围:**" + result.scopeLabel() + "**\n\n"
|
|
|
|
|
|
+ "高频缺勤:<font color=\"warning\">" + result.frequentAbsenceStudentCount() + "人</font>"
|
|
|
|
|
|
+ " | 匹配馆长:" + result.managerCount() + "人"
|
|
|
|
|
|
+ " | 成功消息:" + result.sentMessageCount() + "条"
|
|
|
|
|
|
+ "\n\n未匹配馆长的学员:" + result.unmatchedStudentCount() + "人"
|
|
|
|
|
|
+ " | 发送失败馆长:" + result.failedManagerCount() + "人";
|
2026-07-28 16:24:50 +08:00
|
|
|
|
result.deferredAttachments().forEach(attachment ->
|
|
|
|
|
|
context.deferExcel(attachment.fileName(), attachment.content()));
|
|
|
|
|
|
return reply;
|
2026-07-22 14:56:59 +08:00
|
|
|
|
} catch (ResponseStatusException exception) {
|
|
|
|
|
|
if (exception.getStatusCode().value() == 403) {
|
|
|
|
|
|
return exception.getReason() == null ? "无权限执行高频缺勤名单推送" : exception.getReason();
|
|
|
|
|
|
}
|
|
|
|
|
|
throw exception;
|
|
|
|
|
|
} catch (Exception exception) {
|
|
|
|
|
|
log.error("frequent absence warning push failed wecomUserId={} err={}",
|
|
|
|
|
|
context.wecomUserId(), exception.getMessage(), exception);
|
|
|
|
|
|
return "高频缺勤名单推送失败,请稍后重试。";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|