From e3f738988faf7da5a50685d2e5b4cd7e23eb7c8c Mon Sep 17 00:00:00 2001 From: ljl <17743125563@163.com> Date: Wed, 24 Jan 2024 16:42:02 +0800 Subject: [PATCH] iam: fix account set_ids_and_cate_codes. --- basic/src/rbum/dto/rbum_filer_dto.rs | 2 +- basic/src/rbum/serv/rbum_item_serv.rs | 17 ++++++++++++++--- .../console_interface/api/iam_ci_account_api.rs | 9 ++++++++- .../console_system/api/iam_cs_account_api.rs | 9 ++++++++- .../console_tenant/api/iam_ct_account_api.rs | 9 ++++++++- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/basic/src/rbum/dto/rbum_filer_dto.rs b/basic/src/rbum/dto/rbum_filer_dto.rs index 6ac69b96e..0d9feb7c0 100644 --- a/basic/src/rbum/dto/rbum_filer_dto.rs +++ b/basic/src/rbum/dto/rbum_filer_dto.rs @@ -190,7 +190,7 @@ pub trait RbumItemFilterFetcher { #[serde(default)] pub struct RbumSetItemRelFilterReq { //同时根据set_id cate_code 二元组限制 - pub set_ids_and_cate_codes: Option>, + pub set_ids_and_cate_codes: Option>>, pub with_sub_set_cate_codes: bool, pub rel_item_ids: Option>, } diff --git a/basic/src/rbum/serv/rbum_item_serv.rs b/basic/src/rbum/serv/rbum_item_serv.rs index db021881b..a8c2ce263 100644 --- a/basic/src/rbum/serv/rbum_item_serv.rs +++ b/basic/src/rbum/serv/rbum_item_serv.rs @@ -595,10 +595,21 @@ where if let Some(set_ids_and_cate_codes) = rbum_set_rel_filter_req.set_ids_and_cate_codes.clone() { let mut condition = Condition::any(); for set_id in set_ids_and_cate_codes.keys() { - let expr = Expr::col((rbum_set_item::Entity, rbum_set_item::Column::RelRbumSetId)).eq(set_id.to_string()).and(if rbum_set_rel_filter_req.with_sub_set_cate_codes { - Expr::col((rbum_set_item::Entity, rbum_set_item::Column::RelRbumSetCateCode)).like(format!("{}%", set_ids_and_cate_codes.get(set_id).unwrap())) + let expr = Expr::col((rbum_set_item::Entity, rbum_set_item::Column::RelRbumSetId)).eq(set_id).and(if rbum_set_rel_filter_req.with_sub_set_cate_codes { + if let Some(cate_code) = set_ids_and_cate_codes.get(set_id) { + let like_clauses: Vec<_> = cate_code + .iter() + .map(|cate_code| Expr::col((rbum_set_item::Entity, rbum_set_item::Column::RelRbumSetCateCode)).like(format!("{}%", cate_code))) + .collect(); + // Join LIKE clauses with OR + like_clauses.into_iter().fold(Expr::col((rbum_set_item::Entity, rbum_set_item::Column::RelRbumSetCateCode)).into(), |acc, exprx| { + acc.or(exprx) + }) + } else { + Expr::col((rbum_set_item::Entity, rbum_set_item::Column::RelRbumSetCateCode)).like(format!("{}%", "")) + } } else { - Expr::col((rbum_set_item::Entity, rbum_set_item::Column::RelRbumSetCateCode)).eq(set_ids_and_cate_codes.get(set_id).unwrap().to_string()) + Expr::col((rbum_set_item::Entity, rbum_set_item::Column::RelRbumSetCateCode)).is_in(set_ids_and_cate_codes.get(set_id).unwrap_or(&Vec::::new())) }); condition = condition.add(expr); } diff --git a/support/iam/src/console_interface/api/iam_ci_account_api.rs b/support/iam/src/console_interface/api/iam_ci_account_api.rs index 419a0a02c..a3b9485fb 100644 --- a/support/iam/src/console_interface/api/iam_ci_account_api.rs +++ b/support/iam/src/console_interface/api/iam_ci_account_api.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use bios_basic::rbum::dto::rbum_filer_dto::{RbumBasicFilterReq, RbumCertFilterReq, RbumItemRelFilterReq, RbumSetCateFilterReq, RbumSetItemFilterReq, RbumSetItemRelFilterReq}; use bios_basic::rbum::dto::rbum_set_item_dto::RbumSetItemDetailResp; use bios_basic::rbum::rbum_enumeration::{RbumRelFromKind, RbumSetCateLevelQueryKind}; @@ -80,7 +82,12 @@ impl IamCiAccountApi { ) .await?; Some(RbumSetItemRelFilterReq { - set_ids_and_cate_codes: Some(set_cate_vec.into_iter().map(|sc| (sc.rel_rbum_set_id, sc.sys_code)).collect()), + set_ids_and_cate_codes: Some( + set_cate_vec.into_iter().map(|sc| (sc.rel_rbum_set_id, sc.sys_code)).fold(HashMap::new(), |mut acc, (key, value)| { + acc.entry(key).or_insert_with(Vec::new).push(value); + acc + }), + ), with_sub_set_cate_codes: false, ..Default::default() }) diff --git a/support/iam/src/console_system/api/iam_cs_account_api.rs b/support/iam/src/console_system/api/iam_cs_account_api.rs index 186b8966e..6bbf657b9 100644 --- a/support/iam/src/console_system/api/iam_cs_account_api.rs +++ b/support/iam/src/console_system/api/iam_cs_account_api.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use bios_basic::process::task_processor::TaskProcessor; use bios_basic::rbum::helper::rbum_event_helper; @@ -143,7 +145,12 @@ impl IamCsAccountApi { ) .await?; Some(RbumSetItemRelFilterReq { - set_ids_and_cate_codes: Some(set_cate_vec.into_iter().map(|sc| (sc.rel_rbum_set_id, sc.sys_code)).collect()), + set_ids_and_cate_codes: Some( + set_cate_vec.into_iter().map(|sc| (sc.rel_rbum_set_id, sc.sys_code)).fold(HashMap::new(), |mut acc, (key, value)| { + acc.entry(key).or_insert_with(Vec::new).push(value); + acc + }), + ), with_sub_set_cate_codes: false, ..Default::default() }) diff --git a/support/iam/src/console_tenant/api/iam_ct_account_api.rs b/support/iam/src/console_tenant/api/iam_ct_account_api.rs index 6f34927ec..f240c77ed 100644 --- a/support/iam/src/console_tenant/api/iam_ct_account_api.rs +++ b/support/iam/src/console_tenant/api/iam_ct_account_api.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use bios_basic::process::task_processor::TaskProcessor; use bios_basic::rbum::dto::rbum_set_item_dto::RbumSetItemDetailResp; use bios_basic::rbum::helper::rbum_event_helper; @@ -156,7 +158,12 @@ impl IamCtAccountApi { ) .await?; Some(RbumSetItemRelFilterReq { - set_ids_and_cate_codes: Some(set_cate_vec.into_iter().map(|sc| (sc.rel_rbum_set_id, sc.sys_code)).collect()), + set_ids_and_cate_codes: Some( + set_cate_vec.into_iter().map(|sc| (sc.rel_rbum_set_id, sc.sys_code)).fold(HashMap::new(), |mut acc, (key, value)| { + acc.entry(key).or_insert_with(Vec::new).push(value); + acc + }), + ), with_sub_set_cate_codes: false, ..Default::default() })