from itertools import chain
from Service.CommonService import CommonService
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser
from django.db import models
from django.utils import six, timezone
from django.utils.encoding import python_2_unicode_compatible
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill

from Ansjer.config import SERVER_DOMAIN
from django.utils import timezone


class PermissionsManager(models.Manager):
    use_in_migrations = True

    def get_by_natural_key(self, permName):
        return self.get(
            permName=permName
        )


class RoleManager(models.Manager):
    """
    The manager for the auth's Role model..
    """
    use_in_migrations = True

    def get_by_natural_key(self, roleName):
        return self.get(roleName=roleName)


class UserManager(BaseUserManager):

    def create_user(self, username, password, userID, is_active,
                    user_isValid, **extra_fields):
        user = self.model(
            username=username,
            userID=userID,
            is_active=is_active,
            user_isValid=user_isValid,
            **extra_fields
        )
        user.set_password(password)
        user.save(using=self._db)

        role = Role.objects.get(rid=1)
        user.role.add(role)
        return user

    def create_superuser(self, username, password, userID, is_active,
                         user_isValid, **extra_fields):
        # extra_fields.setdefault('is_superuser', is_superuser)
        is_superuser = extra_fields.get('is_superuser', None)
        if is_superuser != 100 and is_superuser != 1:
            raise ValueError('Superuser must have is_superuser=1 or 100.')

        return self.create_user(username, password, userID, is_active,
                                user_isValid, **extra_fields)


@python_2_unicode_compatible
class Permissions(models.Model):
    permName = models.CharField(blank=True, null=True, max_length=32, unique=True, verbose_name=u'权限名称')
    description = models.CharField(blank=True, null=True, max_length=128, verbose_name=u'描述信息', default='')
    objects = PermissionsManager()

    def __str__(self):
        return "%s" % (
            six.text_type(self.description))

    class Meta:
        ordering = ['permName']
        db_table = 'permissions'
        verbose_name = u'role permission'
        verbose_name_plural = verbose_name
        unique_together = (('permName'),)

    def natural_key(self):
        return (self.permName)


class Role(models.Model):
    rid = models.SmallIntegerField(primary_key=True, unique=True, verbose_name=u'用户角色组ID')
    roleName = models.CharField(max_length=32, unique=True,
                                default='User', verbose_name=u'角色名称')
    permission = models.ManyToManyField(to='Permissions', blank=True, verbose_name=u'权限', db_table='role_permissions')
    Description = models.TextField(blank=True, default='', verbose_name=u'描述信息')

    objects = RoleManager()

    class Meta:
        ordering = ['roleName']
        db_table = 'role'
        verbose_name = u'用户角色'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.roleName

    def natural_key(self):
        return (self.roleName,)

    def get_all_permission(self):
        perms = self.permission.all()

        permslist = []
        if self.rid == 100:
            perms = Permissions.objects.all()
            for perm in perms:
                permslist.append(perm.permName)
            return permslist
        else:
            permlist_tmp = []
            for perm in perms:
                permlist_tmp.append(perm.permName)
            permSet = set(permlist_tmp)
            permslist = list(permSet)
            permslist.sort()
            return permslist


class Device_User(AbstractBaseUser):
    userID = models.CharField(blank=True, max_length=32, primary_key=True,
                              verbose_name=u'用户ID', unique=True)
    role = models.ManyToManyField(to='Role', blank=True, verbose_name=u'用户角色', db_table='user_role')

    username = models.CharField(max_length=64, verbose_name=u'用户名', default='', blank=True)
    password = models.CharField(max_length=128, verbose_name=u'密码')
    userEmail = models.EmailField(max_length=64, verbose_name=u'邮箱', default='', blank=True)
    # 实际的路径就是 MEDIA_ROOT/Image/filename,所以可用upload_to来指定文件存放的前缀路径
    userIconPath = ProcessedImageField(blank=True, upload_to='User/Images/', default='static/User/default.png',
                                       verbose_name=u'头像',
                                       # 图片将处理成85x85的尺寸
                                       processors=[ResizeToFill(85, 85)], )
    userIconUrl = models.URLField(blank=True, max_length=128, default=SERVER_DOMAIN
                                                                      + 'account/getAvatar/User/defaultUser.png')
    NickName = models.CharField(blank=True, max_length=64, default='', verbose_name=u'用户昵称')
    is_superuser = models.IntegerField(blank=True, default=0, verbose_name=u'用户类型')
    is_active = models.BooleanField(blank=True, default=False, verbose_name=u'用户活动状态')
    data_joined = models.DateTimeField(blank=True, verbose_name=u'加入时间', auto_now_add=True)
    last_login = models.DateTimeField(blank=True, verbose_name='u最后登录时间', auto_now=True)
    user_isValid = models.BooleanField(blank=True, default=False, verbose_name=u'用户有效性', help_text=u'是否是认证通过的用户')
    online = models.BooleanField(blank=True, default=False, verbose_name=u'用户登录状态')
    machine_code = models.CharField(blank=True, max_length=128, default='', verbose_name=u'机械码')

    language = models.CharField(blank=True, max_length=16, default='en', verbose_name=u'语言地区')
    # 手机注册增加字段
    phone = models.CharField(max_length=16, verbose_name=u'手机号', default='', blank=True)
    fingerprint_enable = models.SmallIntegerField(default=0, verbose_name=u'是否开启了指纹登录') # 0：未开启，1：已开启
    fingerprint_key = models.CharField(max_length=128, default='', verbose_name=u'客户端用于解码的密钥等信息')
    objects = UserManager()

    USERNAME_FIELD = 'userID'  # 必须有一个唯一标识
    REQUIRED_FIELDS = ['is_superuser']  # 创建superuser时的必须字段

    class Meta:
        ordering = ('-data_joined',)
        verbose_name = u'用户信息'
        db_table = 'device_user'
        get_latest_by = 'last_login'

    def __str__(self):
        return self.username

    def get_role_id(self):
        rids = []
        roles = self.role.all()
        for role in roles:
            rids.append(role.rid)
        return rids

    def get_all_permission(self):
        roles = self.role.all()
        perms = self.permission.all()

        permslist = []
        for role in roles:
            if role.rid == 100:
                perms = Permissions.objects.all()
                for perm in perms:
                    permslist.append(perm.permName)
                return permslist

        for perm in perms:
            permslist.append(perm.permName)

        permSet = set(permslist)
        for role in roles:
            permlist_tmp = []
            for perm in role.permission.all():
                permlist_tmp.append(perm.permName)

            permSet_tmp = set(permlist_tmp)
            permSet = permSet.union(permSet_tmp)
            permslist = list(permSet)
            permslist.sort()
            return permslist

    @property
    def is_staff(self):
        return self.is_superuser


