Merge branch 'master' 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:
@@ -549,10 +549,32 @@ public class EmsController {
|
||||
@RequestBody(required = false) JsonNode body) throws Exception {
|
||||
|
||||
EntityExportResponse<?> entityExportResponse = emsServices.export(typeExport, formatExport, body, headless);
|
||||
List<MessageDTO> messages = new ArrayList<>();
|
||||
|
||||
if (entityExportResponse.getAnomalie() != null && !entityExportResponse.getAnomalie().isEmpty()) {
|
||||
messages = entityExportResponse.getAnomalie().stream()
|
||||
.filter(x -> x.getTipo() != null)
|
||||
.map(x -> {
|
||||
switch (x.getTipo()) {
|
||||
case ERROR:
|
||||
return MessageDTO.error(x.getMessage());
|
||||
case WARNING:
|
||||
default:
|
||||
return MessageDTO.warning(x.getMessage());
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
ServiceRestResponse sr;
|
||||
if (!messages.isEmpty() && messages.stream().anyMatch(x->x.getLevel()==(MessageDTO.Level.ERROR))) {
|
||||
sr = ServiceRestResponse.createNegativeResponse();
|
||||
} else {
|
||||
sr = ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
sr.setMessages(messages);
|
||||
|
||||
ServiceRestResponse sr = ServiceRestResponse.createPositiveResponse();
|
||||
if (entityExportResponse != null) {
|
||||
|
||||
if (binaryDownload) {
|
||||
List<DownloadFileDto> downloadableFileList = new ArrayList<>();
|
||||
for (EntityExportedFile exportedFile : (List<EntityExportedFile>) entityExportResponse.getResponse()) {
|
||||
|
||||
@@ -19,7 +19,8 @@ public enum EntityExportType {
|
||||
LISTINI_ACQUISTO("LISTINI ACQUISTO"),
|
||||
LISTINI_VENDITA("LISTINI VENDITA"),
|
||||
COLLI("COLLI"),
|
||||
SCADENZE("SCADENZE");
|
||||
SCADENZE("SCADENZE"),
|
||||
SCONTRINI("SCONTRINI");
|
||||
|
||||
private String text;
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ public class CsvMapper<T> {
|
||||
List<Field> declaredFields = Arrays.asList(dtoList.get(0).getClass().getDeclaredFields());
|
||||
|
||||
List<Field> sortedFields = Stream.of(declaredFields)
|
||||
.filter(x -> x.getAnnotation(DtoField.class) != null && x.getAnnotation(DtoField.class).startPosition() >= 0)
|
||||
.filter(x -> x.getAnnotation(DtoField.class) != null &&
|
||||
x.getAnnotation(DtoField.class).startPosition() >= 0)
|
||||
.sortBy(x -> x.getAnnotation(DtoField.class).startPosition())
|
||||
.toList();
|
||||
|
||||
@@ -39,7 +40,7 @@ public class CsvMapper<T> {
|
||||
String header = StringUtils.join(Stream
|
||||
.of(sortedFields).map(
|
||||
x -> x.getName()
|
||||
).toList(), CommonConstants.TAB);
|
||||
).toList(), splitChar);
|
||||
|
||||
return serialize(dtoList, splitChar, header, hasHeader);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class LicenseController {
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||
public @ResponseBody ServiceRestResponse retrieve(@RequestParam(CommonConstants.PROFILE_DB) String profile) {
|
||||
LicenseStatusDTO licenseStatusDTO = licenseComponent.getLicenseStatus(profile);
|
||||
LicenseStatusDTO licenseStatusDTO = licenseComponent.getLicenseStatus(profile.toUpperCase());
|
||||
|
||||
if(licenseStatusDTO == null) return ServiceRestResponse.createPositiveResponse();
|
||||
return ServiceRestResponse.createPositiveResponse(licenseStatusDTO);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
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_20250407083930 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "ATTIVO", "N",
|
||||
"Inserire S/N per attivare/disattivare il tipo di importazione", false, null, false, false,
|
||||
false, false, false, null, false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "EMAIL_FOR_LOG", null,
|
||||
"Inserire il file l'indirizzo email per inviare il log dell'importazione", false, null, false, false,
|
||||
false, false, false, null, false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "GG_CANC_FILE", null,
|
||||
"Giorni per la cancellazione dei file dalla cartella di appoggio", false, null, false, false,
|
||||
false, false, false, null, false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "IMPORT_REST", "S",
|
||||
"Inserire S/N per attivare/disattivare il salvataggio con i servizi REST", false, null, false, false,
|
||||
false, false, false, null, false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "PATH_FILE", null,
|
||||
"Directory dove vengono salvati i file temporanei, se non è configurata i file saranno salvati in c:\\mlSetupWS\\TEMP_EXPORT", false, null, false, false,
|
||||
false, false, false, null, false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "INTERCODE_REPARTO", null,
|
||||
"codice identificativo del reparto", true, null, true, false,
|
||||
false, false, false, "mtb_grup", false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "INTERCODE_AZIENDA", null,
|
||||
"codice identificativo dell'azienda", false, null, true, false,
|
||||
false, false, false, null, false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "INTERCODE_PV", null,
|
||||
"codice identificativo del punto vendita", true, null, true, true,
|
||||
false, false, false, null, false, null);
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Carelli_GestFood) || isCustomerDb(IntegryCustomerDB.Carelli_Carelli)){
|
||||
updateSetupValue("EXPORT_SCONTRINI", "ZUCCHETTI", "ATTIVO", "S");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250407084809 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "ATTRIBUTO_FATTURATO", null,
|
||||
"codice identificativo del reparto", true, null, true, false,
|
||||
false, false, false, null, false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "ATTRIBUTO_SCONTRINI", null,
|
||||
"codice identificativo dell'azienda", false, null, true, false,
|
||||
false, false, false, null, false, null);
|
||||
createSetup("EXPORT_SCONTRINI", "ZUCCHETTI", "ATTRIBUTO_BATTUTE", null,
|
||||
"codice identificativo del punto vendita", true, null, true, false,
|
||||
false, false, false, null, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import it.integry.ems.export.base.EntityExporterUtility;
|
||||
import it.integry.ems.export.enums.EntityExportType;
|
||||
import it.integry.ems.retail.Import.RapportiniFgImporter;
|
||||
import it.integry.ems.retail.Import.ScontriniImporter;
|
||||
import it.integry.ems.retail.export.ScontriniExporter;
|
||||
import it.integry.ems.retail.export.VariazioniExporter;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -23,6 +24,7 @@ public class EmsRetailContext {
|
||||
logger.debug("Init");
|
||||
|
||||
EntityExporterUtility.addTypeBinding(EntityExportType.VARIAZIONE_PV, VariazioniExporter.class);
|
||||
EntityExporterUtility.addTypeBinding(EntityExportType.SCONTRINI, ScontriniExporter.class);
|
||||
|
||||
EntityImporterUtility.addTypeBinding(EntityImportType.RAPPORTINI_FG, RapportiniFgImporter.class);
|
||||
EntityImporterUtility.addTypeBinding(EntityImportType.SCONTRINI, ScontriniImporter.class);
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package it.integry.ems.retail.dto;
|
||||
|
||||
import it.integry.ems_model.annotation.DtoField;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class ZucchettiHrDTO {
|
||||
|
||||
@DtoField(maxLength = 3, startPosition = 1)
|
||||
private String tipoRecord = "F01";
|
||||
@DtoField(maxLength = 1, startPosition = 4)
|
||||
private String modalitaOperativa = "C";
|
||||
@DtoField(maxLength = 30, startPosition = 5)
|
||||
private String tabellaRiferimento = "DATI_EFFETTIVI";
|
||||
@DtoField(maxLength = 6, startPosition = 35)
|
||||
private String codiceAzienda;
|
||||
@DtoField(maxLength = 6, startPosition = 41)
|
||||
private String codiceReparto = "000000"; // 6 caratteri
|
||||
@DtoField(maxLength = 10, startPosition = 47)
|
||||
private String codiceFiliale;
|
||||
@DtoField(maxLength = 15, startPosition = 57)
|
||||
private String centroCosto = "000000000000000"; // 15 caratteri
|
||||
@DtoField(maxLength = 5, startPosition = 58)
|
||||
private String businessUnit = "00000"; // 5 caratteri
|
||||
@DtoField(maxLength = 6, startPosition = 64 )
|
||||
private String codiceUnitaLocale = "000000"; // 6 caratteri
|
||||
@DtoField(maxLength = 15, startPosition = 70)
|
||||
private String codiceInternalOrder = "000000000000000"; // 15 caratteri
|
||||
@DtoField(maxLength = 10, startPosition = 85)
|
||||
private String data;
|
||||
@DtoField(showFloatPoint = true, separator = ".", scale = 2, maxLength = 5, startPosition = 95)
|
||||
private BigDecimal orarioInizio;
|
||||
@DtoField(showFloatPoint = true, separator = ".", scale = 2, maxLength = 5, startPosition = 100)
|
||||
private BigDecimal orarioFine;
|
||||
@DtoField(maxLength = 10, startPosition = 105)
|
||||
private String codiceAttributo;
|
||||
@DtoField(showFloatPoint = true, separator = ".", scale = 2, maxLength = 16, startPosition = 115)
|
||||
private BigDecimal valore;
|
||||
|
||||
public String getTipoRecord() {
|
||||
return tipoRecord;
|
||||
}
|
||||
|
||||
public String getModalitaOperativa() {
|
||||
return modalitaOperativa;
|
||||
}
|
||||
|
||||
public String getTabellaRiferimento() {
|
||||
return tabellaRiferimento;
|
||||
}
|
||||
|
||||
public String getCodiceAzienda() {
|
||||
return codiceAzienda;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setCodiceAzienda(String codiceAzienda) {
|
||||
this.codiceAzienda = codiceAzienda;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodiceReparto() {
|
||||
return codiceReparto;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setCodiceReparto(String codiceReparto) {
|
||||
this.codiceReparto = codiceReparto;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodiceFiliale() {
|
||||
return codiceFiliale;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setCodiceFiliale(String codiceFiliale) {
|
||||
this.codiceFiliale = codiceFiliale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCentroCosto() {
|
||||
return centroCosto;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setCentroCosto(String centroCosto) {
|
||||
this.centroCosto = centroCosto;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getBusinessUnit() {
|
||||
return businessUnit;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setBusinessUnit(String businessUnit) {
|
||||
this.businessUnit = businessUnit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodiceUnitaLocale() {
|
||||
return codiceUnitaLocale;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setCodiceUnitaLocale(String codiceUnitaLocale) {
|
||||
this.codiceUnitaLocale = codiceUnitaLocale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodiceInternalOrder() {
|
||||
return codiceInternalOrder;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setCodiceInternalOrder(String codiceInternalOrder) {
|
||||
this.codiceInternalOrder = codiceInternalOrder;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setData(String data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getOrarioInizio() {
|
||||
return orarioInizio;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setOrarioInizio(BigDecimal orarioInizio) {
|
||||
this.orarioInizio = orarioInizio;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getOrarioFine() {
|
||||
return orarioFine;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setOrarioFine(BigDecimal orarioFine) {
|
||||
this.orarioFine = orarioFine;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodiceAttributo() {
|
||||
return codiceAttributo;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setCodiceAttributo(String codiceAttributo) {
|
||||
this.codiceAttributo = codiceAttributo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getValore() {
|
||||
return valore;
|
||||
}
|
||||
|
||||
public ZucchettiHrDTO setValore(BigDecimal valore) {
|
||||
this.valore = valore;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package it.integry.ems.retail.export;
|
||||
|
||||
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.ScontriniZucchettiExportServices;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
|
||||
public class ScontriniExporter extends BaseEntityExporter implements IEntityExporter {
|
||||
@Override
|
||||
public EntityExportResponse doExport() throws Exception {
|
||||
ScontriniExporter.Format currentFormatEnum = ScontriniExporter.Format.fromString(super.format);
|
||||
|
||||
EntityExportResponse entityExportResponse = null;
|
||||
|
||||
if (currentFormatEnum != null) {
|
||||
|
||||
switch (currentFormatEnum) {
|
||||
case ZUCCHETTI:
|
||||
ScontriniZucchettiExportServices scontriniExportServices = ContextLoader.getCurrentWebApplicationContext().getBean(ScontriniZucchettiExportServices.class);
|
||||
entityExportResponse = scontriniExportServices.exportZucchetti(type, format, whereCond, anomalie);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return entityExportResponse;
|
||||
|
||||
}
|
||||
|
||||
public enum Format {
|
||||
ZUCCHETTI("ZUCCHETTI");
|
||||
|
||||
private String text;
|
||||
|
||||
Format(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static ScontriniExporter.Format fromString(String text) {
|
||||
for (ScontriniExporter.Format b : ScontriniExporter.Format.values()) {
|
||||
if (b.text.equalsIgnoreCase(text)) return b;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package it.integry.ems.retail.export.service;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||
import it.integry.ems.export.base.EntityExportResponse;
|
||||
import it.integry.ems.file_formatter.csv.CsvMapper;
|
||||
import it.integry.ems.retail.dto.ZucchettiHrDTO;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
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.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Scope("request")
|
||||
public class ScontriniZucchettiExportServices {
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
@Autowired
|
||||
private SetupGest setupGest;
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
public EntityExportResponse exportZucchetti(String type, String format, String whereCond, List<AnomalieDTO> anomalie) throws Exception {
|
||||
EntityExportResponse<List<File>> entityExportResponse = new EntityExportResponse<>();
|
||||
entityExportResponse.setResponse(new ArrayList<>());
|
||||
Map<String, String> exportSetupSection = setupGest.getExportSetupSection(multiDBTransactionManager.getPrimaryConnection(), type, format);
|
||||
|
||||
String intercodeAzienda = getSetupValue(type, format, exportSetupSection, "INTERCODE_AZIENDA");
|
||||
String attributoFatturato = getSetupValue(type, format, exportSetupSection, "ATTRIBUTO_FATTURATO");
|
||||
String attributoBattute = getSetupValue(type, format, exportSetupSection, "ATTRIBUTO_BATTUTE");
|
||||
String attributoScontrini = getSetupValue(type, format, exportSetupSection, "ATTRIBUTO_SCONTRINI");
|
||||
|
||||
String sql =
|
||||
Query.format(
|
||||
"SELECT cod_mdep,\n" +
|
||||
" value AS intercode\n" +
|
||||
"FROM stb_gest_setup_depo\n" +
|
||||
"WHERE gest_name = %s\n" +
|
||||
" AND section = %s\n" +
|
||||
" AND key_section = 'INTERCODE_PV'",
|
||||
"EXPORT_" + type, format);
|
||||
List<HashMap<String, Object>> setupDepo = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
sql = Query.format(
|
||||
"SELECT val_col_rif as cod_mgrp,\n" +
|
||||
" value AS intercode\n" +
|
||||
"FROM stb_gest_setup_det\n" +
|
||||
"WHERE gest_name = %s\n" +
|
||||
" AND section = %s\n" +
|
||||
" AND key_section = 'INTERCODE_REPARTO'\n" +
|
||||
" AND tipo_setup = 'mtb_grup' ",
|
||||
"EXPORT_" + type, format);
|
||||
List<HashMap<String, Object>> setupReparti = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (UtilityString.isNullOrEmpty(whereCond)) {
|
||||
whereCond = "ntb_doct.date_only_doc = " + UtilityDB.valueDateToString(new Date(), CommonConstants.DATE_FORMAT_YMD);
|
||||
}
|
||||
|
||||
sql =
|
||||
"SELECT ntb_doct.cod_mdep,\n" +
|
||||
" ntb_doct.date_only_doc AS data,\n" +
|
||||
" CONVERT(VARCHAR(5), MIN(ntb_doct.data_doc), 108) AS ora_iniz,\n" +
|
||||
" CONVERT(VARCHAR(5), MAX(ntb_doct.data_doc), 108) AS ora_fine,\n" +
|
||||
" mtb_aart.cod_mgrp,\n" +
|
||||
" CAST(\n" +
|
||||
" CAST(DATEDIFF(MINUTE, ntb_doct.date_only_doc, ntb_doct.data_doc) AS FLOAT) / 30 AS INT) AS gruppo_ore,\n" +
|
||||
" SUM(ntb_docr.qta_doc) AS qta,\n" +
|
||||
" SUM((ntb_docr.qta_doc * ntb_docr.prz_unt_iva) - ntb_docr.val_sco) AS valore,\n" +
|
||||
" COUNT(DISTINCT ntb_doct.id_scontr) AS count_scontrini,\n" +
|
||||
" COUNT(*) AS count_battute\n" +
|
||||
"FROM ntb_doct\n" +
|
||||
" INNER JOIN ntb_docr ON ntb_doct.cod_mdep = ntb_docr.cod_mdep\n" +
|
||||
" AND ntb_doct.cod_cassa = ntb_docr.cod_cassa\n" +
|
||||
" AND ntb_doct.data_doc = ntb_docr.data_doc\n" +
|
||||
" INNER JOIN mtb_aart ON ntb_docr.cod_mart = mtb_aart.cod_mart\n" +
|
||||
"GROUP BY ntb_doct.cod_mdep, ntb_doct.date_only_doc,\n" +
|
||||
" CAST(\n" +
|
||||
" CAST(DATEDIFF(MINUTE, ntb_doct.date_only_doc, ntb_doct.data_doc) AS FLOAT) / 30 AS INT),\n" +
|
||||
" mtb_aart.cod_mgrp\n" +
|
||||
"ORDER BY ntb_doct.cod_mdep, ntb_doct.date_only_doc, 3";
|
||||
|
||||
sql = UtilityDB.addwhereCond(sql, whereCond, false );
|
||||
List<HashMap<String, Object>> scontrini = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if ( scontrini == null || scontrini.isEmpty()) {
|
||||
logger.info("Nessun scontrino trovato ");
|
||||
}
|
||||
|
||||
//Verifica intercode depositi
|
||||
List<String> depositi = scontrini.stream().map(x -> ((String) x.get("cod_mdep"))).distinct().collect(Collectors.toList());
|
||||
|
||||
for (String codMdep : depositi) {
|
||||
getIntercodePV(setupDepo, codMdep, anomalie);
|
||||
}
|
||||
|
||||
//verifica intercode reparti
|
||||
List<String> reparti = scontrini.stream().map(x -> ((String) x.get("cod_mgrp"))).distinct().collect(Collectors.toList());
|
||||
for (String codMgrp : reparti) {
|
||||
getIntecodeReparti(setupReparti, codMgrp, anomalie);
|
||||
}
|
||||
|
||||
if ( !anomalie.isEmpty() && anomalie.stream().anyMatch(x->x.isError())) {
|
||||
return entityExportResponse;
|
||||
}
|
||||
List<ZucchettiHrDTO> dati = new ArrayList<>();
|
||||
for(HashMap<String, Object> row : scontrini) {
|
||||
String intercodePv = getIntercodePV(setupDepo, (String) row.get("cod_mdep"), anomalie);
|
||||
String intercodeReparto = getIntecodeReparti(setupReparti, (String) row.get("cod_mgrp"), anomalie);
|
||||
|
||||
BigDecimal oraInizio = new BigDecimal(row.get("ora_iniz").toString().replace(":", "."));
|
||||
BigDecimal oraFine = new BigDecimal(row.get("ora_fine").toString().replace(":", "."));
|
||||
for ( int i=1; i < 4; i++) {
|
||||
String attributo;
|
||||
BigDecimal valore;
|
||||
if ( i == 1) {
|
||||
attributo = attributoFatturato + intercodeReparto;
|
||||
valore = (BigDecimal) row.get("valore");
|
||||
} else if (i == 2) {
|
||||
attributo = attributoScontrini + intercodeReparto;
|
||||
valore = new BigDecimal((Integer) row.get("count_scontrini"));
|
||||
} else {
|
||||
attributo = attributoBattute + intercodeReparto;
|
||||
valore = new BigDecimal((Integer) row.get("count_scontrini"));
|
||||
}
|
||||
|
||||
ZucchettiHrDTO zucchettiHrDTO = new ZucchettiHrDTO()
|
||||
.setCodiceAzienda(intercodeAzienda)
|
||||
.setCodiceReparto(intercodeReparto)
|
||||
.setCodiceFiliale(intercodePv)
|
||||
.setData(new SimpleDateFormat(CommonConstants.DATE_FORMAT_DMY).format(row.get("data")))
|
||||
.setOrarioInizio(oraInizio)
|
||||
.setOrarioFine(oraFine)
|
||||
.setCodiceAttributo(attributo)
|
||||
.setValore(valore);
|
||||
dati.add(zucchettiHrDTO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( !dati.isEmpty()) {
|
||||
String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".csv";
|
||||
File file = new File(fileName);
|
||||
|
||||
CsvMapper<ZucchettiHrDTO> mapper = new CsvMapper<>();
|
||||
String csv = mapper.serialize(dati, ";", false);
|
||||
FileUtils.writeStringToFile(file, csv);
|
||||
entityExportResponse.getResponse().add(file);
|
||||
}
|
||||
|
||||
return entityExportResponse;
|
||||
|
||||
}
|
||||
|
||||
private String getSetupValue(String type, String format, Map<String, String> exportSetupSection, String keySection) throws Exception {
|
||||
if (UtilityString.isNullOrEmpty(exportSetupSection.get(keySection))) {
|
||||
throw new Exception(String.format("Setup non configurata %S->%S->%S", type, format, keySection));
|
||||
} else {
|
||||
return exportSetupSection.get(keySection);
|
||||
}
|
||||
}
|
||||
|
||||
private String getIntercodePV(List<HashMap<String, Object>> setupDepo, String codMdep, List<AnomalieDTO> anomalie) throws Exception {
|
||||
String intercodePv = setupDepo.stream()
|
||||
.filter(x->((String) x.get("cod_mdep")).equalsIgnoreCase(codMdep)).findFirst().map(x->(String)x.get("intercode")).orElse(null);
|
||||
if ( intercodePv == null) {
|
||||
String errore = String.format("Intercode non trovato per il deposito %s", codMdep);
|
||||
logger.error(errore);
|
||||
anomalie.add(AnomalieDTO.error(errore));
|
||||
}
|
||||
return intercodePv;
|
||||
|
||||
}
|
||||
|
||||
private String getIntecodeReparti(List<HashMap<String, Object>> setupReparti, String codMgrp, List<AnomalieDTO> anomalie) throws Exception {
|
||||
String intercodeReparto = setupReparti.stream()
|
||||
.filter(x->((String) x.get("cod_mgrp")).equalsIgnoreCase(codMgrp)).findFirst().map(x->(String)x.get("intercode")).orElse(null);
|
||||
if ( intercodeReparto == null) {
|
||||
String errore = String.format("Intercode non trovato per il reparto %s", codMgrp);
|
||||
logger.error(errore);
|
||||
anomalie.add(AnomalieDTO.error(errore));
|
||||
}
|
||||
return intercodeReparto;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user