# Edc2MySpcSendManagerImpl.java

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

    import com.mycim.framework.logging.Logger;
    import com.mycim.framework.logging.LoggerFactory;
    import com.mycim.framework.utils.lang.collections.CollectionUtils;
    import com.mycim.framework.utils.lang.collections.MapUtils;
    import com.mycim.framework.utils.msg.JsonUtils;
    import com.mycim.server.ocap.manager.OcapManager;
    import com.mycim.server.spc.manager.impl.SpcAbstractSendManagerImpl;
    import com.mycim.server.wip.manager.DiffBatchQueryManager;
    import com.mycim.server.wip.manager.LotManager;
    import com.mycim.server.wip.manager.LotQueryManager;
    import com.mycim.valueobject.edcspc.dto.SpcCheckResultDto;
    import com.mycim.valueobject.wip.Lot;
    import com.mycim.valueobject.wip.LotStatus;
    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.Arrays;
    import java.util.List;
    import java.util.Map;

    /**
     * @author songpy
     * @version 1.0.0
     * @date 2021/2/25
     **/
    @Service
    @Transactional
    public class Edc2MySpcSendManagerImpl extends SpcAbstractSendManagerImpl {
        private final Logger logger = LoggerFactory.getLogger(Edc2MySpcSendManagerImpl.class);

        @Autowired
        OcapManager ocapManager;

        @Autowired
        LotQueryManager lotQueryManager;

        @Autowired
        LotManager lotManager;

        @Autowired
        DiffBatchQueryManager diffBatchQueryManager;

        private void handleSPChold(List<Map<String, Object>> ocapHoldInfo, Boolean rtFlag) {
            for (Map<String, Object> holdInfo : ocapHoldInfo) {
                lotManager.holdRunningLot(holdInfo);
                long lotRrn = MapUtils.getLongValue(holdInfo, "lotRrn");
                if(lotRrn>0){
                    lotManager.calcStepSpeedTime(LotStatus.RUNNINGHOLD,LotStatus.RUNNING,lotRrn,false);
                }
            }
        }

        @Override
        protected void ocapHandle(List<String> results, Boolean rtFlag) {
            List<Map<String, Object>> ocapHoldInfo = new ArrayList<>();
            if (CollectionUtils.isEmpty(results)) {
                logger.error("ocapHandle - SPC Return Msg is empty!");
                return;
            }

            List<SpcCheckResultDto> totalSpcResultList = new ArrayList<>();
            for (String responseMsg : results) {
                SpcCheckResultDto[] spcResults = JsonUtils.toObject(responseMsg, SpcCheckResultDto[].class);
                totalSpcResultList.addAll(Arrays.asList(spcResults));
            }
            ocapHoldInfo = ocapManager.createOcapByInLine(totalSpcResultList);
            handleSPChold(ocapHoldInfo, rtFlag);
        }

    }