Fix su retrieve degli ultimi versamenti di materiale
This commit is contained in:
parent
c36bc9d8c2
commit
9c72a2a628
@ -4,9 +4,6 @@ import androidx.databinding.BaseObservable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import it.integry.integrywmsnative.core.CommonConst;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityNumber;
|
||||
|
||||
public class BindableFloat extends BaseObservable {
|
||||
private Float value;
|
||||
|
||||
@ -15,10 +12,6 @@ public class BindableFloat extends BaseObservable {
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@ -261,7 +261,7 @@ public class Converters {
|
||||
BigDecimal value = null;
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(s.toString()))
|
||||
value = new BigDecimal(s.toString());
|
||||
value = UtilityNumber.parseBigDecimal(s.toString(), Locale.getDefault());
|
||||
|
||||
observableBigDecimal.set(value);
|
||||
}
|
||||
@ -271,7 +271,7 @@ public class Converters {
|
||||
}
|
||||
|
||||
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)) {
|
||||
view.setText(UtilityNumber.decimalToString(newValue));
|
||||
@ -292,7 +292,7 @@ public class Converters {
|
||||
String newValueString = s.toString().trim();
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(newValueString))
|
||||
value = new BigDecimal(newValueString);
|
||||
value = UtilityNumber.parseBigDecimal(newValueString, Locale.getDefault());
|
||||
|
||||
observableBigDecimal.set(value);
|
||||
}
|
||||
@ -301,7 +301,7 @@ public class Converters {
|
||||
view.addTextChangedListener(watcher);
|
||||
}
|
||||
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)) {
|
||||
view.setText(UtilityNumber.decimalToString(newValue));
|
||||
@ -322,7 +322,7 @@ public class Converters {
|
||||
String newValueString = s.toString().trim();
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(newValueString))
|
||||
value = new BigDecimal(newValueString);
|
||||
value = UtilityNumber.parseBigDecimal(newValueString, Locale.getDefault());
|
||||
|
||||
observableBigDecimal.set(value);
|
||||
}
|
||||
@ -331,7 +331,7 @@ public class Converters {
|
||||
view.addTextChangedListener(watcher);
|
||||
}
|
||||
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)) {
|
||||
view.setText(UtilityNumber.decimalToString(newValue));
|
||||
@ -350,7 +350,8 @@ public class Converters {
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
BigDecimal value = null;
|
||||
if (!UtilityString.isNullOrEmpty(s.toString()))
|
||||
value = new BigDecimal(s.toString());
|
||||
value = UtilityNumber.parseBigDecimal(s.toString(), Locale.getDefault());
|
||||
|
||||
bindableBigDecimal.set(value);
|
||||
}
|
||||
};
|
||||
@ -358,7 +359,7 @@ public class Converters {
|
||||
view.addTextChangedListener(watcher);
|
||||
}
|
||||
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)) {
|
||||
view.setText(UtilityNumber.decimalToString(newValue));
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package it.integry.integrywmsnative.core.rest.consumers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
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.model.materiali.RecuperaMaterialiRequestDTO;
|
||||
import it.integry.integrywmsnative.core.rest.model.materiali.VersaMaterialiRequestDTO;
|
||||
import it.integry.integrywmsnative.gest.prod_recupero_materiale.dto.HistoryVersamentoProdULRestDTO;
|
||||
|
||||
@Singleton
|
||||
public class MaterialiRESTConsumer extends _BaseRESTConsumer {
|
||||
@ -21,6 +23,28 @@ public class MaterialiRESTConsumer extends _BaseRESTConsumer {
|
||||
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 {
|
||||
var materialiRESTConsumerService = restBuilder.getService(MaterialiRESTConsumerService.class);
|
||||
|
||||
|
||||
@ -1,17 +1,26 @@
|
||||
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.materiali.RecuperaMaterialiRequestDTO;
|
||||
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.VersaMaterialiResponseDTO;
|
||||
import it.integry.integrywmsnative.gest.prod_recupero_materiale.dto.HistoryVersamentoProdULRestDTO;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface MaterialiRESTConsumerService {
|
||||
|
||||
@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")
|
||||
Call<ServiceRESTResponse<RecuperaMaterialiResponseDTO>> recupera(@Body RecuperaMaterialiRequestDTO request);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package it.integry.integrywmsnative.core.utility;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
@ -9,7 +10,8 @@ import it.integry.integrywmsnative.core.CommonConst;
|
||||
|
||||
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){
|
||||
if(bigDecimal == null) return "0";
|
||||
@ -23,71 +25,59 @@ public class UtilityNumber {
|
||||
|
||||
public static String decimalToString(BigDecimal bigDecimal, int decimal){
|
||||
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) {
|
||||
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault());
|
||||
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);
|
||||
return decimalToString(BigDecimal.valueOf(floatValue), decimal);
|
||||
}
|
||||
|
||||
public static DecimalFormat getNumberFormatInstance() {
|
||||
|
||||
if(decimalFormatInstance == null) {
|
||||
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault());
|
||||
otherSymbols.setDecimalSeparator('.');
|
||||
otherSymbols.setGroupingSeparator(',');
|
||||
|
||||
decimalFormatInstance = new DecimalFormat();
|
||||
decimalFormatInstance.setMaximumFractionDigits(CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS);
|
||||
decimalFormatInstance.setDecimalFormatSymbols(otherSymbols);
|
||||
decimalFormatInstance.setGroupingUsed(false);
|
||||
public static BigDecimal parseBigDecimal(String value, Locale locale) {
|
||||
if (value == null || value.trim().isEmpty()) return null;
|
||||
try {
|
||||
DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
|
||||
DecimalFormat format = new DecimalFormat();
|
||||
format.setDecimalFormatSymbols(symbols);
|
||||
format.setParseBigDecimal(true);
|
||||
return (BigDecimal) format.parse(value);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decimalFormatInstance;
|
||||
}
|
||||
|
||||
public static int countNumberOfDecimalDigits(Float value) {
|
||||
String text = getNumberFormatInstance().format(Math.abs(value));
|
||||
int integerPlaces = text.indexOf('.');
|
||||
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;
|
||||
|
||||
/**
|
||||
* Parsa una stringa numerica italiana (con virgola come separatore decimale)
|
||||
* e restituisce un BigDecimal
|
||||
*/
|
||||
public static BigDecimal parseItalianBigDecimal(String value) {
|
||||
return parseBigDecimal(value, ITALIAN_LOCALE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,7 +122,13 @@ public class ProdRecuperoMaterialeFragment extends BaseFragment implements ITitl
|
||||
BarcodeManager.removeCallback(mBarcodeScannerInstanceID);
|
||||
}
|
||||
});
|
||||
|
||||
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
|
||||
public void onDataSaved() {
|
||||
this.onLoadingEnded();
|
||||
this.requireActivity().runOnUiThread(() -> {
|
||||
handler.post(() -> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,28 +1,10 @@
|
||||
package it.integry.integrywmsnative.gest.prod_recupero_materiale;
|
||||
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,8 +3,10 @@ package it.integry.integrywmsnative.gest.prod_recupero_materiale;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -32,31 +34,46 @@ public class ProdRecuperoMaterialeViewModel {
|
||||
private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer;
|
||||
private final PrinterRESTConsumer mPrinterRESTConsumer;
|
||||
private final MaterialiRESTConsumer mMaterialiRESTConsumer;
|
||||
private final ExecutorService mExecutorService;
|
||||
|
||||
private final MutableLiveData<List<HistoryVersamentoProdULDTO>> mUlList = new MutableLiveData<>();
|
||||
|
||||
private Listener mListener;
|
||||
|
||||
private String mCodJfas;
|
||||
|
||||
|
||||
@Inject
|
||||
public ProdRecuperoMaterialeViewModel(ProdRecuperoMaterialeRESTConsumer prodRecuperoMaterialeRESTConsumer,
|
||||
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
|
||||
PrinterRESTConsumer printerRESTConsumer,
|
||||
MaterialiRESTConsumer materialiRESTConsumer) {
|
||||
MaterialiRESTConsumer materialiRESTConsumer,
|
||||
ExecutorService executorService) {
|
||||
this.mProdRecuperoMaterialeRESTConsumer = prodRecuperoMaterialeRESTConsumer;
|
||||
this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer;
|
||||
this.mPrinterRESTConsumer = printerRESTConsumer;
|
||||
this.mMaterialiRESTConsumer = materialiRESTConsumer;
|
||||
this.mExecutorService = executorService;
|
||||
}
|
||||
|
||||
public void init(String codJfas) {
|
||||
this.sendOnLoadingStarted();
|
||||
this.mCodJfas = codJfas;
|
||||
}
|
||||
|
||||
mProdRecuperoMaterialeRESTConsumer.loadLastULVersate(codJfas, ulList -> {
|
||||
this.mUlList.postValue(ulList);
|
||||
public void refreshData() {
|
||||
this.sendOnDataRefreshStarted();
|
||||
|
||||
this.sendOnLoadingEnded();
|
||||
}, this::sendError);
|
||||
this.mExecutorService.execute(() -> {
|
||||
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) {
|
||||
@ -204,6 +221,14 @@ public class ProdRecuperoMaterialeViewModel {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void sendOnDataRefreshStarted() {
|
||||
if (this.mListener != null) mListener.onDataRefreshStarted();
|
||||
}
|
||||
|
||||
private void sendOnDataRefreshEnded() {
|
||||
if (this.mListener != null) mListener.onDataRefreshEnded();
|
||||
}
|
||||
|
||||
private void sendOnLoadingStarted() {
|
||||
if (this.mListener != null) mListener.onLoadingStarted();
|
||||
}
|
||||
@ -274,6 +299,10 @@ public class ProdRecuperoMaterialeViewModel {
|
||||
void onNoLUFound(Runnable onComplete);
|
||||
|
||||
void onDataSaved();
|
||||
|
||||
void onDataRefreshStarted();
|
||||
|
||||
void onDataRefreshEnded();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,310 +1,432 @@
|
||||
package it.integry.integrywmsnative.gest.prod_recupero_materiale.rest;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.model.MtbAart;
|
||||
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.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.HistoryVersamentoProdULRestDTO;
|
||||
|
||||
@Singleton
|
||||
public class ProdRecuperoMaterialeRESTConsumer extends _BaseRESTConsumer {
|
||||
|
||||
private final SystemRESTConsumer mSystemRESTConsumer;
|
||||
private final ArticoloRESTConsumer mArticoloRESTConsumer;
|
||||
private final MaterialiRESTConsumer mMaterialiRESTConsumer;
|
||||
|
||||
public ProdRecuperoMaterialeRESTConsumer(SystemRESTConsumer systemRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer) {
|
||||
this.mSystemRESTConsumer = systemRESTConsumer;
|
||||
@Inject
|
||||
public ProdRecuperoMaterialeRESTConsumer(ArticoloRESTConsumer articoloRESTConsumer, MaterialiRESTConsumer materialiRESTConsumer) {
|
||||
this.mMaterialiRESTConsumer = materialiRESTConsumer;
|
||||
this.mArticoloRESTConsumer = articoloRESTConsumer;
|
||||
}
|
||||
|
||||
|
||||
public void loadLastULVersate(RunnableArgs<List<HistoryVersamentoProdULDTO>> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
loadLastULVersate(null, onComplete, onFailed);
|
||||
public List<HistoryVersamentoProdULDTO> loadLastULVersateSynchronized() throws Exception {
|
||||
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";
|
||||
if (ulList == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Type typeOfObjectsList = new TypeToken<ArrayList<HistoryVersamentoProdULRestDTO>>() {
|
||||
}.getType();
|
||||
this.mSystemRESTConsumer.<ArrayList<HistoryVersamentoProdULRestDTO>>processSql(sql, typeOfObjectsList, ulList -> {
|
||||
List<HistoryVersamentoProdULDTO> newUlList = new ArrayList<>();
|
||||
|
||||
if (ulList == null) {
|
||||
onComplete.run(null);
|
||||
return;
|
||||
Map<HashMap<String, Object>, List<HistoryVersamentoProdULRestDTO>> ulListGrouped = ulList.stream()
|
||||
.collect(Collectors.groupingBy(x -> {
|
||||
var keyMap = new HashMap<String, Object>();
|
||||
keyMap.put("gestione", x.getGestione());
|
||||
keyMap.put("data_collo", x.getDataCollo());
|
||||
keyMap.put("ser_collo", x.getSerCollo());
|
||||
keyMap.put("num_collo", x.getNumCollo());
|
||||
keyMap.put("cod_mart", x.getCodMart());
|
||||
keyMap.put("partita_mag", x.getPartitaMag());
|
||||
keyMap.put("gestione_rif", x.getGestioneRif());
|
||||
keyMap.put("data_collo_rif", x.getDataColloRif());
|
||||
keyMap.put("ser_collo_rif", x.getSerColloRif());
|
||||
keyMap.put("num_collo_rif", x.getNumColloRif());
|
||||
return keyMap;
|
||||
}, Collectors.toList()));
|
||||
|
||||
for (HashMap<String, Object> ulKey : ulListGrouped.keySet()) {
|
||||
var matchingUls = ulList.stream().filter(x ->
|
||||
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());
|
||||
|
||||
ulKey.put("qta_col", matchingUls.stream().map(HistoryVersamentoProdULRestDTO::getQtaCol)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
ulKey.put("num_cnf", matchingUls.stream().map(HistoryVersamentoProdULRestDTO::getNumCnf)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
}
|
||||
|
||||
ulListGrouped.forEach((key, value) -> {
|
||||
|
||||
var listaOrdini = value.stream()
|
||||
.filter(x -> x.getDataOrd() != null &&
|
||||
x.getGestioneOrd() != null &&
|
||||
x.getNumOrd() != null)
|
||||
.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()))
|
||||
.distinct()
|
||||
.collect(Collectors.toUnmodifiableList());
|
||||
|
||||
var restData = value.get(0);
|
||||
var qtaCol = (BigDecimal) key.get("qta_col");
|
||||
var numCnf = (BigDecimal) key.get("num_cnf");
|
||||
|
||||
newUlList.add(new HistoryVersamentoProdULDTO()
|
||||
.setGestione(restData.getGestione())
|
||||
.setDataCollo(restData.getDataCollo())
|
||||
.setSerCollo(restData.getSerCollo())
|
||||
.setNumCollo(restData.getNumCollo())
|
||||
.setSegno(restData.getSegno())
|
||||
.setCodMart(restData.getCodMart())
|
||||
.setCodCol(restData.getCodCol())
|
||||
.setCodTagl(restData.getCodTagl())
|
||||
.setCodJfas(restData.getCodJfas())
|
||||
.setDescrizioneArt(restData.getDescrizioneArt())
|
||||
.setDescrizioneFase(restData.getDescrizioneFase())
|
||||
.setQtaCol(qtaCol)
|
||||
.setQtaCnf(restData.getQtaCnf())
|
||||
.setNumCnf(numCnf)
|
||||
.setPartitaMag(restData.getPartitaMag())
|
||||
.setCodJcom(restData.getCodJcom())
|
||||
.setDatetimeRow(restData.getDatetimeRow())
|
||||
.setUntMis(restData.getUntMis())
|
||||
.setGestioneRif(restData.getGestioneRif())
|
||||
.setDataColloRif(restData.getDataColloRif())
|
||||
.setSerColloRif(restData.getSerColloRif())
|
||||
.setNumColloRif(restData.getNumColloRif())
|
||||
.setOrdini(listaOrdini));
|
||||
|
||||
});
|
||||
|
||||
|
||||
if (!newUlList.isEmpty()) {
|
||||
List<String> codMarts = newUlList.stream()
|
||||
.map(HistoryVersamentoProdULDTO::getCodMart)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toUnmodifiableList());
|
||||
|
||||
var arts = this.mArticoloRESTConsumer.getByCodMartsSynchronized(codMarts);
|
||||
|
||||
if (arts != null && !arts.isEmpty()) {
|
||||
for (HistoryVersamentoProdULDTO value : newUlList) {
|
||||
|
||||
MtbAart foundMtbAart = arts.stream()
|
||||
.filter(x -> x.getCodMart().equalsIgnoreCase(value.getCodMart()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
value.setMtbAart(foundMtbAart);
|
||||
}
|
||||
}
|
||||
|
||||
List<HistoryVersamentoProdULDTO> newUlList = new ArrayList<>();
|
||||
return newUlList;
|
||||
|
||||
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 -> {
|
||||
} else {
|
||||
return newUlList;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
// public void loadLastULVersate(String codJfas, RunnableArgs<List<HistoryVersamentoProdULDTO>> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
//
|
||||
// for (HistoryVersamentoProdULDTO.OrdineDto ordine :
|
||||
// ordineList) {
|
||||
// qtaColTot = qtaColTot.add(ordine.getQtaCol());
|
||||
// numCnfColTot = numCnfColTot.add(ordine.getNumCnf());
|
||||
// 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);
|
||||
// }
|
||||
|
||||
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);
|
||||
}
|
||||
// }
|
||||
//
|
||||
// onComplete.run(newUlList);
|
||||
//
|
||||
// }, onFailed);
|
||||
//
|
||||
// } else {
|
||||
// onComplete.run(newUlList);
|
||||
// }
|
||||
//
|
||||
// }, onFailed);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -18,13 +18,23 @@
|
||||
tools:context=".gest.prod_recupero_materiale.ProdRecuperoMaterialeFragment">
|
||||
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:background="@android:color/white"
|
||||
android:id="@+id/prod_recupero_materiale_main_list"
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swiperefresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/prod_recupero_materiale_list_item"/>
|
||||
android:layout_alignParentBottom="true"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/prod_recupero_materiale_main_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/white"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/prod_recupero_materiale_list_item" />
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/empty_view"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user