|
|
@@ -1,21 +1,26 @@
|
|
|
package com.usoftchina.saas.transfers.task;
|
|
|
|
|
|
import com.usoftchina.saas.account.api.CompanyApi;
|
|
|
-import com.usoftchina.saas.inquiry.api.B2BPurchaseApi;
|
|
|
+import com.usoftchina.saas.account.dto.CompanyDTO;
|
|
|
import com.usoftchina.saas.inquiry.po.purchase.Purchase;
|
|
|
import com.usoftchina.saas.inquiry.po.purchase.PurchaseDetail;
|
|
|
import com.usoftchina.saas.purchase.api.PurchaseApi;
|
|
|
import com.usoftchina.saas.purchase.dto.PurchaseDTO;
|
|
|
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.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.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author: guq
|
|
|
@@ -28,12 +33,14 @@ public class SendPurchaseTask extends Executable {
|
|
|
@Autowired
|
|
|
private PurchaseApi purchaseApi;
|
|
|
@Autowired
|
|
|
- private B2BPurchaseApi b2BPurchaseApi;
|
|
|
+ private B2BConfig b2bConfig;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(SendProductTask.class);
|
|
|
+ private final String purchaseUrl = "/erp/purchase";
|
|
|
|
|
|
@Override
|
|
|
- public void execute(MessageInfo messageInfo) {
|
|
|
+ public void execute(MessageInfo messageInfo) throws Exception {
|
|
|
+ CompanyDTO companyDTO = companyApi.getCompanyById(messageInfo.getCompanyId()).getData();
|
|
|
PurchaseFormDTO purchaseFormDTO = purchaseApi.getFormData(Long.parseLong(messageInfo.getBizId())).getData();
|
|
|
if (!ObjectUtils.isEmpty(purchaseFormDTO)){
|
|
|
//采购单主表数据
|
|
|
@@ -44,10 +51,25 @@ public class SendPurchaseTask extends Executable {
|
|
|
List<PurchaseDetail> b2bPurchaseDetailList = BeanMapper.mapList(purchaseFormDTO.getItems(), PurchaseDetail.class);
|
|
|
b2bPurchase.setPurchaseDetails(b2bPurchaseDetailList);
|
|
|
|
|
|
- /*SavePurchaseListResp savePurchaseListResp = */
|
|
|
- b2BPurchaseApi.savePurchase(JsonUtils.toJsonString(b2bPurchase));
|
|
|
+ sendPurchaseToB2B(b2bConfig.getCommon() + purchaseUrl, Long.parseLong(messageInfo.getBizId()), JsonUtils.toJsonString(b2bPurchase), companyDTO.getAccessKey());
|
|
|
purchaseApi.updateB2BStatus(Long.parseLong(messageInfo.getBizId()), "已上传");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送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, "已上传");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|