|
|
@ -1,6 +1,7 @@
|
|
|
|
package cn.estsh.i3plus.core.apiservice.util;
|
|
|
|
package cn.estsh.i3plus.core.apiservice.util;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
|
|
|
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;
|
|
|
@ -17,7 +18,8 @@ import java.util.Map;
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
public final class BarcodeParseUtil {
|
|
|
|
public final class BarcodeParseUtil {
|
|
|
|
|
|
|
|
|
|
|
|
private BarcodeParseUtil(){}
|
|
|
|
private BarcodeParseUtil() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 按指定规则解析条码
|
|
|
|
* 按指定规则解析条码
|
|
|
@ -47,17 +49,71 @@ public final class BarcodeParseUtil {
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
|
|
// 避免出现长度不相等
|
|
|
|
// 校验
|
|
|
|
int size = barcodeKey.length;
|
|
|
|
verifyBarcode(barcodeRule,barcodeKey,barcodeValue,barcode);
|
|
|
|
if (barcodeKey.length != barcodeValue.length) {
|
|
|
|
|
|
|
|
size = Math.min(barcodeKey.length,barcodeValue.length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 匹配条码数据
|
|
|
|
// 匹配条码数据
|
|
|
|
HashMap<String, String> barcodeMap = new HashMap<>();
|
|
|
|
HashMap<String, String> barcodeMap = new HashMap<>();
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
for (int i = 0; i < barcodeKey.length; i++) {
|
|
|
|
barcodeMap.put(barcodeKey[i], barcodeValue[i]);
|
|
|
|
barcodeMap.put(barcodeKey[i], barcodeValue.length > i ? barcodeValue[i] : null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return barcodeMap;
|
|
|
|
return barcodeMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 条码校验
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param barcodeRule 校验模式
|
|
|
|
|
|
|
|
* @param barcodeKey 条码key
|
|
|
|
|
|
|
|
* @param barcodeValue 条码值
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static void verifyBarcode(SysBarcodeRule barcodeRule, String[] barcodeKey, String[] barcodeValue, String barcode) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
} else if (barcodeRule.getCheckModeVal() == CommonEnumUtil.BARCODE_CHECK_MODE.ANALYTIC_NUM.getValue()) {
|
|
|
|
|
|
|
|
// 校验解析后的数量是否相等
|
|
|
|
|
|
|
|
verifyFail = barcodeKey.length != barcodeValue.length;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (verifyFail) {
|
|
|
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
|
|
|
.setErrorDetail("条码与规则不匹配!")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
String str = "{\n" +
|
|
|
|
|
|
|
|
"\t\t\"id\": \"1202112194247430144\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"organizeCode\": \"\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"isValid\": 1,\n" +
|
|
|
|
|
|
|
|
"\t\t\"isDeleted\": 2,\n" +
|
|
|
|
|
|
|
|
"\t\t\"createUser\": \"qianhuasheng\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"createDatetime\": \"2019-12-04 14:27:35\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"modifyUser\": \"qianhuasheng\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"modifyDatetime\": \"2019-12-04 14:27:35\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"createDateTimeStart\": null,\n" +
|
|
|
|
|
|
|
|
"\t\t\"createDateTimeEnd\": null,\n" +
|
|
|
|
|
|
|
|
"\t\t\"modifyDateTimeStart\": null,\n" +
|
|
|
|
|
|
|
|
"\t\t\"modifyDateTimeEnd\": null,\n" +
|
|
|
|
|
|
|
|
"\t\t\"orderByParam\": \"\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"ascOrDesc\": 1,\n" +
|
|
|
|
|
|
|
|
"\t\t\"sortParamMap\": null,\n" +
|
|
|
|
|
|
|
|
"\t\t\"name\": \"VDA生产标签打印解析二维码\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"barcodeRuleCode\": \"VDA_REPORT_SN_2D\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"barcodeRule\": \"partNo|express\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"barcodeSeparator\": \"|\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"barcodeRuleDescription\": \"VDA生产标签打印解析二维码\",\n" +
|
|
|
|
|
|
|
|
"\t\t\"isValidVal\": 1,\n" +
|
|
|
|
|
|
|
|
"\t\t\"checkMode\": 10,\n" +
|
|
|
|
|
|
|
|
"\t\t\"isDeletedVal\": 2\n" +
|
|
|
|
|
|
|
|
"\t}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(parse(JsonUtilTool.decode(str,SysBarcodeRule.class),"YFRHU|"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|