Importazione immagini

This commit is contained in:
2024-07-25 16:25:12 +02:00
parent bc03755afa
commit 36afcc836c
2 changed files with 107 additions and 69 deletions

View File

@@ -26,8 +26,9 @@ public class ArticoliImporter extends BaseEntityImporter<List<EntityBase>> imple
ProductServices importDistinteMorganteService = ContextLoader.getCurrentWebApplicationContext().getBean(ProductServices.class); ProductServices importDistinteMorganteService = ContextLoader.getCurrentWebApplicationContext().getBean(ProductServices.class);
return importDistinteMorganteService.importDistinteMorgante((String) requestDto.getRawContent(), type, format); return importDistinteMorganteService.importDistinteMorgante((String) requestDto.getRawContent(), type, format);
case REPO_IMAGES: case REPO_IMAGES:
case FOTO:
ProductServices importArticoliRepoImagesServices = ContextLoader.getCurrentWebApplicationContext().getBean(ProductServices.class); ProductServices importArticoliRepoImagesServices = ContextLoader.getCurrentWebApplicationContext().getBean(ProductServices.class);
return importArticoliRepoImagesServices.importAarticoliFromREPOIMAGES(type, format, requestDto.getPathFile()); return importArticoliRepoImagesServices.importFotoArticoli(type, format, requestDto);
case APULIA: case APULIA:
return ContextLoader.getCurrentWebApplicationContext().getBean(ProductServices.class).importArticoliApulia(type, format, requestDto.getRawContent()); return ContextLoader.getCurrentWebApplicationContext().getBean(ProductServices.class).importArticoliApulia(type, format, requestDto.getRawContent());
default: default:
@@ -45,7 +46,8 @@ public class ArticoliImporter extends BaseEntityImporter<List<EntityBase>> imple
MORGANTE("MORGANTE"), MORGANTE("MORGANTE"),
MORGANTE_DISTINTE("MORGANTE_DISTINTE"), MORGANTE_DISTINTE("MORGANTE_DISTINTE"),
REPO_IMAGES("REPO_IMAGES"), REPO_IMAGES("REPO_IMAGES"),
APULIA("APULIA"); APULIA("APULIA"),
FOTO("FOTO");
private String text; private String text;

View File

