feat(pchome): automate authorized sales acquisition
Some checks failed
CD Pipeline / deploy (push) Has been cancelled

This commit is contained in:
ogt
2026-07-11 01:30:42 +08:00
parent f68223f0ed
commit 6e65ef00bb
21 changed files with 2428 additions and 617 deletions

View File

@@ -110,3 +110,64 @@ class ImportConfig(Base):
'created_at': self.created_at.isoformat() if self.created_at else None,
'updated_at': self.updated_at.isoformat() if self.updated_at else None,
}
class SalesAcquisitionReceipt(Base):
"""Durable controlled-apply receipt for PChome sales acquisition runs."""
__tablename__ = 'pchome_sales_acquisition_receipts'
receipt_id = Column(String(64), primary_key=True)
trace_id = Column(String(64), nullable=False, index=True)
span_id = Column(String(16), nullable=False, index=True)
run_id = Column(String(64), nullable=False, index=True)
work_item_id = Column(String(100), nullable=False, index=True)
status = Column(String(40), nullable=False, index=True)
source_type = Column(String(40), nullable=False, index=True)
source_fingerprint = Column(String(64), index=True)
source_ref_hash = Column(String(64))
source_file_name = Column(String(500))
risk_level = Column(String(20), nullable=False, default='medium')
policy_decision = Column(String(40), nullable=False)
decision = Column(String(80), nullable=False)
import_job_id = Column(Integer, index=True)
rows_imported = Column(Integer, default=0)
before_freshness_json = Column(Text)
stage_receipts_json = Column(Text)
verifier_json = Column(Text)
error_kind = Column(String(100))
public_message = Column(Text)
started_at = Column(DateTime, default=taipei_now, nullable=False)
completed_at = Column(DateTime)
def to_public_dict(self):
def parse_json(value):
if not value:
return None
try:
import json
return json.loads(value)
except Exception:
return None
return {
'receipt_id': self.receipt_id,
'trace_id': self.trace_id,
'span_id': self.span_id,
'run_id': self.run_id,
'work_item_id': self.work_item_id,
'status': self.status,
'source_type': self.source_type,
'source_file_name': self.source_file_name,
'risk_level': self.risk_level,
'policy_decision': self.policy_decision,
'decision': self.decision,
'import_job_id': self.import_job_id,
'rows_imported': self.rows_imported or 0,
'before_freshness': parse_json(self.before_freshness_json),
'stages': parse_json(self.stage_receipts_json),
'verifier': parse_json(self.verifier_json),
'error_kind': self.error_kind,
'message': self.public_message,
'started_at': self.started_at.isoformat() if self.started_at else None,
'completed_at': self.completed_at.isoformat() if self.completed_at else None,
}