#!/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, client_id): try: client_code = BllClient().findEntity(EntityClient.client_id == client_id).client_code except: client_code = '' for user_id in user_ids: 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)