Merge branch 'main' of git.avatic.de:avatic/lcc_tool

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
This commit is contained in:
Anja Guenther 2025-10-26 21:52:17 +01:00
parent 562764561e
commit 9604d342d7
3 changed files with 17 additions and 7 deletions

View file

@ -210,7 +210,7 @@ public class CalculationExecutionService {
destinationCalculationJob.setAnnualCustomCost(customCost.getAnnualCost()); destinationCalculationJob.setAnnualCustomCost(customCost.getAnnualCost());
destinationCalculationJob.setAnnualTransportationCost(sections.stream().map(SectionInfo::result).map(CalculationJobRouteSection::getAnnualCost).reduce(BigDecimal.ZERO, BigDecimal::add)); destinationCalculationJob.setAnnualTransportationCost(sections.stream().map(SectionInfo::result).map(CalculationJobRouteSection::getAnnualCost).reduce(BigDecimal.ZERO, BigDecimal::add));
destinationCalculationJob.setTransportWeightExceeded(sections.stream().map(SectionInfo::result).anyMatch(CalculationJobRouteSection::isWeightPrice)); destinationCalculationJob.setTransportWeightExceeded(sections.stream().map(SectionInfo::result).filter(CalculationJobRouteSection::getMainRun).anyMatch(CalculationJobRouteSection::isWeightPrice));
destinationCalculationJob.setLayerCount(sections.getFirst().containerResult().getLayer()); destinationCalculationJob.setLayerCount(sections.getFirst().containerResult().getLayer());
destinationCalculationJob.setLayerStructure(null); //TODO generate layer structure destinationCalculationJob.setLayerStructure(null); //TODO generate layer structure
destinationCalculationJob.setHuCount(sections.getFirst().containerResult().getHuUnitCount()); destinationCalculationJob.setHuCount(sections.getFirst().containerResult().getHuUnitCount());

View file

@ -26,15 +26,18 @@ def normalize_part_number(part_number):
# Zu String konvertieren (ohne Float-Konvertierung) # Zu String konvertieren (ohne Float-Konvertierung)
part_str = str(part_number).strip() part_str = str(part_number).strip()
if len(part_str) > 12:
raise Exception("Part number longer than 12 digits. "+part_str)
# Bei rein numerischen Werten: mit führenden Nullen auffüllen # Bei rein numerischen Werten: mit führenden Nullen auffüllen
if part_str.isdigit(): if part_str.isdigit():
return part_str.zfill(12) return part_str.zfill(12)
else: else:
# Bei alphanumerischen Part Numbers: auf 12 Zeichen begrenzen/auffüllen # Bei alphanumerischen Part Numbers: auf 12 Zeichen begrenzen/auffüllen
if len(part_str) > 12: if len(part_str) > 12:
return part_str[:12] # Kürzen auf 12 Zeichen raise Exception("Part number longer than 12 digits. "+part_str)
else: else:
return part_str.ljust(12, '0') # Mit Nullen am Ende auffüllen return part_str.rjust(12, '0') # Mit Nullen am Anfang auffüllen
def format_hs_code(hs_code): def format_hs_code(hs_code):
"""Formatiert HS Code als 8-stelligen String""" """Formatiert HS Code als 8-stelligen String"""
@ -95,6 +98,8 @@ def excel_to_sql(excel_file_path, output_sql_path=None):
sql_statements.append("-- Material Daten Import") sql_statements.append("-- Material Daten Import")
sql_statements.append("-- Generiert aus Excel-Datei\n") sql_statements.append("-- Generiert aus Excel-Datei\n")
existing_materials = set()
for index, row in df.iterrows(): for index, row in df.iterrows():
try: try:
# Daten extrahieren und bereinigen # Daten extrahieren und bereinigen
@ -103,6 +108,7 @@ def excel_to_sql(excel_file_path, output_sql_path=None):
name = clean_text(row['description']) name = clean_text(row['description'])
hs_code = format_hs_code(row['hs_code']) hs_code = format_hs_code(row['hs_code'])
# Überspringe Zeilen ohne Part Number oder Description # Überspringe Zeilen ohne Part Number oder Description
if not part_number or not name or part_number == 'nan': if not part_number or not name or part_number == 'nan':
print(f"Überspringe Zeile {index + 2}: Fehlende Daten") print(f"Überspringe Zeile {index + 2}: Fehlende Daten")
@ -112,7 +118,11 @@ def excel_to_sql(excel_file_path, output_sql_path=None):
sql = f"""INSERT INTO material (part_number, normalized_part_number, hs_code, name, is_deprecated) sql = f"""INSERT INTO material (part_number, normalized_part_number, hs_code, name, is_deprecated)
VALUES ('{part_number}', '{normalized_part_number}', {hs_code}, '{name}', FALSE);""" VALUES ('{part_number}', '{normalized_part_number}', {hs_code}, '{name}', FALSE);"""
sql_statements.append(sql) if not normalized_part_number in existing_materials:
existing_materials.add(normalized_part_number)
sql_statements.append(sql)
else:
print(f"Duplikat gefunden: {normalized_part_number}")
except Exception as e: except Exception as e:
print(f"Fehler bei Zeile {index + 2}: {e}") print(f"Fehler bei Zeile {index + 2}: {e}")
@ -129,7 +139,7 @@ VALUES ('{part_number}', '{normalized_part_number}', {hs_code}, '{name}', FALSE)
# Auch auf Konsole ausgeben # Auch auf Konsole ausgeben
print(f"\n--- SQL-Statements ({len(sql_statements) - 2} Datensätze) ---") print(f"\n--- SQL-Statements ({len(sql_statements) - 2} Datensätze) ---")
print(sql_content) #print(sql_content)
return sql_content return sql_content