规则策略

tags/yfai-pcn-ext-v1.0
微笑着面对明天 11 months ago
parent 22560a0a8b
commit e1f5ed5610

@ -0,0 +1,69 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesNumberRuleMatchDispatchService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProduceSnExtService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionAssemblyNosortContext;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionAssembly;
import cn.estsh.i3plus.pojo.mes.repository.MesProductionAssemblyRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import com.google.common.base.Objects;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
*
*/
@Slf4j
@Service
public class MesNumberRuleMatchAndUniqueService implements IMesNumberRuleMatchDispatchService {
private static final Logger LOGGER = LoggerFactory.getLogger(MesNumberRuleMatchAndUniqueService.class);
@Autowired
private IMesProduceSnExtService produceSnExtService;
@Resource
@Qualifier("mesNumberRuleMatchRegularExpressionService")
private IMesNumberRuleMatchDispatchService mesNumberRuleMatchDispatchService;
@Autowired
private MesProductionAssemblyRepository productionAssemblyRepository;
@Override
public Boolean matchNumberRule(String organizeCode, String sn, Object... params) {
// 校验正则表达式
boolean flag = mesNumberRuleMatchDispatchService.matchNumberRule(organizeCode, sn, params);
// 校验是否唯一
boolean uniqueFlag = validateUnique(sn);
return flag && uniqueFlag;
}
/**
*
* @param sn
* @return
*/
private boolean validateUnique(String sn) {
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
DdlPreparedPack.getStringEqualPack(sn,"assemblySn", ddlPackBean);
MesProductionAssembly productionAssembly = productionAssemblyRepository.getByProperty(ddlPackBean);
if (productionAssembly != null) {
return false;
}
return true;
}
}

@ -52,9 +52,7 @@ public class MesNumberRuleMatchRegularExpressionService implements IMesNumberRul
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;

Loading…
Cancel
Save