diff --git a/ems-engine/src/main/java/it/integry/ems/production/dto/GroupStepDTO.java b/ems-engine/src/main/java/it/integry/ems/production/dto/GroupStepDTO.java index 7c6a08951a..0836d3ec6b 100644 --- a/ems-engine/src/main/java/it/integry/ems/production/dto/GroupStepDTO.java +++ b/ems-engine/src/main/java/it/integry/ems/production/dto/GroupStepDTO.java @@ -4,7 +4,7 @@ import java.util.Date; public class GroupStepDTO { String codJfas; - String idLotto; + Integer idLotto; Date dataLotto; String codJcom; Date dataOrdProd; @@ -24,11 +24,11 @@ public class GroupStepDTO { return this; } - public String getIdLotto() { + public Integer getIdLotto() { return idLotto; } - public GroupStepDTO setIdLotto(String idLotto) { + public GroupStepDTO setIdLotto(Integer idLotto) { this.idLotto = idLotto; return this; } diff --git a/ems-engine/src/main/java/it/integry/ems/production/service/MesProductionServiceV2.java b/ems-engine/src/main/java/it/integry/ems/production/service/MesProductionServiceV2.java index c45a7fbd3a..62d52f345f 100644 --- a/ems-engine/src/main/java/it/integry/ems/production/service/MesProductionServiceV2.java +++ b/ems-engine/src/main/java/it/integry/ems/production/service/MesProductionServiceV2.java @@ -1338,8 +1338,8 @@ public class MesProductionServiceV2 { String sql = Query.format("SELECT dtb_ordr.* from dtb_ordr\n" + " inner join dtb_ordt on dtb_ordr.data_ord = dtb_ordt.data_ord_rif and dtb_ordr.gestione = gestione_rif and dtb_ordr.num_ord = num_ord_rif\n" + - " where dtb_ordt.gestione = {} and dtb_ordt.data_ord = {} and dtb_ordt.num_ord = {} and dtb_ordr.cod_mart = {}",ordine.getGestione(),ordine.getDataOrd(),ordine.getNumOrd(),ordine.getCodProd()); - DtbOrdr oldRow = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(),sql,DtbOrdr.class); + " where dtb_ordt.gestione = {} and dtb_ordt.data_ord = {} and dtb_ordt.num_ord = {} and dtb_ordr.cod_mart = {}", ordine.getGestione(), ordine.getDataOrd(), ordine.getNumOrd(), ordine.getCodProd()); + DtbOrdr oldRow = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, DtbOrdr.class); CreaOrdineProdDTO newOrdDTO = new CreaOrdineProdDTO(); newOrdDTO.setCodAnag(ordine.getCodAnag()) @@ -1351,7 +1351,7 @@ public class MesProductionServiceV2 { .setColliPedana(oldRow.getColliPedana()); ordine = productionService.saveOrdineProd(newOrdDTO); ordine.setOperation(OperationType.SELECT_OBJECT); - entityProcessor.processEntity(ordine,multiDBTransactionManager); + entityProcessor.processEntity(ordine, multiDBTransactionManager); } @@ -1408,16 +1408,16 @@ public class MesProductionServiceV2 { if (UtilityString.isNullOrEmpty(ordine.getPartitaMag()) && scarico.getCodGruppo().equalsIgnoreCase(codMgrpSL) && matchLottoSlToOrdine) { MtbPartitaMag partitaSL = new MtbPartitaMag(); partitaSL.setCodMart(scarico.getCodMart()) - .setPartitaMag(scarico.getPartitaMag()) - .setOperation(OperationType.SELECT_OBJECT); - entityProcessor.processEntity(partitaSL,multiDBTransactionManager); + .setPartitaMag(scarico.getPartitaMag()) + .setOperation(OperationType.SELECT_OBJECT); + entityProcessor.processEntity(partitaSL, multiDBTransactionManager); MtbPartitaMag partitaPf = new MtbPartitaMag(); partitaPf.setCodMart(ordine.getCodProd()) - .setPartitaMag(partitaSL.getPartitaMag()) - .setDataScad(partitaSL.getDataScad()) - .setOperation(OperationType.INSERT_OR_UPDATE); - entityProcessor.processEntity(partitaPf,true,multiDBTransactionManager); + .setPartitaMag(partitaSL.getPartitaMag()) + .setDataScad(partitaSL.getDataScad()) + .setOperation(OperationType.INSERT_OR_UPDATE); + entityProcessor.processEntity(partitaPf, true, multiDBTransactionManager); ordine.setPartitaMag(partitaSL.getPartitaMag()) .setOperation(OperationType.UPDATE); @@ -1452,33 +1452,26 @@ public class MesProductionServiceV2 { throw new MissingDataException("openGroupStep"); } - String whereCond; - - if (UtilityString.isNullOrEmpty(groupStepDTO.getIdLotto())) { - whereCond = Query.format( - "cod_jcom = %s\n" + - " AND data_ord_prod = %s\n" + - " AND num_ord_prod = %s\n" + - " AND cod_prod = %s\n" + - " AND id_lotto IS NULL", - groupStepDTO.getCodJcom(), - groupStepDTO.getDataOrdProd(), - groupStepDTO.getNumOrdProd(), - groupStepDTO.getCodProd() - ); - } else { - whereCond = Query.format( - "id_lotto = %s", - groupStepDTO.getIdLotto() - ); - } - - List ordini = productionOrderDataHandlerService.getOrdiniLavorazione(null, Collections.singletonList(groupStepDTO.getCodJfas()), null, null, null, whereCond); + List ordini = productionOrderDataHandlerService.getOrdiniLavorazione(null, Collections.singletonList(groupStepDTO.getCodJfas()), null, null, null); if (ordini == null) { throw new SQLException("Nessun ordine trovato"); } + if (UtilityString.isNullOrEmpty(groupStepDTO.getIdLotto())) { + ordini = ordini.stream() + .filter(x -> Objects.equals(x.getCodJcom(), groupStepDTO.getCodJcom()) + && Objects.equals(x.getDataOrdProd(), groupStepDTO.getDataOrdProd()) + && Objects.equals(x.getNumOrdProd(), groupStepDTO.getNumOrdProd()) + && Objects.equals(x.getCodProd(), groupStepDTO.getCodProd()) + && x.getIdLotto() == null) + .collect(java.util.stream.Collectors.toList()); + } else { + ordini = ordini.stream() + .filter(x -> Objects.equals(x.getIdLotto(), groupStepDTO.getIdLotto())) + .collect(java.util.stream.Collectors.toList()); + } + List entitiesToSave = new ArrayList<>(); String codJflavDef = setupGest.getSetup("W_PORDI_RC", "GENERA_LOTTO_PROD", "COD_JFLAV_DEF"); @@ -1696,9 +1689,10 @@ public class MesProductionServiceV2 { } RegisterSupervisorDTO supervisorData = getSupervisorPanelData(groupStepDTO.getCodJfas()); - if (supervisorData != null && !UtilityString.isNullOrEmpty(supervisorData.getSupervisorServiceIp())) { + if (supervisorData != null && !UtilityString.isNullOrEmpty(supervisorData.getSupervisorServiceIp())) { String command; + switch (action) { case OPEN: command = "order/start"; @@ -1712,21 +1706,17 @@ public class MesProductionServiceV2 { default: command = null; } - if (command != null) { + if (command != null) { HashMap body = new HashMap<>(); - Integer idLotto = jtbLott != null ? jtbLott.getIdLotto() : Integer.parseInt(groupStepDTO.getIdLotto()); - body.put("idLotto", idLotto); + + body.put("idLotto", jtbLott != null ? jtbLott.getIdLotto() : groupStepDTO.getIdLotto()); body.put("codJfas", groupStepDTO.getCodJfas()); ObjectMapper mapper = new ObjectMapper(); sendCommand(groupStepDTO.getCodJfas(), command, mapper.convertValue(body, JsonNode.class)); } - - } - - } catch (Exception e) { multiDBTransactionManager.rollbackAll(); throw e; diff --git a/ems-engine/src/main/java/it/integry/ems/production/service/ProductionOrderDataHandlerService.java b/ems-engine/src/main/java/it/integry/ems/production/service/ProductionOrderDataHandlerService.java index 23b617b190..52ac8164b8 100644 --- a/ems-engine/src/main/java/it/integry/ems/production/service/ProductionOrderDataHandlerService.java +++ b/ems-engine/src/main/java/it/integry/ems/production/service/ProductionOrderDataHandlerService.java @@ -93,7 +93,7 @@ public class ProductionOrderDataHandlerService { boolean gestioneAbilitata = isMESEnabled(multiDBTransactionManager); if (gestioneAbilitata) { - List ordiniLav = getOrdiniLavorazione(multiDBTransactionManager, onlyInevasi ? "I" : null, null, null, null, null, null); + List ordiniLav = getOrdiniLavorazione(multiDBTransactionManager, onlyInevasi ? "I" : null, null, null, null, null); HashMap> section = getSectionByDBName(orderList, dbName); section.clear(); if (ordiniLav != null) @@ -128,27 +128,19 @@ public class ProductionOrderDataHandlerService { } public List getOrdiniLavorazioneSync(String flagEvaso, List linee, Date startDate, Date endDate, String codAnag) throws Exception { - return this.getOrdiniLavorazioneSync(flagEvaso, linee, startDate, endDate, codAnag, null); - } - - public List getOrdiniLavorazioneSync(String flagEvaso, List linee, Date startDate, Date endDate, String codAnag, String whereCond) throws Exception { MultiDBTransactionManager multiDBTransactionManager = ContextLoader.getCurrentWebApplicationContext().getBean(MultiDBTransactionManager.class); - return getOrdiniLavorazione(multiDBTransactionManager, flagEvaso, linee, startDate, endDate, codAnag, whereCond); + return getOrdiniLavorazione(multiDBTransactionManager, flagEvaso, linee, startDate, endDate, codAnag); } public List getOrdiniLavorazione(String flagEvaso, List linee, Date startDate, Date endDate, String codAnag) throws Exception { - return this.getOrdiniLavorazione(flagEvaso, linee, startDate, endDate, codAnag, null); - } - - public List getOrdiniLavorazione(String flagEvaso, List linee, Date startDate, Date endDate, String codAnag, String whereCond) throws Exception { MultiDBTransactionManager multiDBTransactionManager = ContextLoader.getCurrentWebApplicationContext().getBean(MultiDBTransactionManager.class); - if ( - UtilityDebug.isIntegryServer() || UtilityDebug.isDebugExecution() || - UtilityString.isNullOrEmpty(flagEvaso) - || !flagEvaso.equalsIgnoreCase("I") - || !isMESEnabled(multiDBTransactionManager)) { - return getOrdiniLavorazione(multiDBTransactionManager, flagEvaso, linee, startDate, endDate, codAnag, whereCond); + if (UtilityDebug.isIntegryServer() + || UtilityDebug.isDebugExecution() + || UtilityString.isNullOrEmpty(flagEvaso) + || !flagEvaso.equalsIgnoreCase("I") + || !isMESEnabled(multiDBTransactionManager)) { + return getOrdiniLavorazione(multiDBTransactionManager, flagEvaso, linee, startDate, endDate, codAnag); } else { HashMap>> inputMap = inevasiOrdersCachedData; List ordersList = new ArrayList<>(); @@ -200,8 +192,8 @@ public class ProductionOrderDataHandlerService { .collect(Collectors.toList()); } - private List getOrdiniLavorazione(MultiDBTransactionManager multiDBTransactionManager, String flagEvaso, List linee, Date startDate, Date endDate, String codAnag, String whereCond) throws Exception { - String whereCondFlagEvaso = ""; + private List getOrdiniLavorazione(MultiDBTransactionManager multiDBTransactionManager, String flagEvaso, List linee, Date startDate, Date endDate, String codAnag) throws Exception { + String whereCondFlagEvaso; String whereCondCodJfas = ""; if (startDate == null) { @@ -241,8 +233,7 @@ public class ProductionOrderDataHandlerService { UtilityDB.valueToString(endDate) + "," + UtilityDB.valueToString(flagEvaso) + "," + UtilityDB.valueToString(codAnag) + ")\n" + - "WHERE " + (UtilityString.isNullOrEmpty(whereCond) ? "1 = 1" : whereCond) + "\n" + - " ORDER BY sort"; + "ORDER BY sort"; } else { if (!UtilityString.isNullOrEmpty(flagEvaso)) { @@ -426,7 +417,6 @@ public class ProductionOrderDataHandlerService { " dtb_ord_steps.flag_step_attivo = 'S' " + whereCondFlagEvaso + whereCondCodJfas + - " AND " + (UtilityString.isNullOrEmpty(whereCond) ? "1 = 1" : whereCond) + "\n" + " AND max_step_by_num_fase = max_step" + " GROUP BY dtb_ordr.data_ord, " + " dtb_ordr.num_ord, " +