Migliorata gestione callback e chiamate in background per Picking Libero

This commit is contained in:
Giuseppe Scorrano 2025-02-28 15:26:02 +01:00
parent e5a4cf59c4
commit 5694d8bd1c
10 changed files with 689 additions and 647 deletions

View File

@ -269,8 +269,8 @@ public class MainApplicationModule {
@Provides
@Singleton
GiacenzaRESTConsumer provideGiacenzaRESTConsumer(RESTBuilder restBuilder, ArticoloRESTConsumer articoloRESTConsumer) {
return new GiacenzaRESTConsumer(restBuilder, articoloRESTConsumer);
GiacenzaRESTConsumer provideGiacenzaRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, ArticoloRESTConsumer articoloRESTConsumer) {
return new GiacenzaRESTConsumer(restBuilder, executorService, articoloRESTConsumer);
}
@Provides

View File

@ -16,8 +16,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import javax.inject.Singleton;
@ -37,7 +37,6 @@ import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback;
import it.integry.integrywmsnative.core.rest.model.RettificaULDTO;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import it.integry.integrywmsnative.core.rest.model.SpostaArtsTraULRequestDTO;
import it.integry.integrywmsnative.core.rest.model.SpostaArtsTraULResponseDTO;
import it.integry.integrywmsnative.core.rest.model.SpostaULRequestDTO;
import it.integry.integrywmsnative.core.rest.model.UpdateTipoULRequestDTO;
import it.integry.integrywmsnative.core.rest.model.VersamentoAutomaticoULResponseDTO;
@ -75,7 +74,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
this.executorService = executorService;
}
public void saveCollo(MtbColt mtbColtToSave, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
public MtbColt saveColloSynchronized(MtbColt mtbColtToSave) throws Exception {
MtbColt mtbColtToSaveClone = (MtbColt) mtbColtToSave.clone();
mtbColtToSaveClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE);
mtbColtToSaveClone.setOnlyPkMaster(false);
@ -86,17 +85,18 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
.setMtbPartitaMag(null);
}
this.mEntityRESTConsumer.processEntity(mtbColtToSaveClone, new ISimpleOperationCallback<>() {
@Override
public void onSuccess(MtbColt value) {
if (onComplete != null) onComplete.run(value);
return this.mEntityRESTConsumer.processEntitySynchronized(mtbColtToSaveClone, MtbColt.class);
}
@Override
public void onFailed(Exception ex) {
public void saveCollo(MtbColt mtbColtToSave, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
try {
var mtbColt = saveColloSynchronized(mtbColtToSave);
if (onComplete != null) onComplete.run(mtbColt);
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
}
}, MtbColt.class);
});
}
@ -327,6 +327,36 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
});
}
public List<MtbColr> fillMtbAartsOfMtbColrsSynchronized(List<MtbColr> mtbColrs) throws Exception {
List<String> codMarts = new ArrayList<>(mtbColrs.stream()
.map(MtbColr::getCodMart)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toUnmodifiableList()));
var arts = mArticoloRESTConsumer.getByCodMartsSynchronized(codMarts);
if (arts != null && !arts.isEmpty()) {
for (MtbColr mtbColr : mtbColrs) {
MtbAart foundMtbAart = null;
List<MtbAart> mtbAartStream = arts.stream()
.filter(x -> x.getCodMart().equalsIgnoreCase(mtbColr.getCodMart()))
.collect(Collectors.toList());
if (!mtbAartStream.isEmpty()) {
foundMtbAart = mtbAartStream.get(0);
}
mtbColr.setMtbAart(foundMtbAart);
}
}
return mtbColrs;
}
public List<MtbColt> fillMtbAartsOfMtbColtsSynchronized(List<MtbColt> mtbColts) throws Exception {
List<String> codMarts = new ArrayList<>();
@ -405,6 +435,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
return getByTestataSynchronized(mtbColtToRetrieve, onlyResiduo, throwExcIfNull);
}
public void getByChiaveCollo(GestioneEnum gestione, int numCollo, String dataCollo, String serCollo, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
MtbColt mtbColtToRetrieve = new MtbColt()
.setGestione(gestione)
@ -424,9 +455,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
.execute();
var mtbColt = analyzeAnswer(response, "getColloInGiac");
if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) {
List<MtbColt> mtbColtList = new ArrayList<>();
mtbColtList.add(mtbColt);
var mtbColts = fillMtbAartsOfMtbColtsSynchronized(mtbColtList);
var mtbColts = fillMtbAartsOfMtbColtsSynchronized(Collections.singletonList(mtbColt));
return mtbColts.get(0);
}
@ -576,8 +605,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
});
}
public void spostaArtsTraUL(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs, RunnableArgs<List<MtbColr>> onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
public List<MtbColr> spostaArtsTraULSynchronized(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs) throws Exception {
MtbColt mtbColtToMoveClone = (MtbColt) sourceMtbColt.clone();
MtbColt mtbColtDestClone = (MtbColt) destMtbColt.clone();
@ -595,25 +623,27 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
.setFlagForceUseRefs(flagForceUseRefs);
ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class);
colliMagazzinoRESTConsumerService.spostaArtsTraUL(spostaArtsTraULRequestDTO).enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<SpostaArtsTraULResponseDTO>> call, Response<ServiceRESTResponse<SpostaArtsTraULResponseDTO>> response) {
analyzeAnswer(response, "spostaArtsTraUL", data -> {
var response = colliMagazzinoRESTConsumerService.spostaArtsTraUL(spostaArtsTraULRequestDTO)
.execute();
fillMtbAartsOfMtbColrs(data.getGeneratedMtbColr(), onComplete, onFailed);
var data = analyzeAnswer(response, "spostaArtsTraUL");
var mtbColrs = fillMtbAartsOfMtbColrsSynchronized(data.getGeneratedMtbColr());
}, onFailed);
return mtbColrs;
}
@Override
public void onFailure(Call<ServiceRESTResponse<SpostaArtsTraULResponseDTO>> call, @NonNull final Exception e) {
if (onFailed != null) onFailed.run(e);
public void spostaArtsTraUL(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs, RunnableArgs<List<MtbColr>> onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
try {
var result = spostaArtsTraULSynchronized(sourceMtbColt, destMtbColt, flagForceUseRefs);
if (onComplete != null) onComplete.run(result);
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
}
});
});
}
public void assegnaLottoSuColloScarico(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs<Exception> onFailed) {
public MtbColt assegnaLottoSuColloScaricoSynchronized(MtbColt sourceMtbColt) throws Exception {
MtbColt sourceMtbColtClone = (MtbColt) sourceMtbColt.clone();
for (int i = 0; i < sourceMtbColtClone.getMtbColr().size(); i++) {
@ -623,17 +653,20 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
}
ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class);
colliMagazzinoRESTConsumerService.assegnaLottoSuColloScarico(sourceMtbColtClone).enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<MtbColt>> call, Response<ServiceRESTResponse<MtbColt>> response) {
analyzeAnswer(response, "assegnaLottoSuColloScarico", data -> {
onComplete.run();
}, onFailed);
var response = colliMagazzinoRESTConsumerService.assegnaLottoSuColloScarico(sourceMtbColtClone)
.execute();
var data = analyzeAnswer(response, "assegnaLottoSuColloScarico");
return data;
}
@Override
public void onFailure(Call<ServiceRESTResponse<MtbColt>> call, @NonNull final Exception e) {
if (onFailed != null) onFailed.run(e);
public void assegnaLottoSuColloScarico(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
try {
var result = assegnaLottoSuColloScaricoSynchronized(sourceMtbColt);
if (onComplete != null) onComplete.run();
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
}
});
}

