出口订单推送-数据推送修改 出口仓单推送

This commit is contained in:
zhaoqing
2026-05-28 18:29:11 +08:00
parent 01c7e3f9b5
commit 1e61760d45
3 changed files with 289 additions and 50 deletions
@@ -1089,67 +1089,130 @@ public class ReservationStockOutOrderApplicationService {
int failCount = 0;
StringBuilder failMsg = new StringBuilder();
for (Long id : idList) {
GwStockOutOrder gwStockOutOrder = new GwStockOutOrder();
// 查询出库单
ReservationStockOutOrder reservationStockOutOrder = reservationStockOutOrderMapper.selectById(id);
if (reservationStockOutOrder == null) {
failCount++;
failMsg.append("id:").append(id).append("不存在;");
continue;
}
// 获取货主NC编码
Long shipperId = reservationStockOutOrder.getShipperId();
String userNcCode = reservationStockInOrderMapper.getUserNcCode(shipperId);
gwStockOutOrder.setBill_no(reservationStockOutOrder.getOutOrderNumber());
gwStockOutOrder.setBill_date(reservationStockOutOrder.getDocumentDate());
gwStockOutOrder.setIe_flag("E");
gwStockOutOrder.setCorp_code(userNcCode);
// 构建主单Map
Map<String, Object> order = new HashMap<>();
order.put("billNo", reservationStockOutOrder.getOutOrderNumber());
order.put("ieFlag", "E");
order.put("billDate", reservationStockOutOrder.getDocumentDate());
order.put("corpCode", userNcCode != null ? userNcCode : "");
List<ReservationOutMaterialDetail> reservationOutMaterialDetails = reservationOutMaterialDetailMapper.selectList(new LambdaQueryWrapper<ReservationOutMaterialDetail>().eq(ReservationOutMaterialDetail::getOutOrderNumber, reservationStockOutOrder.getOutOrderNumber()));
Integer lineNum = 1;
List<GwOutDetail> orderList = new LinkedList<>();
for (ReservationOutMaterialDetail reservationOutMaterialDetail : reservationOutMaterialDetails) {
GwOutDetail gwOutDetail = new GwOutDetail();
Long materialBaseInfoId = reservationOutMaterialDetail.getMaterialBaseInfoId();
gwOutDetail.setBill_no(gwStockOutOrder.getBill_no());
gwOutDetail.setLine_num(lineNum);
lineNum++;
gwOutDetail.setItem_no(materialBaseInfoId.toString());
gwOutDetail.setItem_name(reservationOutMaterialDetail.getMaterialName());
MaterialBaseInfoPO materialBaseInfoPO = reservationStockInOrderMapper.getinfo(materialBaseInfoId);
gwOutDetail.setSpec(materialBaseInfoPO.getSpecificationModel());
gwOutDetail.setUnit(materialBaseInfoPO.getDeclarationUnit());
gwOutDetail.setQty(reservationOutMaterialDetail.getQuantity());
gwOutDetail.setErp_curr(materialBaseInfoPO.getCurrency());
gwOutDetail.setErp_price(materialBaseInfoPO.getUnitPrice());
BigDecimal unitPrice = materialBaseInfoPO.getUnitPrice();
BigDecimal quantity = reservationOutMaterialDetail.getQuantity();
if (unitPrice != null && quantity != null && unitPrice.compareTo(BigDecimal.ZERO) != 0&&quantity.compareTo(BigDecimal.ZERO) != 0) {
BigDecimal Amount = unitPrice.multiply(quantity).setScale(2, BigDecimal.ROUND_HALF_UP);
gwOutDetail.setAmount(Amount);
}
orderList.add(gwOutDetail);
// 查询出库物料明细
List<ReservationOutMaterialDetail> reservationOutMaterialDetails =
reservationOutMaterialDetailMapper.selectList(
new LambdaQueryWrapper<ReservationOutMaterialDetail>()
.eq(ReservationOutMaterialDetail::getOutOrderNumber, reservationStockOutOrder.getOutOrderNumber())
);
Long kcId = reservationOutMaterialDetailMapper.getKcId(reservationOutMaterialDetail.getLotNo());
String inOrderNumber = reservationOutMaterialDetailMapper.getInOrderNumber(kcId);
String inLotNo = reservationOutMaterialDetailMapper.getInLotNo(inOrderNumber,materialBaseInfoId);
String warehouse = reservationOutMaterialDetailMapper.getWarehouse(kcId);
String opWhLoc = reservationOutMaterialDetailMapper.getOpWhLoc(kcId);
Integer result = null;
if (inLotNo != null && inLotNo.contains("-")) {
// 截取最后一个 "-" 后面的内容(兼容多 "-" 场景)
String numStr = inLotNo.substring(inLotNo.lastIndexOf("-") + 1);
// 转成 Integer
result = Integer.valueOf(numStr);
}
gwOutDetail.setOrder_i_no(inOrderNumber);
gwOutDetail.setBill_i(inLotNo);
gwOutDetail.setOrder_i_row(result);
gwOutDetail.setBill_i_row(result);
gwOutDetail.setWarehouse(warehouse);
gwOutDetail.setOp_wh_loc(opWhLoc);
if (reservationOutMaterialDetails == null || reservationOutMaterialDetails.isEmpty()) {
failCount++;
failMsg.append("id:").append(id).append("无物料明细;");
continue;
}
gwStockOutOrder.setOrderList(orderList);
// 构建明细List<Map>
List<Map<String, Object>> orderList = new ArrayList<>();
int lineNum = 1;
for (ReservationOutMaterialDetail detail : reservationOutMaterialDetails) {
Map<String, Object> item = new HashMap<>();
item.put("billNo", reservationStockOutOrder.getOutOrderNumber());
item.put("lineNum", lineNum++);
item.put("itemNo", detail.getMaterialBaseInfoId() != null ? detail.getMaterialBaseInfoId().toString() : "");
item.put("itemName", detail.getMaterialName() != null ? detail.getMaterialName() : "");
item.put("spec", detail.getSpecificationModel() != null ? detail.getSpecificationModel() : "");
item.put("unit", detail.getDeclareUnit() != null ? detail.getDeclareUnit() : "");
item.put("qty", detail.getQuantity());
// 获取物料详情
if (detail.getMaterialBaseInfoId() != null) {
MaterialBaseInfoPO materialBaseInfoPO = reservationStockInOrderMapper.getinfo(detail.getMaterialBaseInfoId());
if (materialBaseInfoPO != null) {
item.put("erpCurr", materialBaseInfoPO.getCurrency() != null ? materialBaseInfoPO.getCurrency() : "");
item.put("erpPrice", materialBaseInfoPO.getUnitPrice());
// 计算金额
BigDecimal unitPrice = materialBaseInfoPO.getUnitPrice();
BigDecimal quantity = detail.getQuantity();
if (unitPrice != null && quantity != null && unitPrice.compareTo(BigDecimal.ZERO) != 0 && quantity.compareTo(BigDecimal.ZERO) != 0) {
BigDecimal amount = unitPrice.multiply(quantity).setScale(2, BigDecimal.ROUND_HALF_UP);
item.put("amount", amount);
}
}
}
// 库存关联信息
if (detail.getLotNo() != null) {
Long kcId = reservationOutMaterialDetailMapper.getKcId(detail.getLotNo());
if (kcId != null) {
String inOrderNumber = reservationOutMaterialDetailMapper.getInOrderNumber(kcId);
String inLotNo = inOrderNumber != null ? reservationOutMaterialDetailMapper.getInLotNo(inOrderNumber, detail.getMaterialBaseInfoId()) : null;
String warehouse = reservationOutMaterialDetailMapper.getWarehouse(kcId);
String opWhLoc = reservationOutMaterialDetailMapper.getOpWhLoc(kcId);
item.put("orderINo", inOrderNumber != null ? inOrderNumber : "");
item.put("warehouse", warehouse != null ? warehouse : "");
item.put("opWhLoc", opWhLoc != null ? opWhLoc : "");
item.put("billI", inLotNo != null ? inLotNo : "");
// 处理批次号中的数字
if (inLotNo != null && inLotNo.contains("-")) {
String numStr = inLotNo.substring(inLotNo.lastIndexOf("-") + 1);
try {
Integer result = Integer.valueOf(numStr);
item.put("orderIRow", result);
item.put("billIRow", result);
} catch (NumberFormatException e) {
item.put("orderIRow", null);
item.put("billIRow", null);
}
} else {
item.put("orderIRow", null);
item.put("billIRow", null);
}
} else {
item.put("orderINo", "");
item.put("orderIRow", null);
item.put("warehouse", "");
item.put("opWhLoc", "");
item.put("billI", "");
item.put("billIRow", null);
}
} else {
item.put("orderINo", "");
item.put("orderIRow", null);
item.put("warehouse", "");
item.put("opWhLoc", "");
item.put("billI", "");
item.put("billIRow", null);
}
orderList.add(item);
}
order.put("orderList", orderList);
// 构建推送body
List<Map<String, Object>> bodyList = new ArrayList<>();
bodyList.add(order);
GwLog gwLog = new GwLog();
gwLog.setType("出口订单");
gwLog.setBusinessId(id);
gwLog.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(gwStockOutOrder));
gwLog.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(bodyList));
gwLog.setResponseBody("");
gwLog.setStatus(1);
gwLog.setSendTime(new Date());
@@ -1165,7 +1228,7 @@ public class ReservationStockOutOrderApplicationService {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(PUSH_API_URL);
StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(gwStockOutOrder), "UTF-8");
StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(bodyList), "UTF-8");
httpPost.setEntity(postingString);
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("apiName", API_NAME);