コード例 #1
0
ファイル: models.py プロジェクト: ngjaying/ActorCloud
class Permission(BaseModel):
    __tablename__ = 'permissions'
    roleIntID = db.Column(
        db.Integer,
        db.ForeignKey('roles.id', onupdate="CASCADE", ondelete="CASCADE"))
    resourceIntID = db.Column(
        db.Integer,
        db.ForeignKey('resources.id', onupdate="CASCADE", ondelete="CASCADE"))
コード例 #2
0
class Application(BaseModel):
    __tablename__ = 'applications'
    appID = db.Column(db.String(6), default=random_app_uid, unique=True)
    appName = db.Column(db.String(50))
    appToken = db.Column(db.String(100), default=generate_uuid)  # 32-bit
    expiredAt = db.Column(db.DateTime)  # app token expired time
    description = db.Column(db.String(300))
    appStatus = db.Column(db.Integer)  # 0:blocked,1:run
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
    roleIntID = db.Column(db.Integer, db.ForeignKey('roles.id'))  # app role id
    groups = db.relationship('Group',
                             secondary=ApplicationGroup,
                             lazy='dynamic')
コード例 #3
0
class EndDevice(Device):
    __tablename__ = 'end_devices'
    id = db.Column(db.Integer,
                   db.ForeignKey('devices.id',
                                 onupdate="CASCADE",
                                 ondelete="CASCADE"),
                   primary_key=True)
    loraData = db.Column(JSONB)  # lora protocol extend
    lwm2mData = db.Column(JSONB)  # lwm2m protocol extend
    upLinkSystem = db.Column(
        db.SmallInteger, server_default='1')  # 1:cloud 2:gateway, 3:endDevice
    gateway = db.Column(db.Integer, db.ForeignKey('gateways.id'))  # gateway
    parentDevice = db.Column(
        db.Integer,
        db.ForeignKey('end_devices.id', onupdate="CASCADE",
                      ondelete="CASCADE"))
    __mapper_args__ = {'polymorphic_identity': 1}
コード例 #4
0
ファイル: models.py プロジェクト: ngjaying/ActorCloud
class LoginLog(BaseModel):
    __tablename__ = 'login_logs'
    IP = db.Column(db.String(50))  # IP
    isLogged = db.Column(db.SmallInteger)  # 登录结果 失败0,成功1
    loginTime = db.Column(db.DateTime)  # 登录时间
    userIntID = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate="CASCADE", ondelete="CASCADE"))
コード例 #5
0
class Group(BaseModel):
    __tablename__ = 'groups'
    groupID = db.Column(db.String(6), default=random_group_uid, unique=True)
    groupName = db.Column(db.String(50))
    description = db.Column(db.String(300))
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
    devices = db.relationship('Device', secondary=GroupDevice,
                              lazy='dynamic')  # group devices
コード例 #6
0
ファイル: models.py プロジェクト: imfht/flaskapp1
class Codec(BaseModel):
    __tablename__ = 'codec'
    code = db.Column(JSONB)
    reviewOpinion = db.Column(db.String)
    codeStatus = db.Column(db.SmallInteger, server_default='1')  # 1:Pending, 2:Success, 3:Failed
    tenantID = db.Column(db.String,
                         db.ForeignKey('tenants.tenantID',
                                       onupdate="CASCADE",
                                       ondelete="CASCADE"))
    productID = db.Column(db.String,
                          db.ForeignKey('products.productID',
                                        onupdate="CASCADE",
                                        ondelete="CASCADE"))
    userIntID = db.Column(db.Integer,
                          db.ForeignKey('users.id',
                                        onupdate="CASCADE",
                                        ondelete="CASCADE"))
コード例 #7
0
class TimerPublish(BaseModel):
    __tablename__ = 'timer_publish'
    taskName = db.Column(db.String)  # 任务名
    taskStatus = db.Column(db.SmallInteger,
                           server_default='2')  # 任务状态2 执行 3 成功
    timerType = db.Column(db.SmallInteger)  # 定时类型1 固定 , 2 间隔
    topic = db.Column(db.String(1000))  # 主题(mqtt)
    payload = db.Column(JSONB)  # 下发消息内容
    intervalTime = db.Column(JSONB)  # 间隔时间{'weekday': 'hour': 'minute'}
    crontabTime = db.Column(db.DateTime)  # 指定下发时间
    deviceIntID = db.Column(db.Integer,
                            db.ForeignKey('devices.id',
                                          onupdate="CASCADE",
                                          ondelete="CASCADE"))  # 设备id
    userIntID = db.Column(db.Integer,
                          db.ForeignKey('users.id',
                                        onupdate="CASCADE",
                                        ondelete="CASCADE"))  # 用户
