prepare better DB interaction with reload

This commit is contained in:
2026-05-06 15:35:49 +02:00
parent 3dbc9ecfcb
commit c3462d3d3a
4 changed files with 365 additions and 76 deletions

View File

@@ -34,6 +34,31 @@ class CompanyInfo(TypedDict):
ma_archiviert: str
class ContactPersonInfo(TypedDict):
an_id: str
ma_id: str
wce_id: str
st_id: str
an_sachgebiet: str
an_anrede: str
an_titel: str
an_nachname: str
an_vorname: str
an_position: str
an_mail: str
an_festnetz: str
an_mobil: str
an_faxnummer: str
an_hauptansprechpartner: str
an_anrede_anschrift: str
an_bemerkung: str
an_aktualisierung_datum: str
an_aktualisierung_nutzer: str
an_letztes_kontaktdatum: str
an_ersteintrag_datum: str
an_archiviert: str
def _transform_for_gui_output(
data: pl.DataFrame,
) -> pl.DataFrame:
@@ -53,18 +78,19 @@ def _transform_for_gui_output(
return q.collect()
def comp_search_choice_mapping() -> dict[str, int]:
def comp_search_choices() -> tuple[tuple[str, int], ...]:
# TODO no reload functionality
q = db.df_crm_master.lazy()
counter = pl.int_range(0, pl.len()).over(pl.col.ma_unternehmensname)
q = q.with_columns(
ma_unternehmensname_dedupl=pl.when(counter == 0)
dedupl=pl.when(counter == 0)
.then(pl.col.ma_unternehmensname)
.otherwise(pl.format("{} ({})", pl.col.ma_unternehmensname, counter))
)
df = q.collect()
return dict(zip(df["ma_unternehmensname_dedupl"], df["ma_id"]))
# return dict(zip(df["dedupl"], df["ma_id"]))
return tuple(zip(df["dedupl"], df["ma_id"]))
def comp_search_get_info(
@@ -76,3 +102,42 @@ def comp_search_get_info(
df = _transform_for_gui_output(df)
return cast(CompanyInfo, df.row(0, named=True))
def contact_person_search_choices(
ma_id: int | None,
use_both_names: bool,
) -> tuple[tuple[str, int], ...]:
# TODO no reload functionality
q = db.df_contact_person.lazy()
if ma_id is not None:
q = q.filter(pl.col.ma_id == ma_id)
dedupl_col = pl.col.an_nachname
if use_both_names:
q = q.with_columns(
name_search=(pl.format("{}, {}", pl.col.an_nachname, pl.col.an_vorname))
)
dedupl_col = pl.col.name_search
counter = pl.int_range(0, pl.len()).over(dedupl_col)
q = q.with_columns(
dedupl=pl.when(counter == 0)
.then(dedupl_col)
.otherwise(pl.format("{} ({})", dedupl_col, counter))
)
df = q.collect()
# return dict(zip(df["dedupl"], df["an_id"]))
return tuple(zip(df["dedupl"], df["an_id"]))
def contact_person_search_get_info(
an_id: int,
) -> ContactPersonInfo:
df = db.df_contact_person.filter(pl.col.an_id == an_id)
if df.height > 1 or df.height == 0:
raise ValueError(f"Größe des zurückgelieferten Datenpakets ungültig: {df.height}")
df = _transform_for_gui_output(df)
return cast(ContactPersonInfo, df.row(0, named=True))