Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20240312175552 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
createOrUpdateView("MES_MachineStatusByOrder", "CREATE VIEW MES_MachineStatusByOrder AS\n" +
|
||||
"WITH base AS (\n" +
|
||||
" SELECT gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" id_riga,\n" +
|
||||
" data_mov,\n" +
|
||||
" ISNULL(LEAD(data_mov)\n" +
|
||||
" OVER (PARTITION BY cod_cmac, data_ord, num_ord, gestione ORDER BY id_riga),\n" +
|
||||
" DATEADD(MINUTE, 1, data_mov)) AS data_mov_fine,\n" +
|
||||
" cod_cmac,\n" +
|
||||
" CASE WHEN evento <> 'START' THEN 'STOP' ELSE evento END as evento,\n" +
|
||||
" evento AS causale,\n" +
|
||||
" descrizione,\n" +
|
||||
" qta_mov,\n" +
|
||||
" num_fase,\n" +
|
||||
" activity_id\n" +
|
||||
" FROM dtb_ord_macc\n" +
|
||||
"),\n" +
|
||||
"\n" +
|
||||
" statuses AS (\n" +
|
||||
" SELECT cod_cmac,\n" +
|
||||
" id_riga,\n" +
|
||||
" LAG(evento)\n" +
|
||||
" OVER (PARTITION BY cod_cmac, data_ord, num_ord, gestione ORDER BY id_riga) AS prev_evento,\n" +
|
||||
" evento,\n" +
|
||||
" num_ord,\n" +
|
||||
" data_ord,\n" +
|
||||
" gestione,\n" +
|
||||
" data_mov,\n" +
|
||||
" data_mov_fine,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN MAX(id_riga) OVER ( PARTITION BY cod_cmac, data_ord, num_ord, gestione ) = id_riga\n" +
|
||||
" THEN evento END AS last_evento\n" +
|
||||
" FROM base\n" +
|
||||
" WHERE DATEDIFF(MINUTE, data_mov, data_mov_fine) > 0\n" +
|
||||
" ),\n" +
|
||||
" steps AS (\n" +
|
||||
" SELECT data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" gestione,\n" +
|
||||
" MIN(data_iniz) AS data_iniz,\n" +
|
||||
" MAX(ISNULL(data_fine, GETDATE())) AS data_fine,\n" +
|
||||
" cod_jfas\n" +
|
||||
" FROM dtb_ord_steps\n" +
|
||||
" WHERE data_iniz IS NOT NULL\n" +
|
||||
" GROUP BY data_ord, num_ord, gestione, cod_jfas\n" +
|
||||
" ),\n" +
|
||||
" advanced_statuses AS (\n" +
|
||||
" SELECT statuses.cod_cmac,\n" +
|
||||
" statuses.id_riga,\n" +
|
||||
" statuses.prev_evento,\n" +
|
||||
" statuses.evento,\n" +
|
||||
" MAX(last_evento)\n" +
|
||||
" OVER ( PARTITION BY statuses.cod_cmac, statuses.data_ord, statuses.num_ord, statuses.gestione) AS last_evento,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN statuses.evento = 'START' AND ISNULL(statuses.prev_evento, '') <> 'START' THEN 1\n" +
|
||||
" ELSE\n" +
|
||||
" CASE\n" +
|
||||
" WHEN statuses.evento <> 'START' AND ISNULL(statuses.prev_evento, '') = 'START' THEN -1\n" +
|
||||
" ELSE 0 END\n" +
|
||||
" END AS value,\n" +
|
||||
" DATEADD(MINUTE, DATEDIFF(MINUTE, 0, ISNULL(statuses.data_mov, steps.data_iniz)),\n" +
|
||||
" 0) as data_mov,\n" +
|
||||
" DATEADD(MINUTE, DATEDIFF(MINUTE, 0, ISNULL(statuses.data_mov_fine, steps.data_fine)),\n" +
|
||||
" 0) as data_mov_fine,\n" +
|
||||
" statuses.num_ord,\n" +
|
||||
" statuses.data_ord,\n" +
|
||||
" statuses.gestione,\n" +
|
||||
" steps.cod_jfas\n" +
|
||||
" FROM statuses\n" +
|
||||
" INNER JOIN steps ON statuses.num_ord = steps.num_ord\n" +
|
||||
" AND statuses.data_ord = steps.data_ord\n" +
|
||||
" AND statuses.gestione = steps.gestione\n" +
|
||||
" ),\n" +
|
||||
" grouped_events AS (\n" +
|
||||
" SELECT cod_cmac,\n" +
|
||||
" evento,\n" +
|
||||
" value,\n" +
|
||||
" SUM(ABS(value))\n" +
|
||||
" OVER (PARTITION BY cod_cmac, num_ord, data_ord, gestione ORDER BY cod_cmac, num_ord, data_ord, gestione, data_mov\n" +
|
||||
" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS event_groups,\n" +
|
||||
" data_mov,\n" +
|
||||
" data_mov_fine,\n" +
|
||||
" DATEDIFF(SECOND, data_mov, data_mov_fine) AS duration_seconds,\n" +
|
||||
" DATEDIFF(MINUTE, data_mov, data_mov_fine) AS duration_minutes,\n" +
|
||||
" num_ord,\n" +
|
||||
" data_ord,\n" +
|
||||
" gestione,\n" +
|
||||
" cod_jfas\n" +
|
||||
" FROM advanced_statuses\n" +
|
||||
" WHERE DATEDIFF(MINUTE, data_mov, data_mov_fine) > 0\n" +
|
||||
" )\n" +
|
||||
"\n" +
|
||||
"SELECT cod_cmac,\n" +
|
||||
" evento,\n" +
|
||||
" value,\n" +
|
||||
" MIN(data_mov) AS data_mov_iniz,\n" +
|
||||
" MAX(data_mov_fine) AS data_mov_fine,\n" +
|
||||
" SUM(duration_minutes) AS duration_minutes,\n" +
|
||||
" num_ord,\n" +
|
||||
" data_ord,\n" +
|
||||
" gestione,\n" +
|
||||
" cod_jfas\n" +
|
||||
"FROM grouped_events\n" +
|
||||
"group by cod_cmac, evento, value, event_groups, num_ord, data_ord, gestione, cod_jfas");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package it.integry.ems_model.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import com.google.common.base.Objects;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.rules.completing.PurchasesRules;
|
||||
import it.integry.ems_model.annotation.*;
|
||||
@@ -13,6 +12,7 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@@ -357,4 +357,17 @@ public class AtbListData extends EntityBase {
|
||||
ArlListDataAttach arlListDataAttach = new ArlListDataAttach();
|
||||
arlListDataAttach.deleteAllEntities(connection, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AtbListData)) return false;
|
||||
AtbListData that = (AtbListData) o;
|
||||
return Objects.equals(getCodAlis(), that.getCodAlis()) && Objects.equals(getVersione(), that.getVersione()) && Objects.equals(getDataIniz(), that.getDataIniz()) && Objects.equals(getDataInizSellOut(), that.getDataInizSellOut()) && Objects.equals(getDataFine(), that.getDataFine()) && Objects.equals(getDataFineSellOut(), that.getDataFineSellOut()) && Objects.equals(getCodDiviAcq(), that.getCodDiviAcq()) && Objects.equals(getNote(), that.getNote()) && Objects.equals(getCodPromo(), that.getCodPromo()) && Objects.equals(getDataIns(), that.getDataIns()) && Objects.equals(getInseritoDa(), that.getInseritoDa()) && Objects.equals(getDataMod(), that.getDataMod()) && Objects.equals(getModificatoDa(), that.getModificatoDa()) && Objects.equals(getFlagTipoPromo(), that.getFlagTipoPromo()) && Objects.equals(getCodVage(), that.getCodVage()) && Objects.equals(getCodVvet(), that.getCodVvet()) && Objects.equals(getCostoTrasp(), that.getCostoTrasp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getCodAlis(), getVersione(), getDataIniz(), getDataInizSellOut(), getDataFine(), getDataFineSellOut(), getCodDiviAcq(), getNote(), getCodPromo(), getDataIns(), getInseritoDa(), getDataMod(), getModificatoDa(), getFlagTipoPromo(), getCodVage(), getCodVvet(), getCostoTrasp());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,4 +668,6 @@ public class MtbLisaData extends EntityBase {
|
||||
MtbLisaPromo mtbLisaPromo = new MtbLisaPromo();
|
||||
mtbLisaPromo.deleteAllEntities(connection, this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -892,6 +893,7 @@ public class SqlFieldHolder {
|
||||
if (date.equals(EmsRestConstants.DATE_NULL)) {
|
||||
dato = null;
|
||||
} else {
|
||||
date.setTime((date.getTime() / 1000) * 1000);
|
||||
dato = date;
|
||||
}
|
||||
}
|
||||
@@ -908,7 +910,8 @@ public class SqlFieldHolder {
|
||||
if (localTime.equals(LocalTime.MIN)) {
|
||||
dato = null;
|
||||
} else {
|
||||
dato = localTime;
|
||||
dato = localTime
|
||||
.truncatedTo(ChronoUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
else if (obj instanceof LocalDateTime) {
|
||||
@@ -916,7 +919,8 @@ public class SqlFieldHolder {
|
||||
if (localDateTime.equals(LocalDateTime.MIN)) {
|
||||
dato = null;
|
||||
} else {
|
||||
dato = localDateTime;
|
||||
dato = localDateTime
|
||||
.truncatedTo(ChronoUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
else if (obj instanceof Integer) {
|
||||
|
||||
@@ -4,14 +4,15 @@ import com.annimon.stream.Stream;
|
||||
import it.integry.WooCommerce.dto.product.TextTilesBatchUpdateRequest;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.Import.dto.ImportRequestDTO;
|
||||
import it.integry.ems.rules.completing.PurchasesRules;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
import it.integry.ems.utility.UtilityFile;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.db.ResultSetMapper;
|
||||
import it.integry.ems_model.entity.AtbList;
|
||||
import it.integry.ems_model.entity.AtbListLogImport;
|
||||
import it.integry.ems_model.entity.MtbLisaData;
|
||||
import it.integry.ems_model.entity.*;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.types.TypeDbObject;
|
||||
@@ -20,6 +21,8 @@ import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityHashMap;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -45,9 +48,13 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
@Autowired
|
||||
private EntityProcessor entityProcessor;
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
public List<EntityBase> importListino(ImportRequestDTO param, String type, String format) throws Exception {
|
||||
Connection conn = multiDBTransactionManager.getPrimaryConnection();
|
||||
|
||||
List<EntityBase> entityRet = new ArrayList<>();
|
||||
Date dataImport;
|
||||
if (param != null && param.getDataImportazione() != null) {
|
||||
dataImport = param.getDataImportazione();
|
||||
@@ -77,7 +84,6 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
importFileCsv(conn, pathFile, type, format, setup);
|
||||
|
||||
//INSERIMENTO TESTATE
|
||||
List<EntityBase> entityList = new ArrayList<>();
|
||||
String sql =
|
||||
"SELECT DISTINCT "
|
||||
+ "cod_alis, "
|
||||
@@ -89,9 +95,6 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
|
||||
List<AtbList> atbList = new ResultSetMapper()
|
||||
.mapQuerySetToList(conn, sql, AtbList.class, OperationType.INSERT_OR_UPDATE);
|
||||
if (atbList != null) {
|
||||
entityList.addAll(atbList);
|
||||
}
|
||||
|
||||
//INSERIMENTO E AGGIORNAMENTO PREZZI E CANCELLAZIONE
|
||||
/*
|
||||
@@ -215,7 +218,6 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
+ "viewLisa.unt_mis_acq, "
|
||||
+ "viewLisa.qta_cnf, "
|
||||
+ "viewLisa.colli_x_pedane, "
|
||||
+ "viewLisa.prz_ven_sug, "
|
||||
+ "viewLisa.tipo_variazione, "
|
||||
+ "Convert(datetime, " + UtilityDB.valueDateToString(dataOraImport, CommonConstants.DATETIME_FORMAT_YMD) + ") as data_agg_prz, "
|
||||
+ "viewLisa.perc_oneri, "
|
||||
@@ -229,11 +231,11 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
+ " ORDER BY viewLisa.cod_alis, viewLisa.data_iniz ";
|
||||
|
||||
|
||||
|
||||
List<MtbLisaData> righeListino = new ArrayList<>();
|
||||
List<MtbLisaData> mtbLisaData = new ResultSetMapper()
|
||||
.mapQuerySetToList(conn, sql, MtbLisaData.class, OperationType.INSERT);
|
||||
if (mtbLisaData != null) {
|
||||
entityList.addAll(mtbLisaData);
|
||||
righeListino.addAll(mtbLisaData);
|
||||
}
|
||||
|
||||
if (setup.get("IMPORT_VAR_FUTURE").equalsIgnoreCase("S")) {
|
||||
@@ -263,12 +265,12 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
mtbLisaData = new ResultSetMapper()
|
||||
.mapQuerySetToList(conn, sql, MtbLisaData.class, OperationType.INSERT);
|
||||
if (mtbLisaData != null) {
|
||||
entityList.addAll(mtbLisaData);
|
||||
righeListino.addAll(mtbLisaData);
|
||||
}
|
||||
|
||||
List<String> listCond =
|
||||
Stream.of(entityList)
|
||||
.filter(x->((MtbLisaData) x).getQtaCnf() != null )
|
||||
Stream.of(righeListino)
|
||||
.filter(x->x.getQtaCnf() != null )
|
||||
.map(lisa -> {
|
||||
String whereCond =
|
||||
"mtb_lisa.cod_art_for = " + UtilityDB.valueToString(((MtbLisaData) lisa).getCodArtFor()) + " AND " +
|
||||
@@ -288,16 +290,15 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
for(HashMap<String, Object> l: datiLisa) {
|
||||
String codArtForDb = UtilityHashMap.getValueIfExists(l, "cod_art_for");
|
||||
BigDecimal rapConvDb = UtilityHashMap.getValueIfExists(l, "rap_conv");
|
||||
List<EntityBase> list = Stream.of(entityList)
|
||||
.filter(x -> x instanceof MtbLisaData)
|
||||
.filter(x -> ((MtbLisaData) x).getCodArtFor().equalsIgnoreCase(codArtForDb) &&
|
||||
((MtbLisaData) x).getQtaCnf() != null
|
||||
List<MtbLisaData> list = Stream.of(righeListino)
|
||||
.filter(x -> x.getCodArtFor().equalsIgnoreCase(codArtForDb) &&
|
||||
x.getQtaCnf() != null
|
||||
).toList();
|
||||
for (EntityBase e:list) {
|
||||
entityList.remove(e);
|
||||
BigDecimal qtaCnf = ((MtbLisaData) e).getQtaCnf().multiply(rapConvDb);
|
||||
((MtbLisaData) e).setQtaCnf(qtaCnf);
|
||||
entityList.add(e);
|
||||
for (MtbLisaData e:list) {
|
||||
righeListino.remove(e);
|
||||
BigDecimal qtaCnf = e.getQtaCnf().multiply(rapConvDb);
|
||||
e.setQtaCnf(qtaCnf);
|
||||
righeListino.add(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,9 +331,7 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
+ " ORDER BY cod_alis, data_iniz ";
|
||||
|
||||
List<AtbListLogImport> atbListLogImport = new ResultSetMapper().mapQuerySetToList(conn, sql, AtbListLogImport.class, OperationType.INSERT_OR_UPDATE);
|
||||
if (atbListLogImport != null) {
|
||||
entityList.addAll(atbListLogImport);
|
||||
}
|
||||
|
||||
//cancellazione tabella temporanea
|
||||
Boolean existView = UtilityDB.existDatabaseObject(conn, viewName, TypeDbObject.VIEW);
|
||||
|
||||
@@ -343,34 +342,57 @@ public class ImportListiniAcquistoApuliaCarrefourService {
|
||||
psDelete.close();
|
||||
}
|
||||
|
||||
if (entityList.size() > 0) {
|
||||
Stream.of(entityList).filter(x -> x instanceof MtbLisaData)
|
||||
//salvataggio testate listini
|
||||
if ( atbList != null )
|
||||
UtilityEntity.throwEntitiesException(entityProcessor.processEntityList(atbList, multiDBTransactionManager, false));
|
||||
|
||||
if (righeListino != null && righeListino.size() > 0) {
|
||||
//Salvataggio righe
|
||||
Stream.of(righeListino)
|
||||
.forEach(
|
||||
x -> ((MtbLisaData) x)
|
||||
.setPrzVenSug(UtilityBigDecimal.isNull(((MtbLisaData) x).getPrzVenSug(), BigDecimal.ZERO))
|
||||
x -> x
|
||||
.setPrzVenSug(UtilityBigDecimal.isNull(x.getPrzVenSug(), BigDecimal.ZERO))
|
||||
.setPerc1(BigDecimal.ZERO)
|
||||
.setPerc2(BigDecimal.ZERO)
|
||||
.setPerc3(BigDecimal.ZERO)
|
||||
.setPerc4(BigDecimal.ZERO)
|
||||
.setPercOneri(UtilityBigDecimal.isNull(((MtbLisaData) x).getPercOneri(), BigDecimal.ZERO))
|
||||
.setValOneri(UtilityBigDecimal.isNull(((MtbLisaData) x).getValOneri(), BigDecimal.ZERO))
|
||||
.setPercPromo(UtilityBigDecimal.isNull(((MtbLisaData) x).getPercPromo(), BigDecimal.ZERO))
|
||||
.setValPromo(UtilityBigDecimal.isNull(((MtbLisaData) x).getValPromo(), BigDecimal.ZERO))
|
||||
.setPercOneri(UtilityBigDecimal.isNull(x.getPercOneri(), BigDecimal.ZERO))
|
||||
.setValOneri(UtilityBigDecimal.isNull(x.getValOneri(), BigDecimal.ZERO))
|
||||
.setPercPromo(UtilityBigDecimal.isNull(x.getPercPromo(), BigDecimal.ZERO))
|
||||
.setValPromo(UtilityBigDecimal.isNull(x.getValPromo(), BigDecimal.ZERO))
|
||||
);
|
||||
|
||||
int limitArt = 1000;
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
List<List<EntityBase>> list = Stream.of(entityList)
|
||||
.chunkBy(x -> counter.getAndIncrement() / limitArt).toList();
|
||||
List<EntityBase> entityRet = new ArrayList<>();
|
||||
for (List<EntityBase> e : list) {
|
||||
entityRet.addAll(importAnagListiniService.importAnagListinoAcq(e, "V", null, null, false, false));
|
||||
|
||||
List<Map.Entry<AtbListData, List<MtbLisaData>>> listini =
|
||||
Stream.of(righeListino)
|
||||
.groupBy(
|
||||
x -> {
|
||||
AtbListData atbListData =
|
||||
new AtbListData()
|
||||
.setCodAlis(x.getCodAlis())
|
||||
.setDataIniz(x.getDataIniz())
|
||||
.setDataFine(x.getDataFine());
|
||||
atbListData.setOperation(OperationType.INSERT);
|
||||
return atbListData;
|
||||
}
|
||||
).toList();
|
||||
|
||||
|
||||
for (Map.Entry<AtbListData, List<MtbLisaData>> listino : listini) {
|
||||
AtbListData atbListData = listino.getKey();
|
||||
atbListData.setMtbLisaData(listino.getValue());
|
||||
UtilityEntity.throwEntityException(entityProcessor.processEntity(atbListData, multiDBTransactionManager));
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Non ci sono listini da aggiornare");
|
||||
}
|
||||
|
||||
return entityList;
|
||||
if (atbListLogImport != null)
|
||||
UtilityEntity.throwEntitiesException(entityProcessor.processEntityList(atbListLogImport, multiDBTransactionManager, false));
|
||||
|
||||
logger.info("Importazione " + type + " - " + format + " terminata");
|
||||
|
||||
return entityRet;
|
||||
}
|
||||
|
||||
private void importFileCsv(Connection conn, String pathFile, String type, String format, Map<String, String> setup) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user