Merge branch 'develop' into feature/MRP_RimossoCodMdep

This commit is contained in:
2024-05-24 17:26:35 +02:00
13 changed files with 478 additions and 18 deletions

View File

@@ -0,0 +1,31 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20240522152800 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
createSetup("IMPORT_COLLI", "EVIOSYS", "ATTIVO", "N", "Inserire S/N per attivare/disattivare il tipo di importazione", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "COD_ANAG", null, "Codice fornitore", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "COD_MDEP", null, "Codice deposito", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "EMAIL_FOR_LOG", null, "Inserire il file l'indirizzo email per inviare il log dell'importazione", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "FILE_FILTER", null, "Inserire il criterio di filtro dei file o il nome del file specifio (seguire la sintassi di java)", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "GG_CANC_FILE", null, "Giorni per la cancellazione dei file dalla cartella di appoggio", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "IMPORT_REST", "S", "Inserire S/N per attivare/disattivare il salvataggio con i servizi REST", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "LISTENING", "N", "Se LISTENIG = 'N' la procedura di importazione non si potrà mai mettere in ascolto sulla directory perchè nella procedura vengono prese in considerazione più file.", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "PATH_FILE", null, "Directory contente i file da importare.", false, null, false, false, false, false, false, null, false, null);
createSetup("IMPORT_COLLI", "EVIOSYS", "PATH_FILE_IMPORTED", null, "Directory dove vengono spostati i file dopo l'importazione.", false, null, false, false, false, false, false, null, false, null);
}
@Override
public void down() throws Exception {
}
}

View File

@@ -0,0 +1,21 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20240523120224 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
executeStatement("alter table jtb_flav add iban varchar(40)");
}
@Override
public void down() throws Exception {
}
}

View File

@@ -148,6 +148,9 @@ public class JtbFlav extends EntityBase {
@SqlField(value = "cod_intercode", maxLength = 40, nullable = true)
private String codIntercode;
@SqlField(value = "iban", maxLength = 40, nullable = true)
private String iban;
private String precode;
@EntityChild
@@ -501,6 +504,14 @@ public class JtbFlav extends EntityBase {
this.codIntercode = codIntercode;
}
public String getIban() {
return iban;
}
public void setIban(String iban) {
this.iban = iban;
}
public String getPrecode() {
return precode;
}

View File

@@ -98,7 +98,7 @@ public class DocCostiTrasporto {
if (rifDoc == null || rifDoc.length() == 0){
rifDoc = "[VUOTO]";
}
note += "@RIF_DOC=" + rifDoc + " riferimento documento non valida";
note += "@RIF_DOC=" + rifDoc + " riferimento documento presente nel file non valida";
dataDoc = dataSped;
} else {
codAnag = null;

View File

@@ -10,6 +10,7 @@ import it.integry.ems.document.fatture.services.InvoicePAService;
import it.integry.ems.export.base.BaseEntityExporter;
import it.integry.ems.export.base.EntityExportResponse;
import it.integry.ems.export.base.IEntityExporter;
import it.integry.ems.order.export.service.OrdiniVenditaExportServices;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems_model.base.EntityBase;
import it.integry.ems_model.entity.*;
@@ -106,6 +107,14 @@ public class DocumentiExporter extends BaseEntityExporter implements IEntityExpo
DocumentiChepExportService chepExportServices = context.getBean(DocumentiChepExportService.class);
entityExportResponse = chepExportServices.export(type, format, whereCond);
break;
case DAS:
DocumentDasExport exportDASAccise = ContextLoader.getCurrentWebApplicationContext().getBean(DocumentDasExport.class);
entityExportResponse = exportDASAccise.exportDASAccise(username,type, format, whereCond);
break;
case TOSCA:
DocumentiToscaExportService toscaExportService = context.getBean(DocumentiToscaExportService.class);
entityExportResponse = toscaExportService.export(username, type, format);
break;
}
}
@@ -213,6 +222,8 @@ public class DocumentiExporter extends BaseEntityExporter implements IEntityExpo
COOP("COOP"),
SIAN("SIAN"),
BRT("BRT"),
DAS("DAS"),
TOSCA("TOSCA"),
CHEP("CHEP");
private String text;

