Aggiornata procedura pianificata di import scontrini per evitare le internal call
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good

This commit is contained in:
2025-10-03 11:13:14 +02:00
parent e436b9773e
commit b64cd203eb
15 changed files with 114 additions and 111 deletions

View File

@@ -552,7 +552,7 @@ public class EmsController {
@RequestParam(required = false, defaultValue = "true") boolean headless,
@RequestBody(required = false) JsonNode body) throws Exception {
EntityExportResponse<?> entityExportResponse = emsServices.export(typeExport, formatExport, body, headless);
EntityExportResponse<?> entityExportResponse = emsServices.export(multiDBTransactionManager, requestDataDTO, typeExport, formatExport, body, headless);
List<AnomalieDTO> anomalie = new ArrayList<>();
if (entityExportResponse != null && entityExportResponse.getAnomalie() != null && !entityExportResponse.getAnomalie().isEmpty())
@@ -608,7 +608,7 @@ public class EmsController {
@RequestParam(required = false, defaultValue = "true") boolean headless,
@RequestBody(required = false) ImportRequestDTO requestBody) throws Exception {
EntityImportResponse<List<EntityBase>> importResponse = emsServices.importEntity(importType, importFormat, requestBody, headless);
EntityImportResponse<List<EntityBase>> importResponse = emsServices.importEntity(multiDBTransactionManager, requestDataDTO, importType, importFormat, requestBody, headless);
List<EntityBase> entities = importResponse.getResponse();
@@ -733,7 +733,7 @@ public class EmsController {
@PathVariable String filename,
@RequestParam(name = "contentDisposition", defaultValue = "attachment") String contentDispositionType,
@RequestParam(defaultValue = "false") boolean requestThumbnail) throws Exception {
AttachmentDTO attachmentDTO = emsServices.downloadStbFileAttachment(idAttach, requestThumbnail);
AttachmentDTO attachmentDTO = emsServices.downloadStbFileAttachment(multiDBTransactionManager, idAttach, requestThumbnail);
if (attachmentDTO != null) {
return ResponseEntity.ok()
@@ -754,7 +754,7 @@ public class EmsController {
public ResponseEntity<byte[]> downloadFileFromRefUuid(@RequestParam(CommonConstants.PROFILE_DB) String config,
@RequestParam() String refUuid,
@RequestParam() String fileName) throws Exception {
AttachmentDTO attached = emsServices.downloadFileFromRefUuid(refUuid, fileName);
AttachmentDTO attached = emsServices.downloadFileFromRefUuid(multiDBTransactionManager, refUuid, fileName);
if (attached == null) return ResponseEntity.notFound().build();
@@ -774,7 +774,7 @@ public class EmsController {
@RequestParam(CommonConstants.PROFILE_DB) String config,
@RequestParam String idAttach,
@RequestParam(defaultValue = "false") boolean requestThumbnail) throws Exception {
AttachmentDTO attachmentDTO = emsServices.downloadStbFileAttachment(idAttach, requestThumbnail);
AttachmentDTO attachmentDTO = emsServices.downloadStbFileAttachment(multiDBTransactionManager, idAttach, requestThumbnail);
if (attachmentDTO != null) {
return ResponseEntity.ok()
@@ -927,7 +927,7 @@ public class EmsController {
throw new Exception("Sono stati inviati più file del previsto");
}
StbFilesAttached stbFilesAttached = emsServices.uploadStbFilesAttached(idAttach,
StbFilesAttached stbFilesAttached = emsServices.uploadStbFilesAttached(multiDBTransactionManager, idAttach,
files[0].getOriginalFilename(),
files[0].getBytes(),
descrizione,
@@ -1106,7 +1106,7 @@ public class EmsController {
.setCodDtip(codDtip);
drlDocAttached.setOperation(OperationType.INSERT);
StbFilesAttached stbFilesAttached = emsServices.uploadStbFilesAttached(idAttach,
StbFilesAttached stbFilesAttached = emsServices.uploadStbFilesAttached(multiDBTransactionManager, idAttach,
files[0].getOriginalFilename(),
files[0].getBytes(),
descrizione,
@@ -1125,7 +1125,7 @@ public class EmsController {
@RequestMapping(value = "createZipFromFiles", method = RequestMethod.POST)
public @ResponseBody
ServiceRestResponse createZipFromFiles(@RequestBody CreateZipDTO createZipDTO) throws Exception {
return ServiceRestResponse.createPositiveResponse(emsServices.createZipFromFiles(createZipDTO));
return ServiceRestResponse.createPositiveResponse(emsServices.createZipFromFiles(multiDBTransactionManager, createZipDTO));
}
// @RequestMapping(value = EmsRestConstants.PATH_UPLOAD_STB_EMAIL_CONTENT, method = RequestMethod.POST)
@@ -1174,7 +1174,7 @@ public class EmsController {
@RequestMapping(value = EmsRestConstants.PATH_EXPORT_SERVER_INFO_ISCC, method = RequestMethod.POST)
public @ResponseBody
ServiceRestResponse exportServerInfoISCC(@RequestParam(CommonConstants.PROFILE_DB) String config) throws Exception {
emsServices.checkServerVariables();
emsServices.checkServerVariables(multiDBTransactionManager);
return ServiceRestResponse.createPositiveResponse();
}

View File

@@ -98,6 +98,12 @@ public class RequestDataDTO {
.setPassword("sql");
}
public static RequestDataDTO scheduledOperationsMockupData() {
return new RequestDataDTO()
.setUsername("INTEGRY")
.setPassword("INTEGRY");
}
public boolean isValidProfileDB() {
return !UtilityString.isNullOrEmpty(profileDB);
}

View File

@@ -61,7 +61,6 @@ import org.apache.http.entity.ContentType;
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 javax.annotation.Nonnull;
@@ -85,10 +84,9 @@ import java.util.stream.Collectors;
import java.util.zip.ZipOutputStream;
@Service
@Scope("request")
public class EmsServices {
private Logger logger = LogManager.getLogger();
private final Logger logger = LogManager.getLogger();
@Autowired
private EmsProperties properties;
@@ -102,9 +100,6 @@ public class EmsServices {
@Autowired
private EntityProcessor entityProcessor;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private MailService mailService;
@@ -114,9 +109,6 @@ public class EmsServices {
@Autowired
private EntityPropertyHolder entityPropertyHolder;
@Autowired
private RequestDataDTO requestDataDTO;
@Autowired
private EnvProperties envProperties;
@@ -129,9 +121,6 @@ public class EmsServices {
@Autowired
private MediaVideoService mediaVideoService;
@Autowired
private MimeTypesHandler mimetypesFileTypeMap;
@Autowired
private SettingsController settingsController;
@@ -141,7 +130,8 @@ public class EmsServices {
@Autowired
private MinIOService minIOService;
public EntityImportResponse<List<EntityBase>> importEntity(String type, String format, ImportRequestDTO body, boolean headless) throws Exception {
public EntityImportResponse<List<EntityBase>> importEntity(MultiDBTransactionManager multiDBTransactionManager, RequestDataDTO requestDataDTO,
String type, String format, ImportRequestDTO body, boolean headless) throws Exception {
logger.debug("Starting import [Type: " + type + ", Format: " + format + "]");
String gestName = "IMPORT_" + type;
@@ -220,8 +210,8 @@ public class EmsServices {
if (!file.isDirectory()) {
body.setRawContent(new String(Files.readAllBytes(file.toPath())));
fileContent = ((String) body.getRawContent()).getBytes();
IEntityImporter entityImporter = EntityImporterUtility.getRightImporterClassByType(enumType).newInstance();
setEntityImporter(entityImporter, file, multiDBTransactionManager, type, format, body, headless);
IEntityImporter<?> entityImporter = EntityImporterUtility.getRightImporterClassByType(enumType).newInstance();
setEntityImporter(entityImporter, file, multiDBTransactionManager, requestDataDTO, type, format, body, headless);
// if (UtilityString.isNullOrEmpty(body.getFileName())) {
// body.setFileName(file.getName());
@@ -231,11 +221,11 @@ public class EmsServices {
List<EntityBase> tmpResult = (List<EntityBase>) entityImporter.doImport();
response.getAnomalie().addAll(entityImporter.getAnomalie());
boolean anyError = checkForErrorsAndAddToResponse(entityImporter, tmpResult, result, gestName, format, fileContent, file.getName(), anomaliaIsError, headless);
boolean anyError = checkForErrorsAndAddToResponse(multiDBTransactionManager, entityImporter, tmpResult, result, gestName, format, fileContent, file.getName(), anomaliaIsError, headless);
/* 22/01/2018 MARCO: Se la procedura di import va a buon fine, il file viene spostato nella cartella Imported a prescindere dalla presenza o meno di anomalie. */
if (!anyError && file != null && !anomaliaIsError)
moveFileImported(type, format, file, entityImporter, tmpResult);
moveFileImported(multiDBTransactionManager, type, format, file, entityImporter, tmpResult);
}
} catch (Exception ex) {
if (headless) {
@@ -260,8 +250,8 @@ public class EmsServices {
} else { // in caso sia presente solo rawContent
try {
anomaliaIsError = false;
IEntityImporter entityImporter = EntityImporterUtility.getRightImporterClassByType(enumType).newInstance();
setEntityImporter(entityImporter, null, multiDBTransactionManager, type, format, body, headless);
IEntityImporter<?> entityImporter = EntityImporterUtility.getRightImporterClassByType(enumType).newInstance();
setEntityImporter(entityImporter, null, multiDBTransactionManager, requestDataDTO, type, format, body, headless);
if (body != null && body.getRawContent() != null) {
if (body.getRawContent() instanceof String) {
@@ -288,22 +278,25 @@ public class EmsServices {
List<EntityBase> tmpResult = (List<EntityBase>) entityImporter.doImport();
response.getAnomalie().addAll(entityImporter.getAnomalie());
boolean anyError = checkForErrorsAndAddToResponse(entityImporter, tmpResult, result, gestName, format, fileContent, fileName, anomaliaIsError, headless);
boolean anyError = checkForErrorsAndAddToResponse(multiDBTransactionManager, entityImporter, tmpResult, result, gestName, format, fileContent, fileName, anomaliaIsError, headless);
if (!anyError && fileContent != null && !anomaliaIsError) {
File file = new File(fileName);
FileUtils.writeByteArrayToFile(file, fileContent);
moveFileImported(type, format, file, entityImporter, tmpResult);
moveFileImported(multiDBTransactionManager, type, format, file, entityImporter, tmpResult);
file.delete();
}
} catch (Exception ex) {
if (headless) {
List<EntityBase> entityBases = new ArrayList<EntityBase>();
EntityBase entityBase = new EntityBase(logger) {
};
EntityException newEx = new EntityException(ex.getMessage());
EntityException newEx = new EntityException(ex);
newEx.setStackTrace(ex.getStackTrace());
entityBase.setException(newEx);
entityBases.add(entityBase);
logger.error("Import entity", ex);
@@ -324,7 +317,7 @@ public class EmsServices {
}
}
private void moveFileImported(String type, String format, File file, IEntityImporter entityImporter, List<EntityBase> tmpResult) throws Exception {
private void moveFileImported(MultiDBTransactionManager multiDBTransactionManager, String type, String format, File file, IEntityImporter entityImporter, List<EntityBase> tmpResult) throws Exception {
String absolutePath = setupGest.getImportSetup(multiDBTransactionManager.getPrimaryConnection(), type, format, "PATH_FILE_IMPORTED");
if (!UtilityString.isNullOrEmpty(absolutePath) && file.exists()) {
String fileNameDest = entityImporter.renameFile(file.getName(), tmpResult);
@@ -354,6 +347,7 @@ public class EmsServices {
private IEntityImporter setEntityImporter(IEntityImporter entityImporter, File file,
MultiDBTransactionManager multiDBTransactionManager,
RequestDataDTO requestDataDTO,
String type, String format, ImportRequestDTO body, boolean headless) throws Exception {
entityImporter.setSetupGest(setupGest);
entityImporter.setMultiDBTransactionManager(multiDBTransactionManager);
@@ -387,7 +381,7 @@ public class EmsServices {
* @throws Exception
*/
private boolean checkForErrorsAndAddToResponse(IEntityImporter entityImporter, List<EntityBase> tmpResult, List<EntityBase> finalResult, String gestName, String format, byte[] fileInput, String fileName, Boolean anomaliaIsError, boolean headless) {
private boolean checkForErrorsAndAddToResponse(MultiDBTransactionManager multiDBTransactionManager, IEntityImporter entityImporter, List<EntityBase> tmpResult, List<EntityBase> finalResult, String gestName, String format, byte[] fileInput, String fileName, Boolean anomaliaIsError, boolean headless) {
boolean anyError = false;
try {
List<AnomalieDTO> anomalie = entityImporter.getAnomalie();
@@ -425,7 +419,7 @@ public class EmsServices {
return anyError;
}
private boolean checkAnomalieExport(IEntityExporter entityExporter, String gestName, String format, boolean headless) {
private boolean checkAnomalieExport(MultiDBTransactionManager multiDBTransactionManager, IEntityExporter entityExporter, String gestName, String format, boolean headless) {
boolean anyError = false;
try {
List<AnomalieDTO> anomalie = entityExporter.getAnomalie();
@@ -451,7 +445,7 @@ public class EmsServices {
}
public EntityExportResponse export(String type, String format, JsonNode body, boolean headless) throws Exception {
public EntityExportResponse<?> export(MultiDBTransactionManager multiDBTransactionManager, RequestDataDTO requestDataDTO, String type, String format, JsonNode body, boolean headless) throws Exception {
try {
String username = requestDataDTO.getUsername();
String password = requestDataDTO.getPassword();
@@ -482,8 +476,8 @@ public class EmsServices {
entityExporter.setEmsProperties(properties);
entityExporter.setJsonBody(body);
EntityExportResponse entityExportResponse = entityExporter.doExport();
boolean anyError = checkAnomalieExport(entityExporter, "EXPORT_" + type, format, headless);
EntityExportResponse<?> entityExportResponse = entityExporter.doExport();
boolean anyError = checkAnomalieExport(multiDBTransactionManager, entityExporter, "EXPORT_" + type, format, headless);
if (!anyError) {
if (entityExporter.send(entityExportResponse)) {
entityExporter.postSend(entityExportResponse);
@@ -509,18 +503,20 @@ public class EmsServices {
}
}
public StbFilesAttached uploadStbFilesAttached(@Nullable String idAttach,
public StbFilesAttached uploadStbFilesAttached(@Nonnull MultiDBTransactionManager multiDBTransactionManager,
@Nullable String idAttach,
@Nonnull String filename,
@Nonnull byte[] fileContent,
@Nullable String descrizione,
@Nullable String mimeType,
@Nullable MrlPartitaMagAttached mrlPartitaMagAttached,
@Nullable Date datetimeAttach) throws Exception {
return uploadStbFilesAttached(idAttach, filename, fileContent, descrizione, mimeType, null, mrlPartitaMagAttached, datetimeAttach);
return uploadStbFilesAttached(multiDBTransactionManager, idAttach, filename, fileContent, descrizione, mimeType, null, mrlPartitaMagAttached, datetimeAttach);
}
public StbFilesAttached uploadStbFilesAttached(@Nullable String idAttach,
public StbFilesAttached uploadStbFilesAttached(@Nonnull MultiDBTransactionManager multiDBTransactionManager,
@Nullable String idAttach,
@Nonnull String filename,
@Nonnull byte[] fileContent,
@Nullable String descrizione,
@@ -529,11 +525,12 @@ public class EmsServices {
@Nullable MrlPartitaMagAttached mrlPartitaMagAttached,
@Nullable Date datetimeAttach) throws Exception {
return uploadStbFilesAttached(idAttach, filename, fileContent, descrizione, mimeType, typeAttach, mrlPartitaMagAttached, null, datetimeAttach);
return uploadStbFilesAttached(multiDBTransactionManager, idAttach, filename, fileContent, descrizione, mimeType, typeAttach, mrlPartitaMagAttached, null, datetimeAttach);
}
public StbFilesAttached uploadStbFilesAttached(@Nullable String idAttach,
public StbFilesAttached uploadStbFilesAttached(@Nonnull MultiDBTransactionManager multiDBTransactionManager,
@Nullable String idAttach,
@Nonnull String filename,
@Nonnull byte[] fileContent,
@Nullable String descrizione,
@@ -544,7 +541,7 @@ public class EmsServices {
@Nullable Date datetimeAttach) throws Exception {
String calcMimeType = mimeType == null || mimeType.equals("application/octet-stream") ?
mimetypesFileTypeMap.getContentType(filename).toString() :
mimeTypesHandler.getContentType(filename).toString() :
mimeType;
byte[] thumbContent = null;
@@ -589,7 +586,8 @@ public class EmsServices {
return stbFilesAttached;
}
public AttachmentDTO downloadStbFileAttachment(String idAttach, boolean requestThumbnail) throws Exception {
public AttachmentDTO downloadStbFileAttachment(MultiDBTransactionManager multiDBTransactionManager,
String idAttach, boolean requestThumbnail) throws Exception {
StbFilesAttached stbFilesAttached = new StbFilesAttached();
stbFilesAttached.setIdAttach(idAttach);
stbFilesAttached.setOperation(OperationType.SELECT_OBJECT);
@@ -632,7 +630,7 @@ public class EmsServices {
return null;
}
public AttachmentDTO downloadFileFromRefUuid(String refUuid, String fileName) throws Exception {
public AttachmentDTO downloadFileFromRefUuid(MultiDBTransactionManager multiDBTransactionManager, String refUuid, String fileName) throws Exception {
byte[] bytes = minIOService.downloadObject(refUuid, multiDBTransactionManager.getPrimaryConnection());
String mimeType = mimeTypesHandler.getContentType(fileName).toString();
@@ -643,7 +641,7 @@ public class EmsServices {
.setFileName(fileName);
}
public String createZipFromFiles(CreateZipDTO createZipDTO) throws Exception {
public String createZipFromFiles(MultiDBTransactionManager multiDBTransactionManager, CreateZipDTO createZipDTO) throws Exception {
if (createZipDTO == null) {
throw new MissingDataException("createZipFromFiles");
}
@@ -758,6 +756,7 @@ public class EmsServices {
switch (createZipDTO.getSaveMode()) {
case STB_FILES_ATTACHED:
StbFilesAttached zipFile = this.uploadStbFilesAttached(
multiDBTransactionManager,
null,
fileName,
baos.toByteArray(),
@@ -810,12 +809,10 @@ public class EmsServices {
}
public void checkServerVariables() throws Exception {
public void checkServerVariables(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
if (UtilityDebug.isDebugExecution() || UtilityDebug.isIntegryServer())
throw new Exception("Cannot export server info in DEBUG mode");
multiDBTransactionManager.setPrimaryDB(settingsModel.getDefaultProfile());
HashMap<String, Object> arguments = new HashMap<>();
arguments.put("databaseEngine", getDatabaseEngineInfo(multiDBTransactionManager));
@@ -968,7 +965,7 @@ public class EmsServices {
for (Connection connection : mdb.getActiveConnections()) {
HashMap<String, Object> resultDbInfo = UtilityDB.executeSimpleQueryOnlyFirstRow(connection, sql);
final HashMap<String, String> setupSection = setupGest.getSetupSection(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "SETUP");
final HashMap<String, String> setupSection = setupGest.getSetupSection(connection, "DATI_AZIENDA", "SETUP");
ApplicationInfoDTO applicationInfoDTO = new ApplicationInfoDTO()
.setName(UtilityHashMap.getValueIfExists(resultDbInfo, "databaseName"))
@@ -989,7 +986,7 @@ public class EmsServices {
}
private PvmInfoDTO getPvmInfo(MultiDBTransactionManager mdb) throws Exception {
String pvmUrl = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "URL", "PVM");
String pvmUrl = setupGest.getSetup(mdb.getPrimaryConnection(), "DATI_AZIENDA", "URL", "PVM");
if (UtilityString.isNullOrEmpty(pvmUrl)) {
return null;

View File

@@ -404,7 +404,7 @@ public class DocumentiImportService {
jsonNode.put("whereCond", whereCond);
emsServices.export(exportType, formatFile, jsonNode, true);
emsServices.export(multiDBTransactionManager, requestDataDTO, exportType, formatFile, jsonNode, true);
} else {
throw new Exception("Non è possibile esportare l'ordine. Non sono stati definiti i dati per la comunicazione con il fornitore");
}

View File

@@ -50,8 +50,6 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -905,7 +903,9 @@ public class DocumentController {
List<ServiceRestResponse> listResponse = new ArrayList<ServiceRestResponse>();
try {
ImportRequestDTO body = new ImportRequestDTO().setRawContent(documenti);
EntityImportResponse<List<EntityBase>> importResponse = emsServices.importEntity(EntityImportType.DOCUMENTI.getText(), DocumentiImporter.Format.ELO.getText(), body, true);
EntityImportResponse<List<EntityBase>> importResponse = emsServices.importEntity(
multiDBTransactionManager, requestDataDTO,
EntityImportType.DOCUMENTI.getText(), DocumentiImporter.Format.ELO.getText(), body, true);
ServiceRestResponse response = ServiceRestResponse.createEntityPositiveResponse(importResponse.getResponse());
listResponse.add(response);

View File

@@ -583,7 +583,8 @@ public class ListiniVenditaServices {
.findFirst()
.orElse(null);
List<String> listaArticoli = listini.stream().map(x -> x.getCodMart())
List<String> listaArticoli = listini.stream()
.map(MtbLisvData::getCodMart)
.filter(Objects::nonNull).collect(Collectors.toList());
LocalDate dataValidita = UtilityLocalDate.getNow();
@@ -595,7 +596,7 @@ public class ListiniVenditaServices {
variazioniPvDTO.setUserName(requestDataDTO.getUsername());
JsonNode node = jsonObjectMapper.valueToTree(variazioniPvDTO);
emsServices.export(EntityExportType.VARIAZIONE_PV.getText(), formatFile, node, true);
emsServices.export(multiDBTransactionManager, requestDataDTO, EntityExportType.VARIAZIONE_PV.getText(), formatFile, node, true);
}
}

View File

@@ -71,7 +71,7 @@ public class AgribookOrderAttachmentService {
.setCodMart(codMart)
.setPartitaMag(partitaMag);
return emsServices.uploadStbFilesAttached(null,
return emsServices.uploadStbFilesAttached(multiDBTransactionManager, null,
fileName,
fileContent,
null,

View File

@@ -45,7 +45,7 @@ public class ScontriniImporter extends BaseEntityImporter implements IEntityImpo
break;
case MMPOS:
ContextLoader.getCurrentWebApplicationContext().getBean(MmposServices.class)
.importScontrini(type, requestDto.getWhereCond(), recuperoScontrini, anomalie);
.importScontrini(multiDBTransactionManager, type, requestDto.getWhereCond(), recuperoScontrini, anomalie);
break;

View File

@@ -6,7 +6,6 @@ import it.integry.ems.retail.Scontrini.dto.MMPosDTO;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems.sync.MultiDBTransaction.Connection;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.task.TaskExecutorService;
import it.integry.ems.utility.UtilityEntity;
import it.integry.ems_model.base.EntityBase;
import it.integry.ems_model.config.EmsRestConstants;
@@ -17,7 +16,6 @@ import it.integry.ems_model.utility.*;
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.math.BigDecimal;
@@ -32,21 +30,18 @@ import java.util.stream.Collectors;
import static java.util.stream.Collectors.groupingBy;
@Service
@Scope("request")
public class MmposServices {
@Autowired
private SetupGest setupGest;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
private List<HashMap<String, String>> elencoPromozioni = new ArrayList<>();
@Autowired
private EntityProcessor entityProcessor;
private final Logger logger = LogManager.getLogger();
public List<EntityBase> importScontrini(String typeImport, String whereCond, boolean recuperoScontrini, List<AnomalieDTO> anomalie) throws Exception {
public List<EntityBase> importScontrini(MultiDBTransactionManager multiDBTransactionManager, String typeImport, String whereCond, boolean recuperoScontrini, List<AnomalieDTO> anomalie) throws Exception {
List<EntityBase> entityReturn = new ArrayList<>();
final String formatImport = "MMPOS_SERVICES";
@@ -112,7 +107,7 @@ public class MmposServices {
List<MMPosDTO> mmPosDTOS = UtilityDB.executeSimpleQueryDTO(mmpos.getPrimaryConnection(), sql, MMPosDTO.class);
if ( mmPosDTOS == null || mmPosDTOS.isEmpty() ) {
if (mmPosDTOS == null || mmPosDTOS.isEmpty()) {
logger.info("Nessun scontrino da importare");
return entityReturn;
}
@@ -143,6 +138,8 @@ public class MmposServices {
List<Callable<Void>> tasks = new ArrayList<>();
List<HashMap<String, String>> elencoPromozioni = new ArrayList<>();
for (Map.Entry<HashMap<String, Object>, List<MMPosDTO>> entry : orderedKeys) {
List<EntityBase> entityBaseList = new ArrayList<>();
if (entry.getValue().get(0).getFlTrans().equalsIgnoreCase("IS")) {
@@ -171,13 +168,13 @@ public class MmposServices {
"C".equals(flagTrans.substring(0, 1)) || "R".equals(flagTrans.substring(0, 1))) {
NtbDocr ntbDocr;
MMPosDTO rigaVendita = null;
if ( flagTrans.equalsIgnoreCase("CX") && !UtilityString.isNullOrEmpty(row.getKeysRef())) {
if (flagTrans.equalsIgnoreCase("CX") && !UtilityString.isNullOrEmpty(row.getKeysRef())) {
rigaVendita = entry.getValue().stream().filter(x -> x.getKeyBattuta().equalsIgnoreCase(row.getKeysRef())).findFirst().orElse(null);
}
if (rigaVendita != null) {
ntbDocr = getRow(rigaVendita, multiDBTransactionManager.getPrimaryConnection(), impostaDatiOrdine, impostaKit, mmpos.getPrimaryConnection(), true);
ntbDocr = getRow(rigaVendita, multiDBTransactionManager.getPrimaryConnection(), impostaDatiOrdine, impostaKit, mmpos.getPrimaryConnection(), true, elencoPromozioni);
} else {
ntbDocr = getRow(row, multiDBTransactionManager.getPrimaryConnection(), impostaDatiOrdine, impostaKit, mmpos.getPrimaryConnection(), false);
ntbDocr = getRow(row, multiDBTransactionManager.getPrimaryConnection(), impostaDatiOrdine, impostaKit, mmpos.getPrimaryConnection(), false, elencoPromozioni);
}
if (ntbDocr != null) {
@@ -202,7 +199,7 @@ public class MmposServices {
.setCodMdep(ntbDoct.getCodMdep());
MtbDepoCasse mtbDepoCasse = new MtbDepoCasse()
.setCodCassa(ntbDoct.getCodCassa())
.setLastIdx(lastIdx);
.setLastIdx(lastIdx);
mtbDepoCasse.setOperation(OperationType.UPDATE);
mtbDepo.getMtbDepoCasse().add(mtbDepoCasse);
entityBaseList.add(mtbDepo);
@@ -329,7 +326,8 @@ public class MmposServices {
}
private NtbDocr getRow(MMPosDTO row, Connection connection, boolean impostaDatiOrdine,
boolean impostaKit, Connection mmPosConn, boolean isStorno) throws Exception {
boolean impostaKit, Connection mmPosConn, boolean isStorno, List<HashMap<String, String>> elencoPromozioni) throws Exception {
NtbDocr ntbDocr = new NtbDocr();
ntbDocr
.setBarCode(row.getCodice().trim())
@@ -341,8 +339,11 @@ public class MmposServices {
if ((!UtilityString.isNullOrEmpty(promozione)) && !("NULL").equalsIgnoreCase(promozione) && row.getFlTrans().equalsIgnoreCase("CV")) {
String finalPromozione = promozione;
HashMap<String, String> datiPromo = Stream.of(elencoPromozioni)
.filter(x -> UtilityHashMap.getValueIfExists(x, finalPromozione) != null).findFirst().orElse(null);
HashMap<String, String> datiPromo =
elencoPromozioni.stream()
.filter(x -> UtilityHashMap.getValueIfExists(x, finalPromozione) != null)
.findFirst()
.orElse(null);
if (datiPromo != null) {
promozione = datiPromo.get(finalPromozione);

View File

@@ -3,10 +3,8 @@ package it.integry.ems.retail.controller;
import com.fasterxml.jackson.databind.JsonNode;
import it.integry.common.var.CommonConstants;
import it.integry.ems.Import.base.EntityImportResponse;
import it.integry.ems.Import.dto.AnomalieDTO;
import it.integry.ems.Import.dto.ImportRequestDTO;
import it.integry.ems.Import.enums.EntityImportType;
import it.integry.ems.document.Import.DocumentiImporter;
import it.integry.ems.export.base.EntityExportResponse;
import it.integry.ems.export.enums.EntityExportType;
import it.integry.ems.javabeans.RequestDataDTO;
@@ -20,10 +18,10 @@ import it.integry.ems.retail.Scontrini.service.MmposServices;
import it.integry.ems.retail.dto.RecuperoScontriniRequestDTO;
import it.integry.ems.retail.export.VariazioniExporter;
import it.integry.ems.retail.pvmRetail.controller.PvmController;
import it.integry.ems.retail.service.RecuperoScontriniService;
import it.integry.ems.retail.service.ScontriniService;
import it.integry.ems.service.EmsServices;
import it.integry.ems.status.ServiceChecker;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems_model.base.EntityBase;
import it.integry.ems_model.config.EmsRestConstants;
import it.integry.ems_model.utility.UtilityDate;
@@ -39,14 +37,11 @@ import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RestController
@Scope(value = "request")
public class RetailController {
private final Logger logger = LogManager.getLogger();
@@ -70,6 +65,8 @@ public class RetailController {
@Autowired
private MmposServices mmposServices;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@RequestMapping(value = "/retail/status", method = RequestMethod.GET)
public @ResponseBody
@@ -156,7 +153,9 @@ public class RetailController {
variazioniPvDTO.setUserName(requestDataDTO.getUsername());
JsonNode node = jsonObjectMapper.valueToTree(variazioniPvDTO);
EntityExportResponse exportResponse = emsServices.export(EntityExportType.VARIAZIONE_PV.getText(), VariazioniExporter.Format.XML_DIALOGO.getText(), node, true);
EntityExportResponse<?> exportResponse = emsServices.export(
multiDBTransactionManager, requestDataDTO,
EntityExportType.VARIAZIONE_PV.getText(), VariazioniExporter.Format.XML_DIALOGO.getText(), node, true);
response = ServiceRestResponse.createPositiveResponse(exportResponse.getResponse());
@@ -176,7 +175,8 @@ public class RetailController {
ServiceRestResponse response = null;
requestDTO.setRecuperoScontrini(true);
ImportRequestDTO body = new ImportRequestDTO().setRawContent(requestDTO);
EntityImportResponse<List<EntityBase>> importResponse = emsServices.importEntity(EntityImportType.SCONTRINI.getText(), requestDTO.getFormat(), body, true);
EntityImportResponse<List<EntityBase>> importResponse = emsServices.importEntity(multiDBTransactionManager, requestDataDTO,
EntityImportType.SCONTRINI.getText(), requestDTO.getFormat(), body, true);
return ServiceRestResponse.createEntityPositiveResponse(importResponse.getResponse());
}

View File

@@ -259,7 +259,7 @@ public class PvmService {
ObjectNode body = JsonNodeFactory.instance.objectNode();
body.put("whereCond", whereCond);
emsServices.export(typeExport, formatFile, body, true);
emsServices.export(multiDBTransactionManager, requestDataDTO, typeExport, formatFile, body, true);
} else {
throw new Exception("Non è possibile esportare l'ordine. Non sono stati definiti i dati per la comunicazione con il fornitore");
}
@@ -269,7 +269,8 @@ public class PvmService {
public FileItem getOrdineFromPicking(String chiaveOrdine, String gestione, Date dataOrd, Integer numOrd) throws Exception {
String whereCond = "", pickMultiOrd = "N", cliente = "", query, gestioneFinded = null;
Date dataOrdFinded = null;
Integer countRow = 0, numOrdFinded = null;
int countRow = 0;
Integer numOrdFinded = null;
DatiFiltroDTO datiOrdine = new DatiFiltroDTO();
PreparedStatement info;
@@ -387,7 +388,7 @@ public class PvmService {
if (dataOrdFinded != null && numOrdFinded != null) {
((Element) ordNode).setAttribute("DATA_ORD", new SimpleDateFormat("dd-MM-yyyy").format(dataOrdFinded));
((Element) ordNode).setAttribute("NUM_ORD", numOrdFinded.toString());
((Element) ordNode).setAttribute("RIGHE_ORD", countRow.toString());
((Element) ordNode).setAttribute("RIGHE_ORD", Integer.toString(countRow));
}
((Element) ordNode).setAttribute("CLIENTE", cliente);

View File

@@ -1196,7 +1196,7 @@ public class PvmServiceSave {
ObjectNode jsonNode = JsonNodeFactory.instance.objectNode();
jsonNode.put("whereCond", whereCond);
try {
emsServices.export(exportType, formatExport, jsonNode, true);
emsServices.export(multiDBTransactionManager, requestDataDTO, exportType, formatExport, jsonNode, true);
} catch (Exception e) {
logger.error("saveDocFromPicking", e);
}

View File

@@ -1,23 +1,23 @@
package it.integry.ems.retail.service;
import it.integry.ems.Import.dto.ImportRequestDTO;
import it.integry.ems._context.ApplicationContextProvider;
import it.integry.ems.json.ResponseJSONObjectMapper;
import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.service.EmsServices;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems.service.HttpRestWrapper;
import it.integry.ems.settings.Model.AvailableConnectionsModel;
import it.integry.ems.settings.Model.SettingsModel;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.utility.UtilityDebug;
import it.integry.ems_model.base.EntityBase;
import it.integry.ems_model.utility.*;
import it.integry.ems_model.utility.Query;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityLocalDate;
import it.integry.ems_model.utility.UtilityTiming;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.ws.rs.client.Entity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -34,6 +34,8 @@ public class MmposImportHandlerService {
@Autowired
private EntityProcessor entityProcessor;
@Autowired
private EmsServices emsServices;
private boolean canBeExecuted = false;
@@ -42,6 +44,7 @@ public class MmposImportHandlerService {
private final String type = "SCONTRINI";
private final String format = "MMPOS";
private final String keySectionAttivo = "ATTIVO";
@Scheduled(fixedDelay = 1, timeUnit = TimeUnit.HOURS, zone = "Europe/Rome")
private void refreshCronPermission() throws Exception {
//canBeExecuted = !UtilityDebug.isDebugExecution() && settingsModel.isPrimaryInstance() && !UtilityDebug.isIntegryServer();
@@ -99,7 +102,7 @@ public class MmposImportHandlerService {
}
public List<EntityBase> importScontrini(MultiDBTransactionManager mdb) throws Exception {
public List<EntityBase> importScontrini(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
List<EntityBase> ret = new ArrayList<>();
String sql =
Query.format(
@@ -117,14 +120,14 @@ public class MmposImportHandlerService {
" value = 'S')\n",
"IMPORT_" + type, format, keySectionAttivo);
List<HashMap<String, Object>> depoCasse = UtilityDB.executeSimpleQuery(mdb.getPrimaryConnection(), sql);
List<HashMap<String, Object>> depoCasse = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
for (HashMap<String, Object> depoCassa : depoCasse) {
String codMdep = (String) depoCassa.get("cod_mdep");
String codCassa = (String) depoCassa.get("cod_cassa");
Integer lastIdx = ((Integer) depoCassa.get("last_idx"));
try {
try (MultiDBTransactionManager mdb = new MultiDBTransactionManager(multiDBTransactionManager.getPrimaryConnection().getProfileName())) {
String whereCond = Query.format("codMagaz = %s AND n_cassa = %s",
codMdep,
codCassa);
@@ -135,19 +138,9 @@ public class MmposImportHandlerService {
whereCond += Query.format(" AND giorno = %s", UtilityLocalDate.getNow()) ;
}
ResponseJSONObjectMapper objectMapper = ApplicationContextProvider.getApplicationContext().getBean(ResponseJSONObjectMapper.class);
String port = UtilityServer.getLocalServerPort();
String baseUrl = "http://localhost:" + port + "/ems-api";
StringBuilder jsonResponse = new StringBuilder();
ImportRequestDTO importRequestDTO = new ImportRequestDTO().setWhereCond(whereCond);
HttpRestWrapper.callImport(baseUrl, mdb.getPrimaryConnection().getProfileName(),
"INTEGRY", "INTEGRY", type, format,
Entity.json(importRequestDTO),
jsonResponse);
final int timingId = UtilityTiming.startNewTiming(getClass().getSimpleName() + " - " + codMdep + " - " + codCassa);
emsServices.importEntity(mdb, RequestDataDTO.scheduledOperationsMockupData(), type, format,
importRequestDTO, true);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);

View File

@@ -193,7 +193,7 @@ public class RecuperoScontriniService {
if (listaCond.size() > 0)
whereCond = StringUtils.join(listaCond, " OR ");
return mmposServices.importScontrini(typeImport, whereCond, true, anomalie);
return mmposServices.importScontrini(multiDBTransactionManager, typeImport, whereCond, true, anomalie);
}

View File

@@ -2,6 +2,7 @@ package it.integry.ems.retail.wms.generic.service;
import com.fasterxml.jackson.databind.JsonNode;
import it.integry.ems.export.enums.EntityExportType;
import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.json.ResponseJSONObjectMapper;
import it.integry.ems.logistic.Export.ColliExporter;
import it.integry.ems.retail.wms.dto.CreateUDSRequestDTO;
@@ -51,6 +52,9 @@ public class WMSMagazzinoAutomaticoService {
@Autowired
private UserSession userSession;
@Autowired
private RequestDataDTO requestDataDTO;
public void pickItems(MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO) throws Exception {
MtbColt refMtbColt = null;
@@ -102,7 +106,7 @@ public class WMSMagazzinoAutomaticoService {
JsonNode node = jsonObjectMapper.valueToTree(magazzinoAutomaticoMissionePickDTO);
emsServices.export(
emsServices.export(multiDBTransactionManager, requestDataDTO,
EntityExportType.COLLI.getText(),
ColliExporter.Format.ICON_PICKING.getText(),
node, false);
@@ -113,7 +117,7 @@ public class WMSMagazzinoAutomaticoService {
MtbColt mtbColtToPut = magazzinoAutomaticoPutItemsRequestDTO.getInputMtbColt();
JsonNode node = jsonObjectMapper.valueToTree(mtbColtToPut);
emsServices.export(
emsServices.export(multiDBTransactionManager, requestDataDTO,
EntityExportType.COLLI.getText(),
ColliExporter.Format.ICON_ACCETTAZIONE.getText(),
node, false);