From 731b1fc4b76f06133ac8e6f1f0bf742aea378bce Mon Sep 17 00:00:00 2001 From: va1is Date: Tue, 28 Oct 2025 16:52:56 +0300 Subject: [PATCH] UIapi fix --- API-UI/main.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/API-UI/main.py b/API-UI/main.py index 7fba566..9633e7b 100644 --- a/API-UI/main.py +++ b/API-UI/main.py @@ -268,31 +268,32 @@ class ImportApp(QMainWindow): self.map_table.setCellWidget(i, 2, combo) def autofill_mapping(self): - """Простое автосопоставление по подстроке (без учета регистра).""" + """Автосопоставление только при полном совпадении названия поля JSON и колонки Excel.""" rows = self.map_table.rowCount() + matched = 0 for i in range(rows): - json_field = self.map_table.item(i, 0).text() - jf_key = json_field.split(".")[-1].lower() - best = "" - score_best = 0 - for h in self.headers: - hl = h.lower() - score = 0 - if hl == jf_key: - score = 3 - elif jf_key in hl or hl in jf_key: - score = 2 - elif hl.replace(" ", "") == jf_key.replace("_", ""): - score = 1 - if score > score_best: - score_best = score - best = h + json_field = self.map_table.item(i, 0).text().strip() combo = self.map_table.cellWidget(i, 2) - if combo and best: - idx = combo.findText(best) + if not combo: + continue + + # точное совпадение (с учётом регистра) + if json_field in self.headers: + idx = combo.findText(json_field) if idx >= 0: combo.setCurrentIndex(idx) - self.log("✨ Выполнено автосопоставление.") + matched += 1 + # допускаем вариант без учёта регистра (если нужно) + else: + for h in self.headers: + if h.lower() == json_field.lower(): + idx = combo.findText(h) + if idx >= 0: + combo.setCurrentIndex(idx) + matched += 1 + break + + self.log(f"✨ Автосопоставление завершено: найдено точных совпадений {matched}") # ---------- Excel ---------- def load_excel(self):