LotSpecialEquipContextValueManagerImpl.java

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

import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.beans.BeanUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.server.base.manager.NamedObjectManager;
import com.mycim.server.ctx.exec.manager.LotSpecialEquipContextValueManager;
import com.mycim.server.ctx.manager.ContextValueManager;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.prp.ContextValue;
import com.mycim.valueobject.prp.LotSpecialEquipContextValue;
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 shijie.deng
 * @version 6.0.0
 * @date 2019/9/20
 **/
@Service
@Transactional
public class LotSpecialEquipContextValueManagerImpl implements LotSpecialEquipContextValueManager {

    @Autowired
    private ContextValueManager contextValueManager;

    @Autowired
    private NamedObjectManager namedObjectManager;

    @Override
    public LotSpecialEquipContextValue getLotSpecialEquipContextValue(Lot lot) {
        long facilityRrn = LocalContext.getFacilityRrn();
        LotSpecialEquipContextValue specialEquipContextValue = new LotSpecialEquipContextValue();
        long contextRrn = namedObjectManager
                .getNamedObjectRrn(specialEquipContextValue.getContextId(), facilityRrn, ObjectList.CONTEXT_KEY);
        if (contextRrn > 0) {
            specialEquipContextValue.setContextRrn(contextRrn);
            specialEquipContextValue.setProductRrn(lot.getProductRrn());
            specialEquipContextValue.setProcessRrn(lot.getProcessRrn());
            specialEquipContextValue.setRouteRrn(lot.getRouteRrn());
            specialEquipContextValue.setOperationRrn(lot.getOperationRrn());
            specialEquipContextValue.setLotRrn(new Long(lot.getLotRrn()));
            specialEquipContextValue.setRouteSeq(lot.getRouteSeq());
            specialEquipContextValue.setOperationSeq(lot.getOperationSeq());
            ContextValue contextValue = contextValueManager.simulateContextValue(specialEquipContextValue);
            if (contextValue != null) {
                BeanUtils.copyProperties(contextValue, specialEquipContextValue);
            }
        }
        return specialEquipContextValue;
    }

    @Override
    public boolean isOverrideConstrain(Lot lot) {
        boolean overrideConstrain = false;
        LotSpecialEquipContextValue contextValue = getLotSpecialEquipContextValue(lot);
        if (contextValue != null && StringUtils.isNotEmpty(contextValue.getResultValue2()) &&
                StringUtils.equalsIgnoreCase(contextValue.getResultValue2(), "1")) {
            overrideConstrain = true;
        }

        return overrideConstrain;
    }

}