説明なし

models.py 9.4KB

    # -*- 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 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='隔离点名称') # [{"start": "8:00", "end": "9:00"}, {"start": "12:00", "end": "14:00"}] point_measure_window = JSONField(_('point_measure_window'), default=[], 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): return { 'point_id': self.point_id, 'point_name': self.point_name, 'point_measure_window': self.point_measure_window, } @property def current_measure_window(self): current_ymd = tc.local_string(format='%Y-%m-%d') current_dt = tc.utc_datetime() for window in self.point_measure_window: start_t, end_t = window.get('start'), window.get('end') start_dt = tc.string_to_utc_datetime(f'{current_ymd} {start_t}:00') end_dt = tc.string_to_utc_datetime(f'{current_ymd} {end_t}:00') if tc.utc_datetime(start_dt, minutes=-30) < current_dt < tc.utc_datetime(end_dt, minutes=30): return f'{start_t}-{end_t}' return '' class IsolationPointUserInfo(BaseModelMixin): 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='字段信息') class Meta: verbose_name = _('隔离点用户录入信息') verbose_name_plural = _('隔离点用户录入信息') unique_together = ( ('point_id', 'user_id'), ) def __unicode__(self): return self.pk @property def data(self): return { 'point_id': self.point_id, 'user_id': self.user_id, 'fields': self.fields, } class ThermometerEquipmentInfo(BaseModelMixin): ONLINE = 1 OFFLINE = 0 ACTIVE_STATUE_TUPLE = ( (ONLINE, '已激活'), (OFFLINE, '已离线'), ) SUCCESS = 1 FAIL = 0 REGISTER_STATUE_TUPLE = ( (SUCCESS, '注册成功'), (FAIL, '注册失败'), ) 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') 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='生日时间戳') age = models.IntegerField(_('age'), default=0, help_text='用户年龄') phone = models.CharField(_('phone'), max_length=11, blank=True, null=True, help_text='用户电话', db_index=True) remark = models.CharField(_('remark'), max_length=255, blank=True, null=True, help_text='备注') last_submit_at = models.DateTimeField(_('last_submit_at'), blank=True, null=True, help_text=_('上一次上报时间')) eqpt_register_status = models.IntegerField(_('eqpt_register_status'), choices=REGISTER_STATUE_TUPLE, default=FAIL, help_text='设备注册状态') eqpt_register_result = models.TextField(_('eqpt_register_result'), blank=True, null=True, help_text='设备注册结果') 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), 'name': self.name or '', 'sex': self.sex, 'sex_str': dict(SexModelMixin.SEX_TUPLE).get(self.sex, ''), 'age': self.age or '', 'phone': self.phone or '', 'remark': self.remark or '', 'last_submit_at': tc.local_string(utc_dt=self.last_submit_at), 'eqpt_register_status': self.eqpt_register_status, 'eqpt_register_status_str': dict(self.REGISTER_STATUE_TUPLE).get(self.eqpt_register_status, ''), 'eqpt_register_result': self.eqpt_register_result, 'created_at': tc.local_string(utc_dt=self.created_at), } class ThermometerMeasureInfo(BaseModelMixin): point_id = models.CharField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True) point_measure_ymd = models.CharField(_('point_measure_ymd'), max_length=10, blank=True, null=True, help_text='隔离点测温日期', db_index=True) point_measure_window = models.CharField(_('point_measure_window'), max_length=16, 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='序列号') temperature = models.FloatField(_('temperature'), default=0, help_text='用户体温') class Meta: verbose_name = _('测温信息') verbose_name_plural = _('测温信息') unique_together = ( ('point_id', 'point_measure_ymd', 'point_measure_window', 'macid') ) def __unicode__(self): return self.pk @property def data(self): return { 'point_id': self.point_id, 'point_measure_window': self.point_measure_window, 'macid': self.macid, 'sn': self.sn, 'temperature': self.temperature, } 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, }