fix:分隔符计数比较方式

yun-zuoyi
汪云昊 5 years ago
parent 7c88ff29d3
commit 85f11d7d0a

@ -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.platform.bean.SysBarcodeRule;
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.Map;
@ -21,6 +23,22 @@ public final class 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();
}
Long start=System.currentTimeMillis();
//特殊分隔符处理
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[] barcodeValue = barcode.split(barcodeRule.getBarcodeSeparator());
Long fgtm =System.currentTimeMillis();
System.out.println("分隔条码信息" + (fgtm - tsfgf));
// 校验
verifyBarcode(barcodeRule,barcodeKey,barcodeValue,barcode);
Long jy =System.currentTimeMillis();
System.out.println("校验" + (jy - fgtm));
// 匹配条码数据
HashMap<String, String> barcodeMap = new HashMap<>();
for (int i = 0; i < barcodeKey.length; i++) {
barcodeMap.put(barcodeKey[i], barcodeValue.length > i ? barcodeValue[i] : null);
}
Long pp =System.currentTimeMillis();
System.out.println("匹配条码数据" + (pp - jy));
return barcodeMap;
}
@ -71,8 +98,11 @@ public final class BarcodeParseUtil {
boolean verifyFail = false;
if (barcodeRule.getCheckModeVal() == CommonEnumUtil.BARCODE_CHECK_MODE.SEPARATOR_NUM.getValue()) {
// 校验分隔符的数量
int separatorNum = barcode.length() - barcode.replaceAll(barcodeRule.getBarcodeSeparator(), "").length() + 1;
verifyFail = barcodeKey.length != separatorNum;
int barcodeSeparatorNum = barcode.length() - barcode.replaceAll(barcodeRule.getBarcodeSeparator(), "").length() + 1;
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()) {
// 校验解析后的数量是否相等
verifyFail = barcodeKey.length != barcodeValue.length;

Loading…
Cancel
Save