WebServiceClient.java 4.8 KB
package StSys.RoyoTech;

import StSys.RoyoTech.client.AdapterService;
import StSys.RoyoTech.client.IWSAdapter;
import com.myproject.bean.update.Barcode;
import com.myproject.util.XmlUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by sunke on 2019/10/12.
 */
public class WebServiceClient {

    protected static final transient Logger log = LogManager.getLogger(WebServiceClient.class);

    private static IWSAdapter adapter = null;

    public static String NotifyCarrierNew(String barcode, String pn){
        log.info("扫到条码["+barcode+"]通知纬创接口");
        String commandStr = "<XmlCommand><Command>NotifyCarrierNew</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /><Field key=\"ARTICLE\" value=\""+pn+"\" /></FieldList></Parameter></XmlCommand>";
        //commandStr = "<XmlCommand><Command>NotifyCarrierNew</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\"M680174253219ACBT\" /><Field key=\"ARTICLE\" value=\"68.8R2BN.201\" /></FieldList></Parameter></XmlCommand>";
        String resultXml = exeCommand(commandStr);
        String errorCode =  XmlUtil.getNodeBody("Errorcode",resultXml);
        if(!"0".equals(errorCode)){
            return XmlUtil.getNodeBody("Message",resultXml);
        }
        return "";
    }

    /**
     * 3.2.1 RequestLoad
     */
    public static String RequestLoad(String barcode){
        log.info("验证["+barcode+"]是否可以入库");
        String commandStr = "<XmlCommand><Command>RequestLoad</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /></FieldList></Parameter></XmlCommand>";
        String resultXml = exeCommand(commandStr);
        String errorCode =  XmlUtil.getNodeBody("Errorcode",resultXml);
        if(!"0".equals(errorCode)){
            return XmlUtil.getNodeBody("Message",resultXml);
        }
        return "";
    }



    public static void NotifyCarrierLoad(String barcode, String cid){
        log.info("通知["+barcode+"]入库完成");
        String commandStr = "<XmlCommand><Command>NotifyCarrierLoad</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /><Field key=\"TOWER\" value=\""+cid+"\" /></FieldList></Parameter></XmlCommand>";
        exeCommand(commandStr);
        //String errorCode =  XmlUtil.getNodeBody("Errorcode",resultXml);
    }

    /**
     * 3.2.1 RequestUnload
     */
    public static String RequestUnload(String barcode){
        log.info("验证["+barcode+"]是否可以出库");
        String commandStr = "<XmlCommand><Command>RequestUnload</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /></FieldList></Parameter></XmlCommand>";
        String resultXml = exeCommand(commandStr);
        String errorCode =  XmlUtil.getNodeBody("Errorcode",resultXml);
        if(!"0".equals(errorCode)){
            return XmlUtil.getNodeBody("Message",resultXml);
        }
        return "";
    }

    public static String NotifyCarrierUnload(String barcode, String cid){
        log.info("通知["+barcode+"] 出库完成");
        String commandStr = "<XmlCommand><Command>NotifyCarrierUnload</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /><Field key=\"TOWER\" value=\""+cid+"\" /></FieldList></Parameter></XmlCommand>";
        String result = exeCommand(commandStr);
        return result;
    }

//    public static Barcode RequestCarrierData(String barcode){
//        String commandStr = "<XmlCommand><Command>RequestCarrierData</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /></FieldList></Parameter></XmlCommand>";
//        String resultXml = exeCommand(commandStr);
//
//    }

    public static void reloadAdapter(String wsdlUrl){
        AdapterService.init(wsdlUrl);
        adapter = new AdapterService().getBasicHttpBindingIWSAdapter();
    }

    private static String exeCommand(String commandStr){
        try {
            if(adapter == null){
                adapter = new AdapterService().getBasicHttpBindingIWSAdapter();
            }
            log.info("execute: " + commandStr);
            String result = adapter.adapterCommand(commandStr);
            log.info("result:" + result);
            return result;

        }catch (Exception e){
            log.error("执行命令出错",e);
        }
        return "";
    }


    public static void main(String args[]) throws Exception{
        String barcode = "M780174253919WFH9";
        String pn = "78.10520.5SL";
        String cid = "wczt001";
        WebServiceClient.NotifyCarrierNew(barcode,pn);
        //WebServiceClient.RequestLoad(barcode);
        //WebServiceClient.NotifyCarrierLoad(barcode,cid);


        //WebServiceClient.RequestUnload(barcode);
        //WebServiceClient.NotifyCarrierUnload(barcode,cid);

    }

}