Merge branch 'hotfix/Hotfix-1'
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -486,6 +486,7 @@ public class EmsRestConstants {
|
||||
public static final String PATH_CMD_2_EXPORT = PATH + "cmd2Export";
|
||||
public static final String PATH_VALIDATE_XML_BY_SCHEMA = PATH + "validateXMLBySchema";
|
||||
public static final String PATH_DECODE_EAN_128 = PATH + "decodeEan128";
|
||||
public static final String PATH_EXTRACT_SSCC = PATH + "extractSSCC";
|
||||
public static final String PATH_SQL_TO_EXCEL = PATH + "sqlToExcel";
|
||||
public static final String PATH_READ_REMOTE_FILE = PATH + "readRemoteFile";
|
||||
public static final String PATH_FPX_TO_PDF = PATH + "fpxToPdf";
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package it.integry.ems_model.utility;
|
||||
|
||||
import it.integry.ems_model.utility.BarcodeEan128.Ean128Model;
|
||||
import it.integry.ems_model.utility.BarcodeEan128.UtilityBarcodeEan128;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class UtilityBarcode {
|
||||
|
||||
private static String stato = "";
|
||||
@@ -147,6 +153,32 @@ public class UtilityBarcode {
|
||||
|
||||
}
|
||||
|
||||
public static String extractSSCC(String barcode) {
|
||||
Ean128Model ean128;
|
||||
try{
|
||||
ean128 = UtilityBarcodeEan128.decode(barcode.getBytes());
|
||||
}catch (Exception e) {
|
||||
ean128 = new Ean128Model();
|
||||
}
|
||||
if (!UtilityString.isNullOrEmpty(ean128.Sscc))
|
||||
return ean128.Sscc;
|
||||
|
||||
final Pattern pattern = Pattern.compile("^[0-9]{18}$");
|
||||
final Matcher matcher = pattern.matcher(barcode);
|
||||
if (matcher.find() && barcode.substring(17,18).equalsIgnoreCase(getSSCCCheckDigit(barcode))) {
|
||||
return barcode;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isUlAnonima(String barcode){
|
||||
final Pattern pattern = Pattern.compile("^U[0-9]{9}[a-zA-Z]{0,2}$");
|
||||
final Matcher matcher = pattern.matcher(barcode);
|
||||
|
||||
return matcher.find();
|
||||
}
|
||||
|
||||
public enum TypeTable {
|
||||
A, B, C;
|
||||
}
|
||||
@@ -178,4 +210,44 @@ public class UtilityBarcode {
|
||||
}
|
||||
return tot % 10 == 0 ? "0" : "" + (10 - (tot % 10));
|
||||
}
|
||||
|
||||
private static String getSSCCCheckDigit(String sscc) {
|
||||
if (sscc == null || sscc.length() == 0 || sscc.length() < 17 || sscc.length() > 18) {
|
||||
throw new IllegalArgumentException("La stringa richiesta non è un SSCC valido");
|
||||
}
|
||||
|
||||
|
||||
sscc = sscc.substring(0, 17);
|
||||
|
||||
|
||||
final Pattern pattern = Pattern.compile("^[0-9]{17}$");
|
||||
final Matcher matcher = pattern.matcher(sscc);
|
||||
|
||||
if (!matcher.find()) {
|
||||
throw new IllegalArgumentException("L'SSCC deve contenere solo cifre numeriche");
|
||||
}
|
||||
|
||||
|
||||
int sum = 0;
|
||||
|
||||
// Applica l'algoritmo Modulo 10
|
||||
// Moltiplica per 3 le cifre in posizione pari (contando da destra)
|
||||
// Moltiplica per 1 le cifre in posizione dispari (contando da destra)
|
||||
for (int i = 0; i < sscc.length(); i++) {
|
||||
int digit = Character.getNumericValue(sscc.charAt(i));
|
||||
|
||||
// Gli indici pari vengono dalla fine, quindi per le posizioni da sinistra
|
||||
// usiamo i % 2 == 0 per posizioni dispari e i % 2 == 1 per posizioni pari
|
||||
if (i % 2 == 0) {
|
||||
sum += digit * 3; // Posizioni dispari (indice 0, 2, 4, ecc.)
|
||||
} else {
|
||||
sum += digit * 1; // Posizioni pari (indice 1, 3, 5, ecc.)
|
||||
}
|
||||
}
|
||||
|
||||
// Calcola il complemento a 10 della somma
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
|
||||
return String.valueOf(checkDigit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import it.integry.ems.utility.request.SqlToExcelRequest;
|
||||
import it.integry.ems.utility.service.UtilityService;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
import it.integry.ems_model.utility.BarcodeEan128.UtilityBarcodeEan128;
|
||||
import it.integry.ems_model.utility.UtilityBarcode;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -199,4 +200,11 @@ public class UtilityController {
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(utilityService.getRicorrenze(anno));
|
||||
}
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_EXTRACT_SSCC, method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse extractSSCC(HttpServletRequest request,
|
||||
@RequestParam("barcode") String barcode) throws Exception {
|
||||
return ServiceRestResponse.createPositiveResponse(UtilityBarcode.extractSSCC(barcode));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user