|
|
@ -7,8 +7,10 @@ import com.gaotao.modules.crossAreaTransfer.service.CrossAreaTransferService; |
|
|
import com.gaotao.modules.inboundNotification.dao.InboundNotificationHeadMapper; |
|
|
import com.gaotao.modules.inboundNotification.dao.InboundNotificationHeadMapper; |
|
|
import com.gaotao.modules.trans.entity.TransDetail; |
|
|
import com.gaotao.modules.trans.entity.TransDetail; |
|
|
import com.gaotao.modules.trans.entity.TransDetailDto; |
|
|
import com.gaotao.modules.trans.entity.TransDetailDto; |
|
|
|
|
|
import com.gaotao.modules.trans.entity.TransDetailSub; |
|
|
import com.gaotao.modules.trans.entity.TransHeader; |
|
|
import com.gaotao.modules.trans.entity.TransHeader; |
|
|
import com.gaotao.modules.trans.service.TransDetailService; |
|
|
import com.gaotao.modules.trans.service.TransDetailService; |
|
|
|
|
|
import com.gaotao.modules.trans.service.TransDetailSubService; |
|
|
import com.gaotao.modules.trans.service.TransHeaderService; |
|
|
import com.gaotao.modules.trans.service.TransHeaderService; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -46,6 +48,9 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
@Autowired |
|
|
@Autowired |
|
|
private InboundNotificationHeadMapper headMapper; |
|
|
private InboundNotificationHeadMapper headMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private TransDetailSubService transDetailSubService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Map<String, Object> getTransferInfo(Map<String, Object> params) { |
|
|
public Map<String, Object> getTransferInfo(Map<String, Object> params) { |
|
|
logger.info("获取跨区调拨信息,参数: {}", params); |
|
|
logger.info("获取跨区调拨信息,参数: {}", params); |
|
|
@ -130,12 +135,10 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
if (locationInfo == null || locationInfo.isEmpty()) { |
|
|
if (locationInfo == null || locationInfo.isEmpty()) { |
|
|
throw new RuntimeException("该库位不存在,请检查"); |
|
|
throw new RuntimeException("该库位不存在,请检查"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
String locationStatus = (String) locationInfo.get("status"); |
|
|
String locationStatus = (String) locationInfo.get("status"); |
|
|
if (!"Y".equals(locationStatus)) { |
|
|
if (!"Y".equals(locationStatus)) { |
|
|
throw new RuntimeException("该库位已停用,请检查"); |
|
|
throw new RuntimeException("该库位已停用,请检查"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 2. 根据源库位查询库存信息 |
|
|
// 2. 根据源库位查询库存信息 |
|
|
List<Map<String, Object>> stockInfoList = new ArrayList<>(); |
|
|
List<Map<String, Object>> stockInfoList = new ArrayList<>(); |
|
|
if ("label".equals(transferMode)) { |
|
|
if ("label".equals(transferMode)) { |
|
|
@ -155,18 +158,14 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 根据库位获取实际的仓库ID |
|
|
// 根据库位获取实际的仓库ID |
|
|
String actualWarehouseId = (String) locationInfo.get("warehouseId"); |
|
|
|
|
|
if (actualWarehouseId != null && !actualWarehouseId.trim().isEmpty()) { |
|
|
|
|
|
warehouseId = actualWarehouseId; |
|
|
|
|
|
logger.info("根据库位号 {} 获取到仓库ID: {}", targetLocation, warehouseId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String targetWarehouseId = (String) locationInfo.get("warehouseId"); |
|
|
|
|
|
|
|
|
// 3. 更新库存表 - 根据源库位更新到目标库位和仓库 |
|
|
// 3. 更新库存表 - 根据源库位更新到目标库位和仓库 |
|
|
Map<String, Object> updateParams = new HashMap<>(); |
|
|
Map<String, Object> updateParams = new HashMap<>(); |
|
|
updateParams.put("site", site); |
|
|
updateParams.put("site", site); |
|
|
updateParams.put("sourceLocation", sourceLocation); |
|
|
updateParams.put("sourceLocation", sourceLocation); |
|
|
updateParams.put("targetLocation", targetLocation); |
|
|
updateParams.put("targetLocation", targetLocation); |
|
|
updateParams.put("targetWarehouseId", warehouseId); // 目标仓库ID |
|
|
|
|
|
|
|
|
updateParams.put("targetWarehouseId", targetWarehouseId); // 目标仓库ID |
|
|
updateParams.put("operator", operator); |
|
|
updateParams.put("operator", operator); |
|
|
updateParams.put("updateTime", new Date()); |
|
|
updateParams.put("updateTime", new Date()); |
|
|
|
|
|
|
|
|
@ -186,7 +185,7 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 5. 生成标签变动事务记录 |
|
|
// 5. 生成标签变动事务记录 |
|
|
generateTransferTransaction(site, warehouseId, scanCode, transferMode, buNo, stockInfoList); |
|
|
|
|
|
|
|
|
generateTransferTransaction(site, sourceLocation, warehouseId, targetLocation, targetWarehouseId, scanCode, transferMode, buNo, stockInfoList); |
|
|
|
|
|
|
|
|
logger.info("跨区调拨保存成功,模式: {}, 扫描码: {}, 目标库位: {}", transferMode, scanCode, targetLocation); |
|
|
logger.info("跨区调拨保存成功,模式: {}, 扫描码: {}, 目标库位: {}", transferMode, scanCode, targetLocation); |
|
|
return true; |
|
|
return true; |
|
|
@ -200,7 +199,8 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
/** |
|
|
/** |
|
|
* 生成跨区调拨事务记录 |
|
|
* 生成跨区调拨事务记录 |
|
|
*/ |
|
|
*/ |
|
|
private void generateTransferTransaction(String site, String warehouseId, String scanCode, String transferMode, String buNo, List<Map<String, Object>> stockInfoList) { |
|
|
|
|
|
|
|
|
private void generateTransferTransaction(String site, String sourceLocation, String warehouseId, String targetLocation, String targetWarehouseId, |
|
|
|
|
|
String scanCode, String transferMode, String buNo, List<Map<String, Object>> stockInfoList) { |
|
|
logger.info("开始生成跨区调拨事务记录,扫描码: {}", scanCode); |
|
|
logger.info("开始生成跨区调拨事务记录,扫描码: {}", scanCode); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
@ -209,24 +209,23 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
transDetailDto.setSite(site); |
|
|
transDetailDto.setSite(site); |
|
|
transDetailDto.setRemark("跨区调拨 - " + transferMode); |
|
|
transDetailDto.setRemark("跨区调拨 - " + transferMode); |
|
|
transDetailDto.setOrderref1(scanCode); // 扫描码(标签或库位) |
|
|
transDetailDto.setOrderref1(scanCode); // 扫描码(标签或库位) |
|
|
transDetailDto.setOrderref2(transferMode); // 调拨模式 |
|
|
|
|
|
transDetailDto.setOrderref3(warehouseId); // 仓库ID |
|
|
transDetailDto.setOrderref3(warehouseId); // 仓库ID |
|
|
|
|
|
|
|
|
// 使用TransHeaderService的genTrans方法生成事务头 |
|
|
// 使用TransHeaderService的genTrans方法生成事务头 |
|
|
// CAT = Cross Area Transfer 跨区调拨 |
|
|
// CAT = Cross Area Transfer 跨区调拨 |
|
|
TransHeader transHeader = transHeaderService.genTrans(transDetailDto, "CAT", warehouseId, buNo); |
|
|
TransHeader transHeader = transHeaderService.genTrans(transDetailDto, "CAT", warehouseId, buNo); |
|
|
|
|
|
|
|
|
if (transHeader == null) { |
|
|
if (transHeader == null) { |
|
|
throw new RuntimeException("生成跨区调拨事务头记录失败"); |
|
|
throw new RuntimeException("生成跨区调拨事务头记录失败"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
logger.info("跨区调拨事务头记录生成成功,事务单号: {}", transHeader.getTransno()); |
|
|
logger.info("跨区调拨事务头记录生成成功,事务单号: {}", transHeader.getTransno()); |
|
|
|
|
|
|
|
|
// 生成事务明细记录 |
|
|
// 生成事务明细记录 |
|
|
generateTransactionDetails(transHeader.getTransno(), stockInfoList, site); |
|
|
|
|
|
|
|
|
List<TransDetail> transDetailList = generateTransactionDetails(transHeader.getTransno(), stockInfoList, site, buNo, sourceLocation, warehouseId, targetLocation, targetWarehouseId); |
|
|
|
|
|
logger.info("跨区调拨事务记录生成完成,事务单号: {}, 扫描码: {}, 明细记录数: {}", transHeader.getTransno(), scanCode, stockInfoList.size()); |
|
|
|
|
|
|
|
|
logger.info("跨区调拨事务记录生成完成,事务单号: {}, 扫描码: {}, 明细记录数: {}", |
|
|
|
|
|
transHeader.getTransno(), scanCode, stockInfoList.size()); |
|
|
|
|
|
|
|
|
// 生成事务子明细记录 |
|
|
|
|
|
addSubTransactionDetails(transHeader.getTransno(), stockInfoList, site, buNo, sourceLocation, warehouseId, targetLocation, targetWarehouseId, transDetailList); |
|
|
|
|
|
logger.info("跨区调拨事务子记录生成完成,事务单号: {}", transHeader.getTransno()); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("生成跨区调拨事务记录失败", e); |
|
|
logger.error("生成跨区调拨事务记录失败", e); |
|
|
@ -237,37 +236,54 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
/** |
|
|
/** |
|
|
* 生成事务明细记录 |
|
|
* 生成事务明细记录 |
|
|
*/ |
|
|
*/ |
|
|
private void generateTransactionDetails(String transNo, List<Map<String, Object>> stockInfoList, String site) { |
|
|
|
|
|
|
|
|
private List<TransDetail> generateTransactionDetails(String transNo, List<Map<String, Object>> stockInfoList, String site, String buNo, |
|
|
|
|
|
String sourceLocation, String warehouseId, String targetLocation, String targetWarehouseId) { |
|
|
logger.info("开始生成跨区调拨事务明细记录,事务单号: {}, 明细数量: {}", transNo, stockInfoList.size()); |
|
|
logger.info("开始生成跨区调拨事务明细记录,事务单号: {}, 明细数量: {}", transNo, stockInfoList.size()); |
|
|
|
|
|
|
|
|
List<TransDetail> transDetailList = new ArrayList<>(); |
|
|
List<TransDetail> transDetailList = new ArrayList<>(); |
|
|
double itemNo = 1.0; // 行号从1开始 |
|
|
|
|
|
|
|
|
|
|
|
for (Map<String, Object> stockInfo : stockInfoList) { |
|
|
|
|
|
String labelCode = (String) stockInfo.get("label_code"); |
|
|
|
|
|
String partNo = (String) stockInfo.get("part_no"); |
|
|
|
|
|
String batchNo = (String) stockInfo.get("batch_no"); |
|
|
|
|
|
Object quantityObj = stockInfo.get("quantity"); |
|
|
|
|
|
|
|
|
|
|
|
// 转换数量 |
|
|
|
|
|
BigDecimal quantity = convertToDecimal(quantityObj); |
|
|
|
|
|
|
|
|
// 统计每个partNo的数量总和 |
|
|
|
|
|
Map<String, BigDecimal> partNoQuantityMap = new HashMap<>(); |
|
|
|
|
|
for (Map<String, Object> label : stockInfoList) { |
|
|
|
|
|
String partNo = (String) label.get("partNo"); |
|
|
|
|
|
Object quantityObj = label.get("quantity"); |
|
|
|
|
|
BigDecimal quantity = BigDecimal.ZERO; |
|
|
|
|
|
if (quantityObj != null) { |
|
|
|
|
|
if (quantityObj instanceof BigDecimal) { |
|
|
|
|
|
quantity = (BigDecimal) quantityObj; |
|
|
|
|
|
} else if (quantityObj instanceof Number) { |
|
|
|
|
|
quantity = new BigDecimal(quantityObj.toString()); |
|
|
|
|
|
} else { |
|
|
|
|
|
quantity = new BigDecimal(quantityObj.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
partNoQuantityMap.put(partNo, partNoQuantityMap.getOrDefault(partNo, BigDecimal.ZERO).add(quantity)); |
|
|
|
|
|
} |
|
|
|
|
|
for (Map.Entry<String, BigDecimal> entry : partNoQuantityMap.entrySet()) { |
|
|
|
|
|
String partNo = entry.getKey(); |
|
|
|
|
|
BigDecimal quantity = entry.getValue(); |
|
|
|
|
|
|
|
|
// 构建事务明细记录 |
|
|
// 构建事务明细记录 |
|
|
TransDetail transDetail = new TransDetail(); |
|
|
TransDetail transDetail = new TransDetail(); |
|
|
transDetail.setSite(site); |
|
|
transDetail.setSite(site); |
|
|
transDetail.setTransno(transNo); |
|
|
transDetail.setTransno(transNo); |
|
|
transDetail.setItemno(itemNo); |
|
|
|
|
|
|
|
|
transDetail.setItemno(1.0); |
|
|
transDetail.setPartno(partNo); |
|
|
transDetail.setPartno(partNo); |
|
|
transDetail.setTransqty(quantity); |
|
|
transDetail.setTransqty(quantity); |
|
|
transDetail.setBatchno(batchNo); |
|
|
|
|
|
transDetail.setDirection("-"); // 调拨方向 |
|
|
transDetail.setDirection("-"); // 调拨方向 |
|
|
transDetail.setOrderref1(labelCode); // 标签条码 |
|
|
|
|
|
transDetail.setOrderref2(partNo); // 物料编码 |
|
|
|
|
|
transDetail.setOrderref3(batchNo); // 批次号 |
|
|
|
|
|
transDetail.setRemark("跨区调拨 - 标签: " + labelCode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transDetail.setOrderref2(buNo); // bu |
|
|
|
|
|
transDetail.setRemark("跨区调拨出库"); |
|
|
transDetailList.add(transDetail); |
|
|
transDetailList.add(transDetail); |
|
|
itemNo += 1.0; // 行号递增 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TransDetail newTransDetail = new TransDetail(); |
|
|
|
|
|
newTransDetail.setSite(site); |
|
|
|
|
|
newTransDetail.setTransno(transNo); |
|
|
|
|
|
newTransDetail.setItemno(2.0); |
|
|
|
|
|
newTransDetail.setPartno(partNo); |
|
|
|
|
|
newTransDetail.setTransqty(quantity); |
|
|
|
|
|
newTransDetail.setDirection("+"); // 调拨方向 |
|
|
|
|
|
newTransDetail.setOrderref2(buNo); // bu |
|
|
|
|
|
newTransDetail.setRemark("跨区调拨入库"); |
|
|
|
|
|
transDetailList.add(newTransDetail); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 批量保存事务明细记录 |
|
|
// 批量保存事务明细记录 |
|
|
@ -278,6 +294,69 @@ public class CrossAreaTransferServiceImpl extends ServiceImpl<CrossAreaTransferM |
|
|
} |
|
|
} |
|
|
logger.info("跨区调拨事务明细记录生成成功,共生成 {} 条明细记录", transDetailList.size()); |
|
|
logger.info("跨区调拨事务明细记录生成成功,共生成 {} 条明细记录", transDetailList.size()); |
|
|
} |
|
|
} |
|
|
|
|
|
return transDetailList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 添加子明细数据 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void addSubTransactionDetails(String transNo, List<Map<String, Object>> stockInfoList, String site, String buNo, |
|
|
|
|
|
String sourceLocation, String warehouseId, String targetLocation, String targetWarehouseId, List<TransDetail> transDetailList) { |
|
|
|
|
|
logger.info("开始添加子明细数据,事务单号: {}", transNo); |
|
|
|
|
|
|
|
|
|
|
|
// 创建 partNo 到 itemNo 的映射 |
|
|
|
|
|
Map<String, Double> partNoToItemNoMap = new HashMap<>(); |
|
|
|
|
|
for (TransDetail detail : transDetailList) { |
|
|
|
|
|
partNoToItemNoMap.put(detail.getPartno(), detail.getItemno()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<TransDetailSub> subDetailList = new ArrayList<>(); |
|
|
|
|
|
for (Map<String, Object> label : stockInfoList) { |
|
|
|
|
|
String partNo = (String) label.get("partNo"); |
|
|
|
|
|
String labelCode = (String) label.get("labelCode"); // subNo |
|
|
|
|
|
String batchNo = (String) label.get("batchNo"); // orderRef3 |
|
|
|
|
|
Object quantityObj = label.get("quantity"); // 标签数量 |
|
|
|
|
|
Double quantity = quantityObj == null ? 0.0 : Double.parseDouble(quantityObj.toString()); |
|
|
|
|
|
// 获取对应的明细 itemNo |
|
|
|
|
|
Double itemNo = partNoToItemNoMap.get(partNo); |
|
|
|
|
|
if (itemNo == null) { |
|
|
|
|
|
logger.warn("未找到物料 {} 对应的明细记录,跳过该标签 {}", partNo, labelCode); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TransDetailSub transDetail = new TransDetailSub(); |
|
|
|
|
|
transDetail.setSite(site); |
|
|
|
|
|
transDetail.setTransNo(transNo); |
|
|
|
|
|
transDetail.setItemNo(itemNo); // 使用明细的 itemNo |
|
|
|
|
|
transDetail.setSubNo(labelCode); |
|
|
|
|
|
transDetail.setSubQty(quantity); |
|
|
|
|
|
transDetail.setDirection("-"); |
|
|
|
|
|
transDetail.setOrderRef2(buNo); |
|
|
|
|
|
transDetail.setOrderRef3(batchNo); |
|
|
|
|
|
transDetail.setOrderRef4(warehouseId); |
|
|
|
|
|
transDetail.setOrderRef5(sourceLocation); |
|
|
|
|
|
subDetailList.add(transDetail); |
|
|
|
|
|
|
|
|
|
|
|
TransDetailSub newSubDetail = new TransDetailSub(); |
|
|
|
|
|
newSubDetail.setSite(site); |
|
|
|
|
|
newSubDetail.setTransNo(transNo); |
|
|
|
|
|
newSubDetail.setItemNo(2.0); |
|
|
|
|
|
newSubDetail.setSubNo(labelCode); |
|
|
|
|
|
newSubDetail.setSubQty(quantity); |
|
|
|
|
|
newSubDetail.setDirection("+"); |
|
|
|
|
|
newSubDetail.setOrderRef2(buNo); |
|
|
|
|
|
newSubDetail.setOrderRef3(batchNo); |
|
|
|
|
|
newSubDetail.setOrderRef4(targetWarehouseId); |
|
|
|
|
|
newSubDetail.setOrderRef5(targetLocation); |
|
|
|
|
|
subDetailList.add(newSubDetail); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 批量保存子明细记录 |
|
|
|
|
|
boolean success = transDetailSubService.saveBatch(subDetailList); |
|
|
|
|
|
if (!success) { |
|
|
|
|
|
throw new RuntimeException("子明细记录保存失败"); |
|
|
|
|
|
} |
|
|
|
|
|
logger.info("子明细记录生成成功,共生成 {} 条子明细记录", subDetailList.size()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|