File size: 1,716 Bytes
7e6b994
4e2a6d5
77d18dc
 
7e6b994
8bc50ed
 
4e2a6d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77d18dc
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from sqlalchemy import Column, Integer, String, Float, DateTime, Boolean
import uuid
from pydantic import BaseModel
from typing import List
from database import Base


class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    username = Column(String, unique=True, index=True)
    email = Column(String, unique=True, index=True)
    password = Column(String)
    is_admin = Column(Boolean, default=False)
    last_login = Column(DateTime, nullable=True)
    is_active = Column(Boolean, default=True)

class StatusRecord(Base):
    __tablename__ = "status_records"

    id = Column(Integer, primary_key=True, index=True)
    uuid = Column(String, unique=True, default=lambda: str(uuid.uuid4()))
    device_id = Column(String, index=True)
    latitude = Column(Float)
    longitude = Column(Float)
    timestamp = Column(DateTime)
    connect_status = Column(Integer)  # 0 or 1

class SystemSetting(Base):
    __tablename__ = "system_settings"

    id = Column(Integer, primary_key=True, index=True)
    check_connect_period = Column(Integer, default=10)
    data_sync_period = Column(Integer, default=3600)
    get_config_period = Column(Integer, default=60)
    point_distance = Column(Integer, default=5)

class Device(Base):
    __tablename__ = "devices"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String)
    description = Column(String)
    device_id = Column(String, unique=True, index=True)
    password = Column(String)

class StatusRecordCreate(BaseModel):
    uuid: str
    latitude: float
    longitude: float
    timestamp: str
    connect_status: int

class StatusRecordBatch(BaseModel):
    records: List[StatusRecordCreate]