Phase 1 scaffolding: config/, core/, base models, AES-256-GCM phone encryption, enums mirror apps.tenant: Tenant + Domain (django-tenants) apps.org: 11 models (OrgUnit hierarchy, Staff, audit logs) apps.account: 4 models (UserAccount as AUTH_USER_MODEL, login/password tracking) apps.permission: 7 models (RBAC + overrides + datascope + append-only changelog) apps.region: 5 models (District, BusinessArea, MetroLine, MetroStation, School) All migrations generated, manage.py check passes
165 lines
5.3 KiB
Python
165 lines
5.3 KiB
Python
from django.db import models
|
|
|
|
from core.enums import StaffAccountPlatform, StaffTransferType
|
|
from core.models.base import SoftDeleteModel, TimeStampedModel
|
|
|
|
|
|
class StaffTransferLog(TimeStampedModel):
|
|
staff = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.RESTRICT,
|
|
related_name="transfer_logs",
|
|
)
|
|
transfer_type = models.CharField(max_length=30, choices=StaffTransferType.choices)
|
|
old_value = models.JSONField(null=True, blank=True)
|
|
new_value = models.JSONField(null=True, blank=True)
|
|
transfer_date = models.DateField()
|
|
remarks = models.CharField(max_length=50, blank=True, default="")
|
|
operator = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.RESTRICT,
|
|
related_name="operated_transfers",
|
|
)
|
|
operated_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
db_table = "staff_transfer_logs"
|
|
indexes = [
|
|
models.Index(fields=["staff", "-transfer_date"], name="idx_transfer_logs_staff"),
|
|
models.Index(fields=["transfer_type", "-operated_at"], name="idx_transfer_logs_type"),
|
|
models.Index(fields=["operator"], name="idx_transfer_logs_operator"),
|
|
]
|
|
|
|
|
|
class StaffRewardPunish(SoftDeleteModel):
|
|
staff = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.CASCADE,
|
|
related_name="reward_punish_records",
|
|
)
|
|
rp_date = models.DateField()
|
|
category = models.CharField(
|
|
max_length=50,
|
|
help_text="Configurable lookup_items domain: org.reward_punish_category.",
|
|
)
|
|
name = models.CharField(max_length=100)
|
|
remarks = models.TextField(blank=True, default="")
|
|
created_by = models.ForeignKey(
|
|
"org.Staff",
|
|
null=True,
|
|
blank=True,
|
|
on_delete=models.SET_NULL,
|
|
related_name="created_reward_punish",
|
|
)
|
|
|
|
class Meta:
|
|
db_table = "staff_reward_punish"
|
|
|
|
|
|
class StaffAccount(TimeStampedModel):
|
|
staff = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.CASCADE,
|
|
related_name="external_accounts",
|
|
)
|
|
platform = models.CharField(max_length=30, choices=StaffAccountPlatform.choices)
|
|
account_no = models.CharField(max_length=100, blank=True, default="")
|
|
is_real_name_match = models.BooleanField(null=True, blank=True)
|
|
is_bound = models.BooleanField(default=False)
|
|
bound_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
class Meta:
|
|
db_table = "staff_accounts"
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["staff", "platform"],
|
|
name="uq_staff_accounts_staff_platform",
|
|
),
|
|
]
|
|
|
|
|
|
class StaffWorkExperience(TimeStampedModel):
|
|
staff = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.CASCADE,
|
|
related_name="work_experiences",
|
|
)
|
|
company = models.CharField(max_length=200)
|
|
job_title = models.CharField(max_length=100, blank=True, default="")
|
|
start_date = models.DateField(null=True, blank=True)
|
|
end_date = models.DateField(null=True, blank=True)
|
|
reason = models.CharField(max_length=200, blank=True, default="")
|
|
reference_name = models.CharField(max_length=50, blank=True, default="")
|
|
reference_phone = models.CharField(max_length=30, blank=True, default="")
|
|
|
|
class Meta:
|
|
db_table = "staff_work_experiences"
|
|
|
|
|
|
class StaffEducation(TimeStampedModel):
|
|
staff = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.CASCADE,
|
|
related_name="educations",
|
|
)
|
|
stage = models.CharField(max_length=30, blank=True, default="")
|
|
school = models.CharField(max_length=200)
|
|
major = models.CharField(max_length=100, blank=True, default="")
|
|
start_date = models.DateField(null=True, blank=True)
|
|
end_date = models.DateField(null=True, blank=True)
|
|
enrollment_status = models.CharField(max_length=30, blank=True, default="")
|
|
degree = models.CharField(max_length=30, blank=True, default="")
|
|
|
|
class Meta:
|
|
db_table = "staff_educations"
|
|
|
|
|
|
class StaffTraining(TimeStampedModel):
|
|
staff = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.CASCADE,
|
|
related_name="trainings",
|
|
)
|
|
training_name = models.CharField(max_length=200)
|
|
training_date = models.DateField(null=True, blank=True)
|
|
certificate = models.CharField(max_length=200, blank=True, default="")
|
|
|
|
class Meta:
|
|
db_table = "staff_trainings"
|
|
|
|
|
|
class StaffFamilyMember(TimeStampedModel):
|
|
staff = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.CASCADE,
|
|
related_name="family_members",
|
|
)
|
|
relation = models.CharField(max_length=30)
|
|
name = models.CharField(max_length=50)
|
|
birthdate = models.DateField(null=True, blank=True)
|
|
occupation = models.CharField(max_length=100, blank=True, default="")
|
|
work_unit = models.CharField(max_length=200, blank=True, default="")
|
|
phone_enc = models.BinaryField(null=True, blank=True)
|
|
|
|
class Meta:
|
|
db_table = "staff_family_members"
|
|
|
|
|
|
class StaffRemark(SoftDeleteModel):
|
|
staff = models.ForeignKey(
|
|
"org.Staff",
|
|
on_delete=models.CASCADE,
|
|
related_name="remarks",
|
|
)
|
|
content = models.TextField()
|
|
created_by = models.ForeignKey(
|
|
"org.Staff",
|
|
null=True,
|
|
blank=True,
|
|
on_delete=models.SET_NULL,
|
|
related_name="created_remarks",
|
|
)
|
|
|
|
class Meta:
|
|
db_table = "staff_remarks"
|