factory/apps/third/models.py

64 lines
2.5 KiB
Python
Executable File

from django.db import models
from apps.am.models import Area
import uuid
from apps.hrm.models import Employee
from apps.utils.constants import Algo
from apps.utils.models import BaseModel
# Create your models here.
class TDevice(BaseModel):
"""
三方设备补充信息
"""
DEVICE_BLG = 10
DEVICE_IBEACON = 20
DEVICE_BLT = 30
DEVICE_AOA = 40
DEVICE_SPEAKER = 50
DEVICE_VCHANNEL = 60
DEVICE_DCHANNEL = 70
DEVICE_PANEL = 80
DEVICE_CHOICE = (
(DEVICE_BLG, '定位基站'),
(DEVICE_IBEACON, '定位信标'),
(DEVICE_BLT, '定位标签'),
(DEVICE_AOA, 'aoa引擎'),
(DEVICE_SPEAKER, '音响'),
(DEVICE_VCHANNEL, '视频通道'),
(DEVICE_DCHANNEL, '闸机通道'),
(DEVICE_PANEL, '面板机')
)
type = models.PositiveSmallIntegerField('设备类型', choices=DEVICE_CHOICE)
code = models.CharField('设备唯一标识', max_length=50, db_index=True)
location = models.JSONField('位置信息', default=dict,
null=False, blank=True)
algos = models.ManyToManyField('ecm.eventcate', verbose_name='启用算法', blank=True)
area = models.ForeignKey(Area, on_delete=models.CASCADE,
verbose_name='所在区', null=True, blank=True)
areas = models.ManyToManyField(Area, verbose_name='覆盖区',
related_name='tareas')
obj_cate = models.CharField('绑定对象', max_length=20, help_text='people/...', null=True, blank=True)
employee = models.ForeignKey(Employee, verbose_name='绑定人员', on_delete=models.CASCADE, null=True, blank=True)
is_clock = models.BooleanField('是否打卡设备', default=False)
third_info = models.JSONField('三方信息', default=dict,
null=False, blank=True)
class Tlog(BaseModel):
"""第三方请求与处理日志
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
target = models.CharField('请求目标', max_length=20)
result = models.CharField('请求结果', max_length=20)
path = models.CharField(max_length=400, help_text="请求地址")
requested_at = models.DateTimeField()
response_ms = models.PositiveIntegerField(default=0)
response = models.JSONField(null=True, blank=True)
method = models.CharField(max_length=10)
url = models.TextField(null=True, blank=True)
params = models.JSONField(null=True, blank=True)
body = models.JSONField(null=True, blank=True)