Fix su retrieve degli ultimi versamenti di materiale

This commit is contained in:
Giuseppe Scorrano 2025-09-17 15:09:01 +02:00
parent c36bc9d8c2
commit 9c72a2a628
10 changed files with 561 additions and 373 deletions

View File

@ -4,9 +4,6 @@ import androidx.databinding.BaseObservable;
import java.math.BigDecimal; import java.math.BigDecimal;
import it.integry.integrywmsnative.core.CommonConst;
import it.integry.integrywmsnative.core.utility.UtilityNumber;
public class BindableFloat extends BaseObservable { public class BindableFloat extends BaseObservable {
private Float value; private Float value;
@ -15,10 +12,6 @@ public class BindableFloat extends BaseObservable {
} }
public BigDecimal getBigDecimal() { public BigDecimal getBigDecimal() {
int numberOfDigits = UtilityNumber.countNumberOfDecimalDigits(get());
if(numberOfDigits > CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS) numberOfDigits = CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS;
return BigDecimal.valueOf(get()); return BigDecimal.valueOf(get());
} }

View File

@ -261,7 +261,7 @@ public class Converters {
BigDecimal value = null; BigDecimal value = null;
if (!UtilityString.isNullOrEmpty(s.toString())) if (!UtilityString.isNullOrEmpty(s.toString()))
value = new BigDecimal(s.toString()); value = UtilityNumber.parseBigDecimal(s.toString(), Locale.getDefault());
observableBigDecimal.set(value); observableBigDecimal.set(value);
} }
@ -271,7 +271,7 @@ public class Converters {
} }
BigDecimal newValue = observableBigDecimal.get(); BigDecimal newValue = observableBigDecimal.get();
BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? new BigDecimal(view.getText().toString()) : null; BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? UtilityNumber.parseBigDecimal(view.getText().toString(), Locale.getDefault()) : null;
if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) { if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) {
view.setText(UtilityNumber.decimalToString(newValue)); view.setText(UtilityNumber.decimalToString(newValue));
@ -292,7 +292,7 @@ public class Converters {
String newValueString = s.toString().trim(); String newValueString = s.toString().trim();
if (!UtilityString.isNullOrEmpty(newValueString)) if (!UtilityString.isNullOrEmpty(newValueString))
value = new BigDecimal(newValueString); value = UtilityNumber.parseBigDecimal(newValueString, Locale.getDefault());
observableBigDecimal.set(value); observableBigDecimal.set(value);
} }
@ -301,7 +301,7 @@ public class Converters {
view.addTextChangedListener(watcher); view.addTextChangedListener(watcher);
} }
BigDecimal newValue = observableBigDecimal.get(); BigDecimal newValue = observableBigDecimal.get();
BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? new BigDecimal(view.getText().toString()) : null; BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? UtilityNumber.parseBigDecimal(view.getText().toString(), Locale.getDefault()) : null;
if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) { if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) {
view.setText(UtilityNumber.decimalToString(newValue)); view.setText(UtilityNumber.decimalToString(newValue));
@ -322,7 +322,7 @@ public class Converters {
String newValueString = s.toString().trim(); String newValueString = s.toString().trim();
if (!UtilityString.isNullOrEmpty(newValueString)) if (!UtilityString.isNullOrEmpty(newValueString))
value = new BigDecimal(newValueString); value = UtilityNumber.parseBigDecimal(newValueString, Locale.getDefault());
observableBigDecimal.set(value); observableBigDecimal.set(value);
} }
@ -331,7 +331,7 @@ public class Converters {
view.addTextChangedListener(watcher); view.addTextChangedListener(watcher);
} }
BigDecimal newValue = observableBigDecimal.get(); BigDecimal newValue = observableBigDecimal.get();
BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? new BigDecimal(view.getText().toString()) : null; BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? UtilityNumber.parseBigDecimal(view.getText().toString(), Locale.getDefault()) : null;
if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) { if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) {
view.setText(UtilityNumber.decimalToString(newValue)); view.setText(UtilityNumber.decimalToString(newValue));
@ -350,7 +350,8 @@ public class Converters {
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
BigDecimal value = null; BigDecimal value = null;
if (!UtilityString.isNullOrEmpty(s.toString())) if (!UtilityString.isNullOrEmpty(s.toString()))
value = new BigDecimal(s.toString()); value = UtilityNumber.parseBigDecimal(s.toString(), Locale.getDefault());
bindableBigDecimal.set(value); bindableBigDecimal.set(value);
} }
}; };
@ -358,7 +359,7 @@ public class Converters {
view.addTextChangedListener(watcher); view.addTextChangedListener(watcher);
} }
BigDecimal newValue = bindableBigDecimal.get(); BigDecimal newValue = bindableBigDecimal.get();
BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? new BigDecimal(view.getText().toString()) : null; BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? UtilityNumber.parseBigDecimal(view.getText().toString(), Locale.getDefault()) : null;
if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) { if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) {
view.setText(UtilityNumber.decimalToString(newValue)); view.setText(UtilityNumber.decimalToString(newValue));

View File

@ -1,5 +1,6 @@
package it.integry.integrywmsnative.core.rest.consumers; package it.integry.integrywmsnative.core.rest.consumers;
import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -9,6 +10,7 @@ import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.core.rest.RESTBuilder; import it.integry.integrywmsnative.core.rest.RESTBuilder;
import it.integry.integrywmsnative.core.rest.model.materiali.RecuperaMaterialiRequestDTO; import it.integry.integrywmsnative.core.rest.model.materiali.RecuperaMaterialiRequestDTO;
import it.integry.integrywmsnative.core.rest.model.materiali.VersaMaterialiRequestDTO; import it.integry.integrywmsnative.core.rest.model.materiali.VersaMaterialiRequestDTO;
import it.integry.integrywmsnative.gest.prod_recupero_materiale.dto.HistoryVersamentoProdULRestDTO;
@Singleton @Singleton
public class MaterialiRESTConsumer extends _BaseRESTConsumer { public class MaterialiRESTConsumer extends _BaseRESTConsumer {
@ -21,6 +23,28 @@ public class MaterialiRESTConsumer extends _BaseRESTConsumer {
this.executorService = executorService; this.executorService = executorService;
} }
public List<HistoryVersamentoProdULRestDTO> makeSynchronousRetrieveLastVersamentiRequest(String codJfas) throws Exception {
var materialiRESTConsumerService = restBuilder.getService(MaterialiRESTConsumerService.class);
var response = materialiRESTConsumerService.retrieveLastVersamenti(codJfas)
.execute();
var data = analyzeAnswer(response, "retrieveLastVersamenti");
return data;
}
public void makeRetrieveLastVersamentiRequest(String codJfas, final RunnableArgs<List<HistoryVersamentoProdULRestDTO>> onComplete, final RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
try {
var response = makeSynchronousRetrieveLastVersamentiRequest(codJfas);
if (onComplete != null) onComplete.run(response);
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
}
});
}
public MtbColt makeSynchronousRecuperaRequest(RecuperaMaterialiRequestDTO request) throws Exception { public MtbColt makeSynchronousRecuperaRequest(RecuperaMaterialiRequestDTO request) throws Exception {
var materialiRESTConsumerService = restBuilder.getService(MaterialiRESTConsumerService.class); var materialiRESTConsumerService = restBuilder.getService(MaterialiRESTConsumerService.class);

View File

@ -1,17 +1,26 @@
package it.integry.integrywmsnative.core.rest.consumers; package it.integry.integrywmsnative.core.rest.consumers;
import java.util.List;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse; 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.RecuperaMaterialiRequestDTO;
import it.integry.integrywmsnative.core.rest.model.materiali.RecuperaMaterialiResponseDTO; import it.integry.integrywmsnative.core.rest.model.materiali.RecuperaMaterialiResponseDTO;
import it.integry.integrywmsnative.core.rest.model.materiali.VersaMaterialiRequestDTO; import it.integry.integrywmsnative.core.rest.model.materiali.VersaMaterialiRequestDTO;
import it.integry.integrywmsnative.core.rest.model.materiali.VersaMaterialiResponseDTO;
import it.integry.integrywmsnative.gest.prod_recupero_materiale.dto.HistoryVersamentoProdULRestDTO;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.Query;
public interface MaterialiRESTConsumerService { public interface MaterialiRESTConsumerService {
@POST("wms/materiali/versa") @POST("wms/materiali/versa")
Call<ServiceRESTResponse<RecuperaMaterialiResponseDTO>> versa(@Body VersaMaterialiRequestDTO request); Call<ServiceRESTResponse<VersaMaterialiResponseDTO>> versa(@Body VersaMaterialiRequestDTO request);
@GET("wms/materiali/retrieveLastVersamenti")
Call<ServiceRESTResponse<List<HistoryVersamentoProdULRestDTO>>> retrieveLastVersamenti(@Query("codJfas") String codJfas);
@POST("wms/materiali/recupera") @POST("wms/materiali/recupera")
Call<ServiceRESTResponse<RecuperaMaterialiResponseDTO>> recupera(@Body RecuperaMaterialiRequestDTO request); Call<ServiceRESTResponse<RecuperaMaterialiResponseDTO>> recupera(@Body RecuperaMaterialiRequestDTO request);

View File

@ -1,6 +1,7 @@
package it.integry.integrywmsnative.core.utility; package it.integry.integrywmsnative.core.utility;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.Locale; import java.util.Locale;
@ -9,7 +10,8 @@ import it.integry.integrywmsnative.core.CommonConst;
public class UtilityNumber { public class UtilityNumber {
private static DecimalFormat decimalFormatInstance; // Locale italiano per la formattazione
private static final Locale ITALIAN_LOCALE = new Locale("it", "IT");
public static String decimalToString(Float bigDecimal){ public static String decimalToString(Float bigDecimal){
if(bigDecimal == null) return "0"; if(bigDecimal == null) return "0";
@ -23,71 +25,59 @@ public class UtilityNumber {
public static String decimalToString(BigDecimal bigDecimal, int decimal){ public static String decimalToString(BigDecimal bigDecimal, int decimal){
if(bigDecimal == null) return "0"; if(bigDecimal == null) return "0";
return decimalToString(bigDecimal.floatValue(), decimal);
// Usa stripTrailingZeros per rimuovere gli zeri finali
BigDecimal stripped = bigDecimal.stripTrailingZeros();
// Limita il numero di decimali visualizzati
int scale = Math.min(stripped.scale(), decimal);
stripped = stripped.setScale(scale, RoundingMode.DOWN);
// Configura il formato italiano con virgola come separatore decimale
DecimalFormatSymbols italianSymbols = new DecimalFormatSymbols(ITALIAN_LOCALE);
italianSymbols.setDecimalSeparator(',');
// Crea il pattern dinamico basato sul numero di decimali
StringBuilder patternBuilder = new StringBuilder("0");
if (scale > 0) {
patternBuilder.append(".");
for (int i = 0; i < scale; i++) {
patternBuilder.append("0");
}
}
DecimalFormat formatter = new DecimalFormat(patternBuilder.toString(), italianSymbols);
String result = formatter.format(stripped);
// Se il risultato termina con ',', rimuovilo (per i numeri interi)
if (result.endsWith(",")) {
result = result.substring(0, result.length() - 1);
}
return result;
} }
public static String decimalToString(float floatValue, int decimal) { public static String decimalToString(float floatValue, int decimal) {
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault()); return decimalToString(BigDecimal.valueOf(floatValue), decimal);
otherSymbols.setDecimalSeparator('.');
otherSymbols.setGroupingSeparator(',');
final DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setMaximumFractionDigits(decimal);
decimalFormat.setDecimalFormatSymbols(otherSymbols);
decimalFormat.setGroupingUsed(false);
decimalFormat.setMinimumFractionDigits(Math.min(2, decimal));
return decimalFormat.format(floatValue);
} }
public static DecimalFormat getNumberFormatInstance() { public static BigDecimal parseBigDecimal(String value, Locale locale) {
if (value == null || value.trim().isEmpty()) return null;
if(decimalFormatInstance == null) { try {
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault()); DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
otherSymbols.setDecimalSeparator('.'); DecimalFormat format = new DecimalFormat();
otherSymbols.setGroupingSeparator(','); format.setDecimalFormatSymbols(symbols);
format.setParseBigDecimal(true);
decimalFormatInstance = new DecimalFormat(); return (BigDecimal) format.parse(value);
decimalFormatInstance.setMaximumFractionDigits(CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS); } catch (Exception e) {
decimalFormatInstance.setDecimalFormatSymbols(otherSymbols); return null;
decimalFormatInstance.setGroupingUsed(false); }
} }
return decimalFormatInstance; /**
} * Parsa una stringa numerica italiana (con virgola come separatore decimale)
* e restituisce un BigDecimal
public static int countNumberOfDecimalDigits(Float value) { */
String text = getNumberFormatInstance().format(Math.abs(value)); public static BigDecimal parseItalianBigDecimal(String value) {
int integerPlaces = text.indexOf('.'); return parseBigDecimal(value, ITALIAN_LOCALE);
int decimalPlaces = text.length() - integerPlaces - 1;
return decimalPlaces;
}
public static String normalizeStringNumber(String numberString) {
return numberString.replaceAll(",", ".");
}
public static Float decimalToFloat(BigDecimal bigDecimalValue) {
float multiplier = (float) Math.pow(10, CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS);
Float floatValue = null;
if(bigDecimalValue != null) {
int intValue = (int) (bigDecimalValue.floatValue() * multiplier);
floatValue = Float.valueOf(intValue / multiplier);
}
return floatValue;
}
public static float truncateToDecimal(float v, int i) {
int delta = 10*i;
return ((int)v*delta)/delta;
} }
} }

View File

@ -122,7 +122,13 @@ public class ProdRecuperoMaterialeFragment extends BaseFragment implements ITitl
BarcodeManager.removeCallback(mBarcodeScannerInstanceID); BarcodeManager.removeCallback(mBarcodeScannerInstanceID);
} }
}); });
mViewModel.init(codJfas); mViewModel.init(codJfas);
mViewModel.refreshData(); // This will eventually trigger the LiveData observer for getOrderList
mBinding.swiperefresh.setOnRefreshListener(() -> {
mViewModel.refreshData();
});
} }
@ -299,8 +305,30 @@ public class ProdRecuperoMaterialeFragment extends BaseFragment implements ITitl
@Override @Override
public void onDataSaved() { public void onDataSaved() {
this.onLoadingEnded(); this.onLoadingEnded();
this.requireActivity().runOnUiThread(() -> { handler.post(() -> {
DialogCommon.showDataSaved(requireActivity(), this::popMe); DialogCommon.showDataSaved(requireActivity(), this::popMe);
}); });
} }
@Override
public void onDataRefreshStarted() {
handler.post(() -> {
mBinding.swiperefresh.setRefreshing(true);
});
}
@Override
public void onDataRefreshEnded() {
handler.post(() -> {
mBinding.swiperefresh.setRefreshing(false);
// applyFilters(); // Non strettamente necessario qui se l'observer di getOrderList() fa il suo dovere
});
}
@Override
public void onError(Exception ex) {
super.onError(ex);
onDataRefreshEnded();
}
} }

