diff --git a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColt.java b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColt.java index 2160046e..dfad9b2d 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColt.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColt.java @@ -66,6 +66,8 @@ public class MtbColt extends EntityBase { private BigDecimal altezzaCm; private String codJcom; + private String barcodeUl; + private final transient MutableLiveData mtbTCol = new MutableLiveData<>(); private Boolean disablePrint; @@ -544,6 +546,15 @@ public class MtbColt extends EntityBase { return this; } + public String getBarcodeUl() { + return barcodeUl; + } + + public MtbColt setBarcodeUl(String barcodeUl) { + this.barcodeUl = barcodeUl; + return this; + } + public ObservableMtbTcol getMtbTCol() { return mtbTCol.getValue(); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java index b8788485..9ff820df 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java @@ -114,8 +114,19 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { return this.mEntityRESTConsumer.processEntityListSynchronized(mtbColtsToSave, true, MtbColt.class); } - public void createColloScaricoDaCarico(MtbColt sourceMtbColt, MtbDepoPosizione posizione, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var mtbColt = createColloScaricoDaCaricoSynchronized(sourceMtbColt, posizione); + if (onComplete != null) onComplete.run(mtbColt); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + + public MtbColt createColloScaricoDaCaricoSynchronized(MtbColt sourceMtbColt, MtbDepoPosizione posizione) throws Exception { MtbColt newMtbColt = new MtbColt() .initDefaultFields(GestioneEnum.LAVORAZIONE) @@ -164,7 +175,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { } - saveCollo(newMtbColt, onComplete, onFailed); + return saveColloSynchronized(newMtbColt); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MaterialiRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MaterialiRESTConsumer.java index da79b417..ada5b12f 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MaterialiRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MaterialiRESTConsumer.java @@ -8,6 +8,7 @@ import it.integry.integrywmsnative.core.expansion.RunnableArgs; import it.integry.integrywmsnative.core.model.MtbColt; import it.integry.integrywmsnative.core.rest.RESTBuilder; import it.integry.integrywmsnative.core.rest.model.materiali.RecuperaMaterialiRequestDTO; +import it.integry.integrywmsnative.core.rest.model.materiali.VersaMaterialiRequestDTO; @Singleton public class MaterialiRESTConsumer extends _BaseRESTConsumer { @@ -43,4 +44,27 @@ public class MaterialiRESTConsumer extends _BaseRESTConsumer { }); } + public void makeSynchronousVersaRequest(VersaMaterialiRequestDTO request) throws Exception { + var materialiRESTConsumerService = restBuilder.getService(MaterialiRESTConsumerService.class); + + var response = materialiRESTConsumerService.versa(request) + .execute(); + + + var data = analyzeAnswer(response, "versaMateriali"); +// if (data == null) return null; +// return data.getUpdatedMtbColtScarico(); + } + + public void makeVersaRequest(VersaMaterialiRequestDTO request, final Runnable onComplete, final RunnableArgs onFailed) { + executorService.execute(() -> { + try { + makeSynchronousVersaRequest(request); + if (onComplete != null) onComplete.run(); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MaterialiRESTConsumerService.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MaterialiRESTConsumerService.java index 57b6a67e..b26c51a2 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MaterialiRESTConsumerService.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MaterialiRESTConsumerService.java @@ -3,12 +3,16 @@ package it.integry.integrywmsnative.core.rest.consumers; import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse; import it.integry.integrywmsnative.core.rest.model.materiali.RecuperaMaterialiRequestDTO; import it.integry.integrywmsnative.core.rest.model.materiali.RecuperaMaterialiResponseDTO; +import it.integry.integrywmsnative.core.rest.model.materiali.VersaMaterialiRequestDTO; import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.POST; public interface MaterialiRESTConsumerService { + @POST("wms/materiali/versa") + Call> versa(@Body VersaMaterialiRequestDTO request); + @POST("wms/materiali/recupera") Call> recupera(@Body RecuperaMaterialiRequestDTO request); diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/model/materiali/VersaMaterialiRequestDTO.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/model/materiali/VersaMaterialiRequestDTO.java new file mode 100644 index 00000000..8cb1fa80 --- /dev/null +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/model/materiali/VersaMaterialiRequestDTO.java @@ -0,0 +1,110 @@ +package it.integry.integrywmsnative.core.rest.model.materiali; + +import java.math.BigDecimal; +import java.time.LocalDate; + +public class VersaMaterialiRequestDTO { + + private String codMart; + private String partitaMag; + private BigDecimal numCnf; + private BigDecimal qtaCnf; + private BigDecimal qtaTot; + + private Integer numCollo; + private LocalDate dataCollo; + private String gestione; + private String serCollo; + private String barcodeUl; + + + public String getCodMart() { + return codMart; + } + + public VersaMaterialiRequestDTO setCodMart(String codMart) { + this.codMart = codMart; + return this; + } + + public String getPartitaMag() { + return partitaMag; + } + + public VersaMaterialiRequestDTO setPartitaMag(String partitaMag) { + this.partitaMag = partitaMag; + return this; + } + + public BigDecimal getNumCnf() { + return numCnf; + } + + public VersaMaterialiRequestDTO setNumCnf(BigDecimal numCnf) { + this.numCnf = numCnf; + return this; + } + + public BigDecimal getQtaCnf() { + return qtaCnf; + } + + public VersaMaterialiRequestDTO setQtaCnf(BigDecimal qtaCnf) { + this.qtaCnf = qtaCnf; + return this; + } + + public BigDecimal getQtaTot() { + return qtaTot; + } + + public VersaMaterialiRequestDTO setQtaTot(BigDecimal qtaTot) { + this.qtaTot = qtaTot; + return this; + } + + public Integer getNumCollo() { + return numCollo; + } + + public VersaMaterialiRequestDTO setNumCollo(Integer numCollo) { + this.numCollo = numCollo; + return this; + } + + public LocalDate getDataCollo() { + return dataCollo; + } + + public VersaMaterialiRequestDTO setDataCollo(LocalDate dataCollo) { + this.dataCollo = dataCollo; + return this; + } + + public String getGestione() { + return gestione; + } + + public VersaMaterialiRequestDTO setGestione(String gestione) { + this.gestione = gestione; + return this; + } + + public String getSerCollo() { + return serCollo; + } + + public VersaMaterialiRequestDTO setSerCollo(String serCollo) { + this.serCollo = serCollo; + return this; + } + + public String getBarcodeUl() { + return barcodeUl; + } + + public VersaMaterialiRequestDTO setBarcodeUl(String barcodeUl) { + this.barcodeUl = barcodeUl; + return this; + } +} \ No newline at end of file diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/model/materiali/VersaMaterialiResponseDTO.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/model/materiali/VersaMaterialiResponseDTO.java new file mode 100644 index 00000000..9f997465 --- /dev/null +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/model/materiali/VersaMaterialiResponseDTO.java @@ -0,0 +1,4 @@ +package it.integry.integrywmsnative.core.rest.model.materiali; + +public class VersaMaterialiResponseDTO { +} diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeFragment.java index 4c9f2df4..3b00ea87 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeFragment.java @@ -23,6 +23,7 @@ import java.util.List; import javax.inject.Inject; +import it.integry.barcode_base_android_library.model.BarcodeScanDTO; import it.integry.integrywmsnative.MainApplication; import it.integry.integrywmsnative.R; import it.integry.integrywmsnative.core.barcode_reader.BarcodeCallbackDTO; @@ -194,12 +195,26 @@ public class ProdVersamentoMaterialeFragment extends BaseFragment implements Pro private void initBarcodeReader() { mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() - .setOnScanSuccessful(mViewModel::processBarcodeDTO) + .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(this::onError)); BarcodeManager.enable(mBarcodeScannerInstanceID); } + private final RunnableArgs onScanSuccessful = data -> { + this.onLoadingStarted(); + + executorService.execute(() -> { + try { + this.mViewModel.processBarcodeDTO(data); + } catch (Exception e) { + onError(e); + } + }); + + this.onLoadingEnded(); + }; + // private void openLU() { // DialogScanOrCreateLUView.newInstance(false, false, true, false, true, (mtbColt, created) -> { // if (mtbColt == null) { @@ -223,13 +238,14 @@ public class ProdVersamentoMaterialeFragment extends BaseFragment implements Pro // }).show(requireActivity().getSupportFragmentManager(), "tag"); // } - private void choosePosition(RunnableArgs onComplete) { + private void choosePosition(RunnableArgss onComplete) { DialogAskPositionOfLUView.newInstance(false, (status, mtbDepoPosizione) -> { if (status == DialogConsts.Results.ABORT) { + onComplete.run(false, null); popMe(); } else { - onComplete.run(mtbDepoPosizione); + onComplete.run(true, mtbDepoPosizione); } }) @@ -359,7 +375,7 @@ public class ProdVersamentoMaterialeFragment extends BaseFragment implements Pro } @Override - public void onRequestChoosePosition(RunnableArgs onComplete) { + public void onRequestChoosePosition(RunnableArgss onComplete) { choosePosition(onComplete); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeModule.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeModule.java index 694b6879..f4c88e0a 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeModule.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeModule.java @@ -6,6 +6,7 @@ import it.integry.integrywmsnative.core.rest.consumers.ArticoloRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.ColliLavorazioneRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsumer; +import it.integry.integrywmsnative.core.rest.consumers.MaterialiRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.MesRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.PosizioniRESTConsumer; @@ -18,8 +19,9 @@ public class ProdVersamentoMaterialeModule { ColliLavorazioneRESTConsumer colliLavorazioneRESTConsumer, MesRESTConsumer mesRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, - ArticoloRESTConsumer articoloRESTConsumer) { - return new ProdVersamentoMaterialeViewModel(posizioniRESTConsumer, colliMagazzinoRESTConsumer, colliLavorazioneRESTConsumer, mesRESTConsumer, barcodeRESTConsumer, articoloRESTConsumer); + ArticoloRESTConsumer articoloRESTConsumer, + MaterialiRESTConsumer materialiRESTConsumer) { + return new ProdVersamentoMaterialeViewModel(posizioniRESTConsumer, colliMagazzinoRESTConsumer, colliLavorazioneRESTConsumer, mesRESTConsumer, barcodeRESTConsumer, articoloRESTConsumer, materialiRESTConsumer); } } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeViewModel.java index b4484c1a..8ec4a251 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeViewModel.java @@ -1,8 +1,8 @@ package it.integry.integrywmsnative.gest.prod_versamento_materiale; -import androidx.lifecycle.MutableLiveData; +import android.util.Pair; -import com.annimon.stream.Stream; +import androidx.lifecycle.MutableLiveData; import org.jetbrains.annotations.NotNull; @@ -10,6 +10,8 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.util.Iterator; import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; @@ -18,7 +20,6 @@ import it.integry.integrywmsnative.core.exception.InvalidCodMdepException; import it.integry.integrywmsnative.core.exception.NoLUFoundException; import it.integry.integrywmsnative.core.exception.NoResultFromBarcodeException; import it.integry.integrywmsnative.core.exception.TooManyLUFoundInMonoLUPositionException; -import it.integry.integrywmsnative.core.expansion.RunnableArgs; import it.integry.integrywmsnative.core.expansion.RunnableArgss; import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILoadingListener; import it.integry.integrywmsnative.core.model.MtbAart; @@ -30,6 +31,7 @@ import it.integry.integrywmsnative.core.rest.consumers.ArticoloRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.ColliLavorazioneRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsumer; +import it.integry.integrywmsnative.core.rest.consumers.MaterialiRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.MesRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.PosizioniRESTConsumer; import it.integry.integrywmsnative.core.rest.model.Ean128Model; @@ -50,6 +52,7 @@ public class ProdVersamentoMaterialeViewModel { private final MesRESTConsumer mMesRESTConsumer; private final BarcodeRESTConsumer mBarcodeRESTConsumer; private final ArticoloRESTConsumer mArticoloRESTConsumer; + private final MaterialiRESTConsumer mMaterialiRESTConsumer; private boolean mFlagVersamentoDirettoProduzione; @@ -66,13 +69,15 @@ public class ProdVersamentoMaterialeViewModel { ColliLavorazioneRESTConsumer colliLavorazioneRESTConsumer, MesRESTConsumer mesRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, - ArticoloRESTConsumer articoloRESTConsumer) { + ArticoloRESTConsumer articoloRESTConsumer, + MaterialiRESTConsumer mMaterialiRESTConsumer) { this.mPosizioniRESTConsumer = posizioniRESTConsumer; this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer; this.mColliLavorazioneRESTConsumer = colliLavorazioneRESTConsumer; this.mMesRESTConsumer = mesRESTConsumer; this.mBarcodeRESTConsumer = barcodeRESTConsumer; this.mArticoloRESTConsumer = articoloRESTConsumer; + this.mMaterialiRESTConsumer = mMaterialiRESTConsumer; } @@ -81,7 +86,7 @@ public class ProdVersamentoMaterialeViewModel { } - public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO) { + public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO) throws Exception { if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) { this.executeEtichettaPosizione(barcodeScanDTO); } else if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) { @@ -94,93 +99,91 @@ public class ProdVersamentoMaterialeViewModel { } - private void executeEtichettaPosizione(BarcodeScanDTO barcodeScanDTO) { - - MtbDepoPosizione foundPosizione = Stream.of(SettingsManager.iDB().getAvailablePosizioni()) + private void executeEtichettaPosizione(BarcodeScanDTO barcodeScanDTO) throws Exception { + MtbDepoPosizione foundPosizione = SettingsManager.iDB().getAvailablePosizioni().stream() .filter(x -> x.getPosizione().equalsIgnoreCase(barcodeScanDTO.getStringValue())) - .single(); + .findFirst() + .orElse(null); + this.executePosizione(foundPosizione); - } - private void executePosizione(MtbDepoPosizione posizione) { - this.mPosizioniRESTConsumer.getBancaliInPosizione(posizione, mtbColtList -> { - - if (mtbColtList == null || mtbColtList.isEmpty()) { - this.sendError(new NoLUFoundException()); - } else if (mtbColtList.size() == 1) { - this.mColliMagazzinoRESTConsumer.getByTestata(mtbColtList.get(0), true, false, mtbColt -> { - - boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep()) - .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); - - if (codMdepIsValid) { - this.onLUOpened(mtbColt); - } else this.sendError(new InvalidCodMdepException()); - - }, this::sendError); - } else { - this.sendError(new TooManyLUFoundInMonoLUPositionException()); - } - - }, this::sendError); - } + private void executePosizione(MtbDepoPosizione posizione) throws Exception { + var mtbColtList = this.mPosizioniRESTConsumer.getBancaliInPosizioneSynchronized(posizione); - private void executeEtichettaLU(String sscc) { - this.mColliMagazzinoRESTConsumer.getBySSCC(sscc, true, false, mtbColt -> { + if (mtbColtList == null || mtbColtList.isEmpty()) { + this.sendError(new NoLUFoundException()); + } else if (mtbColtList.size() == 1) { + var mtbColt = this.mColliMagazzinoRESTConsumer.getByTestataSynchronized(mtbColtList.get(0), true, false); - boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep()) + boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream() .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); if (codMdepIsValid) { this.onLUOpened(mtbColt); - } else this.sendError(new InvalidCodMdepException()); + } else + throw new InvalidCodMdepException(); - }, this::sendError); + } else + throw new TooManyLUFoundInMonoLUPositionException(); } - private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO) { - mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> { + private void executeEtichettaLU(String sscc) throws Exception { + var mtbColt = this.mColliMagazzinoRESTConsumer.getBySsccSynchronized(sscc, true, false); - String barcodeProd = null; + boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream() + .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); - if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) barcodeProd = ean128Model.Sscc; - if (!UtilityString.isNullOrEmpty(ean128Model.Gtin)) barcodeProd = ean128Model.Gtin; - if (!UtilityString.isNullOrEmpty(ean128Model.Content)) - barcodeProd = ean128Model.Content; - - - if (!UtilityString.isNullOrEmpty(barcodeProd)) { - - if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) { - this.executeEtichettaLU(ean128Model.Sscc); - } else if (!UtilityString.isNullOrEmpty(barcodeProd)) { - this.loadArticolo(barcodeProd, ean128Model); - } else { - this.sendError(new NoLUFoundException()); - } - - - } else { - //EAN 128 non completo o comunque mancano i riferimenti al prodotto - this.sendError(new NoLUFoundException()); - } - }, this::sendError); + if (codMdepIsValid) { + this.onLUOpened(mtbColt); + } else + throw new InvalidCodMdepException(); } - private void loadArticolo(String barcodeProd, Ean128Model ean128Model) { - mArticoloRESTConsumer.searchByBarcode(barcodeProd, mtbAartList -> { - if (mtbAartList != null && !mtbAartList.isEmpty()) { - MtbAart articolo = mtbAartList.get(0); - this.dispatchArt(articolo, ean128Model); - } else { - this.sendError(new NoResultFromBarcodeException(barcodeProd)); - } + private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO) throws Exception { + var ean128Model = mBarcodeRESTConsumer.decodeEan128Synchronized(barcodeScanDTO); + + String barcodeProd = null; + + if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) barcodeProd = ean128Model.Sscc; + if (!UtilityString.isNullOrEmpty(ean128Model.Gtin)) barcodeProd = ean128Model.Gtin; + if (!UtilityString.isNullOrEmpty(ean128Model.Content)) + barcodeProd = ean128Model.Content; + + + if (!UtilityString.isNullOrEmpty(barcodeProd)) { + + if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) { + this.executeEtichettaLU(ean128Model.Sscc); + + } else if (!UtilityString.isNullOrEmpty(barcodeProd)) { + this.loadArticolo(barcodeProd, ean128Model); + + } else + throw new NoLUFoundException(); + + } else + //EAN 128 non completo o comunque mancano i riferimenti al prodotto + throw new NoLUFoundException(); + + + } + + private void loadArticolo(String barcodeProd, Ean128Model ean128Model) throws Exception { + var mtbAartList = mArticoloRESTConsumer.searchByBarcodeSynchronized(barcodeProd); + + if (mtbAartList != null && !mtbAartList.isEmpty()) { + MtbAart articolo = mtbAartList.get(0); + this.dispatchArt(articolo, ean128Model); + + } else { + throw new NoResultFromBarcodeException(barcodeProd); + } + - }, this::sendError); } @@ -261,8 +264,6 @@ public class ProdVersamentoMaterialeViewModel { } - - this.sendOnItemDispatched( pickingObjectDTO, mtbAart, @@ -281,39 +282,58 @@ public class ProdVersamentoMaterialeViewModel { true, (pickedQuantityDTO, shouldCloseLU) -> { - this.sendRequestChoosePosition(mtbDepoPosizione -> { + var changePosizioneResult = this.sendRequestChoosePosition(); + + if (changePosizioneResult == null || !changePosizioneResult.first) { + return; + } + + mColliLavorazioneRESTConsumer.createColloScaricoDaArticolo(mtbAart, + pickedQuantityDTO.getPartitaMag(), + changePosizioneResult.second, + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getNumCnf(), + null, null, + this::sendOnDataSaved, + this::sendError); - mColliLavorazioneRESTConsumer.createColloScaricoDaArticolo(mtbAart, - pickedQuantityDTO.getPartitaMag(), - mtbDepoPosizione, - pickedQuantityDTO.getQtaTot(), - pickedQuantityDTO.getQtaCnf(), - pickedQuantityDTO.getNumCnf(), - null, null, - this::sendOnDataSaved, - this::sendError); - }); }); } - private void onLUOpened(MtbColt mtbColt) { - this.mtbColtMutableLiveData.setValue(mtbColt); - this.sendRequestChoosePosition(this::setPosizione); + private void onLUOpened(MtbColt mtbColt) throws Exception { + this.mtbColtMutableLiveData.postValue(mtbColt); + var posizioneResult = this.sendRequestChoosePosition(); + + if (posizioneResult == null || !posizioneResult.first) { + return; + } + + this.setPosizione(posizioneResult.second); } - public void setPosizione(MtbDepoPosizione mtbDepoPosizione) { + public void setPosizione(MtbDepoPosizione mtbDepoPosizione) throws Exception { this.mtbDepoPosizioneMutableLiveData.postValue(mtbDepoPosizione); MtbColt mtbColt = mtbColtMutableLiveData.getValue(); this.sendOnLoadingStarted(); + if (mtbDepoPosizione != null && mtbDepoPosizione.isFlagLineaProduzione() && mtbColt != null) { + +// mMaterialiRESTConsumer.makeVersaRequest(new VersaMaterialiRequestDTO() +// .setBarcodeUl(mtbColt.getBarcodeUl()), () -> { +// +// String a = ""; +// +// }, this::sendError); + if (!mFlagVersamentoDirettoProduzione) { createColloScarico(mtbDepoPosizione); } else { - if (mtbColt.getMtbColr() == null || mtbColt.getMtbColr().size() <= 0) { + if (mtbColt.getMtbColr() == null || mtbColt.getMtbColr().isEmpty()) { this.sendWarning("Il collo selezionato non presenta articoli versabili sulla linea.", this::sendRequestLUOpen); return; } else if (mtbColt.getMtbColr().size() > 1) { @@ -344,15 +364,13 @@ public class ProdVersamentoMaterialeViewModel { } } - private void createColloScarico(MtbDepoPosizione mtbDepoPosizione) { - + private void createColloScarico(MtbDepoPosizione mtbDepoPosizione) throws Exception { this.sendOnLoadingStarted(); - this.mColliMagazzinoRESTConsumer.createColloScaricoDaCarico(mtbColtMutableLiveData.getValue(), mtbDepoPosizione, - generatedMtbColt -> { - this.sendOnLoadingEnded(); - this.sendOnDataSaved(); - }, this::sendError); + var generatedMtbColt = this.mColliMagazzinoRESTConsumer.createColloScaricoDaCaricoSynchronized(mtbColtMutableLiveData.getValue(), mtbDepoPosizione); + + this.sendOnLoadingEnded(); + this.sendOnDataSaved(); } @@ -426,8 +444,22 @@ public class ProdVersamentoMaterialeViewModel { if (this.mListener != null) mListener.requestLUOpen(); } - private void sendRequestChoosePosition(RunnableArgs onComplete) { - if (this.mListener != null) mListener.onRequestChoosePosition(onComplete); + private Pair sendRequestChoosePosition() { + final CountDownLatch latch = new CountDownLatch(1); + AtomicReference> result = new AtomicReference<>(); + + if (this.mListener != null) mListener.onRequestChoosePosition((status, data) -> { + result.set(new Pair<>(status, data)); + latch.countDown(); + }); + + try { + latch.await(); // Attende che il dialog venga chiuso + return result.get(); + } catch (InterruptedException e) { + this.sendError(e); + } + return null; } private void sendOnLoadingStarted() { @@ -492,7 +524,7 @@ public class ProdVersamentoMaterialeViewModel { void requestLUOpen(); - void onRequestChoosePosition(RunnableArgs onComplete); + void onRequestChoosePosition(RunnableArgss onComplete); void onItemDispatched(PickingObjectDTO pickingObjectDTO, MtbAart mtbAart,