54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
"""推荐方案记录模型。"""
|
|
from sqlalchemy import Column, Integer, String, Text, SmallInteger, TIMESTAMP, func
|
|
from insurance.db.compat import db
|
|
|
|
|
|
class RecommendationRecord(db.Model):
|
|
"""产品推荐方案的输入参数和生成结果。"""
|
|
__tablename__ = "recommendation_records"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(String(64), nullable=False, index=True)
|
|
customer_name = Column(String(64))
|
|
customer_age = Column(SmallInteger)
|
|
customer_gender = Column(String(8))
|
|
health_status = Column(String(32))
|
|
occupation = Column(String(64))
|
|
annual_income = Column(Integer)
|
|
monthly_budget = Column(Integer)
|
|
insurance_types = Column(Text)
|
|
coverage_amount = Column(Integer)
|
|
coverage_period = Column(String(32))
|
|
existing_policies = Column(Text)
|
|
generated_plan = Column(Text)
|
|
plan_variants = Column(Text)
|
|
task_id = Column(String(64))
|
|
status = Column(String(16), default="pending", index=True)
|
|
error_message = Column(Text)
|
|
created_at = Column(TIMESTAMP, server_default=func.now(), index=True)
|
|
completed_at = Column(TIMESTAMP)
|
|
|
|
def to_dict(self):
|
|
return {
|
|
"id": str(self.id),
|
|
"user_id": self.user_id,
|
|
"customer_name": self.customer_name,
|
|
"customer_age": self.customer_age,
|
|
"customer_gender": self.customer_gender,
|
|
"health_status": self.health_status,
|
|
"occupation": self.occupation,
|
|
"annual_income": self.annual_income,
|
|
"monthly_budget": self.monthly_budget,
|
|
"insurance_types": self.insurance_types,
|
|
"coverage_amount": self.coverage_amount,
|
|
"coverage_period": self.coverage_period,
|
|
"existing_policies": self.existing_policies,
|
|
"generated_plan": self.generated_plan,
|
|
"plan_variants": self.plan_variants,
|
|
"task_id": self.task_id,
|
|
"status": self.status,
|
|
"error_message": self.error_message,
|
|
"created_at": str(self.created_at) if self.created_at else None,
|
|
"completed_at": str(self.completed_at) if self.completed_at else None,
|
|
}
|