コード例 #8
0
class AppApiLogMonth(BaseModel):
    __tablename__ = 'app_api_logs_month'
    countTime = db.Column(db.DateTime)  # 统计时间
    apiCount = db.Column(db.Integer)  # 应用api调用月统计数量
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
コード例 #9
0
class AppApiLogDay(BaseModel):
    __tablename__ = 'app_api_logs_day'
    countTime = db.Column(db.DateTime)
    apiCount = db.Column(db.Integer)
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
コード例 #10
0
ファイル: models.py プロジェクト: imfht/flaskapp1
class DataStream(BaseModel):
    __tablename__ = 'data_streams'
    streamID = db.Column(db.String(50))  # data stream identifier
    streamName = db.Column(db.String(50))
    streamType = db.Column(db.SmallInteger)  # 1:deviceUp, 2:deviceDown
    topic = db.Column(db.String(500))
    description = db.Column(db.String(300))
    dataPoints = db.relationship('DataPoint', secondary=StreamPoint,
                                 backref=db.backref('dataStreams', lazy='dynamic'))
    tenantID = db.Column(db.String,
                         db.ForeignKey('tenants.tenantID',
                                       onupdate="CASCADE",
                                       ondelete="CASCADE"))
    productID = db.Column(db.String, db.ForeignKey('products.productID'))
    userIntID = db.Column(db.Integer,
                          db.ForeignKey('users.id',
                                        onupdate="CASCADE",
                                        ondelete="CASCADE"))
コード例 #11
0
class Rule(BaseModel):
    __tablename__ = 'rules'
    ruleName = db.Column(db.String(50))
    remark = db.Column(db.String(50))
    enable = db.Column(db.SmallInteger, default=1)
    sql = db.Column(db.String)
    fromTopics = db.Column(JSONB)
    scopeData = db.Column(JSONB)
    ruleType = db.Column(db.SmallInteger)
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))

    actions = db.relationship('Action',
                              secondary=RuleAction,
                              backref=db.backref('rules', lazy='dynamic'))
コード例 #12
0
class AppApiLog(BaseModel):
    __tablename__ = 'app_api_logs'
    createAt = db.Column(db.DateTime, server_default=func.now())
    url = db.Column(db.String(200))
    method = db.Column(db.String(100))
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
コード例 #13
0
class Cert(BaseModel):
    __tablename__ = 'certs'
    certName = db.Column(db.String)
    enable = db.Column(db.SmallInteger, default=1)
    CN = db.Column(db.String(36))
    key = db.Column(db.Text)  # key file string
    cert = db.Column(db.Text)  # cert file string
    devices = db.relationship('Device', secondary=CertDevice,
                              lazy='dynamic')  # cert devices
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
コード例 #14
0
ファイル: models.py プロジェクト: imfht/flaskapp1
class Message(BaseModel):
    __tablename__ = 'messages'
    msgTitle = db.Column(db.String(100))
    msgContent = db.Column(db.String(300))
    messageType = db.Column(db.Integer)
    tenantID = db.Column(db.String,
                         db.ForeignKey('tenants.tenantID',
                                       onupdate="CASCADE",
                                       ondelete="CASCADE"),
                         nullable=True)
コード例 #15
0
ファイル: models.py プロジェクト: imfht/flaskapp1
class Tenant(BaseModel):
    __tablename__ = 'tenants'
    tenantType = db.Column(db.SmallInteger, default=1)  # 1: personal,2: company
    tenantID = db.Column(db.String(9), unique=True)
    company = db.Column(db.String(50), unique=True)
    companySize = db.Column(db.String(50))
    companyAddress = db.Column(db.String(50))
    contactPerson = db.Column(db.String(50))
    contactPhone = db.Column(db.String(50))
    contactEmail = db.Column(db.String(50))
    tenantBalance = db.Column(db.Float, server_default='0.00')
    invoiceBalance = db.Column(db.Float, server_default='0.00')
    enable = db.Column(db.SmallInteger, server_default='1')
    logo = db.Column(db.Integer,
                     db.ForeignKey('upload_info.id', onupdate="CASCADE"))
    logoDark = db.Column(db.Integer,
                         db.ForeignKey('upload_info.id', onupdate="CASCADE"))
    deviceCount = db.Column(db.Integer,
                            server_default=get_default_device_count())
コード例 #16
0
ファイル: models.py プロジェクト: ngjaying/ActorCloud
class Tenant(BaseModel):
    __tablename__ = 'tenants'
    tenantType = db.Column(db.SmallInteger, default=1)  # 租户类型:1个人,2企业
    tenantID = db.Column(db.String(9), unique=True)  # 9位不重复租户ID,企业为C开头,个人为P开头
    company = db.Column(db.String(50), unique=True)  # 企业名称,个人用户为空
    companySize = db.Column(db.String(50))  # 企业规模
    companyAddress = db.Column(db.String(50))  # 企业地址
    contactPerson = db.Column(db.String(50))  # 联系人
    contactPhone = db.Column(db.String(50))  # 联系电话
    contactEmail = db.Column(db.String(50))  # 联系邮箱
    tenantBalance = db.Column(db.Float, server_default='0.00')  # 账户余额
    invoiceBalance = db.Column(db.Float, server_default='0.00')  # 开票余额
    enable = db.Column(db.SmallInteger, server_default='1')  # 是否可用
    logo = db.Column(db.Integer,
                     db.ForeignKey('upload_info.id', onupdate="CASCADE"))
    logoDark = db.Column(db.Integer,
                         db.ForeignKey('upload_info.id', onupdate="CASCADE"))
    deviceCount = db.Column(
        db.Integer, server_default=get_default_device_count())  # 设备数量限制
コード例 #17
0
ファイル: models.py プロジェクト: imfht/flaskapp1
class DataPoint(BaseModel):
    __tablename__ = 'data_points'
    dataPointName = db.Column(db.String(50))
    dataPointID = db.Column(db.String(50))
    dataTransType = db.Column(db.Integer)  # 1: Up, 2: Down, 3 UpAndDown
    pointDataType = db.Column(db.Integer)  # 1:num, 2:str, 3:Boolean, 4:time, 5:location
    extendTypeAttr = db.Column(JSONB, server_default='{}')  # extension attr for point data type
    isLocationType = db.Column(db.SmallInteger, server_default='0')  # is location-> 0:no, 1:yes
    locationType = db.Column(db.SmallInteger)  # 1: longitude, 2: latitude, 3: altitude
    enum = db.Column(db.JSON, server_default='[]')  # enum of string or integer
    description = db.Column(db.String(300))
    tenantID = db.Column(db.String,
                         db.ForeignKey('tenants.tenantID',
                                       onupdate="CASCADE",
                                       ondelete="CASCADE"))
    productID = db.Column(db.String, db.ForeignKey('products.productID'))
    userIntID = db.Column(db.Integer,
                          db.ForeignKey('users.id',
                                        onupdate="CASCADE",
                                        ondelete="CASCADE"))
コード例 #18
0
ファイル: models.py プロジェクト: ngjaying/ActorCloud
class Role(BaseModel):
    __tablename__ = 'roles'
    roleName = db.Column(db.String(50))  # 角色名
    description = db.Column(db.String(300))  # 描述
    roleType = db.Column(db.SmallInteger)  # 角色类型,1:用户角色 2:应用角色
    isShare = db.Column(db.SmallInteger, default=0)  # 角色是否公用1公用, 0私有
    tenantID = db.Column(db.String,
                         db.ForeignKey('tenants.tenantID',
                                       onupdate="CASCADE",
                                       ondelete="CASCADE"),
                         nullable=True)
コード例 #19
0
ファイル: models.py プロジェクト: imfht/flaskapp1
class Role(BaseModel):
    __tablename__ = 'roles'
    roleName = db.Column(db.String(50))
    description = db.Column(db.String(300))
    roleType = db.Column(db.SmallInteger)  # 1:user role 2:app role
    isShare = db.Column(db.SmallInteger, default=0)  # 0: private, 1: public
    tenantID = db.Column(db.String,
                         db.ForeignKey('tenants.tenantID',
                                       onupdate="CASCADE",
                                       ondelete="CASCADE"),
                         nullable=True)
