仓库绑定更改

This commit is contained in:
秦鸿展
2026-05-11 09:00:48 +08:00
parent 424621143d
commit 11a0b15d19
@@ -107,7 +107,31 @@ public class AssociationWarehouseImpl extends ServiceImpl<AssociationWarehouseMa
associationWarehouseDO.setWarehouseId(associationWarehouseDO.getWarehouseIdIdList().get(0)); associationWarehouseDO.setWarehouseId(associationWarehouseDO.getWarehouseIdIdList().get(0));
//设置仓库信息 //设置仓库信息
warehouseParam(associationWarehouseDO); warehouseParam(associationWarehouseDO);
for (Long correlationId : associationWarehouseDO.getCorrelationIdList()){ // 先删该仓下「非默认仓」绑定,再批量插入本次提交的用户;保留 is_default=2(如新建仓自动写入的创建人默认仓),避免前端列表不展示该条却全量保存时被误删
remove(new QueryWrapper<AssociationWarehouse>().lambda()
.eq(AssociationWarehouse::getWarehouseId, associationWarehouseDO.getWarehouseId())
.eq(AssociationWarehouse::getDelFlag, 1)
.and(w -> w.isNull(AssociationWarehouse::getIsDefault)
.or()
.ne(AssociationWarehouse::getIsDefault, 2)));
List<AssociationWarehouse> stillBoundRows = associationWarehouseMapper.selectList(new QueryWrapper<AssociationWarehouse>().lambda()
.eq(AssociationWarehouse::getWarehouseId, associationWarehouseDO.getWarehouseId())
.eq(AssociationWarehouse::getDelFlag, 1));
Set<Long> alreadyBoundCorrelationIds = stillBoundRows.stream()
.map(AssociationWarehouse::getCorrelationId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
LinkedHashSet<Long> 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 associationWarehouse = new AssociationWarehouse();
associationWarehouse.setOrganizationId(loginUser.getUserPo().getOrganizationId()); associationWarehouse.setOrganizationId(loginUser.getUserPo().getOrganizationId());
associationWarehouse.setOrganizationName(loginUser.getUserPo().getOrganizationName()); associationWarehouse.setOrganizationName(loginUser.getUserPo().getOrganizationName());
@@ -121,13 +145,6 @@ public class AssociationWarehouseImpl extends ServiceImpl<AssociationWarehouseMa
associationWarehouse.setCreateTime(new Date()); associationWarehouse.setCreateTime(new Date());
associationWarehouseList.add(associationWarehouse); associationWarehouseList.add(associationWarehouse);
} }
// 先删该仓下「非默认仓」绑定,再批量插入本次提交的用户;保留 is_default=2(如新建仓自动写入的创建人默认仓),避免前端列表不展示该条却全量保存时被误删
remove(new QueryWrapper<AssociationWarehouse>().lambda()
.eq(AssociationWarehouse::getWarehouseId, associationWarehouseDO.getWarehouseId())
.eq(AssociationWarehouse::getDelFlag, 1)
.and(w -> w.isNull(AssociationWarehouse::getIsDefault)
.or()
.ne(AssociationWarehouse::getIsDefault, 2)));
} }
return saveBatch(associationWarehouseList); return saveBatch(associationWarehouseList);
} }