Migliorata gestione caricamenti del Picking libero.

This commit is contained in:
Giuseppe Scorrano 2025-02-28 11:50:11 +01:00
parent bc27355ed6
commit e11e270101
7 changed files with 232 additions and 77 deletions

View File

@ -16,6 +16,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.inject.Singleton;
@ -311,15 +313,47 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
});
}
public void fillMtbAartsOfMtbColrs(List<MtbColr> mtbColrs, RunnableArgs<List<MtbColr>> onComplete, RunnableArgs<Exception> onFailed) {
List<String> codMarts = new ArrayList<>(mtbColrs.stream()
.map(MtbColr::getCodMart)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toUnmodifiableList()));
mArticoloRESTConsumer.getByCodMarts(codMarts, arts -> {
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);
}
}
onComplete.run(mtbColrs);
}, onFailed);
}
public void fillMtbAartsOfMtbColts(List<MtbColt> mtbColts, RunnableArgs<List<MtbColt>> onComplete, RunnableArgs<Exception> onFailed) {
List<String> codMarts = new ArrayList<>();
for (MtbColt mtbColt : mtbColts) {
codMarts.addAll(Stream.of(mtbColt.getMtbColr())
codMarts.addAll(mtbColt.getMtbColr().stream()
.map(MtbColr::getCodMart)
.withoutNulls()
.filter(Objects::nonNull)
.distinct()
.toList());
.collect(Collectors.toUnmodifiableList()));
}
@ -331,10 +365,11 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
MtbAart foundMtbAart = null;
List<MtbAart> mtbAartStream = Stream.of(arts)
.filter(x -> x.getCodMart().equalsIgnoreCase(mtbColr.getCodMart())).toList();
List<MtbAart> mtbAartStream = arts.stream()
.filter(x -> x.getCodMart().equalsIgnoreCase(mtbColr.getCodMart()))
.collect(Collectors.toList());
if (mtbAartStream != null && !mtbAartStream.isEmpty()) {
if (!mtbAartStream.isEmpty()) {
foundMtbAart = mtbAartStream.get(0);
}
@ -560,7 +595,9 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
@Override
public void onResponse(Call<ServiceRESTResponse<SpostaArtsTraULResponseDTO>> call, Response<ServiceRESTResponse<SpostaArtsTraULResponseDTO>> response) {
analyzeAnswer(response, "spostaArtsTraUL", data -> {
onComplete.run(data.getGeneratedMtbColr());
fillMtbAartsOfMtbColrs(data.getGeneratedMtbColr(), onComplete, onFailed);
}, onFailed);
}

View File

@ -112,8 +112,13 @@ public class UtilityString {
return stringToCheck == null || stringToCheck.trim().isEmpty();
}
public static String isNull(String stringToCheck, String alternativeString){
return isNullOrEmpty(stringToCheck) ? alternativeString : stringToCheck;
public static String isNull(String... strings) {
for (String string : strings) {
if (!isNullOrEmpty(string)) {
return string;
}
}
return null;
}
public static String empty2null(String stringToCheck) {

View File

@ -373,10 +373,11 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme
.setPartitaMag(resultDTO.getPartitaMag())
.setDataScad(resultDTO.getDataScad());
this.onLoadingStarted();
onComplete.run(pickedQuantityDTO, shouldCloseLU);
})
.setOnAbort(this::onLoadingEnded)
.setOnAbort(() -> {
onComplete.run(null, false);
})
.show(requireActivity().getSupportFragmentManager(), "tag");
}

View File

@ -1,9 +1,12 @@
package it.integry.integrywmsnative.gest.picking_libero;
import java.util.concurrent.ExecutorService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import it.integry.integrywmsnative.core.data_recover.ColliDataRecoverService;
import it.integry.integrywmsnative.core.rest.consumers.ArticoloRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.ColliLavorazioneRESTConsumer;
@ -18,22 +21,27 @@ public class PickingLiberoModule {
@Provides
@Singleton
PickingLiberoViewModel providesPickingLiberoViewModel(ArticoloRESTConsumer articoloRESTConsumer,
PickingLiberoViewModel providesPickingLiberoViewModel(ExecutorService executorService,
ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer,
PosizioniRESTConsumer posizioniRESTConsumer,
GiacenzaRESTConsumer giacenzaRESTConsumer,
MagazzinoAutomaticoRESTConsumer magazzinoAutomaticoRESTConsumer,
ColliLavorazioneRESTConsumer colliLavorazioneRESTConsumer,
ColliSpedizioneRESTConsumer colliSpedizioneRESTConsumer
ColliSpedizioneRESTConsumer colliSpedizioneRESTConsumer,
ColliDataRecoverService colliDataRecoverService
) {
return new PickingLiberoViewModel(articoloRESTConsumer,
return new PickingLiberoViewModel(
executorService,
articoloRESTConsumer,
colliMagazzinoRESTConsumer,
barcodeRESTConsumer,
posizioniRESTConsumer,
giacenzaRESTConsumer,
magazzinoAutomaticoRESTConsumer,
colliLavorazioneRESTConsumer,
colliSpedizioneRESTConsumer);
colliSpedizioneRESTConsumer,
colliDataRecoverService);
}
}

View File

@ -7,12 +7,16 @@ import com.annimon.stream.Stream;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import javax.inject.Inject;
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
import it.integry.integrywmsnative.core.data_recover.ColliDataRecoverService;
import it.integry.integrywmsnative.core.exception.InvalidCodMdepException;
import it.integry.integrywmsnative.core.exception.NoArtsFoundException;
import it.integry.integrywmsnative.core.exception.NoLUFoundException;
@ -66,12 +70,14 @@ public class PickingLiberoViewModel {
private MtbColt mCurrentMtbColt = null;
private final ExecutorService executorService;
private final ArticoloRESTConsumer mArticoloRESTConsumer;
private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer;
private final BarcodeRESTConsumer mBarcodeRESTConsumer;
private final PosizioniRESTConsumer mPosizioniRESTConsumer;
private final GiacenzaRESTConsumer mGiacenzaRESTConsumer;
private final MagazzinoAutomaticoRESTConsumer mMagazzinoAutomaticoRESTConsumer;
private final ColliDataRecoverService mColliDataRecoverService;
private ColliScaricoRESTConsumerInterface mColliScaricoRESTConsumer;
private final ColliLavorazioneRESTConsumer mColliLavorazioneRESTConsumer;
@ -86,17 +92,21 @@ public class PickingLiberoViewModel {
private Listener mListener;
private Integer mMtbColtSessionID;
@Inject
public PickingLiberoViewModel(ArticoloRESTConsumer articoloRESTConsumer,
public PickingLiberoViewModel(ExecutorService executorService,
ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer,
PosizioniRESTConsumer posizioniRESTConsumer,
GiacenzaRESTConsumer giacenzaRESTConsumer,
MagazzinoAutomaticoRESTConsumer mMagazzinoAutomaticoRESTConsumer,
ColliLavorazioneRESTConsumer colliLavorazioneRESTConsumer,
ColliSpedizioneRESTConsumer colliSpedizioneRESTConsumer) {
ColliSpedizioneRESTConsumer colliSpedizioneRESTConsumer,
ColliDataRecoverService colliDataRecoverService) {
this.executorService = executorService;
this.mArticoloRESTConsumer = articoloRESTConsumer;
this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer;
this.mBarcodeRESTConsumer = barcodeRESTConsumer;
@ -105,6 +115,7 @@ public class PickingLiberoViewModel {
this.mMagazzinoAutomaticoRESTConsumer = mMagazzinoAutomaticoRESTConsumer;
this.mColliLavorazioneRESTConsumer = colliLavorazioneRESTConsumer;
this.mColliSpedizioneRESTConsumer = colliSpedizioneRESTConsumer;
this.mColliDataRecoverService = colliDataRecoverService;
}
@ -186,7 +197,18 @@ public class PickingLiberoViewModel {
.map(MvwSitArtUdcDetInventario::toMtbColr)
.toList();
this.sendArtSelectionRequest(mtbColrs, null, selectedMtbColrs -> {
List<MtbColr> selectedMtbColrs = null;
try {
selectedMtbColrs = this.sendArtSelectionRequest(mtbColrs, null);
} catch (InterruptedException e) {
this.sendError(e);
return;
}
if (selectedMtbColrs == null) {
this.sendOnLoadingEnded();
return;
}
final List<MagazzinoAutomaticoPickItemRequestDTO> magazzinoAutomaticoPickItemRequestDTOList = new ArrayList<>();
for (MtbColr selectedArt : selectedMtbColrs) {
@ -205,7 +227,8 @@ public class PickingLiberoViewModel {
mMagazzinoAutomaticoRESTConsumer.pickItems(mtbDepoPosizione,
magazzinoAutomaticoPickRequest, onComplete, this::sendError);
}, this::sendOnLoadingEnded);
this.sendOnLoadingEnded();
}, this::sendError);
@ -382,6 +405,8 @@ public class PickingLiberoViewModel {
mColliScaricoRESTConsumer.createUDS(createUDSRequest, mtbColt -> {
mMtbColtSessionID = mColliDataRecoverService.startNewSession(mtbColt, null);
mtbColt
.setMtbColr(new ObservableArrayList<>());
@ -526,6 +551,11 @@ public class PickingLiberoViewModel {
true,
true,
(pickedQuantityDTO, shouldCloseLU) -> {
if (pickedQuantityDTO == null) {
this.sendOnLoadingEnded();
return;
}
this.saveNewRow(pickingObjectDTO,
pickedQuantityDTO.getNumCnf(),
pickedQuantityDTO.getQtaCnf(),
@ -541,25 +571,40 @@ public class PickingLiberoViewModel {
}
private void pickMerceULtoUL(MtbColt sourceMtbColt, MtbAart mtbAart, Runnable onComplete) {
List<MtbColr> mtbColrsToPick = Stream.of(sourceMtbColt.getMtbColr())
.filter(x -> UtilityBigDecimal.greaterThan(x.getQtaCol(), BigDecimal.ZERO))
.toList();
executorService.execute(() -> {
this.sendArtSelectionRequest(mtbColrsToPick, mtbAart, pickedAarts -> {
List<MtbColr> destNewMtbColr = new ArrayList<>();
try {
List<MtbColr> mtbColrsToPick = sourceMtbColt.getMtbColr().stream()
.filter(x -> UtilityBigDecimal.greaterThan(x.getQtaCol(), BigDecimal.ZERO))
.collect(Collectors.toList());
List<MtbColr> pickedAarts = this.sendArtSelectionRequest(mtbColrsToPick, mtbAart);
if (pickedAarts == null) {
this.sendOnLoadingEnded();
return;
}
List<MtbColr> mtbColrsToMove = new ArrayList<>();
if (!pickedAarts.isEmpty()) {
askQuantities(pickedAarts.iterator(), destNewMtbColr, () -> {
if (!destNewMtbColr.isEmpty()) {
for (var pickedArt : pickedAarts) {
var mtbColr = askSingleQuantity(pickedArt);
if(this.mDefaultCommessa != null)
destNewMtbColr.forEach(x -> x.setCodJcom(this.mDefaultCommessa.getCodJcom()));
if (mtbColr != null)
mtbColrsToMove.add(mtbColr);
}
MtbColt clonedTestata = (MtbColt) sourceMtbColt.clone();
clonedTestata.getMtbColr().clear();
clonedTestata.getMtbColr().addAll(destNewMtbColr);
if (!mtbColrsToMove.isEmpty()) {
mColliMagazzinoRESTConsumer.spostaArtsTraUL(clonedTestata,
if (this.mDefaultCommessa != null)
mtbColrsToMove.forEach(x -> x.setCodJcom(this.mDefaultCommessa.getCodJcom()));
MtbColt clonedSourceTestata = (MtbColt) sourceMtbColt.clone();
clonedSourceTestata.getMtbColr().clear();
clonedSourceTestata.getMtbColr().addAll(mtbColrsToMove);
mColliMagazzinoRESTConsumer.spostaArtsTraUL(clonedSourceTestata,
this.mCurrentMtbColt, true, (generatedMtbColrs) -> {
mCurrentMtbColt.getMtbColr().addAll(generatedMtbColrs);
@ -569,27 +614,24 @@ public class PickingLiberoViewModel {
onComplete.run();
}, this::sendError);
}
}, onComplete);
} else {
onComplete.run();
}
}, this::sendOnLoadingEnded);
this.sendOnLoadingEnded();
}
private void askQuantities(Iterator<MtbColr> sourceMtbColrs, List<MtbColr> destMtbColr, Runnable onComplete, Runnable onAbort) {
if (sourceMtbColrs.hasNext()) {
askSingleQuantity(sourceMtbColrs.next(), mtbColr -> {
destMtbColr.add(mtbColr);
askQuantities(sourceMtbColrs, destMtbColr, onComplete, onAbort);
}, onAbort);
} else {
onComplete.run();
}
this.sendOnLoadingEnded();
}
private void askSingleQuantity(MtbColr mtbColr, RunnableArgs<MtbColr> onComplete, Runnable onAbort) {
} catch (InterruptedException e) {
this.sendError(e);
}
});
}
private MtbColr askSingleQuantity(MtbColr mtbColr) throws InterruptedException {
MtbColt sourceMtbColt = new MtbColt()
.setNumCollo(mtbColr.getNumCollo())
@ -608,6 +650,8 @@ public class PickingLiberoViewModel {
new PickDataDTO()
.setSourceMtbColt(sourceMtbColt));
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<MtbColr> result = new AtomicReference<>();
this.sendOnItemDispatched(
pickingObjectDTO,
@ -627,6 +671,10 @@ public class PickingLiberoViewModel {
false,
false,
(pickedQuantityDTO, shouldCloseLU) -> {
if (pickedQuantityDTO == null) {
countDownLatch.countDown();
return;
}
mtbColr
.setPartitaMag(pickedQuantityDTO.getPartitaMag())
@ -634,16 +682,21 @@ public class PickingLiberoViewModel {
.setQtaCol(pickedQuantityDTO.getQtaTot())
.setQtaCnf(pickedQuantityDTO.getQtaCnf())
.setNumCnf(pickedQuantityDTO.getNumCnf())
.setDatetimeRow(UtilityDate.getDateInstance());
.setDatetimeRow(UtilityDate.getDateInstance())
.setMtbAart(pickingObjectDTO.getMtbAart());
onComplete.run(mtbColr);
result.set(mtbColr);
countDownLatch.countDown();
});
countDownLatch.await();
return result.get();
}
public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) {
new Thread(this::sendOnLoadingStarted).start();
this.sendOnLoadingStarted();
final MtbColr mtbColr = new MtbColr()
.setCodMart(pickingObjectDTO.getMtbAart().getCodMart())
@ -772,8 +825,12 @@ public class PickingLiberoViewModel {
mtbColrToUpdate.getDataScadPartita(),
false,
false,
true,
false,
(pickedQuantityDTO, shouldCloseLU) -> {
if (pickedQuantityDTO == null) {
this.sendOnLoadingEnded();
return;
}
this.saveEditedRow(mtbColrToUpdate,
pickedQuantityDTO.getNumCnf(),
@ -872,6 +929,9 @@ public class PickingLiberoViewModel {
mColliMagazzinoRESTConsumer.canULBeDeleted(mCurrentMtbColt, canBeDeleted -> {
if (canBeDeleted) {
deleteLU(() -> {
if (mMtbColtSessionID != null)
this.mColliDataRecoverService.closeSession(mMtbColtSessionID);
this.sendLUClosed();
this.sendOnLoadingEnded();
@ -893,6 +953,9 @@ public class PickingLiberoViewModel {
}
this.mColliScaricoRESTConsumer.closeUDS(closeUDSRequest, response -> {
if (mMtbColtSessionID != null)
this.mColliDataRecoverService.closeSession(mMtbColtSessionID);
this.sendLUClosed();
this.sendOnLoadingEnded();
@ -951,9 +1014,21 @@ public class PickingLiberoViewModel {
if (this.mListener != null) mListener.onLUCommessaRequired(onComplete, onAbort);
}
private void sendArtSelectionRequest(List<MtbColr> mtbColrsToPick, MtbAart mtbAart, RunnableArgs<List<MtbColr>> onComplete, Runnable onAbort) {
private List<MtbColr> sendArtSelectionRequest(List<MtbColr> mtbColrsToPick, MtbAart mtbAart) throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<List<MtbColr>> result = new AtomicReference<>();
if (this.mListener != null)
mListener.onArtSelectionRequest(mtbColrsToPick, mtbAart, onComplete, onAbort);
mListener.onArtSelectionRequest(mtbColrsToPick, mtbAart, mtbColrs -> {
result.set(mtbColrs);
countDownLatch.countDown();
}, countDownLatch::countDown);
else countDownLatch.countDown();
countDownLatch.await();
return result.get();
}
private void sendOnItemDispatched(PickingObjectDTO pickingObjectDTO,
@ -973,6 +1048,7 @@ public class PickingLiberoViewModel {
boolean canPartitaMagBeChanged,
boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete) {
if (this.mListener != null) mListener.onItemDispatched(pickingObjectDTO,
mtbAart,
initialNumCnf,

View File

@ -74,7 +74,12 @@ public class DialogProgressView extends DialogFragment {
try {
if (!manager.isDestroyed() && !isAdded()) {
//manager.executePendingTransactions();
try {
manager.executePendingTransactions();
} catch (IllegalStateException e) {
//ignore
String a = "";
}
showNow(manager, "loading-dialog");
mBindings.progressBar.setIndeterminate(isIndeterminateProgress());
@ -91,7 +96,16 @@ public class DialogProgressView extends DialogFragment {
handler.post(() -> {
if (isAdded()) {
dismissAllowingStateLoss();
if (!getParentFragmentManager().isDestroyed()) {
try {
getParentFragmentManager().executePendingTransactions();
} catch (IllegalStateException e) {
//ignore
String a = "";
}
}
}
});
}

View File

@ -267,8 +267,7 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
if (validated) {
this.mAbort = false;
dismiss();
this.mOnComplete.run(this.mViewModel.getResult(), false);
dismiss(this.mViewModel.getResult(), false);
}
});
});
@ -278,14 +277,29 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
this.mViewModel.validate(validated -> {
if (validated) {
this.mAbort = false;
dismiss();
this.mOnComplete.run(this.mViewModel.getResult(), true);
dismiss(this.mViewModel.getResult(), true);
} else {
this.onLoadingEnded();
}
});
}
@Override
public void dismiss() {
dismiss(null, false);
}
private void dismiss(DialogInputQuantityV2ResultDTO result, boolean shouldCloseLu) {
if (this.mOnComplete != null) {
if(result == null) {
mOnAbort.run();
} else {
this.mOnComplete.run(result, shouldCloseLu);
}
}
super.dismiss();
}
@Override
public void onStart() {
super.onStart();