appender events and applications are updated
This commit is contained in:
@@ -27,7 +27,9 @@ class Applications(CrudCollection):
|
||||
String, nullable=False, comment="Application Code"
|
||||
)
|
||||
application_type: Mapped[str] = mapped_column(String, comment="Application Type")
|
||||
application_for: Mapped[str] = mapped_column(String, server_default="EMP", comment="Application For")
|
||||
application_for: Mapped[str] = mapped_column(
|
||||
String, server_default="EMP", comment="Application For"
|
||||
)
|
||||
description: Mapped[str] = mapped_column(String, comment="Application Description")
|
||||
|
||||
|
||||
@@ -199,8 +201,30 @@ class Service2Events(CrudCollection):
|
||||
__table_args__ = ({"comment": "Service2Events Information"},)
|
||||
|
||||
|
||||
# class Service2Application(CrudCollection):
|
||||
# pass
|
||||
class Service2Application(CrudCollection):
|
||||
"""
|
||||
Service2Application class based on declarative_base and BaseMixin via session
|
||||
"""
|
||||
|
||||
__tablename__ = "services2applications"
|
||||
__exclude__fields__ = []
|
||||
|
||||
application_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("applications.id"), nullable=False
|
||||
)
|
||||
application_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Application UUID"
|
||||
)
|
||||
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
|
||||
service_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Service UUID"
|
||||
)
|
||||
application_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Application Code"
|
||||
)
|
||||
site_url: Mapped[str] = mapped_column(String, nullable=False, comment="Site URL")
|
||||
|
||||
__table_args__ = {"comment": "Service2Applications Information"}
|
||||
|
||||
|
||||
class Event2OccupantExtra(CrudCollection):
|
||||
@@ -295,17 +319,14 @@ class Event2Employee(CrudCollection):
|
||||
db=db,
|
||||
).data
|
||||
service_ids = list(set([event.event_service_id for event in employee_events]))
|
||||
print("service_ids", service_ids)
|
||||
active_event_ids = Service2Events.filter_all(
|
||||
Service2Events.service_id.in_(service_ids),
|
||||
db=db,
|
||||
).data
|
||||
print("active_event_ids", active_event_ids)
|
||||
active_events = Events.filter_all(
|
||||
Events.id.in_([event.event_id for event in active_event_ids]),
|
||||
db=db,
|
||||
).data
|
||||
print("active_events", active_events)
|
||||
if extra_events := Event2EmployeeExtra.filter_all(
|
||||
Event2EmployeeExtra.employee_id == employee_id,
|
||||
db=db,
|
||||
@@ -321,7 +342,6 @@ class Event2Employee(CrudCollection):
|
||||
events_dict[str(event.endpoint_code)] = str(event.function_code)
|
||||
else:
|
||||
ValueError("Duplicate event code found for single endpoint")
|
||||
print("events_dict", events_dict)
|
||||
return events_dict
|
||||
|
||||
|
||||
@@ -400,45 +420,54 @@ class Application2Employee(CrudCollection):
|
||||
__exclude__fields__ = []
|
||||
|
||||
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
|
||||
employee_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Employee UUID"
|
||||
)
|
||||
|
||||
application_id: Mapped[int] = mapped_column(ForeignKey("applications.id"))
|
||||
application_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Application UUID"
|
||||
)
|
||||
|
||||
site_url: Mapped[str] = mapped_column(String, nullable=False, comment="Site URL")
|
||||
application_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Application Code"
|
||||
)
|
||||
employee_uu_id = mapped_column(String, nullable=False, comment="Employee UUID")
|
||||
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
|
||||
service_uu_id = mapped_column(String, nullable=False, comment="Service UUID")
|
||||
|
||||
@classmethod
|
||||
def get_application_codes(cls, employee_id: int, db) -> dict[str, str]:
|
||||
print("employee_id", employee_id)
|
||||
employee_applications = cls.filter_all(
|
||||
Application2Employee.employee_id == employee_id,
|
||||
def get_application_codes(cls, employee_id: int, db) -> list[int]:
|
||||
employee_services = cls.filter_all(
|
||||
cls.employee_id == employee_id,
|
||||
db=db,
|
||||
).data
|
||||
service_ids = [service.service_id for service in employee_services]
|
||||
active_applications = Service2Application.filter_all(
|
||||
Service2Application.service_id.in_(service_ids),
|
||||
db=db,
|
||||
).data
|
||||
applications = Applications.filter_all(
|
||||
Applications.id.in_(
|
||||
[application.application_id for application in active_applications]
|
||||
),
|
||||
db=db,
|
||||
).data
|
||||
if extra_applications := Application2EmployeeExtra.filter_all(
|
||||
Application2EmployeeExtra.employee_id == employee_id,
|
||||
db=db,
|
||||
).data:
|
||||
applications_extra = Applications.filter_all(
|
||||
Applications.id.in_(
|
||||
[application.application_id for application in extra_applications]
|
||||
),
|
||||
db=db,
|
||||
).data
|
||||
applications.extend(applications_extra)
|
||||
applications_dict = {}
|
||||
print("employee_applications", employee_applications)
|
||||
for employee_application in employee_applications:
|
||||
if employee_application.site_url not in applications_dict:
|
||||
applications_dict[str(employee_application.site_url)] = str(
|
||||
employee_application.application_code
|
||||
)
|
||||
for application in applications:
|
||||
if not application.site_url in applications_dict:
|
||||
applications_dict[str(application.site_url)] = str(application.application_code)
|
||||
else:
|
||||
ValueError("Duplicate application code found for single endpoint")
|
||||
return applications_dict
|
||||
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"application_to_employee",
|
||||
employee_id,
|
||||
site_url,
|
||||
application_id,
|
||||
"application2employee_employee_to_service",
|
||||
employee_uu_id,
|
||||
service_uu_id,
|
||||
unique=True,
|
||||
),
|
||||
{"comment": "Application2Employee Information"},
|
||||
{"comment": "Application to Employee Information"},
|
||||
)
|
||||
|
||||
|
||||
@@ -453,33 +482,114 @@ class Application2Occupant(CrudCollection):
|
||||
build_living_space_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("build_living_space.id"), nullable=False
|
||||
)
|
||||
build_living_space_uu_id: Mapped[str] = mapped_column(
|
||||
build_living_space_uu_id = mapped_column(
|
||||
String, nullable=False, comment="Build Living Space UUID"
|
||||
)
|
||||
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
|
||||
service_uu_id = mapped_column(String, nullable=False, comment="Service UUID")
|
||||
|
||||
@classmethod
|
||||
def get_application_codes(cls, build_living_space_id: int, db) -> list[int]:
|
||||
occupant_services = cls.filter_all(
|
||||
cls.build_living_space_id == build_living_space_id,
|
||||
db=db,
|
||||
).data
|
||||
service_ids = [service.service_id for service in occupant_services]
|
||||
active_applications = Service2Application.filter_all(
|
||||
Service2Application.service_id.in_(service_ids),
|
||||
db=db,
|
||||
).data
|
||||
applications = Applications.filter_all(
|
||||
Applications.id.in_(
|
||||
[application.application_id for application in active_applications]
|
||||
),
|
||||
db=db,
|
||||
).data
|
||||
if extra_applications := Application2OccupantExtra.filter_all(
|
||||
Application2OccupantExtra.build_living_space_id == build_living_space_id,
|
||||
db=db,
|
||||
).data:
|
||||
applications_extra = Applications.filter_all(
|
||||
Applications.id.in_(
|
||||
[application.application_id for application in extra_applications]
|
||||
),
|
||||
db=db,
|
||||
).data
|
||||
applications.extend(applications_extra)
|
||||
applications_dict = {}
|
||||
for application in applications:
|
||||
if not application.site_url in applications_dict:
|
||||
applications_dict[str(application.site_url)] = str(application.application_code)
|
||||
else:
|
||||
ValueError("Duplicate application code found for single endpoint")
|
||||
return applications_dict
|
||||
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"application2occupant_occupant_to_service",
|
||||
build_living_space_uu_id,
|
||||
service_uu_id,
|
||||
unique=True,
|
||||
),
|
||||
{"comment": "Application to Occupant Information"},
|
||||
)
|
||||
|
||||
|
||||
class Application2EmployeeExtra(CrudCollection):
|
||||
"""
|
||||
Application2EmployeeExtra class based on declarative_base and BaseMixin via session
|
||||
"""
|
||||
|
||||
__tablename__ = "application2employee_extra"
|
||||
__exclude__fields__ = []
|
||||
|
||||
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
|
||||
employee_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Employee UUID"
|
||||
)
|
||||
application_id: Mapped[int] = mapped_column(ForeignKey("applications.id"))
|
||||
application_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Application UUID"
|
||||
)
|
||||
|
||||
site_url: Mapped[str] = mapped_column(String, nullable=False, comment="Site URL")
|
||||
application_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Application Code"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_application_codes(cls, build_living_space_id: int, db) -> dict[str, str]:
|
||||
occupant_applications = cls.filter_all(
|
||||
cls.build_living_space_id == build_living_space_id,
|
||||
db=db,
|
||||
).data
|
||||
applications_dict = {}
|
||||
for occupant_application in occupant_applications:
|
||||
if occupant_application.site_url not in applications_dict:
|
||||
applications_dict[str(occupant_application.site_url)] = str(
|
||||
occupant_application.application_code
|
||||
)
|
||||
return applications_dict
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"application_to_employee",
|
||||
employee_id,
|
||||
site_url,
|
||||
application_id,
|
||||
unique=True,
|
||||
),
|
||||
{"comment": "Application2Employee Information"},
|
||||
)
|
||||
|
||||
|
||||
class Application2OccupantExtra(CrudCollection):
|
||||
"""
|
||||
Application2OccupantExtra class based on declarative_base and BaseMixin via session
|
||||
"""
|
||||
|
||||
__tablename__ = "application2occupant_extra"
|
||||
__exclude__fields__ = []
|
||||
|
||||
build_living_space_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("build_living_space.id"), nullable=False
|
||||
)
|
||||
build_living_space_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Build Living Space UUID"
|
||||
)
|
||||
application_id: Mapped[int] = mapped_column(ForeignKey("applications.id"))
|
||||
application_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Application UUID"
|
||||
)
|
||||
site_url: Mapped[str] = mapped_column(String, nullable=False, comment="Site URL")
|
||||
application_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Application Code"
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index(
|
||||
|
||||
Reference in New Issue
Block a user