# 设备表是建项目开发者设计的,自己看着办
# 谢谢提醒！我选择凉拌。
class Device_Info(models.Model):
    id = models.CharField(blank=True, max_length=32, primary_key=True)
    userID = models.ForeignKey(Device_User, blank=True, to_field='userID', on_delete=models.CASCADE)
    NickName = models.CharField(blank=True, max_length=32, verbose_name=u'设备名称')
    UID = models.CharField(blank=True, max_length=32, verbose_name=u'设备UID', default='')
    SID = models.CharField(blank=True, max_length=32, verbose_name=u'服务器ID', default='')
    View_Account = models.CharField(blank=True, max_length=32, verbose_name=u'设备用户名称', default='')
    View_Password = models.CharField(blank=True, max_length=32, verbose_name=u'设备密码', default='')
    AudioFormat = models.IntegerField(blank=True, default=1, verbose_name=u'初始化影像')
    EventNotification = models.IntegerField(blank=True, verbose_name=u'报警类型', default=0)
    ChannelIndex = models.IntegerField(blank=True, verbose_name=u'通道号', default=0)
    Online = models.BooleanField(blank=True, default=False, verbose_name=u'设备是否在线')
    mMonitorIndex = models.IntegerField(blank=True, default=-1)
    Type = models.IntegerField(blank=True, verbose_name='设备类型')
    DebugMode = models.IntegerField(blank=True, verbose_name=u'调试模式', default=0)
    NotificationMode = models.IntegerField(blank=True, verbose_name=u'是否报警', default=0)
    qvgaLevel = models.BooleanField(blank=True, verbose_name=u'SD与HD画面', default=0,
                                    help_text=u'0代表：SD、1代表：HD')
    isShare = models.BooleanField(blank=True, verbose_name=u'共享设备',
                                  help_text=u'是否为共享获取的设备', default=False)
    primaryUserID = models.CharField(blank=True, verbose_name='主用户id', max_length=32, default='')
    primaryMaster = models.CharField(max_length=64, verbose_name=u'主用户名', default='')
    data_joined = models.DateTimeField(blank=True, verbose_name=u'设备添加时间', auto_now_add=True)
    update_time = models.DateTimeField(blank=True, verbose_name=u'更新时间', auto_now=True, null=True)

    ip = models.CharField(blank=True, max_length=20, default='', verbose_name=u'设备区域ip')
    area = models.CharField(blank=True, max_length=100, default='', verbose_name=u'设备区域area')
    # ios要求新增字段
    version = models.CharField(blank=True, max_length=20, default='', verbose_name=u'版本号')
    iSNotification = models.BooleanField(blank=True, verbose_name=u'报警通知 0:关闭,1:开启)', default=False)
    isVod = models.SmallIntegerField(blank=True, default=0, verbose_name='是否支持云存')  # 是否支持云存设备
    isExist = models.SmallIntegerField(blank=True, default=1, verbose_name='是否被删除')  # 是否被删除了(需主用户交互) 1存在，0不存在，2设备被重置
    ###
    REQUIRED_FIELDS = []

    def __str__(self):
        return self.NickName

    def model_to_dict(self, fields=None, exclude=None):
        opts = self._meta
        data = {}
        for f in chain(opts.concrete_fields, opts.private_fields, opts.many_to_many):
            if not getattr(f, 'editable', False):
                continue
            if fields and f.name not in fields:
                continue
            if exclude and f.name in exclude:
                continue
            data[f.name] = f.value_from_object(self)
        return data

    class Meta:
        db_table = 'device_info'
        ordering = ('-data_joined',)
        verbose_name = u'用户设备信息表'
        verbose_name_plural = verbose_name


