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

61 lines
2.0 KiB

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Date: 2022/12/14 15:14:59
'''
import sys
sys.path.append('.')
import datetime
from sqlalchemy import and_
from Common.Utils import Utils
from db_logic.db_base import Repository
from models.power_models import EntityUserTemporaryAuth
from db_logic.client import BllClient
from models.client_models import EntityClient
class BllUserTemporaryAuth(Repository):
def __init__(self, entityType=EntityUserTemporaryAuth):
super().__init__(entityType)
def create_temporary_auth(self, user_ids, auth_type, t=None):
# try:
# client_code = BllClient().findEntity(EntityClient.client_id == client_id).client_code
# except:
# client_code = ''
if not t:
t = 8
for user_id in user_ids:
end_date = str(datetime.datetime.now() + datetime.timedelta(hours=int(t)))[:-7]
obj = self.entityType()
obj.user_id=user_id
obj.create_date = Utils.get_str_datetime()
obj.end_date = end_date
obj.tp = auth_type
# obj.client_id = client_id
# obj.client_code = client_code
self.insert(obj)
# obj = self.findEntity(
# and_(
# self.entityType.user_id == user_id, client_id== client_id
# )
# )
# end_date = str(datetime.datetime.now() + datetime.timedelta(minutes=10))[:-7]
# if obj:
# obj.create_date = Utils.get_str_datetime()
# obj.end_date = end_date
# obj.client_id = client_id
# obj.client_code = client_code
# self.update(obj)
# else:
# obj = self.entityType()
# obj.user_id=user_id
# obj.create_date = Utils.get_str_datetime()
# obj.end_date = end_date
# obj.client_id = client_id
# obj.client_code = client_code
# self.insert(obj)