View File

@@ -0,0 +1,126 @@
package it.integry.ems.document.export.service;
import com.annimon.stream.Stream;
import it.integry.common.var.CommonConstants;
import it.integry.ems.export.base.EntityExportResponse;
import it.integry.ems.export.base.ExportFromQuery;
import it.integry.ems.response.FileItem;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems.service.HttpRestWrapper;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems_model.entity.WtbUsersInfo;
import it.integry.ems_model.service.SetupGest;
import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityDate;
import it.integry.ems_model.utility.UtilityString;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.entity.ContentType;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
@Service
@Scope(value = "request")
public class DocumentDasExport {
@Autowired
MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private SetupGest setupGest;
@Autowired
private EntityProcessor entityProcessor;
@Autowired
ExportFromQuery exportFromQuery;
public EntityExportResponse exportDASAccise(String username, String type, String format, String whereCond) throws Exception {
EntityExportResponse response = exportFromQuery.export(username, type, format, whereCond);
FileItem xlsFile = ((ArrayList<FileItem>) response.getResponse()).stream().findFirst().orElse(null);
WtbUsersInfo wtbUsersInfo = new WtbUsersInfo().setUserName(username).setExportType(type).setFormatFile(format);
wtbUsersInfo.setOperation(OperationType.SELECT_OBJECT);
entityProcessor.processEntity(wtbUsersInfo, multiDBTransactionManager);
String profileDb = multiDBTransactionManager.getPrimaryDatasource().getProfile().toLowerCase();
String queryCustom = wtbUsersInfo.getQueryCustom();
queryCustom = UtilityDB.addwhereCond(queryCustom, whereCond, true);
List<HashMap<String, Object>> result = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), queryCustom);
List<String> fullJsonArray = Stream.of(result).map(x -> x.get("cod_mart").toString()).distinct().toList();
String flagFileCompress = wtbUsersInfo.getFlagFileCompress();
EntityExportResponse<List<FileItem>> entityExportResponse = new EntityExportResponse<>();
entityExportResponse.setResponse(new ArrayList<>());
String url = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "URL", "IMMAGINI_WEB");
String regex = "[\\/]*" + profileDb + "[\\/]*\\b[^.]";
url = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE).matcher(url).replaceAll("/");
HashMap<String, String> params = new HashMap<>();
params.put("profileDb", profileDb);
params.put("XDEBUG_SESSION", "PHPSTORM");
int maxElementsPerPiece = 20;
List<String> responses = new ArrayList<>();
List<List<String>> jsonPieces;
AtomicInteger counter = new AtomicInteger();
jsonPieces = Stream.of(fullJsonArray).chunkBy(x -> counter.getAndIncrement() / maxElementsPerPiece).toList();
for (List<String> jsonPiece : jsonPieces) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("articoli", jsonPiece);
String jsonPieceString = jsonObject.toString();
StringBuilder responseBodyString = new StringBuilder();
HttpRestWrapper.callGeneric(
url,
null,
null,
jsonPieceString,
ContentType.APPLICATION_JSON,
responseBodyString,
params
);
if(!UtilityString.isNullOrEmpty(responseBodyString.toString()))
responses.add(responseBodyString.toString());
}
if (!responses.isEmpty()) {
String fileName;
byte[] fileContent;
/* for (String responseBodyString : responses){
JSONObject jsonObject = new JSONObject(responseBodyString);
for(String key : jsonObject.keySet()){
fileName = jsonObject.getString(key);
fileContent = downloadFile(new URL(url + profileDb + "/" + fileName));
FileItem fileItem = new FileItem(fileName, fileContent, FilenameUtils.getExtension(fileName));
entityExportResponse.getResponse().add(fileItem);
}
}*/
entityExportResponse.getResponse().add(xlsFile);
}
return entityExportResponse;
}
}

View File

