Importazione immagini
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
if (artLinkResult == null || artLinkResult.isEmpty()) {
|
||||
MtbAartLink mtbAartLink = new MtbAartLink();
|
||||
mtbAartLink.setCodMart(codMart);
|
||||
mtbAartLink.setPathLink(fileName);
|
||||
mtbAartLink.setDescrizioneLink("Immagine prodotto " + codMart);
|
||||
|
||||
if (artLinkResult == null || artLinkResult.isEmpty()) {
|
||||
mtbAartLink.setOperation(OperationType.INSERT);
|
||||
} else {
|
||||
mtbAartLink.setOperation(OperationType.UPDATE);
|
||||
}
|
||||
|
||||
MtbAart mtbAart = new MtbAart();
|
||||
mtbAart.setCodMart(codMart);
|
||||
mtbAart.setOperation(OperationType.NO_OP);
|
||||
mtbAart.getMtbAartLink().add(mtbAartLink);
|
||||
|
||||
entityProcessor.processEntity(mtbAart, true, multiDBTransactionManager);
|
||||
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;
|
||||
return mtbAart;
|
||||
}
|
||||
|
||||
public List<EntityBase> saveSalesAgreement(ContrattiVenditaDTO contrattiVenditaDTO) throws Exception {
|
||||
@@ -1210,7 +1246,7 @@ public class ProductServices {
|
||||
"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_anag]", codAnag)
|
||||
.replace("[cod_art_for]", codArtFor);
|
||||
|
||||
String codMart = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
@@ -1235,7 +1271,7 @@ public class ProductServices {
|
||||
|
||||
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)
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user