Importazione packing list Eviosys

This commit is contained in:
2024-05-23 15:19:09 +02:00
parent bf4a4359f7
commit 6cca2bf89e
3 changed files with 205 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20240522152800 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
createSetup("IMPORT_COLLI", "EVIOSYS", "ATTIVO", "N", "Inserire S/N per attivare/disattivare il tipo di importazione", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "COD_ANAG", null, "Codice fornitore", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "COD_MDEP", null, "Codice deposito", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "EMAIL_FOR_LOG", null, "Inserire il file l'indirizzo email per inviare il log dell'importazione", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "FILE_FILTER", null, "Inserire il criterio di filtro dei file o il nome del file specifio (seguire la sintassi di java)", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "GG_CANC_FILE", null, "Giorni per la cancellazione dei file dalla cartella di appoggio", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "IMPORT_REST", "S", "Inserire S/N per attivare/disattivare il salvataggio con i servizi REST", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "LISTENING", "N", "Se LISTENIG = 'N' la procedura di importazione non si potrà mai mettere in ascolto sulla directory perchè nella procedura vengono prese in considerazione più file.", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "PATH_FILE", null, "Directory contente i file da importare.", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "PATH_FILE_IMPORTED", null, "Directory dove vengono spostati i file dopo l'importazione.", false, null, false, false, false, false, false, null, false, null);
}
@Override
public void down() throws Exception {
}
}

View File

@@ -4,6 +4,7 @@ import it.integry.ems.Import.base.BaseEntityImporter;
import it.integry.ems.Import.base.IEntityImporter;
import it.integry.ems.logistic.Import.service.*;
import it.integry.ems.logistic.service.ColliBaioneImportService;
import it.integry.ems.logistic.service.ColliEviosysImportService;
import it.integry.ems.logistic.service.ColliImportService;
import it.integry.ems_model.base.EntityBase;
import org.springframework.web.context.ContextLoader;
@@ -54,7 +55,9 @@ public class ColliImporter extends BaseEntityImporter implements IEntityImporter
break;
case BAIONE:
entities = context.getBean(ColliBaioneImportService.class).importColli(type, format, requestDto, anomalie);
break;
case EVIOSYS:
entities = context.getBean(ColliEviosysImportService.class).importColli(type, format, requestDto, anomalie);
break;
default:
throw new Exception(String.format("Tipo %s non supportato", format));
@@ -75,7 +78,8 @@ public class ColliImporter extends BaseEntityImporter implements IEntityImporter
ICON_ACCETTAZIONE("ICON_ACCETTAZIONE"),
STEUP("STEUP"),
METALSISTEM("METALSISTEM"),
BAIONE("BAIONE");
BAIONE("BAIONE"),
EVIOSYS("EVIOSYS");
private String text;

View File

@@ -0,0 +1,168 @@
package it.integry.ems.logistic.service;
import it.integry.ems.Import.dto.AnomalieDTO;
import it.integry.ems.Import.dto.ImportRequestDTO;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems_model.base.EntityBase;
import it.integry.ems_model.entity.MtbColr;
import it.integry.ems_model.entity.MtbColt;
import it.integry.ems_model.service.SetupGest;
import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.utility.Query;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityExcel;
import it.integry.ems_model.utility.UtilityString;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.sql.Connection;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.StreamSupport.stream;
@Service
@Scope(value = "request")
public class ColliEviosysImportService {
@Autowired
private EntityProcessor entityProcessor;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private SetupGest setupGest;
public List<EntityBase> importColli(String type, String format, ImportRequestDTO requestDTO, List<AnomalieDTO> anomalie) throws Exception {
Connection conn = multiDBTransactionManager.getPrimaryConnection();
Map<String, String> setup = setupGest.getImportSetupSection(conn, type, format);
String codAnag = setup.get("COD_ANAG");
String codMdep = setup.get("COD_MDEP");
Iterator<Row> rowIterator = UtilityExcel.readXlsxFile(requestDTO);
String codMart = null;
boolean hasHeaderPassed = false;
List<MtbColt> mtbColtList = new ArrayList<>();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
if (!hasHeaderPassed) {
if (codMart == null) {
codMart = findCodMart(row);
} else {
hasHeaderPassed = UtilityExcel.getCellAsString(row, 0, false).equalsIgnoreCase("origine");
}
} else {
List<Object> rowData =
stream(((Iterable<Cell>) row::cellIterator).spliterator(), false)
.map(x -> {
Object s = cellToString(x);
if (!UtilityString.isNullOrEmpty(s)) {
return s;
}
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (rowData.size() >= 7) {
String barcodeUl = (String) rowData.get(2);
String qta = (String) rowData.get(6);
if (barcodeUl.length() > 18) {
barcodeUl = barcodeUl.substring(2);
}
MtbColr mtbColr = new MtbColr()
.setCodMart(codMart)
.setQtaCol(UtilityString.stringToBigDecimal(qta));
MtbColt mtbColt = new MtbColt()
.setDataCollo(LocalDate.now())
.setSegno(1)
.setGestione("A")
.setBarcodeUl(barcodeUl)
.setCodMdep(codMdep)
.setCodAnag(codAnag);
mtbColt.setMtbColr(new ArrayList<>())
.getMtbColr()
.add(mtbColr);
mtbColt.setOperation(OperationType.INSERT);
mtbColtList.add(mtbColt);
}
}
}
return entityProcessor.processEntityList(mtbColtList, multiDBTransactionManager, true);
}
private Object cellToString(Cell cell) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
for (int i = 0; i < cell.getStringCellValue().length(); i++) {
if (cell.getStringCellValue().charAt(i) != ' ') {
return cell.getStringCellValue().trim();
}
}
return "";
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
double numericCellValue = cell.getNumericCellValue();
if (numericCellValue == Math.floor(numericCellValue)) {
return String.valueOf((int) numericCellValue);
}
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue();
} else {
return String.valueOf(numericCellValue);
}
} else {
return "";
}
}
private String findCodMart(Row row) throws Exception {
Iterator<Cell> cellIterator = row.cellIterator();
String codArtFor = stream(((Iterable<Cell>) () -> cellIterator).spliterator(), false)
.map(cell -> {
try {
return UtilityExcel.getCellAsString(row, cell.getColumnIndex(), true);
} catch (Exception e) {
return null;
}
})
.filter(Objects::nonNull)
.reduce(new String[]{null, null}, (state, cell) -> {
if (state[0] == null && cell.equalsIgnoreCase("viaggio:")) {
state[0] = "viaggio";
} else if (state[0] != null && state[1] == null && cell.equalsIgnoreCase("articolo:")) {
state[1] = "articolo";
} else if ("articolo".equals(state[1]) && UtilityString.isNumber(cell)) {
state[1] = cell;
}
return state;
}, (s1, s2) -> s1)[1];
if (codArtFor != null) {
String sql = Query.format("SELECT cod_mart FROM mtb_lisa WHERE cod_art_for = %s", codArtFor);
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
}
return null;
}
}