|
|
@@ -1,26 +1,30 @@
|
|
|
package com.usoftchina.saas.transfers.task;
|
|
|
|
|
|
+import com.usoftchina.saas.account.api.AccountApi;
|
|
|
import com.usoftchina.saas.account.api.CompanyApi;
|
|
|
+import com.usoftchina.saas.account.dto.AccountDTO;
|
|
|
import com.usoftchina.saas.account.dto.CompanyDTO;
|
|
|
+import com.usoftchina.saas.document.api.VendorApi;
|
|
|
+import com.usoftchina.saas.document.dto.VendorListDTO;
|
|
|
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.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 com.usoftchina.saas.utils.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author: guq
|
|
|
@@ -31,8 +35,12 @@ public class SendPurchaseTask extends Executable {
|
|
|
@Autowired
|
|
|
private CompanyApi companyApi;
|
|
|
@Autowired
|
|
|
+ private AccountApi accountApi;
|
|
|
+ @Autowired
|
|
|
private PurchaseApi purchaseApi;
|
|
|
@Autowired
|
|
|
+ private VendorApi vendorApi;
|
|
|
+ @Autowired
|
|
|
private B2BConfig b2bConfig;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(SendProductTask.class);
|
|
|
@@ -41,35 +49,56 @@ public class SendPurchaseTask extends Executable {
|
|
|
@Override
|
|
|
public void execute(MessageInfo messageInfo) throws Exception {
|
|
|
CompanyDTO companyDTO = companyApi.getCompanyById(messageInfo.getCompanyId()).getData();
|
|
|
+ AccountDTO accountDTO = accountApi.getAccountById(messageInfo.getUserId()).getData();
|
|
|
PurchaseFormDTO purchaseFormDTO = purchaseApi.getFormData(Long.parseLong(messageInfo.getBizId())).getData();
|
|
|
if (!ObjectUtils.isEmpty(purchaseFormDTO)){
|
|
|
//采购单主表数据
|
|
|
PurchaseDTO purchaseDTO = purchaseFormDTO.getMain();
|
|
|
Purchase b2bPurchase = BeanMapper.map(purchaseDTO, Purchase.class);
|
|
|
- //b2bPurchase.setVe_uu(0L);
|
|
|
+ convertPurchase(purchaseDTO, b2bPurchase, accountDTO, messageInfo.getCompanyId());
|
|
|
+ LOGGER.info("purchaseDTO={}, b2bPurchase={}", JsonUtils.toJsonString(purchaseDTO), JsonUtils.toJsonString(b2bPurchase));
|
|
|
//采购单明细表数据
|
|
|
List<PurchaseDetail> b2bPurchaseDetailList = BeanMapper.mapList(purchaseFormDTO.getItems(), PurchaseDetail.class);
|
|
|
+ convertPurchaseDetail(purchaseFormDTO.getItems(), b2bPurchaseDetailList);
|
|
|
+ LOGGER.info("PurchaseDetailDTO={}, b2bPurchaseDetailList={}", JsonUtils.toJsonString(purchaseFormDTO.getItems()), JsonUtils.toJsonString(b2bPurchaseDetailList));
|
|
|
+
|
|
|
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()), "已上传");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 发送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, "已上传");
|
|
|
+ private void convertPurchase(PurchaseDTO purchaseDTO, Purchase b2bPurchase, AccountDTO accountDTO, Long companyId) {
|
|
|
+ //人员信息
|
|
|
+ b2bPurchase.setEm_email(accountDTO.getEmail());
|
|
|
+ b2bPurchase.setEm_mobile(accountDTO.getMobile());
|
|
|
+ b2bPurchase.setEm_name(accountDTO.getRealname());
|
|
|
+ b2bPurchase.setEm_uu(accountDTO.getUu());
|
|
|
+ VendorListDTO vendorListDTO = vendorApi.getDataById(new BigDecimal(purchaseDTO.getPu_vendid()).longValue()).getData();
|
|
|
+ if (!ObjectUtils.isEmpty(vendorListDTO)){
|
|
|
+ String uu = vendorListDTO.getMain().getVe_uu();
|
|
|
+ if (!StringUtils.isEmpty(uu)){
|
|
|
+ b2bPurchase.setVe_uu(Long.parseLong(uu));
|
|
|
+ }
|
|
|
}
|
|
|
+ b2bPurchase.setPu_rate(new BigDecimal(purchaseDTO.getPu_rate()).floatValue());
|
|
|
+ b2bPurchase.setPu_remark(purchaseDTO.getPu_remark());
|
|
|
+ b2bPurchase.setPu_auditman(purchaseDTO.getPu_auditman());
|
|
|
+ b2bPurchase.setPu_recordman(purchaseDTO.getCreatorName());
|
|
|
+ b2bPurchase.setPu_shipaddresscode(purchaseDTO.getPu_shipaddresscode());
|
|
|
+ b2bPurchase.setPu_id(purchaseDTO.getId());
|
|
|
}
|
|
|
+
|
|
|
+ private void convertPurchaseDetail(List<PurchaseDetailDTO> items, List<PurchaseDetail> b2bPurchaseDetailList){
|
|
|
+ for (int i = 0; i < items.size(); i++) {
|
|
|
+ PurchaseDetailDTO purchaseDetailDTO = items.get(i);
|
|
|
+ PurchaseDetail b2bPurchaseDetail = b2bPurchaseDetailList.get(i);
|
|
|
+ b2bPurchaseDetail.setPd_detno(new BigDecimal(purchaseDetailDTO.getPd_detno()).shortValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|