44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
#!/opt/homebrew/bin/python3
|
|
# -*- coding:utf-8 -*-
|
|
|
|
import json
|
|
import os
|
|
from datetime import datetime
|
|
from PyQt6.QtCore import *
|
|
from models import Device, Session
|
|
from logs import log
|
|
from PyQt6.QtGui import *
|
|
|
|
class DeviceBackend(QObject):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
# 添加设备
|
|
def create_device(self, json_str):
|
|
json_dict = json.loads(json_str)
|
|
name = json_dict['name']
|
|
ok, data = Session.queryByName(Device, name)
|
|
if ok:
|
|
return False, None
|
|
return Session.addByClass(Device, json_dict)
|
|
|
|
# 更新设备
|
|
def update_device(self, json_str):
|
|
json_dict = json.loads(json_str)
|
|
id = json_dict.get('id')
|
|
return Session.updateById(Device, id, json_dict)
|
|
|
|
# 删除设备
|
|
def delete_device(self, id):
|
|
return Session.deleteById(Device, id)
|
|
|
|
# 获取所有设备
|
|
def get_devices(self):
|
|
return Session.queryByAll(Device)
|
|
|
|
# 获取某个设备
|
|
def get_device(self, id):
|
|
return Session.queryById(Device, id)
|
|
|
|
|
|
deviceBackend = DeviceBackend() |