from django.db import models


# 设备sim卡信息(保存的是2G卡信息)
class MongoDevice_SimInfo(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(u'设备ID',blank=True, null=True, max_length=50)
    device_name = models.CharField(u'设备名称', max_length=100, blank=True, null=True)
    device_type = models.CharField(u'设备类型', max_length=10, blank=True, null=True)
    iccid = models.CharField(u'iccid', max_length=30, blank=True, null=True)
    msisdn = models.CharField(u'msisdn', max_length=50, blank=True, null=True)
    imsi = models.CharField(u'imsi', max_length=30, blank=True, null=True)
    sp_code = models.CharField(u'短信端口', max_length=30, blank=True, null=True)
    carrier = models.CharField(u'运营商', max_length=30, blank=True, null=True)
    data_plan = models.CharField(u'套餐大小', max_length=20, blank=True, null=True)
    data_usage = models.CharField(u'当月用量', max_length=20, blank=True, null=True)
    account_status = models.CharField(u'卡状态', max_length=20, blank=True, null=True)
    expiry_date = models.CharField(u'计费结束日期', max_length=20, blank=True, null=True)
    active = models.CharField(u'激活状态', max_length=10, blank=True, null=True)
    test_valid_date = models.CharField(u'测试期起始日期', max_length=20, blank=True, null=True)
    silent_valid_date = models.CharField(u'沉默期起始日期', max_length=20, blank=True, null=True)
    test_used_data_usage = models.CharField(u'测试期已用流量', max_length=20, blank=True, null=True)
    active_date = models.CharField(u'激活日期', max_length=20, blank=True, null=True)
    data_balance = models.CharField(u'剩余流量,单位M', max_length=20, blank=True, null=True)
    outbound_date = models.CharField(u'出库日期', max_length=20, blank=True, null=True)
    support_sms = models.CharField(u'是否支持短信', max_length=10, blank=True, null=True)
    sim_alarm = models.TextField(u'sim卡提示配置', blank=True, null=True)
    uptime = models.IntegerField(default=0) #上传时间

    class Meta:
       db_table = "sa_device_sim_info"


# 企鹏SIM卡表
class MongoDevice_QP_SimInfo(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(u'设备ID', blank=True, null=True, max_length=50)
    device_name = models.CharField(u'设备名称', max_length=100, blank=True, null=True)
    device_type = models.CharField(u'设备类型', max_length=10, blank=True, null=True)
    iccid = models.CharField(u'iccid', max_length=30, blank=True, null=True)
    msisdn = models.CharField(u'msisdn', max_length=30, blank=True, null=True)
    imsi = models.CharField(u'imsi', max_length=30, blank=True, null=True)
    ratePlanExpirationDate = models.CharField(u'套餐过期时间', max_length=30, blank=True, null=True)
    activeDuration = models.CharField(u'激活宽限期（天）', max_length=30, blank=True, null=True)
    ratePlanId = models.CharField(u'卡当前套餐ID', max_length=20, blank=True, null=True)
    # SINGLE：单卡，POOL：流量池卡
    sim_type = models.CharField(u'卡类型', max_length=20, blank=True, null=True)

    totalDataVolume = models.CharField(u'卡套餐大小, 单位M', max_length=20, blank=True, null=True)
    # 可测试: TEST_READY_NAME, 库存：INVENTORY_NAME，可激活：ACTIVATION_READY_NAME， 已激活：ACTIVATED_NAME， 已停卡：DEACTIVATED_NAME，已销卡：RETIRED_NAME, 已清除：PURGED_NAME
    deviceStatus = models.CharField(u'卡在运营商的状态', max_length=10, blank=True, null=True)
    # false表示按流量（MB），true表示按次数
    useCountAsVolume = models.CharField(u'卡套餐单位', max_length=10, blank=True, null=True)
    expireDate = models.CharField(u'过期时间', max_length=20, blank=True, null=True)
    ratePlanEffetiveDate = models.CharField(u'卡套餐生效时间', max_length=20, blank=True, null=True)
    dataUsage = models.CharField(u'卡本月用量, 单位M', max_length=20, blank=True, null=True)
    nbCard = models.CharField(u'是否NB卡', max_length=10, blank=True, null=True)
    # NOT_SET：未开启，NOT_BIND：待绑定，NORMAL：正常，SPLIT：机卡分离
    imeiStatus = models.CharField(u'机卡绑定状态', max_length=20, blank=True, null=True)
    orgName = models.CharField(u'卡所属机构名称', max_length=30, blank=True, null=True)
    testingExpireDate = models.CharField(u'测试期结束时间', max_length=30, blank=True, null=True)
    usedDataVolume = models.CharField(u'卡套餐用量', blank=True, max_length=30, null=True)

    lastSyncDate = models.CharField(u'餐用量同步时间', blank=True, max_length=30, null=True)
    realnameRequired = models.CharField(u'卡实名需求', blank=True, max_length=30, null=True)
    ## 卡实名审核状态，审核通过：pass、未提交：not-submit、审核不通过：not-pass、待审核：not-audit
    realNameCertifystatus = models.CharField(u'卡实名审核状态', blank=True, max_length=30, null=True)
    speedLimit = models.CharField(u'网络限速值，单位：Kbps', blank=True, max_length=30, null=True)
    # unicom：中国联通，cmcc：中国移动，chinanet：中国电信
    carrier = models.CharField(u'运营商', blank=True, max_length=30, null=True)
    openDate = models.CharField(u'出库时间', blank=True, max_length=30, null=True)
    iratePlanName = models.CharField(u'卡当前套餐', blank=True, max_length=30, null=True)
    startDate = models.CharField(u'激活时间', blank=True, max_length=30, null=True)
    # # 状态，测试中：testing、库存：inventory、待激活：pending-activation、已激活：activation、已停卡：deactivation、已销卡：retired
    status = models.CharField(u'SIM卡状态', blank=True, max_length=30, null=True)

    uptime = models.IntegerField(default=0)  # 上传时间

    class Meta:
        db_table = "sa_device_qp_sim_info"


class MongoSimInfo(models.Model):
    """SIM卡信息表"""
    iccid = models.CharField(verbose_name='sim卡号', max_length=30, unique=True)
    expiry_time = models.IntegerField(verbose_name='到期时间', default=0)
    sim_type = models.IntegerField(verbose_name='sim卡厂商', default=0)
    sim_data = models.TextField(verbose_name='sim信息', default="")
    create_time = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    modify_time = models.DateTimeField(verbose_name="修改时间", auto_now=True)

    class Meta:
        db_table = "sa_sim_info"


#虫害短信配置表：
class MongoMsg_Conf(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(u'设备ID',blank=True, null=True, max_length=50)
    conf = models.TextField(u'短信配置', blank=True, null=True)
    uptime = models.IntegerField(default=0) #上传时间

    class Meta:
        db_table = "sa_device_msg_conf"


# 短信发送记录表:
class MongoMsg_Send(models.Model):
    mobile = models.CharField(u'手机号',max_length=20, blank=True)
    equip_id = models.CharField(u'设备号',max_length=20, blank=True)
    uptime = models.IntegerField(default=0) #发送时间
    send_dec = models.CharField(u'发送内容',max_length=300, blank=True)
    result_desc = models.TextField(u'短信描述', blank=True, null=True)

    class Meta:
        db_table = "sa_device_msg_send"


# APP 版本更新记录
class MongoVersion_Record(models.Model):
    id = models.AutoField(primary_key=True)
    app_name = models.CharField(u'app版本名称', max_length=50, blank=True)
    app_num = models.CharField(u'版本号', max_length=50, blank=True)
    app_desc = models.CharField(u'更新描述', max_length=50, blank=True)
    addtime = models.IntegerField(default=0)  # 新增时间

    class Meta:
        db_table = "sa_app_version_record"
        ordering = ['-id']
