Dish_Recognition/models/Pending_approval.py

61 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding=utf-8
"""待人工审核表(仅总服务器 MySQL;未知菜上报后人工确认)。"""
from datetime import datetime
from sqlalchemy import Column, DateTime, ForeignKey, Index, Integer, String, Text
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from dao.db import Base
class PendingApproval(Base):
__tablename__ = 'pending_approval'
id = Column(Integer, primary_key=True, autoincrement=True, comment='主键ID')
image_url = Column(String(512), nullable=False, comment='图片 URL 或路径')
feature_blob = Column(Text, nullable=False, comment='临时特征 Base64(float32)')
source_base_id = Column(
Integer,
ForeignKey('bases.id', ondelete='CASCADE'),
nullable=False,
comment='来源基地',
)
suggested_category = Column(String(100), nullable=True, comment='系统建议菜名')
# pending / approved / rejected —— String 兼容双库
status = Column(String(20), nullable=False, default='pending', server_default='pending', comment='审核状态')
submit_time = Column(
DateTime,
nullable=False,
default=datetime.now,
server_default=func.now(),
comment='提交时间',
)
approve_time = Column(DateTime, nullable=True, comment='审核时间')
approved_by = Column(String(50), nullable=True, comment='审核人')
source_base = relationship(
'BaseInfo',
back_populates='pending_approvals',
foreign_keys=[source_base_id],
)
__table_args__ = (
Index('idx_pending_status', 'status'),
Index('idx_pending_base', 'source_base_id'),
Index('idx_pending_submit_time', 'submit_time'),
)
def to_dict(self):
return {
'id': self.id,
'image_url': self.image_url,
'feature_blob': self.feature_blob,
'source_base_id': self.source_base_id,
'suggested_category': self.suggested_category,
'status': self.status,
'approved_by': self.approved_by,
'submit_time': self.submit_time.strftime('%Y-%m-%d %H:%M:%S') if self.submit_time else None,
'approve_time': self.approve_time.strftime('%Y-%m-%d %H:%M:%S') if self.approve_time else None,
}