Finish Hotfix-81

This commit is contained in:
2024-09-13 17:42:07 +02:00

View File

@@ -23,7 +23,9 @@ import it.integry.ems_model.service.SetupGest;
import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.types.TypeDbObject;
import it.integry.ems_model.utility.*;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -34,6 +36,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.sql.*;
import java.text.SimpleDateFormat;
@@ -1022,9 +1025,9 @@ public class ProductServices {
String filePath = UtilityString.isNullOrEmpty(requestDto.getPathFile()) ? setup.get("FILE_FILTER") : requestDto.getPathFile();
if (filePath == null) {
mtbAartList.add(
prepareEntityForImportFoto(requestDto.getFileName())
);
// mtbAartList.add(
// prepareEntityForImportFoto(requestDto.getRawContentB64().toLowerCase())
// );
} else {
File directory = new File(filePath);
@@ -1034,10 +1037,9 @@ public class ProductServices {
if (files != null) {
for (File file : files) {
if (file.isFile()) {
mtbAartList.add(
prepareEntityForImportFoto(file.getName())
);
MtbAart aart = prepareEntityForImportFoto(file);
if (aart != null)
mtbAartList.add(aart);
}
}
} else {
@@ -1053,7 +1055,8 @@ public class ProductServices {
return entityProcessor.processEntityList(mtbAartList, multiDBTransactionManager, false);
}
private MtbAart prepareEntityForImportFoto(String fileName) throws Exception {
private MtbAart prepareEntityForImportFoto(File file) throws Exception {
String fileName = file.getName().toLowerCase();
List<String> validExtensions = Arrays.asList(".jpg", ".jpeg", ".png", ".gif");
int extensionIndex = fileName.lastIndexOf(".");
String codMart;
@@ -1067,21 +1070,25 @@ public class ProductServices {
String[] arg = codMart.split("-");
if (arg.length > 0) codMart = arg[0];
MtbAartLink searchArtLink = new MtbAartLink();
searchArtLink.setCodMart(codMart);
searchArtLink.setPathLink(fileName);
searchArtLink.setOperation(OperationType.SELECT);
List<EntityBase> artLinkResult = entityProcessor.processEntity(searchArtLink, multiDBTransactionManager);
Integer idRiga =
UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(),
it.integry.ems_model.utility.Query.format("SELECT id_riga from mtb_aart_link where cod_mart = %s and path_link = %s",
codMart, fileName));
MtbAartLink mtbAartLink = new MtbAartLink();
mtbAartLink.setCodMart(codMart);
mtbAartLink.setPathLink(fileName);
byte[] content = FileUtils.readFileToByteArray(file);
String b64File = Base64.encodeBase64String(content);
mtbAartLink.setB64Content(b64File);
mtbAartLink.setDescrizioneLink("Immagine prodotto " + codMart);
if (artLinkResult == null || artLinkResult.isEmpty()) {
if (idRiga ==null) {
mtbAartLink.setOperation(OperationType.INSERT);
} else {
mtbAartLink.setIdRiga(idRiga);
mtbAartLink.setOperation(OperationType.UPDATE);
}