feat: remove ExcelService and web-upload import path
The ODS-from-filesystem mass import is the sole import workflow. ExcelService (web-upload Excel) is deleted, and DocumentService.updateOrCreateFromExcel() which it exclusively called is removed along with it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -174,43 +174,6 @@ public class DocumentService {
|
||||
return documentRepository.save(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird vom Excel-Service aufgerufen für jede Zeile.
|
||||
*/
|
||||
@Transactional
|
||||
public void updateOrCreateFromExcel(String filename, LocalDate date, String location, String transcription,
|
||||
boolean overwrite) {
|
||||
Optional<Document> existingOpt = documentRepository.findByOriginalFilename(filename);
|
||||
|
||||
Document doc;
|
||||
if (existingOpt.isPresent()) {
|
||||
doc = existingOpt.get();
|
||||
log.info("Excel-Import: Aktualisiere Metadaten für {}", filename);
|
||||
|
||||
// Logik: Nur überschreiben, wenn Feld leer ist ODER overwrite=true gesetzt ist
|
||||
if (doc.getDocumentDate() == null || overwrite) {
|
||||
doc.setDocumentDate(date);
|
||||
}
|
||||
if (doc.getLocation() == null || overwrite) {
|
||||
doc.setLocation(location);
|
||||
}
|
||||
if (doc.getTranscription() == null || overwrite) {
|
||||
doc.setTranscription(transcription);
|
||||
}
|
||||
} else {
|
||||
log.info("Excel-Import: Erstelle Platzhalter für {}", filename);
|
||||
doc = Document.builder()
|
||||
.originalFilename(filename)
|
||||
.title(filename) // Vorläufiger Titel
|
||||
.status(DocumentStatus.PLACEHOLDER)
|
||||
.documentDate(date)
|
||||
.location(location)
|
||||
.transcription(transcription)
|
||||
.build();
|
||||
}
|
||||
documentRepository.save(doc);
|
||||
}
|
||||
|
||||
// 1. Allgemeine Suche (für das Suchfeld im Frontend)
|
||||
public List<Document> searchDocuments(String text, LocalDate from, LocalDate to, UUID sender, UUID reciever, List<String> tags) {
|
||||
log.info("Tags", tags);
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
package org.raddatz.familienarchiv.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class ExcelService {
|
||||
|
||||
private final DocumentService documentService;
|
||||
|
||||
// Wir lesen die Konfiguration ein (mit Defaults, falls nichts in properties steht)
|
||||
@Value("${app.import.excel.col.filename:0}")
|
||||
private int colFilename;
|
||||
|
||||
@Value("${app.import.excel.col.date:1}")
|
||||
private int colDate;
|
||||
|
||||
@Value("${app.import.excel.col.location:2}")
|
||||
private int colLocation;
|
||||
|
||||
@Value("${app.import.excel.col.transcription:3}")
|
||||
private int colTranscription;
|
||||
|
||||
public void importExcel(MultipartFile file, boolean overwrite) {
|
||||
try (InputStream is = file.getInputStream();
|
||||
Workbook workbook = new XSSFWorkbook(is)) {
|
||||
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
log.info("Starte Excel Import mit Mapping: File={}, Date={}, Loc={}, Text={}",
|
||||
colFilename, colDate, colLocation, colTranscription);
|
||||
|
||||
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
|
||||
Row row = sheet.getRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
// Wir nutzen jetzt die dynamischen Index-Variablen
|
||||
String filename = getCellValueAsString(row.getCell(colFilename));
|
||||
if (filename == null || filename.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LocalDate date = null;
|
||||
Cell dateCell = row.getCell(colDate);
|
||||
if (dateCell != null && dateCell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(dateCell)) {
|
||||
date = dateCell.getDateCellValue().toInstant()
|
||||
.atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
}
|
||||
|
||||
String location = getCellValueAsString(row.getCell(colLocation));
|
||||
String transcription = getCellValueAsString(row.getCell(colTranscription));
|
||||
|
||||
documentService.updateOrCreateFromExcel(filename, date, location, transcription, overwrite);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Fehler beim Excel Import", e);
|
||||
throw new RuntimeException("Excel konnte nicht verarbeitet werden: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getCellValueAsString(Cell cell) {
|
||||
if (cell == null) return null;
|
||||
return switch (cell.getCellType()) {
|
||||
case STRING -> cell.getStringCellValue();
|
||||
case NUMERIC -> String.valueOf((int) cell.getNumericCellValue());
|
||||
case BOOLEAN -> String.valueOf(cell.getBooleanCellValue());
|
||||
default -> "";
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user