|
|
@@ -0,0 +1,79 @@
|
|
|
+package com.usoftchina.saas.transfers.task;
|
|
|
+
|
|
|
+import com.usoftchina.saas.account.api.CompanyApi;
|
|
|
+import com.usoftchina.saas.inquiry.po.purchase.PurchaseDetailEnd;
|
|
|
+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.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
|
|
|
+ */
|
|
|
+public class SendPurchaseEndTask extends Executable {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseApi purchaseApi;
|
|
|
+ @Autowired
|
|
|
+ private CompanyApi companyApi;
|
|
|
+
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(SendPurchaseEndTask.class);
|
|
|
+ private final String purchaseEndUrl = "/erp/purchase/end";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute(MessageInfo messageInfo) throws Exception {
|
|
|
+ String accessSecretKey = companyApi.getCompanyById(messageInfo.getCompanyId()).getData().getAccessKey();
|
|
|
+ PurchaseFormDTO purchaseFormDTO = purchaseApi.getFormData(Long.parseLong(messageInfo.getBizId())).getData();
|
|
|
+ short endStatus = 0;
|
|
|
+ //结案、反结案
|
|
|
+ if("CLOSE".equals(purchaseFormDTO.getMain().getPu_statuscode())) {
|
|
|
+ endStatus = 1; //结案
|
|
|
+ } else {
|
|
|
+ endStatus = 0; //反结案
|
|
|
+ }
|
|
|
+ List<PurchaseDetailDTO> purchaseDetailDTOList = purchaseFormDTO.getItems();
|
|
|
+ List<PurchaseDetailEnd> purchaseDetailEndList = new ArrayList<PurchaseDetailEnd>();
|
|
|
+ if (!CollectionUtils.isEmpty(purchaseDetailDTOList)) {
|
|
|
+ //构造需要发送的数据
|
|
|
+ for (PurchaseDetailDTO purchaseDetailDTO : purchaseDetailDTOList) {
|
|
|
+ PurchaseDetailEnd purchaseDetailEnd = new PurchaseDetailEnd(purchaseDetailDTO.getPd_code(),
|
|
|
+ new BigDecimal(purchaseDetailDTO.getPd_detno()).shortValue(), endStatus,
|
|
|
+ new BigDecimal(purchaseDetailDTO.getId()).intValue());
|
|
|
+ purchaseDetailEndList.add(purchaseDetailEnd);
|
|
|
+ }
|
|
|
+ //发送给b2b
|
|
|
+ sendPurchaseEndToB2B(purchaseEndUrl, Long.parseLong(String.valueOf(messageInfo.getBizId())),
|
|
|
+ JsonUtils.toJsonString(purchaseDetailEndList), accessSecretKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送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, "已上传");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|