aggiunto messaggio di errore se l'articolo non esiste
This commit is contained in:
@@ -76,14 +76,22 @@ public class ToscaSalesService {
|
|||||||
Iterator<Row> rowIterator = UtilityExcel.readXlsxFile(inputStream, true);
|
Iterator<Row> rowIterator = UtilityExcel.readXlsxFile(inputStream, true);
|
||||||
List<ToscaOrdineVenditaDTO> ordiniDaImportare = new ArrayList<>();
|
List<ToscaOrdineVenditaDTO> ordiniDaImportare = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Long> diacodNotFound = new ArrayList<>();
|
||||||
while (rowIterator.hasNext()) {
|
while (rowIterator.hasNext()) {
|
||||||
Row row = rowIterator.next();
|
Row row = rowIterator.next();
|
||||||
ToscaOrdineVenditaDTO newDTO = new ToscaOrdineVenditaDTO();
|
ToscaOrdineVenditaDTO newDTO = new ToscaOrdineVenditaDTO();
|
||||||
|
|
||||||
|
String codMart = null;
|
||||||
|
Long diacod= Long.valueOf(UtilityExcel.getCellAsString(row, 2));
|
||||||
|
codMart = findCodMartFromDiacod(String.valueOf(diacod));
|
||||||
|
if (UtilityString.isNullOrEmpty(codMart) && !diacodNotFound.contains(diacod)) {
|
||||||
|
diacodNotFound.add(diacod);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
newDTO
|
newDTO
|
||||||
.setTransactionNumber(UtilityExcel.getCellAsString(row, 0))
|
.setTransactionNumber(UtilityExcel.getCellAsString(row, 0))
|
||||||
.setDateTransaction(UtilityExcel.getCellAsDate(row, 1, CommonConstants.DATE_FORMAT_DMY_DASHED))
|
.setDateTransaction(UtilityExcel.getCellAsDate(row, 1, CommonConstants.DATE_FORMAT_DMY_DASHED))
|
||||||
.setItemNumber(Long.valueOf(UtilityExcel.getCellAsString(row, 2)))
|
.setItemNumber(diacod)
|
||||||
.setItemName(UtilityExcel.getCellAsString(row, 3))
|
.setItemName(UtilityExcel.getCellAsString(row, 3))
|
||||||
.setQuantityDelivered(new BigDecimal(UtilityExcel.getCellAsString(row, 4)))
|
.setQuantityDelivered(new BigDecimal(UtilityExcel.getCellAsString(row, 4)))
|
||||||
.setDepotNumber(UtilityExcel.getCellAsString(row, 5))
|
.setDepotNumber(UtilityExcel.getCellAsString(row, 5))
|
||||||
@@ -99,12 +107,17 @@ public class ToscaSalesService {
|
|||||||
.setTransporterName(UtilityExcel.getCellAsString(row, 15))
|
.setTransporterName(UtilityExcel.getCellAsString(row, 15))
|
||||||
.setDeliveryDate(UtilityExcel.getCellAsDate(row, 16, CommonConstants.DATE_FORMAT_DMY_DASHED))
|
.setDeliveryDate(UtilityExcel.getCellAsDate(row, 16, CommonConstants.DATE_FORMAT_DMY_DASHED))
|
||||||
.setCodAnag(findCodAnagFromDiacod(newDTO.getCounterPNr()))
|
.setCodAnag(findCodAnagFromDiacod(newDTO.getCounterPNr()))
|
||||||
.setCodMart(findCodMartFromDiacod(String.valueOf(newDTO.getItemNumber())))
|
.setCodMart(codMart)
|
||||||
.setCodMdep(findCodMdepFromDiacod(newDTO.getDepotNumber()))
|
.setCodMdep(findCodMdepFromDiacod(newDTO.getDepotNumber()))
|
||||||
;
|
;
|
||||||
|
|
||||||
ordiniDaImportare.add(newDTO);
|
ordiniDaImportare.add(newDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!diacodNotFound.isEmpty()) {
|
||||||
|
throw new Exception("Articoli non trovati: " + String.join(", ", String.valueOf(diacodNotFound)));
|
||||||
|
}
|
||||||
|
|
||||||
return ordiniDaImportare;
|
return ordiniDaImportare;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +128,11 @@ public class ToscaSalesService {
|
|||||||
|
|
||||||
private String findCodMartFromDiacod(String diacod) throws Exception {
|
private String findCodMartFromDiacod(String diacod) throws Exception {
|
||||||
String sql = "SELECT cod_mart from mtb_aart where diacod = " + UtilityDB.valueToString(diacod);
|
String sql = "SELECT cod_mart from mtb_aart where diacod = " + UtilityDB.valueToString(diacod);
|
||||||
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
String codMart = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||||
|
if (UtilityString.isNullOrEmpty(codMart)) {
|
||||||
|
throw new Exception(String.format("Articolo non trovato per il codice %S", diacod));
|
||||||
|
}
|
||||||
|
return codMart;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String findCodAnagFromDiacod(String diacod) throws Exception {
|
private String findCodAnagFromDiacod(String diacod) throws Exception {
|
||||||
@@ -235,7 +252,6 @@ public class ToscaSalesService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String ragSoc = order.getTransporterName();
|
String ragSoc = order.getTransporterName();
|
||||||
GtbAnag gtbAnag = new GtbAnag();
|
GtbAnag gtbAnag = new GtbAnag();
|
||||||
gtbAnag
|
gtbAnag
|
||||||
|
|||||||
Reference in New Issue
Block a user