forked from I3-YF/i3plus-mes-pcn-yfai
byd 装配件策略 截取右侧流水
parent
f82c6626a1
commit
b8cf5c7cfe
@ -0,0 +1,81 @@
|
||||
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.IMesProductionDispatchContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdTempDataContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionAssemblyNosortContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 规则并截取右侧流水
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MesNumberRuleMatchSubstringSerialService implements IMesNumberRuleMatchDispatchService {
|
||||
|
||||
@Autowired
|
||||
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> matchNumberRule(String organizeCode, String sn, Object... params) {
|
||||
// 校验正则表达式
|
||||
Map<String, Object> result = ((IMesNumberRuleMatchDispatchService) SpringContextsUtil.getBean(MesExtEnumUtil.ASSEMBLY_MATCH_TYPE.MATCH_TYPE_20.getStrategyClass())).matchNumberRule(organizeCode, sn, params);
|
||||
|
||||
if (!(Boolean) result.get(MesPcnExtConstWords.RESULT)) return result;
|
||||
|
||||
MesProductionAssemblyNosortContext context = (MesProductionAssemblyNosortContext) params[0];
|
||||
|
||||
if (StringUtils.isEmpty(context.getSerialLength())) {
|
||||
result.put(MesPcnExtConstWords.RESULT, false);
|
||||
result.put(MesPcnExtConstWords.MESSAGE, String.format("装配件ID[%s]信息未维护[截取的流水号长度]!", context.getSourceId()));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (context.getSerialLength().compareTo(sn.length()) > 0 ) {
|
||||
result.put(MesPcnExtConstWords.RESULT, false);
|
||||
result.put(MesPcnExtConstWords.MESSAGE, String.format("装配件条码[%s]不匹配截取的流水号长度[%s]!", sn, context.getSerialLength()));
|
||||
return result;
|
||||
}
|
||||
|
||||
//截取右侧流水, 生成零件条码工步需要使用此流水生成新的零件条码
|
||||
String serialNo = substringSerial(context.getAssemblySn(), context.getSerialLength());
|
||||
|
||||
//一腔如果存在两个这个规则的情况下,需要验证两次的流水号是否一直
|
||||
List<MesProdTempDataContext> prodTempDataContextList = productionDispatchContextStepService.getProdTempDataContext(organizeCode, context.getWorkCenterCode(), context.getWorkCellCode());
|
||||
Optional<MesProdTempDataContext> optional = CollectionUtils.isEmpty(prodTempDataContextList) ? null :
|
||||
prodTempDataContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()) && o.getForeignKey().compareTo(context.getForeignKey()) == 0)).findFirst();
|
||||
if (null == optional || !optional.isPresent() || StringUtils.isEmpty(optional.get().getSerialNo())) {
|
||||
if (CollectionUtils.isEmpty(prodTempDataContextList)) prodTempDataContextList = new ArrayList<>();
|
||||
prodTempDataContextList.add(new MesProdTempDataContext(organizeCode, context.getForeignKey()).serialNo(serialNo));
|
||||
productionDispatchContextStepService.dispatchProdTempDataContext(organizeCode, context.getWorkCenterCode(), context.getWorkCellCode(), prodTempDataContextList);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!serialNo.equals(optional.get().getSerialNo())) {
|
||||
result.put(MesPcnExtConstWords.RESULT, false);
|
||||
result.put(MesPcnExtConstWords.MESSAGE, String.format("装配件条码[%s]的右侧流水号[%s]与首次扫描的流水号[%s]不一致!", sn, serialNo, optional.get().getSerialNo()));
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
//截取右侧流水, 生成零件条码工步需要使用此流水生成新的零件条码
|
||||
private String substringSerial(String sn, Integer serialLength) {
|
||||
return sn.substring(sn.length() - serialLength);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.pojo.context;
|
||||
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 生产过程上下文对象-临时数据
|
||||
*/
|
||||
@Data
|
||||
public class MesProdTempDataContext implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5184127961206077150L;
|
||||
|
||||
@ApiParam("组织代码")
|
||||
public String organizeCode;
|
||||
|
||||
@ApiParam(name = "数据关联键")
|
||||
private Integer foreignKey;
|
||||
|
||||
@ApiParam("流水号")
|
||||
public String serialNo;
|
||||
|
||||
public MesProdTempDataContext() {}
|
||||
|
||||
public MesProdTempDataContext(String organizeCode) {
|
||||
this.organizeCode = organizeCode;
|
||||
}
|
||||
|
||||
public MesProdTempDataContext(String organizeCode, Integer foreignKey) {
|
||||
this.organizeCode = organizeCode;
|
||||
this.foreignKey = foreignKey;
|
||||
}
|
||||
|
||||
public MesProdTempDataContext serialNo(String serialNo) {
|
||||
this.serialNo = serialNo;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue