暂无描述

models.py 8.7KB

    # -*- coding: utf-8 -*- from django.db import models from django.utils.translation import ugettext_lazy as _ from django_models_ext import BaseModelMixin, SexModelMixin from jsonfield import JSONField from shortuuidfield import ShortUUIDField from TimeConvert import TimeConvert as tc from utils.redis.rqrurl import get_qrcode_url class IsolationPointFieldPoolInfo(BaseModelMixin): INPUT = 'input' SELECT = 'select' FILE = 'file' FIELD_TYPE_TUPLE = ( (INPUT, 'input'), (SELECT, 'select'), (FILE, 'file'), ) # { # "type": "input", # input, select, file # "name": "", # "options": ["男", "女"], # type=select # } field_type = models.CharField(_('field_type'), max_length=8, choices=FIELD_TYPE_TUPLE, default=INPUT, help_text='字段类型') field_name = models.CharField(_('field_name'), max_length=32, blank=True, null=True, help_text='字段名称') field_key = models.CharField(_('field_key'), max_length=32, blank=True, null=True, help_text='字段键值') field_options = JSONField(_('field_options'), default=[], blank=True, null=True, help_text='字段选择') class Meta: verbose_name = _('字段池信息') verbose_name_plural = _('字段池信息') def __unicode__(self): return self.pk @property def data(self): return { 'type': self.field_type, 'key': self.field_key, 'name': self.field_name, 'options': self.field_options, } class IsolationPointInfo(BaseModelMixin): point_id = ShortUUIDField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True, unique=True) point_name = models.CharField(_('point_name'), max_length=255, blank=True, null=True, help_text='隔离点名称') # { # "type": "input", # input, select, file # "name": "", # "options": ["男", "女"], # type=select # } point_fields = JSONField(_('point_fields'), default=[], blank=True, null=True, help_text='字段列表') limit_scene_qrcode_url = models.CharField(_('limit_scene_qrcode_url'), max_length=255, blank=True, null=True, help_text='字段二维码') class Meta: verbose_name = _('隔离点信息') verbose_name_plural = _('隔离点信息') def __unicode__(self): return self.pk @property def data(self): qrcode_url = get_qrcode_url(self.point_id) return { 'point_id': self.point_id, 'point_name': self.point_name, 'point_fields': self.point_fields, 'qrcode_url': qrcode_url, } class IsolationPointUserInfo(BaseModelMixin): HAS_NOT_UPLOAD = '未上报' HAS_YET_UPLOAD = '已上报' point_id = models.CharField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True) user_id = models.CharField(_('user_id'), max_length=32, blank=True, null=True, help_text='用户唯一标识', db_index=True) fields = JSONField(_('fields'), default=[], blank=True, null=True, help_text='字段信息') observed_ymds = JSONField(_('observed_ymds'), default=[], blank=True, null=True, help_text='已测温日期') observed_days = models.IntegerField(_('observed_days'), default=0, help_text='已测温天数') temperature = models.FloatField(_('temperature'), default=0, help_text='用户体温') last_submit_at = models.DateTimeField(_('last_submit_at'), blank=True, null=True, help_text='上一次上报时间') leave_at = models.DateTimeField(_('leave_at'), blank=True, null=True, help_text='离开时间') remark = models.CharField(_('remark'), max_length=255, blank=True, null=True, help_text='备注') remarks = JSONField(_('remarks'), default=[], blank=True, null=True, help_text='备注') class Meta: verbose_name = _('隔离点用户录入信息') verbose_name_plural = _('隔离点用户录入信息') unique_together = ( ('point_id', 'user_id'), ) def __unicode__(self): return self.pk @property def temperature_has_upload(self): if not self.last_submit_at: return IsolationPointUserInfo.HAS_NOT_UPLOAD if self.last_submit_at > tc.utc_datetime(hours=-1): return IsolationPointUserInfo.HAS_YET_UPLOAD return IsolationPointUserInfo.HAS_NOT_UPLOAD @property def data(self): return { 'pk': self.pk, 'point_id': self.point_id, 'user_id': self.user_id, 'fields': self.fields, 'observed_days': self.observed_days, 'temperature_has_upload': self.temperature_has_upload, 'temperature': self.temperature, 'last_submit_at': tc.local_string(utc_dt=self.last_submit_at, format='%m-%d %H:%M') if self.last_submit_at else '', 'remark': self.remark or '', } class ThermometerEquipmentInfo(BaseModelMixin): ONLINE = 1 OFFLINE = 0 ACTIVE_STATUE_TUPLE = ( (ONLINE, '已激活'), (OFFLINE, '已离线'), ) eqpt_id = ShortUUIDField(_('eqpt_id'), max_length=32, blank=True, null=True, help_text='设备唯一标识', db_index=True, unique=True) point_id = models.CharField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True) macid = models.CharField(_('macid'), max_length=32, blank=True, null=True, help_text='设备号') sn = models.CharField(_('sn'), max_length=32, blank=True, null=True, help_text='序列号') active_status = models.IntegerField(_('active_status'), choices=ACTIVE_STATUE_TUPLE, default=OFFLINE, help_text='激活状态') active_at = models.DateTimeField(_('active_at'), blank=True, null=True, help_text='激活时间') # 用户基本信息 ipui_pk = models.IntegerField(_('ipui_pk'), default=0, help_text='隔离点用户录入PK') class Meta: verbose_name = _('测温设备信息') verbose_name_plural = _('测温设备信息') def __unicode__(self): return self.pk @property def data(self): return { 'eqpt_id': self.eqpt_id, 'point_id': self.point_id, 'macid': self.macid, 'sn': self.sn, 'active_status': self.active_status, 'active_status_str': dict(self.ACTIVE_STATUE_TUPLE).get(self.active_status, ''), 'active_at': tc.local_string(utc_dt=self.active_at), 'ipui_pk': self.ipui_pk, 'created_at': tc.local_string(utc_dt=self.created_at), } @property def screen_data(self): return { 'point_id': self.point_id, 'macid': self.macid, 'remark': self.remark, 'last_submit_at': tc.local_string(utc_dt=self.last_submit_at, format='%m-%d %H:%M') if self.last_submit_at else '', } class ThermometerMeasureLogInfo(BaseModelMixin): CALLBACK = 1 MQTT = 2 TEMPERATURE_SRC_TUPLE = ( (CALLBACK, '接口回调'), (MQTT, 'MQTT'), ) point_id = models.CharField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True) macid = models.CharField(_('macid'), max_length=32, blank=True, null=True, help_text='设备号') sn = models.CharField(_('sn'), max_length=32, blank=True, null=True, help_text='序列号') name = models.CharField(_('name'), max_length=255, blank=True, null=True, help_text='用户姓名') sex = models.IntegerField(_('sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.UNKNOWN, help_text='用户性别') birth_stamp = models.BigIntegerField(_('birth_stamp'), default=0, help_text='生日时间戳') phone = models.CharField(_('phone'), max_length=11, blank=True, null=True, help_text='用户电话', db_index=True) start_stamp = models.BigIntegerField(_('start_stamp'), default=0, help_text='测温开始时间戳') end_stamp = models.BigIntegerField(_('end_stamp'), default=0, help_text='测温结束时间戳') temperature = models.FloatField(_('temperature'), default=0, help_text='用户体温') temperature_src = models.IntegerField(_('temperature_src'), choices=TEMPERATURE_SRC_TUPLE, default=CALLBACK, help_text='用户体温来源') upload_temperature_info = models.TextField(_('upload_temperature_info'), blank=True, null=True, help_text='测温结果上传信息') class Meta: verbose_name = _('测温记录信息') verbose_name_plural = _('测温记录信息') def __unicode__(self): return self.pk @property def data(self): return { 'point_id': self.point_id, 'macid': self.macid, 'sn': self.sn, 'temperature': self.temperature, }