class Access_Log(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    user = models.CharField(max_length=100, default='', db_index=True, blank=True, verbose_name=u'用户')
    operation = models.CharField(max_length=100, db_index=True, default='', blank=True, verbose_name=u'操作')
    ip = models.CharField(max_length=100, default='', db_index=True, blank=True, verbose_name=u'访问ip地址')
    url = models.CharField(max_length=150, default='', blank=True, verbose_name=u'访问路径')
    status = models.IntegerField(default=0, blank=True, verbose_name=u'状态')
    time = models.DateTimeField(null=True, blank=True, db_index=True, verbose_name=u'访问时间')
    content = models.TextField(blank=True, default='', verbose_name=u'参数内容')

    class Meta:
        db_table = 'access_log'
        verbose_name = u'访问日志表'
        verbose_name_plural = verbose_name


class Equipment_Info(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    devUid = models.CharField(default='', db_index=True, blank=True, max_length=32, verbose_name=u'设备ID')
    devNickName = models.CharField(blank=True, max_length=32, default='', verbose_name=u'设备昵称')
    Channel = models.IntegerField(default=1, blank=True, verbose_name=u'设备通道')
    eventType = models.IntegerField(default=0, blank=True, verbose_name=u'事件类型')
    status = models.BooleanField(blank=True, default=False, verbose_name=u'事件状态')
    alarm = models.CharField(blank=True, max_length=256, verbose_name=u'报警信息')
    eventTime = models.CharField(blank=True, default='', max_length=16, verbose_name=u'设备报警时间')
    receiveTime = models.CharField(blank=True, default='', max_length=16, verbose_name=u'接收到报警时间')
    userID_id = models.CharField(default='',  db_index=True,blank=True, max_length=32, verbose_name=u'用户ID')
    is_st = models.SmallIntegerField(default=0, verbose_name='是否截图')  # 0 否,1 是图，2,视频
    message_id = models.CharField(max_length=32, default='', verbose_name='第三方推送服务器返回的id')
    push_type = models.SmallIntegerField(default=0, verbose_name='第三方推送服务器标志。0：APNS推送，1：谷歌推送，2：极光推送')
    push_server_status = models.IntegerField(default=200, verbose_name='是否成功推送到第三方服务器。200：成功，other：失败')
    push_device_status = models.SmallIntegerField(default=-1, verbose_name='是否成功推送到目标设备。0：失败，1：成功')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'equipment_info'
        verbose_name = u'设备信息推送表'
        verbose_name_plural = verbose_name
        ordering = ('-id',)
        app_label = "db2"

class StatResModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自动ID')
    name = models.CharField(default='', max_length=120, verbose_name='图片名称', unique=True)
    addTime = models.IntegerField(verbose_name='添加时间', default=0)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'statres'
        verbose_name = '静态资源表'
        verbose_name_plural = verbose_name
        ordering = ('id',)


class FeedBackModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    userID = models.ForeignKey(Device_User, null=True, blank=True, to_field='userID', on_delete=models.CASCADE)
    type = models.SmallIntegerField(default=0, verbose_name='反馈类型')  # 【0:产品建议,1:功能异常,2:安全问题】
    status = models.SmallIntegerField(default=0, verbose_name='状态:0未解决/解决')
    content = models.TextField(blank=True, null=True, verbose_name=u'反馈描述')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)
    FS = models.ManyToManyField(to='StatResModel', blank=True, verbose_name=u'用户反馈关联资源',
                                db_table='fb_res')
    app = models.CharField(max_length=8, default='', verbose_name='类型')  # [ios,android]
    phone_model = models.CharField(max_length=64, default='', verbose_name='手机型号')  # [小米,android]
    os_version = models.CharField(max_length=16, default='', verbose_name='系统版本')
    uid = models.CharField(max_length=20, default='', verbose_name='设备uid')
    product_type = models.CharField(max_length=32, default='', verbose_name='设备uid')
    app_version = models.CharField(max_length=32, default='', verbose_name='app版本信息')

    appBundleId = models.CharField(max_length=32, default='', verbose_name='app版本appBundleId')
    email = models.CharField(max_length=32, default='', verbose_name='app版本email')
    score = models.CharField(max_length=32, default='0', verbose_name='评分--星星数')

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'feedback'
        verbose_name = u'用户反馈信息表'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


class User_Brand(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    # 关联用户
    userID = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE)
    deviceSupplier = models.CharField(max_length=32, default='', verbose_name='（必填）设备供应商 string  （例：华为、小米...）')
    deviceModel = models.CharField(max_length=64, default='', verbose_name='（必填）设备型号 string @mock=HM NOTE 1TD')
    osType = models.CharField(max_length=32, default='', verbose_name='（必填）操作系统名称 string @mock=Android')
    osVersion = models.CharField(max_length=32, default='', verbose_name='（必填）操作系统版本号 string @mock=4.0')

    country = models.CharField(max_length=200, default='', verbose_name='国家')
    province = models.CharField(max_length=150, default='', verbose_name='省')
    city = models.CharField(max_length=132, default='', verbose_name='市')
    area = models.CharField(max_length=132, default='', verbose_name='区')
    street = models.CharField(max_length=132, default='', verbose_name='街道')

    longitude = models.CharField(max_length=30, default='', verbose_name='经度')
    latitude = models.CharField(max_length=30, default='', verbose_name='纬度')
    appId = models.CharField(max_length=50, default='', verbose_name='appid_值')
    status = models.IntegerField(default=0, verbose_name='传国家省市信息过来就为状态：1 ，不传就为状态：0')
    ip = models.CharField(blank=True, max_length=20, default='', verbose_name=u'区域ip')

    addTime = models.IntegerField(verbose_name='添加时间', default=0)

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'user_brand'
        verbose_name = u'用户登录手机端手机品牌统计表'
        verbose_name_plural = verbose_name
        ordering = ('id',)


# 存储通表
class VodBucketModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='主键')
    bucket = models.CharField(max_length=30, verbose_name='设备UID')
    storeDay = models.IntegerField(default=0, verbose_name='存储生命周期(天)')
    content = models.TextField(verbose_name='描述', default='')
    endpoint = models.CharField(max_length=125, default='', verbose_name='存储节点')
    area = models.CharField(max_length=16, default='', verbose_name='区域')
    region = models.CharField(max_length=16, default='', verbose_name='regionID')

    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    mold = models.SmallIntegerField(default=0, verbose_name='存储区域类型')  # 0：国内阿里 1：国外aws

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'vod_bucket'
        verbose_name = u'存储通信息'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


