fix(oms):出库添加货物查询不到商品,库存查询改租户+货主维度并出库列表补货主旁路

1.ReservationMaterialInventoryApplicationService.queryList原对非南光组织用户强制organization_id=用户组织且top=2827,委托方(如仓码2841货主)库存被滤空;改为按一级组织(租户)过滤,委托方自动叠加登录货主shipperId查自己的货,库存数据已核实在库
2.ReserveStockOutOrderApplicationService.queryList/detailsList增加货主直查旁路(与入库queryList对齐),委托方按shipperId查询不被组织过滤拦截
This commit is contained in:
rcx
2026-08-18 18:09:53 +08:00
parent f50a3e690a
commit 72e445ea16
2 changed files with 17 additions and 53 deletions
@@ -55,61 +55,19 @@ public class ReservationMaterialInventoryApplicationService {
public List<ReservationMaterialInventoryPO> queryList(ReservationMaterialInventoryDO materialInventoryDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null){
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginTopOrgId = loginUser.getUserPo().getTopOrganizationId();
Long userOrganizationId = loginUser.getUserPo().getOrganizationId();
Long frontendOrganizationId = materialInventoryDO.getOrganizationId(); // 前端传递的 organizationId
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (userOrganizationId != null && userOrganizationId == 2827L) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
materialInventoryDO.setOrganizationId(frontendOrganizationId);
materialInventoryDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件
} else {
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
materialInventoryDO.setOrganizationId(null);
materialInventoryDO.setTopOrganizationId(null);
}
} else {
// 其他组织:设置organizationId,只查询当前组织的数据
// 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (frontendOrganizationId != null && userOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(userOrganizationId)) {
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
materialInventoryDO.setOrganizationId(userOrganizationId);
}
// 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
} else {
// 前端没有传递 organizationId,使用当前登录用户的组织ID
if (userOrganizationId != null) {
materialInventoryDO.setOrganizationId(userOrganizationId);
}
}
// 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件
// 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId
if (materialInventoryDO.getOrganizationId() == null) {
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1) {
materialInventoryDO.setTopOrganizationId(topOrganizationId);
}
} else {
// 对于非2827组织,必须设置 topOrganizationId=2827
materialInventoryDO.setTopOrganizationId(2827L);
}
boolean isTopOrgUser = userOrganizationId != null && userOrganizationId.equals(loginTopOrgId);
// 出库预约-添加货物:按一级组织(租户)过滤;委托方(货主)叠加货主维度查自己的货
materialInventoryDO.setOrganizationId(null);
if (loginTopOrgId != null && loginTopOrgId != 1) {
materialInventoryDO.setTopOrganizationId(loginTopOrgId);
}
if (!isTopOrgUser && materialInventoryDO.getShipperId() == null) {
materialInventoryDO.setShipperId(loginUser.getUserPo().getUserId());
}
// 前端有传warehouseId则优先使用传参;未传时才使用"用户关联仓库"作为默认值
// if (materialInventoryDO.getWarehouseId() == null) {
// AssociationWarehouseCacheDO associationWarehouseCacheDO =
// SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid());
// if (associationWarehouseCacheDO != null) {
// materialInventoryDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId());
// }
// }
}
return materialInventoryDomainService.queryList(materialInventoryDO);
}
@@ -103,6 +103,9 @@ public class ReserveStockOutOrderApplicationService {
*/
public List<ReserveStockOutOrderPO> queryList(ReserveStockOutOrderDO stockOutOrderDO) {
if (stockOutOrderDO.getShipperId() != null && stockOutOrderDO.getShipperId() != 0L) {
return stockOutOrderDomainService.queryList(stockOutOrderDO);
}
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
@@ -221,6 +224,9 @@ public class ReserveStockOutOrderApplicationService {
public List<ReserveOutMaterialDetailPO> detailsList(ReserveStockOutOrderDO stockOutOrderDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (stockOutOrderDO.getShipperId() != null && stockOutOrderDO.getShipperId() != 0L) {
return stockOutOrderDomainService.detailsList(stockOutOrderDO);
}
if (loginUser != null && loginUser.getUserPo() != null) {
Long userOrganizationId = loginUser.getUserPo().getOrganizationId();