View File

@ -1,28 +1,10 @@
package it.integry.integrywmsnative.gest.prod_recupero_materiale; package it.integry.integrywmsnative.gest.prod_recupero_materiale;
import dagger.Module; import dagger.Module;
import dagger.Provides;
import it.integry.integrywmsnative.core.rest.consumers.ArticoloRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.MaterialiRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.PrinterRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer;
import it.integry.integrywmsnative.gest.prod_recupero_materiale.rest.ProdRecuperoMaterialeRESTConsumer;
@Module(subcomponents = ProdRecuperoMaterialeComponent.class) @Module(subcomponents = ProdRecuperoMaterialeComponent.class)
public class ProdRecuperoMaterialeModule { public class ProdRecuperoMaterialeModule {
@Provides
ProdRecuperoMaterialeRESTConsumer providesProdRecuperMaterialeRESTConsumer(SystemRESTConsumer systemRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer) {
return new ProdRecuperoMaterialeRESTConsumer(systemRESTConsumer, articoloRESTConsumer);
}
@Provides
ProdRecuperoMaterialeViewModel providesProdRecuperoMaterialeViewModel(ProdRecuperoMaterialeRESTConsumer prodRecuperoMaterialeRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
PrinterRESTConsumer printerRESTConsumer,
MaterialiRESTConsumer materialiRESTConsumer) {
return new ProdRecuperoMaterialeViewModel(prodRecuperoMaterialeRESTConsumer, colliMagazzinoRESTConsumer, printerRESTConsumer, materialiRESTConsumer);
}
} }