class Store_Meal(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增ID')
    title = models.CharField(blank=True, max_length=32, verbose_name=u'标题')
    currency = models.CharField(blank=True, default='USD', max_length=32, verbose_name=u'货币')
    price = models.CharField(blank=True, max_length=32, verbose_name=u'价格')
    day = models.IntegerField(default=0, blank=True, verbose_name=u'套餐天数')
    content = models.TextField(blank=True, null=True, verbose_name=u'描述')
    add_time = models.DateTimeField(blank=True, null=True, verbose_name=u'加入时间', auto_now_add=True)
    type = models.SmallIntegerField(default=0, verbose_name='付款类型')  # 0 是paypal,1为支付宝
    update_time = models.DateTimeField(blank=True, verbose_name=u'更新时间', auto_now=True)
    bucket = models.ForeignKey(VodBucketModel, blank=True, to_field='id', on_delete=models.CASCADE,
                               default=1, verbose_name='存储空间')
    commodity_type = models.SmallIntegerField(default=0, verbose_name='云存储套餐类型')  # 0：事件型 1：连续型
    commodity_code = models.CharField(default='', max_length=32, verbose_name='套餐规格码')

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'store_meal'
        verbose_name = u'存储套餐'
        verbose_name_plural = verbose_name
        ordering = ('id',)


class Equipment_Version(models.Model):
    eid = models.CharField(blank=True, max_length=32, primary_key=True)
    ESN = models.CharField(blank=True, max_length=32, verbose_name=u'设备规格名称')
    code = models.CharField(blank=True, max_length=64, verbose_name=u'设备规格代码')
    version = models.CharField(blank=True, max_length=64, verbose_name=u'设备版本')
    softwareVersion = models.CharField(blank=True, max_length=32, verbose_name=u'软件版本')
    chipModelList2Code = models.CharField(max_length=32, blank=True, verbose_name=u'主芯片码')
    channel = models.IntegerField(blank=True, verbose_name=u'通道数')
    resolutionRatio = models.IntegerField(blank=True, verbose_name=u'分辨率')
    type = models.CharField(blank=True, max_length=16, verbose_name=u'设备机型')
    companyCode = models.CharField(blank=True, max_length=128, verbose_name=u'用户公司名称')
    data_joined = models.DateTimeField(blank=True, verbose_name=u'加入时间', auto_now_add=True)
    fileSize = models.IntegerField(blank=True, verbose_name=u'文件总大小')
    filePath = models.CharField(blank=True, max_length=256, verbose_name=u'升级文件路径')
    Description = models.TextField(blank=True, default='', verbose_name=u'描述信息')
    fileMd5 = models.CharField(blank=True, max_length=32, default='', verbose_name=u'上传文件MD5加密')
    status = models.BooleanField(blank=True, default=True, verbose_name=u'是否开启更新状态')
    update_time = models.DateTimeField(blank=True, verbose_name=u'更新时间', auto_now=True)
    lang = models.CharField(blank=True, default='en', max_length=32, verbose_name=u'ota包内置语言')
    mci = models.CharField(default='', blank=True, max_length=10, verbose_name='设备类型')
    img = models.CharField(max_length=300, blank=True, default='', verbose_name=u'图片路径')
    max_ver = models.CharField(default='', max_length=16, verbose_name='最大版本号')

    def __str__(self):
        return self.eid

    class Meta:
        verbose_name = '设备版本信息'
        ordering = ('-data_joined',)
        db_table = 'equipment_version'


class App_Info(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    appBundleId = models.CharField(blank=True, max_length=32, verbose_name=u'appID')
    appName = models.CharField(blank=True, max_length=32, verbose_name=u'app名称')
    systemLanguage = models.CharField(blank=True, max_length=32, verbose_name=u'系统语言')
    newAppversion = models.CharField(blank=True, max_length=12, verbose_name=u'系统版本')
    minAppversion = models.CharField(default='', blank=True, max_length=12, verbose_name=u'最小系统版本')
    bundleVersion = models.CharField(blank=True, max_length=12, verbose_name=u'项目版本')
    content = models.TextField(blank=True, default='', verbose_name=u'更新内容')
    app_type = models.IntegerField(default=0, blank=True, verbose_name=u'app类型')  # ios 1,android 2
    add_time = models.DateTimeField(blank=True, null=True, verbose_name=u'加入时间', auto_now_add=True)
    update_time = models.DateTimeField(blank=True, verbose_name=u'更新时间', auto_now=True)
    downloadLink = models.CharField(max_length=300, blank=True, default='', verbose_name='升级')
    img = models.CharField(default='', max_length=128, verbose_name='图片路径')

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'app_info'
        verbose_name = u'app信息表'
        verbose_name_plural = verbose_name
        ordering = ('id',)


class App_Colophon(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    app_id = models.ForeignKey(App_Info, to_field='id', on_delete=models.CASCADE, verbose_name='appid编号', blank=True,
                               default=1)
    lang = models.CharField(blank=True, max_length=32, verbose_name=u'系统语言')
    newApp_version = models.CharField(blank=True, max_length=12, verbose_name=u'系统版本')
    content = models.TextField(blank=True, default='', verbose_name=u'更新内容')
    version_time = models.IntegerField(default=0, blank=True, verbose_name=u'版本更新的时间')

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'app_colophon'
        verbose_name = u'app信息表的记录关联到App_Info'
        verbose_name_plural = verbose_name
        ordering = ('id',)


class Order_Model(models.Model):
    orderID = models.CharField(blank=True, max_length=20, primary_key=True, verbose_name=u'订单id')
    trade_no = models.CharField(blank=True, max_length=32, default='', verbose_name='第三方订单号')
    # 订单关联用户
    userID = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE)
    UID = models.CharField(max_length=20, verbose_name='设备UID')
    channel = models.SmallIntegerField(default=0, verbose_name=u'通道数')
    desc = models.CharField(max_length=50, default='', verbose_name='商品描述')
    price = models.CharField(default='', max_length=16, verbose_name='价格')
    currency = models.CharField(blank=True, default='USD', max_length=32, verbose_name=u'货币')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)
    endTime = models.IntegerField(verbose_name='结束时间', default=0)
    status = models.SmallIntegerField(default=0, verbose_name='付款状态')  # 0:待支付，1：成功，2：取消，3：已退款
    payType = models.SmallIntegerField(default=0, verbose_name='付款类型0:paypal,1:alipay')
    payTime = models.IntegerField(verbose_name='支付成功时间', default=0)
    rank = models.ForeignKey(Store_Meal, to_field='id', default='', on_delete=models.CASCADE, verbose_name='套餐类型')
    nickname = models.CharField(default='', max_length=64, verbose_name='设备昵称')
    uid_bucket_id = models.IntegerField(default=0, verbose_name='关联uid_bucket的字段')
    commodity_type = models.SmallIntegerField(default=0, verbose_name='云存储套餐类型')
    commodity_code = models.CharField(default='', max_length=32, verbose_name='套餐规格码')
    pay_url = models.CharField(max_length=1000, default='', verbose_name='支付url')
    paypal = models.CharField(max_length=500, null=True, blank=True, verbose_name='支付批准url')


    def __str__(self):
        return self.orderID

    class Meta:
        db_table = 'orders'
        verbose_name = u'订单信息表'
        verbose_name_plural = verbose_name
        ordering = ('-orderID',)


class VodHlsModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='回放列表主键')
    uid = models.CharField(max_length=20, verbose_name='设备UID')
    channel = models.SmallIntegerField(default=0, verbose_name='通道')
    time = models.IntegerField(verbose_name='播放列表名字时间戳', default=0, db_index=True)
    endTime = models.IntegerField(verbose_name='删除时间', default=0)
    sec = models.IntegerField(verbose_name='秒数', default=0)
    bucket = models.ForeignKey(VodBucketModel, blank=True, to_field='id', on_delete=models.CASCADE, default=1,
                               verbose_name='存储空间')
    fg = models.SmallIntegerField(default=0,verbose_name='时间片段数') # 0为阿里云存储方案 >0为亚马逊方案


    def __str__(self):
        return self.id

    class Meta:
        db_table = 'vod_hls'
        verbose_name = u'云存回放信息表'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


class OssCrdModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='主键')
    uid = models.CharField(max_length=20, verbose_name='设备UID')
    channel = models.SmallIntegerField(default=0, verbose_name='通道')
    data = models.TextField(verbose_name='设备sts')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    bucket = models.ForeignKey(VodBucketModel, blank=True, to_field='id', on_delete=models.CASCADE, default=1,
                               verbose_name='存储空间')

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'osscrd'
        verbose_name = u'设备证书'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


class StsCrdModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='主键')
    uid = models.CharField(max_length=20, verbose_name='设备UID')
    channel = models.SmallIntegerField(default=0, verbose_name='通道')
    data = models.TextField(verbose_name='设备sts')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    bucket = models.ForeignKey(VodBucketModel, blank=True, to_field='id', on_delete=models.CASCADE, default=1,
                               verbose_name='存储空间')
    type = models.SmallIntegerField(default=0,verbose_name='sts类型') # 0:阿里云,1:s3

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'stscrd'
        verbose_name = u'设备证书'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


class UID_Bucket(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    uid = models.CharField(max_length=20, verbose_name='设备UID')
    channel = models.SmallIntegerField(default=0, verbose_name='通道')
    bucket = models.ForeignKey(VodBucketModel, blank=True, to_field='id', on_delete=models.CASCADE, verbose_name='存储空间')
    status = models.SmallIntegerField(default=0, verbose_name='状态[0:开启,1:关闭]')
    endTime = models.IntegerField(verbose_name='结束时间', default=0)

    class Meta:
        db_table = 'vod_uid_bucket'
        verbose_name = '设备关联套餐表'
        verbose_name_plural = verbose_name
        ordering = ('id',)


class UID_Preview(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    uid = models.CharField(default='', max_length=20, db_index=True, verbose_name='设备UID')
    channel = models.SmallIntegerField(verbose_name=u'通道号', default=0)
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        db_table = 'uid_preview'
        verbose_name = '设备预览图'
        verbose_name_plural = verbose_name
        ordering = ('id',)


# 系统发送信息新到用户
class SysMsgModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    userID_id = models.CharField(default='', db_index=True,blank=True, max_length=32, verbose_name=u'用户ID')
    msg = models.TextField(blank=True, default='', verbose_name=u'发送内容')
    status = models.SmallIntegerField(verbose_name='是否已读', default=0)  # 0:否,1:是
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)
    eventType = models.IntegerField(verbose_name='消息类型', default=0)  # 默认系统消息类型,0系统消息，1 ipcamera消息
    uid = models.CharField(default='', max_length=20, db_index=True, verbose_name='设备UID')

    class Meta:
        db_table = 'sys_msg'
        verbose_name = '系统消息'
        verbose_name_plural = verbose_name
        ordering = ('-id',)
        app_label = "db2"


# 设备推送重构
# 设备配置表，新
class UidSetModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
    uid = models.CharField(max_length=20, db_index=True, unique=True, verbose_name='设备UID')
    channel = models.SmallIntegerField(default=0, verbose_name='通道数量')  #
    detect_status = models.SmallIntegerField(default=0, verbose_name='推送开关')  # 状态[0:关闭,1:开启,2:用户解绑]
    detect_interval = models.IntegerField(verbose_name='推送间隔', default=60)  # 秒
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)
    ucode = models.CharField(max_length=32, verbose_name='设备产品码', default='')
    version = models.CharField(max_length=32, verbose_name='设备版本', default='')
    p2p_region = models.CharField(max_length=16, verbose_name='设备p2p区域', default='ALL')  # ALL CN EU US
    cloud_vod = models.SmallIntegerField(default=2, verbose_name='云存开关')  # 0,关闭，1开启，2,不支持
    tz = models.CharField(default='', max_length=16, verbose_name ='设备时区')  # +8
    video_code = models.SmallIntegerField(default=0, verbose_name='编码类型')  # 0:264,1:265
    nickname = models.CharField(default='', max_length=64, verbose_name='设备昵称')
    ip = models.CharField(max_length=20, default='', verbose_name=u'设备ip')
    # 设备重置后第一次启动时间
    is_alexa = models.IntegerField(default=0, verbose_name='是否支持alexa')  # 0为不支持，1为支持，2为开启alexa发现
    detect_group = models.CharField(default='', max_length=32, verbose_name=u'检测类型')
    pwd = models.CharField(max_length=32, default='', verbose_name=u'设备密码') # 暂时是预留字段
    resetTime = models.IntegerField(default=0, verbose_name='设备重置时间')
    region_alexa = models.CharField(max_length=8, verbose_name='设备alexa区域', default='ALL')  # ALL CN EU US
    deviceModel = models.CharField(blank=True, max_length=64, default='', verbose_name=u'设备型号')
    TimeZone = models.CharField(blank=True, max_length=50, default='', verbose_name=u'时区')
    TimeStatus = models.SmallIntegerField(default=0, verbose_name='同步手机时间开关。0：关闭，1：开启')
    SpaceUsable = models.CharField(blank=True, max_length=20, default='', verbose_name=u'可用空间')
    SpaceSum = models.CharField(blank=True, max_length=20, default='', verbose_name=u'总空间')
    MirrorType = models.IntegerField(blank=True, default=0, verbose_name=u'镜像类型 0:关闭镜像,1：上下镜像，2:左右镜像，3：上下左右镜像')
    RecordType = models.IntegerField(blank=True, default=0, verbose_name=u'录像模式(0:关闭,1:全是录像,3:报警录像)')
    OutdoorModel = models.IntegerField(blank=True, default=0, verbose_name=u'室外模式 0：关闭，1：开启')
    WIFIName = models.CharField(blank=True, max_length=50, default='', verbose_name=u'无线名称')
    isDetector = models.SmallIntegerField(default=0, verbose_name=u'侦测开关0:关闭,1:开启')
    DetectorRank = models.IntegerField(default=0, verbose_name=u'侦测灵敏度 0:低,1:中,2:高,3:最高')

    class Meta:
        db_table = 'uid_set'
        verbose_name = u'设备配置表'
        verbose_name_plural = verbose_name
        ordering = ('id',)


