65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
"""queries/sharepoint.py — rpa_intra_sharepoint (Intraz)"""
|
|
|
|
from .db import query, e, dt, badge
|
|
|
|
|
|
def get_sharepoint(db_path: str) -> list:
|
|
return query(db_path, """
|
|
SELECT
|
|
sp.id, sp.rpa_intra_ftp_json_id, sp.rpa_process_id,
|
|
sp.file_type, sp.remote_path, sp.stato, sp.note,
|
|
sp.created_at, sp.updated_at,
|
|
json_extract(f.corso, '$.IDsessione') AS sessione_id,
|
|
json_extract(f.corso, '$.descrizione') AS corso_descrizione,
|
|
json_extract(f.azienda, '$.ragione_sociale') AS azienda_nome
|
|
FROM rpa_intra_sharepoint sp
|
|
LEFT JOIN rpa_intra_ftp_json f ON f.id = sp.rpa_intra_ftp_json_id
|
|
WHERE date(sp.created_at) >= date('now', '-10 days')
|
|
ORDER BY sp.id DESC
|
|
LIMIT 500
|
|
""")
|
|
|
|
|
|
def get_stats(db_path: str) -> dict:
|
|
return {
|
|
'sp_total': query(db_path, "SELECT COUNT(*) as n FROM rpa_intra_sharepoint")[0]['n'],
|
|
'sp_uploaded': query(db_path, "SELECT COUNT(*) as n FROM rpa_intra_sharepoint WHERE stato='uploaded'")[0]['n'],
|
|
'sp_errore': query(db_path, "SELECT COUNT(*) as n FROM rpa_intra_sharepoint WHERE stato='errore'")[0]['n'],
|
|
'sp_pending': query(db_path, "SELECT COUNT(*) as n FROM rpa_intra_sharepoint WHERE stato='pending'")[0]['n'],
|
|
}
|
|
|
|
|
|
def render_table(rows: list) -> str:
|
|
if not rows:
|
|
return '<p class="empty">Nessun file SharePoint trovato.</p>'
|
|
|
|
def _badge(stato):
|
|
if stato == 'uploaded':
|
|
return badge('ok', 'Uploaded')
|
|
if stato == 'errore':
|
|
return badge('err', 'Errore')
|
|
return badge('warn', 'Pending')
|
|
|
|
trs = ''.join(
|
|
f'<tr data-stato="{e(r.get("stato") or "pending")}" data-date="{str(r.get("created_at") or "")[:10]}">'
|
|
f'<td>{e(r.get("id"))}</td>'
|
|
f'<td>{e(r.get("rpa_intra_ftp_json_id"))}</td>'
|
|
f'<td>{e(r.get("sessione_id"))}</td>'
|
|
f'<td>{e(r.get("azienda_nome"))}</td>'
|
|
f'<td>{e(r.get("file_type"))}</td>'
|
|
f'<td class="nc">{e(r.get("remote_path"))}</td>'
|
|
f'<td>{_badge(r.get("stato"))}</td>'
|
|
f'<td class="nc">{e(r.get("note"))}</td>'
|
|
f'<td>{dt(r.get("created_at"))}</td>'
|
|
f'<td>{dt(r.get("updated_at"))}</td>'
|
|
f'</tr>'
|
|
for r in rows
|
|
)
|
|
return (
|
|
'<table><thead><tr>'
|
|
'<th>#</th><th>JSON ID</th><th>Sessione</th><th>Azienda</th>'
|
|
'<th>Tipo</th><th>Remote Path</th><th>Stato</th><th>Note</th>'
|
|
'<th>Creato</th><th>Aggiornato</th>'
|
|
f'</tr></thead><tbody>{trs}</tbody></table>'
|
|
)
|