35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import datetime
|
|
|
|
from apps.eps.repositories.worker_repository import WorkerRepository
|
|
from django.db import connection
|
|
|
|
|
|
class WorkerStatisticRepository(WorkerRepository):
|
|
def get_workers_with_threshold(self, threshold: datetime.datetime) -> list[dict]:
|
|
data = []
|
|
# TODO техдолг
|
|
query = """
|
|
SELECT w.name, t.sn, t.charge, z.name
|
|
FROM eps_tag t
|
|
LEFT JOIN workers_worker w ON t.id = w.tag_id
|
|
INNER JOIN eps_zone z ON t.zone_id = z.id
|
|
WHERE t.date_time >= %s AND z.name != 'АБК'
|
|
"""
|
|
params = [threshold]
|
|
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(query, params)
|
|
recent_tags = cursor.fetchall()
|
|
|
|
for tag in recent_tags:
|
|
fio, sn, charge, zone = tag
|
|
data.append(
|
|
{
|
|
"fio": fio if fio else sn,
|
|
"sn": sn,
|
|
"charge": round(charge * 100),
|
|
"location": zone,
|
|
},
|
|
)
|
|
return data
|