Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ideal-world/bios
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Jul 1, 2024
2 parents d09373c + ce7549a commit b794198
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 217 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ rust_decimal_macros = { version = "1" }
testcontainers-modules = { version = "0.3", features = ["redis"] }
strum = { version = "0.26", features = ["derive"] }
# tardis
# tardis = { version = "0.1.0-rc.15" }
tardis = { version = "0.1.0-rc.16" }
# tardis = { path = "../tardis/tardis" }
tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "9e02713" }
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "4eb5ef9" }

#spacegate

# spacegate-shell = { path = "../spacegate/crates/shell", features = [
Expand Down
33 changes: 25 additions & 8 deletions backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use std::collections::HashMap;

use crate::dto::flow_model_dto::{
FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceCiReq, FlowModelExistRelByTemplateIdsReq,
FlowModelFilterReq, FlowModelFindRelStateResp,
};
use crate::flow_constants;
use crate::serv::flow_model_serv::FlowModelServ;
use crate::serv::flow_rel_serv::{FlowRelKind, FlowRelServ};
use bios_basic::rbum::dto::rbum_filer_dto::RbumBasicFilterReq;
use bios_basic::rbum::helper::rbum_scope_helper::{self, check_without_owner_and_unsafe_fill_ctx};
use bios_basic::rbum::rbum_enumeration::RbumScopeLevelKind;
use bios_basic::rbum::serv::rbum_item_serv::RbumItemCrudOperation;
use itertools::Itertools;
use std::iter::Iterator;
use tardis::basic::dto::TardisContext;
use tardis::web::context_extractor::TardisContextExtractor;
use tardis::web::poem::Request;
use tardis::web::poem_openapi;
use tardis::web::poem_openapi::param::{Path, Query};
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};

use crate::dto::flow_model_dto::{
FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceCiReq, FlowModelFilterReq,
FlowModelFindRelStateResp,
};
use crate::flow_constants;
use crate::serv::flow_model_serv::FlowModelServ;
use crate::serv::flow_rel_serv::{FlowRelKind, FlowRelServ};
#[derive(Clone)]
pub struct FlowCiModelApi;

Expand Down Expand Up @@ -232,4 +232,21 @@ impl FlowCiModelApi {
ctx.0.execute_task().await?;
TardisResp::ok(Void)
}

/// Check if there is an association by template ID, return the associated template ID
///
/// 通过模板ID检查是否存在关联,返回关联的模板ID
#[oai(path = "/exist_rel_by_template_ids", method = "post")]
async fn exist_rel_by_template_ids(&self, req: Json<FlowModelExistRelByTemplateIdsReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Vec<String>> {
let funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
let mut result = vec![];
for rel_template_id in req.0.rel_template_ids {
if !FlowRelServ::find_to_simple_rels(&FlowRelKind::FlowModelTemplate, &rel_template_id, None, None, &funs, &ctx.0).await?.is_empty() {
result.push(rel_template_id.clone());
}
}

TardisResp::ok(result)
}
}
31 changes: 30 additions & 1 deletion backend/middlewares/flow/src/api/ct/flow_ct_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use tardis::web::{
};

