# Edc2MyspcSender.java

    package com.mycim.server.edcmyspc.myspc;

    import com.fa.sesa.exception.Errors;
    import com.fa.sesa.exception.SystemIllegalArgumentException;
    import com.fa.sesa.threadlocal.LocalContext;
    import com.mycim.framework.logging.Logger;
    import com.mycim.framework.logging.LoggerFactory;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.server.edcmyspc.manager.Edc2MyspcManager;
    import com.mycim.server.spc.BaseEdc2SpcSender;
    import com.mycim.server.spc.manager.SpcManager;
    import com.mycim.valueobject.spc.SpcConfigConstants;
    import com.mycim.valueobject.wip.Lot;
    import com.mycim.webservice.rtservice.client.stub.ServiceLocator;
    import com.mycim.webservice.rtservice.client.stub.ServiceSoap_PortType;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;

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

    /**
     * @author Johnson.Wang
     * @version 6.0.0
     * @date 2019/11/8
     **/
    @Component
    public class Edc2MyspcSender extends BaseEdc2SpcSender {

        private final Logger logger = LoggerFactory.getLogger(Edc2MyspcSender.class);

        @Autowired
        private Edc2MyspcManager edc2MyspcManager;

        @Autowired
        private SpcManager spcManager;

        @Override
        public List<String> send(List<String> request, List<Map> dcolStepInfos, Boolean rtFlag, Boolean isOcapSend) {
            String edcType = rtFlag ? SpcConfigConstants.EDC_TYPE_RT : SpcConfigConstants.EDC_TYPE_NORT;
            String edc2MyspcUrl = spcManager
                    .getSpcConfigValue(LocalContext.getFacilityRrn(), SpcConfigConstants.SPC_WS_URL, edcType);

            ServiceLocator serviceLocator = new ServiceLocator();
            ServiceSoap_PortType portType;
            String result = StringUtils.EMPTY;
            List<String> results = new ArrayList<>();
            for (String requestMsg : request) {
                if (StringUtils.isNotEmpty(requestMsg)) {
                    try {
                        serviceLocator.setEndpointAddress(SpcConfigConstants.SPC_SOAP_PROTOTOL, edc2MyspcUrl);
                        portType = serviceLocator.getServiceSoap();
                        result = portType.spcCheck(requestMsg);
                        results.add(result);
                    } catch (Exception e) {
                        throw new SystemIllegalArgumentException(Errors.create().content("Spc spcCheck error").build());
                    }
                    edc2MyspcManager.handleSpcCheckResults(result, requestMsg, rtFlag, false, isOcapSend);
                }
            }
            return results;
        }

        @Override
        public void send(List<String> request, List<Lot> lots) {
            String edc2MyspcUrl = spcManager.getSpcConfigValue(LocalContext.getFacilityRrn(), SpcConfigConstants.SPC_WS_URL,
                                                               SpcConfigConstants.EDC_TYPE_RT);

            ServiceLocator serviceLocator = new ServiceLocator();
            ServiceSoap_PortType portType;
            String result;

            for (String requestMsg : request) {
                try {
                    serviceLocator.setEndpointAddress(SpcConfigConstants.SPC_SOAP_PROTOTOL, edc2MyspcUrl);
                    portType = serviceLocator.getServiceSoap();
                    result = portType.spcCheck(requestMsg);
                } catch (Exception e) {
                    throw new SystemIllegalArgumentException(Errors.create().content("Spc spcCheck error").build());
                }
                //edc2MyspcManager.handleSpcCheckResults(result, requestMsg, true, true);
            }

        }

    }