Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flow: improve feature(draft) #860

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
56 changes: 28 additions & 28 deletions backend/middlewares/flow/src/api/ca/flow_ca_model_api.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use std::collections::HashMap;

use bios_basic::rbum::{helper::rbum_scope_helper, rbum_enumeration::RbumScopeLevelKind};
use tardis::{
basic::dto::TardisContext,
web::{
context_extractor::TardisContextExtractor,
poem::{web::Json, Request},
poem_openapi,
web_resp::{TardisApiResult, TardisResp},
},
use tardis::web::{
context_extractor::TardisContextExtractor,
poem::{web::Json, Request},
poem_openapi,
web_resp::{TardisApiResult, TardisResp},
};

use crate::{
dto::flow_model_dto::{FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceReq, FlowModelSingleCopyOrReferenceReq},
dto::flow_model_dto::{FlowModelAggResp, FlowModelCopyOrReferenceReq, FlowModelKind, FlowModelSingleCopyOrReferenceReq},
flow_constants,
serv::{flow_inst_serv::FlowInstServ, flow_model_serv::FlowModelServ},
};
Expand All @@ -37,16 +33,18 @@ impl FlowCaModelApi {
funs.begin().await?;
let _orginal_models = FlowModelServ::clean_rel_models(None, None, None, &funs, &ctx.0).await?;
let mut result = HashMap::new();
let mock_ctx = match req.0.op {
FlowModelAssociativeOperationKind::Copy => ctx.0.clone(),
FlowModelAssociativeOperationKind::Reference => TardisContext {
own_paths: rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &ctx.0.own_paths).unwrap_or_default(),
..ctx.0.clone()
},
};
for (_, rel_model_id) in req.0.rel_model_ids {
let new_model = FlowModelServ::copy_or_reference_model(&rel_model_id, Some(ctx.0.own_paths.clone()), &req.0.op, Some(false), &funs, &mock_ctx).await?;
FlowInstServ::batch_update_when_switch_model(None, &new_model.tag, &new_model.id, new_model.states.clone(), &new_model.init_state_id, &funs, &ctx.0).await?;
let new_model = FlowModelServ::copy_or_reference_model(&rel_model_id, &req.0.op, FlowModelKind::AsModel, &funs, &ctx.0).await?;
FlowInstServ::batch_update_when_switch_model(
None,
&new_model.tag,
&new_model.current_version_id,
new_model.states.clone(),
&new_model.init_state_id,
&funs,
&ctx.0,
)
.await?;

result.insert(rel_model_id.clone(), new_model);
}
Expand All @@ -69,15 +67,17 @@ impl FlowCaModelApi {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let _orginal_models = FlowModelServ::clean_rel_models(None, None, Some(vec![req.0.tag.clone()]), &funs, &ctx.0).await?;
let mock_ctx = match req.0.op {
FlowModelAssociativeOperationKind::Copy => ctx.0.clone(),
FlowModelAssociativeOperationKind::Reference => TardisContext {
own_paths: rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &ctx.0.own_paths).unwrap_or_default(),
..ctx.0.clone()
},
};
let new_model = FlowModelServ::copy_or_reference_model(&req.0.rel_model_id, Some(ctx.0.own_paths.clone()), &req.0.op, Some(false), &funs, &mock_ctx).await?;
FlowInstServ::batch_update_when_switch_model(None, &new_model.tag, &new_model.id, new_model.states.clone(), &new_model.init_state_id, &funs, &ctx.0).await?;
let new_model = FlowModelServ::copy_or_reference_model(&req.0.rel_model_id, &req.0.op, FlowModelKind::AsModel, &funs, &ctx.0).await?;
FlowInstServ::batch_update_when_switch_model(
None,
&new_model.tag,
&new_model.current_version_id,
new_model.states.clone(),
&new_model.init_state_id,
&funs,
&ctx.0,
)
.await?;

funs.commit().await?;
ctx.0.execute_task().await?;
Expand Down
1 change: 1 addition & 0 deletions backend/middlewares/flow/src/api/cc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod flow_cc_inst_api;
pub mod flow_cc_model_api;
pub mod flow_cc_model_version_api;
pub mod flow_cc_state_api;
15 changes: 14 additions & 1 deletion backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl FlowCcInstApi {
async fn paginate(
&self,
flow_model_id: Query<Option<String>>,
rel_business_obj_id: Query<Option<String>>,
tag: Query<Option<String>>,
finish: Query<Option<bool>>,
current_state_id: Query<Option<String>>,
Expand All @@ -76,7 +77,19 @@ impl FlowCcInstApi {
_request: &Request,
) -> TardisApiResult<TardisPage<FlowInstSummaryResp>> {
let funs = flow_constants::get_tardis_inst();
let result = FlowInstServ::paginate(flow_model_id.0, tag.0, finish.0, current_state_id.0, with_sub.0, page_number.0, page_size.0, &funs, &ctx.0).await?;
let result = FlowInstServ::paginate(
flow_model_id.0,
tag.0,
finish.0,
current_state_id.0,
rel_business_obj_id.0,
with_sub.0,
page_number.0,
page_size.0,
&funs,
&ctx.0,
)
.await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}
Expand Down
172 changes: 80 additions & 92 deletions backend/middlewares/flow/src/api/cc/flow_cc_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};

use crate::dto::flow_model_dto::{
FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAddReq, FlowModelAggResp, FlowModelBindStateReq, FlowModelFilterReq, FlowModelFindRelStateResp,
FlowModelModifyReq, FlowModelSortStatesReq, FlowModelSummaryResp, FlowModelUnbindStateReq,
FlowModelAddReq, FlowModelAggResp, FlowModelBindStateReq, FlowModelDetailResp, FlowModelFilterReq, FlowModelFindRelStateResp, FlowModelModifyReq, FlowModelSortStatesReq,
FlowModelSummaryResp, FlowModelUnbindStateReq,
};
use crate::dto::flow_model_version_dto::{FlowModelVersionBindState, FlowModelVersionDetailResp, FlowModelVersionModifyReq, FlowModelVersionModifyState};
use crate::dto::flow_state_dto::FlowStateRelModelModifyReq;
use crate::dto::flow_transition_dto::{FlowTransitionModifyReq, FlowTransitionSortStatesReq};
use crate::dto::flow_transition_dto::{FlowTransitionDetailResp, FlowTransitionSortStatesReq};
use crate::flow_constants;
use crate::serv::flow_model_serv::FlowModelServ;
use crate::serv::flow_rel_serv::{FlowRelKind, FlowRelServ};
Expand Down Expand Up @@ -54,6 +55,17 @@ impl FlowCcModelApi {
TardisResp::ok(Void {})
}

/// GET Editing Model Version By Model Id
///
/// 通过模型ID获取正在编辑的模型版本信息
#[oai(path = "/:flow_model_id/find_editing_verion", method = "get")]
async fn find_editing_verion(&self, flow_model_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<FlowModelVersionDetailResp> {
let funs = flow_constants::get_tardis_inst();
let result = FlowModelServ::find_editing_verion(&flow_model_id.0, &funs, &ctx.0).await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}

/// Copy Model By Model Id
///
/// 复制模型
Expand Down Expand Up @@ -133,16 +145,18 @@ impl FlowCcModelApi {
name: Query<Option<String>>,
tag: Query<Option<String>>,
enabled: Query<Option<bool>>,
rel_template_id: Query<Option<String>>,
main: Query<Option<bool>>,
with_sub: Query<Option<bool>>,
page_number: Query<u32>,
page_size: Query<u32>,
desc_by_create: Query<Option<bool>>,
desc_by_update: Query<Option<bool>>,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<TardisPage<FlowModelSummaryResp>> {
) -> TardisApiResult<TardisPage<FlowModelDetailResp>> {
let funs = flow_constants::get_tardis_inst();
let result = FlowModelServ::paginate_items(
let result = FlowModelServ::paginate_detail_items(
&FlowModelFilterReq {
basic: RbumBasicFilterReq {
ids: flow_model_ids.0.map(|ids| ids.split(',').map(|id| id.to_string()).collect::<Vec<String>>()),
Expand All @@ -151,6 +165,8 @@ impl FlowCcModelApi {
enabled: enabled.0,
..Default::default()
},
main: main.0,
rel_template_id: rel_template_id.0,
tags: tag.0.map(|tag| vec![tag]),
..Default::default()
},
Expand All @@ -166,50 +182,18 @@ impl FlowCcModelApi {
TardisResp::ok(result)
}

/// Find the specified models, or create it if it doesn't exist.
/// Find the specified main models, or create it if it doesn't exist.
///
/// 查找关联的model,如果不存在则创建。创建规则遵循add_custom_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, FlowModelSummaryResp>> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let tag_ids = tag_ids.split(',').map(|tag_id| tag_id.to_string()).collect_vec();
let result = FlowModelServ::find_or_add_models(tag_ids, temp_id.0, is_shared.unwrap_or(false), &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}

/// Find the specified models, or create it if it doesn't exist.
///
/// 查找关联的model。
/// 查找关联的主流程model。
///
/// # Parameters
/// - `temp_id` - associated template_id
/// - `is_shared` - whether the associated template is shared
#[oai(path = "/find_rel_models", method = "put")]
async fn find_rel_models(
&self,
temp_id: Query<Option<String>>,
is_shared: Query<Option<bool>>,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<HashMap<String, FlowModelSummaryResp>> {
async fn find_rel_models(&self, temp_id: Query<Option<String>>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<HashMap<String, FlowModelSummaryResp>> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let result = FlowModelServ::find_rel_models(temp_id.0, is_shared.unwrap_or(false), &funs, &ctx.0).await?;
let result = FlowModelServ::find_rel_model_map(temp_id.0, true, &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
Expand Down Expand Up @@ -242,7 +226,13 @@ impl FlowCcModelApi {
FlowModelServ::modify_model(
&flow_model_id.0,
&mut FlowModelModifyReq {
bind_states: Some(vec![req.0]),
modify_version: Some(FlowModelVersionModifyReq {
bind_states: Some(vec![FlowModelVersionBindState {
exist_state: Some(req.0),
..Default::default()
}]),
..Default::default()
}),
..Default::default()
},
&funs,
Expand All @@ -264,7 +254,10 @@ impl FlowCcModelApi {
FlowModelServ::modify_model(
&flow_model_id.0,
&mut FlowModelModifyReq {
unbind_states: Some(vec![req.state_id.clone()]),
modify_version: Some(FlowModelVersionModifyReq {
unbind_states: Some(vec![req.state_id.clone()]),
..Default::default()
}),
..Default::default()
},
&funs,
Expand All @@ -286,17 +279,27 @@ impl FlowCcModelApi {
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(),
),
modify_version: Some(FlowModelVersionModifyReq {
modify_states: Some(
req.0
.sort_states
.into_iter()
.map(|state| FlowModelVersionModifyState {
id: state.state_id.clone(),
modify_rel: Some(FlowStateRelModelModifyReq {
id: state.state_id,
sort: Some(state.sort),
show_btns: None,
}),
modify_state: None,
add_transitions: None,
modify_transitions: None,
delete_transitions: None,
})
.collect_vec(),
),
..Default::default()
}),
..Default::default()
},
&funs,
Expand All @@ -321,48 +324,13 @@ impl FlowCcModelApi {
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().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.begin().await?;
FlowModelServ::resort_transition(&flow_model_id.0, &req.0, &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}

/// copy parent model to current own_paths
///
/// 复制父级模型到当前 own_paths
/// 实际创建规则:按照 tags 创建模型,若传入proj_template_id,则优先寻找对应的父级模型,否则则获取默认模板模型生成对应的自定义模型。
#[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 mut result = vec![];
for item in &req.0.bind_model_objs {
let model_id = FlowModelServ::add_custom_model(&item.tag, req.0.proj_template_id.clone(), req.0.rel_template_id.clone(), &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
///
/// 获取关联状态
Expand Down Expand Up @@ -390,7 +358,17 @@ impl FlowCcModelApi {
FlowModelServ::modify_model(
&flow_model_id.0,
&mut FlowModelModifyReq {
modify_states: Some(vec![req.0]),
modify_version: Some(FlowModelVersionModifyReq {
modify_states: Some(vec![FlowModelVersionModifyState {
id: req.0.id.clone(),
modify_rel: Some(req.0),
modify_state: None,
add_transitions: None,
modify_transitions: None,
delete_transitions: None,
}]),
..Default::default()
}),
..Default::default()
},
&funs,
Expand Down Expand Up @@ -453,4 +431,14 @@ impl FlowCcModelApi {
funs.commit().await?;
TardisResp::ok(Void)
}

/// Get the operations associated with the model
///
/// 获取模型关联的操作
#[oai(path = "/:flow_model_id/get_transitions", method = "get")]
async fn get_rel_transitions(&self, flow_model_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Vec<FlowTransitionDetailResp>> {
let funs = flow_constants::get_tardis_inst();
let result = FlowModelServ::get_rel_transitions(&flow_model_id.0, &funs, &ctx.0).await?;
TardisResp::ok(result)
}
}
Loading
Loading