进出口单证推送数据修改

This commit is contained in:
zhaoqing
2026-06-08 16:18:09 +08:00
parent 536077ec3a
commit 289c64be2f
2 changed files with 56 additions and 57 deletions
@@ -8,6 +8,7 @@ import com.mhd.oms.domain.businessDeliveryDetailsLink.entity.BusinessDeliveryDet
import com.mhd.oms.domain.businessDeliveryDetailsLink.repository.dto.BusinessDeliveryDetailsLinkDTO; import com.mhd.oms.domain.businessDeliveryDetailsLink.repository.dto.BusinessDeliveryDetailsLinkDTO;
import com.mhd.oms.domain.businessDeliveryDetailsLink.repository.mapper.BusinessDeliveryDetailsLinkMapper; import com.mhd.oms.domain.businessDeliveryDetailsLink.repository.mapper.BusinessDeliveryDetailsLinkMapper;
import com.mhd.oms.domain.businessDocumentCargoMulti.entity.BusinessDocumentCargoMulti; import com.mhd.oms.domain.businessDocumentCargoMulti.entity.BusinessDocumentCargoMulti;
import com.mhd.oms.domain.businessDocumentCargoMulti.repository.mapper.BusinessDocumentCargoMultiMapper;
import com.mhd.oms.domain.businessDocumentOrder.entity.BusinessDocumentOrder; import com.mhd.oms.domain.businessDocumentOrder.entity.BusinessDocumentOrder;
import com.mhd.oms.domain.businessDocumentOrder.repository.mapper.BusinessDocumentOrderMapper; import com.mhd.oms.domain.businessDocumentOrder.repository.mapper.BusinessDocumentOrderMapper;
import com.mhd.oms.domain.businessDocumentOrder.repository.po.BusinessDocumentOrderPO; import com.mhd.oms.domain.businessDocumentOrder.repository.po.BusinessDocumentOrderPO;
@@ -22,7 +23,6 @@ import com.mhd.oms.domain.gwLog.entity.GwLog;
import com.mhd.oms.domain.gwLog.repository.mapper.GwLogMapper; import com.mhd.oms.domain.gwLog.repository.mapper.GwLogMapper;
import com.mhd.oms.interfaces.dto.businessDocumentAddressMulti.BusinessAuditDTO; import com.mhd.oms.interfaces.dto.businessDocumentAddressMulti.BusinessAuditDTO;
import com.mhd.oms.interfaces.dto.businessDocumentOrder.BusinessDocumentOrderDTO; import com.mhd.oms.interfaces.dto.businessDocumentOrder.BusinessDocumentOrderDTO;
import com.mhd.oms.interfaces.dto.originalImportExportDocument.OrderWithMaterialDTO;
import com.mhd.system.api.model.LoginUser; import com.mhd.system.api.model.LoginUser;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
@@ -31,13 +31,11 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.ehcache.shadow.org.terracotta.context.extractor.ObjectContextExtractor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.json.JsonObject;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
@@ -54,7 +52,7 @@ public class BusinessDocumentOrderApplicationService {
private static final String PUSH_API_URL = "http://10.33.0.100/nagu-erp-api/transfer/pushData"; private static final String PUSH_API_URL = "http://10.33.0.100/nagu-erp-api/transfer/pushData";
private static final String API_NAME_I = "saveBill_i"; private static final String API_NAME_I = "saveBill_i";
private static final String API_NAME_E = "saveBill_e"; private static final String API_NAME_E = "saveBill_e";
private static final String VERIFY = "ESLuxAmB6VXCgbqP1eFzxTPVRagkQ62BUkfhElrgQ6XmE/g2reHVflY/SiCSU7JD"; private static final String VERIFY = "FuDjK3iuftzwf8kWJ44DDZJ9icZmL9Ee4Valv8Qz6VfsdW60fNEzNSEtrKlUr6OI";
private static final String API_NAME = "billAppModify"; private static final String API_NAME = "billAppModify";
@@ -73,6 +71,8 @@ public class BusinessDocumentOrderApplicationService {
@Resource @Resource
private GwLogMapper gwLogMapper; private GwLogMapper gwLogMapper;
@Resource
private BusinessDocumentCargoMultiMapper businessDocumentCargoMultiMapper;
@Autowired @Autowired
private BusinessDeliveryDetailsLinkMapper businessDeliveryDetailsLinkMapper; private BusinessDeliveryDetailsLinkMapper businessDeliveryDetailsLinkMapper;
@Resource @Resource
@@ -171,7 +171,7 @@ public class BusinessDocumentOrderApplicationService {
public AjaxResult batchPushForOriginalImportExportDocument(List<BusinessDocumentOrderDTO> businessDocumentOrderDTOList) { public AjaxResult batchPushForOriginalImportExportDocument(List<Long> idList) {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
Long pushBy = loginUser != null ? loginUser.getUserid() : null; Long pushBy = loginUser != null ? loginUser.getUserid() : null;
String pushByName = loginUser != null ? loginUser.getUsername() : null; String pushByName = loginUser != null ? loginUser.getUsername() : null;
@@ -183,40 +183,52 @@ public class BusinessDocumentOrderApplicationService {
int failCount = 0; int failCount = 0;
StringBuilder failMsg = new StringBuilder(); StringBuilder failMsg = new StringBuilder();
for (BusinessDocumentOrderDTO pushData : businessDocumentOrderDTOList) { for (Long id : idList) {
// 1. 构建推送数据 // 1. 查询订单
BusinessDocumentOrder order = businessDocumentOrderMapper.selectById(id);
if (order == null) {
failCount++;
failMsg.append("ID:").append(id).append("订单不存在;");
continue;
}
// 2. 查询cargo明细
List<BusinessDocumentCargoMulti> cargoList = businessDocumentCargoMultiMapper.selectList(
new LambdaQueryWrapper<BusinessDocumentCargoMulti>()
.eq(BusinessDocumentCargoMulti::getOrderId, id)
);
// 3. 构建推送数据
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
body.put("erpBillNo", String.valueOf(pushData.getId())); body.put("erpBillNo", String.valueOf(order.getId()));
body.put("billDate", pushData.getDocumentDate()); body.put("billDate", order.getDocumentDate());
body.put("goodsType", pushData.getGoodsType()); body.put("goodsType", order.getGoodsType());
body.put("ieFlag", pushData.getIeType() != null ? pushData.getIeType() : null); body.put("ieFlag", order.getIeType() != null ? order.getIeType() : null);
body.put("corpCode", pushData.getAppointShipperId() != null ? pushData.getAppointShipperId().toString() : null); body.put("corpCode", order.getAppointShipperId() != null ? order.getAppointShipperId() : null);
List<Map<String, Object>> billList = new ArrayList<>(); List<Map<String, Object>> billList = new ArrayList<>();
int gNo = 1; if (cargoList != null && !cargoList.isEmpty()) {
for(OrderWithMaterialDTO orderWithMaterialDTO : pushData.getOrderWithMaterialDTOList()){ int gNo = 1;
Map<String, Object> billMap = new HashMap<>(); for (BusinessDocumentCargoMulti cargo : cargoList) {
billMap.put("gNo", gNo++); Map<String, Object> billMap = new HashMap<>();
billMap.put("goodsCode", orderWithMaterialDTO.getMaterialCode() != null ? orderWithMaterialDTO.getMaterialCode().toString() : null); billMap.put("gNo", gNo++);
billMap.put("netWt", orderWithMaterialDTO.getWeightLimit()); billMap.put("goodsCode", cargo.getMaterialCode() != null ? cargo.getMaterialCode() : null);
billMap.put("grossWt", orderWithMaterialDTO.getGrossWeight()); billMap.put("packNo", cargo.getCargoNum());
billMap.put("packNo", orderWithMaterialDTO.getCargoNum()); billMap.put("erpQty", cargo.getCargoNum());
billMap.put("erpQty", orderWithMaterialDTO.getCargoNum()); billList.add(billMap);
billList.add(billMap); }
} }
body.put("billList",billList); body.put("billList", billList);
List<Map<String, Object>> bodyList = new ArrayList<>(); List<Map<String, Object>> bodyList = new ArrayList<>();
bodyList.add(body); bodyList.add(body);
if (pushData.getId() != null) { // 4. 更新推送状态为推送中
updatePushStatus(pushData.getId(), 2, null, String.valueOf(pushBy), pushByName); updatePushStatus(order.getId(), 2, null, String.valueOf(pushBy), pushByName);
}
// 5. 记录日志
// 2. 记录日志
GwLog gwLog = new GwLog(); GwLog gwLog = new GwLog();
gwLog.setType("进出口原始单证"); gwLog.setType("进出口原始单证");
gwLog.setBusinessId(Long.valueOf(pushData.getId())); gwLog.setBusinessId(order.getId());
gwLog.setRequestBody(JSONObject.toJSONString(bodyList)); gwLog.setRequestBody(JSONObject.toJSONString(bodyList));
gwLog.setResponseBody(""); gwLog.setResponseBody("");
gwLog.setStatus(1); gwLog.setStatus(1);
@@ -229,7 +241,7 @@ public class BusinessDocumentOrderApplicationService {
gwLog.setDelFlag(1); gwLog.setDelFlag(1);
gwLogMapper.insert(gwLog); gwLogMapper.insert(gwLog);
// 3. 调用推送接口 // 6. 调用推送接口
try { try {
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(PUSH_API_URL); HttpPost httpPost = new HttpPost(PUSH_API_URL);
@@ -238,13 +250,11 @@ public class BusinessDocumentOrderApplicationService {
httpPost.setHeader("Content-type", "application/json"); httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("verify", VERIFY); httpPost.setHeader("verify", VERIFY);
if(pushData.getIeType().equals("I")) if ("I".equals(order.getIeType())) {
{
httpPost.setHeader("apiName", API_NAME_I); httpPost.setHeader("apiName", API_NAME_I);
} } else if ("E".equals(order.getIeType())) {
else if (pushData.getIeType().equals("E")) {
httpPost.setHeader("apiName", API_NAME_E); httpPost.setHeader("apiName", API_NAME_E);
}else{ } else {
AjaxResult.error("进出口方式错误"); AjaxResult.error("进出口方式错误");
} }
@@ -253,35 +263,26 @@ public class BusinessDocumentOrderApplicationService {
gwLog.setResponseBody(responseString); gwLog.setResponseBody(responseString);
if (response.getStatusLine().getStatusCode() == 200) { if (response.getStatusLine().getStatusCode() == 200) {
// gwLog.setStatus(2);
// if (pushData.getId() != null) {
// updatePushStatus(pushData.getId(), 3, new Date(), String.valueOf(pushBy), pushByName);
// }
// successCount++;
JSONObject responseJson = JSONObject.parseObject(responseString); JSONObject responseJson = JSONObject.parseObject(responseString);
Integer dataCode = responseJson.getInteger("code"); Integer dataCode = responseJson.getInteger("code");
if (dataCode != null && dataCode == 200) { if (dataCode != null && dataCode == 200) {
gwLog.setStatus(2); gwLog.setStatus(2);
updatePushStatus(pushData.getId(), 3, new Date(), String.valueOf(pushBy), pushByName); updatePushStatus(order.getId(), 3, new Date(), String.valueOf(pushBy), pushByName);
successCount++; successCount++;
} else { } else {
gwLog.setStatus(3); gwLog.setStatus(3);
gwLog.setErrorMsg(responseString); gwLog.setErrorMsg(responseString);
updatePushStatus(pushData.getId(), 4, new Date(), String.valueOf(pushBy), pushByName); updatePushStatus(order.getId(), 4, new Date(), String.valueOf(pushBy), pushByName);
failCount++; failCount++;
failMsg.append("物料编码:").append(pushData.getMaterialCode()).append("失败;"); failMsg.append("订单ID:").append(order.getId()).append("失败;");
} }
} else { } else {
gwLog.setStatus(3); gwLog.setStatus(3);
gwLog.setErrorMsg(responseString); gwLog.setErrorMsg(responseString);
if (pushData.getId() != null) { updatePushStatus(order.getId(), 4, new Date(), String.valueOf(pushBy), pushByName);
updatePushStatus(pushData.getId(), 4, new Date(), String.valueOf(pushBy), pushByName);
}
failCount++; failCount++;
failMsg.append("物料编码:").append(pushData.getMaterialCode()).append("失败:"); failMsg.append("订单ID:").append(order.getId()).append("失败:");
} }
gwLogMapper.updateById(gwLog); gwLogMapper.updateById(gwLog);
response.close(); response.close();
@@ -290,12 +291,10 @@ public class BusinessDocumentOrderApplicationService {
gwLog.setErrorMsg(e.getMessage()); gwLog.setErrorMsg(e.getMessage());
gwLog.setResponseBody("请求异常:" + e.getMessage()); gwLog.setResponseBody("请求异常:" + e.getMessage());
gwLogMapper.updateById(gwLog); gwLogMapper.updateById(gwLog);
if (pushData.getId() != null) { updatePushStatus(order.getId(), 4, new Date(), String.valueOf(pushBy), pushByName);
updatePushStatus(pushData.getId(), 4, new Date(), String.valueOf(pushBy), pushByName);
}
failCount++; failCount++;
failMsg.append("物料编码:").append(pushData.getMaterialCode()).append("异常:").append(e.getMessage()); failMsg.append("订单ID:").append(order.getId()).append("异常:").append(e.getMessage());
log.error("GW推送异常:materialCode={} error={}", pushData.getMaterialCode(), e.getMessage()); log.error("GW推送异常:orderId={} error={}", order.getId(), e.getMessage());
} }
} }
@@ -76,11 +76,11 @@ public class OriginalImportExportDocumentApi extends BaseController {
@ApiOperation("批量推送") @ApiOperation("批量推送")
@PostMapping("/batchPush") @PostMapping("/batchPush")
public AjaxResult batchPush(@RequestBody List<BusinessDocumentOrderDTO> businessDocumentOrderDTOList){ public AjaxResult batchPush(@RequestBody List<Long> idList){
if(businessDocumentOrderDTOList.isEmpty() || businessDocumentOrderDTOList == null){ if(idList == null || idList.isEmpty()){
return AjaxResult.error("没有数据需要推送"); return AjaxResult.error("没有数据需要推送");
} }
return businessDocumentOrderApplicationService.batchPushForOriginalImportExportDocument(businessDocumentOrderDTOList); return businessDocumentOrderApplicationService.batchPushForOriginalImportExportDocument(idList);
} }