|
|
|
@ -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<CrossAreaTransferM |
|
|
|
@Autowired |
|
|
|
private TransDetailSubService transDetailSubService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ErpInterfaceService erpInterfaceService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ProcedureMapper procedureMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> getTransferInfo(Map<String, Object> params) { |
|
|
|
logger.info("获取跨区调拨信息,参数: {}", params); |
|
|
|
@ -130,7 +138,8 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
|
String buNo = (String) params.get("buNo"); |
|
|
|
String warehouseId = (String) params.get("warehouseId"); |
|
|
|
String operator = (String) params.get("operator"); |
|
|
|
// 1. 验证库位是否存在且可用 |
|
|
|
|
|
|
|
// 1. 验证目标库位是否存在且可用 |
|
|
|
Map<String, Object> locationInfo = headMapper.validateLocation(targetLocation, site); |
|
|
|
if (locationInfo == null || locationInfo.isEmpty()) { |
|
|
|
throw new RuntimeException("该库位不存在,请检查"); |
|
|
|
@ -139,55 +148,98 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
|
if (!"Y".equals(locationStatus)) { |
|
|
|
throw new RuntimeException("该库位已停用,请检查"); |
|
|
|
} |
|
|
|
// 2. 根据源库位查询库存信息 |
|
|
|
List<Map<String, Object>> stockInfoList = new ArrayList<>(); |
|
|
|
if ("label".equals(transferMode)) { |
|
|
|
// 按标签调拨:查询单个标签的库存信息 |
|
|
|
Map<String, Object> stockInfo = crossAreaTransferMapper.getStockInfoByLabelCode(scanCode, site, warehouseId); |
|
|
|
if (stockInfo != null) { |
|
|
|
stockInfoList.add(stockInfo); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 按库位调拨:查询库位下所有标签的库存信息 |
|
|
|
stockInfoList = crossAreaTransferMapper.getStockInfoByLocation(sourceLocation, site, warehouseId); |
|
|
|
} |
|
|
|
|
|
|
|
if (stockInfoList.isEmpty()) { |
|
|
|
logger.error("未找到库存信息,源库位: {}", sourceLocation); |
|
|
|
return false; |
|
|
|
// 2. 调用出库存储过程 GetSaveLabelVerification(跨区调拨-出库) |
|
|
|
logger.info("开始调用出库存储过程,site: {}, buNo: {}, sourceLocation: {}", site, buNo, sourceLocation); |
|
|
|
List<Object> 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<Map<String, Object>> outboundResultList = procedureMapper.getProcedureData("GetSaveLabelVerification", outboundParams); |
|
|
|
|
|
|
|
// 判断出库返回结果 |
|
|
|
if (outboundResultList == null || outboundResultList.isEmpty()) { |
|
|
|
throw new RuntimeException("跨区调拨出库存储过程调用失败"); |
|
|
|
} |
|
|
|
|
|
|
|
// 根据库位获取实际的仓库ID |
|
|
|
String targetWarehouseId = (String) locationInfo.get("warehouseId"); |
|
|
|
Map<String, Object> outboundResult = outboundResultList.get(0); |
|
|
|
String outboundCode = String.valueOf(outboundResult.get("code")); |
|
|
|
|
|
|
|
// 3. 更新库存表 - 根据源库位更新到目标库位和仓库 |
|
|
|
Map<String, Object> 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()); |
|
|
|
if (!"200".equals(outboundCode)) { |
|
|
|
String msg = String.valueOf(outboundResult.get("message")); |
|
|
|
throw new RuntimeException("跨区调拨出库失败: " + msg); |
|
|
|
} |
|
|
|
|
|
|
|
int updateCount = 0; |
|
|
|
if ("label".equals(transferMode)) { |
|
|
|
// 按标签调拨:更新单个标签的库位和仓库 |
|
|
|
updateParams.put("labelCode", scanCode); |
|
|
|
updateCount = crossAreaTransferMapper.updateStockLocationAndWarehouse(updateParams); |
|
|
|
} else { |
|
|
|
// 按库位调拨:更新整个库位下所有标签的库位和仓库 |
|
|
|
updateCount = crossAreaTransferMapper.batchUpdateStockLocationAndWarehouse(updateParams); |
|
|
|
// 如果出库返回的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); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 调用入库存储过程 GetSaveLabelVerification(跨区调拨-入库) |
|
|
|
logger.info("开始调用入库存储过程,site: {}, buNo: {}, targetLocation: {}", site, buNo, targetLocation); |
|
|
|
List<Object> 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<Map<String, Object>> inboundResultList = procedureMapper.getProcedureData("GetSaveLabelVerification", inboundParams); |
|
|
|
|
|
|
|
// 判断入库返回结果 |
|
|
|
if (inboundResultList == null || inboundResultList.isEmpty()) { |
|
|
|
throw new RuntimeException("跨区调拨入库存储过程调用失败"); |
|
|
|
} |
|
|
|
|
|
|
|
if (updateCount == 0) { |
|
|
|
logger.error("更新库存失败,未找到匹配的库存记录"); |
|
|
|
return false; |
|
|
|
Map<String, Object> inboundResult = inboundResultList.get(0); |
|
|
|
String inboundCode = String.valueOf(inboundResult.get("code")); |
|
|
|
|
|
|
|
if (!"200".equals(inboundCode)) { |
|
|
|
String msg = String.valueOf(inboundResult.get("message")); |
|
|
|
throw new RuntimeException("跨区调拨入库失败: " + msg); |
|
|
|
} |
|
|
|
|
|
|
|
// 5. 生成标签变动事务记录 |
|
|
|
generateTransferTransaction(site, sourceLocation, warehouseId, targetLocation, targetWarehouseId, scanCode, transferMode, buNo, stockInfoList); |
|
|
|
// 如果入库返回的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); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("跨区调拨保存成功,模式: {}, 扫描码: {}, 目标库位: {}", transferMode, scanCode, targetLocation); |
|
|
|
logger.info("跨区调拨保存成功,模式: {}, 扫描码: {}, 源库位: {}, 目标库位: {}", transferMode, scanCode, sourceLocation, targetLocation); |
|
|
|
return true; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|