Skip to content

Commit

Permalink
flow: Optimize the performance of flow_model && fix bug (#724)
Browse files Browse the repository at this point in the history
* flow:fix bug (specified role not match)

* flow: Optimize the performance of flow_model && fix bug

* flow:Improve code comments.
  • Loading branch information
ZzIsGod1019 authored May 13, 2024
1 parent 0050768 commit 6602eb0
Show file tree
Hide file tree
Showing 14 changed files with 662 additions and 584 deletions.
1 change: 0 additions & 1 deletion backend/middlewares/event/src/api/event_listener_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct EventListenerApi;
/// 事件监听器API
#[poem_openapi::OpenApi(prefix_path = "/listener")]
impl EventListenerApi {

/// Register event listener
///
/// 注册事件监听器
Expand Down
1 change: 0 additions & 1 deletion backend/middlewares/event/src/api/event_proc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct EventProcApi;
/// 事件处理API
#[poem_openapi::OpenApi(prefix_path = "/proc")]
impl EventProcApi {

/// Process event
///
/// 处理事件
Expand Down
4 changes: 2 additions & 2 deletions backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ impl FlowCcInstApi {
TardisResp::ok(result)
}

/// Modify Assigned[Deprecated]
/// 同步执行人信息[已废弃]
/// Modify Assigned [Deprecated]
/// 同步执行人信息 [已废弃]
#[oai(path = "/:flow_inst_id/transition/modify_assigned", method = "post")]
async fn modify_assigned(
&self,
Expand Down
154 changes: 117 additions & 37 deletions backend/middlewares/flow/src/api/cc/flow_cc_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;

use bios_basic::rbum::dto::rbum_filer_dto::RbumBasicFilterReq;
use bios_basic::rbum::serv::rbum_item_serv::RbumItemCrudOperation;
use itertools::Itertools;
use tardis::web::context_extractor::TardisContextExtractor;
use tardis::web::poem::Request;
use tardis::web::poem_openapi;
Expand All @@ -13,18 +14,19 @@ use crate::dto::flow_model_dto::{
FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAddReq, FlowModelAggResp, FlowModelBindStateReq, FlowModelFilterReq, FlowModelFindRelStateResp,
FlowModelModifyReq, FlowModelSortStatesReq, FlowModelSummaryResp, FlowModelUnbindStateReq, FlowTemplateModelResp,
};
use crate::dto::flow_state_dto::FlowStateRelModelExt;
use crate::dto::flow_transition_dto::FlowTransitionSortStatesReq;
use crate::dto::flow_state_dto::FlowStateRelModelModifyReq;
use crate::dto::flow_transition_dto::{FlowTransitionModifyReq, FlowTransitionSortStatesReq};
use crate::flow_constants;
use crate::serv::flow_model_serv::FlowModelServ;
use crate::serv::flow_rel_serv::FlowRelKind;
#[derive(Clone)]
pub struct FlowCcModelApi;

/// Flow model process API
#[poem_openapi::OpenApi(prefix_path = "/cc/model")]
impl FlowCcModelApi {
/// Add Model / 添加模型
/// Add Model
///
/// 添加模型
#[oai(path = "/", method = "post")]
async fn add(&self, mut add_req: Json<FlowModelAddReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<String> {
let mut funs = flow_constants::get_tardis_inst();
Expand All @@ -34,7 +36,9 @@ impl FlowCcModelApi {
TardisResp::ok(result)
}

/// Modify Model By Model Id / 修改模型
/// Modify Model By Model Id
///
/// 修改模型
#[oai(path = "/:flow_model_id", method = "patch")]
async fn modify(&self, flow_model_id: Path<String>, mut modify_req: Json<FlowModelModifyReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
Expand All @@ -44,15 +48,19 @@ impl FlowCcModelApi {
TardisResp::ok(Void {})
}

/// Get Model By Model Id / 获取模型
/// Get Model By Model Id
///
/// 获取模型
#[oai(path = "/:flow_model_id", method = "get")]
async fn get(&self, flow_model_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<FlowModelAggResp> {
let funs = flow_constants::get_tardis_inst();
let result = FlowModelServ::get_item_detail_aggs(&flow_model_id.0, &funs, &ctx.0).await?;
TardisResp::ok(result)
}

/// Find Models / 获取模型列表
/// Find Models
///
/// 获取模型列表
#[oai(path = "/", method = "get")]
#[allow(clippy::too_many_arguments)]
async fn paginate(
Expand Down Expand Up @@ -93,24 +101,34 @@ impl FlowCcModelApi {
TardisResp::ok(result)
}

/// Get Models By Tag And Template Id / 通过Tag和模板Id获取模型
#[oai(path = "/get_models", method = "get")]
async fn get_models(
/// Find the specified models, or add it if it doesn't exist.
///
/// 查找指定model,如果不存在则新增
///
/// # Parameters
/// - `tag_ids` - list of tag_id
/// - `temp_id` - associated template_id
/// - `is_shared` - whether the associated template is shared
#[oai(path = "/find_or_add_models", method = "put")]
async fn find_or_add_models(
&self,
tag_ids: Query<String>,
temp_id: Query<Option<String>>,
is_shared: Query<Option<bool>>,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<HashMap<String, FlowTemplateModelResp>> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let tag_ids: Vec<_> = tag_ids.split(',').collect();
let result = FlowModelServ::get_models(tag_ids, temp_id.0, &funs, &ctx.0).await?;
let result = FlowModelServ::find_or_add_models(tag_ids, temp_id.0, is_shared.unwrap_or(false), &funs, &ctx.0).await?;
funs.commit().await?;
TardisResp::ok(result)
}

/// Delete Model By Model Id / 删除模型
/// Delete Model By Model Id
///
/// 删除模型
///
/// Valid only when model is not used
///
Expand All @@ -124,37 +142,82 @@ impl FlowCcModelApi {
TardisResp::ok(Void {})
}

/// Bind State By Model Id / 绑定状态
/// Bind State By Model Id [Deprecated]
///
/// 绑定状态 [已废弃]
#[oai(path = "/:flow_model_id/bind_state", method = "post")]
async fn bind_state(&self, flow_model_id: Path<String>, req: Json<FlowModelBindStateReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
FlowModelServ::bind_state(&FlowRelKind::FlowModelState, &flow_model_id.0, &req.0, &funs, &ctx.0).await?;
FlowModelServ::modify_model(
&flow_model_id.0,
&mut FlowModelModifyReq {
bind_states: Some(vec![req.0]),
..Default::default()
},
&funs,
&ctx.0,
)
.await?;
funs.commit().await?;
TardisResp::ok(Void {})
}

/// Unbind State By Model Id / 解绑状态
/// Unbind State By Model Id [Deprecated]
///
/// 解绑状态 [已废弃]
#[oai(path = "/:flow_model_id/unbind_state", method = "post")]
async fn unbind_state(&self, flow_model_id: Path<String>, req: Json<FlowModelUnbindStateReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
FlowModelServ::unbind_state(&FlowRelKind::FlowModelState, &flow_model_id.0, &req, &funs, &ctx.0).await?;
FlowModelServ::modify_model(
&flow_model_id.0,
&mut FlowModelModifyReq {
unbind_states: Some(vec![req.state_id.clone()]),
..Default::default()
},
&funs,
&ctx.0,
)
.await?;
funs.commit().await?;
TardisResp::ok(Void {})
}

/// Resort states / 状态重新排序
/// Resort states [Deprecated]
///
/// 状态重新排序 [已废弃]
#[oai(path = "/:flow_model_id/resort_state", method = "post")]
async fn resort_state(&self, flow_model_id: Path<String>, req: Json<FlowModelSortStatesReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
FlowModelServ::resort_state(&FlowRelKind::FlowModelState, &flow_model_id.0, &req.0, &funs, &ctx.0).await?;
FlowModelServ::modify_model(
&flow_model_id.0,
&mut FlowModelModifyReq {
modify_states: Some(
req.0
.sort_states
.into_iter()
.map(|state| FlowStateRelModelModifyReq {
id: state.state_id,
sort: Some(state.sort),
show_btns: None,
})
.collect_vec(),
),
..Default::default()
},
&funs,
&ctx.0,
)
.await?;
funs.commit().await?;
TardisResp::ok(Void {})
}

/// Resort transitions / 动作重新排序
/// Resort transitions [Deprecated]
///
/// 动作重新排序 [已废弃]
#[oai(path = "/:flow_model_id/resort_transition", method = "post")]
async fn resort_transition(
&self,
Expand All @@ -165,27 +228,49 @@ impl FlowCcModelApi {
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
FlowModelServ::resort_transition(&flow_model_id.0, &req.0, &funs, &ctx.0).await?;
let modify_trans = req
.0
.sort_states
.into_iter()
.map(|sort_req| FlowTransitionModifyReq {
id: sort_req.id.clone().into(),
sort: Some(sort_req.sort),
..Default::default()
})
.collect_vec();
FlowModelServ::modify_model(
&flow_model_id.0,
&mut FlowModelModifyReq {
modify_transitions: Some(modify_trans),
..Default::default()
},
&funs,
&ctx.0,
)
.await?;
funs.commit().await?;
TardisResp::ok(Void {})
}

/// add custom model by template_id / 添加自定义模型
/// copy parent model to current own_paths
///
/// 复制父级模型到当前 own_paths
#[oai(path = "/add_custom_model", method = "post")]
async fn add_custom_model(&self, req: Json<FlowModelAddCustomModelReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Vec<FlowModelAddCustomModelResp>> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let proj_template_id = req.0.proj_template_id.unwrap_or_default();
let mut result = vec![];
for item in req.0.bind_model_objs {
let model_id = FlowModelServ::add_custom_model(&item.tag, &proj_template_id, None, &funs, &ctx.0).await.ok();
result.push(FlowModelAddCustomModelResp { tag: item.tag, model_id });
for item in &req.0.bind_model_objs {
let model_id = FlowModelServ::add_custom_model(&item.tag, req.0.proj_template_id.clone(), None, &funs, &ctx.0).await.ok();
result.push(FlowModelAddCustomModelResp { tag: item.tag.clone(), model_id });
}
funs.commit().await?;
TardisResp::ok(result)
}

/// find rel states by model_id / 获取关联状态
/// find rel states by model_id
///
/// 获取关联状态
#[oai(path = "/find_rel_status", method = "get")]
async fn find_rel_states(
&self,
Expand All @@ -200,19 +285,14 @@ impl FlowCcModelApi {
TardisResp::ok(result)
}

/// modify related state / 编辑关联的状态
#[oai(path = "/:flow_model_id/modify_rel_state/:state_id", method = "patch")]
async fn modify_rel_state(
&self,
flow_model_id: Path<String>,
state_id: Path<String>,
req: Json<FlowStateRelModelExt>,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
/// modify related state [Deprecated]
///
/// 编辑关联的状态 [已废弃]
#[oai(path = "/:flow_model_id/modify_rel_state", method = "patch")]
async fn modify_rel_state(&self, flow_model_id: Path<String>, req: Json<FlowStateRelModelModifyReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
FlowModelServ::modify_rel_state(&flow_model_id.0, &state_id.0, &req.0, &funs, &ctx.0).await?;
FlowModelServ::modify_rel_state_ext(&flow_model_id.0, &req.0, &funs, &ctx.0).await?;
funs.commit().await?;
TardisResp::ok(Void {})
}
Expand Down
16 changes: 11 additions & 5 deletions backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub struct FlowCiModelApi;
/// Flow Config process API
#[poem_openapi::OpenApi(prefix_path = "/ci/model")]
impl FlowCiModelApi {
/// Get model detail / 获取模型详情
/// Get model detail
///
/// 获取模型详情
#[oai(path = "/detail", method = "get")]
async fn get_detail(
&self,
Expand Down Expand Up @@ -50,7 +52,9 @@ impl FlowCiModelApi {
TardisResp::ok(result)
}

/// find rel states by model_id / 获取关联状态
/// find rel states by model_id
///
/// 获取关联状态
#[oai(path = "/find_rel_status", method = "get")]
async fn find_rel_states(
&self,
Expand All @@ -66,7 +70,9 @@ impl FlowCiModelApi {
TardisResp::ok(result)
}

/// add custom model by template_id / 添加自定义模型
/// add custom model by template_id
///
/// 添加自定义模型
#[oai(path = "/add_custom_model", method = "post")]
async fn add_custom_model(
&self,
Expand All @@ -77,10 +83,10 @@ impl FlowCiModelApi {
let mut funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
funs.begin().await?;
let proj_template_id = req.0.proj_template_id.unwrap_or_default();
let proj_template_id = req.0.proj_template_id;
let mut result = vec![];
for item in req.0.bind_model_objs {
let model_id = FlowModelServ::add_custom_model(&item.tag, &proj_template_id, None, &funs, &ctx.0).await.ok();
let model_id = FlowModelServ::add_custom_model(&item.tag, proj_template_id.clone(), None, &funs, &ctx.0).await.ok();
result.push(FlowModelAddCustomModelResp { tag: item.tag, model_id });
}
funs.commit().await?;
Expand Down
Loading

0 comments on commit 6602eb0

Please sign in to comment.