|
|
|
@ -3,6 +3,7 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesNumberRuleMatchDispatchService;
|
|
|
|
|
import com.google.common.base.Objects;
|
|
|
|
|
import jdk.nashorn.internal.runtime.regexp.joni.Regex;
|
|
|
|
|
import jodd.util.StringUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
@ -22,11 +23,8 @@ public class MesNumberRuleMatchRegularExpressionService implements IMesNumberRul
|
|
|
|
|
|
|
|
|
|
String matchRule = params[1].toString();
|
|
|
|
|
|
|
|
|
|
if (sn.matches(matchRule)){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return match(matchRule, sn);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean match(String ruleStr, String barCode) {
|
|
|
|
@ -52,10 +50,31 @@ public class MesNumberRuleMatchRegularExpressionService implements IMesNumberRul
|
|
|
|
|
Matcher matcher = regex.matcher(rule);
|
|
|
|
|
return matcher.matches();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String ruleNoSpecialChar = transfer(rule);
|
|
|
|
|
String barcodeNoSpecialChar = transfer(barCode);
|
|
|
|
|
///将规则转换为正则表达式,使用正则表达式进行匹配,正则中去除二维码的起始特殊符号
|
|
|
|
|
//update by huxj 2020.04.07 添加二维码前缀正则匹配
|
|
|
|
|
String regStr = "^" + ruleNoSpecialChar.toLowerCase().replace(")", "\\)").replace("?", "(?:.|\n){1}").replace("*", "(?:.|-\n)*").replace("[", "\\[") + "$";
|
|
|
|
|
//Regex rgx = new Regex("^" + ruleNoSpecialChar.ToLower().Replace("?", @"(?:.|\n){1}").Replace("*", @"(?:.|\n)*") + "$");
|
|
|
|
|
Pattern regex = Pattern.compile(regStr);
|
|
|
|
|
//end update
|
|
|
|
|
if (regex.matcher(barcodeNoSpecialChar.toLowerCase()).matches()) return true;
|
|
|
|
|
if (rule == barCode) return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String transfer(String str){
|
|
|
|
|
// 1. 定义正则表达式,匹配特殊字符
|
|
|
|
|
String regex = "[^a-zA-Z0-9^\\s^*?[)>.:^/]]";
|
|
|
|
|
|
|
|
|
|
// 2. 使用正则表达式替换特殊字符为空字符串
|
|
|
|
|
return str.replaceAll(regex, "");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
String sn = "1574110000123";
|
|
|
|
|
String matchRule = "1574110000*";
|
|
|
|
|