@@ -0,0 +1,96 @@
package it.integry.ems.document.export.service;
import it.integry.ems.export.base.EntityExportResponse;
import it.integry.ems.response.FileItem;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems_model.entity.WtbUsersInfo;
import it.integry.ems_model.service.SetupGest;
import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.utility.Query;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityResultSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@Service
@Scope(value = "request")
public class DocumentiToscaExportService {
@Autowired
MultiDBTransactionManager multiDBTransactionManager;
@Autowired
EntityProcessor entityProcessor;
@Autowired
SetupGest setupGest;
public EntityExportResponse export(String userName, String type, String format) throws Exception {
EntityExportResponse<List<FileItem>> entityExportResponse = new EntityExportResponse<>();
WtbUsersInfo wtbUsersInfo =
new WtbUsersInfo()
.setUserName(userName)
.setExportType(type)
.setFormatFile(format);
wtbUsersInfo.setOperation(OperationType.SELECT_OBJECT);
entityProcessor.processEntity(wtbUsersInfo, multiDBTransactionManager);
char charSeparator = ';';
String ext = "csv",
fileName = wtbUsersInfo.getFileName();
String sql = Query.format(
"SELECT (SELECT gtb_anag.cod_anag\n" +
" FROM gtb_anag\n" +
" INNER JOIN azienda ON azienda.part_iva = gtb_anag.part_iva\n" +
" INNER JOIN atb_forn ON gtb_anag.cod_anag = atb_forn.cod_anag) AS 'LOCATION_1',\n" +
" mtb_movi.cod_anag AS 'LOCATION_2',\n" +
" mtb_movi.data_reg AS 'DATE',\n" +
" IIF(mtb_movi.qta_car > 0, 'IN', 'OUT') AS 'DIRECTION',\n" +
" mtb_movi.num_doc AS 'REFERENCE',\n" +
" mtb_movi.cod_mart AS 'ITEM',\n" +
" ABS(mtb_movi.qta_car) AS 'QUANTITY'\n" +
"FROM mtb_movi\n" +
" INNER JOIN mtb_tcol\n" +
" ON mtb_tcol.cod_mart = mtb_movi.cod_mart\n" +
"WHERE mtb_movi.data_doc = '2024/05/23'\n" +
" AND mtb_tcol.circuito = 'TOSCA'"
);
PreparedStatement stm = multiDBTransactionManager
.getPrimaryConnection()
.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stm.executeQuery();
byte[] csvContent = UtilityResultSet.mapResultSetToCSV(rs, charSeparator, true, false).getBytes();
rs.close();
stm.close();
fileName += new SimpleDateFormat("yyyyMMdd").format(new Date()) + "." + ext;
FileItem file = new FileItem(fileName, csvContent, ext);
entityExportResponse
.setResponse(new ArrayList<>())
.getResponse()
.add(file);
return entityExportResponse;
}
}

View File

@@ -4,6 +4,7 @@ import it.integry.ems.Import.base.BaseEntityImporter;
import it.integry.ems.Import.base.IEntityImporter;
import it.integry.ems.logistic.Import.service.*;
import it.integry.ems.logistic.service.ColliBaioneImportService;
import it.integry.ems.logistic.service.ColliEviosysImportService;
import it.integry.ems.logistic.service.ColliImportService;
import it.integry.ems_model.base.EntityBase;
import org.springframework.web.context.ContextLoader;
@@ -54,7 +55,9 @@ public class ColliImporter extends BaseEntityImporter implements IEntityImporter
break;
case BAIONE:
entities = context.getBean(ColliBaioneImportService.class).importColli(type, format, requestDto, anomalie);
break;
case EVIOSYS:
entities = context.getBean(ColliEviosysImportService.class).importColli(type, format, requestDto, anomalie);
break;
default:
throw new Exception(String.format("Tipo %s non supportato", format));
@@ -75,7 +78,8 @@ public class ColliImporter extends BaseEntityImporter implements IEntityImporter
ICON_ACCETTAZIONE("ICON_ACCETTAZIONE"),
STEUP("STEUP"),
METALSISTEM("METALSISTEM"),
BAIONE("BAIONE");
BAIONE("BAIONE"),
EVIOSYS("EVIOSYS");
private String text;

