forked from I3-YF/i3plus-mes-pcn-yfai
Merge branch 'dev' into dev-wuhan
commit
f894210e6f
@ -1,159 +0,0 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.equiplog;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesScanMonitorContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.swslog.ISwsWriteDbLogService;
|
||||
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
||||
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCellScanMonitorLog;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesWorkCellScanMonitorLogRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MesWorkCellScanMonitorLogExt2Service implements ISwsWriteDbLogService {
|
||||
|
||||
@Autowired
|
||||
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
||||
|
||||
@Autowired
|
||||
private MesWorkCellScanMonitorLogRepository workCellScanMonitorLogRepository;
|
||||
|
||||
private final static Map<String, List<String>> cellMsg2RepeatMap = new ConcurrentHashMap();
|
||||
|
||||
@Override
|
||||
public void doWriteDbLog(StationResultBean resultBean) {
|
||||
|
||||
//获取上下文工位扫描监控信息
|
||||
MesScanMonitorContext scanMonitorContext = productionProcessContextStepService.getScanMonitorContext(resultBean.getOrganizeCode(), resultBean.getWorkCenterCode(), resultBean.getWorkCellCode());
|
||||
|
||||
if (checkRepeat(resultBean, scanMonitorContext)) return;
|
||||
|
||||
MesWorkCellScanMonitorLog workCellScanMonitorLog = new MesWorkCellScanMonitorLog();
|
||||
|
||||
if (null != scanMonitorContext) BeanUtils.copyProperties(scanMonitorContext, workCellScanMonitorLog);
|
||||
else log.info("工厂{}生产线{}工位{}: MesWorkCellScanMonitorLogExt2Service --- 上下文当前不存在工位扫描监控信息 --- {}", resultBean.getOrganizeCode(), resultBean.getWorkCenterCode(), resultBean.getWorkCellCode(), resultBean.toWriteDbString());
|
||||
|
||||
BeanUtils.copyProperties(resultBean, workCellScanMonitorLog);
|
||||
|
||||
workCellScanMonitorLog.setMessageType(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_MESSAGE_TYPE.codeOfValue(resultBean.getDataType()));
|
||||
|
||||
workCellScanMonitorLog.setOrgWorkCode(new StringJoiner(MesPcnExtConstWords.E_UNDERLINE).add(workCellScanMonitorLog.getOrganizeCode()).add(workCellScanMonitorLog.getWorkCenterCode()).toString());
|
||||
|
||||
ConvertBean.serviceModelInitialize(workCellScanMonitorLog, resultBean.getUserInfo());
|
||||
workCellScanMonitorLog.setCreateDatetime(resultBean.getCreateDatetime());
|
||||
|
||||
//存在开模ID的记录延迟同步
|
||||
if (!StringUtils.isEmpty(workCellScanMonitorLog.getMouldRecordId())) {
|
||||
workCellScanMonitorLog.setSystemSyncStatus(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
||||
workCellScanMonitorLog.setDealStatus(MesExtEnumUtil.MES_LOG_DEAL_STATUS.UNDEAL.getValue());
|
||||
} else {
|
||||
workCellScanMonitorLog.setSystemSyncStatus(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
|
||||
workCellScanMonitorLog.setDealStatus(MesExtEnumUtil.MES_LOG_DEAL_STATUS.DEAL_SUCCESS.getValue());
|
||||
}
|
||||
|
||||
workCellScanMonitorLogRepository.insert(workCellScanMonitorLog);
|
||||
|
||||
}
|
||||
|
||||
private Boolean checkRepeat(StationResultBean resultBean, MesScanMonitorContext scanMonitorContext) {
|
||||
|
||||
initCellMsg2RepeatMap(resultBean);
|
||||
|
||||
Long mouldRecordId = null != scanMonitorContext ? scanMonitorContext.getMouldRecordId() : null;
|
||||
String mouldRecordIdStr = !StringUtils.isEmpty(mouldRecordId) ? mouldRecordId.toString() : MesPcnExtConstWords.EMPTY;
|
||||
|
||||
if (!cellMsg2RepeatMap.get(resultBean.getClientInfo()).get(0).equals(mouldRecordIdStr)) {
|
||||
cellMsg2RepeatMap.get(resultBean.getClientInfo()).clear();
|
||||
cellMsg2RepeatMap.get(resultBean.getClientInfo()).add(0, mouldRecordIdStr);
|
||||
|
||||
//补偿数据
|
||||
DdlPackBean packBean = DdlPackBean.getDdlPackBean(resultBean.getOrganizeCode());
|
||||
DdlPreparedPack.getStringEqualPack(resultBean.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
|
||||
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.MES_LOG_DEAL_STATUS.UNDEAL.getValue(), MesPcnExtConstWords.DEAL_STATUS, packBean);
|
||||
if (!StringUtils.isEmpty(mouldRecordId)) DdlPreparedPack.getNumNOEqualPack(mouldRecordId, MesPcnExtConstWords.MOULD_RECORD_ID, packBean);
|
||||
int count = workCellScanMonitorLogRepository.updateByPropertiesNoSync(
|
||||
new String[]{MesPcnExtConstWords.SYSTEM_SYNC_STATUS, MesPcnExtConstWords.DEAL_STATUS},
|
||||
new Object[]{CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), MesExtEnumUtil.MES_LOG_DEAL_STATUS.DEAL_SUCCESS.getValue()},
|
||||
packBean);
|
||||
|
||||
log.info("工厂{}生产线{}工位{}: MesWorkCellScanMonitorLogExt2Service --- 补偿同步条数:{} ---", resultBean.getOrganizeCode(), resultBean.getWorkCenterCode(), resultBean.getWorkCellCode(), count);
|
||||
|
||||
}
|
||||
|
||||
if (resultBean.getIsCheckRepeat().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0) return false;
|
||||
|
||||
synchronized ((resultBean.getClientInfo() + this.getClass().getSimpleName()).intern()) {
|
||||
|
||||
if (cellMsg2RepeatMap.get(resultBean.getClientInfo()).contains(resultBean.getMessage())) return true;
|
||||
|
||||
cellMsg2RepeatMap.get(resultBean.getClientInfo()).add(resultBean.getMessage());
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initCellMsg2RepeatMap(StationResultBean resultBean) {
|
||||
|
||||
cellMsg2RepeatMap.computeIfAbsent(resultBean.getClientInfo(), o -> {
|
||||
|
||||
List<String> list = new CopyOnWriteArrayList<>();
|
||||
|
||||
list.add(0, MesPcnExtConstWords.EMPTY);
|
||||
|
||||
return list;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRestoreDbLog(StationResultBean resultBean) {
|
||||
|
||||
if (StringUtils.isEmpty(resultBean.getScanInfo()) || CollectionUtils.isEmpty(resultBean.getResultList())) return;
|
||||
|
||||
List<MesProductionPsOutContext> productionPsOutContextList = resultBean.getResultList();
|
||||
|
||||
String workOrderNo = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getWorkOrderNo()))).map(MesProductionPsOutContext::getWorkOrderNo).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
|
||||
String serialNumber = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getSerialNumber()))).map(MesProductionPsOutContext::getSerialNumber).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
|
||||
String productSn = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getProductSn()))).map(MesProductionPsOutContext::getProductSn).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
|
||||
String custSn = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getCustSn()))).map(MesProductionPsOutContext::getCustSn).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
|
||||
String partNo = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPartNo()))).map(MesProductionPsOutContext::getPartNo).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
|
||||
String partName = productionPsOutContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPartName()))).map(MesProductionPsOutContext::getPartName).collect(Collectors.joining(MesPcnExtConstWords.SEMICOLON));
|
||||
|
||||
DdlPackBean packBean = DdlPackBean.getDdlPackBean(resultBean.getOrganizeCode());
|
||||
DdlPreparedPack.getStringEqualPack(resultBean.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
|
||||
DdlPreparedPack.getNumEqualPack(Long.valueOf(resultBean.getScanInfo()), MesPcnExtConstWords.MOULD_RECORD_ID, packBean);
|
||||
|
||||
workCellScanMonitorLogRepository.updateByProperties(
|
||||
new String[]{MesPcnExtConstWords.WORK_ORDER_NO, MesPcnExtConstWords.SERIAL_NUMBER, MesPcnExtConstWords.PRODUCT_SN, MesPcnExtConstWords.CUST_SN,
|
||||
MesPcnExtConstWords.PART_NO, MesPcnExtConstWords.PART_NAME, MesPcnExtConstWords.MODIFY_DATE_TIME, MesPcnExtConstWords.MODIFY_USER, MesPcnExtConstWords.DEAL_STATUS},
|
||||
new Object[]{workOrderNo, serialNumber, productSn, custSn,
|
||||
partNo, partName, TimeTool.getNowTime(true), resultBean.getUserInfo(), MesExtEnumUtil.MES_LOG_DEAL_STATUS.DEAL_SUCCESS.getValue()},
|
||||
packBean);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,408 +0,0 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.*;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.DeepCloneUtil;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.*;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.mes.pcn.actor.shipping.dispatch.IFsmCommonService;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.IStepService;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
||||
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.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description : 生成零件号工步 【非排序】
|
||||
* @Author : wangjie
|
||||
**/
|
||||
@Slf4j
|
||||
@Service("mesAssemblyGeneratePartNoStepService2")
|
||||
public class MesAssemblyGeneratePartNoStepService2 extends BaseStepService {
|
||||
|
||||
@Autowired
|
||||
private IFsmCommonService fsmCommonService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionCustomContextStepService productionCustomContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesNumberRuleMatchDispatchService numberRuleMatchDispatchService;
|
||||
|
||||
@Autowired
|
||||
private MesAssemblyShowNosortStepService assemblyShowNosortStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesAssemblyExtService assemblyExtService;
|
||||
|
||||
@Autowired
|
||||
private IMesProdRuleCfgExtService prodRuleCfgExtService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionRecordService productionRecordService;
|
||||
|
||||
@Autowired
|
||||
private IMesTimeEfficientCfgMatchService timeEfficientCfgMatchService;
|
||||
|
||||
@Override
|
||||
public StepResult execute(StationRequestBean reqBean) {
|
||||
|
||||
StationResultBean resultBean = new StationResultBean();
|
||||
|
||||
StepResult stepResult = StepResult.getSuccessComplete();
|
||||
|
||||
//获取上下文信息
|
||||
MesProductionProcessContext productionProcessContext = productionProcessContextStepService.dispatchCurCellEquipment(reqBean);
|
||||
|
||||
//配置错误 抛出异常
|
||||
if (!productionProcessContext.getSuccess()) stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
|
||||
//存储生产过程上下文对象
|
||||
productionProcessContextStepService.dispatchProductionProcessContext(reqBean, productionProcessContext);
|
||||
|
||||
if (productionDispatchContextStepService.checkProductionPartIsExistContext(reqBean)) stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "当前存在产出零件数据,不支持执行当前工步,请检查工序模版并重置工序!");
|
||||
|
||||
//获取进料主条码数据信息
|
||||
List<MesProductionPsInContext> productionPsInContextList = productionDispatchContextStepService.getProductionPsInContext(reqBean);
|
||||
//剔除空腔主条码
|
||||
List<MesProductionPsInContext> productionPsInContextListNoFinishCode = CollectionUtils.isEmpty(productionPsInContextList) ? null :
|
||||
productionPsInContextList.stream().filter(o -> (null != o && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList());
|
||||
//当前未匹配的主条码
|
||||
List<MesProductionPsInContext> curProductionPsInContextList = CollectionUtils.isEmpty(productionPsInContextList) ? null :
|
||||
productionPsInContextList.stream().filter(o -> (null != o && StringUtils.isEmpty(o.getForeignKey()) && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList());
|
||||
|
||||
//获取上下文产品加工规则数据信息集合
|
||||
List<MesProdRuleContext> prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
||||
|
||||
if (!CollectionUtils.isEmpty(productionPsInContextListNoFinishCode) && !CollectionUtils.isEmpty(prodRuleContextList) &&
|
||||
productionPsInContextListNoFinishCode.size() == prodRuleContextList.size()) stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "当前已存在非排序产品加工规则数据,不支持执行当前工步,请检查工序模版并重置工序!");
|
||||
|
||||
//获取上下文生产扫/读信息:装配件条码
|
||||
List<MesEquipVariableCollectContext> equipVariableCollectContextList = productionDispatchContextStepService.getScanAssemblySnContext(reqBean);
|
||||
|
||||
//删除上下文扫/读信息:装配件条码
|
||||
if (!CollectionUtils.isEmpty(equipVariableCollectContextList)) productionDispatchContextStepService.removeScanAssemblySnContext(reqBean);
|
||||
|
||||
//从上下文中取出工位当前要使用的设备
|
||||
MesCellEquipContext cellEquipContext = productionProcessContext.getCurCellEquip();
|
||||
|
||||
//当前主条码是空腔码
|
||||
if (!CollectionUtils.isEmpty(productionPsInContextList) && CollectionUtils.isEmpty(curProductionPsInContextList)) {
|
||||
//主条码数量是否满足腔数
|
||||
Boolean isEnoughQty = productionPsInContextList.size() == cellEquipContext.getCavity();
|
||||
//主条码数量满足腔数,调用生成零件条码工步
|
||||
if (isEnoughQty) ((IStepService) SpringContextsUtil.getBean("mesProductSnGenerateStepService")).executeInState(reqBean);
|
||||
|
||||
return stepDynamicsCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult,
|
||||
isEnoughQty ? true : stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_PRODUCT_SN).isCompleted(),
|
||||
MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT,
|
||||
String.format("当前主条码为空腔码,无需匹配!当前扫描的主条码数量[%s]%s设备腔数[%s]!", productionPsInContextList.size(), isEnoughQty ? "已满足" : "未满足", cellEquipContext.getCavity()));
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(equipVariableCollectContextList)) return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY), "当前不存在装配件条码!");
|
||||
|
||||
//搜集装配件条码
|
||||
String assemblySn = equipVariableCollectContextList.stream().filter(o -> null != o).map(MesEquipVariableCollectContext::getEquipVariableValue).collect(Collectors.toList()).toString();
|
||||
|
||||
//未知腔数配置【工位参数】, 不验证装配件条码的个数
|
||||
String cavityUnknownCfg = getCavityUnknownCfg(reqBean);
|
||||
|
||||
//非未知腔数,验证装配件条码个数是否匹配 腔数或者未匹配的主条码个数*每腔个数
|
||||
if (StringUtils.isEmpty(cavityUnknownCfg) && equipVariableCollectContextList.size() != (!CollectionUtils.isEmpty(curProductionPsInContextList) ? curProductionPsInContextList.size() : cellEquipContext.getCavity()) * cellEquipContext.getBindQty()) {
|
||||
if (!CollectionUtils.isEmpty(curProductionPsInContextList)) {
|
||||
productionDispatchContextStepService.dispatchProductionPsInContext(reqBean, productionPsInContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).collect(Collectors.toList()));
|
||||
return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_PRODUCT_SN),
|
||||
String.format("当前装配件条码个数[%s]不满足主条码个数[%s]每腔个数[%s]配置!", equipVariableCollectContextList.size(), curProductionPsInContextList.size(), cellEquipContext.getBindQty()));
|
||||
} else {
|
||||
return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY),
|
||||
String.format("当前装配件条码个数[%s]不满足腔数[%s]每腔个数[%s]配置!", equipVariableCollectContextList.size(), cellEquipContext.getCavity(), cellEquipContext.getBindQty()));
|
||||
}
|
||||
}
|
||||
|
||||
//获取设备下所有的装配件规则清单, 根据非排序加工规则ID分组
|
||||
Map<Long, List<MesProductionAssemblyNosortContext>> assemblyNosortCfgMap = doHandleAssemblyNosortCfg(reqBean, resultBean, stepResult, cellEquipContext);
|
||||
|
||||
//生成零件号业务处理
|
||||
prodRuleContextList = doHandleAssemblyGeneratePartNo(reqBean, resultBean, stepResult, cellEquipContext, cavityUnknownCfg, productionProcessContext, productionPsInContextList, prodRuleContextList, assemblyNosortCfgMap, equipVariableCollectContextList);
|
||||
|
||||
String suffix = !CollectionUtils.isEmpty(curProductionPsInContextList) ? String.format("当前主条码%s", curProductionPsInContextList.stream().filter(o -> null != o).map(MesProductionPsInContext::getProductSn).collect(Collectors.toList()).toString()) : MesPcnExtConstWords.EMPTY;
|
||||
|
||||
//判断是否存在未消费的装配件条码
|
||||
Optional<MesEquipVariableCollectContext> optional = equipVariableCollectContextList.stream().filter(o -> (null != o && o.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).findFirst();
|
||||
if (null != optional && optional.isPresent()) {
|
||||
|
||||
stepResult.msg(String.format("%s装配件条码%s匹配失败!%s", suffix, assemblySn, StringUtils.isEmpty(stepResult.getMsg()) ? MesPcnExtConstWords.EMPTY : stepResult.getMsg()));
|
||||
|
||||
this.sendMessage(reqBean, new StationResultBean().writeDbLog().scanInfo(assemblySn),
|
||||
String.format("%s%s", stepResult.getMsg(), StringUtils.isEmpty(stepResult.getObj()) ? MesPcnExtConstWords.EMPTY : stepResult.getObj()), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
|
||||
|
||||
if (!CollectionUtils.isEmpty(curProductionPsInContextList)) productionDispatchContextStepService.dispatchProductionPsInContext(reqBean, productionPsInContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).collect(Collectors.toList()));
|
||||
|
||||
return stepNonCompleteAndSendMsgReturn(reqBean, resultBean, stepResult.nextTriggerEvent(!CollectionUtils.isEmpty(curProductionPsInContextList) ? MesPcnExtConstWords.NEXT_TRIGGER_EVENT_PRODUCT_SN : MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY), stepResult.getMsg());
|
||||
}
|
||||
|
||||
//保存上下文产品加工规则信息集合
|
||||
productionDispatchContextStepService.dispatchProdRuleDataContext(reqBean, prodRuleContextList);
|
||||
|
||||
//保存进料主条码数据
|
||||
if (!CollectionUtils.isEmpty(productionPsInContextList)) productionDispatchContextStepService.dispatchProductionPsInContext(reqBean, productionPsInContextList);
|
||||
|
||||
//显示装配件信息
|
||||
assemblyShowNosortStepService.showProductionAssembly(reqBean, resultBean, productionProcessContext.getWorkCenter(), cellEquipContext, prodRuleContextList);
|
||||
|
||||
//验证主条码是否全部匹配完毕
|
||||
if (!CollectionUtils.isEmpty(productionPsInContextList)) {
|
||||
//主条码数量是否满足腔数
|
||||
Boolean isEnoughQty = productionPsInContextList.size() == cellEquipContext.getCavity();
|
||||
//主条码数量满足腔数,调用生成零件条码工步
|
||||
if (isEnoughQty) ((IStepService) SpringContextsUtil.getBean("mesProductSnGenerateStepService")).executeInState(reqBean);
|
||||
|
||||
return stepDynamicsCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn), stepResult,
|
||||
isEnoughQty ? true : stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_PRODUCT_SN).isCompleted(),
|
||||
MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT,
|
||||
String.format("%s装配件条码%s匹配成功!当前扫描的主条码数量[%s]%s设备腔数[%s]!", suffix, assemblySn, productionPsInContextList.size(), isEnoughQty ? "已满足" : "未满足", cellEquipContext.getCavity()));
|
||||
}
|
||||
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().scanInfo(assemblySn), stepResult, String.format("装配件条码%s匹配成功!", assemblySn));
|
||||
|
||||
}
|
||||
|
||||
//未知腔数配置【工位参数】
|
||||
private String getCavityUnknownCfg(StationRequestBean reqBean) {
|
||||
String cavityUnknownCfg = fsmCommonService.handleFsmWcpcMapDataForDoScan(reqBean).get(MesPcnExtConstWords.CAVITY_UNKNOWN_CFG);
|
||||
return (!StringUtils.isEmpty(cavityUnknownCfg) && cavityUnknownCfg.equals(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr())) ? cavityUnknownCfg : null;
|
||||
}
|
||||
|
||||
//获取设备下所有的装配件规则清单, 根据非排序加工规则ID分组
|
||||
private Map<Long, List<MesProductionAssemblyNosortContext>> doHandleAssemblyNosortCfg(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesCellEquipContext cellEquipContext) {
|
||||
|
||||
//查询工位设备装配件规则信息
|
||||
List<MesProductionAssemblyNosortContext> assemblyNosortCfgList = productionProcessContextStepService.findAssemblyNosortCfgList(reqBean);
|
||||
|
||||
//获取设备的装配件规则清单
|
||||
if (CollectionUtils.isEmpty(assemblyNosortCfgList) || !assemblyNosortCfgList.get(0).getEquipmentCode().equals(cellEquipContext.getEquipmentCode())) {
|
||||
assemblyNosortCfgList = assemblyExtService.getProductionAssemblyNosortContextList(reqBean.getOrganizeCode(), cellEquipContext.getEquipmentCode());
|
||||
|
||||
if (CollectionUtils.isEmpty(assemblyNosortCfgList))
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(),
|
||||
String.format("生产线[%s]工位[%s]设备[%s]未维护含有装配件规则信息的非排序加工规则信息", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), cellEquipContext.getEquipmentName()));
|
||||
|
||||
//存储设备的装配件清单
|
||||
productionProcessContextStepService.dispatchAssemblyNosortCfgContext(reqBean, assemblyNosortCfgList);
|
||||
|
||||
}
|
||||
|
||||
//根据非排序加工规则ID分组
|
||||
return assemblyNosortCfgList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPid()))).collect(Collectors.groupingBy(MesProductionAssemblyNosortContext::getPid));
|
||||
|
||||
}
|
||||
|
||||
//生成零件号业务处理
|
||||
private List<MesProdRuleContext> doHandleAssemblyGeneratePartNo(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesCellEquipContext cellEquipContext, String cavityUnknownCfg,
|
||||
MesProductionProcessContext productionProcessContext, List<MesProductionPsInContext> productionPsInContextList, List<MesProdRuleContext> prodRuleContextList,
|
||||
Map<Long, List<MesProductionAssemblyNosortContext>> assemblyNosortCfgMap, List<MesEquipVariableCollectContext> equipVariableCollectContextList) {
|
||||
//无主条码则无加工规则, 有主条码可能无加工规则
|
||||
prodRuleContextList = CollectionUtils.isEmpty(prodRuleContextList) ? new ArrayList<>() : prodRuleContextList;
|
||||
//拿到当前最大的foreignKey
|
||||
Optional<MesProdRuleContext> maxForeignKeyOptional = CollectionUtils.isEmpty(prodRuleContextList) ? null : prodRuleContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).max(Comparator.comparing(MesProdRuleContext::getForeignKey));
|
||||
Integer foreignKey = (null != maxForeignKeyOptional && maxForeignKeyOptional.isPresent()) ? maxForeignKeyOptional.get().getForeignKey() : MesPcnExtConstWords.ZERO;
|
||||
|
||||
//遍历非排序加工规则ID
|
||||
for (Map.Entry<Long, List<MesProductionAssemblyNosortContext>> entry : assemblyNosortCfgMap.entrySet()) {
|
||||
|
||||
if (null == entry) continue;
|
||||
|
||||
//判断是否存在未消费的装配件条码
|
||||
List<MesEquipVariableCollectContext> unConsumeList = equipVariableCollectContextList.stream().filter(o -> (null != o && o.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(unConsumeList)) break;
|
||||
|
||||
//剔除不扫描/不显示且不扫描/仅目视的数据
|
||||
List<MesProductionAssemblyNosortContext> productionAssemblyNosortContextList = entry.getValue().stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getMatchType()) && MesExtEnumUtil.ASSEMBLY_MATCH_TYPE.checkIsNeedScan(o.getMatchType()))).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(productionAssemblyNosortContextList)) continue;
|
||||
|
||||
//没有未知腔数配置, 剔除装配件规则个数不等于每腔个数的数据
|
||||
if (StringUtils.isEmpty(cavityUnknownCfg) && cellEquipContext.getBindQty().compareTo(productionAssemblyNosortContextList.size()) != 0) continue;
|
||||
|
||||
//收集未消费的临时数据
|
||||
List<MesEquipVariableCollectContext> equipVariableCollectContextListTemp = DeepCloneUtil.deepCloneList(unConsumeList);
|
||||
if (CollectionUtils.isEmpty(equipVariableCollectContextListTemp)) break;
|
||||
|
||||
//遍历非排序加工规则ID对应的装配件规则清单
|
||||
for (MesProductionAssemblyNosortContext productionAssemblyNosortContext : productionAssemblyNosortContextList) {
|
||||
|
||||
if (null == productionAssemblyNosortContext) continue;
|
||||
|
||||
//非扫描模式 或者 扫描模式情况下非可复用件
|
||||
if (equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.SCAN.getValue()) != 0 ||
|
||||
StringUtils.isEmpty(productionAssemblyNosortContext.getIsRepeat()) || productionAssemblyNosortContext.getIsRepeat().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) != 0) {
|
||||
|
||||
for (MesEquipVariableCollectContext equipVariableCollectContext : equipVariableCollectContextListTemp) {
|
||||
|
||||
//已被消费
|
||||
if (null == equipVariableCollectContext || equipVariableCollectContext.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0) continue;
|
||||
|
||||
//匹配规则
|
||||
Map<String, Object> result = numberRuleMatchDispatchService.matchNumberRule(reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), productionAssemblyNosortContext);
|
||||
|
||||
//匹配失败
|
||||
if (!(Boolean) result.get(MesPcnExtConstWords.RESULT)) {
|
||||
String msg = (String) result.get(MesPcnExtConstWords.MESSAGE);
|
||||
stepResult.obj(String.format("%s%s", StringUtils.isEmpty(stepResult.getObj()) ? MesPcnExtConstWords.EMPTY : stepResult.getObj(), StringUtils.isEmpty(msg) ? MesPcnExtConstWords.EMPTY : msg));
|
||||
continue;
|
||||
}
|
||||
|
||||
MesProductionAssemblyNosortContext filter = (MesProductionAssemblyNosortContext) result.get(MesPcnExtConstWords.DATA);
|
||||
|
||||
//前道防错
|
||||
if (!StringUtils.isEmpty(filter.getProductSnId()) && !StringUtils.isEmpty(productionAssemblyNosortContext.getPreCraftCode())) {
|
||||
if (CollectionUtils.isEmpty(productionRecordService.findProductionRecordList(reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), productionAssemblyNosortContext.getPartNo(), productionAssemblyNosortContext.getPreCraftCode()))) {
|
||||
stepResult.msg(String.format("%s%s", StringUtils.isEmpty(stepResult.getMsg()) ? MesPcnExtConstWords.EMPTY : stepResult.getMsg(),
|
||||
String.format("零件条码[%s]前道防错零件号[%s]工艺[%s]验证失败,未查询到加工记录信息!", equipVariableCollectContext.getEquipVariableValue(), productionAssemblyNosortContext.getPartNo(), productionAssemblyNosortContext.getPreCraftCode())));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//时效性验证
|
||||
if (!StringUtils.isEmpty(filter.getProductSnId())) {
|
||||
result = timeEfficientCfgMatchService.checkSnTimeliness(reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), filter.getSourceId(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE30.getValue());
|
||||
if (!(Boolean)result.get(MesPcnExtConstWords.RESULT)) {
|
||||
stepResult.msg(String.format("%s%s", StringUtils.isEmpty(stepResult.getMsg()) ? MesPcnExtConstWords.EMPTY : stepResult.getMsg(), result.get(MesPcnExtConstWords.MESSAGE)));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//装配件清单该数据标记已装配
|
||||
productionAssemblyNosortContext.assemblyStatus(equipVariableCollectContext.getEquipVariableValue()).productSnId(filter.getProductSnId());
|
||||
|
||||
//临时数据标记已消费
|
||||
equipVariableCollectContext.isConsume();
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String getRepeatAssemblySn = getRepeatAssemblySn(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), productionAssemblyNosortContext);
|
||||
if (!StringUtils.isEmpty(getRepeatAssemblySn)) productionAssemblyNosortContext.assemblyStatus(getRepeatAssemblySn);
|
||||
|
||||
//判断当前装配件规则是否被成功匹配条码
|
||||
if (productionAssemblyNosortContext.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) == 0) break;
|
||||
|
||||
}
|
||||
|
||||
//判断当前装配件规则清单是否完全匹配剩余未消费的条码
|
||||
Optional<MesProductionAssemblyNosortContext> optionalRule = productionAssemblyNosortContextList.stream().filter(o -> (null != o && o.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) == 0)).findFirst();
|
||||
if (null != optionalRule && optionalRule.isPresent()) continue;
|
||||
|
||||
//验证加工规则是否有效
|
||||
MesProdRuleContext prodRuleContext = prodRuleCfgExtService.getProdRuleNosortContextByPid(new MesProdRuleContext(
|
||||
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), reqBean.getProcessCode(), productionProcessContext.getCraftCode()).pid(productionAssemblyNosortContextList.get(0).getPid()));
|
||||
|
||||
//根据PID获取非排序加工规则 数据无效
|
||||
if (null == prodRuleContext) continue;
|
||||
|
||||
Boolean productSnIsMatchFlag = false;
|
||||
String errMsg = MesPcnExtConstWords.EMPTY;
|
||||
if (!CollectionUtils.isEmpty(productionPsInContextList)) {
|
||||
|
||||
for (MesProductionPsInContext productionPsInContext : productionPsInContextList) {
|
||||
|
||||
if (null == productionPsInContext || !StringUtils.isEmpty(productionPsInContext.getForeignKey()) || productionPsInContext.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0) continue;
|
||||
|
||||
//验证主条码是否满足当前匹配成功的产品加工规则
|
||||
Map<String, Object> result = checkPsInIsMatchProdRule(reqBean.getOrganizeCode(), productionPsInContext, prodRuleContext);
|
||||
if (!(Boolean) result.get(MesPcnExtConstWords.RESULT)) {
|
||||
errMsg = (String) result.get(MesPcnExtConstWords.MESSAGE);
|
||||
continue;
|
||||
}
|
||||
|
||||
//时效性验证
|
||||
if (!StringUtils.isEmpty(productionPsInContext.getPartNo())) {
|
||||
result = timeEfficientCfgMatchService.checkSnTimeliness(reqBean.getOrganizeCode(), productionPsInContext.getProductSn(), prodRuleContext.getPid(), MesExtEnumUtil.TIME_DATA_SOURCE.DATA_SOURCE20.getValue());
|
||||
if (!(Boolean) result.get(MesPcnExtConstWords.RESULT)) {
|
||||
errMsg = (String) result.get(MesPcnExtConstWords.MESSAGE);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
productSnIsMatchFlag = true;
|
||||
errMsg = MesPcnExtConstWords.EMPTY;
|
||||
|
||||
//主条码赋值数据关联键
|
||||
productionPsInContext.foreignKey(foreignKey += 1);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!productSnIsMatchFlag && !CollectionUtils.isEmpty(productionPsInContextList)) {
|
||||
stepResult.msg(String.format("%s%s", StringUtils.isEmpty(stepResult.getMsg()) ? MesPcnExtConstWords.EMPTY : stepResult.getMsg(), errMsg));
|
||||
continue;
|
||||
}
|
||||
|
||||
//装配件条码标记被消费状态
|
||||
productionAssemblyNosortContextList.forEach(o -> {
|
||||
Optional<MesEquipVariableCollectContext> evccOp = equipVariableCollectContextList.stream().filter(v -> (null != v && v.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0 && v.getEquipVariableValue().equals(o.getAssemblySn()))).findFirst();
|
||||
if (null != evccOp && evccOp.isPresent()) evccOp.get().isConsume();
|
||||
});
|
||||
|
||||
//加工规则赋值装配件数据
|
||||
prodRuleContext.assemblyDataJson(productionAssemblyNosortContextList).foreignKey(!productSnIsMatchFlag ? foreignKey += 1 : foreignKey);
|
||||
|
||||
prodRuleContextList.add(prodRuleContext);
|
||||
|
||||
}
|
||||
|
||||
return prodRuleContextList;
|
||||
|
||||
}
|
||||
|
||||
private Map<String, Object> checkPsInIsMatchProdRule(String organizeCode, MesProductionPsInContext productionPsInContext, MesProdRuleContext prodRuleContext) {
|
||||
//根据进料零件条码匹配进料零件规则
|
||||
if (StringUtils.isEmpty(productionPsInContext.getPartNo())) return numberRuleMatchDispatchService.matchNumberRule(organizeCode, productionPsInContext.getProductSn(), prodRuleContext);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(MesPcnExtConstWords.RESULT, true);
|
||||
//根据进料零件号匹配产品加工规则
|
||||
if (!StringUtils.isEmpty(productionPsInContext.getPartNo()) && (StringUtils.isEmpty(prodRuleContext.getInPartNo()) || !prodRuleContext.getInPartNo().equals(productionPsInContext.getPartNo()))) {
|
||||
result.put(MesPcnExtConstWords.RESULT, false);
|
||||
if (StringUtils.isEmpty(prodRuleContext.getInPartNo()))
|
||||
result.put(MesPcnExtConstWords.MESSAGE, String.format("条码[%s]零件号[%s]匹配的加工规则ID[%s]信息未维护进料零件号!", productionPsInContext.getProductSn(), productionPsInContext.getPartNo(), prodRuleContext.getPid()));
|
||||
else result.put(MesPcnExtConstWords.MESSAGE, String.format("条码[%s]零件号[%s]不匹配加工规则维护的进料零件号[%s]!", productionPsInContext.getProductSn(), productionPsInContext.getPartNo(), prodRuleContext.getInPartNo()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//验证装配件规则对应的ID是否存在可复用装配件条码
|
||||
private String getRepeatAssemblySn(String organizeCode, String workCenterCode, String workCellCode, MesProductionAssemblyNosortContext productionAssemblyNosortContext) {
|
||||
|
||||
if (productionAssemblyNosortContext.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) != 0) return null;
|
||||
|
||||
if (null == productionAssemblyNosortContext || StringUtils.isEmpty(productionAssemblyNosortContext.getIsRepeat()) || productionAssemblyNosortContext.getIsRepeat().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) != 0) return null;
|
||||
|
||||
return productionCustomContextStepService.getRepeatAssemblySn(organizeCode, workCenterCode, workCellCode, productionAssemblyNosortContext.getSourceId().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,267 +0,0 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionCustomContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.*;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description : 扫描装配件条码工步
|
||||
* @Author : wangjie
|
||||
**/
|
||||
@Slf4j
|
||||
@Service("mesAssemblyScanStepService2")
|
||||
public class MesAssemblyScanStepService2 extends BaseStepService {
|
||||
|
||||
@Autowired
|
||||
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionCustomContextStepService productionCustomContextStepService;
|
||||
|
||||
@Override
|
||||
public StepResult guide(StationRequestBean reqBean) {
|
||||
|
||||
productionCustomContextStepService.sendStepContextMessage(reqBean);
|
||||
|
||||
return stepSuccessCompleteAndSendGuideReturn(reqBean, new StationResultBean().writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), "请扫描装配件条码!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StepResult execute(StationRequestBean reqBean) {
|
||||
|
||||
StationResultBean resultBean = new StationResultBean();
|
||||
|
||||
StepResult stepResult = StepResult.getSuccessComplete();
|
||||
|
||||
//扫描信息置空
|
||||
String scanInfo = reqBean.resetScanInfo(reqBean.getScanInfo());
|
||||
|
||||
//获取上下文信息
|
||||
MesProductionProcessContext productionProcessContext = productionProcessContextStepService.dispatchCurCellEquipment(reqBean);
|
||||
|
||||
//配置错误 抛出异常
|
||||
if (!productionProcessContext.getSuccess()) stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
|
||||
//存储生产过程上下文对象
|
||||
productionProcessContextStepService.dispatchProductionProcessContext(reqBean, productionProcessContext);
|
||||
|
||||
//获取进料主条码数据信息
|
||||
List<MesProductionPsInContext> productionPsInContextList = productionDispatchContextStepService.getProductionPsInContext(reqBean);
|
||||
//剔除空腔主条码
|
||||
List<MesProductionPsInContext> productionPsInContextListNoFinishCode = CollectionUtils.isEmpty(productionPsInContextList) ? null :
|
||||
productionPsInContextList.stream().filter(o -> (null != o && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList());
|
||||
//当前未匹配的主条码
|
||||
List<MesProductionPsInContext> curProductionPsInContextList = CollectionUtils.isEmpty(productionPsInContextList) ? null :
|
||||
productionPsInContextList.stream().filter(o -> (null != o && StringUtils.isEmpty(o.getForeignKey()) && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList());
|
||||
|
||||
//获取上下文产品加工规则数据信息集合
|
||||
List<MesProdRuleContext> prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
||||
|
||||
//判断业务场景: 1=唯一加工规则场景; 2=无进无出扫装配件生成零件号场景; 3=有进未匹配加工规则扫装配件生成零件号场景
|
||||
Integer busiType = getBusiType(productionPsInContextListNoFinishCode, prodRuleContextList);
|
||||
|
||||
//验证场景1 当前是否需要扫描装配件条码: 是否存在装配件清单 【当前验证只能对内部触发生效】
|
||||
if (busiType == 1 && !CollectionUtils.isEmpty(prodRuleContextList) && !checkIsNeedScanAssembly(prodRuleContextList))
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "当前加工规则未配置装配件扫描项,当前无需扫描装配件条码!");
|
||||
|
||||
//场景1 处理装配件的装配爆炸图和音频文件
|
||||
if (busiType == 1) doHandleAssemblyFile(reqBean, productionProcessContext.getWorkCenter(), prodRuleContextList);
|
||||
|
||||
//验证场景1 当前是否需要扫描装配件条码: 验证是否存在待绑定数据 【当前验证只能对内部触发生效】
|
||||
if (busiType == 1 && !CollectionUtils.isEmpty(prodRuleContextList) && !hasUnBindAssembly(prodRuleContextList))
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "当前加工规则对应的装配件清单已扫描完毕,当前无需扫描装配件条码!");
|
||||
|
||||
//验证场景3的当前未匹配的主条码是否是空腔码
|
||||
if (busiType == 3 && CollectionUtils.isEmpty(curProductionPsInContextList))
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "当前主条码对应的装配件清单已扫描完毕,当前无需扫描装配件条码!");
|
||||
|
||||
if (StringUtils.isEmpty(scanInfo)) stepSendGuideAndThrowEx(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), "请扫描装配件条码!");
|
||||
|
||||
//发送工步内容
|
||||
productionCustomContextStepService.sendStepContextMessage(reqBean, scanInfo, MesExtEnumUtil.CELL_MESSAGE_SOURCE.SCAN);
|
||||
|
||||
//封装当前扫描的装配件信息
|
||||
List<MesEquipVariableCollectContext> equipVariableCollectContextList = getAssemblySnJson(reqBean, scanInfo);
|
||||
|
||||
//从上下文中取出工位当前要使用的设备
|
||||
MesCellEquipContext cellEquipContext = productionProcessContext.getCurCellEquip();
|
||||
|
||||
//需要扫描的绑定数量
|
||||
Integer needQty = getNeedQty(busiType, cellEquipContext, curProductionPsInContextList);
|
||||
|
||||
//非场景1的情况下代表需要反向匹配出加工规则, 需要根据设备腔数直接批量扫描 生成零件号
|
||||
if (busiType != 1) {
|
||||
|
||||
//根据设备代码获取可复用条码的个数
|
||||
Integer repeatAssemblySnCount = productionCustomContextStepService.getRepeatAssemblySnCount(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), cellEquipContext.getEquipmentCode());
|
||||
|
||||
//获取上下文生产扫/读信息:装配件条码
|
||||
List<MesEquipVariableCollectContext> cachedEquipVariableCollectContextList = productionDispatchContextStepService.getScanAssemblySnContext(reqBean);
|
||||
//删除上下文扫/读信息:装配件条码
|
||||
productionDispatchContextStepService.removeScanAssemblySnContext(reqBean);
|
||||
|
||||
//当前已扫描的装配件条码数量 + 可复用数量 * 当前未匹配的主条码数量
|
||||
Integer scanedQty = (!CollectionUtils.isEmpty(cachedEquipVariableCollectContextList) ? cachedEquipVariableCollectContextList.size() : MesPcnExtConstWords.ZERO) + repeatAssemblySnCount * (!CollectionUtils.isEmpty(curProductionPsInContextList) ? curProductionPsInContextList.size() : 1);
|
||||
|
||||
//判断当前已存在数量是否超过需要数量
|
||||
String suffix = !CollectionUtils.isEmpty(curProductionPsInContextList) ? String.format("主条码数量[%s]", curProductionPsInContextList.size()) : MesPcnExtConstWords.EMPTY;
|
||||
if (scanedQty > needQty) stepSendGuideAndThrowEx(reqBean, resultBean.writeDbLog(), String.format(
|
||||
"%s设备可复用条码数量[%s]设备腔数[%s]每腔个数[%s]此前已扫描的装配件条码数量[%s],当前计算数量[%s]已超过扫描需求总数量[%s],请重新扫描装配件条码!",
|
||||
suffix, repeatAssemblySnCount, cellEquipContext.getCavity(), cellEquipContext.getBindQty(), cachedEquipVariableCollectContextList.size(), scanedQty, needQty));
|
||||
|
||||
if (!CollectionUtils.isEmpty(cachedEquipVariableCollectContextList)) {
|
||||
if (scanedQty == needQty) equipVariableCollectContextList = cachedEquipVariableCollectContextList;
|
||||
else equipVariableCollectContextList.addAll(cachedEquipVariableCollectContextList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//保存上下文扫/读信息:装配件条码
|
||||
productionDispatchContextStepService.dispatchScanAssemblySnContext(reqBean, equipVariableCollectContextList);
|
||||
|
||||
//唯一加工规则场景 默认扫描一次 匹配一次 循环处理直到当前的加工规则全部匹配完毕
|
||||
if (busiType == 1) return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.SCAN.getValue()).scanInfo(scanInfo), stepResult, String.format("当前扫描信息装配件条码[%s]!", scanInfo));
|
||||
|
||||
if (equipVariableCollectContextList.size() == needQty) return stepSuccessCompleteAndSendMsgReturn(
|
||||
reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.SCAN.getValue()).scanInfo(scanInfo), stepResult, String.format("当前扫描信息装配件条码[%s],已扫描个数[%s]!", scanInfo, equipVariableCollectContextList.size() + "/" + needQty));
|
||||
|
||||
return stepDynamicsCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.SCAN.getValue()).scanInfo(scanInfo), stepResult, false,
|
||||
MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT, String.format("当前扫描信息装配件条码[%s],请继续扫描装配件条码,已扫描个数[%s]!", scanInfo, equipVariableCollectContextList.size() + "/" + needQty));
|
||||
|
||||
}
|
||||
|
||||
//判断业务场景: 1=唯一加工规则场景; 2=无进无出扫装配件生成零件号场景; 3=有进未匹配加工规则扫装配件生成零件号场景
|
||||
private Integer getBusiType(List<MesProductionPsInContext> productionPsInContextListNoFinishCode, List<MesProdRuleContext> prodRuleContextList) {
|
||||
if (CollectionUtils.isEmpty(productionPsInContextListNoFinishCode) && CollectionUtils.isEmpty(prodRuleContextList)) return 2;
|
||||
if (!CollectionUtils.isEmpty(productionPsInContextListNoFinishCode) && (CollectionUtils.isEmpty(prodRuleContextList) || productionPsInContextListNoFinishCode.size() != prodRuleContextList.size())) return 3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//需要扫描的绑定数量
|
||||
private Integer getNeedQty(Integer busiType, MesCellEquipContext cellEquipContext, List<MesProductionPsInContext> curProductionPsInContextList) {
|
||||
if (busiType == 1) return 1;
|
||||
if (busiType == 2) return cellEquipContext.getCavity() * cellEquipContext.getBindQty();
|
||||
return curProductionPsInContextList.size() * cellEquipContext.getBindQty();
|
||||
}
|
||||
|
||||
//处理装配件的装配爆炸图和音频文件
|
||||
private void doHandleAssemblyFile(StationRequestBean reqBean, MesWorkCenter workCenter, List<MesProdRuleContext> prodRuleContextList) {
|
||||
|
||||
if (CollectionUtils.isEmpty(prodRuleContextList)) return;
|
||||
|
||||
Boolean isSendFile = false;
|
||||
Boolean isBreakLoop = false;
|
||||
LOOP:
|
||||
for (MesProdRuleContext prodRuleContext : prodRuleContextList) {
|
||||
if (null == prodRuleContext || StringUtils.isEmpty(prodRuleContext.getAssemblyDataJson())) continue;
|
||||
if (MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue() == workCenter.getCenterType()) {
|
||||
List<MesProductionAssemblyNosortContext> productionAssemblyNosortContextList = prodRuleContext.getNosortAssemblyDataContext();
|
||||
for (MesProductionAssemblyNosortContext productionAssemblyNosortContext : productionAssemblyNosortContextList) {
|
||||
if (null == productionAssemblyNosortContext ||
|
||||
productionAssemblyNosortContext.getFileIsFinished().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0 ||
|
||||
MesExtEnumUtil.ASSEMBLY_MATCH_TYPE.checkIsNoShow(productionAssemblyNosortContext.getMatchType()) ||
|
||||
(StringUtils.isEmpty(productionAssemblyNosortContext.getImageFileUrl()) && StringUtils.isEmpty(productionAssemblyNosortContext.getAudioFileUrl()))) continue;
|
||||
//不扫描的默认直接被标记绿色已装配, 但是文件也需要发送
|
||||
if (productionAssemblyNosortContext.getMatchType().compareTo(MesExtEnumUtil.ASSEMBLY_MATCH_TYPE.MATCH_TYPE_50.getValue()) != 0) isBreakLoop = true;
|
||||
isSendFile = true;
|
||||
//发送文件到客户端
|
||||
sendFile(reqBean, productionAssemblyNosortContext.fileIsFinished());
|
||||
if (isBreakLoop) break LOOP;
|
||||
}
|
||||
prodRuleContext.assemblyDataJson(productionAssemblyNosortContextList);
|
||||
} else {
|
||||
List<MesProductionAssemblySortContext> productionAssemblySortContextList = prodRuleContext.getSortAssemblyDataContext();
|
||||
for (MesProductionAssemblySortContext productionAssemblySortContext : productionAssemblySortContextList) {
|
||||
if (null == productionAssemblySortContext ||
|
||||
productionAssemblySortContext.getFileIsFinished().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0 ||
|
||||
MesExtEnumUtil.ASSEMBLY_MATCH_TYPE.checkIsNoShow(productionAssemblySortContext.getMatchType()) ||
|
||||
(StringUtils.isEmpty(productionAssemblySortContext.getImageFileUrl()) && StringUtils.isEmpty(productionAssemblySortContext.getAudioFileUrl()))) continue;
|
||||
//不扫描的默认直接被标记绿色已装配, 但是文件也需要发送
|
||||
if (productionAssemblySortContext.getMatchType().compareTo(MesExtEnumUtil.ASSEMBLY_MATCH_TYPE.MATCH_TYPE_50.getValue()) != 0) isBreakLoop = true;
|
||||
isSendFile = true;
|
||||
//发送文件到客户端
|
||||
sendFile(reqBean, productionAssemblySortContext.fileIsFinished());
|
||||
if (isBreakLoop) break LOOP;
|
||||
}
|
||||
prodRuleContext.assemblyDataJson(productionAssemblySortContextList);
|
||||
}
|
||||
}
|
||||
//保存上下文产品加工规则信息集合
|
||||
if (isSendFile) productionDispatchContextStepService.dispatchProdRuleDataContext(reqBean, prodRuleContextList);
|
||||
}
|
||||
|
||||
//发送文件到客户端
|
||||
private void sendFile(StationRequestBean reqBean, MesProductionAssemblyContext productionAssemblyContext) {
|
||||
if (!StringUtils.isEmpty(productionAssemblyContext.getImageFileUrl()))
|
||||
this.sendMessage(reqBean, new StationResultBean().writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue())
|
||||
.busiType(MesPcnEnumUtil.STATION_BUSI_TYPE.MODULE_CUSTOM_CONTENT.getValue())
|
||||
.dataType(MesPcnEnumUtil.STATION_DATA_TYPE.IMAGE.getValue())
|
||||
.customPageName(MesPcnExtConstWords.CUSTOM_PAGE_NAME_ASSEMBLY)
|
||||
.message(String.format("装配件信息来源ID[%s],装配件爆炸图URL[%s]", productionAssemblyContext.getSourceId(), productionAssemblyContext.getImageFileUrl()))
|
||||
.resultObj(new JSONObject().put(MesPcnExtConstWords.URL, productionAssemblyContext.getImageFileUrl())));
|
||||
if (!StringUtils.isEmpty(productionAssemblyContext.getAudioFileUrl()))
|
||||
this.sendMessage(reqBean, new StationResultBean().writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue())
|
||||
.busiType(MesPcnEnumUtil.STATION_BUSI_TYPE.CUSTOM_COMPONENT.getValue())
|
||||
.dataType(MesPcnEnumUtil.STATION_DATA_TYPE.SOUND.getValue())
|
||||
.message(String.format("装配件信息来源ID[%s],装配件音频文件URL[%s]", productionAssemblyContext.getSourceId(), productionAssemblyContext.getAudioFileUrl()))
|
||||
.resultObj(new JSONObject().put(MesPcnExtConstWords.URL, productionAssemblyContext.getAudioFileUrl())));
|
||||
}
|
||||
|
||||
//判断是否存在装配件清单
|
||||
private Boolean checkIsNeedScanAssembly(List<MesProdRuleContext> prodRuleContextList) {
|
||||
Optional<MesProdRuleContext> optional = prodRuleContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getAssemblyDataJson()))).findFirst();
|
||||
return (null == optional || !optional.isPresent()) ? false : true;
|
||||
}
|
||||
|
||||
//验证是否存在待绑定数据
|
||||
private Boolean hasUnBindAssembly(List<MesProdRuleContext> prodRuleContextList) {
|
||||
Boolean hasUnBindAssembly = false;
|
||||
for (MesProdRuleContext prodRuleContext : prodRuleContextList) {
|
||||
if (null == prodRuleContext || StringUtils.isEmpty(prodRuleContext.getAssemblyDataJson())) continue;
|
||||
List<MesProductionAssemblyNosortContext> productionAssemblyNosortContextList = prodRuleContext.getNosortAssemblyDataContext();
|
||||
Optional<MesProductionAssemblyNosortContext> optional = productionAssemblyNosortContextList.stream().filter(o -> (null != o && o.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) == 0)).findFirst();
|
||||
if (null == optional || !optional.isPresent()) continue;
|
||||
|
||||
hasUnBindAssembly = true;
|
||||
break;
|
||||
}
|
||||
return hasUnBindAssembly;
|
||||
}
|
||||
|
||||
//封装当前扫描的装配件信息
|
||||
private List<MesEquipVariableCollectContext> getAssemblySnJson(StationRequestBean reqBean, String scanInfo) {
|
||||
|
||||
List<MesEquipVariableCollectContext> equipVariableCollectContextList = new ArrayList<>();
|
||||
|
||||
equipVariableCollectContextList.add(new MesEquipVariableCollectContext(reqBean.getOrganizeCode(), scanInfo, MesExtEnumUtil.CELL_MESSAGE_SOURCE.SCAN.getValue()));
|
||||
|
||||
return equipVariableCollectContextList;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue