fix: 3 项问题
1. 审批DB更新精确匹配 — code_hash 从 removed entry 提取 2. delete memo 提取 id — prompt 中数字 → id 参数 3. 清理未使用的 current_user_id 全局变量
This commit is contained in:
@@ -89,7 +89,7 @@ impl ApprovalManager {
|
||||
/// 处理用户回复(由消息循环调用)
|
||||
/// 匹配成功时返回 Some(技能名),匹配失败返回 None
|
||||
pub async fn handle_reply(&self, user_id: &str, reply: &str) -> Option<String> {
|
||||
let (result, name) = {
|
||||
let (result, name, code_hash) = {
|
||||
let mut map = self.pending.lock().await;
|
||||
let entries = map.get_mut(user_id)?;
|
||||
if entries.is_empty() { return None; }
|
||||
@@ -99,19 +99,22 @@ impl ApprovalManager {
|
||||
|
||||
if reply_trimmed == "0" || reply_trimmed == "取消" {
|
||||
let entry = entries.remove(0);
|
||||
let hash = entry.code_hash.clone();
|
||||
let _ = entry.sender.send(ApprovalDecision::Rejected);
|
||||
(ApprovalDecision::Rejected, entry.skill_name.clone())
|
||||
(ApprovalDecision::Rejected, entry.skill_name.clone(), hash)
|
||||
} else if let Some(idx) = entries.iter().position(|e| e.code_hash == reply_hash) {
|
||||
let entry = entries.remove(idx);
|
||||
let hash = entry.code_hash.clone();
|
||||
let _ = entry.sender.send(ApprovalDecision::Approved);
|
||||
(ApprovalDecision::Approved, entry.skill_name.clone())
|
||||
(ApprovalDecision::Approved, entry.skill_name.clone(), hash)
|
||||
} else if let Some(entry) = entries.first_mut() {
|
||||
entry.attempts_left -= 1;
|
||||
if entry.attempts_left <= 0 {
|
||||
let entry = entries.remove(0);
|
||||
let n = entry.skill_name.clone();
|
||||
let hash = entry.code_hash.clone();
|
||||
let _ = entry.sender.send(ApprovalDecision::Rejected);
|
||||
(ApprovalDecision::Rejected, n)
|
||||
(ApprovalDecision::Rejected, n, hash)
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
@@ -128,10 +131,10 @@ impl ApprovalManager {
|
||||
};
|
||||
// 按 user_id + 最近 pending 记录更新
|
||||
let _ = sqlx::query(
|
||||
"UPDATE pending_approvals SET status = $1, consumed_at = NOW() WHERE id = (SELECT id FROM pending_approvals WHERE user_id = $2 AND status = 'pending' ORDER BY created_at DESC LIMIT 1)",
|
||||
"UPDATE pending_approvals SET status = $1, consumed_at = NOW() WHERE code_hash = $2 AND status = 'pending'",
|
||||
)
|
||||
.bind(status)
|
||||
.bind(user_id)
|
||||
.bind(&code_hash)
|
||||
.execute(pool.as_ref())
|
||||
.await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user