feat: keep table binding messages out of QA

This commit is contained in:
姚章浩
2026-08-13 12:55:00 +08:00
parent 2d9490f424
commit 5036071ac2
4 changed files with 108 additions and 15 deletions
+16
View File
@@ -45,6 +45,22 @@ func (r *SettingsRepository) GetPreference(ctx context.Context, tenant, channel,
}
return locale, err
}
func (r *SettingsRepository) GetSettingSession(ctx context.Context, tenant, staff string) (settings.SettingSession, bool, error) {
var session settings.SettingSession
err := r.store.pool.QueryRow(ctx, `SELECT tenant_key,staff_id,conversation_id,conversation_type,pending_action,expires_at FROM setting_sessions WHERE tenant_key=$1 AND staff_id=$2 AND expires_at>NOW()`, tenant, staff).Scan(&session.TenantKey, &session.StaffID, &session.ConversationID, &session.ConversationType, &session.PendingAction, &session.ExpiresAt)
if errors.Is(err, pgx.ErrNoRows) {
return settings.SettingSession{}, false, nil
}
return session, err == nil, err
}
func (r *SettingsRepository) SaveSettingSession(ctx context.Context, session settings.SettingSession) error {
_, err := r.store.pool.Exec(ctx, `INSERT INTO setting_sessions(tenant_key,staff_id,conversation_id,conversation_type,current_step,pending_action,draft_config,expires_at) VALUES($1,$2,$3,$4,'waiting_input',$5,'{}'::JSONB,$6) ON CONFLICT(tenant_key,staff_id) DO UPDATE SET conversation_id=EXCLUDED.conversation_id,conversation_type=EXCLUDED.conversation_type,current_step='waiting_input',pending_action=EXCLUDED.pending_action,draft_config='{}'::JSONB,expires_at=EXCLUDED.expires_at,updated_at=NOW()`, session.TenantKey, session.StaffID, session.ConversationID, session.ConversationType, session.PendingAction, session.ExpiresAt)
return err
}
func (r *SettingsRepository) DeleteSettingSession(ctx context.Context, tenant, staff string) error {
_, err := r.store.pool.Exec(ctx, `DELETE FROM setting_sessions WHERE tenant_key=$1 AND staff_id=$2`, tenant, staff)
return err
}
func (r *SettingsRepository) SaveBinding(ctx context.Context, b settings.ResourceBinding) error {
payload, err := json.Marshal(map[string]string{"conversation_id": b.ConversationID, "conversation_title": b.ConversationTitle, "base_id": b.BaseID, "sheet_id": b.SheetID, "view_id": b.ViewID, "operator_id": b.OperatorID})
if err != nil {