签到检查功能增强:返回签到时间和内容
问题: - 用户询问'我什么时候签到的'时,AI 说'系统只记录是否签到,没有时间戳' - 实际上数据库 signs 表有完整的 sign_time 和 sign_text 字段 解决方案: - 修改 executeCheck 方法,改用 ListSigns 查询今天的签到记录 - 返回完整的签到详情:签到时间(HH:MM:SS格式)+ 签到内容 - 未签到时仍返回简单提示 改动内容: - executeCheck 使用 ListSigns 替代 HasSignedOnDay - 构建 ListOptions 查询今天的签到记录(过滤 NodeID + 时间范围) - 返回格式:'XXX 今天已经签到过了。\n签到时间:10:30:45\n签到内容:上海-Kevin-GAT562签到' - 更新测试验证返回内容包含时间和签到文本 - 更新 mockSignStore.ListSigns 支持 NodeID 和 Limit 过滤 使用效果: - 用户:'我今天签到了吗?' → 返回是否签到 + 时间 + 内容 - 用户:'我什么时候签到的?' → 返回签到时间:10:30:45 测试: - ✅ 未签到场景测试通过 - ✅ 已签到场景测试通过(验证时间和内容) - ✅ 所有签到工具测试通过 - ✅ 项目编译成功 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -179,7 +179,7 @@ func (t *Tool) executeSign(ctx context.Context, params signParams, runtime agent
|
||||
return fmt.Sprintf("签到成功!%s\n签到内容:%s", displayName(node), record.SignText), nil
|
||||
}
|
||||
|
||||
// executeCheck 检查当前节点今天是否已签到
|
||||
// executeCheck 检查当前节点今天是否已签到,并返回签到详情
|
||||
func (t *Tool) executeCheck(ctx context.Context, params signParams, runtime agenttool.Runtime) (string, error) {
|
||||
// 节点身份来自消息上下文
|
||||
node, ok := agenttool.NodeContextFromContext(ctx)
|
||||
@@ -192,16 +192,36 @@ func (t *Tool) executeCheck(ctx context.Context, params signParams, runtime agen
|
||||
now = time.Now()
|
||||
}
|
||||
|
||||
// 查询数据库检查今天是否已签到
|
||||
signed, err := t.store.HasSignedOnDay(node.NodeID, now)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("检查签到状态失败:%w", err)
|
||||
// 构建查询选项:查询今天的签到记录
|
||||
loc := now.Location()
|
||||
if loc == nil {
|
||||
loc = time.Local
|
||||
}
|
||||
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc)
|
||||
end := start.AddDate(0, 0, 1)
|
||||
|
||||
opts := storepkg.ListOptions{
|
||||
NodeID: node.NodeID,
|
||||
Since: &start,
|
||||
Until: &end,
|
||||
Limit: 1,
|
||||
}
|
||||
|
||||
if signed {
|
||||
return fmt.Sprintf("%s 今天已经签到过了。", displayName(node)), nil
|
||||
// 查询数据库获取今天的签到记录
|
||||
signs, err := t.store.ListSigns(opts)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("查询签到记录失败:%w", err)
|
||||
}
|
||||
return fmt.Sprintf("%s 今天还没有签到。", displayName(node)), nil
|
||||
|
||||
if len(signs) == 0 {
|
||||
return fmt.Sprintf("%s 今天还没有签到。", displayName(node)), nil
|
||||
}
|
||||
|
||||
// 返回签到详情
|
||||
sign := signs[0]
|
||||
signTimeStr := sign.SignTime.Format("15:04:05")
|
||||
return fmt.Sprintf("%s 今天已经签到过了。\n签到时间:%s\n签到内容:%s",
|
||||
displayName(node), signTimeStr, sign.SignText), nil
|
||||
}
|
||||
|
||||
// executeQuery 执行查询操作
|
||||
|
||||
Reference in New Issue
Block a user