# 设备关联用户推送
class UidPushModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    userID = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE)
    uid_set = models.ForeignKey(UidSetModel, to_field='id', on_delete=models.CASCADE)
    appBundleId = models.CharField(blank=True, max_length=32, verbose_name=u'appID')
    app_type = models.IntegerField(default=0, verbose_name=u'app类型 1:ios,2:安卓')
    push_type = models.IntegerField(default=0, verbose_name=u'推送类型')  # 0,apns 1,安卓gcm 2,极光
    token_val = models.CharField(default='', max_length=160, verbose_name=u'设备验证令牌')
    m_code = models.CharField(default='', max_length=64, verbose_name='手机唯一标识')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)
    lang = models.CharField(max_length=8, verbose_name='推送语言类型', default='en')  # en英文 cn中文
    tz = models.CharField(max_length=8, verbose_name='utc时区', default='0')

    class Meta:
        db_table = 'uid_push'
        verbose_name = '设备绑定'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


# 设备通道配置
class UidChannelSetModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    uid = models.ForeignKey(UidSetModel, to_field='id', on_delete=models.CASCADE)
    channel = models.IntegerField(default=1, verbose_name='通道号')
    pir_audio = models.SmallIntegerField(default=0, verbose_name='pir声音。0：关闭，1：开启')
    mic_audio = models.SmallIntegerField(default=0, verbose_name='mic声音。0：关闭，1：开启')
    battery_status = models.SmallIntegerField(default=0, verbose_name='低电量提醒状态。0：关闭，1：开启')
    battery_level = models.SmallIntegerField(default=0, verbose_name='低电量提醒级别。0: 低于10%；1：低于25%；2：低于50%；3：低于75%')
    sleep_status = models.SmallIntegerField(default=0, verbose_name='是否开启【休眠通知】。0：关闭；1：开启')
    sleep_time = models.SmallIntegerField(default=0, verbose_name='摄像机进入休眠时间。0：不休眠；1：10秒；2：20秒；3：30秒')
    light_night_model = models.IntegerField(default=0, verbose_name='夜视模式')  # 0：全彩模式，1：黑白模式，2：智能夜视模式
    light_alarm_type = models.IntegerField(default=0, verbose_name='警报人形类型')  # 0为人形，1为移动，3是人形和移动侦测0x0f
    light_alarm_level = models.IntegerField(default=0,
                                            verbose_name='声光报警级别')  # 0: 关闭，1：强烈声光告警，2：轻微声光告警，3: 强烈声告警，4:轻微声告警，5:强烈光告警
    light_alarm_man_en = models.IntegerField(default=0, verbose_name='人为告警状态')  # 0：关，1：开
    light_alarm_vol = models.IntegerField(default=0, verbose_name='报警音量')  # 音量值0-100
    light_long_light = models.IntegerField(default=0, verbose_name='长亮')

    class Meta:
        db_table = 'uid_channel'
        verbose_name = '设备通道设置'
        verbose_name_plural = verbose_name


