Commit 7a08149d by yubin

导入修改

parent cfe4cc3c
...@@ -158,6 +158,7 @@ public class InventoryServiceImpl implements IInventoryService ...@@ -158,6 +158,7 @@ public class InventoryServiceImpl implements IInventoryService
for (OutboundOrderItems outboundOrderItem : outboundOrderItems) { for (OutboundOrderItems outboundOrderItem : outboundOrderItems) {
OutboundOrderLog outboundOrderLog = outboundOrderLogMapper.selectOutboundOrderLogById(outboundOrderItem.getId()); OutboundOrderLog outboundOrderLog = outboundOrderLogMapper.selectOutboundOrderLogById(outboundOrderItem.getId());
Inventory inventory =inventoryMapper.selectInventoryById(outboundOrderLog.getInventoryId()); Inventory inventory =inventoryMapper.selectInventoryById(outboundOrderLog.getInventoryId());
String quantity = String.valueOf(inventory.getQuantity()); String quantity = String.valueOf(inventory.getQuantity());
inventory.setQuantity(inventory.getQuantity()-outboundOrderItem.getActualQuantity()); inventory.setQuantity(inventory.getQuantity()-outboundOrderItem.getActualQuantity());
......
...@@ -101,6 +101,10 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -101,6 +101,10 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
outboundOrders.setCreateUserCode(SystemUtils.getUserName()); outboundOrders.setCreateUserCode(SystemUtils.getUserName());
outboundOrders.setId(UUID.randomUUID().toString()); outboundOrders.setId(UUID.randomUUID().toString());
outboundOrders.setIsImport(0L); outboundOrders.setIsImport(0L);
// 默认启用
outboundOrders.setIsUsed(1L);
// Ensure orderType is consistent with orderTypeId to avoid mixed-type exports
outboundOrders.setOrderType(outboundOrders.getOrderTypeId());
int rows = outboundOrdersMapper.insertOutboundOrders(outboundOrders); int rows = outboundOrdersMapper.insertOutboundOrders(outboundOrders);
insertOutboundOrderItems(outboundOrders); insertOutboundOrderItems(outboundOrders);
...@@ -167,7 +171,7 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -167,7 +171,7 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
String updateUser = SystemUtils.getUserName(); String updateUser = SystemUtils.getUserName();
Date updateTime = DateUtils.getNowDate(); Date updateTime = DateUtils.getNowDate();
for (OutboundOrderItems item : outboundOrderItems) { for (OutboundOrderItems item : outboundOrderItems) {
item.setItemStatus(1L); item.setItemStatus(3L);
item.setUpdateBy(updateUser); item.setUpdateBy(updateUser);
item.setUpdateTime(updateTime); item.setUpdateTime(updateTime);
outboundOrderItemsMapper.updateOutboundOrderItems(item); outboundOrderItemsMapper.updateOutboundOrderItems(item);
...@@ -177,7 +181,7 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -177,7 +181,7 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
outboundOrderLogMapper.updateOutboundOrderLog(outboundOrderLog); outboundOrderLogMapper.updateOutboundOrderLog(outboundOrderLog);
} }
outboundOrders.setOrderStatus(1L); outboundOrders.setOrderStatus(2L);
outboundOrders.setUpdateTime(updateTime); outboundOrders.setUpdateTime(updateTime);
outboundOrders.setUpdateUserCode(updateUser); outboundOrders.setUpdateUserCode(updateUser);
outboundOrdersMapper.updateOutboundOrders(outboundOrders); outboundOrdersMapper.updateOutboundOrders(outboundOrders);
...@@ -318,6 +322,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -318,6 +322,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
return deductRecordMap; return deductRecordMap;
} }
// splitToSingleInvIdItems is defined below (keeps single implementation with isUsed set)
private void splitToSingleInvIdItems(List<OutboundOrderItems> oldItems, Map<String, List<Map<String, Object>>> deductRecordMap, String updateUser, Date updateTime) { private void splitToSingleInvIdItems(List<OutboundOrderItems> oldItems, Map<String, List<Map<String, Object>>> deductRecordMap, String updateUser, Date updateTime) {
if (CollectionUtils.isEmpty(oldItems) || CollectionUtils.isEmpty(deductRecordMap)) { if (CollectionUtils.isEmpty(oldItems) || CollectionUtils.isEmpty(deductRecordMap)) {
return; return;
...@@ -379,6 +385,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -379,6 +385,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
BeanUtils.copyProperties(item, log); BeanUtils.copyProperties(item, log);
log.setOrderId(item.getOutboundOrderId()); log.setOrderId(item.getOutboundOrderId());
log.setItemStatus(1L); log.setItemStatus(1L);
// 默认启用
log.setIsUsed(1L);
return log; return log;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
outboundOrderLogMapper.batchOutboundOrderLog(logList); outboundOrderLogMapper.batchOutboundOrderLog(logList);
...@@ -630,6 +638,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -630,6 +638,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
items.setOutboundOrderId(id); items.setOutboundOrderId(id);
items.setOrderId(outboundOrders.getOrderId()); items.setOrderId(outboundOrders.getOrderId());
items.setId(UUID.randomUUID().toString().replace("-", "")); items.setId(UUID.randomUUID().toString().replace("-", ""));
// 默认启用
items.setIsUsed(1L);
} }
// 批量插入出库单明细 // 批量插入出库单明细
...@@ -642,6 +652,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -642,6 +652,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
OutboundOrderLog log = new OutboundOrderLog(); OutboundOrderLog log = new OutboundOrderLog();
BeanUtils.copyProperties(items, log); BeanUtils.copyProperties(items, log);
log.setOrderId(items.getOutboundOrderId()); log.setOrderId(items.getOutboundOrderId());
// 默认启用
log.setIsUsed(1L);
outboundOrderLogs.add(log); outboundOrderLogs.add(log);
// 仅拆分实际被扣减的库存ID // 仅拆分实际被扣减的库存ID
if (StringUtils.isNotBlank(items.getInventoryId())) { if (StringUtils.isNotBlank(items.getInventoryId())) {
...@@ -722,27 +734,33 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -722,27 +734,33 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
Map<String, String> ownerNameToIdMap = loadOwnerNameToIdMap(); Map<String, String> ownerNameToIdMap = loadOwnerNameToIdMap();
Map<String, List<Inventory>> inventoryGroupMap = loadInventoryGroupMap(); Map<String, List<Inventory>> inventoryGroupMap = loadInventoryGroupMap();
// 4. 按入库单号分组 // 4. 按入库单号 + 订单类型 分组(复合键),保证不同类型即使 orderId 相同也会生成不同主单
Map<String, List<OutboundTemplateVO>> orderGroupMap = inboundOrdersList.stream() Map<String, List<OutboundTemplateVO>> orderGroupMap = inboundOrdersList.stream()
.filter(vo -> StringUtils.isNotBlank(vo.getOrderId())) .filter(vo -> StringUtils.isNotBlank(vo.getOrderId()))
.collect(Collectors.groupingBy(OutboundTemplateVO::getOrderId)); .collect(Collectors.groupingBy(vo -> {
String typePart = StringUtils.isNotBlank(vo.getOrderTypeId()) ? vo.getOrderTypeId().trim() : String.valueOf(orderType);
return vo.getOrderId().trim() + "_" + typePart;
}));
// 5. 数据验证(仅新增逻辑) // 5. 数据验证(仅新增逻辑)
for (Map.Entry<String, List<OutboundTemplateVO>> entry : orderGroupMap.entrySet()) { for (Map.Entry<String, List<OutboundTemplateVO>> entry : orderGroupMap.entrySet()) {
String orderId = entry.getKey(); String compositeKey = entry.getKey(); // orderId_orderType
List<OutboundTemplateVO> voList = entry.getValue(); List<OutboundTemplateVO> voList = entry.getValue();
OutboundOrders mainDO = null; OutboundOrders mainDO = null;
List<OutboundOrderItems> itemDOList = new ArrayList<>(); List<OutboundOrderItems> itemDOList = new ArrayList<>();
try { try {
OutboundTemplateVO firstVO = voList.get(0); OutboundTemplateVO firstVO = voList.get(0);
// 检查出库单是否已存在 String orderId = firstVO.getOrderId() != null ? firstVO.getOrderId().trim() : "";
String typeKey = StringUtils.isNotBlank(firstVO.getOrderTypeId()) ? firstVO.getOrderTypeId().trim() : String.valueOf(orderType);
// 检查出库单是否已存在(按 orderId + orderType 判重)
OutboundOrders outboundOrdersQuery = new OutboundOrders(); OutboundOrders outboundOrdersQuery = new OutboundOrders();
outboundOrdersQuery.setOrderId(orderId); outboundOrdersQuery.setOrderId(orderId);
outboundOrdersQuery.setOrderTypeId(typeKey);
List<OutboundOrders> existMains = outboundOrdersMapper.selectOutboundOrdersList(outboundOrdersQuery); List<OutboundOrders> existMains = outboundOrdersMapper.selectOutboundOrdersList(outboundOrdersQuery);
if (existMains != null && !existMains.isEmpty()) { if (existMains != null && !existMains.isEmpty()) {
throw new ServiceException(String.format("入库单号【%s】已存在,当前系统仅支持新增,不支持更新", orderId)); throw new ServiceException(String.format("出库单号【%s】类型【%s】已存在,当前系统仅支持新增,不支持更新", orderId, typeKey));
} }
// 构建新出库单主数据 // 构建新出库单主数据
...@@ -782,13 +800,18 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -782,13 +800,18 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
mainDO.setOrderStatus(1L); mainDO.setOrderStatus(1L);
mainDO.setCreateBy(operId); mainDO.setCreateBy(operId);
mainDO.setCreateTime(now); mainDO.setCreateTime(now);
mainDO.setOrderTypeId(String.valueOf(orderType)); // 使用实际类型(VO 中的 orderTypeId 优先,否则使用导入参数)
String actualOrderType = StringUtils.isNotBlank(firstVO.getOrderTypeId()) ? firstVO.getOrderTypeId().trim() : String.valueOf(orderType);
mainDO.setOrderTypeId(actualOrderType);
mainDO.setOrderType(actualOrderType);
mainDO.setCreateUserCode(operId); mainDO.setCreateUserCode(operId);
mainDO.setUpdateBy(operId); mainDO.setUpdateBy(operId);
mainDO.setUpdateTime(now); mainDO.setUpdateTime(now);
mainDO.setUpdateUserCode(operId); mainDO.setUpdateUserCode(operId);
mainDO.setSortNo(Optional.ofNullable(mainDO.getSortNo()).orElse(0L)); mainDO.setSortNo(Optional.ofNullable(mainDO.getSortNo()).orElse(0L));
mainDO.setIsImport(0L); mainDO.setIsImport(0L);
// 默认启用
mainDO.setIsUsed(1L);
mainDO.setInboundDate(DateUtils.getNowDate()); mainDO.setInboundDate(DateUtils.getNowDate());
// 明细校验 // 明细校验
...@@ -811,6 +834,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -811,6 +834,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
itemDO.setSortNo(0L); itemDO.setSortNo(0L);
itemDO.setItemStatus(1L); itemDO.setItemStatus(1L);
itemDO.setShippedAt(mainDO.getInboundDate()); itemDO.setShippedAt(mainDO.getInboundDate());
// 默认启用
itemDO.setIsUsed(1L);
// 物料SAP校验 // 物料SAP校验
String sapNo = vo.getSapNo() != null ? vo.getSapNo().trim() : ""; String sapNo = vo.getSapNo() != null ? vo.getSapNo().trim() : "";
...@@ -837,7 +862,7 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -837,7 +862,7 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
} }
// 库存类型设置 // 库存类型设置
itemDO.setInventoryType(orderType); itemDO.setInventoryType(Integer.parseInt(actualOrderType));
// 实际出库数量 // 实际出库数量
itemDO.setActualQuantity(Optional.ofNullable(vo.getActualQuantity()).orElse(0L)); itemDO.setActualQuantity(Optional.ofNullable(vo.getActualQuantity()).orElse(0L));
...@@ -846,14 +871,17 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -846,14 +871,17 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
// 合并相同维度明细 // 合并相同维度明细
List<OutboundOrderItems> mergedItemList = mergeSameInventoryItems(itemDOList); List<OutboundOrderItems> mergedItemList = mergeSameInventoryItems(itemDOList);
validMainMap.put(orderId, mainDO); // 使用 compositeKey 存储,保证同 orderId 不同类型不会覆盖
validItemMap.put(orderId, mergedItemList); validMainMap.put(compositeKey, mainDO);
validItemMap.put(compositeKey, mergedItemList);
} catch (Exception e) { } catch (Exception e) {
hasValidateError = true; hasValidateError = true;
totalMainFailure++; totalMainFailure++;
totalItemFailure += voList.size(); totalItemFailure += voList.size();
failureMsg.append(String.format("入库单号【%s】验证失败:%s;\n", orderId, e.getMessage())); // 尽量从 firstVO 中取 orderId 显示错误信息
String errOrderId = (voList != null && !voList.isEmpty() && voList.get(0).getOrderId() != null) ? voList.get(0).getOrderId() : "";
failureMsg.append(String.format("入库单号【%s】验证失败:%s;\n", errOrderId, e.getMessage()));
} }
} }
...@@ -865,14 +893,14 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -865,14 +893,14 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
// 7. 执行新增操作 // 7. 执行新增操作
Map<String, List<OutboundOrderItems>> allItemListMap = new HashMap<>(); Map<String, List<OutboundOrderItems>> allItemListMap = new HashMap<>();
for (Map.Entry<String, OutboundOrders> entry : validMainMap.entrySet()) { for (Map.Entry<String, OutboundOrders> entry : validMainMap.entrySet()) {
String orderId = entry.getKey(); String compositeKey = entry.getKey();
OutboundOrders mainDO = entry.getValue(); OutboundOrders mainDO = entry.getValue();
List<OutboundOrderItems> itemDOList = validItemMap.get(orderId); List<OutboundOrderItems> itemDOList = validItemMap.get(compositeKey);
// 新增主单 // 新增主单
outboundOrdersMapper.insertOutboundOrders(mainDO); outboundOrdersMapper.insertOutboundOrders(mainDO);
totalMainSuccess++; totalMainSuccess++;
successMsg.append(String.format("入库单号【%s】已新增;\n", orderId)); successMsg.append(String.format("出库单号【%s】(类型:%s)已新增;\n", mainDO.getOrderId(), Optional.ofNullable(mainDO.getOrderTypeId()).orElse("")));
// 插入明细 // 插入明细
if (!CollectionUtils.isEmpty(itemDOList)) { if (!CollectionUtils.isEmpty(itemDOList)) {
...@@ -881,12 +909,12 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -881,12 +909,12 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
int itemFail = itemDOList.size() - itemSuccess; int itemFail = itemDOList.size() - itemSuccess;
totalItemFailure += itemFail; totalItemFailure += itemFail;
successMsg.append(String.format("入库单号【%s】成功导入%d条物料明细;\n", orderId, itemSuccess)); successMsg.append(String.format("出库单号【%s】成功导入%d条物料明细;\n", mainDO.getOrderId(), itemSuccess));
if (itemFail > 0) { if (itemFail > 0) {
failureMsg.append(String.format("入库单号【%s】有%d条物料明细导入失败;\n", orderId, itemFail)); failureMsg.append(String.format("出库单号【%s】有%d条物料明细导入失败;\n", mainDO.getOrderId(), itemFail));
} }
allItemListMap.put(orderId, itemDOList); allItemListMap.put(compositeKey, itemDOList);
} }
} }
...@@ -976,6 +1004,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService { ...@@ -976,6 +1004,8 @@ public class OutboundOrdersServiceImpl implements IOutboundOrdersService {
BeanUtils.copyProperties(item, log); BeanUtils.copyProperties(item, log);
log.setOrderId(item.getOutboundOrderId()); log.setOrderId(item.getOutboundOrderId());
log.setItemStatus(1L); log.setItemStatus(1L);
// 默认启用
log.setIsUsed(1L);
return log; return log;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
outboundOrderLogMapper.batchOutboundOrderLog(logList); outboundOrderLogMapper.batchOutboundOrderLog(logList);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论