Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Sep 19, 2024
2 parents b61ddbb + 99b871d commit 9326b5c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 131 deletions.
1 change: 1 addition & 0 deletions backend/middlewares/flow/src/api/cc/flow_cc_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl FlowCcModelApi {
.await?;
let new_model_id = FlowModelServ::add_item(
&mut FlowModelAddReq {
name: format!("{}-副本", rel_model.name.clone()).into(),
..rel_model.clone().into()
},
&funs,
Expand Down
2 changes: 2 additions & 0 deletions backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ impl FlowCiModelApi {
.map(|rel| rel.rel_id)
.collect_vec(),
),
own_paths: Some("".to_string()),
with_sub_own_paths: true,
..Default::default()
},
..Default::default()
Expand Down
25 changes: 1 addition & 24 deletions backend/middlewares/flow/src/api/ci/flow_ci_state_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ 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 tardis::basic::dto::TardisContext;
use tardis::log;
use tardis::tokio;
use tardis::web::context_extractor::TardisContextExtractor;
use tardis::web::poem::Request;
use tardis::web::poem_openapi;
use tardis::web::poem_openapi::param::Query;
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp};

use crate::dto::flow_state_dto::{FlowStateCountGroupByStateReq, FlowStateCountGroupByStateResp, FlowStateFilterReq, FlowStateKind, FlowStateSummaryResp, FlowSysStateKind};
use crate::flow_constants;
Expand Down Expand Up @@ -106,24 +103,4 @@ impl FlowCiStateApi {
ctx.0.execute_task().await?;
TardisResp::ok(result)
}

///Script: merge global states with the same name
///
/// 脚本:合并相同名称的全局状态
#[oai(path = "/merge_state_by_name", method = "post")]
async fn merge_state_by_name(&self) -> TardisApiResult<Void> {
let funs = flow_constants::get_tardis_inst();
let global_ctx = TardisContext::default();
tokio::spawn(async move {
match FlowStateServ::merge_state_by_name(&funs, &global_ctx).await {
Ok(_) => {
log::trace!("[Flow.Inst] add log success")
}
Err(e) => {
log::warn!("[Flow.Inst] failed to add log:{e}")
}
}
});
TardisResp::ok(Void {})
}
}
5 changes: 2 additions & 3 deletions backend/middlewares/flow/src/api/cs/flow_cs_config_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};

use crate::dto::flow_config_dto::FlowConfigModifyReq;

