Aggiornato menu WMS
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good

This commit is contained in:
2025-03-05 16:09:54 +01:00
parent c27fe7fb5a
commit c2ca6f7f1b
4 changed files with 77 additions and 5 deletions

View File

@@ -6,19 +6,23 @@ import it.integry.ems.menu.dto.MenuConfigDTO;
import it.integry.ems.menu.dto.StbMenuDTO;
import it.integry.ems.menu.dto.StbMenuOpzDTO;
import it.integry.ems.menu.dto.StbTipoAziendaDTO;
import it.integry.ems.sync.MultiDBTransaction.Connection;
import it.integry.ems.utility.UtilityDirs;
import it.integry.ems_model.base.EntityPropertyHolder;
import it.integry.ems_model.entity.StbMenu;
import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.utility.Query;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityLocalDate;
import it.integry.ems_model.utility.UtilityQuery;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import it.integry.ems.sync.MultiDBTransaction.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -32,14 +36,73 @@ public class MenuStaticCreator {
String username = "sa";
String password = "sa";
EntityPropertyHolder entityPropertyHolder = new EntityPropertyHolder();
entityPropertyHolder.init();
try (Connection connection = Connection.fromConnection(DriverManager.getConnection(connectionString, username, password))) {
connection.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_UNCOMMITTED);
connection.setAutoCommit(false);
copyWmsMenuFromGenericaConfig(connection, entityPropertyHolder);
createMenu(connection, UtilityDirs.getDevelopmentMenusFolder());
}
}
private static void copyWmsMenuFromGenericaConfig(Connection connection, EntityPropertyHolder entityPropertyHolder) throws SQLException {
final String wmsRootCodOpz = "MM007";
try {
String sql = Query.format("WITH MenuCTE AS (\n" +
" -- Ancoraggio della ricorsione: Seleziona tutte le opzioni di menu di alto livello (che non hanno un cod_parent)\n" +
" SELECT *,\n" +
" 0 AS Livello -- Livello iniziale\n" +
" FROM " + StbMenu.ENTITY + "\n" +
" WHERE cod_opz = {} AND tipo_azienda = 'GENERICA'\n" +
"\n" +
" UNION ALL\n" +
"\n" +
" -- Ricorsione: Seleziona tutte le opzioni di menu figlie\n" +
" SELECT m.*,\n" +
" c.Livello + 1 AS Livello -- Incrementa il livello per il menu figlio\n" +
" FROM " + StbMenu.ENTITY + " m\n" +
" INNER JOIN\n" +
" MenuCTE c ON m.cod_parent = c.cod_opz AND m.tipo_azienda = c.tipo_azienda)\n" +
"-- Seleziona tutti i risultati dalla CTE ricorsiva\n" +
"SELECT *\n" +
"FROM MenuCTE\n" +
"ORDER BY Livello", wmsRootCodOpz);
final List<StbMenu> stbMenus = UtilityDB.executeSimpleQueryDTO(connection, sql, StbMenu.class);
final List<String> idsToDelete = stbMenus.stream().map(StbMenu::getCodOpz)
.collect(Collectors.toList());
String deleteInOtherAziendaTypes = String.format("DELETE FROM " + StbMenu.ENTITY +
" WHERE cod_opz IN (%s) AND tipo_azienda <> 'GENERICA'", UtilityQuery.concatStringFieldsWithSeparator(idsToDelete, ","));
connection.prepareStatement(deleteInOtherAziendaTypes).executeUpdate();
List<String> tipiAzienda = retrieveTipiAzienda(connection);
for (String tipoAzienda : tipiAzienda) {
for (StbMenu stbMenu : stbMenus) {
stbMenu.setTipoAzienda(tipoAzienda);
stbMenu.setOperation(OperationType.INSERT);
stbMenu.manageWithParentConnection(connection, OperationType.INSERT, null, entityPropertyHolder);
}
}
connection.commit();
} catch (Exception e) {
e.printStackTrace();
connection.rollback();
}
}
public static void createMenu(Connection connection, String menuJsonResourceFolder) throws Exception {
ObjectMapper jsonObjectMapper = new ObjectMapper();
@@ -72,4 +135,12 @@ public class MenuStaticCreator {
outputStream.close();
}
private static List<String> retrieveTipiAzienda(Connection connection) throws SQLException {
return UtilityDB.executeSimpleQueryOnlyFirstColumn(connection, "SELECT DISTINCT tipo_azienda\n" +
"FROM stb_menu\n" +
"WHERE tipo_azienda <> 'GENERICA'\n" +
"ORDER BY tipo_azienda");
}
}

View File

@@ -73,7 +73,7 @@ public enum IntegryCustomer {
IntegryCustomerDB.Igood_ShopService),
Ime(IntegryCustomerDB.Ime_ImeTe),
Integry(IntegryCustomerDB.Integry_Studioml),
Integry_Demo(IntegryCustomerDB.IntegryDemo_OFDemo),
Integry_Demo(IntegryCustomerDB.IntegryDemo_OFDemo, IntegryCustomerDB.IntegryDemo_Menu),
Ivr(IntegryCustomerDB.Ivr_Vetta, IntegryCustomerDB.Ivr_Varci),
Lamonarca(IntegryCustomerDB.Lamonarca_Lamonarca),
Lippolis(IntegryCustomerDB.Lippolis_SGSRL),

View File

@@ -100,6 +100,7 @@ public enum IntegryCustomerDB {
Integry_Studioml("studioml"),
IntegryDemo_Menu("menu"),
IntegryDemo_OFDemo("of_demo"),

File diff suppressed because one or more lines are too long