|
|
@ -5,6 +5,8 @@ import cn.estsh.i3plus.platform.common.tool.JsonUtilTool;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysBarcodeRule;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysBarcodeRule;
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
@ -21,6 +23,22 @@ public final class BarcodeParseUtil {
|
|
|
|
private BarcodeParseUtil() {
|
|
|
|
private BarcodeParseUtil() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ImppRedis redisRes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 按指定规则解析条码
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param barcodeRuleCode 条码规则信息
|
|
|
|
|
|
|
|
* @param barcode 条码
|
|
|
|
|
|
|
|
* @return 条码数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static Map<String, String> parse(String barcodeRuleCode, String barcode) {
|
|
|
|
|
|
|
|
if (redisRes == null) {
|
|
|
|
|
|
|
|
redisRes = SpringContextsUtil.getRedisRes();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return parse((SysBarcodeRule) redisRes.getObject(barcodeRuleCode), barcode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 按指定规则解析条码
|
|
|
|
* 按指定规则解析条码
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -40,23 +58,32 @@ public final class BarcodeParseUtil {
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Long start=System.currentTimeMillis();
|
|
|
|
//特殊分隔符处理
|
|
|
|
//特殊分隔符处理
|
|
|
|
barcodeRule.setBarcodeSeparator(barcodeRule.getBarcodeSeparator().replaceAll("\\\\", "\\\\\\\\"));
|
|
|
|
barcodeRule.setBarcodeSeparator(barcodeRule.getBarcodeSeparator().replaceAll("\\\\", "\\\\\\\\"));
|
|
|
|
barcodeRule.setBarcodeSeparator(barcodeRule.getBarcodeSeparator().replaceAll("\\|", "\\\\|"));
|
|
|
|
barcodeRule.setBarcodeSeparator(barcodeRule.getBarcodeSeparator().replaceAll("\\|", "\\\\|"));
|
|
|
|
barcodeRule.setBarcodeSeparator(barcodeRule.getBarcodeSeparator().replaceAll("\\.", "\\\\."));
|
|
|
|
barcodeRule.setBarcodeSeparator(barcodeRule.getBarcodeSeparator().replaceAll("\\.", "\\\\."));
|
|
|
|
|
|
|
|
Long tsfgf=System.currentTimeMillis();
|
|
|
|
|
|
|
|
System.out.println("特殊分隔符处理" + (tsfgf - start));
|
|
|
|
|
|
|
|
|
|
|
|
// 分隔条码信息
|
|
|
|
// 分隔条码信息
|
|
|
|
String[] barcodeKey = barcodeRule.getBarcodeRule().split(barcodeRule.getBarcodeSeparator());
|
|
|
|
String[] barcodeKey = barcodeRule.getBarcodeRule().split(barcodeRule.getBarcodeSeparator());
|
|
|
|
String[] barcodeValue = barcode.split(barcodeRule.getBarcodeSeparator());
|
|
|
|
String[] barcodeValue = barcode.split(barcodeRule.getBarcodeSeparator());
|
|
|
|
|
|
|
|
Long fgtm =System.currentTimeMillis();
|
|
|
|
|
|
|
|
System.out.println("分隔条码信息" + (fgtm - tsfgf));
|
|
|
|
|
|
|
|
|
|
|
|
// 校验
|
|
|
|
// 校验
|
|
|
|
verifyBarcode(barcodeRule,barcodeKey,barcodeValue,barcode);
|
|
|
|
verifyBarcode(barcodeRule,barcodeKey,barcodeValue,barcode);
|
|
|
|
|
|
|
|
Long jy =System.currentTimeMillis();
|
|
|
|
|
|
|
|
System.out.println("校验" + (jy - fgtm));
|
|
|
|
|
|
|
|
|
|
|
|
// 匹配条码数据
|
|
|
|
// 匹配条码数据
|
|
|
|
HashMap<String, String> barcodeMap = new HashMap<>();
|
|
|
|
HashMap<String, String> barcodeMap = new HashMap<>();
|
|
|
|
for (int i = 0; i < barcodeKey.length; i++) {
|
|
|
|
for (int i = 0; i < barcodeKey.length; i++) {
|
|
|
|
barcodeMap.put(barcodeKey[i], barcodeValue.length > i ? barcodeValue[i] : null);
|
|
|
|
barcodeMap.put(barcodeKey[i], barcodeValue.length > i ? barcodeValue[i] : null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Long pp =System.currentTimeMillis();
|
|
|
|
|
|
|
|
System.out.println("匹配条码数据" + (pp - jy));
|
|
|
|
return barcodeMap;
|
|
|
|
return barcodeMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -71,8 +98,11 @@ public final class BarcodeParseUtil {
|
|
|
|
boolean verifyFail = false;
|
|
|
|
boolean verifyFail = false;
|
|
|
|
if (barcodeRule.getCheckModeVal() == CommonEnumUtil.BARCODE_CHECK_MODE.SEPARATOR_NUM.getValue()) {
|
|
|
|
if (barcodeRule.getCheckModeVal() == CommonEnumUtil.BARCODE_CHECK_MODE.SEPARATOR_NUM.getValue()) {
|
|
|
|
// 校验分隔符的数量
|
|
|
|
// 校验分隔符的数量
|
|
|
|
int separatorNum = barcode.length() - barcode.replaceAll(barcodeRule.getBarcodeSeparator(), "").length() + 1;
|
|
|
|
int barcodeSeparatorNum = barcode.length() - barcode.replaceAll(barcodeRule.getBarcodeSeparator(), "").length() + 1;
|
|
|
|
verifyFail = barcodeKey.length != separatorNum;
|
|
|
|
int ruleSeparatorNum =barcodeRule.getBarcodeRule().length()
|
|
|
|
|
|
|
|
- barcodeRule.getBarcodeRule().replaceAll(barcodeRule.getBarcodeSeparator(), "").length() + 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verifyFail = ruleSeparatorNum != barcodeSeparatorNum;
|
|
|
|
} else if (barcodeRule.getCheckModeVal() == CommonEnumUtil.BARCODE_CHECK_MODE.ANALYTIC_NUM.getValue()) {
|
|
|
|
} else if (barcodeRule.getCheckModeVal() == CommonEnumUtil.BARCODE_CHECK_MODE.ANALYTIC_NUM.getValue()) {
|
|
|
|
// 校验解析后的数量是否相等
|
|
|
|
// 校验解析后的数量是否相等
|
|
|
|
verifyFail = barcodeKey.length != barcodeValue.length;
|
|
|
|
verifyFail = barcodeKey.length != barcodeValue.length;
|
|
|
|