View File

@ -3,8 +3,10 @@ package it.integry.integrywmsnative.gest.prod_recupero_materiale;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
@ -32,31 +34,46 @@ public class ProdRecuperoMaterialeViewModel {
private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer; private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer;
private final PrinterRESTConsumer mPrinterRESTConsumer; private final PrinterRESTConsumer mPrinterRESTConsumer;
private final MaterialiRESTConsumer mMaterialiRESTConsumer; private final MaterialiRESTConsumer mMaterialiRESTConsumer;
private final ExecutorService mExecutorService;
private final MutableLiveData<List<HistoryVersamentoProdULDTO>> mUlList = new MutableLiveData<>(); private final MutableLiveData<List<HistoryVersamentoProdULDTO>> mUlList = new MutableLiveData<>();
private Listener mListener; private Listener mListener;
private String mCodJfas;
@Inject @Inject
public ProdRecuperoMaterialeViewModel(ProdRecuperoMaterialeRESTConsumer prodRecuperoMaterialeRESTConsumer, public ProdRecuperoMaterialeViewModel(ProdRecuperoMaterialeRESTConsumer prodRecuperoMaterialeRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
PrinterRESTConsumer printerRESTConsumer, PrinterRESTConsumer printerRESTConsumer,
MaterialiRESTConsumer materialiRESTConsumer) { MaterialiRESTConsumer materialiRESTConsumer,
ExecutorService executorService) {
this.mProdRecuperoMaterialeRESTConsumer = prodRecuperoMaterialeRESTConsumer; this.mProdRecuperoMaterialeRESTConsumer = prodRecuperoMaterialeRESTConsumer;
this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer; this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer;
this.mPrinterRESTConsumer = printerRESTConsumer; this.mPrinterRESTConsumer = printerRESTConsumer;
this.mMaterialiRESTConsumer = materialiRESTConsumer; this.mMaterialiRESTConsumer = materialiRESTConsumer;
this.mExecutorService = executorService;
} }
public void init(String codJfas) { public void init(String codJfas) {
this.sendOnLoadingStarted(); this.mCodJfas = codJfas;
}
mProdRecuperoMaterialeRESTConsumer.loadLastULVersate(codJfas, ulList -> { public void refreshData() {
this.mUlList.postValue(ulList); this.sendOnDataRefreshStarted();
this.sendOnLoadingEnded(); this.mExecutorService.execute(() -> {
}, this::sendError); try {
List<HistoryVersamentoProdULDTO> lastUlVersate = mProdRecuperoMaterialeRESTConsumer.loadLastULVersateSynchronized(mCodJfas);
lastUlVersate.sort(Comparator.comparing(HistoryVersamentoProdULDTO::getCodJfas));
this.mUlList.postValue(lastUlVersate);
this.sendOnDataRefreshEnded();
} catch (Exception e) {
this.sendError(e);
}
});
} }
public void processBarcodeDTO(BarcodeScanDTO data) { public void processBarcodeDTO(BarcodeScanDTO data) {
@ -204,6 +221,14 @@ public class ProdRecuperoMaterialeViewModel {
return this; return this;
} }
private void sendOnDataRefreshStarted() {
if (this.mListener != null) mListener.onDataRefreshStarted();
}
private void sendOnDataRefreshEnded() {
if (this.mListener != null) mListener.onDataRefreshEnded();
}
private void sendOnLoadingStarted() { private void sendOnLoadingStarted() {
if (this.mListener != null) mListener.onLoadingStarted(); if (this.mListener != null) mListener.onLoadingStarted();
} }
@ -274,6 +299,10 @@ public class ProdRecuperoMaterialeViewModel {
void onNoLUFound(Runnable onComplete); void onNoLUFound(Runnable onComplete);
void onDataSaved(); void onDataSaved();
void onDataRefreshStarted();
void onDataRefreshEnded();
} }
} }

View File