# oauth2 第三方登录补全信息
class UserExModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    userID = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE)
    appBundleId = models.CharField(default='', max_length=32, verbose_name=u'appID')
    region = models.CharField(default='', max_length=16, verbose_name='区域语言')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    # {'cn': '简体中文', 'tc': '繁体中文', 'fr': '法文', 'ru': '俄文', 'es': '西班牙文', 'pl': '波兰文', 'ja': '日文', 'de': '德文', 'en': '英文'}

    class Meta:
        db_table = 'user_ex'
        verbose_name = '用户扩展信息表'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


# oauth2 第三方登录补全信息
class UserOauth2Model(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    userID = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE)
    authType = models.SmallIntegerField(default=0, verbose_name=0)  # 授权类型 0 非授权，1 微信授权，2 苹果授权
    unionID = models.CharField(default='', max_length=64, verbose_name='唯一标记')  # 绑定唯一标记 unionID
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    # {'cn': '简体中文', 'tc': '繁体中文', 'fr': '法文', 'ru': '俄文', 'es': '西班牙文', 'pl': '波兰文', 'ja': '日文', 'de': '德文', 'en': '英文'}

    class Meta:
        db_table = 'user_oauth2'
        verbose_name = '用户oauth2关联'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


class SysMassModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='主键自增id')
    sender = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE)  # 发送人
    platform = models.CharField(default='', verbose_name='平台', max_length=16)
    lang = models.TextField(blank=True, default='', verbose_name=u'语种')
    recever = models.TextField(blank=True, default='', verbose_name=u'接受者')
    msg = models.TextField(blank=True, default='', verbose_name=u'发送内容')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='修改时间', default=0)

    class Meta:
        db_table = 'sys_mass'
        verbose_name = '群发消息记录表'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


class UidUserModel(models.Model):
    id = models.CharField(max_length=32, primary_key=True)
    userID = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE)
    NickName = models.CharField(max_length=32, verbose_name=u'设备名称')
    UID = models.CharField(max_length=32, verbose_name=u'设备UID', default='')
    View_Account = models.CharField(max_length=32, verbose_name=u'设备用户名称', default='')
    View_Password = models.CharField(max_length=32, verbose_name=u'设备密码', default='')
    ChannelIndex = models.IntegerField(verbose_name=u'通道号', default=0)
    Type = models.IntegerField(verbose_name='设备类型')
    NotificationMode = models.IntegerField(verbose_name=u'是否报警', default=0)
    isShare = models.BooleanField(verbose_name=u'共享设备', default=False)
    primaryUserID = models.CharField(verbose_name='主用户id', max_length=32, default='')
    primaryMaster = models.CharField(max_length=64, verbose_name=u'主用户名', default='')
    data_joined = models.DateTimeField(verbose_name=u'设备添加时间', auto_now_add=True)
    version = models.CharField(max_length=20, default='', verbose_name=u'版本号')
    isVod = models.SmallIntegerField(default=0, verbose_name='是否支持云存')  # 是否支持云存设备
    isExist = models.SmallIntegerField(default=1, verbose_name='是否被删除')  # 是否被删除了(需主用户交互) 1存在，0不存在
    is_ap = models.SmallIntegerField(default=1, verbose_name='是否为ap模式添加')  # 1为ap模式添加，0为非ap模式添加

    class Meta:
        db_table = 'uid_user'
        ordering = ('-data_joined',)
        verbose_name = u'用户设备ap表'
        verbose_name_plural = verbose_name


class pushDeployModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='主键自增id')
    name = models.CharField(max_length=32, default='', verbose_name=u'推送配置名称')
    key = models.CharField(max_length=32, default='', verbose_name=u'推送配置key')
    secret = models.CharField(max_length=32, default='', verbose_name=u'推送配置密钥')
    pem = models.CharField(max_length=32, default='', verbose_name=u'推送配置路径')
    type = models.CharField(max_length=32, default='', verbose_name=u'推送配置类型')  # ios 1,android 2
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='修改时间', default=0)

    class Meta:
        db_table = 'push_deploy'
        verbose_name = '推送配置表'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


class AppSetModel(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='主键自增id')
    appBundleId = models.CharField(max_length=64, default='', verbose_name=u'APPid')
    content = models.TextField(default='', verbose_name=u'里面包含评分，用户帮助，ap添加方式，ap工具，广告模块等json字段值')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='修改时间', default=0)

    class Meta:
        db_table = 'app_set'
        verbose_name = 'app的各个版本控制表'
        verbose_name_plural = verbose_name
        ordering = ('-id',)