@@ -5,6 +5,7 @@ import com.annimon.stream.Stream;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import it.integry.common.var.CommonConstants; import it.integry.common.var.CommonConstants;
import it.integry.ems.Import.dto.ImportRequestDTO;
import it.integry.ems.datasource.DataSource; import it.integry.ems.datasource.DataSource;
import it.integry.ems.product.importaz.dto.ArticoliMorganteDTO; import it.integry.ems.product.importaz.dto.ArticoliMorganteDTO;
import it.integry.ems.product.importaz.dto.ContrattiVenditaDTO; import it.integry.ems.product.importaz.dto.ContrattiVenditaDTO;
@@ -1014,47 +1015,82 @@ public class ProductServices {
} }
public List<EntityBase> importAarticoliFromREPOIMAGES(String typeImport, String formatImport, String filePath) throws Exception { public List<EntityBase> importFotoArticoli(String type, String format, ImportRequestDTO requestDto) throws Exception {
List<EntityBase> entitiesReturn = new ArrayList<EntityBase>(); List<MtbAart> mtbAartList = new ArrayList<>();
Connection conn = multiDBTransactionManager.getPrimaryDatasource().getConnection(); Map<String, String> setup = setupGest.getImportSetupSection(multiDBTransactionManager.getPrimaryConnection(), type, format);
String filePath = UtilityString.isNullOrEmpty(requestDto.getPathFile()) ? setup.get("FILE_FILTER") : requestDto.getPathFile();
if (filePath == null) {
mtbAartList.add(
prepareEntityForImportFoto(requestDto.getFileName())
);
} else {
File directory = new File(filePath);
if (directory.exists() && directory.isDirectory()) {
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
mtbAartList.add(
prepareEntityForImportFoto(file.getName())
);
}
}
} else {
throw new Exception("Cartella vuota");
}
}
}
if (mtbAartList.isEmpty()) {
throw new Exception("Nessuna immagine salvata");
}
return entityProcessor.processEntityList(mtbAartList, multiDBTransactionManager, true);
}
private MtbAart prepareEntityForImportFoto(String fileName) throws Exception {
List<String> validExtensions = Arrays.asList(".jpg", ".jpeg", ".png", ".gif");
int extensionIndex = fileName.lastIndexOf(".");
String codMart;
if (extensionIndex >= 0 && validExtensions.contains(fileName.substring(extensionIndex))) {
codMart = fileName.substring(0, extensionIndex);
} else {
return null;
}
String fileName = filePath.substring(filePath.lastIndexOf("\\") + 1);
String codMart = fileName.substring(0, fileName.lastIndexOf(".jpg"));
String[] arg = codMart.split("-"); String[] arg = codMart.split("-");
if (arg != null && arg.length > 0) codMart = arg[0]; if (arg.length > 0) codMart = arg[0];
MtbAartLink searchArtLink = new MtbAartLink(); MtbAartLink searchArtLink = new MtbAartLink();
searchArtLink.setCodMart(codMart); searchArtLink.setCodMart(codMart);
searchArtLink.setPathLink(fileName);
searchArtLink.setOperation(OperationType.SELECT); searchArtLink.setOperation(OperationType.SELECT);
searchArtLink.setNativeSql("select * from mtb_aart_link where cod_mart = " + UtilityDB.valueToString(codMart) + "and path_link = " + UtilityDB.valueToString(fileName));
List<EntityBase> artLinkResult = entityProcessor.processEntity(searchArtLink, multiDBTransactionManager); List<EntityBase> artLinkResult = entityProcessor.processEntity(searchArtLink, multiDBTransactionManager);
if (artLinkResult == null || artLinkResult.isEmpty()) {
MtbAartLink mtbAartLink = new MtbAartLink(); MtbAartLink mtbAartLink = new MtbAartLink();
mtbAartLink.setCodMart(codMart); mtbAartLink.setCodMart(codMart);
mtbAartLink.setPathLink(fileName); mtbAartLink.setPathLink(fileName);
mtbAartLink.setDescrizioneLink("Immagine prodotto " + codMart); mtbAartLink.setDescrizioneLink("Immagine prodotto " + codMart);
if (artLinkResult == null || artLinkResult.isEmpty()) {
mtbAartLink.setOperation(OperationType.INSERT); mtbAartLink.setOperation(OperationType.INSERT);
} else {
mtbAartLink.setOperation(OperationType.UPDATE);
}
MtbAart mtbAart = new MtbAart(); MtbAart mtbAart = new MtbAart();
mtbAart.setCodMart(codMart); mtbAart.setCodMart(codMart);
mtbAart.setOperation(OperationType.NO_OP); mtbAart.setOperation(OperationType.NO_OP);
mtbAart.getMtbAartLink().add(mtbAartLink); mtbAart.getMtbAartLink().add(mtbAartLink);
entityProcessor.processEntity(mtbAart, true, multiDBTransactionManager); return mtbAart;
entitiesReturn.add(mtbAart);
}
/* if ( mtbAart != null){
MtbAartLink mtbAartLink= Stream.of(mtbAart.getMtbAartLink()).filter(x-> x.getCodMart().equalsIgnoreCase(codMart) && x.getPathLink().equalsIgnoreCase(fileName)).single();
}
*/
return entitiesReturn;
} }
public List<EntityBase> saveSalesAgreement(ContrattiVenditaDTO contrattiVenditaDTO) throws Exception { public List<EntityBase> saveSalesAgreement(ContrattiVenditaDTO contrattiVenditaDTO) throws Exception {