diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/associationWarehouse/repository/persistence/AssociationWarehouseImpl.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/associationWarehouse/repository/persistence/AssociationWarehouseImpl.java index dc3fc8eb6..5860b8df2 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/associationWarehouse/repository/persistence/AssociationWarehouseImpl.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/associationWarehouse/repository/persistence/AssociationWarehouseImpl.java @@ -107,7 +107,31 @@ public class AssociationWarehouseImpl extends ServiceImpl().lambda() + .eq(AssociationWarehouse::getWarehouseId, associationWarehouseDO.getWarehouseId()) + .eq(AssociationWarehouse::getDelFlag, 1) + .and(w -> w.isNull(AssociationWarehouse::getIsDefault) + .or() + .ne(AssociationWarehouse::getIsDefault, 2))); + List stillBoundRows = associationWarehouseMapper.selectList(new QueryWrapper().lambda() + .eq(AssociationWarehouse::getWarehouseId, associationWarehouseDO.getWarehouseId()) + .eq(AssociationWarehouse::getDelFlag, 1)); + Set alreadyBoundCorrelationIds = stillBoundRows.stream() + .map(AssociationWarehouse::getCorrelationId) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + LinkedHashSet distinctCorrelationIds = CollectionUtils.isEmpty(associationWarehouseDO.getCorrelationIdList()) + ? new LinkedHashSet<>() + : new LinkedHashSet<>(associationWarehouseDO.getCorrelationIdList()); + for (Long correlationId : distinctCorrelationIds) { + if (correlationId == null) { + continue; + } + // 仍在库内的绑定(多为创建人默认仓 is_default=2)不再插入,否则撞唯一 IDX_ASS_COR_WAR_ID + if (alreadyBoundCorrelationIds.contains(correlationId)) { + continue; + } AssociationWarehouse associationWarehouse = new AssociationWarehouse(); associationWarehouse.setOrganizationId(loginUser.getUserPo().getOrganizationId()); associationWarehouse.setOrganizationName(loginUser.getUserPo().getOrganizationName()); @@ -121,13 +145,6 @@ public class AssociationWarehouseImpl extends ServiceImpl().lambda() - .eq(AssociationWarehouse::getWarehouseId, associationWarehouseDO.getWarehouseId()) - .eq(AssociationWarehouse::getDelFlag, 1) - .and(w -> w.isNull(AssociationWarehouse::getIsDefault) - .or() - .ne(AssociationWarehouse::getIsDefault, 2))); } return saveBatch(associationWarehouseList); }