cargosoft migrations agent
This commit is contained in:
parent
734fe57d09
commit
fe23ba4050
2 changed files with 2158 additions and 0 deletions
|
|
@ -27,8 +27,15 @@
|
|||
|
||||
package com.alexanderlogistics.api;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.imixs.marty.team.TeamService;
|
||||
|
|
@ -191,6 +198,126 @@ public class CargosoftMigrationRestService implements Serializable {
|
|||
return messageBuffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Migriert die Rechnungen mit den neuen cdtr. Nummern
|
||||
*
|
||||
*
|
||||
*/
|
||||
@GET
|
||||
@Path("/cargosoft-renew_cdtr_number")
|
||||
@Produces({ MediaType.TEXT_PLAIN })
|
||||
public String migrationAdresswandlungOpenInvoices(@QueryParam("maxcount") int maxcount,
|
||||
@QueryParam("type") String type)
|
||||
throws QueryException, AccessDeniedException, ProcessingErrorException, PluginException, ModelException {
|
||||
StringBuffer messageBuffer = new StringBuffer();
|
||||
if (maxcount <= 0) {
|
||||
maxcount = 100;
|
||||
}
|
||||
if (type == null || type.isEmpty()) {
|
||||
type = "workitem";
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
log("├── sync process already running!", messageBuffer);
|
||||
return messageBuffer.toString();
|
||||
}
|
||||
isRunning = true;
|
||||
|
||||
log("├── read cargosoft migration file....", messageBuffer);
|
||||
Map<String, String> mapping = readAdressMapping();
|
||||
log("├── found " + mapping.size() + " mappings", messageBuffer);
|
||||
|
||||
String query = "(type:" + type + ") AND ($modelversion:rechnungseingang*)";
|
||||
int syncs = 0;
|
||||
long l = System.currentTimeMillis();
|
||||
int batchSize = 100;
|
||||
int totalObjects = 0;
|
||||
log("├── migration cargosoft addresses....", messageBuffer);
|
||||
log("│ ├── query=" + query, messageBuffer);
|
||||
|
||||
int totalCount = documentService.count(query);
|
||||
log("│ ├── found " + totalCount + " invoices", messageBuffer);
|
||||
|
||||
// Berechne Anzahl der benötigten Pages
|
||||
int totalPages = (int) Math.ceil((double) totalCount / batchSize);
|
||||
|
||||
// Verarbeite Page für Page
|
||||
for (int pageIndex = 0; pageIndex < totalPages; pageIndex++) {
|
||||
log("│ ├── read page " + pageIndex, messageBuffer);
|
||||
List<ItemCollection> invoiceList = documentService.find(query, batchSize, pageIndex);
|
||||
long l1 = System.currentTimeMillis();
|
||||
|
||||
int updates = migratateInvioceBPAddress(invoiceList, mapping);
|
||||
syncs = syncs + updates;
|
||||
log("│ ├── " + updates + " invoices migrated in " +
|
||||
(System.currentTimeMillis() - l1) + "ms ", messageBuffer);
|
||||
// break;
|
||||
}
|
||||
long duration = System.currentTimeMillis() - l;
|
||||
double objectsPerSecond = totalObjects / (duration / 1000.0);
|
||||
log("├── Successfully " + syncs + " business partner objects synced in " + duration + "ms ("
|
||||
+ String.format("%.1f", objectsPerSecond) + " objects/sec)", messageBuffer);
|
||||
|
||||
isRunning = false;
|
||||
return messageBuffer.toString();
|
||||
}
|
||||
|
||||
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
|
||||
private int migratateInvioceBPAddress(List<ItemCollection> invoices, Map<String, String> map) {
|
||||
int count = 0;
|
||||
for (ItemCollection invoice : invoices) {
|
||||
String cdtrNumber = invoice.getItemValueString("cdtr.number");
|
||||
String newNumber = map.get(cdtrNumber);
|
||||
if (newNumber != null) {
|
||||
// migrate number
|
||||
invoice.setItemValue("cdtr.number.old", cdtrNumber);
|
||||
invoice.setItemValue("cdtr.number", newNumber);
|
||||
|
||||
logger.info("│ ├── replace " + cdtrNumber + "->" + newNumber + " : " + invoice.getUniqueID());
|
||||
// documentService.save(invoice);
|
||||
count++;
|
||||
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Diese hilfsmethode liest die Cargosoft Datei mit den Mapping - alt->neu ein
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Map<String, String> readAdressMapping() {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
try (InputStream inputStream = getClass().getClassLoader()
|
||||
.getResourceAsStream("agl_wandlung_20250822.csv");
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
|
||||
String line;
|
||||
boolean firstLine = true;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (firstLine) {
|
||||
firstLine = false;
|
||||
continue; // Header überspringen
|
||||
}
|
||||
|
||||
String[] parts = line.split(";");
|
||||
if (parts.length == 2) {
|
||||
String oldID = parts[0].trim();
|
||||
String newID = parts[1].trim();
|
||||
result.put(oldID, newID);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Logging framework verwenden
|
||||
System.err.println("Fehler beim Laden der CSV: " + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hilfsmethode speichert eine cargoosft kreditor object...
|
||||
*
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue