|
|
@@ -1,14 +1,95 @@
|
|
|
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.inquiry.po.purchase.PurchaseProdInOut;
|
|
|
+import com.usoftchina.saas.inquiry.po.purchase.PurchaseProdInOutDetail;
|
|
|
+import com.usoftchina.saas.purchase.api.ProdInOutApi;
|
|
|
+import com.usoftchina.saas.purchase.dto.ProdIODetailDTO;
|
|
|
+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.utils.BeanMapper;
|
|
|
+import com.usoftchina.saas.utils.JsonUtils;
|
|
|
+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
|
|
|
- * @create: 2019-01-08 13:53
|
|
|
+ * 采购验收单上传
|
|
|
+ * @author: chenwei
|
|
|
+ * @create: 2019-01-016 16:53
|
|
|
**/
|
|
|
public class SendPurchaseInTask extends Executable{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyApi companyApi;
|
|
|
+ @Autowired
|
|
|
+ private AccountApi accountApi;
|
|
|
+ @Autowired
|
|
|
+ private ProdInOutApi prodInOutApi;
|
|
|
+ @Autowired
|
|
|
+ private B2BConfig b2bConfig;
|
|
|
+
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(SendProductTask.class);
|
|
|
+ private final String prodInUrl = "/erp/purchase/prodInOut";
|
|
|
+
|
|
|
@Override
|
|
|
- public void execute(MessageInfo messageInfo) {
|
|
|
- //TODO
|
|
|
+ public void execute(MessageInfo messageInfo) throws Exception {
|
|
|
+ CompanyDTO companyDTO = companyApi.getCompanyById(messageInfo.getCompanyId()).getData();
|
|
|
+ AccountDTO accountDTO = accountApi.getAccountById(messageInfo.getUserId()).getData();
|
|
|
+
|
|
|
+ ProdInOutFormDTO prodInOutFormDTO = prodInOutApi.getProdFormData(Long.parseLong(messageInfo.getBizId())).getData();
|
|
|
+ ProdInOutDTO prodInOutDTO = prodInOutFormDTO.getMain();
|
|
|
+ PurchaseProdInOut b2bPurchaseProdInOut = BeanMapper.map(prodInOutDTO, PurchaseProdInOut.class);
|
|
|
+ convertToPronInOut(prodInOutDTO, b2bPurchaseProdInOut);
|
|
|
+
|
|
|
+ List<PurchaseProdInOutDetail> b2bPurchaseProdInOutDetailList = BeanMapper.mapList(prodInOutFormDTO.getItems(), PurchaseProdInOutDetail.class);
|
|
|
+ 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()), "已上传");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convertToPronInOut(ProdInOutDTO prodInOutDTO, PurchaseProdInOut b2bPurchaseProdInOut) {
|
|
|
+ b2bPurchaseProdInOut.setPi_rate(new BigDecimal(prodInOutDTO.getPi_rate()).floatValue());
|
|
|
+ b2bPurchaseProdInOut.setPi_inoutman(prodInOutDTO.getPi_auditman());
|
|
|
+ b2bPurchaseProdInOut.setPi_id(prodInOutDTO.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convertToPronInOutDetail(List<ProdIODetailDTO> items, List<PurchaseProdInOutDetail> b2bPurchaseProdInOutDetailList){
|
|
|
+ for (int i = 0; i < items.size(); i++) {
|
|
|
+ ProdIODetailDTO prodIODetailDTO = items.get(i);
|
|
|
+ PurchaseProdInOutDetail b2bPurchaseProdInOutDetail = b2bPurchaseProdInOutDetailList.get(i);
|
|
|
+ b2bPurchaseProdInOutDetail.setPd_id(prodIODetailDTO.getId());
|
|
|
+ b2bPurchaseProdInOutDetail.setPd_detno(new BigDecimal(prodIODetailDTO.getPd_pdno()).shortValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送http请求
|
|
|
+ * @param bizId
|
|
|
+ * @param data
|
|
|
+ * @param accessSecretKey
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void sendProdInToB2B(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){
|
|
|
+ prodInOutApi.updateB2BStatus(bizId, "已上传");
|
|
|
+ }
|
|
|
}
|
|
|
}
|