correzioni ad invio variazioni
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
package it.integry.ems.migration.model;
|
||||||
|
|
||||||
|
import it.integry.ems.migration._base.BaseMigration;
|
||||||
|
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||||
|
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||||
|
|
||||||
|
public class Migration_20240708111056 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up() throws Exception {
|
||||||
|
if (isHistoryDB())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (isCustomerDb(IntegryCustomerDB.Carelli_GestFood, IntegryCustomerDB.Carelli_Panimal))
|
||||||
|
executeStatement("insert into stb_gest_setup\n" +
|
||||||
|
"select *\n" +
|
||||||
|
"from carelli.dbo.stb_gest_setup\n" +
|
||||||
|
"where gest_name = 'W_VVARIAZ_PREZZI_DISP'\n" +
|
||||||
|
"and not exists (select * from stb_gest_setup s where s.gest_name = stb_gest_setup.gest_name and s.section = stb_gest_setup.section and s.key_section = stb_gest_setup.key_section )",
|
||||||
|
"update stb_gest_setup set value = s.value, flag_sync = 'S'\n" +
|
||||||
|
"from carelli.dbo.stb_gest_setup s inner join stb_gest_setup on s.gest_name = stb_gest_setup.gest_name and s.section = stb_gest_setup.section and s.key_section = stb_gest_setup.key_section\n" +
|
||||||
|
"where s.gest_name = 'W_VVARIAZ_PREZZI_DISP'",
|
||||||
|
"insert into stb_gest_setup_depo\n" +
|
||||||
|
"select stb_gest_setup_depo.*\n" +
|
||||||
|
"from carelli.dbo.stb_gest_setup \n" +
|
||||||
|
"inner join carelli.dbo.stb_gest_setup_depo on stb_gest_setup_depo.gest_name = stb_gest_setup.gest_name and stb_gest_setup_depo.section = stb_gest_setup.section and stb_gest_setup_depo.key_section = stb_gest_setup.key_section\n" +
|
||||||
|
"where stb_gest_setup.gest_name = 'W_VVARIAZ_PREZZI_DISP'\n" +
|
||||||
|
"and stb_gest_setup.flag_setup_depo = 'S'\n" +
|
||||||
|
"except \n" +
|
||||||
|
"select * from stb_gest_setup_depo",
|
||||||
|
"update stb_gest_setup_depo\n" +
|
||||||
|
"set value = s.value\n" +
|
||||||
|
"from stb_gest_setup_depo\n" +
|
||||||
|
"inner join (select stb_gest_setup_depo.*\n" +
|
||||||
|
"from carelli.dbo.stb_gest_setup \n" +
|
||||||
|
"inner join carelli.dbo.stb_gest_setup_depo on stb_gest_setup_depo.gest_name = stb_gest_setup.gest_name and stb_gest_setup_depo.section = stb_gest_setup.section and stb_gest_setup_depo.key_section = stb_gest_setup.key_section\n" +
|
||||||
|
"where stb_gest_setup.gest_name = 'W_VVARIAZ_PREZZI_DISP'\n" +
|
||||||
|
"and stb_gest_setup.flag_setup_depo = 'S') s on stb_gest_setup_depo.gest_name = s.gest_name and stb_gest_setup_depo.section = s.section and stb_gest_setup_depo.key_section = s.key_section\n" +
|
||||||
|
"and stb_gest_setup_depo.cod_mdep = s.cod_mdep\n",
|
||||||
|
"insert into wtb_gest_setup_user\n" +
|
||||||
|
"select wtb_gest_setup_user.*\n" +
|
||||||
|
"from carelli.dbo.stb_gest_setup \n" +
|
||||||
|
"inner join carelli.dbo.wtb_gest_setup_user on wtb_gest_setup_user.gest_name = stb_gest_setup.gest_name and wtb_gest_setup_user.section = stb_gest_setup.section and wtb_gest_setup_user.key_section = stb_gest_setup.key_section\n" +
|
||||||
|
"where stb_gest_setup.gest_name = 'W_VVARIAZ_PREZZI_DISP'\n" +
|
||||||
|
"and stb_gest_setup.flag_setup_user_web = 'S'\n" +
|
||||||
|
"and exists (select * from stb_user where stb_user.user_name = wtb_gest_setup_user.user_name)\n" +
|
||||||
|
"except \n" +
|
||||||
|
"select * from wtb_gest_setup_user",
|
||||||
|
"update wtb_gest_setup_user\n" +
|
||||||
|
"set value = s.value\n" +
|
||||||
|
"from wtb_gest_setup_user\n" +
|
||||||
|
"inner join (select wtb_gest_setup_user.*\n" +
|
||||||
|
"from carelli.dbo.stb_gest_setup \n" +
|
||||||
|
"inner join carelli.dbo.wtb_gest_setup_user on wtb_gest_setup_user.gest_name = stb_gest_setup.gest_name and wtb_gest_setup_user.section = stb_gest_setup.section and wtb_gest_setup_user.key_section = stb_gest_setup.key_section\n" +
|
||||||
|
"where stb_gest_setup.gest_name = 'W_VVARIAZ_PREZZI_DISP'\n" +
|
||||||
|
"and stb_gest_setup.flag_setup_depo = 'S') s on wtb_gest_setup_user.gest_name = s.gest_name and wtb_gest_setup_user.section = s.section and wtb_gest_setup_user.key_section = s.key_section\n" +
|
||||||
|
"and wtb_gest_setup_user.user_name = s.user_name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package it.integry.ems.migration.model;
|
||||||
|
|
||||||
|
import it.integry.ems.migration._base.BaseMigration;
|
||||||
|
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||||
|
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||||
|
|
||||||
|
public class Migration_20240708130221 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up() throws Exception {
|
||||||
|
if (isHistoryDB())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (isCustomerDb(IntegryCustomerDB.Carelli_Carelli, IntegryCustomerDB.Carelli_GestFood, IntegryCustomerDB.Carelli_Panimal))
|
||||||
|
updateSetupValue("EXPORT_VARIAZIONE PV", "XML_DIALOGO", "SAVE_LOG", "S");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
package it.integry.ems.retail.ReportVariazioni.controller;
|
package it.integry.ems.retail.ReportVariazioni.controller;
|
||||||
|
|
||||||
import it.integry.common.var.CommonConstants;
|
import it.integry.common.var.CommonConstants;
|
||||||
|
import it.integry.ems.javabeans.RequestDataDTO;
|
||||||
import it.integry.ems.response.ServiceRestResponse;
|
import it.integry.ems.response.ServiceRestResponse;
|
||||||
import it.integry.ems.retail.ReportVariazioni.dto.VariazioniPvInputDTO;
|
import it.integry.ems.retail.ReportVariazioni.dto.VariazioniPvInputDTO;
|
||||||
import it.integry.ems.retail.ReportVariazioni.service.VariazioniPvService;
|
import it.integry.ems.retail.ReportVariazioni.service.VariazioniPvService;
|
||||||
|
import it.integry.ems_model.utility.UtilityString;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -22,6 +25,9 @@ public class VariazioniPvController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private VariazioniPvService variazioniPvService;
|
private VariazioniPvService variazioniPvService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RequestDataDTO requestData;
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/", method = RequestMethod.POST)
|
@RequestMapping(value = "/", method = RequestMethod.POST)
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
@@ -52,6 +58,15 @@ public class VariazioniPvController {
|
|||||||
@RequestParam(required = false) String tipoReport,
|
@RequestParam(required = false) String tipoReport,
|
||||||
@RequestBody(required = false) VariazioniPvInputDTO variazioniPvInputDTO) throws Exception {
|
@RequestBody(required = false) VariazioniPvInputDTO variazioniPvInputDTO) throws Exception {
|
||||||
|
|
||||||
|
if ( !requestData.isValidUsername()){
|
||||||
|
throw new UsernameNotFoundException(requestData.getUsername());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variazioniPvInputDTO == null || UtilityString.isNullOrEmpty(variazioniPvInputDTO.getUserName())){
|
||||||
|
if (variazioniPvInputDTO == null )
|
||||||
|
variazioniPvInputDTO = new VariazioniPvInputDTO();
|
||||||
|
variazioniPvInputDTO.setUserName(requestData.getUsername());
|
||||||
|
}
|
||||||
variazioniPvService.exportByTipoReport(tipoReport, variazioniPvInputDTO);
|
variazioniPvService.exportByTipoReport(tipoReport, variazioniPvInputDTO);
|
||||||
return ServiceRestResponse.createPositiveResponse();
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -315,6 +315,14 @@ public class VariazioniPvService {
|
|||||||
codMartType.getContent().add(codMart);
|
codMartType.getContent().add(codMart);
|
||||||
|
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeDescrizione(UtilityString.streNull(var.getDescrArt())));
|
codMartType.getContent().add(objectFactory.createCodMartTypeDescrizione(UtilityString.streNull(var.getDescrArt())));
|
||||||
|
String descrizioneEstesa = var.getDescrizioneEstesa();
|
||||||
|
if (!UtilityString.isNullOrEmpty(setupDescr)) {
|
||||||
|
if (setupDescr.equalsIgnoreCase("D"))
|
||||||
|
descrizioneEstesa = var.getDescrArt();
|
||||||
|
else if (setupDescr.equalsIgnoreCase("B"))
|
||||||
|
descrizioneEstesa = var.getDescrCassa();
|
||||||
|
}
|
||||||
|
codMartType.getContent().add(objectFactory.createCodMartTypeDescrizioneEstesa(UtilityString.streNull(descrizioneEstesa)));
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeUntMis2(UtilityString.streNull(var.getUntMis2())));
|
codMartType.getContent().add(objectFactory.createCodMartTypeUntMis2(UtilityString.streNull(var.getUntMis2())));
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeUntMis(UtilityString.streNull(var.getUntMis())));
|
codMartType.getContent().add(objectFactory.createCodMartTypeUntMis(UtilityString.streNull(var.getUntMis())));
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeRapConv2(UtilityString.bigDecimalToString(var.getRapConv2(), "###0.00").replace(",", ".")));
|
codMartType.getContent().add(objectFactory.createCodMartTypeRapConv2(UtilityString.bigDecimalToString(var.getRapConv2(), "###0.00").replace(",", ".")));
|
||||||
@@ -360,14 +368,6 @@ public class VariazioniPvService {
|
|||||||
tara = (tara.multiply(new BigDecimal("1000"))).setScale(0, RoundingMode.HALF_UP);
|
tara = (tara.multiply(new BigDecimal("1000"))).setScale(0, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeTara(UtilityString.bigDecimalToString(tara, "###0.00").replace(",", ".")));
|
codMartType.getContent().add(objectFactory.createCodMartTypeTara(UtilityString.bigDecimalToString(tara, "###0.00").replace(",", ".")));
|
||||||
String descrizioneEstesa = var.getDescrizioneEstesa();
|
|
||||||
if (!UtilityString.isNullOrEmpty(setupDescr)) {
|
|
||||||
if (setupDescr.equalsIgnoreCase("D"))
|
|
||||||
descrizioneEstesa = var.getDescrArt();
|
|
||||||
else if (setupDescr.equalsIgnoreCase("B"))
|
|
||||||
descrizioneEstesa = var.getDescrCassa();
|
|
||||||
}
|
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeDescrizioneEstesa(descrizioneEstesa));
|
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeAnnotazioniArt(UtilityString.streNull(var.getAnnotazioniArt())));
|
codMartType.getContent().add(objectFactory.createCodMartTypeAnnotazioniArt(UtilityString.streNull(var.getAnnotazioniArt())));
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeCodAliq(UtilityString.streNull(var.getCodAliq())));
|
codMartType.getContent().add(objectFactory.createCodMartTypeCodAliq(UtilityString.streNull(var.getCodAliq())));
|
||||||
codMartType.getContent().add(objectFactory.createCodMartTypeArticoloComposto(UtilityString.streNull(var.getArticoloComposto())));
|
codMartType.getContent().add(objectFactory.createCodMartTypeArticoloComposto(UtilityString.streNull(var.getArticoloComposto())));
|
||||||
@@ -1108,13 +1108,14 @@ public class VariazioniPvService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean existVariazioni = false;
|
boolean existVariazioni = false;
|
||||||
if (variazioniPvInputDTO != null)
|
Date dataValidita = null;
|
||||||
|
if (variazioniPvInputDTO != null) {
|
||||||
existVariazioni = (variazioniPvInputDTO.getVariazioni() != null && !variazioniPvInputDTO.getVariazioni().isEmpty());
|
existVariazioni = (variazioniPvInputDTO.getVariazioni() != null && !variazioniPvInputDTO.getVariazioni().isEmpty());
|
||||||
|
dataValidita = variazioniPvInputDTO.getDataValidita();
|
||||||
Date dataValidita = variazioniPvInputDTO.getDataValidita();
|
}
|
||||||
|
|
||||||
if (dataValidita == null)
|
if (dataValidita == null)
|
||||||
dataValidita = UtilityDate.RelativeDateTime(new Date(), 1);
|
dataValidita = UtilityDate.RelativeDateTime(UtilityDate.getTodayWithoutTime(), 1);
|
||||||
|
|
||||||
List<VariazioniDTO> listini = getListini(variazioniPvInputDTO, existVariazioni);
|
List<VariazioniDTO> listini = getListini(variazioniPvInputDTO, existVariazioni);
|
||||||
|
|
||||||
@@ -1157,8 +1158,6 @@ public class VariazioniPvService {
|
|||||||
|
|
||||||
String emailForLog = setupGest.getExportSetup(multiDBTransactionManager.getPrimaryConnection(), "VARIAZIONE PV", "XML_DIALOGO", "EMAIL_FOR_LOG");
|
String emailForLog = setupGest.getExportSetup(multiDBTransactionManager.getPrimaryConnection(), "VARIAZIONE PV", "XML_DIALOGO", "EMAIL_FOR_LOG");
|
||||||
|
|
||||||
emailForLog = "g.scorrano@integry.it";
|
|
||||||
|
|
||||||
if (!UtilityString.isNullOrEmpty(emailForLog)) {
|
if (!UtilityString.isNullOrEmpty(emailForLog)) {
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@@ -1310,6 +1309,25 @@ public class VariazioniPvService {
|
|||||||
if (testError)
|
if (testError)
|
||||||
throw new Exception("TEST ERROR");
|
throw new Exception("TEST ERROR");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// String emailForLog = setupGest.getExportSetup(multiDBTransactionManager.getPrimaryConnection(), exportType, formatFile, "EMAIL_FOR_LOG");
|
||||||
|
// int numVariazioni = variazioniPvInputDTO.getVariazioni().size();
|
||||||
|
// if (!UtilityString.isNullOrEmpty(emailForLog) && numVariazioni > 0) {
|
||||||
|
// String oggetto =
|
||||||
|
// "Esportazione " +
|
||||||
|
// variazioniPvInputDTO.getTipoReportEnum().toString() +
|
||||||
|
// " punto vendita " +
|
||||||
|
// userName;
|
||||||
|
//
|
||||||
|
// String messaggio = oggetto +
|
||||||
|
// " avvenuta con successo." + CommonConstants.A_CAPO +
|
||||||
|
// " Sono stati esportati n. " + numVariazioni + " articoli";
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// mailService.sendMailPrimary(multiDBTransactionManager, null, null, emailForLog, null, null, oggetto, messaggio, false, false, null, null, null, false, null);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,19 @@
|
|||||||
package it.integry.ems.retail.export;
|
package it.integry.ems.retail.export;
|
||||||
|
|
||||||
|
import com.annimon.stream.Stream;
|
||||||
import it.integry.ems.export.base.BaseEntityExporter;
|
import it.integry.ems.export.base.BaseEntityExporter;
|
||||||
import it.integry.ems.export.base.EntityExportResponse;
|
import it.integry.ems.export.base.EntityExportResponse;
|
||||||
import it.integry.ems.export.base.IEntityExporter;
|
import it.integry.ems.export.base.IEntityExporter;
|
||||||
import it.integry.ems.retail.export.service.VariazioniPvExportServices;
|
import it.integry.ems.retail.export.service.VariazioniPvExportServices;
|
||||||
|
import it.integry.ems.service.EntityProcessor;
|
||||||
|
import it.integry.ems_model.entity.DtbDoct;
|
||||||
|
import it.integry.ems_model.entity.NtbVariazioniExportLog;
|
||||||
import org.springframework.web.context.ContextLoader;
|
import org.springframework.web.context.ContextLoader;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class VariazioniExporter extends BaseEntityExporter implements IEntityExporter {
|
public class VariazioniExporter extends BaseEntityExporter implements IEntityExporter {
|
||||||
|
|
||||||
@@ -36,6 +43,19 @@ public class VariazioniExporter extends BaseEntityExporter implements IEntityExp
|
|||||||
public void postSend(EntityExportResponse entityExportResponse) throws Exception {
|
public void postSend(EntityExportResponse entityExportResponse) throws Exception {
|
||||||
Connection conn = multiDBTransactionManager.getPrimaryDatasource().getConnection();
|
Connection conn = multiDBTransactionManager.getPrimaryDatasource().getConnection();
|
||||||
//SE CONFIGURATO SALVARE NELLA TABELLA DI LOG DELLE VARIAZIONI.
|
//SE CONFIGURATO SALVARE NELLA TABELLA DI LOG DELLE VARIAZIONI.
|
||||||
|
boolean saveLog = setupGest.getExportSetupBoolean(multiDBTransactionManager.getPrimaryConnection(), type, format, "SAVE_LOG");
|
||||||
|
if (saveLog && entityExportResponse != null && entityExportResponse.getExtraInfo() instanceof List){
|
||||||
|
WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
|
||||||
|
|
||||||
|
List<NtbVariazioniExportLog> ntbVariazioniExportLogs =
|
||||||
|
((List<?>) entityExportResponse.getExtraInfo()).stream()
|
||||||
|
.filter(x -> x instanceof NtbVariazioniExportLog)
|
||||||
|
.map(x -> (NtbVariazioniExportLog) x)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
EntityProcessor entityProcessor = context.getBean(EntityProcessor.class);
|
||||||
|
entityProcessor.processEntityList(ntbVariazioniExportLogs, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,14 @@ import it.integry.ems.service.HttpRestWrapper;
|
|||||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
import it.integry.ems.utility.UtilityDirs;
|
import it.integry.ems.utility.UtilityDirs;
|
||||||
import it.integry.ems.utility.UtilityFile;
|
import it.integry.ems.utility.UtilityFile;
|
||||||
|
import it.integry.ems_model.base.EntityBase;
|
||||||
|
import it.integry.ems_model.entity.NtbVariazioniExportLog;
|
||||||
import it.integry.ems_model.entity.WtbUsersInfo;
|
import it.integry.ems_model.entity.WtbUsersInfo;
|
||||||
import it.integry.ems_model.service.SetupGest;
|
import it.integry.ems_model.service.SetupGest;
|
||||||
|
import it.integry.ems_model.types.OperationType;
|
||||||
import it.integry.ems_model.utility.UtilityDB;
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
import it.integry.ems_model.utility.UtilityDate;
|
import it.integry.ems_model.utility.UtilityDate;
|
||||||
|
import it.integry.ems_model.utility.UtilityHashMap;
|
||||||
import it.integry.ems_model.utility.UtilityString;
|
import it.integry.ems_model.utility.UtilityString;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@@ -41,8 +45,6 @@ import javax.xml.transform.stream.StreamSource;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -58,58 +60,60 @@ public class VariazioniPvExportServices {
|
|||||||
private SetupGest setupGest;
|
private SetupGest setupGest;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ResponseJSONObjectMapper jsonObjectMapper;
|
private ResponseJSONObjectMapper jsonObjectMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private VariazioniPvService variazioniPvService;
|
private VariazioniPvService variazioniPvService;
|
||||||
|
|
||||||
|
|
||||||
public EntityExportResponse xmlDialogo(String type, String format, String whereCond, JsonNode jsonBody, WtbUsersInfo wtbUsersInfo) throws Exception {
|
public EntityExportResponse xmlDialogo(String type, String format, String whereCond, JsonNode jsonBody, WtbUsersInfo wtbUsersInfo) throws Exception {
|
||||||
String fileXml = null;
|
String fileXml;
|
||||||
VariazioniPvInputDTO variazioniPvDTO = new VariazioniPvInputDTO();
|
List<EntityBase> extraInfo = new ArrayList<>();
|
||||||
|
|
||||||
EntityExportResponse<List<File>> entityExportResponse = new EntityExportResponse<>();
|
EntityExportResponse<List<File>> entityExportResponse = new EntityExportResponse<>();
|
||||||
entityExportResponse.setResponse(new ArrayList<File>());
|
entityExportResponse.setResponse(new ArrayList<>());
|
||||||
boolean isSingleLisv = false;
|
|
||||||
|
|
||||||
Map<String, String> setup = setupGest.getExportSetupSection(multiDBTransactionManager.getPrimaryConnection(), type, format);
|
Map<String, String> setup = setupGest.getExportSetupSection(multiDBTransactionManager.getPrimaryConnection(), type, format);
|
||||||
|
|
||||||
|
VariazioniPvInputDTO variazioniPvDTO = null;
|
||||||
if (jsonBody != null) {
|
if (jsonBody != null) {
|
||||||
ResponseJSONObjectMapper mapper = new ResponseJSONObjectMapper();
|
variazioniPvDTO = jsonObjectMapper.readValue(jsonBody.toString(), VariazioniPvInputDTO.class);
|
||||||
variazioniPvDTO = mapper.readValue(jsonBody.toString(), VariazioniPvInputDTO.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UtilityString.isNullOrEmpty(variazioniPvDTO.getFileXml())) {
|
if (variazioniPvDTO != null && UtilityString.isNullOrEmpty(variazioniPvDTO.getFileXml())) {
|
||||||
|
boolean existJson = (variazioniPvDTO.getVariazioni() != null || variazioniPvDTO.getVariazioni().size() > 0);
|
||||||
if (variazioniPvDTO.getDataValidita() == null) {
|
if (variazioniPvDTO.getDataValidita() == null) {
|
||||||
variazioniPvDTO.setDataValidita(UtilityDate.RelativeDateTime(new Date(), 1));
|
variazioniPvDTO.setDataValidita( UtilityDate.RelativeDateTime(new Date(), 1));
|
||||||
}
|
}
|
||||||
if (variazioniPvDTO.getTipoReportEnum() == null) {
|
if (variazioniPvDTO.getTipoReportEnum() == null) {
|
||||||
variazioniPvDTO.setTipoReportEnum(VariazioniReportType.VARIAZIONI);
|
variazioniPvDTO.setTipoReportEnum(VariazioniReportType.VARIAZIONI);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!UtilityString.isNullOrEmpty(whereCond) && UtilityString.isNullOrEmpty(variazioniPvDTO.getWhereCondArt())) {
|
if (!existJson) {
|
||||||
variazioniPvDTO.setWhereCondArt(whereCond);
|
if (!UtilityString.isNullOrEmpty(whereCond) && UtilityString.isNullOrEmpty(variazioniPvDTO.getWhereCondArt())) {
|
||||||
} else if (UtilityString.isNullOrEmpty(whereCond) && UtilityString.isNullOrEmpty(variazioniPvDTO.getWhereCondArt()) &&
|
variazioniPvDTO.setWhereCondArt(whereCond);
|
||||||
wtbUsersInfo != null) {
|
} else if (UtilityString.isNullOrEmpty(whereCond) && UtilityString.isNullOrEmpty(variazioniPvDTO.getWhereCondArt()) &&
|
||||||
String query =
|
wtbUsersInfo != null) {
|
||||||
"SELECT cod_vlis " +
|
String query =
|
||||||
" FROM wtb_depo INNER JOIN mtb_depo ON wtb_depo.cod_mdep = mtb_depo.cod_mdep " +
|
"SELECT cod_vlis " +
|
||||||
" WHERE wtb_depo.user_name = " + UtilityDB.valueToString(wtbUsersInfo.getUserName());
|
" FROM wtb_depo INNER JOIN mtb_depo ON wtb_depo.cod_mdep = mtb_depo.cod_mdep " +
|
||||||
PreparedStatement ps = multiDBTransactionManager.prepareStatement(query);
|
" WHERE wtb_depo.user_name = " + UtilityDB.valueToString(wtbUsersInfo.getUserName());
|
||||||
ResultSet rs = ps.executeQuery();
|
String codVlis = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), query);
|
||||||
if (rs.next()) {
|
|
||||||
String codVlis = rs.getString(1);
|
|
||||||
if (!UtilityString.isNullOrEmpty(codVlis)) {
|
if (!UtilityString.isNullOrEmpty(codVlis)) {
|
||||||
whereCond = "vtb_list.cod_vlis = " + UtilityDB.valueToString(codVlis);
|
whereCond = "vtb_list.cod_vlis = " + UtilityDB.valueToString(codVlis);
|
||||||
variazioniPvDTO.setWhereCondLisv(whereCond);
|
variazioniPvDTO.setWhereCondArt(whereCond);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
fileXml = variazioniPvService.variazionePrezzoPVXml(variazioniPvDTO);
|
fileXml = variazioniPvService.variazionePrezzoPVXml(variazioniPvDTO);
|
||||||
} else {
|
} else {
|
||||||
//fileXml = new String(Base64.decodeBase64(variazioniPvDTO.getFileXml()), "UTF-8");
|
|
||||||
fileXml = variazioniPvDTO.getFileXml();
|
fileXml = variazioniPvDTO.getFileXml();
|
||||||
|
logger.trace(String.format(VariazioniPvExportServices.class.getSimpleName() + " %s %s", variazioniPvDTO.getCodVlis(), variazioniPvDTO.getTipoReport()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isSingleLisv = false;
|
||||||
if (!UtilityString.isNullOrEmpty(fileXml)) {
|
if (!UtilityString.isNullOrEmpty(fileXml)) {
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(ReportType.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(ReportType.class);
|
||||||
Source source = new StreamSource(new StringReader(fileXml));
|
Source source = new StreamSource(new StringReader(fileXml));
|
||||||
@@ -135,7 +139,7 @@ public class VariazioniPvExportServices {
|
|||||||
String query =
|
String query =
|
||||||
"SELECT wtb_users.user_name, " +
|
"SELECT wtb_users.user_name, " +
|
||||||
" wtb_users.password, " +
|
" wtb_users.password, " +
|
||||||
" case when charindex('FILE', priority) < 0 THEN 'S' ELSE flag_remote_save END " +
|
" case when charindex('FILE', priority) < 0 THEN 'S' ELSE flag_remote_save END as salvataggio_remoto" +
|
||||||
" FROM wtb_users INNER JOIN wtb_users_info ON wtb_users.user_name = wtb_users_info.user_name " +
|
" FROM wtb_users INNER JOIN wtb_users_info ON wtb_users.user_name = wtb_users_info.user_name " +
|
||||||
" INNER JOIN wtb_depo on wtb_users.user_name = wtb_depo.user_name " +
|
" INNER JOIN wtb_depo on wtb_users.user_name = wtb_depo.user_name " +
|
||||||
" WHERE wtb_users.key_group = '10' AND " +
|
" WHERE wtb_users.key_group = '10' AND " +
|
||||||
@@ -143,55 +147,46 @@ public class VariazioniPvExportServices {
|
|||||||
" wtb_users_info.export_type = " + UtilityDB.valueToString(type) + " AND " +
|
" wtb_users_info.export_type = " + UtilityDB.valueToString(type) + " AND " +
|
||||||
" wtb_users_info.format_file = " + UtilityDB.valueToString(format);
|
" wtb_users_info.format_file = " + UtilityDB.valueToString(format);
|
||||||
|
|
||||||
PreparedStatement ps = multiDBPv.prepareStatement(query);
|
HashMap<String, Object> datiUtente = UtilityDB.executeSimpleQueryOnlyFirstRow(multiDBPv.getPrimaryConnection(), query);
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
if (rs.next()) {
|
|
||||||
String userName = rs.getString(1);
|
|
||||||
String password = rs.getString(2);
|
|
||||||
String salvataggioRemoto = rs.getString(3);
|
|
||||||
|
|
||||||
if ("N".equalsIgnoreCase(salvataggioRemoto)) {
|
if (!UtilityHashMap.isPresent(datiUtente))
|
||||||
throw new Exception(String.format("Impossobile esportare le variazioni del punto vendita %s. Non è attivo il salvataggio in remoto del file.", listino.getCodMdep()));
|
throw new Exception(String.format("Nessun utente trovato per il punto vendita %s", fileVariazioniDTO.getCodVlis()));
|
||||||
}
|
|
||||||
|
|
||||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
String userName = UtilityHashMap.getValueIfExists(datiUtente, "user_name");
|
||||||
//marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
String password = UtilityHashMap.getValueIfExists(datiUtente, "password");
|
||||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
|
String salvataggioRemoto = UtilityHashMap.getValueIfExists(datiUtente, "salvataggio_remoto", "N");
|
||||||
//marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
|
||||||
|
|
||||||
StringWriter fileXmlListino = new StringWriter();
|
if ("N".equalsIgnoreCase(salvataggioRemoto))
|
||||||
marshaller.marshal(fileVariazioniDTO, fileXmlListino);
|
throw new Exception(String.format("Impossobile esportare le variazioni del punto vendita %s. Non è attivo il salvataggio in remoto del file.", listino.getCodMdep()));
|
||||||
//xmlStreamWriter.writeEndDocument();
|
|
||||||
String xmlVariazioni = fileXmlListino.toString();
|
|
||||||
//variazioniPvDTO.setFileXml(Base64.encodeBase64String(xmlVariazioni.getBytes("UTF-8")));
|
|
||||||
variazioniPvDTO.setFileXml(xmlVariazioni);
|
|
||||||
StringBuilder jsonResponse = new StringBuilder();
|
|
||||||
String url = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "WEBSERVICE", "WS_ENDPOINT_REST");
|
|
||||||
if (UtilityString.isNullOrEmpty(url)) {
|
|
||||||
url = "localhost:8080";
|
|
||||||
}
|
|
||||||
HashMap<String, String> param = new HashMap<String, String>();
|
|
||||||
param.put("profileDb", profileDB);
|
|
||||||
param.put("tipoReport", variazioniPvDTO.getTipoReport());
|
|
||||||
param.put("dataValidita", new SimpleDateFormat("dd/MM/yyyy").format(variazioniPvDTO.getDataValidita()));
|
|
||||||
int requestStatusCode = HttpRestWrapper.callGeneric("http://" + url + "/ems-api/exportVariazioniPv", userName, password, xmlVariazioni, ContentType.TEXT_PLAIN, jsonResponse, param);
|
|
||||||
|
|
||||||
if (requestStatusCode != 200) {
|
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||||
throw new Exception(String.format("Non è stato possibile chiamare il servizio di esportazione variazioni (Status: %d)", requestStatusCode));
|
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
|
||||||
} else {
|
|
||||||
ServiceRestResponse responseObject = jsonObjectMapper.readValue(jsonResponse.toString(), ServiceRestResponse.class);
|
StringWriter fileXmlListino = new StringWriter();
|
||||||
if (responseObject.getEsito() == EsitoType.KO) {
|
marshaller.marshal(fileVariazioniDTO, fileXmlListino);
|
||||||
throw new Exception(responseObject.getErrorMessage());
|
String xmlVariazioni = fileXmlListino.toString();
|
||||||
}
|
variazioniPvDTO.setFileXml(xmlVariazioni);
|
||||||
|
StringBuilder jsonResponse = new StringBuilder();
|
||||||
|
String url = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "WEBSERVICE", "WS_ENDPOINT_REST");
|
||||||
|
if (UtilityString.isNullOrEmpty(url)) url = "localhost:8080";
|
||||||
|
|
||||||
|
HashMap<String, String> param = new HashMap<>();
|
||||||
|
param.put("profileDb", profileDB);
|
||||||
|
param.put("type", type);
|
||||||
|
param.put("format", format);
|
||||||
|
String json = jsonObjectMapper.writeValueAsString(variazioniPvDTO);
|
||||||
|
int requestStatusCode = HttpRestWrapper.callGeneric("http://" + url + "/ems-api/export", userName, password, json, ContentType.APPLICATION_JSON, jsonResponse, param);
|
||||||
|
|
||||||
|
if (requestStatusCode != 200) {
|
||||||
|
throw new Exception(String.format("Non è stato possibile chiamare il servizio di esportazione variazioni (Status: %d)", requestStatusCode));
|
||||||
|
} else {
|
||||||
|
ServiceRestResponse responseObject = jsonObjectMapper.readValue(jsonResponse.toString(), ServiceRestResponse.class);
|
||||||
|
if (responseObject.getEsito() == EsitoType.KO) {
|
||||||
|
throw new Exception(responseObject.getErrorMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
multiDBPv.closeAll();
|
multiDBPv.closeAll();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,12 +210,32 @@ public class VariazioniPvExportServices {
|
|||||||
if (!UtilityString.isNullOrEmpty(wtbUsersInfo.getFileName())) {
|
if (!UtilityString.isNullOrEmpty(wtbUsersInfo.getFileName())) {
|
||||||
fileName = UtilityString.replaceSubString(wtbUsersInfo.getFileName(), "%", fileName);
|
fileName = UtilityString.replaceSubString(wtbUsersInfo.getFileName(), "%", fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean saveLog = setupGest.getExportSetupBoolean(multiDBTransactionManager.getPrimaryConnection(), type, format, "SAVE_LOG");
|
||||||
|
|
||||||
|
if ( saveLog ) {
|
||||||
|
String json = null;
|
||||||
|
if (variazioniPvDTO != null && variazioniPvDTO.getVariazioni() != null ){
|
||||||
|
json = jsonObjectMapper.writeValueAsString(variazioniPvDTO.getVariazioni());
|
||||||
|
}
|
||||||
|
NtbVariazioniExportLog ntbVariazioniExportLog =
|
||||||
|
new NtbVariazioniExportLog()
|
||||||
|
.setDataExport(new Date())
|
||||||
|
.setCodVlis(variazioniPvDTO.getCodVlis())
|
||||||
|
.setFormatFile(format)
|
||||||
|
.setJsonString(json)
|
||||||
|
.setXmlFileName(fileName + ".xml")
|
||||||
|
.setUserName(variazioniPvDTO.getUserName());
|
||||||
|
ntbVariazioniExportLog.setOperation(OperationType.INSERT);
|
||||||
|
extraInfo.add(ntbVariazioniExportLog);
|
||||||
|
}
|
||||||
fileName = pathFile + File.separator + fileName + ".xml";
|
fileName = pathFile + File.separator + fileName + ".xml";
|
||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
IOUtils.write(fileXml.toString().getBytes("UTF-8"), fos);
|
IOUtils.write(fileXml.toString().getBytes("UTF-8"), fos);
|
||||||
fos.flush();
|
fos.flush();
|
||||||
IOUtils.closeQuietly(fos);
|
IOUtils.closeQuietly(fos);
|
||||||
|
entityExportResponse.setExtraInfo(extraInfo);
|
||||||
entityExportResponse.getResponse().add(file);
|
entityExportResponse.getResponse().add(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +256,7 @@ public class VariazioniPvExportServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (jsonBody != null) {
|
if (jsonBody != null) {
|
||||||
ResponseJSONObjectMapper mapper = new ResponseJSONObjectMapper();
|
variazioniPvDTO = jsonObjectMapper.readValue(jsonBody.toString(), VariazioniPvInputDTO.class);
|
||||||
variazioniPvDTO = mapper.readValue(jsonBody.toString(), VariazioniPvInputDTO.class);
|
|
||||||
}
|
}
|
||||||
if (variazioniPvDTO.getDataValidita() == null) {
|
if (variazioniPvDTO.getDataValidita() == null) {
|
||||||
variazioniPvDTO.setDataValidita(UtilityDate.RelativeDateTime(new Date(), 1));
|
variazioniPvDTO.setDataValidita(UtilityDate.RelativeDateTime(new Date(), 1));
|
||||||
|
|||||||
Reference in New Issue
Block a user