View File

@ -34,43 +34,39 @@ public class EntityRESTConsumer extends _BaseRESTConsumer {
this.executorService = executorService;
}
public <T extends EntityBase> void processEntity(T entityToSave, final ISimpleOperationCallback<T> callback, Class<T> type) {
RunnableArgs<Exception> tmpFailed = ex -> {
if (callback != null) callback.onFailed(ex);
};
public <T extends EntityBase> T processEntitySynchronized(T entityToSave, Class<T> type) throws Exception {
EntityRESTConsumerService service = restBuilder.getService(EntityRESTConsumerService.class);
service
var response = service
.processEntity(entityToSave)
.enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<JsonObject>> call, Response<ServiceRESTResponse<JsonObject>> response) {
if (response.isSuccessful()) {
.execute();
if (response.isSuccessful()) {
if (response.body() != null) {
if (response.body().getEsito() == EsitoType.OK) {
Gson gson = UtilityGson.createObject();
T object = gson.fromJson(response.body().getEntity(), type);
callback.onSuccess(object);
return gson.fromJson(response.body().getEntity(), type);
} else {
Log.e("EntityRESTConsumer", response.body().getErrorMessage());
tmpFailed.run(new Exception(response.body().getErrorMessage()));
throw new Exception(response.body().getErrorMessage());
}
} else {
Log.e("EntityRESTConsumer", response.message());
tmpFailed.run(new Exception(response.message()));
throw new Exception(response.message());
}
} else {
Log.e("EntityRESTConsumer", "Status " + response.code() + ": " + response.message());
tmpFailed.run(new Exception("Status " + response.code() + ": " + response.message()));
throw new Exception("Status " + response.code() + ": " + response.message());
}
}
@Override
public void onFailure(Call<ServiceRESTResponse<JsonObject>> call, @NonNull final Exception e) {
tmpFailed.run(e);
public <T extends EntityBase> void processEntity(T entityToSave, final ISimpleOperationCallback<T> callback, Class<T> type) {
executorService.execute(() -> {
try {
var data = processEntitySynchronized(entityToSave, type);
if (callback != null) callback.onSuccess(data);
} catch (Exception ex) {
if (callback != null) callback.onFailed(ex);
}
});

View File

@ -7,6 +7,8 @@ import com.annimon.stream.Stream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import javax.inject.Singleton;
@ -28,29 +30,30 @@ import retrofit2.Response;
public class GiacenzaRESTConsumer extends _BaseRESTConsumer {
private final RESTBuilder restBuilder;
private final ExecutorService executorService;
private final ArticoloRESTConsumer mArticoloRESTConsumer;
public GiacenzaRESTConsumer(RESTBuilder restBuilder, ArticoloRESTConsumer articoloRESTConsumer) {
public GiacenzaRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, ArticoloRESTConsumer articoloRESTConsumer) {
this.restBuilder = restBuilder;
this.executorService = executorService;
this.mArticoloRESTConsumer = articoloRESTConsumer;
}
public void getGiacenzeInPosizione(MtbDepoPosizione posizione, RunnableArgs<List<MvwSitArtUdcDetInventario>> onComplete, RunnableArgs<Exception> onFailed) {
public List<MvwSitArtUdcDetInventario> getGiacenzeInPosizioneSynchronized(MtbDepoPosizione posizione) throws Exception {
GiacenzaRESTConsumerService giacenzaRESTConsumerService = restBuilder.getService(GiacenzaRESTConsumerService.class);
giacenzaRESTConsumerService.retrieveAvailableItems(posizione.getPosizione()).enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<List<MvwSitArtUdcDetInventario>>> call, Response<ServiceRESTResponse<List<MvwSitArtUdcDetInventario>>> response) {
analyzeAnswer(response, "getGiacenzeInPosizione", inventarioList -> {
var response = giacenzaRESTConsumerService.retrieveAvailableItems(posizione.getPosizione())
.execute();
var inventarioList = analyzeAnswer(response, "getGiacenzeInPosizione");
if (inventarioList != null && !inventarioList.isEmpty()) {
List<String> codMarts = Stream.of(inventarioList)
List<String> codMarts = inventarioList.stream()
.map(x -> x.getCodMart().trim())
.toList();
.collect(Collectors.toList());
mArticoloRESTConsumer.getByCodMarts(codMarts, mtbAarts -> {
var mtbAarts = mArticoloRESTConsumer.getByCodMartsSynchronized(codMarts);
for (var row : inventarioList) {
MtbAart foundMtbAart = null;
Optional<MtbAart> mtbAartOpt = Stream.of(mtbAarts)
.filter(x -> x.getCodMart().equalsIgnoreCase(row.getCodMart()))
@ -63,17 +66,19 @@ public class GiacenzaRESTConsumer extends _BaseRESTConsumer {
row.setMtbAart(foundMtbAart);
}
onComplete.run(inventarioList);
}, onFailed);
}else{
onComplete.run(new ArrayList<>());
}
}, onFailed);
return inventarioList;
}
@Override
public void onFailure(Call<ServiceRESTResponse<List<MvwSitArtUdcDetInventario>>> call, @NonNull final Exception e) {
onFailed.run(e);
return new ArrayList<>();
}
public void getGiacenzeInPosizione(MtbDepoPosizione posizione, RunnableArgs<List<MvwSitArtUdcDetInventario>> onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
try {
var result = getGiacenzeInPosizioneSynchronized(posizione);
if (onComplete != null) onComplete.run(result);
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
}
});
}

View File

@ -28,7 +28,7 @@ public class MagazzinoAutomaticoRESTConsumer extends _BaseRESTConsumer {
this.restBuilder = restBuilder;
}
public void pickItemsSynchronous(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO) throws Exception {
public void pickItemsSynchronized(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO) throws Exception {
MagazzinoAutomaticoRESTConsumerService magazzinoAutomaticoRESTConsumerService = restBuilder.getService(MagazzinoAutomaticoRESTConsumerService.class);
var response = magazzinoAutomaticoRESTConsumerService.pickItems(posizione.getPosizione(), magazzinoAutomaticoPickItemsRequestDTO)
.execute();
@ -39,7 +39,7 @@ public class MagazzinoAutomaticoRESTConsumer extends _BaseRESTConsumer {
public void pickItems(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO, Runnable onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
try {
pickItemsSynchronous(posizione, magazzinoAutomaticoPickItemsRequestDTO);
pickItemsSynchronized(posizione, magazzinoAutomaticoPickItemsRequestDTO);
if (onComplete != null) onComplete.run();
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);

View File

@ -3,6 +3,7 @@ package it.integry.integrywmsnative.gest.picking_libero;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
@ -76,6 +77,9 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Inject
DialogInputQuantityV2View mDialogInputQuantityV2View;
@Inject
Handler handler;
public BindableBoolean thereIsAnOpenedUL = new BindableBoolean(false);
public BindableBoolean thereIsntAnOpenedUL = new BindableBoolean(true);
public BindableBoolean thereIsAnyRowInUL = new BindableBoolean(false);
@ -206,23 +210,41 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
}
private final RunnableArgs<BarcodeScanDTO> onScanSuccessful = data -> {
BarcodeManager.disable(mBarcodeScannerInstanceID);
this.onLoadingStarted();
this.mViewModel.processBarcodeDTO(data, () -> {
BarcodeManager.enable(mBarcodeScannerInstanceID);
this.onLoadingEnded();
executorService.execute(() -> {
try {
this.mViewModel.processBarcodeDTO(data);
} catch (Exception e) {
onError(e);
}
});
this.onLoadingEnded();
};
public void createNewLU() {
this.mViewModel.createNewLU(null, null, () -> {
executorService.execute(() -> {
try {
this.mViewModel.createNewLU(null, null);
} catch (Exception e) {
this.onError(e);
}
});
}
public void closeLU() {
destroyAdapter();
this.mViewModel.closeLU(null);
executorService.execute(() -> {
try {
this.onLoadingStarted();
this.mViewModel.closeLU();
this.onLoadingEnded();
} catch (Exception e) {
this.onError(e);
}
});
}
@Override
@ -241,7 +263,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Override
public void onLUOpened(MtbColt mtbColt) {
requireActivity().runOnUiThread(() -> {
handler.post(() -> {
mToolbarTitleText.setText(String.format(getActivity().getText(R.string.lu_number_text).toString(), mtbColt.getNumCollo()));
initAdapter();
@ -264,7 +286,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Override
public void onLUClosed() {
requireActivity().runOnUiThread(() -> {
handler.post(() -> {
mToolbarTitleText.setText(getActivity().getText(R.string.free_picking_title_fragment).toString());
destroyAdapter();
@ -285,7 +307,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Override
public void onError(Exception ex) {
requireActivity().runOnUiThread(() -> {
handler.post(() -> {
this.onLoadingEnded();
if (ex instanceof InvalidPesoKGException) {
@ -344,7 +366,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged,
boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete) {
RunnableArgs<PickedQuantityDTO> onComplete) {
DialogInputQuantityV2DTO dialogInputQuantityV2DTO = new DialogInputQuantityV2DTO()
.setMtbAart(mtbAart)
@ -367,7 +389,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
mDialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO)
.setOnComplete(resultDTO -> {
if (resultDTO == null || resultDTO.isAborted()) {
onComplete.run(null, false);
onComplete.run(null);
return;
}
@ -378,17 +400,14 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
.setPartitaMag(resultDTO.getPartitaMag())
.setDataScad(resultDTO.getDataScad());
onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu());
})
.setOnAbort(() -> {
onComplete.run(null, false);
onComplete.run(pickedQuantityDTO);
})
.show(requireActivity().getSupportFragmentManager(), "tag");
}
@Override
public void onRowSaved() {
requireActivity().runOnUiThread(() -> {
handler.post(() -> {
Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT)
.setBackgroundTint(getResources().getColor(R.color.green_500))
.show();
@ -398,19 +417,40 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
@Override
public void onMtbColrEdit(MtbColr mtbColr) {
executorService.execute(() -> {
try {
this.mViewModel.dispatchRowEdit(mtbColr);
} catch (Exception e) {
this.onError(e);
}
});
}
@Override
public void onMtbColrDelete(MtbColr mtbColr) {
executorService.execute(() -> {
try {
this.mViewModel.deleteRow(mtbColr);
} catch (Exception e) {
this.onError(e);
}
});
}
@Override
public void onPreDestroy(Runnable onComplete) {
BarcodeManager.removeCallback(mBarcodeScannerInstanceID);
if (thereIsAnOpenedUL.get()) mViewModel.closeLU(onComplete);
else onComplete.run();
if (thereIsAnOpenedUL.get()) {
executorService.execute(() -> {
try {
this.onLoadingStarted();
mViewModel.closeLU();
this.onLoadingEnded();
} catch (Exception e) {
onError(e);
}
});
} else onComplete.run();
}
@Override

View File

@ -1,5 +1,7 @@
package it.integry.integrywmsnative.gest.picking_libero;
import android.os.Handler;
import java.util.concurrent.ExecutorService;
import javax.inject.Singleton;
@ -22,6 +24,7 @@ public class PickingLiberoModule {
@Provides
@Singleton
PickingLiberoViewModel providesPickingLiberoViewModel(ExecutorService executorService,
Handler handler,
ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer,
@ -34,6 +37,7 @@ public class PickingLiberoModule {
) {
return new PickingLiberoViewModel(
executorService,
handler,
articoloRESTConsumer,
colliMagazzinoRESTConsumer,
barcodeRESTConsumer,

View File

@ -1,5 +1,8 @@
package it.integry.integrywmsnative.gest.picking_libero;
import android.os.Handler;
import android.util.Pair;
import androidx.databinding.ObservableArrayList;
import com.annimon.stream.Stream;
@ -71,6 +74,7 @@ public class PickingLiberoViewModel {
private MtbColt mCurrentMtbColt = null;
private final ExecutorService executorService;
private final Handler handler;
private final ArticoloRESTConsumer mArticoloRESTConsumer;
private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer;
private final BarcodeRESTConsumer mBarcodeRESTConsumer;
@ -96,7 +100,7 @@ public class PickingLiberoViewModel {
@Inject
public PickingLiberoViewModel(ExecutorService executorService,
public PickingLiberoViewModel(ExecutorService executorService, Handler handler,
ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer,
@ -107,6 +111,7 @@ public class PickingLiberoViewModel {
ColliSpedizioneRESTConsumer colliSpedizioneRESTConsumer,
ColliDataRecoverService colliDataRecoverService) {
this.executorService = executorService;
this.handler = handler;
this.mArticoloRESTConsumer = articoloRESTConsumer;
this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer;
this.mBarcodeRESTConsumer = barcodeRESTConsumer;
@ -133,43 +138,41 @@ public class PickingLiberoViewModel {
}
public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO) throws Exception {
if (this.mCurrentMtbColt == null) {
this.createNewLU(null, null, () -> {
executeEtichettaBehaviour(barcodeScanDTO, onComplete);
});
} else {
executeEtichettaBehaviour(barcodeScanDTO, onComplete);
}
this.createNewLU(null, null);
}
private void executeEtichettaBehaviour(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
executeEtichettaBehaviour(barcodeScanDTO);
}
private void executeEtichettaBehaviour(BarcodeScanDTO barcodeScanDTO) throws Exception {
if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) {
//Cerco gli articoli presenti nell'ul dell'etichetta anonima
this.executeEtichettaLU(barcodeScanDTO.getStringValue(), onComplete);
this.executeEtichettaLU(barcodeScanDTO.getStringValue());
} else if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) {
//Cerco tramite etichetta un collo in posizione mono ul
this.executeEtichettaPosizione(barcodeScanDTO, onComplete);
this.executeEtichettaPosizione(barcodeScanDTO);
} else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) {
//Cerco tramite etichetta ean 128 (che può indicarmi una UL)
this.executeEtichettaEan128(barcodeScanDTO, onComplete);
this.executeEtichettaEan128(barcodeScanDTO);
} else if (UtilityBarcode.isEanPeso(barcodeScanDTO) && SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) {
//Cerco tramite etichetta ean 128 (che può indicarmi un articolo o una UL)
this.executeEtichettaEanPeso(barcodeScanDTO, onComplete);
this.executeEtichettaEanPeso(barcodeScanDTO);
} else if (SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) {
//Cerco tramite ean13 un collo in posizione mono ul definita in anagrafica articolo, altrimenti se abilitato procedo con picking manuale
this.loadArticolo(barcodeScanDTO.getStringValue(), null, onComplete);
this.loadArticolo(barcodeScanDTO.getStringValue(), null);
} else {
this.sendError(new NoArtsFoundException());
throw new NoArtsFoundException();
}
}
private void executeEtichettaPosizione(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
private void executeEtichettaPosizione(BarcodeScanDTO barcodeScanDTO) throws Exception {
MtbDepoPosizione foundPosizione = Stream.of(SettingsManager.iDB().getAvailablePosizioni())
.filter(x -> x.getPosizione().equalsIgnoreCase(barcodeScanDTO.getStringValue()))
@ -177,33 +180,27 @@ public class PickingLiberoViewModel {
if (foundPosizione == null) {
//Nessuna posizione trovata con questo barcode
this.sendError(new ScannedPositionNotExistException());
return;
throw new ScannedPositionNotExistException();
}
if (foundPosizione.isMagazzinoAutomatico()) {
//Eseguo picking da magazzino automatico
this.executeMagazzinoAutomatico(foundPosizione, onComplete);
this.executeMagazzinoAutomatico(foundPosizione);
} else {
this.executePosizione(foundPosizione, null, onComplete);
this.executePosizione(foundPosizione, null);
}
}
private void executeMagazzinoAutomatico(MtbDepoPosizione mtbDepoPosizione, Runnable onComplete) {
mGiacenzaRESTConsumer.getGiacenzeInPosizione(mtbDepoPosizione, availableItems -> {
private void executeMagazzinoAutomatico(MtbDepoPosizione mtbDepoPosizione) throws Exception {
this.sendOnLoadingStarted();
var availableItems = mGiacenzaRESTConsumer.getGiacenzeInPosizioneSynchronized(mtbDepoPosizione);
var mtbColrs = Stream.of(availableItems)
var mtbColrs = availableItems.stream()
.map(MvwSitArtUdcDetInventario::toMtbColr)
.toList();
.collect(Collectors.toList());
List<MtbColr> selectedMtbColrs = null;
try {
selectedMtbColrs = this.sendArtSelectionRequest(mtbColrs, null);
} catch (InterruptedException e) {
this.sendError(e);
return;
}
List<MtbColr> selectedMtbColrs = this.sendArtSelectionRequest(mtbColrs, null);
if (selectedMtbColrs == null) {
this.sendOnLoadingEnded();
@ -225,75 +222,64 @@ public class PickingLiberoViewModel {
.setDefaultGestioneOfNewUDS(mDefaultGestione.getText())
.setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList);
mMagazzinoAutomaticoRESTConsumer.pickItems(mtbDepoPosizione,
magazzinoAutomaticoPickRequest, onComplete, this::sendError);
mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione,
magazzinoAutomaticoPickRequest);
this.sendOnLoadingEnded();
}, this::sendError);
}
private void executePosizione(MtbDepoPosizione posizione, MtbAart articolo, Runnable onComplete) {
this.mPosizioniRESTConsumer.getBancaliInPosizione(posizione, mtbColtList -> {
private void executePosizione(MtbDepoPosizione posizione, MtbAart articolo) throws Exception {
var mtbColtList = this.mPosizioniRESTConsumer.getBancaliInPosizioneSynchronized(posizione);
if (mtbColtList == null || mtbColtList.isEmpty()) {
if (articolo != null) {
this.dispatchArt(articolo, null);
} else {
this.sendError(new NoLUFoundException());
throw new NoLUFoundException();
}
} else if (mtbColtList.size() == 1) {
this.mColliMagazzinoRESTConsumer.getByTestata(mtbColtList.get(0), true, false, mtbColt -> {
var mtbColt = this.mColliMagazzinoRESTConsumer.getByTestataSynchronized(mtbColtList.get(0), true, false);
boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep())
.anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep()));
if (codMdepIsValid) {
pickMerceULtoUL(mtbColt, articolo, onComplete);
} else this.sendError(new InvalidCodMdepException());
pickMerceULtoUL(mtbColt, articolo);
} else throw new InvalidCodMdepException();
}, this::sendError);
} else {
this.sendError(new TooManyLUFoundInMonoLUPositionException());
throw new TooManyLUFoundInMonoLUPositionException();
}
}
}, this::sendError);
}
private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
try {
private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO) throws Exception {
Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue());
this.loadArticolo(ean13PesoModel.getPrecode(), ean13PesoModel.toEan128(), onComplete);
} catch (Exception ex) {
this.sendError(ex);
}
this.loadArticolo(ean13PesoModel.getPrecode(), ean13PesoModel.toEan128());
}
private void executeEtichettaLU(String sscc, Runnable onComplete) {
mColliMagazzinoRESTConsumer.getBySSCC(sscc, true, false, mtbColtScanned -> {
private void executeEtichettaLU(String sscc) throws Exception {
var mtbColtScanned = mColliMagazzinoRESTConsumer.getBySsccSynchronized(sscc, true, false);
if (mtbColtScanned == null) {
this.sendError(new NoLUFoundException());
throw new NoLUFoundException();
} else if ((mtbColtScanned.getGestioneEnum() == GestioneEnum.ACQUISTO || mtbColtScanned.getGestioneEnum() == GestioneEnum.LAVORAZIONE) && mtbColtScanned.getSegno() > 0) {
boolean codMdepIsValid = Stream.of(SettingsManager.iDB().getAvailableCodMdep())
boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream()
.anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColtScanned.getCodMdep()));
if (codMdepIsValid) {
pickMerceULtoUL(mtbColtScanned, onComplete);
} else this.sendError(new InvalidCodMdepException());
pickMerceULtoUL(mtbColtScanned);
} else throw new InvalidCodMdepException();
} else {
this.sendError(new NoLUFoundException());
throw new NoLUFoundException();
}
}
}, this::sendError);
}
private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> {
private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO) throws Exception {
var ean128Model = mBarcodeRESTConsumer.decodeEan128Synchronized(barcodeScanDTO);
String barcodeProd = null;
@ -305,76 +291,79 @@ public class PickingLiberoViewModel {
if (!UtilityString.isNullOrEmpty(barcodeProd)) {
if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) {
this.executeEtichettaLU(ean128Model.Sscc, onComplete);
this.executeEtichettaLU(ean128Model.Sscc);
} else if (!UtilityString.isNullOrEmpty(barcodeProd) && SettingsManager.iDB().isFlagPickingLiberoEnableScanArt()) {
this.loadArticolo(barcodeProd, ean128Model, onComplete);
this.loadArticolo(barcodeProd, ean128Model);
} else {
this.sendError(new NoLUFoundException());
throw new NoLUFoundException();
}
} else {
//EAN 128 non completo o comunque mancano i riferimenti al prodotto
this.sendError(new NoLUFoundException());
}
}, this::sendError);
throw new NoLUFoundException();
}
private void loadArticolo(String barcodeProd, Ean128Model ean128Model, Runnable onComplete) {
mArticoloRESTConsumer.searchByBarcode(barcodeProd, mtbAartList -> {
}
private void loadArticolo(String barcodeProd, Ean128Model ean128Model) throws Exception {
var mtbAartList = mArticoloRESTConsumer.searchByBarcodeSynchronized(barcodeProd);
if (mtbAartList != null && !mtbAartList.isEmpty()) {
MtbAart articolo = mtbAartList.get(0);
MtbDepoPosizione posizione = UtilityPosizione.getFromCache(articolo.getPosizione());
if (posizione != null && posizione.isFlagMonoCollo()) {
this.executePosizione(posizione, articolo, onComplete);
this.executePosizione(posizione, articolo);
} else if (mDefaultGestione == GestioneEnum.VENDITA) {
this.dispatchArt(articolo, ean128Model);
onComplete.run();
} else {
this.sendError(new NoResultFromBarcodeException(barcodeProd));
throw new NoResultFromBarcodeException(barcodeProd);
}
} else {
this.sendError(new NoResultFromBarcodeException(barcodeProd));
throw new NoResultFromBarcodeException(barcodeProd);
}
}, this::sendError);
}
public void createNewLU(Integer customNumCollo, String customSerCollo, Runnable onComplete) {
public void createNewLU(Integer customNumCollo, String customSerCollo) throws Exception {
VtbDest vtbDest = null;
String codJcom = null;
if (this.mFlagAskCliente) {
this.sendLUClienteRequired((vtbDest, codJcom) -> {
createNewLU_PostClienteAsk(customNumCollo, customSerCollo, vtbDest, onComplete);
}, this::sendOnLoadingEnded);
} else {
createNewLU_PostClienteAsk(customNumCollo, customSerCollo, null, onComplete);
}
var data = this.sendLUClienteRequired();
vtbDest = data.first;
codJcom = data.second;
}
private void createNewLU_PostClienteAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, Runnable onComplete) {
createNewLU_PostClienteAsk(customNumCollo, customSerCollo, vtbDest);
}
private void createNewLU_PostClienteAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest) throws Exception {
DialogAskLineaProdResponse dialogAskLineaProdResponse = null;
if (this.mFlagAskLineaProd) {
this.sendLULineaProdRequired(response -> {
createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, response.getPosizione(), response.getIdLotto(), onComplete);
}, this::sendOnLoadingEnded);
} else {
createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, null, null, onComplete);
}
dialogAskLineaProdResponse = this.sendLULineaProdRequired();
}
private void createNewLU_PostLineaProdAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String posizione, Integer idLotto, Runnable onComplete) {
createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest,
dialogAskLineaProdResponse != null ? dialogAskLineaProdResponse.getPosizione() : null,
dialogAskLineaProdResponse != null ? dialogAskLineaProdResponse.getIdLotto() : null);
}
private void createNewLU_PostLineaProdAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String posizione, Integer idLotto) throws Exception {
JtbComt commessa = null;
if (this.mFlagAskCommessa) {
this.sendLUCommessaRequired(response -> {
createNewLU_PostCommessaAsk(customNumCollo, customSerCollo, vtbDest, posizione, idLotto, response, onComplete);
}, this::sendOnLoadingEnded);
} else {
createNewLU_PostCommessaAsk(customNumCollo, customSerCollo, vtbDest, null, null, null, onComplete);
commessa = this.sendLUCommessaRequired();
}
createNewLU_PostCommessaAsk(customNumCollo, customSerCollo, vtbDest, posizione, idLotto, commessa);
}
private void createNewLU_PostCommessaAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String codJfas, Integer idLotto, JtbComt codJcom, Runnable onComplete) {
private void createNewLU_PostCommessaAsk(Integer customNumCollo, String customSerCollo, VtbDest vtbDest, String codJfas, Integer idLotto, JtbComt codJcom) throws Exception {
this.mDefaultCommessa = codJcom;
this.sendOnLoadingStarted();
@ -404,59 +393,19 @@ public class PickingLiberoViewModel {
}
mColliScaricoRESTConsumer.createUDS(createUDSRequest, mtbColt -> {
var mtbColt = mColliScaricoRESTConsumer.createUDSSynchronized(createUDSRequest);
mMtbColtSessionID = mColliDataRecoverService.startNewSession(mtbColt, null);
mtbColt
.setMtbColr(new ObservableArrayList<>());
mtbColt.setMtbColr(new ObservableArrayList<>());
this.mCurrentMtbColt = mtbColt;
this.sendOnLoadingEnded();
if (onComplete != null) onComplete.run();
this.sendLUOpened(mtbColt);
}, this::sendError);
// MtbColt mtbColt = new MtbColt();
// mtbColt.initDefaultFields(mDefaultGestione)
// .setRifOrd(mDefaultGestione == GestioneEnum.LAVORAZIONE ? "PICKING LIBERO" : null)
// .setSegno(-1)
// .setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE);
//
// if (customNumCollo != null) {
// mtbColt.setNumCollo(customNumCollo);
// }
//
// if (!UtilityString.isNullOrEmpty(customSerCollo)) {
// mtbColt.setSerCollo(customSerCollo);
// }
//
// if (vtbDest != null) {
// mtbColt.setCodAnag(vtbDest.getCodAnag());
// mtbColt.setCodVdes(vtbDest.getCodVdes());
// }
//
// if (!UtilityString.isNullOrEmpty(codJcom)) {
// mtbColt.setCodJcom(codJcom);
// }
// mColliMagazzinoRESTConsumer.saveCollo(mtbColt, value -> {
// mtbColt
// .setNumCollo(value.getNumCollo())
// .setDataCollo(value.getDataColloS())
// .setMtbColr(new ObservableArrayList<>());
//
// this.mCurrentMtbColt = mtbColt;
//
// this.sendOnLoadingEnded();
//
// if (onComplete != null) onComplete.run();
// this.sendLUOpened(mtbColt);
// }, this::sendError);
}
private void dispatchArt(MtbAart mtbAart, Ean128Model ean128Model) {
private void dispatchArt(MtbAart mtbAart, Ean128Model ean128Model) throws Exception {
PickingObjectDTO pickingObjectDTO = new PickingObjectDTO()
.setMtbAart(mtbAart)
.setTempPickData(PickDataDTO.fromEan128(ean128Model));
@ -485,7 +434,7 @@ public class PickingLiberoViewModel {
if (manualPickDTO.isEanPeso()) {
if (mtbAart.getUntMisRifPeso() == MtbAart.UntMisRifPesoEnum.M) {
if (UtilityBigDecimal.equalsTo(mtbAart.getPesoKg(), BigDecimal.ZERO)) {
this.sendError(new InvalidPesoKGException());
throw new InvalidPesoKGException();
} else {
qtaColDaPrelevare = UtilityBigDecimal.divide(qtaColDaPrelevare, mtbAart.getPesoKg());
}
@ -533,7 +482,7 @@ public class PickingLiberoViewModel {
}
this.sendOnItemDispatched(
var pickedQuantityDTO = this.sendOnItemDispatched(
pickingObjectDTO,
pickingObjectDTO.getMtbAart(),
initialNumCnf,
@ -549,10 +498,9 @@ public class PickingLiberoViewModel {
dataScad,
false,
true,
true,
(pickedQuantityDTO, shouldCloseLU) -> {
true);
if (pickedQuantityDTO == null) {
this.sendOnLoadingEnded();
return;
}
@ -562,18 +510,15 @@ public class PickingLiberoViewModel {
pickedQuantityDTO.getQtaTot(),
pickedQuantityDTO.getPartitaMag(),
pickedQuantityDTO.getDataScad(),
shouldCloseLU);
});
pickedQuantityDTO.isShouldCloseLu());
}
private void pickMerceULtoUL(MtbColt sourceMtbColt, Runnable onComplete) {
pickMerceULtoUL(sourceMtbColt, null, onComplete);
private void pickMerceULtoUL(MtbColt sourceMtbColt) throws Exception {
pickMerceULtoUL(sourceMtbColt, null);
}
private void pickMerceULtoUL(MtbColt sourceMtbColt, MtbAart mtbAart, Runnable onComplete) {
executorService.execute(() -> {
private void pickMerceULtoUL(MtbColt sourceMtbColt, MtbAart mtbAart) throws Exception {
try {
List<MtbColr> mtbColrsToPick = sourceMtbColt.getMtbColr().stream()
.filter(x -> UtilityBigDecimal.greaterThan(x.getQtaCol(), BigDecimal.ZERO))
.collect(Collectors.toList());
@ -581,7 +526,6 @@ public class PickingLiberoViewModel {
List<MtbColr> pickedAarts = this.sendArtSelectionRequest(mtbColrsToPick, mtbAart);
if (pickedAarts == null) {
this.sendOnLoadingEnded();
return;
}
@ -596,6 +540,7 @@ public class PickingLiberoViewModel {
}
if (!mtbColrsToMove.isEmpty()) {
this.sendOnLoadingStarted();
if (this.mDefaultCommessa != null)
mtbColrsToMove.forEach(x -> x.setCodJcom(this.mDefaultCommessa.getCodJcom()));
@ -604,31 +549,20 @@ public class PickingLiberoViewModel {
clonedSourceTestata.getMtbColr().clear();
clonedSourceTestata.getMtbColr().addAll(mtbColrsToMove);
mColliMagazzinoRESTConsumer.spostaArtsTraUL(clonedSourceTestata,
this.mCurrentMtbColt, true, (generatedMtbColrs) -> {
var generatedMtbColrs = mColliMagazzinoRESTConsumer.spostaArtsTraULSynchronized(clonedSourceTestata,
this.mCurrentMtbColt, true);
handler.post(() -> {
mCurrentMtbColt.getMtbColr().addAll(generatedMtbColrs);
});
this.sendOnRowSaved();
this.sendOnLoadingEnded();
onComplete.run();
}, this::sendError);
} else {
onComplete.run();
this.sendOnLoadingEnded();
}
} else {
onComplete.run();
this.sendOnLoadingEnded();
}
} catch (InterruptedException e) {
this.sendError(e);
}
});
}
private MtbColr askSingleQuantity(MtbColr mtbColr) throws InterruptedException {
@ -650,10 +584,7 @@ public class PickingLiberoViewModel {
new PickDataDTO()
.setSourceMtbColt(sourceMtbColt));
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<MtbColr> result = new AtomicReference<>();
this.sendOnItemDispatched(
var pickedQuantityDTO = this.sendOnItemDispatched(
pickingObjectDTO,
pickingObjectDTO.getMtbAart(),
mtbColr.getNumCnf(),
@ -669,12 +600,10 @@ public class PickingLiberoViewModel {
mtbColr.getDataScadPartita(),
false,
false,
false,
(pickedQuantityDTO, shouldCloseLU) -> {
if (pickedQuantityDTO == null) {
countDownLatch.countDown();
return;
}
false);
if (pickedQuantityDTO == null)
return null;
mtbColr
.setPartitaMag(pickedQuantityDTO.getPartitaMag())
@ -685,19 +614,11 @@ public class PickingLiberoViewModel {
.setDatetimeRow(UtilityDate.getDateInstance())
.setMtbAart(pickingObjectDTO.getMtbAart());
result.set(mtbColr);
countDownLatch.countDown();
});
countDownLatch.await();
return result.get();
return mtbColr;
}
public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) {
this.sendOnLoadingStarted();
public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) throws Exception {
final MtbColr mtbColr = new MtbColr()
.setCodMart(pickingObjectDTO.getMtbAart().getCodMart())
.setPartitaMag(partitaMag)
@ -722,7 +643,8 @@ public class PickingLiberoViewModel {
return;
}
mColliMagazzinoRESTConsumer.saveCollo(cloneMtbColt, value -> {
var value = mColliMagazzinoRESTConsumer.saveColloSynchronized(cloneMtbColt);
mtbColr
.setDataCollo(value.getDataColloS())
.setNumCollo(value.getNumCollo())
@ -735,15 +657,12 @@ public class PickingLiberoViewModel {
mCurrentMtbColt.getMtbColr().add(mtbColr);
this.sendOnRowSaved();
this.sendOnLoadingEnded();
if (shouldCloseLU) closeLU(null);
}, this::sendError);
if (shouldCloseLU) closeLU();
}
private void loadRifULFromMtbColr(MtbColr mtbColr, RunnableArgs<MtbColt> onComplete) {
private MtbColt loadRifULFromMtbColr(MtbColr mtbColr) throws Exception {
//Se ho dei riferimenti ad una UL devo leggere la QTA ancora disponibile sulla Ul
if (mtbColr != null &&
!UtilityString.isNullOrEmpty(mtbColr.getGestioneRif()) &&
@ -751,28 +670,28 @@ public class PickingLiberoViewModel {
!UtilityString.isNullOrEmpty(mtbColr.getDataColloRifS()) &&
mtbColr.getNumColloRif() != null) {
mColliMagazzinoRESTConsumer.getByChiaveCollo(
MtbColt mtbColt = mColliMagazzinoRESTConsumer.getByChiaveColloSynchronized(
mtbColr.getGestioneRifEnum(),
mtbColr.getNumColloRif(),
mtbColr.getDataColloRifS(),
mtbColr.getSerColloRif(),
true,
false,
onComplete,
this::sendError);
false);
} else {
onComplete.run(null);
return mtbColt;
}
return null;
}
public void dispatchRowEdit(MtbColr mtbColrToUpdate) {
public void dispatchRowEdit(MtbColr mtbColrToUpdate) throws Exception {
this.sendOnLoadingStarted();
final PickingObjectDTO pickingObjectDTO = new PickingObjectDTO()
.setMtbAart(mtbColrToUpdate.getMtbAart());
loadRifULFromMtbColr(mtbColrToUpdate, mtbColtRif -> {
var mtbColtRif = loadRifULFromMtbColr(mtbColrToUpdate);
BigDecimal totalQtaAvailable = null;
@ -786,30 +705,30 @@ public class PickingLiberoViewModel {
if (mtbColrRifs != null && !mtbColrRifs.isEmpty()) {
//TODO: Da capire se è necessario controllare anche il cod_jcom
mtbColrRif = Stream.of(mtbColrRifs)
mtbColrRif = mtbColrRifs.stream()
.filter(x -> UtilityString.equalsIgnoreCase(x.getCodMart(), mtbColrToUpdate.getCodMart()) &&
UtilityString.equalsIgnoreCase(x.getCodCol(), mtbColrToUpdate.getCodCol()) &&
UtilityString.equalsIgnoreCase(x.getCodTagl(), mtbColrToUpdate.getCodTagl()) &&
UtilityString.equalsIgnoreCase(x.getPartitaMag(), mtbColrToUpdate.getPartitaMag()))
.findFirstOrElse(null);
.findFirst()
.orElse(null);
}
if (mtbColrRif != null) {
totalQtaAvailable = mtbColrRif.getQtaCol().add(mtbColrToUpdate.getQtaCol());
totalNumCnfAvailable = mtbColrRif.getNumCnf().add(mtbColrToUpdate.getNumCnf());
qtaCnfAvailable = mtbColrRif.getQtaCnf();
} else {
totalQtaAvailable = mtbColrToUpdate.getQtaCol();
totalNumCnfAvailable = mtbColrToUpdate.getNumCnf();
qtaCnfAvailable = mtbColrToUpdate.getQtaCnf();
}
this.sendOnLoadingEnded();
this.sendOnItemDispatched(
var pickedQuantityDTO = this.sendOnItemDispatched(
pickingObjectDTO,
pickingObjectDTO.getMtbAart(),
mtbColrToUpdate.getNumCnf(),
@ -825,29 +744,25 @@ public class PickingLiberoViewModel {
mtbColrToUpdate.getDataScadPartita(),
false,
false,
false,
(pickedQuantityDTO, shouldCloseLU) -> {
false);
if (pickedQuantityDTO == null) {
this.sendOnLoadingEnded();
return;
}
this.sendOnLoadingStarted();
this.saveEditedRow(mtbColrToUpdate,
pickedQuantityDTO.getNumCnf(),
pickedQuantityDTO.getQtaCnf(),
pickedQuantityDTO.getQtaTot(),
pickedQuantityDTO.getPartitaMag(),
pickedQuantityDTO.getDataScad(),
shouldCloseLU);
});
});
pickedQuantityDTO.isShouldCloseLu());
this.sendOnLoadingEnded();
}
private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) {
private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) throws Exception {
this.sendOnLoadingStarted();
@ -871,24 +786,24 @@ public class PickingLiberoViewModel {
mtbColt.getMtbColr().add(mtbColr);
this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> {
var value = this.mColliMagazzinoRESTConsumer.saveColloSynchronized(mtbColt);
mtbColr.setNumCnf(numCnf)
.setQtaCnf(qtaCnf)
.setQtaCol(qtaTot);
handler.post(() -> {
this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate);
this.mCurrentMtbColt.getMtbColr().add(mtbColr);
});
this.sendOnRowSaved();
this.sendOnLoadingEnded();
}, this::sendError);
}
public void deleteRow(MtbColr mtbColrToDelete) {
this.sendMtbColrDeleteRequest(shouldDelete -> {
public void deleteRow(MtbColr mtbColrToDelete) throws Exception {
var shouldDelete = this.sendMtbColrDeleteRequest();
if (shouldDelete) {
this.sendOnLoadingStarted();
@ -898,6 +813,7 @@ public class PickingLiberoViewModel {
.setSerCollo(mtbColrToDelete.getSerCollo())
.setGestione(mtbColrToDelete.getGestione())
.setMtbColr(new ObservableArrayList<>());
mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP);
MtbColr mtbColr = (MtbColr) mtbColrToDelete.clone();
@ -905,30 +821,30 @@ public class PickingLiberoViewModel {
mtbColr.setOperation(CommonModelConsts.OPERATION.DELETE);
mtbColt.getMtbColr().add(mtbColr);
this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> {
var value = this.mColliMagazzinoRESTConsumer.saveColloSynchronized(mtbColt);
handler.post(() -> {
this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete);
});
this.sendOnRowSaved();
this.sendOnLoadingEnded();
}, this::sendError);
}
});
}
public void closeLU(Runnable onComplete) {
public void closeLU() throws Exception {
if (mCurrentMtbColt == null) {
if (onComplete != null) onComplete.run();
return;
}
this.sendOnLoadingStarted();
this.mDefaultCommessa = null;
mColliMagazzinoRESTConsumer.canULBeDeleted(mCurrentMtbColt, canBeDeleted -> {
var canBeDeleted = mColliMagazzinoRESTConsumer.canULBeDeletedSynchronized(mCurrentMtbColt);
if (canBeDeleted) {
deleteLU(() -> {
deleteLU();
if (mMtbColtSessionID != null)
this.mColliDataRecoverService.closeSession(mMtbColtSessionID);
@ -936,11 +852,9 @@ public class PickingLiberoViewModel {
this.sendOnLoadingEnded();
this.mCurrentMtbColt = null;
if (onComplete != null) onComplete.run();
});
} else {
this.mColliMagazzinoRESTConsumer.assegnaLottoSuColloScarico(mCurrentMtbColt, () -> {
} else {
this.mColliMagazzinoRESTConsumer.assegnaLottoSuColloScaricoSynchronized(mCurrentMtbColt);
var closeUDSRequest = new CloseUDSRequestDTO()
.setMtbColt(mCurrentMtbColt);
@ -952,29 +866,25 @@ public class PickingLiberoViewModel {
.setDocumentCodAnag(SettingsManager.iDB().getInternalCodAnags().stream().filter(InternalCodAnagsDTO::isFornitore).findFirst().get().getCodAnag());
}
this.mColliScaricoRESTConsumer.closeUDS(closeUDSRequest, response -> {
var response = this.mColliScaricoRESTConsumer.closeUDSSynchronized(closeUDSRequest);
if (mMtbColtSessionID != null)
this.mColliDataRecoverService.closeSession(mMtbColtSessionID);
this.sendLUClosed();
this.sendOnLoadingEnded();
this.mCurrentMtbColt = null;
if (onComplete != null) onComplete.run();
}, this::sendError);
}, this::sendError);
}
}, this::sendError);
}
private void deleteLU(Runnable onComplete) {
}
private void deleteLU() throws Exception {
DeleteULRequestDTO deleteULRequestDTO = new DeleteULRequestDTO()
.setMtbColt(mCurrentMtbColt);
mColliMagazzinoRESTConsumer.deleteUL(deleteULRequestDTO, () -> {
this.mCurrentMtbColt = null;
if (onComplete != null) onComplete.run();
}, this::sendError);
mColliMagazzinoRESTConsumer.deleteULSynchronized(deleteULRequestDTO);
this.mCurrentMtbColt = null;
}
@ -998,20 +908,61 @@ public class PickingLiberoViewModel {
if (this.mListener != null) mListener.onLUClosed();
}
private void sendMtbColrDeleteRequest(RunnableArgs<Boolean> onComplete) {
if (this.mListener != null) mListener.onMtbColrDeleteRequest(onComplete);
private Boolean sendMtbColrDeleteRequest() throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<Boolean> result = new AtomicReference<>();
if (this.mListener != null) mListener.onMtbColrDeleteRequest(data -> {
result.set(data);
countDownLatch.countDown();
});
else countDownLatch.countDown();
countDownLatch.await();
return result.get();
}
private void sendLUClienteRequired(RunnableArgss<VtbDest, String> onComplete, Runnable onAbort) {
if (this.mListener != null) mListener.onLUClienteRequired(onComplete, onAbort);
private Pair<VtbDest, String> sendLUClienteRequired() throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<Pair<VtbDest, String>> result = new AtomicReference<>();
if (this.mListener != null) mListener.onLUClienteRequired((vtbDest, codJcom) -> {
result.set(new Pair<>(vtbDest, codJcom));
countDownLatch.countDown();
}, countDownLatch::countDown);
else countDownLatch.countDown();
countDownLatch.await();
return result.get();
}
private void sendLULineaProdRequired(RunnableArgs<DialogAskLineaProdResponse> onComplete, Runnable onAbort) {
if (this.mListener != null) mListener.onLULineaProdRequired(onComplete, onAbort);
private DialogAskLineaProdResponse sendLULineaProdRequired() throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<DialogAskLineaProdResponse> result = new AtomicReference<>();
if (this.mListener != null) mListener.onLULineaProdRequired(data -> {
result.set(data);
countDownLatch.countDown();
}, countDownLatch::countDown);
else countDownLatch.countDown();
countDownLatch.await();
return result.get();
}
private void sendLUCommessaRequired(RunnableArgs<JtbComt> onComplete, Runnable onAbort) {
if (this.mListener != null) mListener.onLUCommessaRequired(onComplete, onAbort);
private JtbComt sendLUCommessaRequired() throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<JtbComt> result = new AtomicReference<>();
if (this.mListener != null) mListener.onLUCommessaRequired(data -> {
result.set(data);
countDownLatch.countDown();
}, countDownLatch::countDown);
else countDownLatch.countDown();
countDownLatch.await();
return result.get();
}
private List<MtbColr> sendArtSelectionRequest(List<MtbColr> mtbColrsToPick, MtbAart mtbAart) throws InterruptedException {
@ -1026,12 +977,11 @@ public class PickingLiberoViewModel {
}, countDownLatch::countDown);
else countDownLatch.countDown();
countDownLatch.await();
return result.get();
}
private void sendOnItemDispatched(PickingObjectDTO pickingObjectDTO,
private PickedQuantityDTO sendOnItemDispatched(PickingObjectDTO pickingObjectDTO,
MtbAart mtbAart,
BigDecimal initialNumCnf,
BigDecimal initialQtaCnf,
@ -1046,8 +996,11 @@ public class PickingLiberoViewModel {
LocalDate dataScad,
boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged,
boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete) {
boolean canLUBeClosed) throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<PickedQuantityDTO> result = new AtomicReference<>();
if (this.mListener != null) mListener.onItemDispatched(pickingObjectDTO,
mtbAart,
@ -1065,7 +1018,17 @@ public class PickingLiberoViewModel {
canOverflowOrderQuantity,
canPartitaMagBeChanged,
canLUBeClosed,
onComplete);
pickedQuantityDTO -> {
if (pickedQuantityDTO != null) {
result.set(pickedQuantityDTO);
}
countDownLatch.countDown();
});
countDownLatch.await();
return result.get();
}
private void sendOnRowSaved() {
@ -1105,7 +1068,7 @@ public class PickingLiberoViewModel {
boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged,
boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete);
RunnableArgs<PickedQuantityDTO> onComplete);
}

View File

@ -812,7 +812,7 @@ public class SpedizioneViewModel {
.setOrdersOfNewUDS(orders)
.setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList);
mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronous(mtbDepoPosizione, magazzinoAutomaticoPickRequest);
mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione, magazzinoAutomaticoPickRequest);
}
public void executeEmptyMagazzinoAutomaticoRequest(MtbDepoPosizione mtbDepoPosizione) throws Exception {
@ -826,7 +826,7 @@ public class SpedizioneViewModel {
.setDefaultGestioneOfNewUDS(mDefaultGestioneOfUL.getText())
.setOrdersOfNewUDS(orders);
mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronous(mtbDepoPosizione, magazzinoAutomaticoPickRequest);
mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronized(mtbDepoPosizione, magazzinoAutomaticoPickRequest);
}
private void searchArtFromUL(MtbColt scannedUL) throws Exception {

View File

@ -298,6 +298,8 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
}
private void dismiss(DialogInputQuantityV2ResultDTO result) {
super.dismiss();
if (this.mOnComplete != null) {
if(result == null) {
result = new DialogInputQuantityV2ResultDTO()
@ -306,7 +308,6 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
this.mOnComplete.run(result);
}
super.dismiss();
}
@Override