View File

@@ -0,0 +1,168 @@
package it.integry.ems.logistic.service;
import it.integry.ems.Import.dto.AnomalieDTO;
import it.integry.ems.Import.dto.ImportRequestDTO;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems_model.base.EntityBase;
import it.integry.ems_model.entity.MtbColr;
import it.integry.ems_model.entity.MtbColt;
import it.integry.ems_model.service.SetupGest;
import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.utility.Query;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityExcel;
import it.integry.ems_model.utility.UtilityString;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.sql.Connection;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.StreamSupport.stream;
@Service
@Scope(value = "request")
public class ColliEviosysImportService {
@Autowired
private EntityProcessor entityProcessor;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private SetupGest setupGest;
public List<EntityBase> importColli(String type, String format, ImportRequestDTO requestDTO, List<AnomalieDTO> anomalie) throws Exception {
Connection conn = multiDBTransactionManager.getPrimaryConnection();
Map<String, String> setup = setupGest.getImportSetupSection(conn, type, format);
String codAnag = setup.get("COD_ANAG");
String codMdep = setup.get("COD_MDEP");
Iterator<Row> rowIterator = UtilityExcel.readXlsxFile(requestDTO);
String codMart = null;
boolean hasHeaderPassed = false;
List<MtbColt> mtbColtList = new ArrayList<>();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
if (!hasHeaderPassed) {
if (codMart == null) {
codMart = findCodMart(row);
} else {
hasHeaderPassed = UtilityExcel.getCellAsString(row, 0, false).equalsIgnoreCase("origine");
}
} else {
List<Object> rowData =
stream(((Iterable<Cell>) row::cellIterator).spliterator(), false)
.map(x -> {
Object s = cellToString(x);
if (!UtilityString.isNullOrEmpty(s)) {
return s;
}
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (rowData.size() >= 7) {
String barcodeUl = (String) rowData.get(2);
String qta = (String) rowData.get(6);
if (barcodeUl.length() > 18) {
barcodeUl = barcodeUl.substring(2);
}
MtbColr mtbColr = new MtbColr()
.setCodMart(codMart)
.setQtaCol(UtilityString.stringToBigDecimal(qta));
MtbColt mtbColt = new MtbColt()
.setDataCollo(LocalDate.now())
.setSegno(1)
.setGestione("A")
.setBarcodeUl(barcodeUl)
.setCodMdep(codMdep)
.setCodAnag(codAnag);
mtbColt.setMtbColr(new ArrayList<>())
.getMtbColr()
.add(mtbColr);
mtbColt.setOperation(OperationType.INSERT);
mtbColtList.add(mtbColt);
}
}
}
return entityProcessor.processEntityList(mtbColtList, multiDBTransactionManager, true);
}
private Object cellToString(Cell cell) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
for (int i = 0; i < cell.getStringCellValue().length(); i++) {
if (cell.getStringCellValue().charAt(i) != ' ') {
return cell.getStringCellValue().trim();
}
}
return "";
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
double numericCellValue = cell.getNumericCellValue();
if (numericCellValue == Math.floor(numericCellValue)) {
return String.valueOf((int) numericCellValue);
}
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue();
} else {
return String.valueOf(numericCellValue);
}
} else {
return "";
}
}
private String findCodMart(Row row) throws Exception {
Iterator<Cell> cellIterator = row.cellIterator();
String codArtFor = stream(((Iterable<Cell>) () -> cellIterator).spliterator(), false)
.map(cell -> {
try {
return UtilityExcel.getCellAsString(row, cell.getColumnIndex(), true);
} catch (Exception e) {
return null;
}
})
.filter(Objects::nonNull)
.reduce(new String[]{null, null}, (state, cell) -> {
if (state[0] == null && cell.equalsIgnoreCase("viaggio:")) {
state[0] = "viaggio";
} else if (state[0] != null && state[1] == null && cell.equalsIgnoreCase("articolo:")) {
state[1] = "articolo";
} else if ("articolo".equals(state[1]) && UtilityString.isNumber(cell)) {
state[1] = cell;
}
return state;
}, (s1, s2) -> s1)[1];
if (codArtFor != null) {
String sql = Query.format("SELECT cod_mart FROM mtb_lisa WHERE cod_art_for = %s", codArtFor);
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
}
return null;
}
}