use crate::{
dto::flow_model_dto::{FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceReq, FlowModelFilterReq},
dto::flow_model_dto::{
FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceReq, FlowModelExistRelByTemplateIdsReq, FlowModelFilterReq,
FlowModelFindRelNameByTemplateIdsReq,
},
flow_constants,
serv::{
flow_model_serv::FlowModelServ,
Expand Down Expand Up @@ -136,4 +139,30 @@ impl FlowCtModelApi {
ctx.0.execute_task().await?;
TardisResp::ok(Void)
}

/// Get associated model names by template ID, multiple comma separated
///
/// 通过模板ID获取关联的模型名,多个逗号隔开
#[oai(path = "/find_rel_name_by_template_ids", method = "post")]
async fn find_rel_name_by_template_ids(
&self,
req: Json<FlowModelFindRelNameByTemplateIdsReq>,
mut ctx: TardisContextExtractor,
request: &Request,
) -> TardisApiResult<HashMap<String, Vec<String>>> {
let funs = flow_constants::get_tardis_inst();
let mut result = HashMap::new();
for rel_template_id in req.0.rel_template_ids {
result.insert(
rel_template_id.clone(),
FlowRelServ::find_to_simple_rels(&FlowRelKind::FlowModelTemplate, &rel_template_id, None, None, &funs, &ctx.0)
.await?
.into_iter()
.map(|rel| rel.rel_name)
.collect_vec(),
);
}

TardisResp::ok(result)
}
}
16 changes: 15 additions & 1 deletion backend/middlewares/flow/src/dto/flow_model_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct FlowModelModifyReq {
pub name: Option<TrimString>,
#[oai(validator(min_length = "2", max_length = "2000"))]
pub icon: Option<String>,
#[oai(validator(min_length = "2", max_length = "2000"))]
#[oai(validator(max_length = "2000"))]
pub info: Option<String>,
/// 初始化状态ID
pub init_state_id: Option<String>,
Expand Down Expand Up @@ -347,3 +347,17 @@ pub struct FlowModelCopyOrReferenceCiReq {
/// 修改的模板ID
pub op: FlowModelAssociativeOperationKind,
}

/// 检查关联模板请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct FlowModelExistRelByTemplateIdsReq {
/// 关联的模板ID
pub rel_template_ids: Vec<String>,
}

/// 获取关联的模型名请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct FlowModelFindRelNameByTemplateIdsReq {
/// 关联的模板ID
pub rel_template_ids: Vec<String>,
}
5 changes: 2 additions & 3 deletions backend/middlewares/flow/src/flow_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ use bios_basic::rbum::{
use bios_sdk_invoke::invoke_initializer;

use itertools::Itertools;
use serde_json::json;

use tardis::{
basic::{dto::TardisContext, field::TrimString, result::TardisResult},
db::{
reldb_client::TardisActiveModel,
sea_orm::{
ColumnTrait, EntityTrait, QueryFilter,
self,
sea_query::{Expr, Query, Table},
ColumnTrait, EntityTrait, QueryFilter,
},
},
futures::future::join_all,
Expand Down Expand Up @@ -170,7 +169,7 @@ pub async fn merge_state_by_name(funs: &TardisFunsInst, ctx: &TardisContext) ->
None,
false,
true,
Some(json!(rel.rel.ext).to_string()),
Some(rel.rel.ext),
funs,
&mock_ctx,
)
Expand Down
30 changes: 15 additions & 15 deletions backend/middlewares/flow/src/serv/clients/search_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ impl IamSearchClient {
// flow model 全局搜索埋点方法
pub async fn add_or_modify_model_search(model_resp: &FlowModelDetailResp, is_modify: Box<bool>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let model_id = &model_resp.id;

// 数据共享权限处理
let mut visit_tenants = rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &model_resp.own_paths).map(|tenant| vec![tenant]).unwrap_or_default();
let mut visit_apps = rbum_scope_helper::get_path_item(RbumScopeLevelKind::L2.to_int(), &model_resp.own_paths).map(|app| vec![app]).unwrap_or_default();
let mut own_paths = Some(model_resp.own_paths.clone());
if model_resp.scope_level == RbumScopeLevelKind::Root {
visit_apps.push("".to_string());
visit_tenants.push("".to_string());
own_paths = None;
}
let key = model_id.clone();
if *is_modify {
let modify_req = SearchItemModifyReq {
Expand All @@ -85,7 +93,7 @@ impl IamSearchClient {
name: Some(model_resp.name.clone()),
content: Some(model_resp.name.clone()),
owner: Some(model_resp.owner.clone()),
own_paths: Some(model_resp.own_paths.clone()),
own_paths,
create_time: Some(model_resp.create_time),
update_time: Some(model_resp.update_time),
ext: Some(json!({
Expand All @@ -98,12 +106,8 @@ impl IamSearchClient {
ext_override: Some(true),
visit_keys: Some(SearchItemVisitKeysReq {
accounts: None,
apps: Some(vec![
rbum_scope_helper::get_path_item(RbumScopeLevelKind::L2.to_int(), &model_resp.own_paths).unwrap_or_default()
]),
tenants: Some(vec![
rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &model_resp.own_paths).unwrap_or_default()
]),
apps: Some(visit_apps),
tenants: Some(visit_tenants),
roles: None,
groups: None,
}),
Expand Down Expand Up @@ -131,7 +135,7 @@ impl IamSearchClient {
name: Some(model_resp.name.clone()),
content: model_resp.name.clone(),
owner: Some(model_resp.owner.clone()),
own_paths: Some(model_resp.own_paths.clone()),
own_paths,
create_time: Some(model_resp.create_time),
update_time: Some(model_resp.update_time),
ext: Some(json!({
Expand All @@ -143,12 +147,8 @@ impl IamSearchClient {
})),
visit_keys: Some(SearchItemVisitKeysReq {
accounts: None,
apps: Some(vec![
rbum_scope_helper::get_path_item(RbumScopeLevelKind::L2.to_int(), &model_resp.own_paths).unwrap_or_default()
]),
tenants: Some(vec![
rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &model_resp.own_paths).unwrap_or_default()
]),
apps: Some(visit_apps),
tenants: Some(visit_tenants),
roles: None,
groups: None,
}),
Expand Down
6 changes: 2 additions & 4 deletions backend/middlewares/schedule/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ bios-basic = { path = "../../basic", features = ["default"] }
bios-sdk-invoke = { path = "../../../frontend/sdks/invoke", features = [
"spi_log", "spi_kv", "event"
], default-features = false }
[dependencies.tokio-cron-scheduler]
git = "https://github.com/4t145/tokio-cron-scheduler.git"
branch = "time-local"
features = ["cron_local"]
tsuki-scheduler = { version = "0.1.3", features= ["cron", "tokio", "async-scheduler"]}

[dev-dependencies]
tardis = { workspace = true, features = ["test", "ws-client"] }
bios-basic = { path = "../../basic", features = ["default", "test"] }
Expand Down
Loading

0 comments on commit b794198

Please sign in to comment.