Ver código fonte

增加请求发送工具类

chenw 7 anos atrás
pai
commit
67b7d90f99

+ 6 - 20
applications/transfers/transfers-server/src/main/java/com/usoftchina/saas/transfers/task/SendPurchaseEndTask.java

@@ -6,20 +6,19 @@ import com.usoftchina.saas.purchase.api.PurchaseApi;
 import com.usoftchina.saas.purchase.dto.PurchaseDetailDTO;
 import com.usoftchina.saas.purchase.dto.PurchaseFormDTO;
 import com.usoftchina.saas.transfers.dto.MessageInfo;
+import com.usoftchina.saas.transfers.utils.SendUtil;
 import com.usoftchina.saas.utils.CollectionUtils;
 import com.usoftchina.saas.utils.JsonUtils;
-import com.usoftchina.saas.utils.http.HttpUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 /**
+ * 采购单结案/反结案
  * @Author chenwei
  * @Date 2019/01/15
  */
@@ -55,25 +54,12 @@ public class SendPurchaseEndTask extends Executable {
                 purchaseDetailEndList.add(purchaseDetailEnd);
             }
             //发送给b2b
-            sendPurchaseEndToB2B(purchaseEndUrl, Long.parseLong(String.valueOf(messageInfo.getBizId())),
-                    JsonUtils.toJsonString(purchaseDetailEndList), accessSecretKey);
+            boolean success = SendUtil.sendToB2B(purchaseEndUrl, JsonUtils.toJsonString(purchaseDetailEndList), accessSecretKey);
+            if (success) {
+                purchaseApi.updateB2BStatus(Long.parseLong(messageInfo.getBizId()), "已上传");
+            }
         }
 
     }
 
-    /**
-     * 发送http请求,更新上传状态
-     * @param bizId
-     * @param data
-     * @param accessSecretKey
-     * @throws Exception
-     */
-    private void sendPurchaseEndToB2B(String url, Long bizId, String data, String accessSecretKey) throws Exception {
-        Map<String, String> params = new HashMap<String, String>();
-        params.put("data", JsonUtils.toJsonString(data));
-        HttpUtil.Response response = HttpUtil.sendPostRequest(url, params, true, accessSecretKey);
-        if (response.getStatusCode() == 200){
-            purchaseApi.updateB2BStatus(bizId, "已上传");
-        }
-    }
 }

+ 5 - 2
applications/transfers/transfers-server/src/main/java/com/usoftchina/saas/transfers/task/SendPurchaseInTask.java

@@ -12,6 +12,7 @@ import com.usoftchina.saas.purchase.dto.ProdInOutDTO;
 import com.usoftchina.saas.purchase.dto.ProdInOutFormDTO;
 import com.usoftchina.saas.transfers.config.B2BConfig;
 import com.usoftchina.saas.transfers.dto.MessageInfo;
+import com.usoftchina.saas.transfers.utils.SendUtil;
 import com.usoftchina.saas.utils.BeanMapper;
 import com.usoftchina.saas.utils.JsonUtils;
 import com.usoftchina.saas.utils.http.HttpUtil;
