feat(application-form-fill): 新增自动填表批次模型
This commit is contained in:
@@ -334,6 +334,8 @@ class ExportedSummaryFile(models.Model):
|
||||
MARKDOWN = "markdown", "Markdown"
|
||||
EXCEL = "excel", "Excel"
|
||||
JSON = "json", "JSON"
|
||||
WORD = "word", "Word"
|
||||
PDF = "pdf", "PDF"
|
||||
|
||||
class Status(models.TextChoices):
|
||||
SUCCESS = "success", "成功"
|
||||
@@ -397,6 +399,92 @@ class RegulatoryRuleVersion(models.Model):
|
||||
return self.code
|
||||
|
||||
|
||||
class ApplicationFormFillBatch(models.Model):
|
||||
"""Tracks one application-form auto-fill workflow run."""
|
||||
|
||||
class Status(models.TextChoices):
|
||||
PENDING = "pending", "待执行"
|
||||
RUNNING = "running", "执行中"
|
||||
WAITING_USER = "waiting_user", "等待用户"
|
||||
SUCCESS = "success", "成功"
|
||||
PARTIAL_SUCCESS = "partial_success", "部分成功"
|
||||
FAILED = "failed", "失败"
|
||||
CANCELLED = "cancelled", "已取消"
|
||||
|
||||
class RegistrationTypeSource(models.TextChoices):
|
||||
USER_MESSAGE = "user_message", "用户话语"
|
||||
REGULATORY_BATCH = "regulatory_batch", "法规核查批次"
|
||||
FILE_EXTRACT = "file_extract", "文件抽取"
|
||||
UNKNOWN = "unknown", "未知"
|
||||
|
||||
conversation = models.ForeignKey(
|
||||
Conversation,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="application_form_fill_batches",
|
||||
)
|
||||
user = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="review_application_form_fill_batches",
|
||||
)
|
||||
trigger_message = models.ForeignKey(
|
||||
Message,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="triggered_application_form_fill_batches",
|
||||
)
|
||||
source_summary_batch = models.ForeignKey(
|
||||
FileSummaryBatch,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="application_form_fill_batches",
|
||||
)
|
||||
source_regulatory_batch = models.ForeignKey(
|
||||
"RegulatoryReviewBatch",
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="application_form_fill_batches",
|
||||
)
|
||||
batch_no = models.CharField(max_length=64, unique=True)
|
||||
status = models.CharField(max_length=30, choices=Status.choices, default=Status.PENDING)
|
||||
requested_templates = models.JSONField(default=list, blank=True)
|
||||
selected_templates = models.JSONField(default=list, blank=True)
|
||||
output_types = models.JSONField(default=list, blank=True)
|
||||
registration_type = models.CharField(max_length=80, blank=True, default="")
|
||||
registration_type_source = models.CharField(
|
||||
max_length=40,
|
||||
choices=RegistrationTypeSource.choices,
|
||||
default=RegistrationTypeSource.UNKNOWN,
|
||||
)
|
||||
product_name = models.CharField(max_length=200, blank=True, default="")
|
||||
conflict_summary = models.JSONField(default=list, blank=True)
|
||||
risk_notes = models.JSONField(default=list, blank=True)
|
||||
template_config_version = models.CharField(max_length=80, blank=True, default="")
|
||||
template_config_hash = models.CharField(max_length=128, blank=True, default="")
|
||||
work_dir = models.CharField(max_length=500, blank=True, default="")
|
||||
error_message = models.TextField(blank=True, default="")
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
started_at = models.DateTimeField(null=True, blank=True)
|
||||
finished_at = models.DateTimeField(null=True, blank=True)
|
||||
archived_at = models.DateTimeField(null=True, blank=True)
|
||||
is_deleted = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
db_table = "ra_application_form_fill_batch"
|
||||
ordering = ["-created_at", "-id"]
|
||||
indexes = [
|
||||
models.Index(fields=["conversation", "status"], name="idx_ra_aff_batch_conv_status"),
|
||||
models.Index(fields=["source_summary_batch"], name="idx_ra_aff_batch_summary"),
|
||||
models.Index(fields=["source_regulatory_batch"], name="idx_ra_aff_batch_regulatory"),
|
||||
models.Index(fields=["user", "created_at"], name="idx_ra_aff_batch_user_created"),
|
||||
models.Index(fields=["created_at"], name="idx_ra_aff_batch_created"),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.batch_no
|
||||
|
||||
|
||||
class RegulatoryReviewBatch(models.Model):
|
||||
"""Tracks one NMPA regulatory review workflow run."""
|
||||
|
||||
@@ -571,3 +659,98 @@ class RegulatoryNotificationRecord(models.Model):
|
||||
indexes = [
|
||||
models.Index(fields=["batch", "status"], name="idx_ra_rr_notify_status"),
|
||||
]
|
||||
|
||||
|
||||
class ApplicationFormFillArtifact(models.Model):
|
||||
"""Stores auto-fill intermediate files and generated artifacts."""
|
||||
|
||||
class ArtifactType(models.TextChoices):
|
||||
TEMPLATE_COPY = "template_copy", "模板副本"
|
||||
FIELD_EXTRACT_RESULT = "field_extract_result", "字段抽取结果"
|
||||
MERGED_FIELDS = "merged_fields", "字段合并结果"
|
||||
TRACEABILITY = "traceability", "追溯清单"
|
||||
FILLED_TEMPLATE = "filled_template", "已填模板"
|
||||
NOTIFICATION_RECORD = "notification_record", "通知记录"
|
||||
|
||||
class FileFormat(models.TextChoices):
|
||||
JSON = "json", "JSON"
|
||||
EXCEL = "excel", "Excel"
|
||||
DOCX = "docx", "DOCX"
|
||||
PDF = "pdf", "PDF"
|
||||
MARKDOWN = "markdown", "Markdown"
|
||||
|
||||
batch = models.ForeignKey(
|
||||
ApplicationFormFillBatch,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="artifacts",
|
||||
)
|
||||
artifact_type = models.CharField(max_length=60, choices=ArtifactType.choices)
|
||||
file_format = models.CharField(max_length=20, choices=FileFormat.choices)
|
||||
name = models.CharField(max_length=160)
|
||||
file_name = models.CharField(max_length=255)
|
||||
storage_path = models.CharField(max_length=500)
|
||||
file_size = models.BigIntegerField(default=0)
|
||||
content_hash = models.CharField(max_length=128, blank=True, default="")
|
||||
metadata = models.JSONField(default=dict, blank=True)
|
||||
created_by_node = models.CharField(max_length=60, blank=True, default="")
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
is_deleted = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
db_table = "ra_application_form_fill_artifact"
|
||||
ordering = ["-created_at", "-id"]
|
||||
indexes = [
|
||||
models.Index(fields=["batch", "artifact_type"], name="idx_ra_aff_artifact_batch_type"),
|
||||
models.Index(fields=["file_format"], name="idx_ra_aff_artifact_format"),
|
||||
models.Index(fields=["created_at"], name="idx_ra_aff_artifact_created"),
|
||||
]
|
||||
|
||||
|
||||
class ApplicationFormFillNotificationRecord(models.Model):
|
||||
"""Stores mock/Feishu notification records for application-form auto-fill."""
|
||||
|
||||
class Channel(models.TextChoices):
|
||||
FEISHU_CLI = "feishu_cli", "飞书 CLI"
|
||||
FEISHU_API = "feishu_api", "飞书 API"
|
||||
MOCK = "mock", "模拟"
|
||||
|
||||
class SendStatus(models.TextChoices):
|
||||
PENDING = "pending", "待发送"
|
||||
SUCCESS = "success", "成功"
|
||||
FAILED = "failed", "失败"
|
||||
|
||||
batch = models.ForeignKey(
|
||||
ApplicationFormFillBatch,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="notifications",
|
||||
)
|
||||
recipient = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="application_form_fill_notifications",
|
||||
)
|
||||
channel = models.CharField(max_length=30, choices=Channel.choices, default=Channel.MOCK)
|
||||
template_codes = models.JSONField(default=list, blank=True)
|
||||
export_ids = models.JSONField(default=list, blank=True)
|
||||
message_summary = models.TextField(blank=True, default="")
|
||||
send_status = models.CharField(
|
||||
max_length=20,
|
||||
choices=SendStatus.choices,
|
||||
default=SendStatus.PENDING,
|
||||
)
|
||||
retry_count = models.PositiveIntegerField(default=0)
|
||||
external_message_id = models.CharField(max_length=120, blank=True, default="")
|
||||
error_message = models.TextField(blank=True, default="")
|
||||
sent_at = models.DateTimeField(null=True, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
is_deleted = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
db_table = "ra_application_form_fill_notification_record"
|
||||
ordering = ["-created_at", "-id"]
|
||||
indexes = [
|
||||
models.Index(fields=["batch", "created_at"], name="idx_ra_aff_notify_batch"),
|
||||
models.Index(fields=["recipient", "send_status"], name="idx_ra_aff_notify_recipient"),
|
||||
models.Index(fields=["send_status", "retry_count"], name="idx_ra_aff_notify_status"),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user