46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
|
|
"""
|
||
|
|
用户行为日志模型 — 记录用户四大维度的操作行为
|
||
|
|
用于数字分身的观察和学习
|
||
|
|
"""
|
||
|
|
from sqlalchemy import Column, String, Text, Integer, DateTime, JSON, Enum as SAEnum
|
||
|
|
from sqlalchemy.dialects.mysql import CHAR
|
||
|
|
from app.core.database import Base
|
||
|
|
from datetime import datetime
|
||
|
|
import uuid
|
||
|
|
import enum
|
||
|
|
|
||
|
|
|
||
|
|
class BehaviorCategory(str, enum.Enum):
|
||
|
|
EMAIL = "email" # 邮件处理
|
||
|
|
CODE_REVIEW = "code_review" # 代码审核
|
||
|
|
DOCUMENT = "document" # 文档撰写
|
||
|
|
DECISION = "decision" # 决策行为
|
||
|
|
GENERAL = "general" # 通用操作
|
||
|
|
|
||
|
|
|
||
|
|
class UserBehaviorLog(Base):
|
||
|
|
"""用户行为观察日志"""
|
||
|
|
__tablename__ = "user_behavior_logs"
|
||
|
|
|
||
|
|
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="日志ID")
|
||
|
|
user_id = Column(String(36), nullable=False, index=True, comment="用户 ID")
|
||
|
|
category = Column(String(30), nullable=False, index=True, comment="行为类别: email/code_review/document/decision/general")
|
||
|
|
action = Column(String(100), nullable=False, comment="具体动作: open_email/reply_email/review_pr/approve_pr/write_doc/make_decision")
|
||
|
|
|
||
|
|
# 上下文信息
|
||
|
|
context = Column(JSON, nullable=True, comment="行为上下文: {url, params, entity_id, ...}")
|
||
|
|
|
||
|
|
# 行为结果
|
||
|
|
result = Column(JSON, nullable=True, comment="行为结果: {action_taken, duration_ms, outcome, ...}")
|
||
|
|
|
||
|
|
# 元信息
|
||
|
|
source = Column(String(50), nullable=True, comment="来源: api/webhook/feishu/manual")
|
||
|
|
session_id = Column(String(100), nullable=True, comment="会话标识")
|
||
|
|
ip_address = Column(String(50), nullable=True, comment="客户端 IP")
|
||
|
|
user_agent = Column(String(500), nullable=True, comment="用户代理")
|
||
|
|
|
||
|
|
created_at = Column(DateTime, default=datetime.now, index=True, comment="发生时间")
|
||
|
|
|
||
|
|
def __repr__(self):
|
||
|
|
return f"<UserBehaviorLog(id={self.id}, user={self.user_id}, action={self.action})>"
|