Merge remote-tracking branch 'origin/develop' into develop
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -14,6 +14,8 @@ public class CRMTransferProspectResponseDTO {
|
||||
private CtbAnag ctbAnag;
|
||||
|
||||
private AnagClieDTO anagClie;
|
||||
private List<VtbDest> vtbDest;
|
||||
private List<VtbCliePersRif> vtbCliePersRif;
|
||||
|
||||
private List<WdtbOrdt> wdtbOrdts = new ArrayList<>();
|
||||
private List<JtbComt> jtbComts = new ArrayList<>();
|
||||
@@ -57,6 +59,24 @@ public class CRMTransferProspectResponseDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<VtbDest> getVtbDest() {
|
||||
return vtbDest;
|
||||
}
|
||||
|
||||
public CRMTransferProspectResponseDTO setVtbDest(List<VtbDest> vtbDest) {
|
||||
this.vtbDest = vtbDest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<VtbCliePersRif> getVtbCliePersRif() {
|
||||
return vtbCliePersRif;
|
||||
}
|
||||
|
||||
public CRMTransferProspectResponseDTO setVtbCliePersRif(List<VtbCliePersRif> vtbCliePersRif) {
|
||||
this.vtbCliePersRif = vtbCliePersRif;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<WdtbOrdt> getWdtbOrdts() {
|
||||
return wdtbOrdts;
|
||||
}
|
||||
@@ -103,8 +123,12 @@ public class CRMTransferProspectResponseDTO {
|
||||
}
|
||||
|
||||
public List<EntityBase> getEntityToProcess() {
|
||||
return getEntityToProcess(true);
|
||||
}
|
||||
|
||||
public List<EntityBase> getEntityToProcess(boolean includeGtbAnag) {
|
||||
List<EntityBase> entities = new ArrayList<>();
|
||||
if (gtbAnag != null) {
|
||||
if (gtbAnag != null && includeGtbAnag) {
|
||||
entities.add(gtbAnag);
|
||||
}
|
||||
|
||||
|
||||
@@ -524,51 +524,29 @@ public class CrmService {
|
||||
}
|
||||
|
||||
public CRMTransferProspectResponseDTO transferProspect(CRMTransferProspectRequestDTO request) throws Exception {
|
||||
Connection conn = multiDBTransactionManager.getPrimaryConnection();
|
||||
CRMTransferProspectResponseDTO transferProspectResponse =
|
||||
CRMUtility.prospectToClie(
|
||||
multiDBTransactionManager.getPrimaryConnection(), request.getCodAnag(), request.getCodPpro()
|
||||
conn , request.getCodAnag(), request.getCodPpro()
|
||||
);
|
||||
|
||||
try {
|
||||
entityProcessor.processEntityList(transferProspectResponse.getEntityToProcess(), multiDBTransactionManager, true);
|
||||
transferProspectResponse.setCodAnag(transferProspectResponse.getGtbAnag().getCodAnag());
|
||||
GtbAnag gtbAnag = transferProspectResponse.getGtbAnag();
|
||||
entityProcessor.processEntity(gtbAnag, multiDBTransactionManager, true);
|
||||
String codAnag = gtbAnag.getCodAnag();
|
||||
transferProspectResponse.setCodAnag(codAnag);
|
||||
|
||||
String sql = Query.format(
|
||||
"SELECT gtb_anag.cod_anag,\n" +
|
||||
" vtb_clie.cod_vtip,\n" +
|
||||
" vtb_clie.cod_vage,\n" +
|
||||
" vtb_clie.flag_stato,\n" +
|
||||
" rag_soc,\n" +
|
||||
" indirizzo,\n" +
|
||||
" cap,\n" +
|
||||
" citta,\n" +
|
||||
" prov,\n" +
|
||||
" nazione,\n" +
|
||||
" telefono,\n" +
|
||||
" fax,\n" +
|
||||
" part_iva,\n" +
|
||||
" cod_fisc,\n" +
|
||||
" gtb_anag.note,\n" +
|
||||
" persona_rif,\n" +
|
||||
" e_mail,\n" +
|
||||
" nome,\n" +
|
||||
" data_ins,\n" +
|
||||
" num_cell,\n" +
|
||||
" e_mail_pec,\n" +
|
||||
" cognome,\n" +
|
||||
" diacod,\n" +
|
||||
" lat,\n" +
|
||||
" lng,\n" +
|
||||
" data_mod\n" +
|
||||
"FROM gtb_anag\n" +
|
||||
" INNER JOIN vtb_clie ON gtb_anag.cod_anag = vtb_clie.cod_anag\n" +
|
||||
"WHERE gtb_anag.cod_anag = %s",
|
||||
transferProspectResponse.getCodAnag()
|
||||
entityProcessor.processEntityList(
|
||||
CRMUtility.addNewClieToOldEntity(transferProspectResponse, codAnag, request.getCodPpro(), conn).getEntityToProcess(false),
|
||||
multiDBTransactionManager, true
|
||||
);
|
||||
|
||||
transferProspectResponse.setAnagClie(UtilityDB.executeSimpleQueryOnlyFirstRowDTO(
|
||||
multiDBTransactionManager.getPrimaryConnection(), sql, AnagClieDTO.class
|
||||
));
|
||||
CRMSyncResponseDTO crmSyncResponse = retrieveClienti(new CRMAnagRequestDTO().setCodAnag(codAnag));
|
||||
if (!crmSyncResponse.getAnagClie().isEmpty()){
|
||||
transferProspectResponse.setAnagClie(crmSyncResponse.getAnagClie().get(0));
|
||||
}
|
||||
transferProspectResponse.setVtbDest(crmSyncResponse.getVtbDest());
|
||||
transferProspectResponse.setVtbCliePersRif(crmSyncResponse.getVtbCliePersRif());
|
||||
|
||||
return transferProspectResponse;
|
||||
} catch (Exception e) {
|
||||
@@ -889,13 +867,13 @@ public class CrmService {
|
||||
|
||||
String sql = "SELECT * FROM ptb_pros WHERE cod_anag IS NULL";
|
||||
if (requestDTO.getFilterDate() != null)
|
||||
sql = UtilityDB.addwhereCond(sql, " AND data_ins >= " + UtilityDB.valueToString(requestDTO.getFilterDate()), false);
|
||||
sql = UtilityDB.addwhereCond(sql, "data_ins >= " + UtilityDB.valueToString(requestDTO.getFilterDate()), false);
|
||||
|
||||
if (requestDTO.getPartitaIva() != null)
|
||||
sql = UtilityDB.addwhereCond(sql, " AND part_iva = " + UtilityDB.valueToString(requestDTO.getPartitaIva()), false);
|
||||
sql = UtilityDB.addwhereCond(sql, "part_iva = " + UtilityDB.valueToString(requestDTO.getPartitaIva()), false);
|
||||
|
||||
if (requestDTO.getCodPpro() != null)
|
||||
sql = UtilityDB.addwhereCond(sql, " AND cod_ppro = " + UtilityDB.valueToString(requestDTO.getCodPpro()), false);
|
||||
sql = UtilityDB.addwhereCond(sql, "cod_ppro = " + UtilityDB.valueToString(requestDTO.getCodPpro()), false);
|
||||
|
||||
taskSyncResponse.setPtbPros(
|
||||
UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, PtbPros.class)
|
||||
@@ -982,6 +960,10 @@ public class CrmService {
|
||||
sql = "SELECT *\n" +
|
||||
"FROM vtb_dest\n" +
|
||||
"WHERE EXISTS(SELECT * FROM vtb_clie WHERE vtb_clie.cod_anag = vtb_dest.cod_anag)";
|
||||
|
||||
if (requestDTO.getCodAnag() != null)
|
||||
sql = UtilityDB.addwhereCond(sql, "cod_anag = " + UtilityDB.valueToString(requestDTO.getCodAnag()), false);
|
||||
|
||||
taskSyncResponse.setVtbDest(
|
||||
UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, VtbDest.class)
|
||||
);
|
||||
@@ -989,6 +971,10 @@ public class CrmService {
|
||||
sql = "SELECT *\n" +
|
||||
"FROM vtb_clie_pers_rif\n" +
|
||||
"WHERE EXISTS(SELECT * FROM vtb_clie WHERE vtb_clie.cod_anag = vtb_clie_pers_rif.cod_anag)";
|
||||
|
||||
if (requestDTO.getCodAnag() != null)
|
||||
sql = UtilityDB.addwhereCond(sql, "cod_anag = " + UtilityDB.valueToString(requestDTO.getCodAnag()), false);
|
||||
|
||||
taskSyncResponse.setVtbCliePersRif(
|
||||
UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, VtbCliePersRif.class)
|
||||
);
|
||||
|
||||
@@ -313,38 +313,13 @@ public class CRMUtility {
|
||||
}
|
||||
|
||||
public static CRMTransferProspectResponseDTO prospectToClie(Connection conn, String codAnag, String codPpro) throws Exception {
|
||||
if (UtilityString.isNullOrEmpty(codAnag))
|
||||
throw new Exception("Codice cliente da generare obbligatorio");
|
||||
|
||||
if (UtilityString.isNullOrEmpty(codPpro))
|
||||
throw new Exception("Codice prospect da trasferire in anagrafica obbligatorio");
|
||||
|
||||
CRMTransferProspectResponseDTO response = new CRMTransferProspectResponseDTO();
|
||||
|
||||
//Verifica esistenza prospect
|
||||
String sql = Query.format(
|
||||
"SELECT CAST(COUNT(*) AS BIT)\n" +
|
||||
"FROM ptb_pros\n" +
|
||||
"WHERE cod_ppro = %s",
|
||||
codPpro
|
||||
);
|
||||
boolean existingCodPpro = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
if (!existingCodPpro)
|
||||
throw new Exception("Codice prospect inesistente (" + codPpro + ")");
|
||||
|
||||
//Verifica esisteza cliente
|
||||
sql = Query.format(
|
||||
"SELECT CAST(COUNT(*) AS BIT)\n" +
|
||||
"FROM gtb_anag\n" +
|
||||
"WHERE cod_anag = %s",
|
||||
codAnag
|
||||
);
|
||||
boolean existingCodAnag = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
if (existingCodAnag)
|
||||
throw new Exception("Codice cliente già esistente (" + codAnag + ")");
|
||||
|
||||
//Verifica esistenza cliente trasformato in prospect
|
||||
sql = Query.format(
|
||||
String sql = Query.format(
|
||||
"SELECT cod_anag\n" +
|
||||
"FROM ptb_pros\n" +
|
||||
"WHERE cod_ppro = %s\n" +
|
||||
@@ -355,10 +330,33 @@ public class CRMUtility {
|
||||
if (!UtilityString.isNullOrEmpty(codAnagInPtbPros))
|
||||
throw new Exception("Codice prospect già trasferito in anagrafica (Codice cliente: " + codAnagInPtbPros + ")");
|
||||
|
||||
//Verifica esistenza prospect
|
||||
sql = Query.format(
|
||||
"SELECT CAST(COUNT(*) AS BIT)\n" +
|
||||
"FROM ptb_pros\n" +
|
||||
"WHERE cod_ppro = %s",
|
||||
codPpro
|
||||
);
|
||||
boolean existingCodPpro = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
if (!existingCodPpro)
|
||||
throw new Exception("Codice prospect inesistente (" + codPpro + ")");
|
||||
|
||||
//Verifica esisteza cliente
|
||||
if (codAnag != null) {
|
||||
sql = Query.format(
|
||||
"SELECT CAST(COUNT(*) AS BIT)\n" +
|
||||
"FROM gtb_anag\n" +
|
||||
"WHERE cod_anag = %s",
|
||||
codAnag
|
||||
);
|
||||
boolean existingCodAnag = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
if (existingCodAnag)
|
||||
throw new Exception("Codice cliente già esistente (" + codAnag + ")");
|
||||
}
|
||||
|
||||
//Acquisizione dati anagrafici
|
||||
sql = Query.format(
|
||||
"SELECT %s AS cod_anag,\n" +
|
||||
" ptb_pros.rag_soc,\n" +
|
||||
"SELECT ptb_pros.rag_soc,\n" +
|
||||
" ptb_pros.indirizzo,\n" +
|
||||
" ptb_pros.cap,\n" +
|
||||
" ptb_pros.citta,\n" +
|
||||
@@ -371,19 +369,16 @@ public class CRMUtility {
|
||||
" ptb_pros.note,\n" +
|
||||
" ptb_pros.e_mail,\n" +
|
||||
" ptb_pros.rag_soc2,\n" +
|
||||
" ptb_pros.persona_rif,\n" +
|
||||
" 'S' AS allegato,\n" +
|
||||
" 'G' AS flag_persona_fg,\n" +
|
||||
" 0 AS classe_merito\n" +
|
||||
" ptb_pros.persona_rif\n" +
|
||||
"FROM ptb_pros\n" +
|
||||
"WHERE cod_ppro = %s",
|
||||
codAnag, codPpro
|
||||
codPpro
|
||||
);
|
||||
GtbAnag gtbAnag = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(conn, sql, GtbAnag.class);
|
||||
gtbAnag.setCodAnag(codAnag);
|
||||
gtbAnag.setOperation(OperationType.INSERT);
|
||||
|
||||
CtbAnag ctbAnag = new CtbAnag()
|
||||
.setCodCcon(getCodCcon(conn));
|
||||
CtbAnag ctbAnag = new CtbAnag().setCodCcon(getCodCcon(conn));
|
||||
ctbAnag.setOperation(OperationType.INSERT);
|
||||
gtbAnag.setCtbAnag(ctbAnag);
|
||||
|
||||
@@ -399,13 +394,7 @@ public class CRMUtility {
|
||||
" ptb_pros.cod_cab,\n" +
|
||||
" ptb_pros.cod_paga,\n" +
|
||||
" ptb_pros.cod_vlis,\n" +
|
||||
" ISNULL(ptb_pros.sconto1, 0),\n" +
|
||||
" ISNULL(ptb_pros.sconto2, 0),\n" +
|
||||
" ptb_pros.cod_aliq,\n" +
|
||||
" 0 AS fido,\n" +
|
||||
" 'S' AS flag_spese,\n" +
|
||||
" 0 AS perc_prov,\n" +
|
||||
" 'A' AS flag_stato,\n" +
|
||||
" 'GIORNALIERA' AS period_fat,\n" +
|
||||
" 'SINGOLA BOLLA' AS tipo_fat_dif,\n" +
|
||||
" ptb_pros.fonte,\n" +
|
||||
@@ -467,8 +456,15 @@ public class CRMUtility {
|
||||
gtbAnag.setVtbCliePersRif(persRif);
|
||||
}
|
||||
|
||||
response.setGtbAnag(gtbAnag);
|
||||
|
||||
if (codAnag == null) return response;
|
||||
else return addNewClieToOldEntity(response, codAnag, codPpro, conn);
|
||||
}
|
||||
|
||||
public static CRMTransferProspectResponseDTO addNewClieToOldEntity(CRMTransferProspectResponseDTO response, String codAnag, String codPpro, Connection conn) throws Exception {
|
||||
//Assegnazione nuovo cliente a eventuali offerte
|
||||
sql = Query.format(
|
||||
String sql = Query.format(
|
||||
"SELECT *\n" +
|
||||
"FROM ptb_prevt\n" +
|
||||
"WHERE cod_ppro = %s",
|
||||
@@ -550,8 +546,6 @@ public class CRMUtility {
|
||||
response.getWdtbOrdts().addAll(wdtbOrdtToUpdate);
|
||||
}
|
||||
|
||||
response.setGtbAnag(gtbAnag);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user