EenActionQueryManagerImpl.java

package com.mycim.server.wip.manager.impl;

import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
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.server.wip.dao.EenActionQueryDAO;
import com.mycim.server.wip.manager.EenActionQueryManager;
import com.mycim.server.wip.manager.LotQueryManager;
import com.mycim.valueobject.alm.EenAction;
import com.mycim.valueobject.consts.EenActionType;
import com.mycim.valueobject.prp.ContextValue;
import com.mycim.valueobject.wip.Lot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Johnson.Wang
 * @version 6.0.0
 * @date 2019/10/8
 **/
@Service
@Transactional
public class EenActionQueryManagerImpl implements EenActionQueryManager {

    @Autowired
    private EenActionQueryDAO eenActionQueryDAO;

    @Autowired
    private LotQueryManager lotQueryManager;

    @Autowired
    private NamedObjectManager namedObjectManager;

    @Autowired
    private EenLotContextValueManager eenLotContextValueManager;

    @Autowired
    private ContextValueManager contextValueManager;

    @Override
    public List<EenAction> getEenActionsWithMerged(long actionRrn) {
        return eenActionQueryDAO.getEenActionsWithMerged(actionRrn);
    }

    @Override
    public List<EenAction> getFutureActions(Lot lot, String actionPoint) {
        List<Long> actionRrns = eenLotContextValueManager.getFutureActionRrns(lot, actionPoint);

        if (CollectionUtils.isEmpty(actionRrns)) {
            return null;
        }

        List<EenAction> eenActionList = new ArrayList<>();
        for (Long actionRrn : actionRrns) {
            eenActionList.addAll(getEenActions(actionRrn));
        }

        return eenActionList;
    }

    @Override
    public EenAction getEenAction(EenAction eenAction) {
        return eenActionQueryDAO.getEenAction(eenAction);
    }

    @Override
    public List<EenAction> getEenActions(long actionRrn) {
        List<EenAction> eenActionList = eenActionQueryDAO.getEenActions(actionRrn);
        if (CollectionUtils.isEmpty(eenActionList)) {
            return null;
        }

        for (EenAction action : eenActionList) {
            if (action.getActionType().equals(EenActionType.HOLD_LOT_KEY)) {

                if (StringUtils.isNotEmpty(action.getParameterValue1())) {
                    action.setParameterValue1Id(lotQueryManager.getLotId(Long.parseLong(action.getParameterValue1())));
                }
            } else if (action.getActionType().equals(EenActionType.SPLIT_LOT_KEY)) {

                if (StringUtils.isNotEmpty(action.getParameterValue1())) {
                    action.setParameterValue1Id(lotQueryManager.getLotId(Long.parseLong(action.getParameterValue1())));
                }
            } else {

                action.setParameterValue1Id(
                        namedObjectManager.getNamedObjectId(Long.valueOf(action.getParameterValue1())));

                action.setParameterValue2Id(
                        namedObjectManager.getNamedObjectId(Long.parseLong(action.getParameterValue2())));
            }
        }

        return eenActionList;
    }

    @Override
    public List<EenAction> getFutureActions(ContextValue contextValue, long facilityRrn) {
        List actions = new ArrayList();
        List<ContextValue> contextValues = new ArrayList();
        contextValue = contextValueManager.filterContextValueToRrn(contextValue, facilityRrn);
        if (contextValue == null) {
            return actions;
        }
        contextValues = contextValueManager.simulateContextValues(contextValue);

        ContextValue item = null;

        for (ContextValue contextValue1 : contextValues) {
            if (contextValue1.getResultValue1() != null) {
                actions.addAll(getEenActions(new Long(item.getResultValue1()).longValue()));
            }
        }
        return actions;
    }

}