File size: 2,526 Bytes
b4f2238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import annotations

from typing import Any, ClassVar

from django.db import models
from django.utils.translation import gettext_lazy as _


class SessionStatus(models.TextChoices):
    PENDING = "pending", _("待开始")
    IN_PROGRESS = "in_progress", _("进行中")
    COMPLETED = "completed", _("已完成")
    FAILED = "failed", _("失败")
    CANCELLED = "cancelled", _("已取消")


class FilingSession(models.Model):
    """OA立案执行记录"""

    id: int

    contract: Any = models.ForeignKey(
        "contracts.Contract",
        on_delete=models.CASCADE,
        related_name="filing_sessions",
        verbose_name=_("合同"),
    )
    case: Any = models.ForeignKey(
        "cases.Case",
        on_delete=models.CASCADE,
        null=True,
        blank=True,
        related_name="filing_sessions",
        verbose_name=_("案件"),
    )
    oa_config: Any = models.ForeignKey(
        "oa_filing.OAConfig",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="filing_sessions",
        verbose_name=_("OA配置"),
    )
    credential: Any = models.ForeignKey(
        "organization.AccountCredential",
        on_delete=models.SET_NULL,
        null=True,
        related_name="filing_sessions",
        verbose_name=_("登录凭证"),
    )
    user: Any = models.ForeignKey(
        "organization.Lawyer",
        on_delete=models.CASCADE,
        related_name="filing_sessions",
        verbose_name=_("发起用户"),
    )
    status: str = models.CharField(  # type: ignore[assignment]
        max_length=16,
        choices=SessionStatus.choices,
        default=SessionStatus.PENDING,
        verbose_name=_("状态"),
    )
    error_message: str = models.TextField(  # type: ignore[assignment]
        blank=True,
        default="",
        verbose_name=_("错误信息"),
    )
    created_at: Any = models.DateTimeField(
        auto_now_add=True,
        verbose_name=_("创建时间"),
    )
    updated_at: Any = models.DateTimeField(
        auto_now=True,
        verbose_name=_("更新时间"),
    )

    class Meta:
        verbose_name = _("立案记录")
        verbose_name_plural = _("立案记录")
        indexes: ClassVar = [
            models.Index(fields=["contract", "-created_at"]),
            models.Index(fields=["user", "-created_at"]),
            models.Index(fields=["status", "-created_at"]),
        ]

    def __str__(self) -> str:
        return f"FilingSession #{self.id} - {self.status}"