View File

@@ -67,13 +67,6 @@ public class ProductController {
@Autowired
private ServiceChecker serviceChecker;
@ExceptionHandler({Exception.class})
public @ResponseBody
ServiceRestResponse handleException(HttpServletRequest request, HttpServletResponse response, Exception ex) {
logger.error(request.getRequestURI(), ex);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return ServiceRestResponse.createNegativeResponse(ex);
}
@RequestMapping(value = "/product/status", method = RequestMethod.GET)
public @ResponseBody
@@ -89,9 +82,8 @@ public class ProductController {
ServiceRestResponse confirmTempListino(
HttpServletRequest request,
@RequestParam(CommonConstants.PROFILE_DB) String configuration) throws Exception {
ServiceRestResponse response = ServiceRestResponse.createEntityPositiveResponse(importAnagListiniService.confirmTempListino());
ServiceRestResponse response = ServiceRestResponse.createPositiveResponse();
response.setEntityList(importAnagListiniService.confirmTempListino());
return response;
}

View File

@@ -4,6 +4,8 @@ import com.annimon.stream.Optional;
import com.annimon.stream.Stream;
import it.integry.common.var.CommonConstants;
import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.response.EsitoType;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.user.UserSession;
@@ -13,6 +15,7 @@ import it.integry.ems_model.config.EmsRestConstants;
import it.integry.ems_model.db.EntityToDatabaseMapper;
import it.integry.ems_model.db.ResultSetMapper;
import it.integry.ems_model.entity.*;
import it.integry.ems_model.exception.EntityException;
import it.integry.ems_model.service.SetupGest;
import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.utility.*;
@@ -47,6 +50,7 @@ public class ImportAnagListiniService {
private UserSession userSession;
public List<AtbListData> confirmTempListino() throws Exception {
List<AtbListData> atbListDataToSave = new ArrayList<>();
if (!userSession.isAttivo())
throw new Exception("L'utente non è valido");
@@ -173,7 +177,6 @@ public class ImportAnagListiniService {
if (!atbListImpNoPrefsToUpdate.isEmpty()) {
entityProcessor.processEntityList(atbListImpNoPrefsToUpdate, true);
throw new Exception("Si sono verificati alcuni errori, controllare i dati importati.");
}
@@ -210,8 +213,6 @@ public class ImportAnagListiniService {
}
List<EntityBase> entitiesToSave = new ArrayList<>();
List<AtbListData> atbListDataToSave = new ArrayList<>();
for (AtbListImpNoPref data : dbData) {
@@ -405,7 +406,6 @@ public class ImportAnagListiniService {
ps.close();
}
return atbListDataToSave;
}

View File

@@ -401,7 +401,7 @@ public class ListiniVenditaServices {
.setDataIniz(x.getDataIniz())
.setDataFine(x.getDataFine())
.setDescrPromo(x.getDescrPromo())
.setNote(x.getNote());
.setNote(x.getNoteLisv());
return vtbListData;
}
).toList();

View File

@@ -378,7 +378,7 @@ public class AgribookOrderService {
" dtb_ordr.data_ord = dtb_ordt.data_ord AND\n" +
" dtb_ordr.num_ord = dtb_ordt.num_ord\n" +
" INNER JOIN gtb_anag ON dtb_ordt.cod_anag = gtb_anag.cod_anag\n" +
" INNER JOIN azienda ON azienda.part_iva <> gtb_anag.part_iva\n" +
" INNER JOIN azienda ON azienda.part_iva <> ISNULL(gtb_anag.part_iva, '')\n" +
" INNER JOIN mtb_colt ON mtb_colt.gestione = dtb_ordt.gestione AND\n" +
" mtb_colt.data_ord = dtb_ordt.data_ord AND\n" +
" mtb_colt.num_ord = dtb_ordt.num_ord\n" +