use crate::dto::flow_inst_dto::FlowInstFilterReq;
use crate::dto::flow_state_dto::FlowStateFilterReq;
use crate::flow_constants;
use crate::serv::flow_config_serv::FlowConfigServ;
Expand Down Expand Up @@ -83,7 +82,7 @@ impl FlowCsConfigApi {
}
for inst in insts {
let state_name = states.get(&inst.current_state_id).cloned().unwrap_or_default();
if let Some(table) = tag_search_map.get(&inst.tag.as_str()) {
if let Some(table) = tag_search_map.get(&inst.tag.as_str()) {
SpiSearchClient::modify_item_and_name(table, &inst.rel_business_obj_id, &SearchItemModifyReq {
kind: None,
title: None,
Expand All @@ -94,7 +93,7 @@ impl FlowCsConfigApi {
create_time: None,
update_time: None,
ext: Some(json!({
"state": state_name,
"status": state_name,
})),
ext_override: None,
visit_keys: None,
Expand Down
104 changes: 3 additions & 101 deletions backend/middlewares/flow/src/serv/flow_state_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@ use bios_basic::rbum::{
rbum_item_dto::{RbumItemKernelAddReq, RbumItemKernelModifyReq},
},
helper::rbum_scope_helper,
rbum_enumeration::RbumScopeLevelKind,
serv::{rbum_item_serv::RbumItemCrudOperation, rbum_kind_serv::RbumKindServ, rbum_rel_serv::RbumRelServ},
rbum_enumeration::RbumScopeLevelKind, serv::rbum_item_serv::RbumItemCrudOperation,
};
use itertools::Itertools;
use tardis::{
basic::{dto::TardisContext, field::TrimString, result::TardisResult},
db::sea_orm::{
sea_query::{Cond, Expr, SelectStatement},
ColumnTrait, EntityName, EntityTrait, QueryFilter, Set,
EntityName, Set,
},
futures::future::join_all,
serde_json::json,
TardisFuns, TardisFunsInst,
};

use crate::{
domain::{flow_inst, flow_model, flow_state, flow_transition},
domain::flow_state,
dto::flow_state_dto::{
FlowStateAddReq, FlowStateCountGroupByStateReq, FlowStateCountGroupByStateResp, FlowStateDetailResp, FlowStateFilterReq, FlowStateKind, FlowStateModifyReq,
FlowStateNameResp, FlowStateSummaryResp, FlowSysStateKind,
},
flow_config::FlowBasicInfoManager,
flow_constants,
};
use async_trait::async_trait;

Expand Down Expand Up @@ -381,99 +378,4 @@ impl FlowStateServ {
}
Ok(result.into_values().collect_vec())
}

pub async fn merge_state_by_name(funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let kind_state_id = RbumKindServ::get_rbum_kind_id_by_code(flow_constants::RBUM_KIND_STATE_CODE, funs)
.await?
.ok_or_else(|| funs.err().not_found("flow", "merge_state_by_name", "not found state kind", ""))?;
let states = Self::find_items(
&FlowStateFilterReq {
basic: RbumBasicFilterReq {
ignore_scope: true,
own_paths: Some("".to_string()),
rel_ctx_owner: true,
rbum_kind_id: Some(kind_state_id),
..Default::default()
},
..Default::default()
},
None,
None,
funs,
ctx,
)
.await?;
let mut exists_states: HashMap<String, FlowStateSummaryResp> = HashMap::new();
for state in states {
if let Some(exists_state) = exists_states.get(&state.name) {
// flow inst
flow_inst::Entity::update_many()
.col_expr(flow_inst::Column::CurrentStateId, Expr::value(exists_state.id.as_str()))
.filter(flow_inst::Column::CurrentStateId.eq(&state.id))
.exec(funs.db().raw_conn())
.await?;
// flow model
flow_model::Entity::update_many()
.col_expr(flow_model::Column::InitStateId, Expr::value(exists_state.id.as_str()))
.filter(flow_model::Column::InitStateId.eq(&state.id))
.exec(funs.db().raw_conn())
.await?;
// flow transition
flow_transition::Entity::update_many()
.col_expr(flow_transition::Column::FromFlowStateId, Expr::value(exists_state.id.as_str()))
.filter(flow_transition::Column::FromFlowStateId.eq(&state.id))
.exec(funs.db().raw_conn())
.await?;
flow_transition::Entity::update_many()
.col_expr(flow_transition::Column::ToFlowStateId, Expr::value(exists_state.id.as_str()))
.filter(flow_transition::Column::ToFlowStateId.eq(&state.id))
.exec(funs.db().raw_conn())
.await?;
// rbum rel
join_all(
RbumRelServ::find_to_rels("FlowModelState", &state.id, None, None, funs, ctx)
.await?
.into_iter()
.map(|rel| async move {
let mock_ctx = TardisContext {
own_paths: rel.rel.own_paths,
..Default::default()
};
FlowRelServ::add_simple_rel(
&FlowRelKind::FlowModelState,
&rel.rel.from_rbum_id,
&exists_state.id,
None,
None,
true,
true,
Some(rel.rel.ext),
funs,
&mock_ctx,
)
.await
.unwrap();
FlowRelServ::delete_simple_rel(&FlowRelKind::FlowModelState, &rel.rel.from_rbum_id, &rel.rel.to_rbum_item_id, funs, &mock_ctx).await.unwrap();
})
.collect::<Vec<_>>(),
)
.await;
// flow state
Self::modify_item(
&exists_state.id,
&mut FlowStateModifyReq {
tags: Some(vec![]),
..Default::default()
},
funs,
ctx,
)
.await?;
Self::delete_item(&state.id, funs, ctx).await?;
} else {
exists_states.insert(state.name.clone(), state);
}
}
Ok(())
}
}
9 changes: 7 additions & 2 deletions backend/middlewares/flow/tests/test_flow_scenes_fsm1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,17 @@ pub async fn test(flow_client: &mut TestHttpClient, search_client: &mut TestHttp
}).await;
assert_eq!(model_templates.total_size, 1);
assert_eq!(model_templates.records[0].key, req_default_model_template_id);
// check bind model
// project template bind flow model
ctx.owner = "u001".to_string();
ctx.own_paths = "t2".to_string();
ctx.own_paths = "t1".to_string();
flow_client.set_auth(&ctx)?;
search_client.set_auth(&ctx)?;
//
let req_models: Vec<FlowModelSummaryResp> = flow_client.get(&format!("/cc/model/find_by_rel_template_id?tag=REQ&template=true&rel_template_id={}", req_template_id1)).await;
assert_eq!(req_models.len(), 3);
assert!(req_models.iter().any(|mdoel| mdoel.id == req_default_model_template_id));
assert!(req_models.iter().any(|mdoel| mdoel.id == req_model_template_id));
assert!(req_models.iter().all(|mdoel| mdoel.id != req_model_uninit_template_id));

Ok(())
}
2 changes: 1 addition & 1 deletion frontend/sdks/invoke/src/clients/spi_search_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::dto::search_item_dto::{SearchEventItemDeleteReq, SearchEventItemModif
use crate::invoke_enumeration::InvokeModuleKind;

use super::base_spi_client::BaseSpiClient;
use super::event_client::{mq_node, ContextEvent, EventAttributeExt, EventCenterClient};
use super::event_client::{EventAttributeExt, EventCenterClient};
use super::spi_kv_client::{KvItemAddOrModifyReq, KvItemDeleteReq, SpiKvClient};

pub struct SpiSearchClient;
Expand Down

0 comments on commit 9326b5c

Please sign in to comment.