From 59805866d2cd459d98d933d60f34f1bed23be676 Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Mon, 19 Jan 2026 16:09:13 +0800 Subject: [PATCH] =?UTF-8?q?2026-01-19=20pda=E7=9A=84=E8=B7=A8=E5=9F=9F?= =?UTF-8?q?=E8=B0=83=E6=8B=A8=E5=8A=9F=E8=83=BD=E8=B0=83=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E5=92=8C=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=AF=B7?= =?UTF-8?q?=E6=B1=82erp=E6=8E=A5=E5=8F=A3=E7=9A=84=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E6=97=B6=E9=95=BF=E8=B0=83=E6=95=B4=E4=B8=BA?= =?UTF-8?q?120s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gaotao/config/RestTemplateConfig.java | 15 +- .../impl/CrossAreaTransferServiceImpl.java | 134 ++++++++++++------ 2 files changed, 104 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/gaotao/config/RestTemplateConfig.java b/src/main/java/com/gaotao/config/RestTemplateConfig.java index ad9aff5..387dcab 100644 --- a/src/main/java/com/gaotao/config/RestTemplateConfig.java +++ b/src/main/java/com/gaotao/config/RestTemplateConfig.java @@ -7,17 +7,24 @@ import org.springframework.web.client.RestTemplate; /** * RestTemplate配置 + * 用于ERP接口调用等HTTP请求 */ @Configuration public class RestTemplateConfig { + /** + * ERP接口调用超时配置 + * - 连接超时:60秒(建立连接的最长等待时间) + * - 读取超时:120秒(等待ERP接口处理响应的最长时间,ERP处理较慢需要更长等待) + */ @Bean public RestTemplate restTemplate() { SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); - // 设置连接超时时间(毫秒) - factory.setConnectTimeout(30000); - // 设置读取超时时间(毫秒) - factory.setReadTimeout(60000); + // 设置连接超时时间(毫秒)- 60秒 + factory.setConnectTimeout(60000); + // 设置读取超时时间(毫秒)- 120秒 + // 用于等待ERP接口处理响应,ERP接口处理较慢,需要较长的等待时间 + factory.setReadTimeout(120000); return new RestTemplate(factory); } diff --git a/src/main/java/com/gaotao/modules/crossAreaTransfer/service/impl/CrossAreaTransferServiceImpl.java b/src/main/java/com/gaotao/modules/crossAreaTransfer/service/impl/CrossAreaTransferServiceImpl.java index 9a55087..ddbce6f 100644 --- a/src/main/java/com/gaotao/modules/crossAreaTransfer/service/impl/CrossAreaTransferServiceImpl.java +++ b/src/main/java/com/gaotao/modules/crossAreaTransfer/service/impl/CrossAreaTransferServiceImpl.java @@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gaotao.modules.crossAreaTransfer.dao.CrossAreaTransferMapper; import com.gaotao.modules.crossAreaTransfer.entity.CrossAreaTransferEntity; import com.gaotao.modules.crossAreaTransfer.service.CrossAreaTransferService; +import com.gaotao.modules.erp.service.ErpInterfaceService; import com.gaotao.modules.inboundNotification.dao.InboundNotificationHeadMapper; +import com.gaotao.modules.schedule.mapper.ProcedureMapper; import com.gaotao.modules.trans.entity.TransDetail; import com.gaotao.modules.trans.entity.TransDetailDto; import com.gaotao.modules.trans.entity.TransDetailSub; @@ -51,6 +53,12 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl getTransferInfo(Map params) { logger.info("获取跨区调拨信息,参数: {}", params); @@ -130,7 +138,8 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl locationInfo = headMapper.validateLocation(targetLocation, site); if (locationInfo == null || locationInfo.isEmpty()) { throw new RuntimeException("该库位不存在,请检查"); @@ -139,55 +148,98 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl> stockInfoList = new ArrayList<>(); - if ("label".equals(transferMode)) { - // 按标签调拨:查询单个标签的库存信息 - Map stockInfo = crossAreaTransferMapper.getStockInfoByLabelCode(scanCode, site, warehouseId); - if (stockInfo != null) { - stockInfoList.add(stockInfo); - } - } else { - // 按库位调拨:查询库位下所有标签的库存信息 - stockInfoList = crossAreaTransferMapper.getStockInfoByLocation(sourceLocation, site, warehouseId); + + // 2. 调用出库存储过程 GetSaveLabelVerification(跨区调拨-出库) + logger.info("开始调用出库存储过程,site: {}, buNo: {}, sourceLocation: {}", site, buNo, sourceLocation); + List outboundParams = new ArrayList<>(); + outboundParams.add(site); // 参数1: site + outboundParams.add(buNo); // 参数2: buNo + outboundParams.add(""); // 参数3: 空字符串 + outboundParams.add(""); // 参数4: 空字符串 + outboundParams.add(""); // 参数5: 空字符串 + outboundParams.add("label".equals(transferMode) ? "标签" : "库位"); // 参数6: 扫描的类型 "标签/库位" + outboundParams.add(sourceLocation); // 参数7: 扫描的标签条码/库位号 + outboundParams.add(targetLocation != null ? targetLocation : ""); // 参数8: 保存时的库位 + outboundParams.add("跨区调拨-出库"); // 参数9: 跨区调拨-出库 + outboundParams.add(operator); // 参数10: 当前登陆人 + + List> outboundResultList = procedureMapper.getProcedureData("GetSaveLabelVerification", outboundParams); + + // 判断出库返回结果 + if (outboundResultList == null || outboundResultList.isEmpty()) { + throw new RuntimeException("跨区调拨出库存储过程调用失败"); } - if (stockInfoList.isEmpty()) { - logger.error("未找到库存信息,源库位: {}", sourceLocation); - return false; + Map outboundResult = outboundResultList.get(0); + String outboundCode = String.valueOf(outboundResult.get("code")); + + if (!"200".equals(outboundCode)) { + String msg = String.valueOf(outboundResult.get("message")); + throw new RuntimeException("跨区调拨出库失败: " + msg); + } + + // 如果出库返回的transNo有值且不为"*",则异步调用ERP接口 + try { + String outboundTransNo = String.valueOf(outboundResult.get("transNo")); + if (outboundTransNo != null && !outboundTransNo.isEmpty() && !"*".equals(outboundTransNo) && !"null".equals(outboundTransNo)) { + String returnSite = String.valueOf(outboundResult.get("Site")); + String returnBuNo = String.valueOf(outboundResult.get("buNo")); + logger.info("跨区调拨出库存储过程执行成功,准备异步调用ERP接口,site={}, buNo={}, transNo={}", + returnSite, returnBuNo, outboundTransNo); + erpInterfaceService.asyncCallErpInterface(returnSite, returnBuNo, outboundTransNo); + } else { + logger.info("跨区调拨出库transNo为空或'*',不调用ERP接口"); + } + } catch (Exception e) { + logger.error("跨区调拨出库异步调用ERP接口触发失败(不影响主流程),错误: {}", e.getMessage(), e); } - // 根据库位获取实际的仓库ID - String targetWarehouseId = (String) locationInfo.get("warehouseId"); + // 3. 调用入库存储过程 GetSaveLabelVerification(跨区调拨-入库) + logger.info("开始调用入库存储过程,site: {}, buNo: {}, targetLocation: {}", site, buNo, targetLocation); + List inboundParams = new ArrayList<>(); + inboundParams.add(site); // 参数1: site + inboundParams.add(buNo); // 参数2: buNo + inboundParams.add(""); // 参数3: 空字符串 + inboundParams.add(""); // 参数4: 空字符串 + inboundParams.add(""); // 参数5: 空字符串 + inboundParams.add("label".equals(transferMode) ? "标签" : "库位"); // 参数6: 扫描的类型 "标签/库位" + inboundParams.add(sourceLocation); // 参数7: 扫描的标签条码/库位号 + inboundParams.add(targetLocation != null ? targetLocation : ""); // 参数8: 保存时的库位(目标库位) + inboundParams.add("跨区调拨-入库"); // 参数9: 跨区调拨-入库 + inboundParams.add(operator); // 参数10: 当前登陆人 + + List> inboundResultList = procedureMapper.getProcedureData("GetSaveLabelVerification", inboundParams); + + // 判断入库返回结果 + if (inboundResultList == null || inboundResultList.isEmpty()) { + throw new RuntimeException("跨区调拨入库存储过程调用失败"); + } - // 3. 更新库存表 - 根据源库位更新到目标库位和仓库 - Map updateParams = new HashMap<>(); - updateParams.put("site", site); - updateParams.put("sourceLocation", sourceLocation); - updateParams.put("targetLocation", targetLocation); - updateParams.put("targetWarehouseId", targetWarehouseId); // 目标仓库ID - updateParams.put("operator", operator); - updateParams.put("updateTime", new Date()); + Map inboundResult = inboundResultList.get(0); + String inboundCode = String.valueOf(inboundResult.get("code")); - int updateCount = 0; - if ("label".equals(transferMode)) { - // 按标签调拨:更新单个标签的库位和仓库 - updateParams.put("labelCode", scanCode); - updateCount = crossAreaTransferMapper.updateStockLocationAndWarehouse(updateParams); - } else { - // 按库位调拨:更新整个库位下所有标签的库位和仓库 - updateCount = crossAreaTransferMapper.batchUpdateStockLocationAndWarehouse(updateParams); + if (!"200".equals(inboundCode)) { + String msg = String.valueOf(inboundResult.get("message")); + throw new RuntimeException("跨区调拨入库失败: " + msg); } - - if (updateCount == 0) { - logger.error("更新库存失败,未找到匹配的库存记录"); - return false; + + // 如果入库返回的transNo有值且不为"*",则异步调用ERP接口 + try { + String inboundTransNo = String.valueOf(inboundResult.get("transNo")); + if (inboundTransNo != null && !inboundTransNo.isEmpty() && !"*".equals(inboundTransNo) && !"null".equals(inboundTransNo)) { + String returnSite = String.valueOf(inboundResult.get("Site")); + String returnBuNo = String.valueOf(inboundResult.get("buNo")); + logger.info("跨区调拨入库存储过程执行成功,准备异步调用ERP接口,site={}, buNo={}, transNo={}", + returnSite, returnBuNo, inboundTransNo); + erpInterfaceService.asyncCallErpInterface(returnSite, returnBuNo, inboundTransNo); + } else { + logger.info("跨区调拨入库transNo为空或'*',不调用ERP接口"); + } + } catch (Exception e) { + logger.error("跨区调拨入库异步调用ERP接口触发失败(不影响主流程),错误: {}", e.getMessage(), e); } - // 5. 生成标签变动事务记录 - generateTransferTransaction(site, sourceLocation, warehouseId, targetLocation, targetWarehouseId, scanCode, transferMode, buNo, stockInfoList); - - logger.info("跨区调拨保存成功,模式: {}, 扫描码: {}, 目标库位: {}", transferMode, scanCode, targetLocation); + logger.info("跨区调拨保存成功,模式: {}, 扫描码: {}, 源库位: {}, 目标库位: {}", transferMode, scanCode, sourceLocation, targetLocation); return true; } catch (Exception e) {