@@ -58,8 +59,10 @@ public class SendPurchaseInTask extends Executable{
         convertToPronInOutDetail(prodInOutFormDTO.getItems(), b2bPurchaseProdInOutDetailList);
         b2bPurchaseProdInOut.setDetails(b2bPurchaseProdInOutDetailList);
 
-        sendProdInToB2B(b2bConfig.getCommon() + prodInUrl, Long.parseLong(messageInfo.getBizId()), JsonUtils.toJsonString(b2bPurchaseProdInOut), companyDTO.getAccessKey());
-        prodInOutApi.updateB2BStatus(Long.valueOf(messageInfo.getBizId()), "已上传");
+        boolean success = SendUtil.sendToB2B(b2bConfig.getCommon() + prodInUrl, JsonUtils.toJsonString(b2bPurchaseProdInOut), companyDTO.getAccessKey());
+        if (success) {
+            prodInOutApi.updateB2BStatus(Long.parseLong(messageInfo.getBizId()), "已上传");
+        }
     }
 
     private void convertToPronInOut(ProdInOutDTO prodInOutDTO, PurchaseProdInOut b2bPurchaseProdInOut) {

+ 5 - 21
applications/transfers/transfers-server/src/main/java/com/usoftchina/saas/transfers/task/SendPurchaseTask.java

@@ -12,19 +12,16 @@ import com.usoftchina.saas.purchase.dto.PurchaseDetailDTO;
 import com.usoftchina.saas.purchase.dto.PurchaseFormDTO;
 import com.usoftchina.saas.transfers.config.B2BConfig;
 import com.usoftchina.saas.transfers.dto.MessageInfo;
+import com.usoftchina.saas.transfers.utils.SendUtil;
 import com.usoftchina.saas.utils.BeanMapper;
 import com.usoftchina.saas.utils.JsonUtils;
 import com.usoftchina.saas.utils.ObjectUtils;
-import com.usoftchina.saas.utils.http.HttpUtil;
-import com.usoftchina.saas.utils.http.HttpUtil.Response;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.math.BigDecimal;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author: guq
@@ -62,8 +59,10 @@ public class SendPurchaseTask extends Executable {
 
             b2bPurchase.setPurchaseDetails(b2bPurchaseDetailList);
 
-            sendPurchaseToB2B(b2bConfig.getCommon() + purchaseUrl, Long.parseLong(messageInfo.getBizId()), JsonUtils.toJsonString(b2bPurchase), companyDTO.getAccessKey());
-            purchaseApi.updateB2BStatus(Long.parseLong(messageInfo.getBizId()), "已上传");
+            boolean success = SendUtil.sendToB2B(b2bConfig.getCommon() + purchaseUrl, JsonUtils.toJsonString(b2bPurchase), companyDTO.getAccessKey());
+            if (success) {
+                purchaseApi.updateB2BStatus(Long.parseLong(messageInfo.getBizId()), "已上传");
+            }
         }
 
     }
@@ -92,19 +91,4 @@ public class SendPurchaseTask extends Executable {
         }
     }
 
-    /**
-     * 发送http请求
-     * @param bizId
-     * @param data
-     * @param accessSecretKey
-     * @throws Exception
-     */
-    private void sendPurchaseToB2B(String url, Long bizId, String data, String accessSecretKey) throws Exception {
-        Map<String, String> params = new HashMap<String, String>();
-        params.put("data", JsonUtils.toJsonString(data));
-        Response response = HttpUtil.sendPostRequest(url, params, true, accessSecretKey);
-        if (response.getStatusCode() == 200){
-            purchaseApi.updateB2BStatus(bizId, "已上传");
-        }
-    }
 }

+ 35 - 0
applications/transfers/transfers-server/src/main/java/com/usoftchina/saas/transfers/utils/SendUtil.java

@@ -0,0 +1,35 @@
+package com.usoftchina.saas.transfers.utils;
+
+import com.usoftchina.saas.utils.JsonUtils;
+import com.usoftchina.saas.utils.http.HttpUtil;
+import com.usoftchina.saas.utils.http.HttpUtil.Response;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Description 发送请求至B2B工具类
+ * @Author chenwei
+ * @Date 2019/01/16
+ */
+public class SendUtil {
+
+    /**
+     *  发送请求给B2B
+     * @param url         URL
+     * @param data        要发送的数据
+     * @param accessSecretKey       企业秘钥
+     * @return
+     * @throws Exception
+     */
+    public static boolean sendToB2B(String url, String data, String accessSecretKey) throws Exception {
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("data", JsonUtils.toJsonString(data));
+        Response response = HttpUtil.sendPostRequest(url, params, true, accessSecretKey);
+        if (response.getStatusCode() == 200){
+            return true;
+        }
+        return false;
+    }
+
+}