Migliorie MRP cached data
This commit is contained in:
@@ -1,35 +1,33 @@
|
|||||||
package it.integry.ems.service.production;
|
package it.integry.ems.service.production;
|
||||||
|
|
||||||
import com.annimon.stream.Stream;
|
import com.annimon.stream.Stream;
|
||||||
import it.integry.annotations.PostWebServerConstruct;
|
|
||||||
import it.integry.ems.looper.service.LooperService;
|
|
||||||
import it.integry.ems.service.dto.production.MRPDailyConsumiDTO;
|
import it.integry.ems.service.dto.production.MRPDailyConsumiDTO;
|
||||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||||
import it.integry.ems.settings.Model.SettingsModel;
|
import it.integry.ems.settings.Model.SettingsModel;
|
||||||
import it.integry.ems.settings.SettingsController;
|
import it.integry.ems.settings.SettingsController;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
import it.integry.ems.utility.UtilityDebug;
|
|
||||||
import it.integry.ems_model.service.SetupGest;
|
import it.integry.ems_model.service.SetupGest;
|
||||||
import it.integry.ems_model.utility.*;
|
import it.integry.ems_model.utility.*;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.ContextLoader;
|
import org.springframework.web.context.ContextLoader;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
import java.util.stream.Collectors;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class MrpConsumiHandlerService {
|
public class MrpConsumiHandlerService {
|
||||||
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private LooperService looperService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SettingsModel settingsModel;
|
private SettingsModel settingsModel;
|
||||||
|
|
||||||
@@ -39,69 +37,43 @@ public class MrpConsumiHandlerService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
public SetupGest setupGest;
|
public SetupGest setupGest;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MrpSetupHandlerService mrpSetupHandlerService;
|
||||||
|
|
||||||
private final HashMap<String, HashMap<String, Map<String, List<MRPDailyConsumiDTO>>>> consumiCachedData = new HashMap<>();
|
private final HashMap<String, HashMap<String, Map<String, List<MRPDailyConsumiDTO>>>> consumiCachedData = new HashMap<>();
|
||||||
|
|
||||||
@PostWebServerConstruct
|
|
||||||
public void init() {
|
|
||||||
if ( saveCache() ) {
|
|
||||||
looperService.add(() -> this.internalCacheConsumi(consumiCachedData), (UtilityDebug.isDebugExecution()?5:1) * 60 * 1000, MrpConsumiHandlerService.class.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
@Scheduled(fixedDelay = 1, timeUnit = TimeUnit.MINUTES, initialDelay = 60, zone = "Europe/Rome")
|
||||||
|
private void updateData() throws Exception {
|
||||||
private boolean saveCache(){
|
String historyProfileDb = settingsController.getHistoryProfileDb();
|
||||||
return !UtilityDebug.isDebugExecution() && !UtilityDebug.isIntegryServer() && settingsModel.isPrimaryInstance();
|
final List<AvailableConnectionsModel> availableConnections = settingsModel.getAvailableConnectionsWithoutDuplicatedProfiles(true, historyProfileDb);
|
||||||
}
|
|
||||||
|
|
||||||
public void internalCacheConsumi(HashMap<String, HashMap<String, Map<String, List<MRPDailyConsumiDTO>>>> consumiList) {
|
|
||||||
try {
|
|
||||||
String historyProfileDb = settingsController.getHistoryProfileDb();
|
|
||||||
|
|
||||||
Map<String, List<AvailableConnectionsModel>> databases = settingsModel.getAvailableConnections()
|
|
||||||
.stream()
|
|
||||||
.filter(AvailableConnectionsModel::getInternalDb)
|
|
||||||
.filter(x -> !historyProfileDb.equalsIgnoreCase(x.getProfileName()))
|
|
||||||
.collect(Collectors.groupingBy(AvailableConnectionsModel::getDbName));
|
|
||||||
|
|
||||||
for (String dbName : databases.keySet()) {
|
|
||||||
String profileName = databases.get(dbName).get(0).getProfileName();
|
|
||||||
|
|
||||||
|
|
||||||
loadConsumi(dbName,profileName,consumiList);
|
for (AvailableConnectionsModel connectionModel : availableConnections) {
|
||||||
|
boolean isEnabled = mrpSetupHandlerService.isGestioneAbilitata(connectionModel.getDbName());
|
||||||
|
if(!isEnabled) continue;
|
||||||
|
|
||||||
|
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(connectionModel, false)) {
|
||||||
|
int timingId = UtilityTiming.startNewTiming(MrpConsumiHandlerService.class.getSimpleName() + " (" + connectionModel.getProfileName() + ")");
|
||||||
|
|
||||||
|
internalCacheConsumi(multiDBTransactionManager);
|
||||||
|
|
||||||
|
UtilityTiming.endTiming(timingId, true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex.getMessage(), ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConsumi(String dbName, String profileName, HashMap<String, HashMap<String, Map<String, List<MRPDailyConsumiDTO>>>> consumiList) throws Exception {
|
|
||||||
Date startDate = new Date();
|
|
||||||
MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(profileName, false);
|
|
||||||
|
|
||||||
boolean gestioneAbilitata = isGestioneAbilitata(multiDBTransactionManager);
|
private void internalCacheConsumi(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||||
|
String dbName = multiDBTransactionManager.getPrimaryDatasource().getDbName();
|
||||||
|
|
||||||
if ( gestioneAbilitata ) {
|
Map<String, List<MRPDailyConsumiDTO>> consumi = getConsumi(multiDBTransactionManager);
|
||||||
Map<String, List<MRPDailyConsumiDTO>> consumi = getConsumi(multiDBTransactionManager);
|
HashMap<String, Map<String, List<MRPDailyConsumiDTO>>> section = getSectionConsumiByDBName(consumiCachedData, dbName);
|
||||||
HashMap<String, Map<String, List<MRPDailyConsumiDTO>>> section = getSectionConsumiByDBName(consumiList, dbName);
|
|
||||||
section.clear();
|
|
||||||
section.put(dbName, consumi);
|
|
||||||
|
|
||||||
}
|
section.clear();
|
||||||
logger.trace(MrpConsumiHandlerService.class.getSimpleName() + " - Consumi: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
section.put(dbName, consumi);
|
||||||
|
|
||||||
multiDBTransactionManager.closeAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isGestioneAbilitata(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
|
||||||
String sql =
|
|
||||||
"SELECT CAST(COUNT(*) AS BIT)\n" +
|
|
||||||
"FROM stb_abil\n" +
|
|
||||||
"WHERE cod_opz IN ('WG125') \n" +
|
|
||||||
" AND flag_abil <> 'N'";
|
|
||||||
boolean gestioneAbilitata = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
|
||||||
return gestioneAbilitata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, Map<String, List<MRPDailyConsumiDTO>>> getSectionConsumiByDBName(HashMap<String, HashMap<String, Map<String, List<MRPDailyConsumiDTO>>>> inputData, String profileDb) {
|
private HashMap<String, Map<String, List<MRPDailyConsumiDTO>>> getSectionConsumiByDBName(HashMap<String, HashMap<String, Map<String, List<MRPDailyConsumiDTO>>>> inputData, String profileDb) {
|
||||||
@@ -112,28 +84,28 @@ public class MrpConsumiHandlerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Map<String, List<MRPDailyConsumiDTO>> getConsumi(MultiDBTransactionManager multiDBTransactionManager ) throws Exception {
|
private Map<String, List<MRPDailyConsumiDTO>> getConsumi(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||||
final String gestName = "PVM";
|
final String gestName = "PVM";
|
||||||
final String section = "MRP";
|
final String section = "MRP";
|
||||||
final String keySection = "MEDIA_CONSUMI";
|
final String keySection = "MEDIA_CONSUMI";
|
||||||
String mediaConsumi = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, section,keySection);
|
String mediaConsumi = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, section, keySection);
|
||||||
String listaDepositi = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, section,"LIST_COD_MDEP");
|
String listaDepositi = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, section, "LIST_COD_MDEP");
|
||||||
String whereCondDepo = null;
|
String whereCondDepo = null;
|
||||||
if (!UtilityString.isNullOrEmpty(listaDepositi) )
|
if (!UtilityString.isNullOrEmpty(listaDepositi))
|
||||||
whereCondDepo = String.format("mtb_movi.cod_mdep in ('%s')", listaDepositi.replace(",", "','"));
|
whereCondDepo = String.format("mtb_movi.cod_mdep in ('%s')", listaDepositi.replace(",", "','"));
|
||||||
|
|
||||||
String codDtipMix = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "DTB_DOCT","MOVIMENTAZIONE_OLIO", "COD_DTIP_SCAR");
|
String codDtipMix = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "DTB_DOCT", "MOVIMENTAZIONE_OLIO", "COD_DTIP_SCAR");
|
||||||
|
|
||||||
String sql =
|
String sql =
|
||||||
Query.format(
|
Query.format(
|
||||||
"SELECT mtb_sgrp.cod_mgrp,\n" +
|
"SELECT mtb_sgrp.cod_mgrp,\n" +
|
||||||
"mtb_sgrp.cod_msgr,\n" +
|
"mtb_sgrp.cod_msgr,\n" +
|
||||||
"IsNull(stb_gest_setup_det.value, %s) as tipo_media\n" +
|
"IsNull(stb_gest_setup_det.value, %s) as tipo_media\n" +
|
||||||
"FROM mtb_sgrp \n" +
|
"FROM mtb_sgrp \n" +
|
||||||
"Left outer join stb_gest_setup_det on gest_name = %s and\n" +
|
"Left outer join stb_gest_setup_det on gest_name = %s and\n" +
|
||||||
"section = %s and\n" +
|
"section = %s and\n" +
|
||||||
"key_section = %s and\n" +
|
"key_section = %s and\n" +
|
||||||
"tipo_setup = 'mtb_sgrp' and mtb_sgrp.cod_mgrp + '~'+ mtb_sgrp.cod_msgr = stb_gest_setup_det.val_col_rif ",
|
"tipo_setup = 'mtb_sgrp' and mtb_sgrp.cod_mgrp + '~'+ mtb_sgrp.cod_msgr = stb_gest_setup_det.val_col_rif ",
|
||||||
mediaConsumi, gestName, section, keySection);
|
mediaConsumi, gestName, section, keySection);
|
||||||
|
|
||||||
List<HashMap<String, Object>> sottoGruppi = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
List<HashMap<String, Object>> sottoGruppi = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||||
@@ -143,7 +115,7 @@ public class MrpConsumiHandlerService {
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
List<MRPDailyConsumiDTO> consumiDTO = new ArrayList<>();
|
List<MRPDailyConsumiDTO> consumiDTO = new ArrayList<>();
|
||||||
for (Map.Entry<Object, List<HashMap<String, Object>>> d: tipoMedia ) {
|
for (Map.Entry<Object, List<HashMap<String, Object>>> d : tipoMedia) {
|
||||||
String queryconsumi;
|
String queryconsumi;
|
||||||
if (d.getKey().equals("M")) {
|
if (d.getKey().equals("M")) {
|
||||||
queryconsumi = getQueryConsumiMesili(d.getValue(), d.getKey().toString(), whereCondDepo, codDtipMix);
|
queryconsumi = getQueryConsumiMesili(d.getValue(), d.getKey().toString(), whereCondDepo, codDtipMix);
|
||||||
@@ -169,18 +141,18 @@ public class MrpConsumiHandlerService {
|
|||||||
|
|
||||||
String sql =
|
String sql =
|
||||||
String.format(
|
String.format(
|
||||||
"SELECT periodo.cod_mart,\n" +
|
"SELECT periodo.cod_mart,\n" +
|
||||||
"periodo.finemese AS data,\n" +
|
"periodo.finemese AS data,\n" +
|
||||||
"SUM(ISNULL(qta_scar, 0)) qta,\n" +
|
"SUM(ISNULL(qta_scar, 0)) qta,\n" +
|
||||||
"'%s' as tipo_media\n" +
|
"'%s' as tipo_media\n" +
|
||||||
"FROM (SELECT DISTINCT cod_mart,\n" +
|
"FROM (SELECT DISTINCT cod_mart,\n" +
|
||||||
" EOMONTH(date) AS finemese\n" +
|
" EOMONTH(date) AS finemese\n" +
|
||||||
" FROM [dbo].[stb_dates],\n" +
|
" FROM [dbo].[stb_dates],\n" +
|
||||||
" mtb_aart\n" +
|
" mtb_aart\n" +
|
||||||
" WHERE stb_dates.date BETWEEN %s AND %s AND %s) periodo\n" +
|
" WHERE stb_dates.date BETWEEN %s AND %s AND %s) periodo\n" +
|
||||||
" LEFT OUTER JOIN (" + getQueryMovimenti(dataIniz, dataFine, whereCondDepo, codDtipMix ) + ") mtb_movi ON EOMONTH(data_reg) = periodo.finemese AND periodo.cod_mart = mtb_movi.cod_mart\n " +
|
" LEFT OUTER JOIN (" + getQueryMovimenti(dataIniz, dataFine, whereCondDepo, codDtipMix) + ") mtb_movi ON EOMONTH(data_reg) = periodo.finemese AND periodo.cod_mart = mtb_movi.cod_mart\n " +
|
||||||
"GROUP BY periodo.cod_mart, periodo.finemese\n"+
|
"GROUP BY periodo.cod_mart, periodo.finemese\n" +
|
||||||
"ORDER BY periodo.cod_mart, periodo.finemese desc",
|
"ORDER BY periodo.cod_mart, periodo.finemese desc",
|
||||||
tipoMedia,
|
tipoMedia,
|
||||||
UtilityDB.valueToString(dataIniz),
|
UtilityDB.valueToString(dataIniz),
|
||||||
UtilityDB.valueToString(dataFine),
|
UtilityDB.valueToString(dataFine),
|
||||||
@@ -197,28 +169,28 @@ public class MrpConsumiHandlerService {
|
|||||||
dataIniz = dataIniz.minusDays(1);
|
dataIniz = dataIniz.minusDays(1);
|
||||||
String sql =
|
String sql =
|
||||||
String.format(
|
String.format(
|
||||||
"SELECT tempo.cod_mart,\n" +
|
"SELECT tempo.cod_mart,\n" +
|
||||||
" tempo.data,\n" +
|
" tempo.data,\n" +
|
||||||
" SUM(ISNULL(mtb_movi.qta_scar, 0)) AS qta,\n" +
|
" SUM(ISNULL(mtb_movi.qta_scar, 0)) AS qta,\n" +
|
||||||
" '%s' AS tipo_media\n" +
|
" '%s' AS tipo_media\n" +
|
||||||
"FROM (SELECT mtb_aart.cod_mart,\n" +
|
"FROM (SELECT mtb_aart.cod_mart,\n" +
|
||||||
" DATEPART(ISO_WEEK, date) settimana,\n" +
|
" DATEPART(ISO_WEEK, date) settimana,\n" +
|
||||||
" MAX(DATEFROMPARTS(YEAR(date), MONTH(date), DAY(date))) AS data,\n" +
|
" MAX(DATEFROMPARTS(YEAR(date), MONTH(date), DAY(date))) AS data,\n" +
|
||||||
" DATEADD(DAY, -6, MAX(DATEFROMPARTS(YEAR(date), MONTH(date), DAY(date)))) AS data_min\n" +
|
" DATEADD(DAY, -6, MAX(DATEFROMPARTS(YEAR(date), MONTH(date), DAY(date)))) AS data_min\n" +
|
||||||
" FROM dbo.stb_dates,\n" +
|
" FROM dbo.stb_dates,\n" +
|
||||||
" mtb_part\n" +
|
" mtb_part\n" +
|
||||||
" INNER JOIN mtb_aart ON mtb_part.cod_mart = mtb_aart.cod_mart\n" +
|
" INNER JOIN mtb_aart ON mtb_part.cod_mart = mtb_aart.cod_mart\n" +
|
||||||
" WHERE stb_dates.date BETWEEN %s AND %s AND \n%s\n" +
|
" WHERE stb_dates.date BETWEEN %s AND %s AND \n%s\n" +
|
||||||
" GROUP BY mtb_aart.cod_mart, DATEPART(ISO_WEEK, date)) tempo\n" +
|
" GROUP BY mtb_aart.cod_mart, DATEPART(ISO_WEEK, date)) tempo\n" +
|
||||||
" LEFT OUTER JOIN (" + getQueryMovimenti(dataIniz, dataFine, whereCondDepo, codDtipMix) + ") mtb_movi ON mtb_movi.data_reg BETWEEN tempo.data_min AND tempo.data\n" +
|
" LEFT OUTER JOIN (" + getQueryMovimenti(dataIniz, dataFine, whereCondDepo, codDtipMix) + ") mtb_movi ON mtb_movi.data_reg BETWEEN tempo.data_min AND tempo.data\n" +
|
||||||
" AND mtb_movi.cod_mart = tempo.cod_mart \n" +
|
" AND mtb_movi.cod_mart = tempo.cod_mart \n" +
|
||||||
" LEFT OUTER JOIN dtb_tipi ON mtb_movi.cod_dtip = dtb_tipi.cod_dtip \n" +
|
" LEFT OUTER JOIN dtb_tipi ON mtb_movi.cod_dtip = dtb_tipi.cod_dtip \n" +
|
||||||
"GROUP BY tempo.cod_mart, tempo.data\n" +
|
"GROUP BY tempo.cod_mart, tempo.data\n" +
|
||||||
"ORDER BY tempo.cod_mart, tempo.data DESC \n",
|
"ORDER BY tempo.cod_mart, tempo.data DESC \n",
|
||||||
tipoMedia,
|
tipoMedia,
|
||||||
UtilityDB.valueToString(dataIniz),
|
UtilityDB.valueToString(dataIniz),
|
||||||
UtilityDB.valueToString(dataFine),
|
UtilityDB.valueToString(dataFine),
|
||||||
whereCond );
|
whereCond);
|
||||||
|
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
@@ -237,13 +209,14 @@ public class MrpConsumiHandlerService {
|
|||||||
|
|
||||||
return whereCond;
|
return whereCond;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<MRPDailyConsumiDTO>> getConsumi() throws Exception {
|
public Map<String, List<MRPDailyConsumiDTO>> getConsumi() throws Exception {
|
||||||
MultiDBTransactionManager multiDBTransactionManager = ContextLoader.getCurrentWebApplicationContext().getBean(MultiDBTransactionManager.class);
|
MultiDBTransactionManager multiDBTransactionManager = ContextLoader.getCurrentWebApplicationContext().getBean(MultiDBTransactionManager.class);
|
||||||
|
String dbName = multiDBTransactionManager.getPrimaryDatasource().getDbName();
|
||||||
|
|
||||||
if (!saveCache()) {
|
if (!mrpSetupHandlerService.isGestioneAbilitata(dbName)) {
|
||||||
return getConsumi(multiDBTransactionManager);
|
return getConsumi(multiDBTransactionManager);
|
||||||
} else {
|
} else {
|
||||||
String dbName = multiDBTransactionManager.getPrimaryDatasource().getDbName();
|
|
||||||
Map<String, List<MRPDailyConsumiDTO>> consumiList = getSectionConsumiByDBName(consumiCachedData, dbName).get(dbName);
|
Map<String, List<MRPDailyConsumiDTO>> consumiList = getSectionConsumiByDBName(consumiCachedData, dbName).get(dbName);
|
||||||
if (consumiList == null)
|
if (consumiList == null)
|
||||||
return getConsumi(multiDBTransactionManager);
|
return getConsumi(multiDBTransactionManager);
|
||||||
@@ -251,12 +224,12 @@ public class MrpConsumiHandlerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getQueryMovimenti(LocalDate dataInizio, LocalDate dataFine, String whereCondDepo, String codDtipMix ){
|
private String getQueryMovimenti(LocalDate dataInizio, LocalDate dataFine, String whereCondDepo, String codDtipMix) {
|
||||||
String whereCondTipiDoc = "";
|
String whereCondTipiDoc = "";
|
||||||
if (!UtilityString.isNullOrEmpty(codDtipMix)) {
|
if (!UtilityString.isNullOrEmpty(codDtipMix)) {
|
||||||
whereCondTipiDoc =
|
whereCondTipiDoc =
|
||||||
" AND dtb_tipi.flag_gestione_speciale = 0\n" +
|
" AND dtb_tipi.flag_gestione_speciale = 0\n" +
|
||||||
" AND dtb_tipi.cod_dtip NOT IN (SELECT value_string from dbo.ParseStringIntoArray ('" + codDtipMix + "', '|')) " ;
|
" AND dtb_tipi.cod_dtip NOT IN (SELECT value_string from dbo.ParseStringIntoArray ('" + codDtipMix + "', '|')) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
String queryMovimenti =
|
String queryMovimenti =
|
||||||
@@ -266,21 +239,21 @@ public class MrpConsumiHandlerService {
|
|||||||
"WHERE dtb_tipi.flag_cons_consumi = 1 \n" +
|
"WHERE dtb_tipi.flag_cons_consumi = 1 \n" +
|
||||||
" AND qta_scar <> 0 \n" +
|
" AND qta_scar <> 0 \n" +
|
||||||
" AND data_reg BETWEEN '[dataIniz]' AND '[dataFine]'\n" +
|
" AND data_reg BETWEEN '[dataIniz]' AND '[dataFine]'\n" +
|
||||||
(whereCondDepo!=null?"AND " + whereCondDepo + " \n":"") +
|
(whereCondDepo != null ? "AND " + whereCondDepo + " \n" : "") +
|
||||||
whereCondTipiDoc;
|
whereCondTipiDoc;
|
||||||
|
|
||||||
if (!UtilityString.isNullOrEmpty(codDtipMix)){
|
if (!UtilityString.isNullOrEmpty(codDtipMix)) {
|
||||||
queryMovimenti =
|
queryMovimenti =
|
||||||
queryMovimenti +
|
queryMovimenti +
|
||||||
"UNION ALL\n" +
|
"UNION ALL\n" +
|
||||||
"SELECT cod_mart, qta_scar, lvw_movimentiposture.cod_dtip, data_reg\n" +
|
"SELECT cod_mart, qta_scar, lvw_movimentiposture.cod_dtip, data_reg\n" +
|
||||||
"FROM lvw_movimentiposture\n" +
|
"FROM lvw_movimentiposture\n" +
|
||||||
" INNER JOIN dtb_tipi ON lvw_movimentiposture.cod_dtip = dtb_tipi.cod_dtip\n" +
|
" INNER JOIN dtb_tipi ON lvw_movimentiposture.cod_dtip = dtb_tipi.cod_dtip\n" +
|
||||||
"WHERE (dtb_tipi.flag_gestione_speciale = 1 OR (dtb_tipi.gestione = 'L' AND\n" +
|
"WHERE (dtb_tipi.flag_gestione_speciale = 1 OR (dtb_tipi.gestione = 'L' AND\n" +
|
||||||
" (dtb_tipi.segno_qta_car < 0 OR dtb_tipi.segno_qta_scar <> 0) AND\n" +
|
" (dtb_tipi.segno_qta_car < 0 OR dtb_tipi.segno_qta_scar <> 0) AND\n" +
|
||||||
" dtb_tipi.flag_gestione_speciale = 0)) AND \n" +
|
" dtb_tipi.flag_gestione_speciale = 0)) AND \n" +
|
||||||
" data_reg BETWEEN '[dataIniz]' AND '[dataFine]'" +
|
" data_reg BETWEEN '[dataIniz]' AND '[dataFine]'" +
|
||||||
(whereCondDepo!=null?"AND " + whereCondDepo.replace("mtb_movi", "lvw_movimentiposture") + " \n":"");
|
(whereCondDepo != null ? "AND " + whereCondDepo.replace("mtb_movi", "lvw_movimentiposture") + " \n" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
queryMovimenti =
|
queryMovimenti =
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import it.integry.ems.settings.Model.SettingsModel;
|
|||||||
import it.integry.ems.settings.SettingsController;
|
import it.integry.ems.settings.SettingsController;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
|
import it.integry.ems.utility.UtilityDebug;
|
||||||
import it.integry.ems_model.service.SetupGest;
|
import it.integry.ems_model.service.SetupGest;
|
||||||
import it.integry.ems_model.utility.Query;
|
import it.integry.ems_model.utility.Query;
|
||||||
import it.integry.ems_model.utility.UtilityDB;
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
@@ -37,18 +38,15 @@ public class MrpSetupHandlerService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
public SetupGest setupGest;
|
public SetupGest setupGest;
|
||||||
|
|
||||||
private final HashMap<String, HashMap<String, List<MRPDailySetupSottogruppiDTO>>> setupSottogruppiCachedData = new HashMap<>();
|
|
||||||
|
|
||||||
private final HashMap<String, HashMap<String, List<MRPDailySetupGruppiDTO>>> setupGruppiCachedData = new HashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
private boolean canBeExecuted = false;
|
private boolean canBeExecuted = false;
|
||||||
private final HashMap<String, Boolean> executionPermission = new HashMap<>();
|
private final HashMap<String, Boolean> executionPermission = new HashMap<>();
|
||||||
|
|
||||||
|
private final HashMap<String, HashMap<String, List<MRPDailySetupSottogruppiDTO>>> setupSottogruppiCachedData = new HashMap<>();
|
||||||
|
private final HashMap<String, HashMap<String, List<MRPDailySetupGruppiDTO>>> setupGruppiCachedData = new HashMap<>();
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 1, timeUnit = TimeUnit.HOURS, zone = "Europe/Rome")
|
@Scheduled(fixedDelay = 1, timeUnit = TimeUnit.HOURS, zone = "Europe/Rome")
|
||||||
private void refreshCronPermission() throws Exception {
|
private void refreshCronPermission() throws Exception {
|
||||||
canBeExecuted = true;
|
canBeExecuted = !UtilityDebug.isDebugExecution() && settingsModel.isPrimaryInstance() && !UtilityDebug.isIntegryServer();
|
||||||
// canBeExecuted = !UtilityDebug.isDebugExecution() && settingsModel.isPrimaryInstance() && !UtilityDebug.isIntegryServer();
|
|
||||||
if (!canBeExecuted) return;
|
if (!canBeExecuted) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -76,7 +74,7 @@ public class MrpSetupHandlerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGestioneAbilitata(String dbName) {
|
public boolean isGestioneAbilitata(String dbName) {
|
||||||
if(!canBeExecuted) return false;
|
if (!canBeExecuted) return false;
|
||||||
return executionPermission.getOrDefault(dbName, false);
|
return executionPermission.getOrDefault(dbName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,16 +88,14 @@ public class MrpSetupHandlerService {
|
|||||||
|
|
||||||
|
|
||||||
for (AvailableConnectionsModel connectionModel : availableConnections) {
|
for (AvailableConnectionsModel connectionModel : availableConnections) {
|
||||||
|
boolean isEnabled = isGestioneAbilitata(connectionModel.getDbName());
|
||||||
|
if (!isEnabled) continue;
|
||||||
|
|
||||||
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(connectionModel, false)) {
|
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(connectionModel, false)) {
|
||||||
|
|
||||||
boolean isEnabled = isGestioneAbilitata(connectionModel.getDbName());
|
|
||||||
|
|
||||||
int timingId = UtilityTiming.startNewTiming(MrpSetupHandlerService.class.getSimpleName() + " (" + connectionModel.getProfileName() + ")");
|
int timingId = UtilityTiming.startNewTiming(MrpSetupHandlerService.class.getSimpleName() + " (" + connectionModel.getProfileName() + ")");
|
||||||
|
|
||||||
if (isEnabled) {
|
internalSottogruppoSetupCache(multiDBTransactionManager);
|
||||||
internalSottogruppoSetupCache(multiDBTransactionManager);
|
internalGruppoSetupCache(multiDBTransactionManager);
|
||||||
internalGruppoSetupCache(multiDBTransactionManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
UtilityTiming.endTiming(timingId, true);
|
UtilityTiming.endTiming(timingId, true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user