ChangeFlowContextValueManagerImpl.java

package com.mycim.server.ctx.exec.manager.impl;

import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.server.base.manager.NamedObjectManager;
import com.mycim.server.ctx.exec.manager.ChangeFlowContextValueManager;
import com.mycim.server.ctx.manager.ContextValueManager;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.context.ChangeFlowContextValue;
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.List;

/**
 * @author Johnson.Wang
 * @version 6.0.0
 * @date 2019/10/6
 **/
@Service
@Transactional
public class ChangeFlowContextValueManagerImpl implements ChangeFlowContextValueManager {

    private final NamedObjectManager namedObjectManager;

    private final ContextValueManager contextValueManager;

    public ChangeFlowContextValueManagerImpl(NamedObjectManager namedObjectManager,
                                             ContextValueManager contextValueManager) {
        this.namedObjectManager = namedObjectManager;
        this.contextValueManager = contextValueManager;
    }

    @Override
    public List<ContextValue> getChangeFlowContextValues(Lot lot) {
        ChangeFlowContextValue contextValue = buildNewChangeFlowContextValue(lot);

        return contextValueManager.simulateContextValues(contextValue);
    }

    private ChangeFlowContextValue buildNewChangeFlowContextValue(Lot lot) {
        ChangeFlowContextValue changeFlowContextValue = buildNewChangeFlowContextValue();

        changeFlowContextValue.setContextKey1(String.valueOf(lot.getProductRrn()));
        changeFlowContextValue.setContextKey2(String.valueOf(lot.getProcessRrn()));
        long routeRrn = namedObjectManager
                .getNamedObjectRrn(lot.getRouteId(), LocalContext.getFacilityRrn(), ObjectList.WFL_KEY);
        changeFlowContextValue.setContextKey3(String.valueOf(routeRrn));
        changeFlowContextValue.setContextKey4(String.valueOf(lot.getOperationRrn()));

        Long recipeLogicalRrn = lot.getRecipeLogicalRrn();

        if (recipeLogicalRrn != null) {
            changeFlowContextValue.setContextKey5(String.valueOf(recipeLogicalRrn));
        }

        changeFlowContextValue.setContextKey6(String.valueOf(lot.getEqptRrn()));
        changeFlowContextValue.setContextKey7(String.valueOf(lot.getPriority()));

        return changeFlowContextValue;
    }

    private ChangeFlowContextValue buildNewChangeFlowContextValue() {
        ChangeFlowContextValue contextValue = new ChangeFlowContextValue();
        long contextRrn = namedObjectManager
                .getNamedObjectRrn(contextValue.getContextId(), LocalContext.getFacilityRrn(), ObjectList.CONTEXT_KEY);
        contextValue.setContextRrn(contextRrn);
        return contextValue;
    }

}