Gestione incassi PUDDY e importazione ordini
This commit is contained in:
@@ -28,10 +28,6 @@ public class DistintaIncassiPrevPuddyDTO {
|
||||
@SqlField("imp_incasso")
|
||||
private BigDecimal impPaga;
|
||||
|
||||
@SqlField("azienda")
|
||||
private String azienda;
|
||||
|
||||
|
||||
public String getCodAnag() {
|
||||
return codAnag;
|
||||
}
|
||||
@@ -87,12 +83,4 @@ public class DistintaIncassiPrevPuddyDTO {
|
||||
public void setImpPaga(BigDecimal impPaga) {
|
||||
this.impPaga = impPaga;
|
||||
}
|
||||
|
||||
public String getAzienda() {
|
||||
return azienda;
|
||||
}
|
||||
|
||||
public void setAzienda(String azienda) {
|
||||
this.azienda = azienda;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -941,11 +941,11 @@ public class PuddyService {
|
||||
private ServiceRestResponse importOrdAgenti(MultiDBTransactionManager multiDBTransactionManager, String codVage) throws Exception {
|
||||
PreparedStatement info = null;
|
||||
ResultSet res = null;
|
||||
boolean existAnomalia = false, existOrdAgente = false;
|
||||
boolean existAnomalia = false;
|
||||
ServiceRestResponse resp = new ServiceRestResponse();
|
||||
|
||||
Connection conn = multiDBTransactionManager.getPrimaryDatasource().getConnection();
|
||||
String registraDistIncassi = UtilityString.streNull(setupGest.getSetup(conn, "W_MLUPDSRV_CONFIG_DLG", "SETUP", "REGISTRA_INCASSI_PUDDY"));
|
||||
// String registraDistIncassi = UtilityString.streNull(setupGest.getSetup(conn, "W_MLUPDSRV_CONFIG_DLG", "SETUP", "REGISTRA_INCASSI_PUDDY"));
|
||||
String newVersion = UtilityString.streNull(setupGest.getSetup(conn, "W_MLUPDSRV_CONFIG_DLG", "SETUP", "NEW_VERSION"));
|
||||
|
||||
String sql =
|
||||
@@ -968,7 +968,6 @@ public class PuddyService {
|
||||
Integer numOrdProv = res.getInt(2);
|
||||
Date dataOrdProvv = res.getDate(3);
|
||||
String flagTD = res.getString(4);
|
||||
existOrdAgente = true;
|
||||
|
||||
if (newVersion.compareTo("S") == 0) {
|
||||
resp = importOrdine(multiDBTransactionManager, serie, dataOrdProvv, numOrdProv, flagTD, codVage);
|
||||
@@ -984,63 +983,46 @@ public class PuddyService {
|
||||
res.close();
|
||||
info.close();
|
||||
|
||||
if (!existAnomalia) {
|
||||
if (registraDistIncassi.compareTo("S") == 0) {
|
||||
String whereCond = "(x_puddy3_prev_incassi.cod_vage = '" + codVage + "')";
|
||||
importDistintaIncassiPrev(whereCond);
|
||||
// Controllo invio esito
|
||||
String oggetto = null, messaggio = null;
|
||||
String emailForLog = setupGest.getSetup("IMPORT_ORDINI", "PUDDY", "EMAIL_FOR_LOG");
|
||||
if (existAnomalia) {
|
||||
if (!UtilityString.isNullOrEmpty(emailForLog)) {
|
||||
oggetto = "ERRORE IMPORTAZIONE ORDINI DI VENDITA AGENTE " + codVage;
|
||||
messaggio = resp.getErrorMessage();
|
||||
}
|
||||
} else {
|
||||
String oggetto = null, messaggio = null;
|
||||
String emailForLog = setupGest.getSetup("IMPORT_ORDINI", "PUDDY", "EMAIL_FOR_LOG");
|
||||
if (existAnomalia) {
|
||||
if (!UtilityString.isNullOrEmpty(emailForLog)) {
|
||||
oggetto = "ERRORE IMPORTAZIONE ORDINI DI VENDITA AGENTE " + codVage;
|
||||
messaggio = resp.getErrorMessage();
|
||||
}
|
||||
|
||||
multiDBTransactionManager.rollbackAll();
|
||||
} else {
|
||||
if (!UtilityString.isNullOrEmpty(emailForLog)) {
|
||||
oggetto = "IMPORTAZIONE ORDINI VENDITA AGENTE " + codVage + " AVVENUTA CON SUCCESSO";
|
||||
messaggio = oggetto + CommonConstants.A_CAPO;
|
||||
}
|
||||
|
||||
multiDBTransactionManager.commitAll();
|
||||
if (!UtilityString.isNullOrEmpty(emailForLog)) {
|
||||
oggetto = "IMPORTAZIONE ORDINI VENDITA AGENTE " + codVage + " AVVENUTA CON SUCCESSO";
|
||||
messaggio = oggetto + CommonConstants.A_CAPO;
|
||||
}
|
||||
mailService.sendMail(emailForLog, null, oggetto, messaggio);
|
||||
}
|
||||
mailService.sendMail(emailForLog, null, oggetto, messaggio);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
public List<EntityBase> importOrdiniFromPuddy() throws Exception {
|
||||
VtbAgen vtbAgen = new VtbAgen();
|
||||
List<EntityBase> response = new ArrayList<EntityBase>();
|
||||
String username = requestDataDTO.getUsername();
|
||||
PreparedStatement info = null;
|
||||
ResultSet res = null;
|
||||
ServiceRestResponse resp = new ServiceRestResponse();
|
||||
List<ServiceRestResponse> respList = new ArrayList<ServiceRestResponse>();
|
||||
ServiceRestResponse List = new ServiceRestResponse();
|
||||
String whereCond = "";
|
||||
|
||||
Connection conn = multiDBTransactionManager.getPrimaryDatasource().getConnection();
|
||||
String profileDB = multiDBTransactionManager.getPrimaryDatasource().getProfile();
|
||||
String emailLog = setupGest.getSetup(conn, "PUDDY", "ORDINI_VENDITA", "EMAIL_FOR_LOG");
|
||||
String registraDistIncassi = UtilityString.streNull(setupGest.getSetup(conn, "W_MLUPDSRV_CONFIG_DLG", "SETUP", "REGISTRA_INCASSI_PUDDY"));
|
||||
|
||||
String sql =
|
||||
"SELECT distinct cod_vage" +
|
||||
" FROM x_puddy3_prev_ordini " +
|
||||
"WHERE flag_elaborato = 'N' AND " +
|
||||
"WHERE flag_elaborato = 'N' AND " +
|
||||
condEsclResi +
|
||||
"ORDER BY 1";
|
||||
"ORDER BY 1";
|
||||
|
||||
info = conn.prepareStatement(sql);
|
||||
res = info.executeQuery();
|
||||
PreparedStatement info = conn.prepareStatement(sql);
|
||||
ResultSet res = info.executeQuery();
|
||||
while (res.next()) {
|
||||
String codVage = res.getString(1);
|
||||
vtbAgen = new VtbAgen();
|
||||
VtbAgen vtbAgen = new VtbAgen();
|
||||
vtbAgen.setCodVage(codVage);
|
||||
resp = importOrdAgenti(multiDBTransactionManager, codVage);
|
||||
ServiceRestResponse resp = resp = importOrdAgenti(multiDBTransactionManager, codVage);
|
||||
if (resp.getEsito() == EsitoType.OK) {
|
||||
response.add(vtbAgen);
|
||||
}
|
||||
@@ -1048,58 +1030,28 @@ public class PuddyService {
|
||||
res.close();
|
||||
info.close();
|
||||
|
||||
// Verifica esistenza anomalie da segnalare
|
||||
/* try {
|
||||
if (!logList.isEmpty()) {
|
||||
List<FileItem> fileAttachmentList = new ArrayList<FileItem>();
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
jsonObjectMapper.writeValue(writer, logList);
|
||||
String jsonBody = writer.toString();
|
||||
|
||||
FileItem fileItem = new FileItem("LogImportOrdiniPuddy.txt", jsonBody, "txt");
|
||||
fileAttachmentList.add(fileItem);
|
||||
|
||||
mailService.sendMail(
|
||||
null,
|
||||
null,
|
||||
emailLog,
|
||||
null,
|
||||
null,
|
||||
"ERRORE IMPORTAZIONE ORDINI PUDDY ",
|
||||
"Si è verificato il seguente errore durante l'importazione degli ordini",
|
||||
true,
|
||||
fileAttachmentList,
|
||||
false);
|
||||
} catch (Exception e) {
|
||||
logger.error("NON E' STATO POSSIBILE INVIARE LA MAIL DI NOTIFICA ERRORE IMPORTAZIONE " + e.toString());
|
||||
}*/
|
||||
//respList.add(new ServiceRestResponse(EsitoType.OK, "Importazione completata"));
|
||||
if (registraDistIncassi.compareTo("S") == 0) {
|
||||
importDistintaIncassiPrev(whereCond);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public List<EntityBase> importDistintaIncassiPrev(String whereCond) throws Exception {
|
||||
Integer numDistinta = 0;
|
||||
List<EntityBase> listDistIncat = new ArrayList<EntityBase>();
|
||||
List<EntityBase> listDistIncat2ndDB = new ArrayList<EntityBase>();
|
||||
List<EntityBase> listDistIncatVG = new ArrayList<EntityBase>();
|
||||
Connection conn = multiDBTransactionManager.getPrimaryDatasource().getConnection();
|
||||
MultiDBTransactionManager multiDBTransactionManagerVG = new MultiDBTransactionManager();
|
||||
PreparedStatement psDistintaAgente = null;
|
||||
boolean existAssVG = false;
|
||||
|
||||
|
||||
String profileDBVG = setupGest.getSetup("IMPORT_ORDINI", "PUDDY", "PROFILE_DB_VG");
|
||||
String profileDB = multiDBTransactionManager.getPrimaryDatasource().getProfile();
|
||||
|
||||
// Connessione DB VG
|
||||
String columnTipoAzienda = profileDB;
|
||||
String columnTipoAzienda = multiDBTransactionManager.getPrimaryDatasource().getProfile();
|
||||
if (!UtilityString.isNullOrEmpty(profileDBVG)){
|
||||
DataSource dsSync = new DataSource();
|
||||
dsSync.initialize(profileDBVG);
|
||||
multiDBTransactionManagerVG.setPrimaryDs(profileDBVG);
|
||||
|
||||
existAssVG = true;
|
||||
columnTipoAzienda = "case when ser_doc like 'S%' then 'ASS_VG' else 'ASS_SEVEN' end";
|
||||
}
|
||||
|
||||
@@ -1107,8 +1059,9 @@ public class PuddyService {
|
||||
String query =
|
||||
"SELECT DISTINCT x_puddy3_prev_incassi.data_incasso, " +
|
||||
" x_puddy3_prev_incassi.cod_vage, " +
|
||||
columnTipoAzienda + " " +
|
||||
" FROM x_puddy3_prev_incassi " +
|
||||
columnTipoAzienda + ", " +
|
||||
" x_puddy3_prev_intercode_agenti_vg.cod_vage_vg " +
|
||||
" FROM x_puddy3_prev_incassi left outer join x_puddy3_prev_intercode_agenti_vg on x_puddy3_prev_incassi.cod_vage = x_puddy3_prev_intercode_agenti_vg.cod_vage " +
|
||||
" WHERE x_puddy3_prev_incassi.flag_elaborato = 'N' " +
|
||||
" ORDER BY 3 ";
|
||||
query = UtilityDB.addwhereCond(query, whereCond, false);
|
||||
@@ -1118,9 +1071,10 @@ public class PuddyService {
|
||||
Date dataIncasso = rs.getDate(1);
|
||||
String codVage = rs.getString(2);
|
||||
String azienda = rs.getString(3);
|
||||
String codVageVG = rs.getString(4);
|
||||
|
||||
// verifica esitenza distinta incassi su DB di competenza
|
||||
numDistinta = 0;
|
||||
Integer numDistinta = 0;
|
||||
query = "SELECT num_dist " +
|
||||
" FROM vtb_dist_incat " +
|
||||
" WHERE vtb_dist_incat.data_dist = " + UtilityDB.valueToString(dataIncasso) + " AND " +
|
||||
@@ -1132,47 +1086,41 @@ public class PuddyService {
|
||||
numDistinta = (Integer) QueryRules.getSingleValue(multiDBTransactionManagerVG.getPrimaryConnection(), query);
|
||||
}
|
||||
|
||||
|
||||
// Generazione distinta incassi
|
||||
query =
|
||||
"SELECT x_puddy3_prev_incassi.cod_anag, " +
|
||||
" x_puddy3_prev_incassi.cod_vdes, " +
|
||||
"SELECT case when left(x_puddy3_prev_incassi.ser_doc, 1) = 'S' then x_puddy3_prev_intercode_clienti_VG.cod_anag_vg ELSE x_puddy3_prev_incassi.cod_anag end as cod_anag, " +
|
||||
" case when left(x_puddy3_prev_incassi.ser_doc, 1) = 'S' then x_puddy3_prev_intercode_clienti_VG.cod_vdes_vg ELSE x_puddy3_prev_incassi.cod_vdes end as cod_vdes, " +
|
||||
" x_puddy3_prev_incassi.cod_causale, " +
|
||||
" x_puddy3_prev_incassi.data_doc, " +
|
||||
" x_puddy3_prev_incassi.ser_doc, " +
|
||||
" case when left(x_puddy3_prev_incassi.ser_doc, 1) = 'S' then SUBSTRING(x_puddy3_prev_incassi.ser_doc, 2, 2) else x_puddy3_prev_incassi.ser_doc end as ser_doc, " +
|
||||
" x_puddy3_prev_incassi.num_doc, " +
|
||||
" x_puddy3_prev_incassi.imp_incasso " +
|
||||
" FROM x_puddy3_prev_incassi " +
|
||||
" FROM x_puddy3_prev_incassi left outer join x_puddy3_prev_intercode_clienti_VG on x_puddy3_prev_incassi.cod_anag = x_puddy3_prev_intercode_clienti_VG.cod_anag and " +
|
||||
" x_puddy3_prev_incassi.cod_vdes = x_puddy3_prev_intercode_clienti_VG.cod_vdes " +
|
||||
" WHERE x_puddy3_prev_incassi.flag_elaborato = 'N' AND " +
|
||||
" x_puddy3_prev_incassi.data_incasso = " + UtilityDB.valueToString(dataIncasso) + " AND " +
|
||||
" x_puddy3_prev_incassi.cod_vage = " + UtilityDB.valueToString(codVage);
|
||||
" x_puddy3_prev_incassi.cod_vage = " + UtilityDB.valueToString(codVage) + " AND " +
|
||||
columnTipoAzienda + " = " + UtilityDB.valueToString(azienda);
|
||||
|
||||
if (!azienda.equals("VG")) {
|
||||
psDistintaAgente = multiDBTransactionManager.prepareStatement(query);
|
||||
} else {
|
||||
psDistintaAgente = multiDBTransactionManagerVG.prepareStatement(query);
|
||||
}
|
||||
PreparedStatement psDistintaAgente = multiDBTransactionManager.prepareStatement(query);
|
||||
ResultSet rsDistintaAgente = psDistintaAgente.executeQuery();
|
||||
List<DistintaIncassiPrevPuddyDTO> datiDistintaPuddy = new ResultSetMapper()
|
||||
.mapResultSetToList(rsDistintaAgente, DistintaIncassiPrevPuddyDTO.class);
|
||||
List<DistintaIncassiPrevPuddyDTO> datiDistintaPuddy = new ResultSetMapper().mapResultSetToList(rsDistintaAgente, DistintaIncassiPrevPuddyDTO.class);
|
||||
psDistintaAgente.close();
|
||||
|
||||
String aziendaOld = "";
|
||||
VtbDistIncat vtbDistIncat = new VtbDistIncat();
|
||||
int rows = datiDistintaPuddy.size();
|
||||
for (int i = 0; i < datiDistintaPuddy.size(); i++) {
|
||||
DistintaIncassiPrevPuddyDTO datoDistinta = datiDistintaPuddy.get(i);
|
||||
azienda = datoDistinta.getAzienda();
|
||||
|
||||
if (azienda.compareTo(aziendaOld) != 0) {
|
||||
if (i == 1) {
|
||||
vtbDistIncat.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
vtbDistIncat.setDataDist(dataIncasso);
|
||||
vtbDistIncat.setNumDist(numDistinta);
|
||||
vtbDistIncat.setCodVage(codVage);
|
||||
if (!azienda.equals("ASS_VG")){
|
||||
vtbDistIncat.setCodVage(codVage);
|
||||
listDistIncat.add(vtbDistIncat);
|
||||
} else {
|
||||
listDistIncat2ndDB.add(vtbDistIncat); // Inserimento elenco distitne nel secondo DB
|
||||
vtbDistIncat.setCodVage(codVageVG);
|
||||
listDistIncatVG.add(vtbDistIncat); // Inserimento elenco distitne nel secondo DB
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1188,11 +1136,6 @@ public class PuddyService {
|
||||
vtbDistIncar.setImpIncasso(datoDistinta.getImpPaga());
|
||||
vtbDistIncar.setFlagRegAcc("S");
|
||||
vtbDistIncat.getVtbDistIncar().add(vtbDistIncar);
|
||||
|
||||
aziendaOld = azienda;
|
||||
if (i < rows) {
|
||||
aziendaOld = datiDistintaPuddy.get(i + 1).getAzienda();
|
||||
}
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
@@ -1206,11 +1149,12 @@ public class PuddyService {
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < listDistIncat2ndDB.size(); i++) {
|
||||
entityProcessor.processEntity(listDistIncat2ndDB.get(i), true, true, multiDBTransactionManagerVG.getPrimaryDatasource().getProfile(), multiDBTransactionManagerVG);
|
||||
if (listDistIncat2ndDB.get(i).getException() != null) {
|
||||
for (int i = 0; i < listDistIncatVG.size(); i++) {
|
||||
entityProcessor.processEntity(listDistIncatVG.get(i), true, true, multiDBTransactionManagerVG.getPrimaryDatasource().getProfile(), multiDBTransactionManagerVG);
|
||||
if (listDistIncatVG.get(i).getException() != null) {
|
||||
multiDBTransactionManager.rollbackAll();
|
||||
multiDBTransactionManagerVG.rollbackAll();
|
||||
throw new Exception(listDistIncat2ndDB.get(i).getException().getMessage());
|
||||
throw new Exception(listDistIncatVG.get(i).getException().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1220,13 +1164,9 @@ public class PuddyService {
|
||||
cmd.execute(query);
|
||||
cmd.close();
|
||||
|
||||
if (existAssVG){
|
||||
multiDBTransactionManagerVG.commitAll();
|
||||
}
|
||||
|
||||
multiDBTransactionManagerVG.commitAll();
|
||||
multiDBTransactionManager.commitAll();
|
||||
|
||||
|
||||
return listDistIncat;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user