# 认证客户端类型表
class ApplicationModel(models.Model):
    CLIENT_TYPES = (
        ('confidential', 'confidential'),
        ('public', 'public'),
    )
    # authorization_code
    # 授权码模式(即先登录获取code, 再获取token)
    # password
    # 密码模式(将用户名, 密码传过去, 直接获取token)
    # client_credentials
    # 客户端模式(无用户, 用户向客户端注册, 然后客户端以自己的名义向’服务端’获取资源)
    # implicit
    # 简化模式(在redirect_uri
    # 的Hash传递token;
    # Auth客户端运行在浏览器中, 如JS, Flash)
    # refresh_token
    # 刷新access_token
    GRANT_TYPES = (
        ('authorization_code', "authorization_code"),
        ('password', "password"),
        ('client_credentials', "client_credentials"),
        ('implicit', "implicit"),
        ('refresh_token', "refresh_token"),
    )
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=128, blank=True, verbose_name='client名字描述')
    client_id = models.CharField(max_length=50, unique=True, verbose_name='客户端id')
    client_secret = models.CharField(max_length=50, unique=True, verbose_name='客户端secret')
    client_type = models.CharField(max_length=32, choices=CLIENT_TYPES, verbose_name='客户端类型')
    grant_type = models.CharField(max_length=32, choices=GRANT_TYPES, blank=True, null=True)
    redirect_uri = models.TextField(blank=True, null=True, verbose_name='重定向url')
    skip_auth = models.BooleanField(default=False, verbose_name='是否跳过点击授权')
    add_time = models.IntegerField(verbose_name='添加时间', default=0)
    update_time = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        ordering = ('-add_time',)
        verbose_name = u'可授权客户端表'
        db_table = 'oauth_application'


# 授权码信息表
class GrantCodeModel(models.Model):
    id = models.BigAutoField(primary_key=True)
    userID = models.ForeignKey(Device_User, verbose_name="用户表userID", to_field='userID', on_delete=models.CASCADE)
    code = models.CharField(max_length=32, unique=True)
    app_id = models.CharField(max_length=100, default='', verbose_name="appBundleId")
    application = models.ForeignKey(ApplicationModel, verbose_name="用户表id", to_field='id', on_delete=models.CASCADE)
    expire_time = models.IntegerField(verbose_name='过期时间', default=0)
    add_time = models.IntegerField(verbose_name='添加时间', default=0)
    update_time = models.IntegerField(verbose_name='更新时间', default=0)

    # 输出的永远是本地时间输出的永远是本地时间
    def is_expired(self):
        return timezone.now() >= self.expire_time

    class Meta:
        ordering = ('-add_time',)
        verbose_name = u'授权码表'
        db_table = 'oauth_grant_code'


class UserAppFrequencyModel(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE, verbose_name='关联设备用户表')
    type = models.SmallIntegerField(default=0, verbose_name='使用频率类型') # 1：每天，2：三天，3：一周，4：两周，5：一个月，6：一个月以上
    data_time = models.IntegerField(default=0, verbose_name='数据时间')
    add_time = models.IntegerField(default=0, verbose_name='添加时间')
    update_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        verbose_name = '用户使用APP频率表'
        verbose_name_plural = verbose_name
        db_table = 'user_app_frequency'
        ordering = ('-add_time',)


class AppFrequencyStatisticsModel(models.Model):
    id = models.AutoField(primary_key=True)
    data = models.TextField(default='', verbose_name='统计好的数据')
    month = models.IntegerField(default=0, verbose_name='月份')
    year = models.IntegerField(default=0, verbose_name='年份')

    class Meta:
        verbose_name = 'app月使用频率统计表'
        verbose_name_plural = verbose_name
        db_table = 'app_frequency_statistics'


class AppFrequencyYearStatisticsModel(models.Model):
    id = models.AutoField(primary_key=True)
    data = models.TextField(default='', verbose_name='统计好的数据')
    year = models.IntegerField(default=0, verbose_name='年份')
    num = models.IntegerField(default=0, verbose_name='总人数')

    class Meta:
        verbose_name = 'app使用频率统计表，年度统计'
        verbose_name_plural = verbose_name
        db_table = 'app_frequency_year_statistics'

# alexa连接数统计表
class AlexaConnectStatisticsModel(models.Model):
    id = models.AutoField(primary_key=True)
    num = models.IntegerField(default=0, verbose_name='总人数')
    data_time = models.IntegerField(default=0, verbose_name='数据时间')

    class Meta:
        verbose_name = 'alexa连接数统计表'
        verbose_name_plural = verbose_name
        db_table = 'alexa_statistics'


class FAQModel(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=64, default='', unique=True, verbose_name='标题')
    content = models.TextField(default='', verbose_name='内容')
    add_time = models.IntegerField(default=0, verbose_name='添加时间')
    update_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = 'tb_faq'
        verbose_name = '问题帮助表'
        verbose_name_plural = verbose_name


class AppLogModel(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(Device_User, to_field='userID', on_delete=models.CASCADE, verbose_name='关联设备用户表')
    uid = models.CharField(max_length=20, default='', verbose_name='设备uid')
    average_delay = models.CharField(max_length=32, default='', verbose_name='最高平均延时')
    status = models.SmallIntegerField(default=0, verbose_name='失败状态')
    filename = models.CharField(max_length=120, default='', verbose_name='文件名')
    add_time = models.IntegerField(default=0, verbose_name='日期')

    class Meta:
        db_table = 'app_log'
        verbose_name = 'APP日志表'
        verbose_name_plural = verbose_name


class EquipmentInfoExStatisticsModel(models.Model):
    id = models.AutoField(primary_key=True)
    push_type = models.SmallIntegerField(default=0, verbose_name='第三方推送服务器标志。0：APNS推送，1：谷歌推送，2：极光推送')
    number_of_successes = models.IntegerField(default=0, verbose_name='推送成功数量')
    number_of_failures = models.IntegerField(default=0, verbose_name='推送失败数量')
    number_of_arrival = models.IntegerField(default=0, verbose_name='推送到达数量')
    statistics_date = models.IntegerField(default=0, verbose_name='属于哪天、哪月的统计')
    date_type = models.SmallIntegerField(default=0, verbose_name='统计日期的类型。0：天，1：月')
    add_time = models.IntegerField(default=0, verbose_name='添加时间')

    class Meta:
        db_table = 'equipment_info_ex_statistics'
        verbose_name = '推送消息统计表'
        verbose_name_plural = verbose_name





