|
|
@@ -0,0 +1,78 @@
|
|
|
+package com.usoftchina.saas.transfers.task;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.usoftchina.saas.account.api.CompanyApi;
|
|
|
+import com.usoftchina.saas.account.dto.CompanyDTO;
|
|
|
+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.config.B2BConfig;
|
|
|
+import com.usoftchina.saas.transfers.utils.SendUtil;
|
|
|
+import com.usoftchina.saas.utils.CollectionUtils;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author chenwei
|
|
|
+ * @Date 2019/01/21
|
|
|
+ */
|
|
|
+@SpringBootTest
|
|
|
+@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
+@EnableAutoConfiguration
|
|
|
+public class SendPurchaseEndTaskTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseApi purchaseApi;
|
|
|
+ @Autowired
|
|
|
+ private CompanyApi companyApi;
|
|
|
+ @Autowired
|
|
|
+ private B2BConfig b2bConfig;
|
|
|
+
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(SendPurchaseEndTask.class);
|
|
|
+ private final String purchaseEndUrl = "/erp/purchase/end";
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testA_SendPurchaseEndTaskTest() throws Exception {
|
|
|
+ CompanyDTO companyDTO = companyApi.getCompanyById(371L).getData();
|
|
|
+ PurchaseFormDTO purchaseFormDTO = purchaseApi.getFormData(0L).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);
|
|
|
+ }
|
|
|
+ //添加身份ID
|
|
|
+ String url = b2bConfig.getCommon() + purchaseEndUrl + "?access_id=" + companyDTO.getUu();
|
|
|
+ //发送给b2b
|
|
|
+ boolean success = SendUtil.sendToB2B(url, JSON.toJSONString(purchaseDetailEndList), companyDTO.getAccessKey());
|
|
|
+ if (success) {
|
|
|
+ LOGGER.info("上传成功!");
|
|
|
+ } else {
|
|
|
+ LOGGER.info("上传失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|