Merge branch 'develop' into feature/LottiScadMult

This commit is contained in:
2025-04-09 16:51:55 +02:00
7 changed files with 120 additions and 29 deletions

View File

@@ -0,0 +1,61 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20250409125908 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
createOrUpdateFunction("relativeWorkDateConsLav", "CREATE FUNCTION [dbo].[relativeWorkDateConsLav] (@StartDate DATE, @DaysToAdd INT)\n" +
"RETURNS DATETIME\n" +
"AS\n" +
"BEGIN\n" +
" DECLARE @CurrentDate DATE = @StartDate;\n" +
" DECLARE @Counter INT = 0;\n" +
" DECLARE @gg INT = 0;\n" +
"\n" +
" IF @DaysToAdd < 0 \n" +
" BEGIN\n" +
" SELECT @gg = -1 -- Per sottrarre giorni\n" +
" SELECT @DaysToAdd = ABS(@DaysToAdd) -- Rendi il numero di giorni positivo\n" +
" END\n" +
" ELSE\n" +
" SELECT @gg = 1 -- Per aggiungere giorni\n" +
"\n" +
" -- Inizia a contare i giorni lavorativi, considerando weekend e festività\n" +
" WHILE @Counter < @DaysToAdd\n" +
" BEGIN\n" +
" SET @CurrentDate = DATEADD(DAY, @gg, @CurrentDate); -- Aggiungi o sottrai un giorno\n" +
"\n" +
" -- Verifica se la data corrente è un sabato, una domenica o una festività\n" +
" IF (DATEPART(WEEKDAY, @CurrentDate) NOT IN (SELECT dayweek.rowId \n" +
" FROM getTableRowByNumber(1, 7) dayweek \n" +
" LEFT OUTER JOIN (SELECT CONVERT(INTEGER, value_string) AS rowid\n" +
" FROM ParseStringIntoArray((SELECT dbo.getGestSetup('DATI_AZIENDA','DOCU_ORD','GG_CONSEGNA')), '|') \n" +
" WHERE LEN(value_string) <> 0) dayLav \n" +
" ON dayweek.rowid = dayLav.rowid\n" +
" WHERE dayLav.rowid IS NULL) OR (SELECT COUNT(*)\n" +
" FROM ParseStringIntoArray((SELECT dbo.getGestSetup('DATI_AZIENDA','DOCU_ORD','GG_CONSEGNA')), '|') \n" +
" WHERE LEN(value_string) <> 0\n" +
" ) = 0)\n" +
" AND @CurrentDate NOT IN (SELECT data FROM jtb_ricorrenze WHERE DATEPART(YEAR, @CurrentDate) = anno) -- Verifica che non sia una festività\n" +
" BEGIN\n" +
" SET @Counter = @Counter + 1; -- Incrementa il contatore se è un giorno lavorativo\n" +
" END\n" +
" END\n" +
"\n" +
" RETURN @CurrentDate; -- Restituisce la data finale\n" +
"END");
}
@Override
public void down() throws Exception {
}
}

View File