@ -1,228 +1,93 @@
package it.integry.integrywmsnative.gest.prod_recupero_materiale.rest; package it.integry.integrywmsnative.gest.prod_recupero_materiale.rest;
import com.annimon.stream.Stream; import androidx.annotation.NonNull;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.model.MtbAart; import it.integry.integrywmsnative.core.model.MtbAart;
import it.integry.integrywmsnative.core.rest.consumers.ArticoloRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.ArticoloRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.MaterialiRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers._BaseRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers._BaseRESTConsumer;
import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.core.utility.UtilityDB;
import it.integry.integrywmsnative.core.utility.UtilityString;
import it.integry.integrywmsnative.gest.prod_recupero_materiale.dto.HistoryVersamentoProdULDTO; import it.integry.integrywmsnative.gest.prod_recupero_materiale.dto.HistoryVersamentoProdULDTO;
import it.integry.integrywmsnative.gest.prod_recupero_materiale.dto.HistoryVersamentoProdULRestDTO; import it.integry.integrywmsnative.gest.prod_recupero_materiale.dto.HistoryVersamentoProdULRestDTO;
@Singleton @Singleton
public class ProdRecuperoMaterialeRESTConsumer extends _BaseRESTConsumer { public class ProdRecuperoMaterialeRESTConsumer extends _BaseRESTConsumer {
private final SystemRESTConsumer mSystemRESTConsumer;
private final ArticoloRESTConsumer mArticoloRESTConsumer; private final ArticoloRESTConsumer mArticoloRESTConsumer;
private final MaterialiRESTConsumer mMaterialiRESTConsumer;
public ProdRecuperoMaterialeRESTConsumer(SystemRESTConsumer systemRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer) { @Inject
this.mSystemRESTConsumer = systemRESTConsumer; public ProdRecuperoMaterialeRESTConsumer(ArticoloRESTConsumer articoloRESTConsumer, MaterialiRESTConsumer materialiRESTConsumer) {
this.mMaterialiRESTConsumer = materialiRESTConsumer;
this.mArticoloRESTConsumer = articoloRESTConsumer; this.mArticoloRESTConsumer = articoloRESTConsumer;
} }
public void loadLastULVersate(RunnableArgs<List<HistoryVersamentoProdULDTO>> onComplete, RunnableArgs<Exception> onFailed) { public List<HistoryVersamentoProdULDTO> loadLastULVersateSynchronized() throws Exception {
loadLastULVersate(null, onComplete, onFailed); return loadLastULVersateSynchronized(null);
} }
public void loadLastULVersate(String codJfas, RunnableArgs<List<HistoryVersamentoProdULDTO>> onComplete, RunnableArgs<Exception> onFailed) { public @NonNull List<HistoryVersamentoProdULDTO> loadLastULVersateSynchronized(String codJfas) throws Exception {
var ulList = mMaterialiRESTConsumer.makeSynchronousRetrieveLastVersamentiRequest(codJfas);
String sql = "WITH ul_list AS ( " +
" SELECT jtb_fasi.cod_jfas, " +
" jtb_fasi.descrizione AS descrizione_fase, " +
" mtb_colr.gestione, " +
" mtb_colr.data_collo, " +
" mtb_colr.num_collo, " +
" mtb_colr.ser_collo, " +
" mtb_colr.cod_mart, " +
" mtb_colr.cod_col, " +
" mtb_colr.cod_tagl, " +
" SUM(mtb_colr.qta_col) AS qta_col, " +
" mtb_colr.qta_cnf AS qta_cnf, " +
" SUM(mtb_colr.num_cnf) AS num_cnf, " +
" mtb_colr.partita_mag, " +
" mtb_colr.cod_jcom, " +
" mtb_colr.num_collo_rif, " +
" mtb_colr.data_collo_rif, " +
" mtb_colr.ser_collo_rif, " +
" mtb_colr.gestione_rif, " +
" mtb_colt.segno, " +
" ISNULL(mtb_aart.descrizione_estesa, mtb_aart.descrizione) AS descrizione_art, " +
" mtb_aart.unt_mis, " +
" MAX(datetime_row) AS datetime_row, " +
" mtb_colr.num_ord, " +
" mtb_colr.data_ord, " +
" mtb_colr.gestione as gestione_ord, " +
" mtb_colr.riga_ord, " +
" dtb_ord_steps.hr_num as hr, " +
" CONVERT(INTEGER, ROUND((CAST(dtb_ord_steps.hr_num AS DECIMAL(20, 5)) / " +
" SUM(dtb_ord_steps.hr_num) OVER (PARTITION BY mtb_colr.num_collo)) * 100, " +
" SUM(CASE WHEN dtb_ord_steps.hr_num > 0 then dtb_ord_steps.hr_num else 1 end) OVER (PARTITION BY mtb_colr.num_collo)) * 100, " +
" 0) as percentage_hr " +
" FROM mtb_colr " +
" INNER JOIN mtb_colt ON mtb_colr.num_collo = mtb_colt.num_collo " +
" AND mtb_colr.data_collo = mtb_colt.data_collo " +
" AND mtb_colr.ser_collo = mtb_colt.ser_collo " +
" AND mtb_colr.gestione = mtb_colt.gestione " +
" " + (SettingsManager.iDB().isFlagVersamentoDirettoProduzione() ? "INNER" : "LEFT OUTER") + " join dtb_ord_steps ON dtb_ord_steps.data_ord = mtb_colr.data_ord " +
" AND dtb_ord_steps.gestione = mtb_colr.gestione " +
" AND dtb_ord_steps.num_ord = mtb_colr.num_ord " +
" AND dtb_ord_steps.data_iniz is not null " +
" AND dtb_ord_steps.data_fine is null " +
" INNER JOIN mtb_aart ON mtb_colr.cod_mart = mtb_aart.cod_mart " +
" LEFT OUTER JOIN jtb_fasi ON mtb_colt.cod_jfas = jtb_fasi.cod_jfas " +
" WHERE jtb_fasi.cod_jfas IS NOT NULL " +
(UtilityString.isNullOrEmpty(codJfas) ? "" : " AND jtb_fasi.cod_jfas = " + UtilityDB.valueToString(codJfas)) +
" AND segno = -1 " +
" AND mtb_colr.data_collo > DATEADD(DAY, -5, GETDATE()) " +
" GROUP BY jtb_fasi.cod_jfas, " +
" jtb_fasi.descrizione, " +
" mtb_colr.gestione, " +
" mtb_colr.data_collo, " +
" mtb_colr.num_collo, " +
" mtb_colr.ser_collo, " +
" mtb_colr.qta_cnf, " +
" mtb_colr.cod_mart, " +
" mtb_colr.cod_col, " +
" mtb_colr.cod_tagl, " +
" mtb_colr.ser_collo, " +
" mtb_colr.partita_mag, " +
" mtb_colr.cod_jcom, " +
" mtb_aart.descrizione_estesa, " +
" mtb_aart.descrizione, " +
" mtb_aart.unt_mis, " +
" mtb_colr.num_collo_rif, " +
" mtb_colr.data_collo_rif, " +
" mtb_colr.ser_collo_rif, " +
" mtb_colr.gestione_rif, " +
" mtb_colt.segno, " +
" mtb_colr.num_ord, " +
" mtb_colr.data_ord, " +
" mtb_colr.gestione, " +
" mtb_colr.riga_ord, " +
" dtb_ord_steps.hr_num " +
" HAVING SUM(mtb_colr.qta_col) > 0 " +
"), max_ul AS ( " +
" SELECT " +
" cod_jfas, " +
" descrizione_fase, " +
" gestione, " +
" cod_mart, " +
" cod_col, " +
" cod_tagl, " +
" ser_collo, " +
" partita_mag, " +
" cod_jcom, " +
" descrizione_art, " +
" unt_mis, " +
" num_collo_rif, " +
" data_collo_rif, " +
" ser_collo_rif, " +
" gestione_rif, " +
" segno, " +
" num_ord, " +
" data_ord, " +
" gestione_ord, " +
" riga_ord, " +
" hr, " +
" MAX (datetime_row) as max_datetime_row " +
" FROM ul_list " +
" GROUP BY cod_jfas, " +
" descrizione_fase, " +
" gestione, " +
" cod_mart, " +
" cod_col, " +
" cod_tagl, " +
" ser_collo, " +
" partita_mag, " +
" cod_jcom, " +
" descrizione_art, " +
" unt_mis, " +
" num_collo_rif, " +
" data_collo_rif, " +
" ser_collo_rif, " +
" gestione_rif, " +
" segno, " +
" num_ord, " +
" data_ord, " +
" gestione_ord, " +
" riga_ord, " +
" hr " +
") " +
" " +
"SELECT ul_list.* FROM max_ul " +
"LEFT OUTER JOIN ul_list ON " +
" ISNULL(max_ul.cod_jfas, '') = ISNULL(ul_list.cod_jfas, '') AND " +
" ISNULL(max_ul.descrizione_fase, '') = ISNULL(ul_list.descrizione_fase, '') AND " +
" ISNULL(max_ul.gestione, '') = ISNULL(ul_list.gestione, '') AND " +
" ISNULL(max_ul.cod_mart, '') = ISNULL(ul_list.cod_mart, '') AND " +
" ISNULL(max_ul.cod_col, '') = ISNULL(ul_list.cod_col, '') AND " +
" ISNULL(max_ul.cod_tagl, '') = ISNULL(ul_list.cod_tagl, '') AND " +
" ISNULL(max_ul.ser_collo, '') = ISNULL(ul_list.ser_collo, '') AND " +
" ISNULL(max_ul.partita_mag, '') = ISNULL(ul_list.partita_mag, '') AND " +
" ISNULL(max_ul.cod_jcom, '') = ISNULL(ul_list.cod_jcom, '') AND " +
" ISNULL(max_ul.descrizione_art, '') = ISNULL(ul_list.descrizione_art, '') AND " +
" ISNULL(max_ul.unt_mis, '') = ISNULL(ul_list.unt_mis, '') AND " +
" ISNULL(max_ul.num_collo_rif, '') = ISNULL(ul_list.num_collo_rif, '') AND " +
" ISNULL(max_ul.data_collo_rif, '') = ISNULL(ul_list.data_collo_rif, '') AND " +
" ISNULL(max_ul.ser_collo_rif, '') = ISNULL(ul_list.ser_collo_rif, '') AND " +
" ISNULL(max_ul.gestione_rif, '') = ISNULL(ul_list.gestione_rif, '') AND " +
" ISNULL(max_ul.segno, '') = ISNULL(ul_list.segno, '') AND " +
" ISNULL(max_ul.num_ord, '') = ISNULL(ul_list.num_ord, '') AND " +
" ISNULL(max_ul.data_ord, '') = ISNULL(ul_list.data_ord, '') AND " +
" ISNULL(max_ul.gestione_ord, '') = ISNULL(ul_list.gestione_ord, '') AND " +
" ISNULL(max_ul.riga_ord, '') = ISNULL(ul_list.riga_ord, '') AND " +
" ISNULL(max_ul.hr, '') = ISNULL(ul_list.hr, '') AND " +
" max_ul.max_datetime_row = ul_list.datetime_row";
Type typeOfObjectsList = new TypeToken<ArrayList<HistoryVersamentoProdULRestDTO>>() {
}.getType();
this.mSystemRESTConsumer.<ArrayList<HistoryVersamentoProdULRestDTO>>processSql(sql, typeOfObjectsList, ulList -> {
if (ulList == null) { if (ulList == null) {
onComplete.run(null); return new ArrayList<>();
return;
} }
List<HistoryVersamentoProdULDTO> newUlList = new ArrayList<>(); List<HistoryVersamentoProdULDTO> newUlList = new ArrayList<>();
Stream.of(ulList) Map<HashMap<String, Object>, List<HistoryVersamentoProdULRestDTO>> ulListGrouped = ulList.stream()
.distinctBy(x -> { .collect(Collectors.groupingBy(x -> {
HashMap<String, Object> hashMap = new HashMap<>(); var keyMap = new HashMap<String, Object>();
hashMap.put("gestione", x.getGestione()); keyMap.put("gestione", x.getGestione());
hashMap.put("data_collo", x.getDataCollo()); keyMap.put("data_collo", x.getDataCollo());
hashMap.put("ser_collo", x.getSerCollo()); keyMap.put("ser_collo", x.getSerCollo());
hashMap.put("num_collo", x.getNumCollo()); keyMap.put("num_collo", x.getNumCollo());
hashMap.put("cod_mart", x.getCodMart()); keyMap.put("cod_mart", x.getCodMart());
hashMap.put("gestione_rif", x.getGestioneRif()); keyMap.put("partita_mag", x.getPartitaMag());
hashMap.put("data_collo_rif", x.getDataColloRif()); keyMap.put("gestione_rif", x.getGestioneRif());
hashMap.put("ser_collo_rif", x.getSerColloRif()); keyMap.put("data_collo_rif", x.getDataColloRif());
hashMap.put("num_collo_rif", x.getNumColloRif()); keyMap.put("ser_collo_rif", x.getSerColloRif());
keyMap.put("num_collo_rif", x.getNumColloRif());
return keyMap;
}, Collectors.toList()));
return hashMap; for (HashMap<String, Object> ulKey : ulListGrouped.keySet()) {
}) var matchingUls = ulList.stream().filter(x ->
.forEach(restDTO -> { Objects.equals(x.getGestione(), ulKey.get("gestione")) &&
Objects.equals(x.getDataCollo(), ulKey.get("data_collo")) &&
Objects.equals(x.getSerCollo(), ulKey.get("ser_collo")) &&
Objects.equals(x.getNumCollo(), ulKey.get("num_collo")) &&
Objects.equals(x.getCodMart(), ulKey.get("cod_mart")) &&
Objects.equals(x.getPartitaMag(), ulKey.get("partita_mag")) &&
Objects.equals(x.getGestioneRif(), ulKey.get("gestione_rif")) &&
Objects.equals(x.getDataColloRif(), ulKey.get("data_collo_rif")) &&
Objects.equals(x.getSerColloRif(), ulKey.get("ser_collo_rif")) &&
Objects.equals(x.getNumColloRif(), ulKey.get("num_collo_rif"))
).collect(Collectors.toUnmodifiableList());
List<HistoryVersamentoProdULDTO.OrdineDto> ordineList = ulList.stream() ulKey.put("qta_col", matchingUls.stream().map(HistoryVersamentoProdULRestDTO::getQtaCol)
.filter(x -> x.getNumCollo().equals(restDTO.getNumCollo()) && .reduce(BigDecimal.ZERO, BigDecimal::add));
x.getDataCollo().equals(restDTO.getDataCollo()) && ulKey.put("num_cnf", matchingUls.stream().map(HistoryVersamentoProdULRestDTO::getNumCnf)
x.getSerCollo().equals(restDTO.getSerCollo()) && .reduce(BigDecimal.ZERO, BigDecimal::add));
x.getGestione().equals(restDTO.getGestione()) && }
(x.getRigaOrd() == null || Objects.equals(x.getRigaOrd(), restDTO.getRigaOrd())))
ulListGrouped.forEach((key, value) -> {
var listaOrdini = value.stream()
.filter(x -> x.getDataOrd() != null &&
x.getGestioneOrd() != null &&
x.getNumOrd() != null)
.map(x -> new HistoryVersamentoProdULDTO.OrdineDto() .map(x -> new HistoryVersamentoProdULDTO.OrdineDto()
.setData(x.getDataOrd()) .setData(x.getDataOrd())
.setNumero(x.getNumOrd()) .setNumero(x.getNumOrd())
@ -231,80 +96,337 @@ public class ProdRecuperoMaterialeRESTConsumer extends _BaseRESTConsumer {
.setQtaCol(x.getQtaCol()) .setQtaCol(x.getQtaCol())
.setNumCnf(x.getNumCnf()) .setNumCnf(x.getNumCnf())
.setPercentageHr(x.getPercentageHr())) .setPercentageHr(x.getPercentageHr()))
.collect(Collectors.toList()); .distinct()
.collect(Collectors.toUnmodifiableList());
// BigDecimal qtaColTot = BigDecimal.ZERO; var restData = value.get(0);
// BigDecimal numCnfColTot = BigDecimal.ZERO; var qtaCol = (BigDecimal) key.get("qta_col");
// var numCnf = (BigDecimal) key.get("num_cnf");
// for (HistoryVersamentoProdULDTO.OrdineDto ordine :
// ordineList) {
// qtaColTot = qtaColTot.add(ordine.getQtaCol());
// numCnfColTot = numCnfColTot.add(ordine.getNumCnf());
// }
newUlList.add(new HistoryVersamentoProdULDTO() newUlList.add(new HistoryVersamentoProdULDTO()
.setGestione(restDTO.getGestione()) .setGestione(restData.getGestione())
.setDataCollo(restDTO.getDataCollo()) .setDataCollo(restData.getDataCollo())
.setSerCollo(restDTO.getSerCollo()) .setSerCollo(restData.getSerCollo())
.setNumCollo(restDTO.getNumCollo()) .setNumCollo(restData.getNumCollo())
.setSegno(restDTO.getSegno()) .setSegno(restData.getSegno())
.setCodMart(restDTO.getCodMart()) .setCodMart(restData.getCodMart())
.setCodCol(restDTO.getCodCol()) .setCodCol(restData.getCodCol())
.setCodTagl(restDTO.getCodTagl()) .setCodTagl(restData.getCodTagl())
.setCodJfas(restDTO.getCodJfas()) .setCodJfas(restData.getCodJfas())
.setDescrizioneArt(restDTO.getDescrizioneArt()) .setDescrizioneArt(restData.getDescrizioneArt())
.setDescrizioneFase(restDTO.getDescrizioneFase()) .setDescrizioneFase(restData.getDescrizioneFase())
.setQtaCol(restDTO.getQtaCol()) .setQtaCol(qtaCol)
.setQtaCnf(restDTO.getQtaCnf()) .setQtaCnf(restData.getQtaCnf())
.setNumCnf(restDTO.getNumCnf()) .setNumCnf(numCnf)
.setPartitaMag(restDTO.getPartitaMag()) .setPartitaMag(restData.getPartitaMag())
.setCodJcom(restDTO.getCodJcom()) .setCodJcom(restData.getCodJcom())
.setDatetimeRow(restDTO.getDatetimeRow()) .setDatetimeRow(restData.getDatetimeRow())
.setUntMis(restDTO.getUntMis()) .setUntMis(restData.getUntMis())
.setGestioneRif(restDTO.getGestioneRif()) .setGestioneRif(restData.getGestioneRif())
.setDataColloRif(restDTO.getDataColloRif()) .setDataColloRif(restData.getDataColloRif())
.setSerColloRif(restDTO.getSerColloRif()) .setSerColloRif(restData.getSerColloRif())
.setNumColloRif(restDTO.getNumColloRif()) .setNumColloRif(restData.getNumColloRif())
.setOrdini(ordineList)); .setOrdini(listaOrdini));
}); });
if (!newUlList.isEmpty()) { if (!newUlList.isEmpty()) {
List<String> codMarts = Stream.of(newUlList) List<String> codMarts = newUlList.stream()
.map(HistoryVersamentoProdULDTO::getCodMart) .map(HistoryVersamentoProdULDTO::getCodMart)
.withoutNulls() .filter(Objects::nonNull)
.distinct() .distinct()
.toList(); .collect(Collectors.toUnmodifiableList());
this.mArticoloRESTConsumer.getByCodMarts(codMarts, arts -> { var arts = this.mArticoloRESTConsumer.getByCodMartsSynchronized(codMarts);
if (arts != null && !arts.isEmpty()) { if (arts != null && !arts.isEmpty()) {
for (HistoryVersamentoProdULDTO value : newUlList) { for (HistoryVersamentoProdULDTO value : newUlList) {
MtbAart foundMtbAart = null; MtbAart foundMtbAart = arts.stream()
.filter(x -> x.getCodMart().equalsIgnoreCase(value.getCodMart()))
List<MtbAart> mtbAartStream = Stream.of(arts) .findFirst()
.filter(x -> x.getCodMart().equalsIgnoreCase(value.getCodMart())).toList(); .orElse(null);
if (mtbAartStream != null && !mtbAartStream.isEmpty()) {
foundMtbAart = mtbAartStream.get(0);
}
value.setMtbAart(foundMtbAart); value.setMtbAart(foundMtbAart);
} }
} }
onComplete.run(newUlList); return newUlList;
}, onFailed);
} else { } else {
onComplete.run(newUlList); return newUlList;
}
} }
}, onFailed);
} // public void loadLastULVersate(String codJfas, RunnableArgs<List<HistoryVersamentoProdULDTO>> onComplete, RunnableArgs<Exception> onFailed) {
//
// String sql = "WITH ul_list AS ( " +
// " SELECT jtb_fasi.cod_jfas, " +
// " jtb_fasi.descrizione AS descrizione_fase, " +
// " mtb_colr.gestione, " +
// " mtb_colr.data_collo, " +
// " mtb_colr.num_collo, " +
// " mtb_colr.ser_collo, " +
// " mtb_colr.cod_mart, " +
// " mtb_colr.cod_col, " +
// " mtb_colr.cod_tagl, " +
// " SUM(mtb_colr.qta_col) AS qta_col, " +
// " mtb_colr.qta_cnf AS qta_cnf, " +
// " SUM(mtb_colr.num_cnf) AS num_cnf, " +
// " mtb_colr.partita_mag, " +
// " mtb_colr.cod_jcom, " +
// " mtb_colr.num_collo_rif, " +
// " mtb_colr.data_collo_rif, " +
// " mtb_colr.ser_collo_rif, " +
// " mtb_colr.gestione_rif, " +
// " mtb_colt.segno, " +
// " ISNULL(mtb_aart.descrizione_estesa, mtb_aart.descrizione) AS descrizione_art, " +
// " mtb_aart.unt_mis, " +
// " MAX(datetime_row) AS datetime_row, " +
// " mtb_colr.num_ord, " +
// " mtb_colr.data_ord, " +
// " mtb_colr.gestione as gestione_ord, " +
// " mtb_colr.riga_ord, " +
// " dtb_ord_steps.hr_num as hr, " +
// " CONVERT(INTEGER, ROUND((CAST(dtb_ord_steps.hr_num AS DECIMAL(20, 5)) / " +
// " SUM(dtb_ord_steps.hr_num) OVER (PARTITION BY mtb_colr.num_collo)), " +
// " SUM(CASE WHEN dtb_ord_steps.hr_num > 0 then dtb_ord_steps.hr_num else 1 end) OVER (PARTITION BY mtb_colr.num_collo)) * 100, " +
// " 0) as percentage_hr " +
// " FROM mtb_colr " +
// " INNER JOIN mtb_colt ON mtb_colr.num_collo = mtb_colt.num_collo " +
// " AND mtb_colr.data_collo = mtb_colt.data_collo " +
// " AND mtb_colr.ser_collo = mtb_colt.ser_collo " +
// " AND mtb_colr.gestione = mtb_colt.gestione " +
// " " + (SettingsManager.iDB().isFlagVersamentoDirettoProduzione() ? "INNER" : "LEFT OUTER") + " join dtb_ord_steps ON dtb_ord_steps.data_ord = mtb_colr.data_ord " +
// " AND dtb_ord_steps.gestione = mtb_colr.gestione " +
// " AND dtb_ord_steps.num_ord = mtb_colr.num_ord " +
// " AND dtb_ord_steps.data_iniz is not null " +
// " AND dtb_ord_steps.data_fine is null " +
// " INNER JOIN mtb_aart ON mtb_colr.cod_mart = mtb_aart.cod_mart " +
// " LEFT OUTER JOIN jtb_fasi ON mtb_colt.cod_jfas = jtb_fasi.cod_jfas " +
// " WHERE jtb_fasi.cod_jfas IS NOT NULL " +
// (UtilityString.isNullOrEmpty(codJfas) ? "" : " AND jtb_fasi.cod_jfas = " + UtilityDB.valueToString(codJfas)) +
// " AND segno = -1 " +
// " AND mtb_colr.data_collo > DATEADD(DAY, -5, GETDATE()) " +
// " GROUP BY jtb_fasi.cod_jfas, " +
// " jtb_fasi.descrizione, " +
// " mtb_colr.gestione, " +
// " mtb_colr.data_collo, " +
// " mtb_colr.num_collo, " +
// " mtb_colr.ser_collo, " +
// " mtb_colr.qta_cnf, " +
// " mtb_colr.cod_mart, " +
// " mtb_colr.cod_col, " +
// " mtb_colr.cod_tagl, " +
// " mtb_colr.ser_collo, " +
// " mtb_colr.partita_mag, " +
// " mtb_colr.cod_jcom, " +
// " mtb_aart.descrizione_estesa, " +
// " mtb_aart.descrizione, " +
// " mtb_aart.unt_mis, " +
// " mtb_colr.num_collo_rif, " +
// " mtb_colr.data_collo_rif, " +
// " mtb_colr.ser_collo_rif, " +
// " mtb_colr.gestione_rif, " +
// " mtb_colt.segno, " +
// " mtb_colr.num_ord, " +
// " mtb_colr.data_ord, " +
// " mtb_colr.gestione, " +
// " mtb_colr.riga_ord, " +
// " dtb_ord_steps.hr_num " +
// " HAVING SUM(mtb_colr.qta_col) > 0 " +
// "), max_ul AS ( " +
// " SELECT " +
// " cod_jfas, " +
// " descrizione_fase, " +
// " gestione, " +
// " cod_mart, " +
// " cod_col, " +
// " cod_tagl, " +
// " ser_collo, " +
// " partita_mag, " +
// " cod_jcom, " +
// " descrizione_art, " +
// " unt_mis, " +
// " num_collo_rif, " +
// " data_collo_rif, " +
// " ser_collo_rif, " +
// " gestione_rif, " +
// " segno, " +
// " num_ord, " +
// " data_ord, " +
// " gestione_ord, " +
// " riga_ord, " +
// " hr, " +
// " MAX (datetime_row) as max_datetime_row " +
// " FROM ul_list " +
// " GROUP BY cod_jfas, " +
// " descrizione_fase, " +
// " gestione, " +
// " cod_mart, " +
// " cod_col, " +
// " cod_tagl, " +
// " ser_collo, " +
// " partita_mag, " +
// " cod_jcom, " +
// " descrizione_art, " +
// " unt_mis, " +
// " num_collo_rif, " +
// " data_collo_rif, " +
// " ser_collo_rif, " +
// " gestione_rif, " +
// " segno, " +
// " num_ord, " +
// " data_ord, " +
// " gestione_ord, " +
// " riga_ord, " +
// " hr " +
// ") " +
// " " +
// "SELECT ul_list.* FROM max_ul " +
// "LEFT OUTER JOIN ul_list ON " +
// " ISNULL(max_ul.cod_jfas, '') = ISNULL(ul_list.cod_jfas, '') AND " +
// " ISNULL(max_ul.descrizione_fase, '') = ISNULL(ul_list.descrizione_fase, '') AND " +
// " ISNULL(max_ul.gestione, '') = ISNULL(ul_list.gestione, '') AND " +
// " ISNULL(max_ul.cod_mart, '') = ISNULL(ul_list.cod_mart, '') AND " +
// " ISNULL(max_ul.cod_col, '') = ISNULL(ul_list.cod_col, '') AND " +
// " ISNULL(max_ul.cod_tagl, '') = ISNULL(ul_list.cod_tagl, '') AND " +
// " ISNULL(max_ul.ser_collo, '') = ISNULL(ul_list.ser_collo, '') AND " +
// " ISNULL(max_ul.partita_mag, '') = ISNULL(ul_list.partita_mag, '') AND " +
// " ISNULL(max_ul.cod_jcom, '') = ISNULL(ul_list.cod_jcom, '') AND " +
// " ISNULL(max_ul.descrizione_art, '') = ISNULL(ul_list.descrizione_art, '') AND " +
// " ISNULL(max_ul.unt_mis, '') = ISNULL(ul_list.unt_mis, '') AND " +
// " ISNULL(max_ul.num_collo_rif, '') = ISNULL(ul_list.num_collo_rif, '') AND " +
// " ISNULL(max_ul.data_collo_rif, '') = ISNULL(ul_list.data_collo_rif, '') AND " +
// " ISNULL(max_ul.ser_collo_rif, '') = ISNULL(ul_list.ser_collo_rif, '') AND " +
// " ISNULL(max_ul.gestione_rif, '') = ISNULL(ul_list.gestione_rif, '') AND " +
// " ISNULL(max_ul.segno, '') = ISNULL(ul_list.segno, '') AND " +
// " ISNULL(max_ul.num_ord, '') = ISNULL(ul_list.num_ord, '') AND " +
// " ISNULL(max_ul.data_ord, '') = ISNULL(ul_list.data_ord, '') AND " +
// " ISNULL(max_ul.gestione_ord, '') = ISNULL(ul_list.gestione_ord, '') AND " +
// " ISNULL(max_ul.riga_ord, '') = ISNULL(ul_list.riga_ord, '') AND " +
// " ISNULL(max_ul.hr, '') = ISNULL(ul_list.hr, '') AND " +
// " max_ul.max_datetime_row = ul_list.datetime_row";
//
// Type typeOfObjectsList = new TypeToken<ArrayList<HistoryVersamentoProdULRestDTO>>() {
// }.getType();
// this.mSystemRESTConsumer.<ArrayList<HistoryVersamentoProdULRestDTO>>processSql(sql, typeOfObjectsList, ulList -> {
//
// if (ulList == null) {
// onComplete.run(null);
// return;
// }
//
// List<HistoryVersamentoProdULDTO> newUlList = new ArrayList<>();
//
// Stream.of(ulList)
// .distinctBy(x -> {
// HashMap<String, Object> hashMap = new HashMap<>();
// hashMap.put("gestione", x.getGestione());
// hashMap.put("data_collo", x.getDataCollo());
// hashMap.put("ser_collo", x.getSerCollo());
// hashMap.put("num_collo", x.getNumCollo());
// hashMap.put("cod_mart", x.getCodMart());
// hashMap.put("gestione_rif", x.getGestioneRif());
// hashMap.put("data_collo_rif", x.getDataColloRif());
// hashMap.put("ser_collo_rif", x.getSerColloRif());
// hashMap.put("num_collo_rif", x.getNumColloRif());
//
// return hashMap;
// })
// .forEach(restDTO -> {
//
// List<HistoryVersamentoProdULDTO.OrdineDto> ordineList = ulList.stream()
// .filter(x -> x.getNumCollo().equals(restDTO.getNumCollo()) &&
// x.getDataCollo().equals(restDTO.getDataCollo()) &&
// x.getSerCollo().equals(restDTO.getSerCollo()) &&
// x.getGestione().equals(restDTO.getGestione()) &&
// (x.getRigaOrd() == null || Objects.equals(x.getRigaOrd(), restDTO.getRigaOrd())))
// .map(x -> new HistoryVersamentoProdULDTO.OrdineDto()
// .setData(x.getDataOrd())
// .setNumero(x.getNumOrd())
// .setGestione(x.getGestione())
// .setRigaOrd(x.getRigaOrd())
// .setQtaCol(x.getQtaCol())
// .setNumCnf(x.getNumCnf())
// .setPercentageHr(x.getPercentageHr()))
// .collect(Collectors.toList());
//
//// BigDecimal qtaColTot = BigDecimal.ZERO;
//// BigDecimal numCnfColTot = BigDecimal.ZERO;
////
//// for (HistoryVersamentoProdULDTO.OrdineDto ordine :
//// ordineList) {
//// qtaColTot = qtaColTot.add(ordine.getQtaCol());
//// numCnfColTot = numCnfColTot.add(ordine.getNumCnf());
//// }
//
// newUlList.add(new HistoryVersamentoProdULDTO()
// .setGestione(restDTO.getGestione())
// .setDataCollo(restDTO.getDataCollo())
// .setSerCollo(restDTO.getSerCollo())
// .setNumCollo(restDTO.getNumCollo())
// .setSegno(restDTO.getSegno())
// .setCodMart(restDTO.getCodMart())
// .setCodCol(restDTO.getCodCol())
// .setCodTagl(restDTO.getCodTagl())
// .setCodJfas(restDTO.getCodJfas())
// .setDescrizioneArt(restDTO.getDescrizioneArt())
// .setDescrizioneFase(restDTO.getDescrizioneFase())
// .setQtaCol(restDTO.getQtaCol())
// .setQtaCnf(restDTO.getQtaCnf())
// .setNumCnf(restDTO.getNumCnf())
// .setPartitaMag(restDTO.getPartitaMag())
// .setCodJcom(restDTO.getCodJcom())
// .setDatetimeRow(restDTO.getDatetimeRow())
// .setUntMis(restDTO.getUntMis())
// .setGestioneRif(restDTO.getGestioneRif())
// .setDataColloRif(restDTO.getDataColloRif())
// .setSerColloRif(restDTO.getSerColloRif())
// .setNumColloRif(restDTO.getNumColloRif())
// .setOrdini(ordineList));
//
// });
//
//
// if (!newUlList.isEmpty()) {
// List<String> codMarts = Stream.of(newUlList)
// .map(HistoryVersamentoProdULDTO::getCodMart)
// .withoutNulls()
// .distinct()
// .toList();
//
// this.mArticoloRESTConsumer.getByCodMarts(codMarts, arts -> {
//
// if (arts != null && !arts.isEmpty()) {
// for (HistoryVersamentoProdULDTO value : newUlList) {
//
// MtbAart foundMtbAart = null;
//
// List<MtbAart> mtbAartStream = Stream.of(arts)
// .filter(x -> x.getCodMart().equalsIgnoreCase(value.getCodMart())).toList();
//
// if (mtbAartStream != null && !mtbAartStream.isEmpty()) {
// foundMtbAart = mtbAartStream.get(0);
// }
//
// value.setMtbAart(foundMtbAart);
// }
// }
//
// onComplete.run(newUlList);
//
// }, onFailed);
//
// } else {
// onComplete.run(newUlList);
// }
//
// }, onFailed);
// }
} }

View File

@ -18,13 +18,23 @@
tools:context=".gest.prod_recupero_materiale.ProdRecuperoMaterialeFragment"> tools:context=".gest.prod_recupero_materiale.ProdRecuperoMaterialeFragment">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:background="@android:color/white"
android:id="@+id/prod_recupero_materiale_main_list" android:id="@+id/prod_recupero_materiale_main_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/white"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/prod_recupero_materiale_list_item"/> tools:listitem="@layout/prod_recupero_materiale_list_item" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/empty_view" android:id="@+id/empty_view"