diff --git a/demo/web/server.py b/demo/web/server.py index fb360e9..d2ae96d 100644 --- a/demo/web/server.py +++ b/demo/web/server.py @@ -254,7 +254,8 @@ def list_customers( cu.key_needs, cu.stage, cu.last_analysis, c.display_name AS contact_display_name, max(m.created_at) AS last_message_at, - string_agg(DISTINCT p.category, ', ') AS product_categories + string_agg(DISTINCT p.category, ', ') AS deal_categories, + string_agg(m.normalized_content, ' ') AS all_messages FROM customer cu JOIN salesperson s ON s.id = cu.salesperson_id JOIN contact c ON c.id = cu.contact_id @@ -283,8 +284,25 @@ def list_customers( ORDER BY cu.salesperson_id, cu.id """ cur.execute(sql, params) - return [ - { + # 产品线关键词:通过对话内容推断产品线 + diet_keywords = ["减肥", "减脂", "瘦身", "B420", "纤益", "代餐", "体脂", "产后减肥", "节食"] + child_keywords = ["湿疹", "过敏", "鼻炎", "腹泻", "便秘", "免疫力", "胀气", + "拉肚子", "打喷嚏", "流鼻涕", "感冒", "食物过敏", "牛奶蛋白", + "宝宝", "宝妈", "儿童", "丹麦", "鼠李糖", "LGG", "合生元"] + results = [] + for r in cur.fetchall(): + deal_cats = r[11] + all_msgs = r[12] or "" + # 优先用 deal 关联的产品线,其次通过对话内容推断 + if deal_cats: + product_categories = deal_cats + elif any(kw in all_msgs for kw in diet_keywords): + product_categories = "女性减肥益生菌" + elif any(kw in all_msgs for kw in child_keywords): + product_categories = "儿童益生菌" + else: + product_categories = None + results.append({ "id": r[0], "salesperson_id": r[1], "salesperson_name": r[2], "customer_name": r[3], "industry": r[4], @@ -293,10 +311,9 @@ def list_customers( "last_analysis": r[8].isoformat() if r[8] else None, "contact_display_name": r[9], "last_message_at": r[10].isoformat() if r[10] else None, - "product_categories": r[11], - } - for r in cur.fetchall() - ] + "product_categories": product_categories, + }) + return results finally: put_conn(conn)