feat: 初始化项目并提交一次代码

This commit is contained in:
2025-12-17 20:25:15 +08:00
commit 355098025f
19 changed files with 585 additions and 0 deletions

0
models/__init__.py Normal file
View File

55
models/ammeter_usage.py Normal file
View File

@@ -0,0 +1,55 @@
import time
import aiosqlite
from database import get_conn
class AmmeterUsageModel:
@classmethod
async def create_table(cls):
async with get_conn() as conn:
conn.row_factory = aiosqlite.Row
await conn.execute(
"""
CREATE TABLE IF NOT EXISTS ammeter_usage (
id INTEGER PRIMARY KEY AUTOINCREMENT,
room_id INTEGER,
room_name TEXT,
left_ele REAL,
left_money REAL,
left_free_ele REAL,
left_free_money REAL,
ele_price REAL,
mon_time INTEGER,
created_at INTEGER UNIQUE
)
"""
)
await conn.commit()
@classmethod
async def insert(cls, data: dict):
print(data)
async with get_conn() as conn:
conn.row_factory = aiosqlite.Row
await conn.execute(
"""
INSERT OR IGNORE INTO ammeter_usage (
room_id, room_name,
left_ele, left_money,
left_free_ele, left_free_money,
ele_price, mon_time, created_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
data["roomId"],
data["roomName"],
data["leftEle"],
data["leftMoney"],
data["leftFreeEle"],
data["leftFreeMoney"],
data["elePrice"],
data["monTime"],
int(time.time() * 1000),
),
)
await conn.commit()

55
models/water_usage.py Normal file
View File

@@ -0,0 +1,55 @@
import time
import aiosqlite
from database import get_conn
class WaterUsageModel:
@classmethod
async def create_table(cls):
async with get_conn() as conn:
conn.row_factory = aiosqlite.Row
await conn.execute(
"""
CREATE TABLE IF NOT EXISTS water_usage (
id INTEGER PRIMARY KEY AUTOINCREMENT,
room_id INTEGER,
room_name TEXT,
left_water REAL,
left_money REAL,
left_free_water REAL,
left_free_money REAL,
water_price REAL,
mon_time INTEGER,
created_at INTEGER UNIQUE
)
"""
)
await conn.commit()
@classmethod
async def insert(cls, data: dict):
print(data)
async with get_conn() as conn:
conn.row_factory = aiosqlite.Row
await conn.execute(
"""
INSERT OR IGNORE INTO water_usage (
room_id, room_name,
left_water, left_money,
left_free_water, left_free_money,
water_price, mon_time, created_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
data["roomId"],
data["roomName"],
data["leftWater"],
data["leftMoney"],
data["leftFreeWater"],
data["leftFreeMoney"],
data["coldWaterPrice"],
data["monTime"],
int(time.time() * 1000),
),
)
await conn.commit()