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);
return importDistinteMorganteService.importDistinteMorgante((String) requestDto.getRawContent(), type, format);
case REPO_IMAGES:
case FOTO:
ProductServices importArticoliRepoImagesServices = ContextLoader.getCurrentWebApplicationContext().getBean(ProductServices.class);
return importArticoliRepoImagesServices.importAarticoliFromREPOIMAGES(type, format, requestDto.getPathFile());
return importArticoliRepoImagesServices.importFotoArticoli(type, format, requestDto);
case APULIA:
return ContextLoader.getCurrentWebApplicationContext().getBean(ProductServices.class).importArticoliApulia(type, format, requestDto.getRawContent());
default:
@@ -45,7 +46,8 @@ public class ArticoliImporter extends BaseEntityImporter<List<EntityBase>> imple
MORGANTE("MORGANTE"),
MORGANTE_DISTINTE("MORGANTE_DISTINTE"),
REPO_IMAGES("REPO_IMAGES"),
APULIA("APULIA");
APULIA("APULIA"),
FOTO("FOTO");
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.databind.ObjectMapper;
import it.integry.common.var.CommonConstants;
import it.integry.ems.Import.dto.ImportRequestDTO;
import it.integry.ems.datasource.DataSource;
import it.integry.ems.product.importaz.dto.ArticoliMorganteDTO;
import it.integry.ems.product.importaz.dto.ContrattiVenditaDTO;
@@ -62,22 +63,22 @@ public class ProductServices {
private Logger logger = LogManager.getLogger();
public List<EntityBase> saveArtDialogo (MtbAart mtbAart) throws Exception {
public List<EntityBase> saveArtDialogo(MtbAart mtbAart) throws Exception {
List<EntityBase> entityList = new ArrayList<>();
mtbAart.setOperation(OperationType.INSERT_OR_UPDATE);
entityList.add(mtbAart);
for (MtbAartBarCode b: mtbAart.getMtbAartBarCode()) {
for (MtbAartBarCode b : mtbAart.getMtbAartBarCode()) {
b.setOperation(OperationType.INSERT_OR_UPDATE);
}
if (mtbAart.getMtbLisa() != null )
for (MtbLisa l: mtbAart.getMtbLisa()) {
if (mtbAart.getMtbLisa() != null)
for (MtbLisa l : mtbAart.getMtbLisa()) {
l.setOperation(OperationType.INSERT_OR_UPDATE);
entityList.add(l);
}
List<EntityBase> entitites = importAnagListiniService.importAnagListinoAcq(entityList, "V" , null, null);
List<EntityBase> entitites = importAnagListiniService.importAnagListinoAcq(entityList, "V", null, null);
return entitites;
}
@@ -1014,47 +1015,82 @@ public class ProductServices {
}
public List<EntityBase> importAarticoliFromREPOIMAGES(String typeImport, String formatImport, String filePath) throws Exception {
List<EntityBase> entitiesReturn = new ArrayList<EntityBase>();
public List<EntityBase> importFotoArticoli(String type, String format, ImportRequestDTO requestDto) throws Exception {
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("-");
if (arg != null && arg.length > 0) codMart = arg[0];
if (arg.length > 0) codMart = arg[0];
MtbAartLink searchArtLink = new MtbAartLink();
searchArtLink.setCodMart(codMart);
searchArtLink.setPathLink(fileName);
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);
MtbAartLink mtbAartLink = new MtbAartLink();
mtbAartLink.setCodMart(codMart);
mtbAartLink.setPathLink(fileName);
mtbAartLink.setDescrizioneLink("Immagine prodotto " + codMart);
if (artLinkResult == null || artLinkResult.isEmpty()) {
MtbAartLink mtbAartLink = new MtbAartLink();
mtbAartLink.setCodMart(codMart);
mtbAartLink.setPathLink(fileName);
mtbAartLink.setDescrizioneLink("Immagine prodotto " + codMart);
mtbAartLink.setOperation(OperationType.INSERT);
MtbAart mtbAart = new MtbAart();
mtbAart.setCodMart(codMart);
mtbAart.setOperation(OperationType.NO_OP);
mtbAart.getMtbAartLink().add(mtbAartLink);
entityProcessor.processEntity(mtbAart, true, multiDBTransactionManager);
entitiesReturn.add(mtbAart);
} else {
mtbAartLink.setOperation(OperationType.UPDATE);
}
/* if ( mtbAart != null){
MtbAartLink mtbAartLink= Stream.of(mtbAart.getMtbAartLink()).filter(x-> x.getCodMart().equalsIgnoreCase(codMart) && x.getPathLink().equalsIgnoreCase(fileName)).single();
MtbAart mtbAart = new MtbAart();
mtbAart.setCodMart(codMart);
mtbAart.setOperation(OperationType.NO_OP);
mtbAart.getMtbAartLink().add(mtbAartLink);
}
*/
return entitiesReturn;
return mtbAart;
}
public List<EntityBase> saveSalesAgreement(ContrattiVenditaDTO contrattiVenditaDTO) throws Exception {
@@ -1194,23 +1230,23 @@ public class ProductServices {
String sql =
(
"WITH lisa as (\n" +
"select atb_forn.cod_alis\n" +
"from atb_forn inner join atb_list on atb_forn.cod_alis = atb_list.cod_alis\n" +
"where atb_forn.cod_anag = '[cod_anag]'\n" +
"and atb_list.part_iva_forn is null\n" +
"union\n" +
"select vtb_dest.cod_alis\n" +
"from vtb_dest inner join atb_list on vtb_dest.cod_alis = atb_list.cod_alis\n" +
"where vtb_dest.cod_anag = '[cod_anag]'\n" +
"and atb_list.part_iva_forn is null ),\n" +
"barcode as (\n" +
"select l.cod_mart\n" +
"from dbo.getListinoAcquisto(null, null, '[cod_art_for]', null, 'N', null) l\n" +
"inner join lisa on lisa.cod_alis = l.cod_alis\n" +
"where l.tipo_variazione <> 'D' and l.cod_mart is not null )\n" +
"select cod_mart from barcode")
.replace("[cod_anag]",codAnag )
"WITH lisa as (\n" +
"select atb_forn.cod_alis\n" +
"from atb_forn inner join atb_list on atb_forn.cod_alis = atb_list.cod_alis\n" +
"where atb_forn.cod_anag = '[cod_anag]'\n" +
"and atb_list.part_iva_forn is null\n" +
"union\n" +
"select vtb_dest.cod_alis\n" +
"from vtb_dest inner join atb_list on vtb_dest.cod_alis = atb_list.cod_alis\n" +
"where vtb_dest.cod_anag = '[cod_anag]'\n" +
"and atb_list.part_iva_forn is null ),\n" +
"barcode as (\n" +
"select l.cod_mart\n" +
"from dbo.getListinoAcquisto(null, null, '[cod_art_for]', null, 'N', null) l\n" +
"inner join lisa on lisa.cod_alis = l.cod_alis\n" +
"where l.tipo_variazione <> 'D' and l.cod_mart is not null )\n" +
"select cod_mart from barcode")
.replace("[cod_anag]", codAnag)
.replace("[cod_art_for]", codArtFor);
String codMart = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
@@ -1218,28 +1254,28 @@ public class ProductServices {
if (!UtilityString.isNullOrEmpty(codMart)) {
sql =
"WITH barcode_new as (SELECT DISTINCT cod_barre \n" +
"FROM (\n" +
"VALUES ('" + StringUtils.join(barcode, "'),('") + "')\n" +
") AS a(cod_barre)),\n" +
"barcode as (\n" +
"SELECT mvw_barcode.cod_mart, mvw_barcode.cod_barre\n" +
"FROM mvw_barcode \n" +
"WHERE mvw_barcode.cod_mart = " + UtilityDB.valueToString(codMart) + " \n" +
"union all\n" +
"SELECT mtb_comp.cod_mart, mvw_barcode.cod_barre\n" +
"FROM mvw_barcode inner join mtb_comp on mvw_barcode.cod_mart = mtb_comp.cod_mart\n" +
"WHERE mtb_comp.cod_comp = " + UtilityDB.valueToString(codMart) + "\n) " +
"SELECT DISTINCT CASE WHEN LEFT(barcode_new.cod_barre, 5) = '00000' THEN substring(barcode_new.cod_barre, 6, 8) ELSE barcode_new.cod_barre END as cod_barre\n" +
"FROM barcode_new \n" +
"WHERE not EXISTS(SELECT * FROM barcode WHERE barcode.cod_barre = CASE WHEN LEFT(barcode_new.cod_barre, 5) = '00000' THEN substring(barcode_new.cod_barre, 6, 8) ELSE barcode_new.cod_barre END )";
"FROM (\n" +
"VALUES ('" + StringUtils.join(barcode, "'),('") + "')\n" +
") AS a(cod_barre)),\n" +
"barcode as (\n" +
"SELECT mvw_barcode.cod_mart, mvw_barcode.cod_barre\n" +
"FROM mvw_barcode \n" +
"WHERE mvw_barcode.cod_mart = " + UtilityDB.valueToString(codMart) + " \n" +
"union all\n" +
"SELECT mtb_comp.cod_mart, mvw_barcode.cod_barre\n" +
"FROM mvw_barcode inner join mtb_comp on mvw_barcode.cod_mart = mtb_comp.cod_mart\n" +
"WHERE mtb_comp.cod_comp = " + UtilityDB.valueToString(codMart) + "\n) " +
"SELECT DISTINCT CASE WHEN LEFT(barcode_new.cod_barre, 5) = '00000' THEN substring(barcode_new.cod_barre, 6, 8) ELSE barcode_new.cod_barre END as cod_barre\n" +
"FROM barcode_new \n" +
"WHERE not EXISTS(SELECT * FROM barcode WHERE barcode.cod_barre = CASE WHEN LEFT(barcode_new.cod_barre, 5) = '00000' THEN substring(barcode_new.cod_barre, 6, 8) ELSE barcode_new.cod_barre END )";
List<MtbAartBarCode> mtbAartBarCodes = new ResultSetMapper().mapQuerySetToList(multiDBTransactionManager.getPrimaryConnection(), sql, MtbAartBarCode.class, OperationType.INSERT);
if (mtbAartBarCodes != null && mtbAartBarCodes.size() > 0 ) {
if (mtbAartBarCodes != null && mtbAartBarCodes.size() > 0) {
MtbAart mtbAart =
new MtbAart()
.setCodMart(codMart)
.setMtbAartBarCode(mtbAartBarCodes);
.setCodMart(codMart)
.setMtbAartBarCode(mtbAartBarCodes);
entityList.add(mtbAart);
}
@@ -1248,7 +1284,7 @@ public class ProductServices {
}
}
if ( entityList != null && entityList.size() > 0 ) {
if (entityList != null && entityList.size() > 0) {
List<EntityBase> entityBases = entityProcessor.processEntityList(entityList, true);
UtilityEntity.throwEntitiesException(entityBases);
return entityBases;
@@ -1256,10 +1292,10 @@ public class ProductServices {
return null;
}
private List<String> getElencoBarcode(String elencoBarcode){
private List<String> getElencoBarcode(String elencoBarcode) {
String[] splitString = elencoBarcode.split("(?<=\\G.{13})");
List<String> barcode = Stream.of(splitString)
.filterNot(s->s.equalsIgnoreCase("0000000000000"))
.filterNot(s -> s.equalsIgnoreCase("0000000000000"))
.distinct()
.toList();