Browse Source

add_万通上架通知接口测试类

konglingbin 6 months ago
parent
commit
a3f5742682

+ 56 - 0
src/main/java/com/hrsoft/edi/stub/wt/ShelveNoticeRequestTest.java

@@ -0,0 +1,56 @@
+package com.hrsoft.edi.stub.wt;
+
+import com.alibaba.fastjson.JSON;
+import com.taobao.api.ApiException;
+import lombok.Getter;
+
+/**
+ * @description: 万通上架通知测试请求
+ * @author: konglingbin
+ * @date 2024/9/6 15:40
+ */
+public class ShelveNoticeRequestTest {
+
+    public static void main(String[] args) throws ApiException {
+        WTWcsQimenClient client = new WTWcsQimenClient(WTAppInfo.REQUEST_URL, WTAppInfo.APP_KEY, WTAppInfo.SECRET);
+        WTWcsRequest<WTShelveNoticeRequest> request = new WTWcsRequest<>();
+        request.setCustomerId(WTAppInfo.CUSTOMER_CODE);
+        request.setApiMethodName("shelves");
+
+        WTShelveNoticeRequest requestBody = new WTShelveNoticeRequest();
+        requestBody.setWarehouseCode("TA");
+        requestBody.setTaskId("RKSJ20240910161932858");
+        requestBody.setBusinessCode("819254807029211141");
+        requestBody.setTaskType(TaskType.SHELVE.getCode());
+        requestBody.setUserId("b1169a96d1a04e52a66af1afaeceddcf");
+        requestBody.setTrayCode("TP001");
+        requestBody.setItemCode("DHC");
+        requestBody.setLocationName("JHKW-01");
+        requestBody.setWeight("50");
+        request.setRequest(requestBody);
+
+        long time1 = System.currentTimeMillis();
+        WTWcsResponse response = client.execute(request);
+        long time2 = System.currentTimeMillis();
+
+        String outFmt = "耗时: %sms, Task ID: %s, Business Code: %s, response: %s";
+        System.out.printf((outFmt) + "%n", (time2 - time1), requestBody.getTaskId(), requestBody.getBusinessCode(), JSON.toJSONString(response));
+    }
+
+    @Getter
+    enum TaskType {
+        SHELVE("0", "上架单"),
+        PICK("1", "拣货单"),
+        UNSHELVE("2", "盘点单"),
+        ;
+
+        private final String code;
+        private final String desc;
+
+        TaskType(String code, String desc) {
+            this.code = code;
+            this.desc = desc;
+        }
+    }
+
+}

+ 17 - 0
src/main/java/com/hrsoft/edi/stub/wt/WTAppInfo.java

@@ -0,0 +1,17 @@
+package com.hrsoft.edi.stub.wt;
+
+/**
+ * @description:
+ * @author: konglingbin
+ * @date 2024/9/6 15:40
+ */
+public interface WTAppInfo {
+
+    String REQUEST_URL = "http://127.0.0.1:9862/api/edi/wcs/service";
+
+    String APP_KEY = "wantong";
+
+    String SECRET = "wantong";
+    String CUSTOMER_CODE = "wantong";
+
+}

+ 69 - 0
src/main/java/com/hrsoft/edi/stub/wt/WTShelveNoticeRequest.java

@@ -0,0 +1,69 @@
+package com.hrsoft.edi.stub.wt;
+
+import com.taobao.api.internal.mapping.ApiField;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 上架成功通知接口
+ */
+@Data
+//@EqualsAndHashCode(callSuper = false)
+public class WTShelveNoticeRequest {
+
+    /**
+     * 仓库
+     */
+    @ApiField("warehouseCode")
+    private String warehouseCode;
+
+    /**
+     * 任务主键ID
+     */
+    @ApiField("taskId")
+    private String taskId;
+
+    /**
+     * 业务编码
+     */
+    @ApiField("businessCode")
+    private String businessCode;
+
+    /**
+     * 任务类型
+     * 0:上架单 1:拣货单 2:盘点单
+     */
+    @ApiField("taskType")
+    private String taskType;
+
+    /**
+     * 用户id
+     */
+    @ApiField("userId")
+    private String userId;
+
+    /**
+     * 托盘编号
+     */
+    @ApiField("trayCode")
+    private String trayCode;
+
+    /**
+     * 商品编码
+     */
+    @ApiField("itemCode")
+    private String itemCode;
+
+    /**
+     * 上架库位
+     */
+    @ApiField("locationName")
+    private String locationName;
+
+    /**
+     * 上架重量
+     */
+    @ApiField("weight")
+    private String weight;
+
+}

+ 196 - 0
src/main/java/com/hrsoft/edi/stub/wt/WTWcsQimenClient.java

@@ -0,0 +1,196 @@
+package com.hrsoft.edi.stub.wt;
+
+import cn.hutool.http.HttpResponse;
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSON;
+import com.hrsoft.edi.stub.internal.XmlWriter;
+import com.qimen.api.QimenClient;
+import com.qimen.api.QimenRequest;
+import com.qimen.api.QimenResponse;
+import com.taobao.api.ApiException;
+import com.taobao.api.Constants;
+import com.taobao.api.TaobaoParser;
+import com.taobao.api.internal.cluster.ClusterManager;
+import com.taobao.api.internal.cluster.DnsConfig;
+import com.taobao.api.internal.parser.xml.QimenXmlParser;
+import com.taobao.api.internal.util.*;
+import org.springframework.http.MediaType;
+
+import java.io.IOException;
+import java.net.Proxy;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+
+public class WTWcsQimenClient implements QimenClient
+{
+    protected String serverUrl;
+
+    protected String appKey;
+
+    protected String appSecret;
+
+    protected String signMethod = "md5";
+
+    protected int connectTimeout = 15000;
+
+    protected int readTimeout = 30000;
+
+    protected boolean needEnableParser = true;
+
+    protected boolean useGzipEncoding = true;
+
+    private boolean isHttpDnsEnabled = false;
+
+    private String originalHttpHost = null;
+
+    public WTWcsQimenClient(String serverUrl, String appKey, String appSecret)
+    {
+        this.appKey = appKey;
+        this.appSecret = appSecret;
+        this.serverUrl = serverUrl;
+    }
+
+    public <T extends QimenResponse> T execute(QimenRequest<T> request)
+        throws ApiException
+    {
+        return this.execute(request, null);
+    }
+
+    public <T extends QimenResponse> T execute(QimenRequest<T> request, String session)
+        throws ApiException
+    {
+        long start = System.currentTimeMillis();
+        RequestParametersHolder requestHolder = new RequestParametersHolder();
+        requestHolder.setApplicationParams(request.getQueryParams());
+        TaobaoHashMap protocalMustParams = new TaobaoHashMap();
+        protocalMustParams.put("method", request.getApiMethodName());
+        protocalMustParams.put("appKey", this.appKey);
+        Long timestamp = request.getTimestamp();
+        if (timestamp == null)
+        {
+            timestamp = System.currentTimeMillis();
+        }
+
+        protocalMustParams.put("timestamp", new Date(timestamp));
+        requestHolder.setProtocalMustParams(protocalMustParams);
+        TaobaoHashMap protocalOptParams = new TaobaoHashMap();
+        protocalOptParams.put("session", session);
+        protocalOptParams.put("customerCode", request.getCustomerId());
+        requestHolder.setProtocalOptParams(protocalOptParams);
+
+        try
+        {
+            String apiBody = request.getBody();
+
+            protocalMustParams.put("sign", TaobaoUtils.signTopRequestWithBody(requestHolder, apiBody, this.appSecret, this.signMethod));
+            String sysMustQuery = WebUtils.buildQuery(requestHolder.getProtocalMustParams(), "UTF-8");
+            String sysOptQuery = WebUtils.buildQuery(requestHolder.getProtocalOptParams(), "UTF-8");
+            String realServerUrl = this.getServerUrl(this.serverUrl);
+            String fullUrl = WebUtils.buildRequestUrl(realServerUrl, new String[] {sysMustQuery, sysOptQuery});
+            TaobaoHashMap headerMap = new TaobaoHashMap();
+            if (this.useGzipEncoding)
+            {
+                headerMap.put("Accept-Encoding", "gzip");
+            }
+
+            if (this.getTopHttpDnsHost() != null)
+            {
+                headerMap.put("TOP_HTTP_DNS_HOST", this.getTopHttpDnsHost());
+            }
+
+            HttpResponse response = HttpUtil.createPost(fullUrl)
+                    .addHeaders(headerMap)
+                    .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
+                    .body(apiBody.getBytes(StandardCharsets.UTF_8))
+                    .setConnectionTimeout(this.connectTimeout)
+                    .setReadTimeout(this.readTimeout)
+                    .execute();
+            requestHolder.setResponseBody(response.body());
+            requestHolder.setResponseHeaders(response.headers());
+        }
+        catch (IOException var17)
+        {
+            TaobaoLogger.logApiError(this.appKey,
+                request.getApiMethodName(),
+                this.serverUrl,
+                requestHolder.getAllParams(),
+                System.currentTimeMillis() - start,
+                var17.toString());
+            throw new ApiException(var17);
+        }
+
+        T tRsp = null;
+        try
+        {
+            tRsp = request.getResponseClass().newInstance();
+            tRsp.setBody(requestHolder.getResponseBody());
+        }
+        catch (Exception e)
+        {
+            throw new ApiException(e);
+        }
+
+        if (!tRsp.isSuccess())
+        {
+            TaobaoLogger.logApiError(appKey,
+                request.getApiMethodName(),
+                serverUrl,
+                requestHolder.getAllParams(),
+                System.currentTimeMillis() - start,
+                tRsp.getBody());
+        }
+        return tRsp;
+    }
+
+    public String getServerUrl(String serverUrl)
+    {
+        if (this.isHttpDnsEnabled)
+        {
+            DnsConfig dnsConfig = ClusterManager.GetDnsConfigFromCache();
+            return dnsConfig == null ? serverUrl : dnsConfig.getVipUrl(serverUrl);
+        }
+        else
+        {
+            return serverUrl;
+        }
+    }
+
+    public String getTopHttpDnsHost()
+    {
+        return this.isHttpDnsEnabled ? this.originalHttpHost : null;
+    }
+
+    public void enableHttpDns()
+    {
+        WebUtils.setIgnoreHostCheck(true);
+        this.setHttpDnsHost(this.serverUrl);
+        ClusterManager.initRefreshThread(this.appKey, this.appSecret);
+        this.isHttpDnsEnabled = true;
+    }
+
+    public void enableHttpDns(String onlineAppKey, String onlineAppSecret)
+    {
+        WebUtils.setIgnoreHostCheck(true);
+        this.setHttpDnsHost(this.serverUrl);
+        ClusterManager.initRefreshThread(onlineAppKey, onlineAppSecret);
+        this.isHttpDnsEnabled = true;
+    }
+
+    private void setHttpDnsHost(String serverUrl)
+    {
+        if (serverUrl != null)
+        {
+            try
+            {
+                URL url = new URL(serverUrl);
+                this.originalHttpHost = url.getHost();
+            }
+            catch (Exception var3)
+            {
+                throw new RuntimeException("error serverUrl:" + serverUrl, var3);
+            }
+        }
+    }
+}
+

+ 36 - 0
src/main/java/com/hrsoft/edi/stub/wt/WTWcsRequest.java

@@ -0,0 +1,36 @@
+package com.hrsoft.edi.stub.wt;
+
+import com.alibaba.fastjson.JSON;
+import com.qimen.api.QimenRequest;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * @description:
+ * @author: konglingbin
+ * @date 2024/9/6 17:44
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class WTWcsRequest<T> extends QimenRequest<WTWcsResponse> {
+
+    private String apiMethodName;
+
+    private T request;
+
+
+    @Override
+    public String getApiMethodName() {
+        return this.apiMethodName;
+    }
+
+    @Override
+    public String getBody() {
+        return JSON.toJSONString(request);
+    }
+
+    @Override
+    public Class<WTWcsResponse> getResponseClass() {
+        return WTWcsResponse.class;
+    }
+}

+ 18 - 0
src/main/java/com/hrsoft/edi/stub/wt/WTWcsResponse.java

@@ -0,0 +1,18 @@
+package com.hrsoft.edi.stub.wt;
+
+import com.qimen.api.QimenResponse;
+import lombok.Data;
+
+
+/**
+ * @description: 万通通用应答
+ * @author: konglingbin
+ * @date 2024/9/6 15:56
+ */
+@Data
+public class WTWcsResponse extends QimenResponse {
+
+    String code;
+    String message;
+
+}