# DspEqptStatusContextValueManagerImpl.java

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

    import com.fa.sesa.threadlocal.LocalContext;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.ctx.exec.manager.DspEqptStatusContextValueManager;
    import com.mycim.server.ctx.manager.ContextValueManager;
    import com.mycim.valueobject.ObjectList;
    import com.mycim.valueobject.ems.Equipment;
    import com.mycim.valueobject.prp.ContextValue;
    import com.mycim.valueobject.prp.DspEqptStatusContextValue;
    import com.mycim.valueobject.wip.Lot;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    /**
     * @author Johnson.Wang
     * @version 6.0.0
     * @date 2019/9/23
     **/
    @Service
    @Transactional
    public class DspEqptStatusContextValueManagerImpl implements DspEqptStatusContextValueManager {

        @Autowired
        private NamedObjectManager namedObjectManager;

        @Autowired
        private ContextValueManager contextValueManager;

        @Override
        public DspEqptStatusContextValue getDspEqptStatusContextValue(Lot lot, Equipment equipment) {
            DspEqptStatusContextValue dspEqptStatusContextValue = buildNewDspEqptStatusContextValue(lot, equipment);

            ContextValue contextValue = contextValueManager.simulateContextValue(dspEqptStatusContextValue);

            if (contextValue != null) {
                dspEqptStatusContextValue.copy(contextValue);
            }
            return dspEqptStatusContextValue;
        }

        private DspEqptStatusContextValue buildNewDspEqptStatusContextValue(Lot lot, Equipment equipment) {
            DspEqptStatusContextValue contextValue = buildNewDspEqptStatusContextValue();

            contextValue.setProductRrn(lot.getProductRrn());
            contextValue.setProcessRrn(lot.getProcessRrn());
            contextValue.setRouteRrn(lot.getRouteRrn());
            contextValue.setOperationRrn(lot.getOperationRrn());
            contextValue.setRecipeRrn(lot.getRecipeRrn());
            contextValue.setLotRrn(lot.getLotRrn());
            contextValue.setLotType(lot.getLotType());
            // 6* P* G*
            String lotIdPrefix = StringUtils.left(lot.getLotId(), 1);
            contextValue.setLotIdPrefix(lotIdPrefix);
            return contextValue;
        }

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

    }