from django.db import models


# 小麦赤霉病-状态表
class MongoWheatstatus(models.Model):
    device_id = models.CharField(max_length=50, default='') # 设备id
    province = models.CharField(u'省', max_length=20, blank=True, null=True)
    city = models.CharField(u'市', max_length=20, blank=True, null=True)
    county = models.CharField(u'县', max_length=20, blank=True, null=True)
    uptime = models.IntegerField(u'上传时间', default=0)
    status = models.TextField(u'状态', max_length=500, blank=True, null=True)

    class Meta:
        db_table = "sa_device_wheatstatus"


# 小麦赤霉病-数据表
class MongoWheatdata(models.Model):
    device_id = models.CharField(max_length=50, default='') # 设备id
    province = models.CharField(u'省', max_length=20, blank=True, null=True)
    city = models.CharField(u'市', max_length=20, blank=True, null=True)
    county = models.CharField(u'县', max_length=20, blank=True, null=True)
    uptime = models.IntegerField(u'上传时间', default=0)
    data = models.TextField(u'数据',blank=True, null=True)

    class Meta:
        db_table = "sa_device_wheatdata"


# 小麦赤霉病-发生率
class MongoWheatIncidence(models.Model):
    device_id = models.CharField(max_length=50, default='') # 设备id
    province = models.CharField(u'省', max_length=20, blank=True, null=True)
    city = models.CharField(u'市', max_length=20, blank=True, null=True)
    county = models.CharField(u'县', max_length=20, blank=True, null=True)
    uptime = models.IntegerField(u'上传时间', default=0)
    incidence = models.CharField(u'发生率', max_length=200, blank=True, null=True)

    class Meta:
        db_table = "sa_device_wheatincidence"


# 设备到期充值流量记录
class MongoDevice_Payment(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(u'设备号',max_length=50, default='')
    device_type = models.CharField(u'设备类型',max_length=10, default='')
    order_number = models.CharField(u'订单编号',max_length=50, default='')
    addtime = models.IntegerField(u'下单时间', default=0)
    upltime = models.IntegerField(u'支付时间', default=0)
    price = models.CharField(u'支付钱数', max_length=20, blank=True, null=True)
    menu = models.CharField(u'套餐', max_length=20, blank=True, null=True)
    payment_method = models.CharField(u'支付方式', max_length=20, default=1) # 1 支付宝，2微信，3其他
    recharge_user = models.CharField(u'充值用户', max_length=20, blank=True, null=True)
    paystatus = models.CharField(u'支付状态', max_length=20, default=0) # 0未支付,1已支付
    paytype = models.PositiveIntegerField(u'充值状态', default=0) # 0用户付钱充值，1管理员后台充值
    class Meta:
        db_table = "sa_device_payment"


# 色诱测报灯照片记录：
class MongoAttractphoto(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(max_length=50, default='')  # 设备id
    addtime = models.IntegerField(default=0)  # 新增时间
    uptime = models.IntegerField(default=0)  # 修改时间
    addr = models.CharField(u'照片路径', max_length=200, default=0)
    at = models.CharField(u'环境温度', max_length=50,default=0)
    ah = models.CharField(u'环境湿度', max_length=50, default=0)
    # 用户自定义添加：作物名称、病虫害阶段、病虫名称、雌雄、数量
    describe = models.CharField(u'描述', max_length=50,default=0)
    indentify_photo = models.CharField(u'识别照片路径', max_length=200, default=0)
    indentify_result = models.CharField(max_length=100,default=0)  # 识别结果
    photo_status = models.PositiveIntegerField(default=1)  # 照片状态 默认为1正常 4为删除
    is_mark = models.PositiveIntegerField(default=0) # 是否手动标记
    mark = models.TextField(default='[]')  # 手动标记识别结果

    class Meta:
        db_table = "sa_device_attract_photo"


# 吸虫塔照片记录：
class MongoXCTphoto(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(max_length=50, default='')  # 设备id
    addtime = models.IntegerField(default=0)  # 新增时间
    uptime = models.IntegerField(default=0)  # 修改时间
    addr = models.CharField(u'照片路径', max_length=200, default=0)
    at = models.CharField(u'环境温度', max_length=50,default=0)
    ah = models.CharField(u'环境湿度', max_length=50, default=0)
    # 用户自定义添加：作物名称、病虫害阶段、病虫名称、雌雄、数量
    describe = models.CharField(u'描述', max_length=50,default=0)
    indentify_photo = models.CharField(u'识别照片路径', max_length=200, default=0)
    indentify_result = models.CharField(max_length=100,default=0)  # 识别结果
    photo_status = models.PositiveIntegerField(default=1)  # 照片状态 默认为1正常 4为删除
    is_mark = models.PositiveIntegerField(default=0) # 是否手动标记
    mark = models.TextField(default='[]')  # 手动标记识别结果
    label = models.TextField(blank=True)  # 机器标记识别结果
    # up_success = models.BooleanField(verbose_name="FTP图片真正上传成功", default=False)  # FTP图片真正上传成功

    class Meta:
        db_table = "sa_device_xct_photo"


# 性诱3.0照片记录：
class MongoXYThreephoto(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(max_length=50, default='')  # 设备id
    addtime = models.IntegerField(default=0)  # 新增时间
    uptime = models.IntegerField(default=0)  # 修改时间
    addr = models.CharField(u'照片路径', max_length=200, default=0)
    at = models.CharField(u'环境温度', max_length=50,default=0)
    ah = models.CharField(u'环境湿度', max_length=50, default=0)
    # 用户自定义添加：作物名称、病虫害阶段、病虫名称、雌雄、数量
    describe = models.CharField(u'描述', max_length=50,default=0)
    indentify_photo = models.CharField(u'识别照片路径', max_length=200, default=0)
    indentify_result = models.CharField(max_length=100,default=0)  # 识别结果
    photo_status = models.PositiveIntegerField(default=1)  # 照片状态 默认为1正常 4为删除
    is_mark = models.PositiveIntegerField(default=0) # 是否手动标记
    mark = models.TextField(default='[]')  # 手动标记识别结果

    class Meta:
        db_table = "sa_device_xy_three_photo"


class MongoDeviceTemporary(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(max_length=50, default='')  # 设备id
    addtime = models.IntegerField(default=0)  # 新增时间
    equipment = models.CharField(u'设备状态', max_length=10, default=0)  # 设备状态 0生产 1发货 2安装、3返修、4更换设备号、5报废、6对接
    whether_equipment_status = models.CharField(u'是否更新设备状态', max_length=10, default=0)  # 设备状态 0未更新，1已更新
    device_expire_time = models.IntegerField(default=0)  # 设备到期时间
    device_activation =  models.IntegerField(default=0)  # 设备激活时间
    device_expire = models.CharField(u'设备是否到期', max_length=10, default=0)  # 设备状态 0未到期，1已到期,2即将到期
    device_expire_days = models.CharField(u'设备到期天数', max_length=10, default=0)  # 设备到期天数

    class Meta:
        db_table = "sa_device_temporary"


# 害虫统计表
class MongoDevicePestInfo(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(max_length=50, default='')  # 设备id
    photo_id = models.CharField(max_length=50, default='')  # 图片id
    addtime = models.IntegerField(default=0)  # 害虫采集时间
    pest_name = models.CharField(max_length=50, default=0)  # 害虫名
    pest_num = models.CharField(max_length=50, default=0)  # 害虫数量
    at = models.CharField(u'环境温度', max_length=50,default=0)
    ah = models.CharField(u'环境湿度', max_length=50, default=0)
    upltime = models.IntegerField(default=0)  # 数据更新时间

    class Meta:
        db_table = "sa_device_pest_info"


# 用户预警联系人表
class MongoUserWarningLiaisons(models.Model):
    id = models.AutoField(primary_key=True)
    user_id = models.CharField(u"用户id", max_length=50, default='',blank=True, null=True)
    liaisons = models.CharField(u"联系人名称",max_length=50, default='')
    phone = models.IntegerField(u"联系人电话", default=0)
    send_count = models.IntegerField(u"发送次数", default=0)
    create_time = models.IntegerField(u"创建时间",default=0)
    class Meta:
        db_table = "sa_device_user_warning_liaisons"
        

# 用户害虫预警设置表
class MongoUserPestWarningSMSConf(models.Model):
    id = models.AutoField(primary_key=True)
    user_id = models.CharField(u"用户id",max_length=50, default='',blank=True, null=True)
    warning_id = models.CharField(u"预警设置id",max_length=50, default='',blank=True, null=True)
    device_ids = models.TextField(u"多个设备号",default='')
    warning_type = models.IntegerField(u"预警类型", default=0) #0逐台 1合并
    conf = models.TextField(u"短信预警内容", default=0)
    send_user = models.TextField(u"多个发送用户", default=0)
    create_time = models.IntegerField(u"创建时间",default=0)
    class Meta:
        db_table = "sa_device_user_pest_warning_sms_conf"


# 手动预警记录表
class MongoManual_Alert_Record(models.Model):
    id = models.AutoField(primary_key=True)
    user_id = models.CharField(u"用户id", max_length=50, default='',blank=True, null=True)
    device_type_id = models.IntegerField(u"设备类型", default=0)
    conf = models.TextField(u"短信预警内容", default=0)
    liaisons = models.CharField(u"联系人名称", max_length=50)
    phone = models.IntegerField(u"联系人电话", default=0)
    create_time = models.IntegerField(u"创建时间",default=0)
    status = models.IntegerField(u"是否已读",default=0) # 0未读 1已读
    class Meta:
        db_table = "sa_device_manual_alert_record"



#用户预警设置
class MongoUserEarlyWarningConfig(models.Model):
    id = models.AutoField(primary_key=True)
    user_id = models.CharField(u"用户id", max_length=50, default='',blank=True, null=True)
    title = models.CharField(u"标题", max_length=50)
    create_time = models.IntegerField(u"创建时间",default=0)
    device_type_id = models.IntegerField(u"设备类型", default=0)
    status = models.IntegerField(u"状态",default=1) # 0禁用 1启用
    class Meta:
        db_table = "sa_device_user_early_warning_config"
        
        
        
# 测报灯害虫预警记录表
class MongoCBDPestWarning(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.TextField(u"设备号",default='')
    user_id = models.CharField(u"用户id", max_length=50, default='',blank=True, null=True)
    warning_name = models.CharField(u"预警设置名称",max_length=50, default='',blank=True, null=True)
    warning_content = models.TextField(u"预警内容",default='')
    warning_types = models.CharField(u"预警类型",max_length=10,default=0) # 1目标种类预警 2、指定害虫数量预警  3 害虫数量总和预警 4综合预警
    upltime = models.IntegerField(u"预警时间",default=0)
    send_user = models.TextField(u"发送用户",default='')
    status = models.IntegerField(u"是否已读",default=0) # 0未读 1已读

    class Meta:
        db_table = "sa_device_cbd_pest_warning"