|
|
@ -38,7 +38,7 @@ public class ConversationService { |
|
|
return listConversations(page, size, keyword, null, null); |
|
|
return listConversations(page, size, keyword, null, null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Map<String, Object> listConversations(int page, int size, String keyword, Long accountId, Long roleId) { |
|
|
|
|
|
|
|
|
public Map<String, Object> listConversations(int page, int size, String keyword, String accountId, Long roleId) { |
|
|
// 构建基础 SQL 条件 |
|
|
// 构建基础 SQL 条件 |
|
|
StringBuilder whereClause = new StringBuilder("WHERE cm1.is_delete = false "); |
|
|
StringBuilder whereClause = new StringBuilder("WHERE cm1.is_delete = false "); |
|
|
List<Object> params = new ArrayList<>(); |
|
|
List<Object> params = new ArrayList<>(); |
|
|
@ -58,9 +58,17 @@ public class ConversationService { |
|
|
params.add(like); |
|
|
params.add(like); |
|
|
params.add(like); |
|
|
params.add(like); |
|
|
} |
|
|
} |
|
|
if (accountId != null && accountId > 0) { |
|
|
|
|
|
whereClause.append(" AND cs.account_id = ? "); |
|
|
|
|
|
params.add(accountId); |
|
|
|
|
|
|
|
|
if (accountId != null && !accountId.isBlank()) { |
|
|
|
|
|
String normalizedAccountId = accountId.trim(); |
|
|
|
|
|
Long numericAccountId = toLong(normalizedAccountId); |
|
|
|
|
|
if (numericAccountId != null && numericAccountId > 0) { |
|
|
|
|
|
whereClause.append(" AND (cs.account_id = ? OR ca.account_key = ?) "); |
|
|
|
|
|
params.add(numericAccountId); |
|
|
|
|
|
params.add(normalizedAccountId); |
|
|
|
|
|
} else { |
|
|
|
|
|
whereClause.append(" AND ca.account_key = ? "); |
|
|
|
|
|
params.add(normalizedAccountId); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if (roleId != null && roleId > 0) { |
|
|
if (roleId != null && roleId > 0) { |
|
|
whereClause.append(" AND cs.role_id = ? "); |
|
|
whereClause.append(" AND cs.role_id = ? "); |
|
|
@ -147,8 +155,8 @@ public class ConversationService { |
|
|
INSERT INTO conversation_session (conversation_id, account_id, role_id) |
|
|
INSERT INTO conversation_session (conversation_id, account_id, role_id) |
|
|
VALUES (?, ?, ?) |
|
|
VALUES (?, ?, ?) |
|
|
ON CONFLICT (conversation_id) |
|
|
ON CONFLICT (conversation_id) |
|
|
DO UPDATE SET account_id = EXCLUDED.account_id, |
|
|
|
|
|
role_id = EXCLUDED.role_id, |
|
|
|
|
|
|
|
|
DO UPDATE SET account_id = COALESCE(EXCLUDED.account_id, conversation_session.account_id), |
|
|
|
|
|
role_id = COALESCE(EXCLUDED.role_id, conversation_session.role_id), |
|
|
update_time = CURRENT_TIMESTAMP |
|
|
update_time = CURRENT_TIMESTAMP |
|
|
""", conversationId, normalizedAccountId, normalizedRoleId); |
|
|
""", conversationId, normalizedAccountId, normalizedRoleId); |
|
|
} |
|
|
} |
|
|
@ -389,4 +397,15 @@ public class ConversationService { |
|
|
|
|
|
|
|
|
return stats; |
|
|
return stats; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Long toLong(String value) { |
|
|
|
|
|
if (value == null || value.isBlank()) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
return Long.valueOf(value.trim()); |
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |