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;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.retail.ReportVariazioni.dto.VariazioniPvInputDTO;
|
||||
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.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -22,6 +25,9 @@ public class VariazioniPvController {
|
||||
@Autowired
|
||||
private VariazioniPvService variazioniPvService;
|
||||
|
||||
@Autowired
|
||||
private RequestDataDTO requestData;
|
||||
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
@@ -52,6 +58,15 @@ public class VariazioniPvController {
|
||||
@RequestParam(required = false) String tipoReport,
|
||||
@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);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
@@ -315,6 +315,14 @@ public class VariazioniPvService {
|
||||
codMartType.getContent().add(codMart);
|
||||
|
||||
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.createCodMartTypeUntMis(UtilityString.streNull(var.getUntMis())));
|
||||
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);
|
||||
}
|
||||
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.createCodMartTypeCodAliq(UtilityString.streNull(var.getCodAliq())));
|
||||
codMartType.getContent().add(objectFactory.createCodMartTypeArticoloComposto(UtilityString.streNull(var.getArticoloComposto())));
|
||||
@@ -1108,13 +1108,14 @@ public class VariazioniPvService {
|
||||
}
|
||||
|
||||
boolean existVariazioni = false;
|
||||
if (variazioniPvInputDTO != null)
|
||||
Date dataValidita = null;
|
||||
if (variazioniPvInputDTO != null) {
|
||||
existVariazioni = (variazioniPvInputDTO.getVariazioni() != null && !variazioniPvInputDTO.getVariazioni().isEmpty());
|
||||
|
||||
Date dataValidita = variazioniPvInputDTO.getDataValidita();
|
||||
dataValidita = variazioniPvInputDTO.getDataValidita();
|
||||
}
|
||||
|
||||
if (dataValidita == null)
|
||||
dataValidita = UtilityDate.RelativeDateTime(new Date(), 1);
|
||||
dataValidita = UtilityDate.RelativeDateTime(UtilityDate.getTodayWithoutTime(), 1);
|
||||
|
||||
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");
|
||||
|
||||
emailForLog = "g.scorrano@integry.it";
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(emailForLog)) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -1310,6 +1309,25 @@ public class VariazioniPvService {
|
||||
if (testError)
|
||||
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;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.ems.export.base.BaseEntityExporter;
|
||||
import it.integry.ems.export.base.EntityExportResponse;
|
||||
import it.integry.ems.export.base.IEntityExporter;
|
||||
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.WebApplicationContext;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 {
|
||||
Connection conn = multiDBTransactionManager.getPrimaryDatasource().getConnection();
|
||||
//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.utility.UtilityDirs;
|
||||
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.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityDate;
|
||||
import it.integry.ems_model.utility.UtilityHashMap;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -41,8 +45,6 @@ import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@@ -58,58 +60,60 @@ public class VariazioniPvExportServices {
|
||||
private SetupGest setupGest;
|
||||
@Autowired
|
||||
private ResponseJSONObjectMapper jsonObjectMapper;
|
||||
|
||||
@Autowired
|
||||
private VariazioniPvService variazioniPvService;
|
||||
|
||||
|
||||
public EntityExportResponse xmlDialogo(String type, String format, String whereCond, JsonNode jsonBody, WtbUsersInfo wtbUsersInfo) throws Exception {
|
||||
String fileXml = null;
|
||||
VariazioniPvInputDTO variazioniPvDTO = new VariazioniPvInputDTO();
|
||||
String fileXml;
|
||||
List<EntityBase> extraInfo = new ArrayList<>();
|
||||
|
||||
EntityExportResponse<List<File>> entityExportResponse = new EntityExportResponse<>();
|
||||
entityExportResponse.setResponse(new ArrayList<File>());
|
||||
boolean isSingleLisv = false;
|
||||
entityExportResponse.setResponse(new ArrayList<>());
|
||||
|
||||
|
||||
Map<String, String> setup = setupGest.getExportSetupSection(multiDBTransactionManager.getPrimaryConnection(), type, format);
|
||||
|
||||
VariazioniPvInputDTO variazioniPvDTO = null;
|
||||
if (jsonBody != null) {
|
||||
ResponseJSONObjectMapper mapper = new ResponseJSONObjectMapper();
|
||||
variazioniPvDTO = mapper.readValue(jsonBody.toString(), VariazioniPvInputDTO.class);
|
||||
variazioniPvDTO = jsonObjectMapper.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) {
|
||||
variazioniPvDTO.setDataValidita(UtilityDate.RelativeDateTime(new Date(), 1));
|
||||
variazioniPvDTO.setDataValidita( UtilityDate.RelativeDateTime(new Date(), 1));
|
||||
}
|
||||
if (variazioniPvDTO.getTipoReportEnum() == null) {
|
||||
variazioniPvDTO.setTipoReportEnum(VariazioniReportType.VARIAZIONI);
|
||||
|
||||
}
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(whereCond) && UtilityString.isNullOrEmpty(variazioniPvDTO.getWhereCondArt())) {
|
||||
variazioniPvDTO.setWhereCondArt(whereCond);
|
||||
} else if (UtilityString.isNullOrEmpty(whereCond) && UtilityString.isNullOrEmpty(variazioniPvDTO.getWhereCondArt()) &&
|
||||
wtbUsersInfo != null) {
|
||||
String query =
|
||||
"SELECT cod_vlis " +
|
||||
" FROM wtb_depo INNER JOIN mtb_depo ON wtb_depo.cod_mdep = mtb_depo.cod_mdep " +
|
||||
" WHERE wtb_depo.user_name = " + UtilityDB.valueToString(wtbUsersInfo.getUserName());
|
||||
PreparedStatement ps = multiDBTransactionManager.prepareStatement(query);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
String codVlis = rs.getString(1);
|
||||
if (!existJson) {
|
||||
if (!UtilityString.isNullOrEmpty(whereCond) && UtilityString.isNullOrEmpty(variazioniPvDTO.getWhereCondArt())) {
|
||||
variazioniPvDTO.setWhereCondArt(whereCond);
|
||||
} else if (UtilityString.isNullOrEmpty(whereCond) && UtilityString.isNullOrEmpty(variazioniPvDTO.getWhereCondArt()) &&
|
||||
wtbUsersInfo != null) {
|
||||
String query =
|
||||
"SELECT cod_vlis " +
|
||||
" FROM wtb_depo INNER JOIN mtb_depo ON wtb_depo.cod_mdep = mtb_depo.cod_mdep " +
|
||||
" WHERE wtb_depo.user_name = " + UtilityDB.valueToString(wtbUsersInfo.getUserName());
|
||||
String codVlis = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), query);
|
||||
if (!UtilityString.isNullOrEmpty(codVlis)) {
|
||||
whereCond = "vtb_list.cod_vlis = " + UtilityDB.valueToString(codVlis);
|
||||
variazioniPvDTO.setWhereCondLisv(whereCond);
|
||||
variazioniPvDTO.setWhereCondArt(whereCond);
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
fileXml = variazioniPvService.variazionePrezzoPVXml(variazioniPvDTO);
|
||||
} else {
|
||||
//fileXml = new String(Base64.decodeBase64(variazioniPvDTO.getFileXml()), "UTF-8");
|
||||
fileXml = variazioniPvDTO.getFileXml();
|
||||
logger.trace(String.format(VariazioniPvExportServices.class.getSimpleName() + " %s %s", variazioniPvDTO.getCodVlis(), variazioniPvDTO.getTipoReport()));
|
||||
}
|
||||
|
||||
boolean isSingleLisv = false;
|
||||
if (!UtilityString.isNullOrEmpty(fileXml)) {
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(ReportType.class);
|
||||
Source source = new StreamSource(new StringReader(fileXml));
|
||||
@@ -135,7 +139,7 @@ public class VariazioniPvExportServices {
|
||||
String query =
|
||||
"SELECT wtb_users.user_name, " +
|
||||
" 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 " +
|
||||
" INNER JOIN wtb_depo on wtb_users.user_name = wtb_depo.user_name " +
|
||||
" 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.format_file = " + UtilityDB.valueToString(format);
|
||||
|
||||
PreparedStatement ps = multiDBPv.prepareStatement(query);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
String userName = rs.getString(1);
|
||||
String password = rs.getString(2);
|
||||
String salvataggioRemoto = rs.getString(3);
|
||||
HashMap<String, Object> datiUtente = UtilityDB.executeSimpleQueryOnlyFirstRow(multiDBPv.getPrimaryConnection(), query);
|
||||
|
||||
if ("N".equalsIgnoreCase(salvataggioRemoto)) {
|
||||
throw new Exception(String.format("Impossobile esportare le variazioni del punto vendita %s. Non è attivo il salvataggio in remoto del file.", listino.getCodMdep()));
|
||||
}
|
||||
if (!UtilityHashMap.isPresent(datiUtente))
|
||||
throw new Exception(String.format("Nessun utente trovato per il punto vendita %s", fileVariazioniDTO.getCodVlis()));
|
||||
|
||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||
//marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
|
||||
//marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
||||
String userName = UtilityHashMap.getValueIfExists(datiUtente, "user_name");
|
||||
String password = UtilityHashMap.getValueIfExists(datiUtente, "password");
|
||||
String salvataggioRemoto = UtilityHashMap.getValueIfExists(datiUtente, "salvataggio_remoto", "N");
|
||||
|
||||
StringWriter fileXmlListino = new StringWriter();
|
||||
marshaller.marshal(fileVariazioniDTO, fileXmlListino);
|
||||
//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 ("N".equalsIgnoreCase(salvataggioRemoto))
|
||||
throw new Exception(String.format("Impossobile esportare le variazioni del punto vendita %s. Non è attivo il salvataggio in remoto del file.", listino.getCodMdep()));
|
||||
|
||||
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());
|
||||
}
|
||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
|
||||
|
||||
StringWriter fileXmlListino = new StringWriter();
|
||||
marshaller.marshal(fileVariazioniDTO, fileXmlListino);
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,12 +210,32 @@ public class VariazioniPvExportServices {
|
||||
if (!UtilityString.isNullOrEmpty(wtbUsersInfo.getFileName())) {
|
||||
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";
|
||||
File file = new File(fileName);
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
IOUtils.write(fileXml.toString().getBytes("UTF-8"), fos);
|
||||
fos.flush();
|
||||
IOUtils.closeQuietly(fos);
|
||||
entityExportResponse.setExtraInfo(extraInfo);
|
||||
entityExportResponse.getResponse().add(file);
|
||||
}
|
||||
|
||||
@@ -241,8 +256,7 @@ public class VariazioniPvExportServices {
|
||||
}
|
||||
|
||||
if (jsonBody != null) {
|
||||
ResponseJSONObjectMapper mapper = new ResponseJSONObjectMapper();
|
||||
variazioniPvDTO = mapper.readValue(jsonBody.toString(), VariazioniPvInputDTO.class);
|
||||
variazioniPvDTO = jsonObjectMapper.readValue(jsonBody.toString(), VariazioniPvInputDTO.class);
|
||||
}
|
||||
if (variazioniPvDTO.getDataValidita() == null) {
|
||||
variazioniPvDTO.setDataValidita(UtilityDate.RelativeDateTime(new Date(), 1));
|
||||
|
||||
Reference in New Issue
Block a user