@@ -1,7 +1,6 @@
package it.integry.ems.user.service;
import it.integry.annotations.PostContextConstruct;
import it.integry.ems.looper.service.LooperService;
import it.integry.ems.model.IntegryApplicationEnum;
import it.integry.ems.settings.Model.AvailableConnectionsModel;
import it.integry.ems.settings.Model.SettingsModel;
@@ -18,20 +17,18 @@ import it.integry.ems_model.utility.UtilityHash;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
@Service
public class UserCacheService {
@Autowired
private LooperService looperService;
@Autowired
private SettingsModel settingsModel;
@@ -47,14 +44,22 @@ public class UserCacheService {
private final ReentrantLock cacheLock = new ReentrantLock();
boolean canStart = false;
@PostContextConstruct(priority = 10)
private void init() {
if (!UtilityDebug.isDebugExecution())
looperService.add(this::internalCheck, 5 * 60 * 1000, UserCacheService.class.getName()); //Ogni 5 minuti
else this.internalCheck();
if(UtilityDebug.isDebugExecution()) internalCacheUpdate(true);
canStart = !UtilityDebug.isDebugExecution();
}
private void internalCheck() {
@Scheduled(fixedDelay = 5, timeUnit = TimeUnit.MINUTES)
private void internalCacheUpdate() {
internalCacheUpdate(false);
}
private void internalCacheUpdate(boolean forceStart) {
if(!forceStart && !canStart) return;
String historyProfileDb;
try {
historyProfileDb = settingsController.getHistoryProfileDb();
@@ -226,6 +231,6 @@ public class UserCacheService {
this.cachedUsers.clear();
cacheLock.unlock();
this.internalCheck();
this.internalCacheUpdate();
}
}

View File

@@ -55,7 +55,7 @@ public class JwtTokenCacheComponent implements ApplicationListener {
@Scheduled(fixedDelay = 5, timeUnit = TimeUnit.MINUTES)
private void updateCacheScheduled() {
if (!settingsModel.isEnableTokenCaching()) return;
if (!canStart || !settingsModel.isEnableTokenCaching()) return;
List<AvailableConnectionsModel> availableConnectionsModels = settingsModel.getAvailableConnections(true);

View File

@@ -16,6 +16,28 @@ global Boolean postRulesEnabled
global Boolean checkRulesEnabled
global Boolean completeRulesEnabled
rule "completeIdRilPrz"
when
eval(completeRulesEnabled)
$entity : VtbRilPrzt(idRil == null || idRil == 0)
then
Integer idRil = CommonRules.completeIdRilPrz(conn, $entity.getDataRil());
modify ( $entity ) { setIdRil(idRil) }
end
rule "completeDataInsRilPrz"
when
eval(completeRulesEnabled)
$entity : VtbRilPrzt(dataIns == null)
then
modify ( $entity ) {
setDataIns(new Date()),
setCompilatoDa(username),
setDataUltMod(new Date()),
setModificatoDa(username)
}
end
rule "completeDataUltModRilPrz"
no-loop
when

View File

@@ -1548,7 +1548,7 @@ public class ActivityService {
public List<OldUpdateDTO> getOldUpdate() throws Exception {
String sql = "WITH commesse AS (SELECT cod_jcom,\n" +
" jtb_comt.cod_anag,\n" +
" ROW_NUMBER() OVER (PARTITION BY jtb_comt.cod_anag ORDER BY cod_jcom DESC, servers.updated_at DESC, , vtb_clie.flag_stato) AS conta,\n" +
" ROW_NUMBER() OVER (PARTITION BY jtb_comt.cod_anag ORDER BY cod_jcom DESC, servers.updated_at DESC, vtb_clie.flag_stato) AS conta,\n" +
" servers.last_update,\n" +
" gtb_anag.rag_soc\n" +
" FROM jtb_comt\n" +

View File

@@ -2694,12 +2694,21 @@ public class PvmService {
public PvmAuthorizationDTO getAuthorization(String section, String authName) throws Exception {
String username = requestDataDTO.getUsername();
String sql = "SELECT dw_name AS module, dw_colname AS authorization_name, display_only as editable, enabled, visible\n" +
String sql = Query.format(
"SELECT dw_name AS module,\n" +
" dw_colname AS authorization_name,\n" +
" CAST(IIF(enabled IS NULL, 1, IIF(enabled = 'S', 1, 0)) AS BIT) AS enabled,\n" +
" CAST(IIF(visible IS NULL, 1, IIF(visible = 'S', 1, 0)) AS BIT) AS visible,\n" +
" CAST(IIF(required IS NULL, 0, IIF(required = 'S', 1, 0)) AS BIT) AS required\n" +
"FROM stb_edit_limit\n" +
"WHERE gest_name = 'PVM'\n" +
" AND dw_name = " + UtilityDB.valueToString(section) + "\n" +
" AND dw_colname = " + UtilityDB.valueToString(authName) + "\n" +
" AND user_name = " + UtilityDB.valueToString(username) + " ";
" AND dw_name = %s\n" +
" AND dw_colname = %s\n" +
" AND user_name = %s",
section,
authName,
username
);
return UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, PvmAuthorizationDTO.class);

View File

@@ -10,17 +10,15 @@ 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.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityTiming;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoader;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class WMSBarcodeOrdiniAcquistoHandlerService {
@@ -68,25 +66,21 @@ public class WMSBarcodeOrdiniAcquistoHandlerService {
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));
List<AvailableConnectionsModel> availableConnections = settingsModel.getAvailableConnectionsWithoutDuplicatedProfiles(true, historyProfileDb);
for (String dbName : databases.keySet()) {
String profileName = databases.get(dbName).get(0).getProfileName();
for (AvailableConnectionsModel availableConnection : availableConnections) {
String profileName = availableConnection.getProfileName();
Date startDate = new Date();
final int timingId = UtilityTiming.startNewTiming(WMSBarcodeOrdiniAcquistoHandlerService.class.getSimpleName() + " - Barcode (" + profileName + ")");
MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(profileName, false);
boolean gestioneAbilitata = isGestioneAbilitata(multiDBTransactionManager);
if ( gestioneAbilitata ) {
List<BarcodeOrdiniAcquistoDTO> Barcode = getBarcode(multiDBTransactionManager);
barcodeCachedData.put(dbName, Barcode);
barcodeCachedData.put(availableConnection.getDbName(), Barcode);
}
logger.trace(WMSBarcodeOrdiniAcquistoHandlerService.class.getSimpleName() + " - Barcode: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
UtilityTiming.endTiming(timingId, true);
multiDBTransactionManager.closeAll();
}