EenLotContextValueManagerImpl.java
package com.mycim.server.ctx.exec.manager.impl;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
import com.mycim.framework.utils.lang.math.NumberUtils;
import com.mycim.server.base.manager.NamedObjectManager;
import com.mycim.server.ctx.exec.manager.EenLotContextValueManager;
import com.mycim.server.ctx.manager.ContextValueManager;
import com.mycim.utils.WipUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.context.EenLotContextValue;
import com.mycim.valueobject.prp.ContextValue;
import com.mycim.valueobject.wip.Lot;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author Johnson.Wang
* @version 6.0.0
* @date 2019/10/8
**/
@Service
@Transactional
public class EenLotContextValueManagerImpl implements EenLotContextValueManager {
private final NamedObjectManager namedObjectManager;
private final ContextValueManager contextValueManager;
public EenLotContextValueManagerImpl(NamedObjectManager namedObjectManager,
ContextValueManager contextValueManager) {
this.namedObjectManager = namedObjectManager;
this.contextValueManager = contextValueManager;
}
@Override
public List<Long> getFutureActionRrns(Lot lot, String actionPoint) {
EenLotContextValue actionCondition = buildNewEenLotContextValue(lot, actionPoint);
ContextValue actionConditionContextValue = contextValueManager
.filterContextValueToRrn(actionCondition, LocalContext.getFacilityRrn());
List<ContextValue> contextValues = contextValueManager.simulateContextValues(actionConditionContextValue);
if (CollectionUtils.isEmpty(contextValues)) {
return null;
}
List<Long> actionRrns = new ArrayList<>();
for (ContextValue contextValue : contextValues) {
actionRrns.add(NumberUtils.toLong(contextValue.getResultValue1()));
}
return actionRrns;
}
private EenLotContextValue buildNewEenLotContextValue(Lot lot, String actionPoint) {
EenLotContextValue actionCondition = buildNewEenLotContextValue();
actionCondition.setContextKey1(namedObjectManager.getNamedObjectId(lot.getProductRrn()));
actionCondition.setContextKey2(namedObjectManager.getNamedObjectId(lot.getProcessRrn()));
actionCondition.setContextKey3(
Objects.requireNonNull(WipUtils.getRouteByProcessStepVersion(lot.getProcessStepIdVersion()))[0]);
actionCondition.setContextKey4(namedObjectManager.getNamedObjectId(lot.getOperationRrn()));
if (lot.getRecipeLogicalRrn() != null) {
actionCondition.setContextKey5(namedObjectManager.getNamedObjectId(lot.getRecipeLogicalRrn()));
} else {
actionCondition.setContextKey5(null);
}
actionCondition.setContextKey6(lot.getLotId());
actionCondition.setContextKey7(actionPoint);
return actionCondition;
}
private EenLotContextValue buildNewEenLotContextValue() {
EenLotContextValue eenLotContextValue = new EenLotContextValue();
eenLotContextValue.setContextRrn(namedObjectManager.getNamedObjectRrn(eenLotContextValue.getContextId(),
LocalContext.getFacilityRrn(),
ObjectList.CONTEXT_KEY));
return eenLotContextValue;
}
}