コード例 #20
0
class Gateway(Device):
    __tablename__ = 'gateways'
    id = db.Column(db.Integer,
                   db.ForeignKey('devices.id',
                                 onupdate="CASCADE",
                                 ondelete="CASCADE"),
                   primary_key=True)
    devices = db.relationship('EndDevice',
                              foreign_keys="EndDevice.gateway",
                              lazy='dynamic')  # 设备
    __mapper_args__ = {'polymorphic_identity': 2}
コード例 #21
0
class EmqxBillMonth(BaseModel):
    __tablename__ = 'emqx_bills_month'
    msgType = db.Column(db.Integer)  # 消息类型
    msgCount = db.Column(db.Integer)  # 月消息数量
    msgSize = db.Column(db.Integer)  # 月消息流量
    countTime = db.Column(db.DateTime)  # 统计时间
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
コード例 #22
0
ファイル: models.py プロジェクト: ngjaying/ActorCloud
class Message(BaseModel):
    __tablename__ = 'messages'
    msgTitle = db.Column(db.String(100))  # 消息标题
    msgContent = db.Column(db.String(300))  # 消息内容
    messageType = db.Column(
        db.Integer)  # 消息类型,1:财务消息,2:产品消息,3:安全消息,4:其它消息,5:公告
    tenantID = db.Column(db.String,
                         db.ForeignKey('tenants.tenantID',
                                       onupdate="CASCADE",
                                       ondelete="CASCADE"),
                         nullable=True)
コード例 #23
0
class EmqxBillHour(ModelMixin, db.Model):
    __tablename__ = 'emqx_bills_hour'
    __table_args__ = (db.Index('emqx_bills_hour_countTime_idx', "countTime"), )
    msgType = db.Column(db.Integer, primary_key=True)  # 消息类型
    msgCount = db.Column(db.Integer)  # 小时消息数量
    msgSize = db.Column(db.Integer)  # 小时消息流量
    countTime = db.Column(db.DateTime, primary_key=True)  # 统计时间
    tenantID = db.Column(db.String,
                         db.ForeignKey('tenants.tenantID',
                                       onupdate="CASCADE",
                                       ondelete="CASCADE"),
                         primary_key=True)
コード例 #24
0
class DeviceCountMonth(BaseModel):
    __tablename__ = 'device_count_month'
    deviceCount = db.Column(db.Integer)  # 月设备数量
    deviceOnlineCount = db.Column(db.Integer)  # 日设备在线数量
    deviceOfflineCount = db.Column(db.Integer)  # 日离线设备数量
    deviceSleepCount = db.Column(db.Integer)  # 休眠设备数
    countTime = db.Column(db.DateTime)  # 统计时间
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
コード例 #25
0
class Action(BaseModel):
    """
    config
    1 alert {"alertTitle": "","alertContent": "","alertSeverity":1}
    2 mail {"title": "","content": "",,"emails":["*****@*****.**","*****@*****.**"]}
    3 Webhook {"token": "jasdkjabsk","url": "http://127.0.0.1:6010"}
    4 Publish {"topic": "", "payload": "","deviceID": "","protocol": "mqtt","prefixTopic": ""}
    5 MQTT {"topic":"topic"}
    """
    __tablename__ = 'actions'
    actionName = db.Column(db.String(50))
    actionType = db.Column(
        db.SmallInteger)  # 1:alert,2:mail,3:Webhook,4:Publish,5:MQTT
    description = db.Column(db.String(300))
    config = db.Column(JSONB)
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
コード例 #26
0
class Device(BaseModel):
    __tablename__ = 'devices'
    deviceName = db.Column(db.String(50))
    deviceType = db.Column(db.Integer)  # 1:end_device 2:gateway
    deviceID = db.Column(db.String(50))
    deviceUsername = db.Column(db.String(50))
    token = db.Column(db.String(50), default=generate_uuid(size=36))
    authType = db.Column(db.SmallInteger, server_default='1')  # 1:token 2:cert
    lastConnection = db.Column(db.DateTime)
    blocked = db.Column(db.SmallInteger, server_default='0')  # 0:false 1:true
    deviceStatus = db.Column(db.SmallInteger,
                             server_default='0')  # 0:offline 1:online 2:sleep
    location = db.Column(db.String(300))
    longitude = db.Column(db.Float)
    latitude = db.Column(db.Float)
    softVersion = db.Column(db.String(50))
    hardwareVersion = db.Column(db.String(50))
    manufacturer = db.Column(db.String(50))
    serialNumber = db.Column(db.String(100))
    deviceConsoleIP = db.Column(db.String(50))
    deviceConsoleUsername = db.Column(db.String(50))
    deviceConsolePort = db.Column(db.Integer, server_default='22')
    carrier = db.Column(db.Integer, server_default='1')
    upLinkNetwork = db.Column(db.Integer)  # 1:2G, 2:3G.....
    description = db.Column(db.String(300))
    mac = db.Column(db.String(50))
    metaData = db.Column(JSONB)  # meta data
    groups = db.relationship('Group', secondary=GroupDevice,
                             lazy='dynamic')  # device groups
    certs = db.relationship('Cert', secondary=CertDevice,
                            lazy='dynamic')  # device certs
    productID = db.Column(db.String, db.ForeignKey('products.productID'))
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
    __mapper_args__ = {'polymorphic_on': deviceType}
