abschluss migration
This commit is contained in:
parent
c6205b9c43
commit
e0e5bbd8f3
1 changed files with 192 additions and 110 deletions
|
|
@ -27,15 +27,8 @@
|
||||||
|
|
||||||
package com.alexanderlogistics.api;
|
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.io.Serializable;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.imixs.marty.team.TeamService;
|
import org.imixs.marty.team.TeamService;
|
||||||
|
|
@ -203,131 +196,220 @@ public class CargosoftMigrationRestService implements Serializable {
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@GET
|
// @GET
|
||||||
@Path("/cargosoft-renew_cdtr_number")
|
// @Path("/cargosoft-renew_cdtr_number")
|
||||||
@Produces({ MediaType.TEXT_PLAIN })
|
// @Produces({ MediaType.TEXT_PLAIN })
|
||||||
public String migrationAdresswandlungOpenInvoices(@QueryParam("maxcount") int maxcount,
|
// public String migrationAdresswandlungOpenInvoices(@QueryParam("maxcount") int
|
||||||
@QueryParam("type") String type)
|
// maxcount,
|
||||||
throws QueryException, AccessDeniedException, ProcessingErrorException, PluginException, ModelException {
|
// @QueryParam("type") String type)
|
||||||
StringBuffer messageBuffer = new StringBuffer();
|
// throws QueryException, AccessDeniedException, ProcessingErrorException,
|
||||||
if (maxcount <= 0) {
|
// PluginException, ModelException {
|
||||||
maxcount = 10;
|
// StringBuffer messageBuffer = new StringBuffer();
|
||||||
}
|
// if (maxcount <= 0) {
|
||||||
if (type == null || type.isEmpty()) {
|
// maxcount = 10;
|
||||||
type = "workitem";
|
// }
|
||||||
}
|
// if (type == null || type.isEmpty()) {
|
||||||
|
// type = "workitem";
|
||||||
|
// }
|
||||||
|
|
||||||
if (isRunning) {
|
// if (isRunning) {
|
||||||
log("├── sync process already running!", messageBuffer);
|
// log("├── sync process already running!", messageBuffer);
|
||||||
return messageBuffer.toString();
|
// return messageBuffer.toString();
|
||||||
}
|
// }
|
||||||
isRunning = true;
|
// isRunning = true;
|
||||||
|
|
||||||
log("├── read cargosoft migration file....", messageBuffer);
|
// log("├── read cargosoft migration file....", messageBuffer);
|
||||||
Map<String, String> mapping = readAdressMapping();
|
// Map<String, String> mapping = readAdressMapping();
|
||||||
log("├── found " + mapping.size() + " mappings", messageBuffer);
|
// log("├── found " + mapping.size() + " mappings", messageBuffer);
|
||||||
|
|
||||||
String query = "(type:" + type + ") AND ($modelversion:rechnungseingang*)";
|
// String query = "(type:" + type + ") AND ($modelversion:rechnungseingang*)";
|
||||||
// int syncs = 0;
|
// // int syncs = 0;
|
||||||
long l = System.currentTimeMillis();
|
// long l = System.currentTimeMillis();
|
||||||
int batchSize = 100;
|
// int batchSize = 100;
|
||||||
int totalUpdates = 0;
|
// int totalUpdates = 0;
|
||||||
|
|
||||||
log("├── migration cargosoft addresses....", messageBuffer);
|
// log("├── migration cargosoft addresses....", messageBuffer);
|
||||||
log("│ ├── query=" + query, messageBuffer);
|
// log("│ ├── query=" + query, messageBuffer);
|
||||||
|
|
||||||
int totalCount = documentService.count(query);
|
// int totalCount = documentService.count(query);
|
||||||
log("│ ├── found " + totalCount + " invoices", messageBuffer);
|
// log("│ ├── found " + totalCount + " invoices", messageBuffer);
|
||||||
|
|
||||||
// Berechne Anzahl der benötigten Pages
|
// // Berechne Anzahl der benötigten Pages
|
||||||
int totalPages = (int) Math.ceil((double) totalCount / batchSize);
|
// int totalPages = (int) Math.ceil((double) totalCount / batchSize);
|
||||||
|
|
||||||
// Verarbeite Page für Page
|
// // Verarbeite Page für Page
|
||||||
for (int pageIndex = 0; pageIndex < totalPages; pageIndex++) {
|
// for (int pageIndex = 0; pageIndex < totalPages; pageIndex++) {
|
||||||
log("│ ├── read page " + pageIndex, messageBuffer);
|
// log("│ ├── read page " + pageIndex, messageBuffer);
|
||||||
List<ItemCollection> invoiceList = documentService.find(query, batchSize, pageIndex);
|
// List<ItemCollection> invoiceList = documentService.find(query, batchSize,
|
||||||
long l1 = System.currentTimeMillis();
|
// pageIndex);
|
||||||
log("│ ├── ...verifying " + invoiceList.size() + " invoices...", messageBuffer);
|
// long l1 = System.currentTimeMillis();
|
||||||
int updates = migratateInvioceBPAddress(invoiceList, mapping);
|
// log("│ ├── ...verifying " + invoiceList.size() + " invoices...",
|
||||||
totalUpdates = totalUpdates + updates;
|
// messageBuffer);
|
||||||
log("│ ├── " + updates + " invoices migrated in " +
|
// int updates = migratateInvioceBPAddress(invoiceList, mapping);
|
||||||
(System.currentTimeMillis() - l1) + "ms ", messageBuffer);
|
// totalUpdates = totalUpdates + updates;
|
||||||
// break;
|
// log("│ ├── " + updates + " invoices migrated in " +
|
||||||
if (totalUpdates >= maxcount) {
|
// (System.currentTimeMillis() - l1) + "ms ", messageBuffer);
|
||||||
break;
|
// // break;
|
||||||
}
|
// if (totalUpdates >= maxcount) {
|
||||||
}
|
// break;
|
||||||
long duration = System.currentTimeMillis() - l;
|
// }
|
||||||
double objectsPerSecond = totalUpdates / (duration / 1000.0);
|
// }
|
||||||
log("├── Successfully " + totalUpdates + " invoices migrated in " + duration + "ms ("
|
// long duration = System.currentTimeMillis() - l;
|
||||||
+ String.format("%.1f", objectsPerSecond) + " objects/sec)", messageBuffer);
|
// double objectsPerSecond = totalUpdates / (duration / 1000.0);
|
||||||
|
// log("├── Successfully " + totalUpdates + " invoices migrated in " + duration
|
||||||
|
// + "ms ("
|
||||||
|
// + String.format("%.1f", objectsPerSecond) + " objects/sec)", messageBuffer);
|
||||||
|
|
||||||
isRunning = false;
|
// isRunning = false;
|
||||||
return messageBuffer.toString();
|
// return messageBuffer.toString();
|
||||||
}
|
// }
|
||||||
|
|
||||||
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
|
// @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
|
||||||
private int migratateInvioceBPAddress(List<ItemCollection> invoices, Map<String, String> map) {
|
// private int migratateInvioceBPAddress(List<ItemCollection> invoices,
|
||||||
int count = 0;
|
// Map<String, String> map) {
|
||||||
for (ItemCollection invoice : invoices) {
|
// int count = 0;
|
||||||
String cdtrNumber = invoice.getItemValueString("cdtr.number");
|
// for (ItemCollection invoice : invoices) {
|
||||||
if (cdtrNumber.isBlank()) {
|
// String cdtrNumber = invoice.getItemValueString("cdtr.number");
|
||||||
logger.warning(" ..Invoice " + invoice.getUniqueID() + " has no cdtr.number!");
|
// if (cdtrNumber.isBlank()) {
|
||||||
continue;
|
// logger.warning(" ..Invoice " + invoice.getUniqueID() + " has no
|
||||||
}
|
// cdtr.number!");
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
// logger.info("==> check cdtr.number: " + cdtrNumber);
|
// // logger.info("==> check cdtr.number: " + cdtrNumber);
|
||||||
// K überspringen
|
// // K überspringen
|
||||||
String newNumber = map.get(cdtrNumber.substring(1));
|
// String newNumber = map.get(cdtrNumber.substring(1));
|
||||||
if (newNumber != null) {
|
// if (newNumber != null) {
|
||||||
// migrate number
|
// // migrate number
|
||||||
invoice.setItemValue("cdtr.number.old", cdtrNumber);
|
// invoice.setItemValue("cdtr.number.old", cdtrNumber);
|
||||||
invoice.setItemValue("cdtr.number", "K" + newNumber);
|
// invoice.setItemValue("cdtr.number", "K" + newNumber);
|
||||||
|
|
||||||
logger.info("│ ├── replace " + cdtrNumber + " -> K" + newNumber + " : " + invoice.getUniqueID());
|
// logger.info("│ ├── replace " + cdtrNumber + " -> K" + newNumber + " : " +
|
||||||
documentService.save(invoice);
|
// invoice.getUniqueID());
|
||||||
count++;
|
// documentService.save(invoice);
|
||||||
|
// count++;
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return count;
|
// return count;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migriert die Rechnungen mit den neuen cdtr. Nummern
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// @GET
|
||||||
|
// @Path("/fix-separun")
|
||||||
|
// @Produces({ MediaType.TEXT_PLAIN })
|
||||||
|
// public String fixSepaRun(@QueryParam("maxcount") int maxcount)
|
||||||
|
// throws QueryException, AccessDeniedException, ProcessingErrorException,
|
||||||
|
// PluginException, ModelException {
|
||||||
|
// StringBuffer messageBuffer = new StringBuffer();
|
||||||
|
// int totalUpdates = 0;
|
||||||
|
// if (maxcount <= 0) {
|
||||||
|
// maxcount = 10;
|
||||||
|
|
||||||
|
// if (isRunning) {
|
||||||
|
// log("├── sync process already running!", messageBuffer);
|
||||||
|
// return messageBuffer.toString();
|
||||||
|
// }
|
||||||
|
// isRunning = true;
|
||||||
|
|
||||||
|
// String query = "(type:workitem) AND ($modelversion:rechnungseingang*) AND
|
||||||
|
// ($taskid:5500)";
|
||||||
|
// // int syncs = 0;
|
||||||
|
// long l = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// log("├── migration sepa run....", messageBuffer);
|
||||||
|
// log("│ ├── query=" + query, messageBuffer);
|
||||||
|
// int totalCount = documentService.count(query);
|
||||||
|
// log("│ ├── found " + totalCount + " invoices", messageBuffer);
|
||||||
|
// List<ItemCollection> invoiceList = documentService.find(query, 999, 0);
|
||||||
|
// long l1 = System.currentTimeMillis();
|
||||||
|
// log("│ ├── ...verifying " + invoiceList.size() + " invoices...",
|
||||||
|
// messageBuffer);
|
||||||
|
|
||||||
|
// for (ItemCollection invoice : invoiceList) {
|
||||||
|
|
||||||
|
// String cdtrNumber = invoice.getItemValueString("cdtr.number");
|
||||||
|
// String cdtrNumberOld = invoice.getItemValueString("cdtr.number.old");
|
||||||
|
// String bpPartnerID = invoice.getItemValueString("partner.id");
|
||||||
|
// if (bpPartnerID.isEmpty()) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// if (cdtrNumberOld.isEmpty()) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // lookup bp ....
|
||||||
|
// ItemCollection bpPartner =
|
||||||
|
// businessPartnerService.getBusinessPartnerByID(InvoiceUtil.getBPID(invoice));
|
||||||
|
// String fixPartnerName = bpPartner.getItemValueString("partner.name");
|
||||||
|
// String fixPartnerId = bpPartner.getItemValueString("partner.id");
|
||||||
|
|
||||||
|
// if (!bpPartnerID.equals(fixPartnerId)) {
|
||||||
|
// logger.info("Problem found with invoice: " + invoice.getUniqueID() + " wrong
|
||||||
|
// partnerID="
|
||||||
|
// + bpPartnerID + " correct= " + fixPartnerId);
|
||||||
|
// logger.info(" correct name= " + fixPartnerName);
|
||||||
|
|
||||||
|
// invoice.setItemValue("partner.id", fixPartnerId);
|
||||||
|
// invoice.setItemValue("cdtr.name", fixPartnerName);
|
||||||
|
// invoice.setItemValue("partner.name", fixPartnerName);
|
||||||
|
// documentService.save(invoice);
|
||||||
|
// // workflowService.processWorkItem(invoice.event(10));
|
||||||
|
// totalUpdates++;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// log("│ ├── " + totalUpdates + " invoices migrated in " +
|
||||||
|
// (System.currentTimeMillis() - l1) + "ms ", messageBuffer);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// log("├── Successfully " + totalUpdates + " invoices migrated",
|
||||||
|
// messageBuffer);
|
||||||
|
|
||||||
|
// isRunning = false;
|
||||||
|
// return messageBuffer.toString();
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Diese hilfsmethode liest die Cargosoft Datei mit den Mapping - alt->neu ein
|
* Diese hilfsmethode liest die Cargosoft Datei mit den Mapping - alt->neu ein
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Map<String, String> readAdressMapping() {
|
// private Map<String, String> readAdressMapping() {
|
||||||
Map<String, String> result = new HashMap<>();
|
// Map<String, String> result = new HashMap<>();
|
||||||
try (InputStream inputStream = getClass().getClassLoader()
|
// try (InputStream inputStream = getClass().getClassLoader()
|
||||||
.getResourceAsStream("agl_wandlung_20250822.csv");
|
// .getResourceAsStream("agl_wandlung_20250822.csv");
|
||||||
BufferedReader reader = new BufferedReader(
|
// BufferedReader reader = new BufferedReader(
|
||||||
new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
// new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||||
|
|
||||||
String line;
|
// String line;
|
||||||
boolean firstLine = true;
|
// boolean firstLine = true;
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
// while ((line = reader.readLine()) != null) {
|
||||||
if (firstLine) {
|
// if (firstLine) {
|
||||||
firstLine = false;
|
// firstLine = false;
|
||||||
continue; // Header überspringen
|
// continue; // Header überspringen
|
||||||
}
|
// }
|
||||||
|
|
||||||
String[] parts = line.split(";");
|
// String[] parts = line.split(";");
|
||||||
if (parts.length == 2) {
|
// if (parts.length == 2) {
|
||||||
String oldID = parts[0].trim();
|
// String oldID = parts[0].trim();
|
||||||
String newID = parts[1].trim();
|
// String newID = parts[1].trim();
|
||||||
result.put(oldID, newID);
|
// result.put(oldID, newID);
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
// Logging framework verwenden
|
// // Logging framework verwenden
|
||||||
System.err.println("Fehler beim Laden der CSV: " + e.getMessage());
|
// System.err.println("Fehler beim Laden der CSV: " + e.getMessage());
|
||||||
}
|
// }
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hilfsmethode speichert eine cargoosft kreditor object...
|
* Hilfsmethode speichert eine cargoosft kreditor object...
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue