factory/apps/am/models.py

64 lines
2.3 KiB
Python
Executable File

from django.db import models
from apps.hrm.models import Employee
from apps.system.models import Post, User
from apps.utils.constants import ObjCate
from apps.utils.models import CommonADModel, CommonBModel
# Create your models here.
class Area(CommonBModel):
"""
地图区域
"""
AREA_1 = 10
AREA_2 = 20
AREA_3 = 30
AREA_4 = 40
AREA_LEVEL_CHOICES = (
(AREA_1, '办公'),
(AREA_2, '生产一般'),
(AREA_3, '生产重点'),
(AREA_4, '四级')
)
AREA_TYPE_FIX = 10
AREA_TYPE_TEMP = 20
AREA_TYPE_CHOICES = (
(10, '固定'),
(20, '临时作业')
)
name = models.CharField('名称', max_length=20)
type = models.PositiveSmallIntegerField('区域类型', default=10, choices=AREA_TYPE_CHOICES)
level = models.PositiveSmallIntegerField('区域风险等级')
cate = models.PositiveSmallIntegerField('区域分类')
number = models.CharField('编号', max_length=20, null=True, blank=True)
visitor_yes = models.BooleanField('准许访客人员', default=False)
remployee_yes = models.BooleanField('准许相关方人员', default=False)
employee_yes = models.BooleanField('准许全部员工', default=True)
count_people_min = models.PositiveIntegerField('最小人员数', default=0)
count_people_max = models.PositiveIntegerField('最大人员数', default=1000)
count_people = models.PositiveIntegerField('当前人数', default=0)
is_hidden = models.BooleanField('隐藏围栏用', default=False)
third_info = models.JSONField('三方信息', default=dict,
null=False, blank=True)
def __str__(self) -> str:
return self.name
class Access(CommonADModel):
"""
准入禁入权限(动态变化)
"""
ACCESS_IN_YES = 10
ACCESS_IN_NO = 20
ACCESS_CHOICE = (
(ACCESS_IN_YES, '准入'),
(ACCESS_IN_NO, '禁入')
)
type = models.PositiveSmallIntegerField('准入类型', choices=ACCESS_CHOICE)
area = models.ForeignKey(Area, verbose_name='关联区域',
on_delete=models.CASCADE)
obj_cate = models.CharField('对象类型', max_length=20, help_text='employee/post')
obj = models.CharField('关联对象', unique=True, max_length=50, null=True, blank=True)