コード例 #27
0
ファイル: models.py プロジェクト: imfht/flaskapp1
class Product(BaseModel):
    """
    cloudProtocol: 1:MQTT,2:CoAp,3:LwM2M,4:LoRaWAN,5:HTTP,6:WebSocket
    """
    __tablename__ = 'products'
    productID = db.Column(db.String(6), default=random_product_uid, unique=True)  # 产品标识
    productName = db.Column(db.String(50))  # 产品名称
    description = db.Column(db.String(300))  # 产品描述
    cloudProtocol = db.Column(db.SmallInteger, server_default='1')  # 云端协议, 网关类型产品显示为上联协议
    gatewayProtocol = db.Column(db.Integer)  # 网关协议
    productType = db.Column(db.SmallInteger, server_default='1')  # 产品类型1:设备,2:网关
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
    devices = db.relationship('Device', backref='products', lazy='dynamic')
コード例 #28
0
ファイル: models.py プロジェクト: ngjaying/ActorCloud
class Invitation(BaseModel):
    __tablename__ = 'invitations'
    inviteEmail = db.Column(db.String(50))  # 被邀请人邮箱
    roleIntID = db.Column(db.Integer)  # 角色id
    tenantID = db.Column(db.String(9))  # 租户id
    inviteStatus = db.Column(db.Integer, default=0)  # 邀请状态,0:未加入,1:已加入
    userIntID = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate="CASCADE", ondelete="CASCADE"))

    def generate_auth_token(self):
        expires_in = current_app.config['TOKEN_LIFETIME_INVITATION']
        s = JWT(current_app.config['SECRET_KEY'], expires_in=expires_in)
        return s.dumps({'invitation_id': self.id})
コード例 #29
0
class CurrentAlert(BaseModel):
    __tablename__ = 'current_alerts'
    createAt = db.Column(db.DateTime, server_default=func.now())
    alertName = db.Column(db.String(50))
    alertContent = db.Column(db.String(300))
    alertTimes = db.Column(db.Integer)
    alertDetail = db.Column(JSON)
    alertSeverity = db.Column(db.SmallInteger)
    startTime = db.Column(db.DateTime)
    deviceID = db.Column(db.String(100))
    ruleIntID = db.Column(
        db.Integer,
        db.ForeignKey('rules.id', onupdate="CASCADE", ondelete="CASCADE"))
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
    __table_args__ = (db.Index('alerts_rule_key',
                               'tenantID',
                               'deviceID',
                               'ruleIntID',
                               unique=True), )
コード例 #30
0
ファイル: models.py プロジェクト: imfht/flaskapp1
class Resource(BaseModel):
    __tablename__ = 'resources'
    code = db.Column(db.String(50), unique=True)
    url = db.Column(db.String(50))
    method = db.Column(db.String(10))  # get post put delete
    order = db.Column(db.Integer)
    level = db.Column(db.Integer)
    icon = db.Column(db.String(50))
    enable = db.Column(db.SmallInteger, server_default='1')
    parentCode = db.Column(db.String(50), db.ForeignKey('resources.code'))
    tabs = db.Column(db.SmallInteger)
    children = db.relationship('Resource', cascade='all, delete-orphan')
    parent = db.relationship('Resource', remote_side=[code])
    service = db.Column(db.String(50))