Fix DocInterniSetup

This commit is contained in:
2024-02-22 13:51:33 +01:00
parent 80333cc27e
commit cc6f8dfa52

View File

@@ -9,6 +9,7 @@ import it.integry.ems.service.EntityProcessor;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems_model.db.ResultSetMapper;
import it.integry.ems_model.service.SetupGest;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityString;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -40,7 +41,7 @@ public class SmartEnterpriseService {
public DocInterniSetupDTO getDocInterniSetup(String username) throws Exception {
DocInterniSetupDTO result = new DocInterniSetupDTO();
result.setTipiDoc(getDocTypes(username));
result.setFornitori(getFornitori());
result.setFornitori(getFornitori(username));
result.setGruppiArt(getArtsGroups());
return result;
@@ -91,7 +92,7 @@ public class SmartEnterpriseService {
docTypes = Stream.of(docTypes).filter(type -> {
if (checkDocType.containsKey(type.getCodDtip())) {
Object users = checkDocType.get(type.getCodDtip());
return !((users instanceof String && users.equals(username))
return ((users instanceof String && users.equals(username))
|| ((users instanceof ArrayList) &&
(((ArrayList<?>) users).contains(username) || ((ArrayList<?>) users).contains(username.toUpperCase()))));
}
@@ -103,51 +104,56 @@ public class SmartEnterpriseService {
return docTypes;
}
public List<FornitoreDTO> getFornitori() throws Exception {
public List<FornitoreDTO> getFornitori(String username) throws Exception {
String sql =
"SELECT atb_list.cod_alis + ' - ' + atb_list.descrizione AS descrizione,\n" +
" anagrafica.cod_anag,\n" +
" anagrafica.cod_vdes,\n" +
" 'F' as tipo_anag,\n" +
" NULL as gestione_anag\n" +
"FROM atb_list,\n" +
" (SELECT cod_alis, cod_anag, CONVERT(VARCHAR(5), NULL) AS cod_vdes\n" +
" FROM atb_forn\n" +
" WHERE cod_alis IS NOT NULL\n" +
" AND flag_stato = 'A'\n" +
" UNION\n" +
" SELECT cod_alis, cod_anag, cod_vdes\n" +
" FROM vtb_dest\n" +
" WHERE cod_alis IS NOT NULL\n" +
" AND flag_attivo = 'S'\n" +
" ) anagrafica\n" +
"WHERE atb_list.flag_attivo = 'S'\n" +
" AND atb_list.cod_alis = anagrafica.cod_alis\n" +
"union\n" +
"SELECT destinazione as descrizione,\n" +
" cod_anag,\n" +
" cod_vdes,\n" +
" 'D' as tipo_anag,\n" +
" gestione_anag\n" +
"FROM (SELECT gtb_anag.rag_soc +\n" +
" ISNULL(' - ' + vtb_dest.destinatario, '') +\n" +
" ISNULL(' - ' + vtb_dest.indirizzo, '') +\n" +
" ISNULL(', ' + vtb_dest.citta, '') AS destinazione,\n" +
" gtb_anag.cod_anag,\n" +
" vtb_dest.cod_vdes,\n" +
" case when gvw_part_iva_infragroup.part_iva is not null and gestione_anag = 'A' THEN 'L' ELSE gestione_anag END as gestione_anag\n" +
" FROM gtb_anag\n" +
" INNER JOIN vtb_dest ON gtb_anag.cod_anag = vtb_dest.cod_anag\n" +
" INNER JOIN (SELECT cod_anag, flag_stato, 'A' as gestione_anag\n" +
" FROM atb_forn \n" +
" UNION\n" +
" SELECT cod_anag, flag_stato, 'V' as gestione_anag\n" +
" FROM vtb_clie\n" +
" ) anagrafiche ON gtb_anag.cod_anag = anagrafiche.cod_anag\n"+
" LEFT OUTER JOIN gvw_part_iva_infragroup ON gtb_anag.part_iva = gvw_part_iva_infragroup.part_iva \n" +
" WHERE vtb_dest.flag_attivo = 'S'\n" +
" AND anagrafiche.flag_stato = 'A'\n" +
" ) destinatari";
" anagrafica.cod_anag,\n" +
" anagrafica.cod_vdes,\n" +
" 'F' AS tipo_anag,\n" +
" NULL AS gestione_anag\n" +
"FROM atb_list,\n" +
" (SELECT cod_alis, cod_anag, CONVERT(VARCHAR(5), NULL) AS cod_vdes\n" +
" FROM atb_forn\n" +
" WHERE cod_alis IS NOT NULL\n" +
" AND flag_stato = 'A'\n" +
" UNION\n" +
" SELECT cod_alis, cod_anag, cod_vdes\n" +
" FROM vtb_dest\n" +
" WHERE cod_alis IS NOT NULL\n" +
" AND flag_attivo = 'S') anagrafica\n" +
"WHERE atb_list.flag_attivo = 'S'\n" +
" AND atb_list.cod_alis = anagrafica.cod_alis\n" +
"UNION\n" +
"SELECT destinazione AS descrizione,\n" +
" cod_anag,\n" +
" cod_vdes,\n" +
" 'D' AS tipo_anag,\n" +
" gestione_anag\n" +
"FROM (SELECT gtb_anag.rag_soc +\n" +
" ISNULL(' - ' + vtb_dest.destinatario, '') +\n" +
" ISNULL(' - ' + vtb_dest.indirizzo, '') +\n" +
" ISNULL(', ' + vtb_dest.citta, '') AS destinazione,\n" +
" gtb_anag.cod_anag,\n" +
" vtb_dest.cod_vdes,\n" +
" CASE\n" +
" WHEN gvw_part_iva_infragroup.part_iva IS NOT NULL AND gestione_anag = 'A' THEN 'L'\n" +
" ELSE gestione_anag END AS gestione_anag\n" +
" FROM gtb_anag\n" +
" INNER JOIN vtb_dest ON gtb_anag.cod_anag = vtb_dest.cod_anag\n" +
" INNER JOIN (SELECT cod_anag, flag_stato, 'A' AS gestione_anag\n" +
" FROM atb_forn\n" +
" UNION\n" +
" SELECT cod_anag, flag_stato, 'V' AS gestione_anag\n" +
" FROM vtb_clie) anagrafiche ON gtb_anag.cod_anag = anagrafiche.cod_anag\n" +
" LEFT OUTER JOIN gvw_part_iva_infragroup ON gtb_anag.part_iva = gvw_part_iva_infragroup.part_iva\n" +
" WHERE vtb_dest.flag_attivo = 'S'\n" +
" AND anagrafiche.flag_stato = 'A') destinatari\n" +
"WHERE NOT EXISTS(SELECT *\n" +
" FROM wtb_depo\n" +
" INNER JOIN mtb_depo ON wtb_depo.cod_mdep = mtb_depo.cod_mdep\n" +
" WHERE wtb_depo.user_name = " + UtilityDB.valueToString(username) + "\n" +
" AND destinatari.cod_anag = mtb_depo.cod_anag\n" +
" AND destinatari.cod_vdes = mtb_depo.cod_vdes)";
PreparedStatement ps = multiDBTransactionManager.getPrimaryDatasource().getConnection().prepareStatement(sql);
ResultSet rs = ps.executeQuery();
ResultSetMapper tipiDocDTOResultSetMapper = new ResultSetMapper();