Skip to content

Commit

Permalink
iam: fix account set_ids_and_cate_codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Jan 24, 2024
1 parent 7b225d4 commit e3f7389
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion basic/src/rbum/dto/rbum_filer_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub trait RbumItemFilterFetcher {
#[serde(default)]
pub struct RbumSetItemRelFilterReq {
//同时根据set_id cate_code 二元组限制
pub set_ids_and_cate_codes: Option<HashMap<String, String>>,
pub set_ids_and_cate_codes: Option<HashMap<String, Vec<String>>>,
pub with_sub_set_cate_codes: bool,
pub rel_item_ids: Option<Vec<String>>,
}
Expand Down
17 changes: 14 additions & 3 deletions basic/src/rbum/serv/rbum_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>::new()))
});
condition = condition.add(expr);
}
Expand Down
9 changes: 8 additions & 1 deletion support/iam/src/console_interface/api/iam_ci_account_api.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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()
})
Expand Down
9 changes: 8 additions & 1 deletion support/iam/src/console_system/api/iam_cs_account_api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use bios_basic::process::task_processor::TaskProcessor;
use bios_basic::rbum::helper::rbum_event_helper;

Expand Down Expand Up @@ -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()
})
Expand Down
9 changes: 8 additions & 1 deletion support/iam/src/console_tenant/api/iam_ct_account_api.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
})
Expand Down

0 comments on commit e3f7389

Please sign in to comment.