models.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # coding: utf-8
  2. from sqlalchemy import Column, DateTime, Integer, Numeric, String
  3. from flask_sqlalchemy import SQLAlchemy
  4. #與當前項目相關的模型文件,即所有的實體類在此編寫
  5. from manage import db
  6. class User(db.Model):
  7. __tablename__ = 'user'
  8. sn = db.Column(db.Integer, primary_key=True)
  9. firstname = db.Column(db.String(30), nullable=False)
  10. lastname = db.Column(db.String(30), nullable=False)
  11. mail = db.Column(db.String(50), nullable=False)
  12. phone = db.Column(db.String(20), nullable=False)
  13. username = db.Column(db.String(30), nullable=False, unique=True)
  14. password = db.Column(db.String(40), nullable=False)
  15. status = db.Column(db.Integer, nullable=False, info='0:admin;1:new;2:old')
  16. isActive = db.Column(db.Boolean, nullable=False, default=True)
  17. purchase_info = db.relationship('PurchaseInfo', backref='user', uselist=False)
  18. node_info = db.relationship('NodeInfo', backref='user', uselist=False)
  19. farm_info = db.relationship('FarmInfo', backref='user', uselist=False)
  20. permission = db.relationship('Permissions', backref='user', uselist=False)
  21. node_imgs = db.relationship('NodeImage', backref='user', lazy='dynamic')
  22. node_positions = db.relationship('NodePosition', backref='user', lazy='dynamic')
  23. module_sn_numbers = db.relationship('ModuleSerialNumber', backref='user', lazy='dynamic')
  24. class PurchaseInfo(db.Model):
  25. __tablename__ = 'purchase_info'
  26. sn = db.Column(db.Integer, primary_key=True)
  27. loc_length = db.Column(db.Text, nullable=False)
  28. loc_width = db.Column(db.Text, nullable=False)
  29. location = db.Column(db.Text, nullable=False)
  30. monitor_num = db.Column(db.Integer, nullable=False)
  31. connect = db.Column(db.Text, nullable=False)
  32. user_id = db.Column(db.Integer, db.ForeignKey('user.sn'))
  33. datetime = db.Column(db.DateTime, nullable=False)
  34. class NodeInfo(db.Model):
  35. __tablename__ = 'node_info'
  36. sn = db.Column(db.Integer, primary_key=True)
  37. node_info = db.Column(db.Text, nullable=False)
  38. user_id = db.Column(db.Integer, db.ForeignKey('user.sn'))
  39. class FarmInfo(db.Model):
  40. __tablename__ = 'farm_info'
  41. sn = db.Column(db.Integer, primary_key=True)
  42. path = db.Column(db.Text, nullable=False, default='0')
  43. location = db.Column(db.Text, nullable=False, default='0')
  44. loc_lat = db.Column(db.Text, nullable=False, default='0')
  45. loc_lng = db.Column(db.Text, nullable=False, default='0')
  46. user_id = db.Column(db.Integer, db.ForeignKey('user.sn'))
  47. datetime = db.Column(db.DateTime, nullable=False)
  48. class NodeImage(db.Model):
  49. __tablename__ = 'node_img'
  50. sn = db.Column(db.Integer, primary_key=True)
  51. node_name = db.Column(db.String(10), nullable=False)
  52. path = db.Column(db.Text, nullable=False, default='0')
  53. user_id = db.Column(db.Integer, db.ForeignKey('user.sn'))
  54. datetime = db.Column(db.DateTime, nullable=False)
  55. class NodePosition(db.Model):
  56. __tablename__ = 'node_position'
  57. sn = db.Column(db.Integer, primary_key=True)
  58. node_name = db.Column(db.String(10), nullable=False)
  59. pos_lat = db.Column(db.Text, nullable=False)
  60. pos_lng = db.Column(db.Text, nullable=False)
  61. user_id = db.Column(db.Integer, db.ForeignKey('user.sn'))
  62. datetime = db.Column(db.DateTime, nullable=False)
  63. class ModuleSerialNumber(db.Model):
  64. __tablename__ = 'module_sn_number'
  65. sn = db.Column(db.Integer, primary_key=True)
  66. module_name = db.Column(db.String(30), nullable=False)
  67. sn_number = db.Column(db.Text, nullable=False)
  68. user_id = db.Column(db.Integer, db.ForeignKey('user.sn'))
  69. datetime = db.Column(db.DateTime, nullable=False)
  70. #權限表
  71. class Permissions(db.Model):
  72. __tablename__ = 'permissions'
  73. sn = db.Column(db.Integer, primary_key=True)
  74. user_id = db.Column(db.Integer, db.ForeignKey('user.sn'))
  75. add_domain = db.Column(db.Integer, nullable=False, default=0)
  76. company_profile = db.Column(db.Integer, nullable=False, default=0)
  77. product_info = db.Column(db.Integer, nullable=False, default=0)
  78. erp = db.Column(db.Integer, nullable=False, default=0)
  79. rma = db.Column(db.Integer, nullable=False, default=0)
  80. download_data = db.Column(db.Integer, nullable=False, default=0)
  81. gps = db.Column(db.Integer, nullable=False, default=0)
  82. sensor = db.Column(db.Integer, nullable=False, default=0)
  83. Actuator = db.Column(db.Integer, nullable=False, default=0)
  84. diary_log = db.Column(db.Integer, nullable=False, default=0)
  85. repair_log = db.Column(db.Integer, nullable=False, default=0)
  86. set_permission = db.Column(db.Integer, nullable=False, default=0)
  87. register = db.Column(db.Integer, nullable=False, default=0)
  88. blacklist = db.Column(db.Integer, nullable=False, default=0)
  89. back_manage = db.Column(db.Integer, nullable=False, default=0)
  90. module_test = db.Column(db.Integer, nullable=False, default=0)
  91. class SensorList(db.Model):
  92. __tablename__ = 'sensor_list'
  93. sn = db.Column(db.Integer, primary_key=True)
  94. ch_name = db.Column(db.String(20), nullable=False)
  95. en_name = db.Column(db.String(20), nullable=False)
  96. version = db.Column(db.String(10), nullable=False)
  97. datetime = db.Column(db.DateTime, nullable=False)
  98. #自定義序列化方法,方便在前端拿數據
  99. def toDict(self):
  100. return {'ch_name':self.ch_name, 'en_name':self.en_name, 'version':self.version}
  101. db.create_all()