You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.9 KiB
Python

2 years ago
import os
import openpyxl
from utils.DBModels.ProtocolModel import ModBusVar
from utils.DBModels.UserModels import User
from utils import Globals
# ID 从站地址 变量名 变量描述 功能码 寄存器地址 工程量下限 工程量上限
class UserManage(object):
def __init__(self):
super(UserManage, self).__init__()
@classmethod
def createUser(self, userName, userPwd, description, projectAuthority, protocolSetting, userAuthority, trendAuthority):
# 创建用户
self.userName = str(userName)
self.userPwd = str(userPwd)
self.description = str(description)
self.projectAuthority = projectAuthority
self.protocolSetting = protocolSetting
self.userAuthority = userAuthority
self.trendAuthority = trendAuthority
if User.getByName(userName):
print('已有同名变量')
else:
userModel = User()
userModel.createUser(userName = userName, userPwd = userPwd, description = description, projectAuthority = projectAuthority, protocolSetting = protocolSetting, userAuthority = userAuthority, trendAuthority = trendAuthority)
@classmethod
def deleteUser(self, name):
# 删除用户
name = str(name)
# print(name)
User.deleteUser(userName = name)
@classmethod
def editUser(self, userName, Nname, userPwd, description, projectAuthority, protocolSetting, userAuthority, trendAuthority):
# 修改用户信息
userName = str(userName)
Nname = str(Nname)
userPwd = str(userPwd)
description = str(description)
projectAuthority = str(projectAuthority)
protocolSetting = str(protocolSetting)
userAuthority = str(userAuthority)
trendAuthority = str(trendAuthority)
if Nname == userName:
User.update(userName = Nname, userPwd = userPwd, description = description, projectAuthority = projectAuthority, protocolSetting = protocolSetting, userAuthority = userAuthority, trendAuthority = trendAuthority).where(User.userName == userName).execute()
elif User.getByName(Nname):
print('已有同名变量')
return
elif not User.getByName(userName):
print('不存在的变量')
return
else:
User.update(userName = Nname, userPwd = userPwd, description = description, projectAuthority = projectAuthority, protocolSetting = protocolSetting, userAuthority = userAuthority, trendAuthority = trendAuthority).where(User.userName == userName).execute()
@classmethod
def getAllUser(self):
# 查询所有用户
users = User.get_all()
if users is 'Error':
return
l = []
for user in users:
l.append([user.id, user.userName, user.userPwd, user.description, user.createTime, user.projectAuthority, user.protocolSetting, user.userAuthority, user.trendAuthority])
return l
@classmethod
def getByName(self, name):
# 查询指定用户信息
user = User.getByName(name)
if user:
return [user.id, user.userName, user.userPwd, user.description, user.createTime, user.projectAuthority, user.protocolSetting, user.userAuthority, user.trendAuthority]
else:
return [user.id, user.userName, user.userPwd, user.description, user.createTime, user.projectAuthority, user.protocolSetting, user.userAuthority, user.trendAuthority]
@classmethod
def authentication(self, name, passwd):
user = User.getByName(name)
if user:
if str(user.userPwd) == str(passwd):
return 0
else:
return 1
else:
return 2
@classmethod
def initUser(self):
self.createUser(userName = 'admin', userPwd = 'admin', description = '1', projectAuthority = '1', protocolSetting = '1', userAuthority = '1', trendAuthority = '1')