Skip to content

Commit

Permalink
flow: improve log (#886)
Browse files Browse the repository at this point in the history
* flow: fix bug (inst search failed)

* flow: fix bug (instance referral error)

* flow: fix bug (instance referral failed)

* flow: add api instance details

* flow: improve log

* flow: fix bug (switch model failed)
  • Loading branch information
ZzIsGod1019 authored Dec 26, 2024
1 parent 63f055c commit 5a9863e
Show file tree
Hide file tree
Showing 27 changed files with 1,588 additions and 2,075 deletions.
12 changes: 4 additions & 8 deletions backend/middlewares/flow/src/api/ca/flow_ca_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ impl FlowCaModelApi {
for (_, rel_model_id) in req.0.rel_model_ids {
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(
&new_model,
None,
None,
&new_model.tag,
&new_model.current_version_id,
new_model.states.clone(),
&new_model.init_state_id,
&funs,
&ctx.0,
)
Expand Down Expand Up @@ -69,11 +67,9 @@ impl FlowCaModelApi {
let _orginal_models = FlowModelServ::clean_rel_models(None, None, Some(vec![req.0.tag.clone()]), &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(
&new_model,
None,
None,
&new_model.tag,
&new_model.current_version_id,
new_model.states.clone(),
&new_model.init_state_id,
&funs,
&ctx.0,
)
Expand Down
46 changes: 42 additions & 4 deletions backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};

use crate::dto::flow_external_dto::FlowExternalCallbackOp;
use crate::dto::flow_inst_dto::{
FlowInstAbortReq, FlowInstCommentReq, FlowInstDetailResp, FlowInstFindNextTransitionResp, FlowInstFindNextTransitionsReq, FlowInstFindStateAndTransitionsReq,
FlowInstFindStateAndTransitionsResp, FlowInstModifyAssignedReq, FlowInstModifyCurrentVarsReq, FlowInstOperateReq, FlowInstSearchReq, FlowInstStartReq, FlowInstSummaryResp,
FlowInstTransferReq, FlowInstTransferResp,
FlowInstAbortReq, FlowInstCommentReq, FlowInstDetailResp, FlowInstFilterReq, FlowInstFindNextTransitionResp, FlowInstFindNextTransitionsReq, FlowInstFindStateAndTransitionsReq, FlowInstFindStateAndTransitionsResp, FlowInstModifyAssignedReq, FlowInstModifyCurrentVarsReq, FlowInstOperateReq, FlowInstSearchReq, FlowInstSearchResp, FlowInstStartReq, FlowInstSummaryResp, FlowInstTransferReq, FlowInstTransferResp
};
use crate::flow_constants;
use crate::helper::loop_check_helper;
Expand Down Expand Up @@ -111,6 +109,46 @@ impl FlowCcInstApi {
TardisResp::ok(result)
}

/// Find Instances
///
/// 获取实例列表
#[oai(path = "/details", method = "get")]
async fn paginate_detail_items(
&self,
flow_model_id: Query<Option<String>>,
rel_business_obj_id: Query<Option<String>>,
tag: Query<Option<String>>,
finish: Query<Option<bool>>,
main: Query<Option<bool>>,
current_state_id: Query<Option<String>>,
with_sub: Query<Option<bool>>,
page_number: Query<u32>,
page_size: Query<u32>,
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<TardisPage<FlowInstDetailResp>> {
let funs = flow_constants::get_tardis_inst();
let result = FlowInstServ::paginate_detail_items(
&FlowInstFilterReq {
flow_version_id: flow_model_id.0,
tag: tag.0,
finish: finish.0,
main: main.0,
current_state_id: current_state_id.0,
rel_business_obj_ids: rel_business_obj_id.0.map(|id| vec![id]),
with_sub: with_sub.0,
..Default::default()
},
page_number.0,
page_size.0,
&funs,
&ctx.0,
)
.await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}

/// Find Next Transitions
///
/// 获取下一个流转状态列表
Expand Down Expand Up @@ -287,7 +325,7 @@ impl FlowCcInstApi {

/// Search Items
#[oai(path = "/search", method = "put")]
async fn search(&self, mut search_req: Json<FlowInstSearchReq>, ctx: TardisContextExtractor) -> TardisApiResult<TardisPage<FlowInstSummaryResp>> {
async fn search(&self, mut search_req: Json<FlowInstSearchReq>, ctx: TardisContextExtractor) -> TardisApiResult<TardisPage<FlowInstSearchResp>> {
let funs = flow_constants::get_tardis_inst();
let resp = FlowInstServ::search(&mut search_req.0, &funs, &ctx.0).await?;
TardisResp::ok(resp)
Expand Down
18 changes: 3 additions & 15 deletions backend/middlewares/flow/src/api/cc/flow_cc_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,26 +246,14 @@ impl FlowCcModelApi {
TardisResp::ok(Void {})
}

/// Unbind State By Model Id [Deprecated]
/// Unbind State By Model Id
///
/// 解绑状态 [已废弃]
/// 解绑状态
#[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::modify_model(
&flow_model_id.0,
&mut FlowModelModifyReq {
modify_version: Some(FlowModelVersionModifyReq {
unbind_states: Some(vec![req.state_id.clone()]),
..Default::default()
}),
..Default::default()
},
&funs,
&ctx.0,
)
.await?;
FlowModelServ::unbind_state(&flow_model_id.0, &req.0, &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
Expand Down
136 changes: 72 additions & 64 deletions backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ use crate::flow_constants;
use crate::serv::flow_inst_serv::FlowInstServ;
use crate::serv::flow_model_serv::FlowModelServ;
use crate::serv::flow_rel_serv::{FlowRelKind, FlowRelServ};
use bios_basic::rbum::dto::rbum_filer_dto::{RbumBasicFilterReq, RbumRelFilterReq};
use bios_basic::rbum::dto::rbum_filer_dto::{RbumBasicFilterReq, RbumItemRelFilterReq, RbumRelFilterReq};
use bios_basic::rbum::helper::rbum_scope_helper::check_without_owner_and_unsafe_fill_ctx;
use bios_basic::rbum::rbum_enumeration::RbumRelFromKind;
use bios_basic::rbum::serv::rbum_item_serv::RbumItemCrudOperation;
use bios_basic::rbum::serv::rbum_rel_serv::RbumRelServ;
use itertools::Itertools;
use tardis::futures::future::join_all;
use std::iter::Iterator;
use tardis::basic::dto::TardisContext;
use tardis::log::warn;
Expand Down Expand Up @@ -119,29 +121,24 @@ impl FlowCiModelApi {
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
funs.begin().await?;
warn!("ci copy_or_reference_model req: {:?}", req.0);
let _orginal_models = FlowModelServ::clean_rel_models(None, None, None, &funs, &ctx.0).await?;
let orginal_models = FlowModelServ::clean_rel_models(None, None, None, &funs, &ctx.0).await?;
// find rel models
let rel_model_ids = FlowRelServ::find_to_simple_rels(
&FlowRelKind::FlowModelTemplate,
&req.0.rel_template_id.clone().unwrap_or_default(),
None,
None,
&funs,
&ctx.0,
)
.await?
.into_iter()
.map(|rel| rel.rel_id)
.collect_vec();
let rel_models = FlowModelServ::find_items(
&FlowModelFilterReq {
basic: RbumBasicFilterReq {
ids: Some(rel_model_ids),
enabled: Some(true),
own_paths: Some("".to_string()),
with_sub_own_paths: true,
..Default::default()
},
rel: Some(RbumItemRelFilterReq {
optional: false,
rel_by_from: true,
tag: Some(FlowRelKind::FlowModelTemplate.to_string()),
from_rbum_kind: Some(RbumRelFromKind::Item),
rel_item_id: Some(req.0.rel_template_id.clone().unwrap_or_default()),
..Default::default()
}),
// main: Some(true),
..Default::default()
},
Expand All @@ -154,16 +151,16 @@ impl FlowCiModelApi {
let mut result = HashMap::new();
for rel_model in rel_models {
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(
new_model.rel_template_ids.first().cloned(),
&new_model.tag,
&new_model.current_version_id,
new_model.states.clone(),
&new_model.init_state_id,
&funs,
&ctx.0,
)
.await?;
if new_model.main && orginal_models.contains_key(&new_model.tag) {
FlowInstServ::batch_update_when_switch_model(
&new_model,
new_model.rel_template_ids.first().cloned(),
req.update_states.clone().map(|update_states| update_states.get(&new_model.tag).cloned().unwrap_or_default()),
&funs,
&ctx.0,
)
.await?;
}
result.insert(rel_model.id.clone(), new_model.id.clone());
}
funs.commit().await?;
Expand Down Expand Up @@ -261,45 +258,56 @@ impl FlowCiModelApi {
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
warn!("ci exist_rel_by_template_ids req: {:?}", req.0);
let support_tags = req.0.support_tags;
let mut result = vec![];
for (rel_template_id, current_tags) in req.0.rel_tag_by_template_ids {
// 当前模板tag和需要支持的tag取交集,得到当前模板tag中需要检查的tag列表
let tags = current_tags.into_iter().filter(|current_tag| support_tags.contains(current_tag)).collect_vec();
if !tags.is_empty() {
// 当前模板关联的模型所支持的tag
let rel_model_tags = FlowModelServ::find_items(
&FlowModelFilterReq {
basic: RbumBasicFilterReq {
ids: Some(
FlowRelServ::find_to_simple_rels(&FlowRelKind::FlowModelTemplate, &rel_template_id, None, None, &funs, &ctx.0)
.await?
.into_iter()
.map(|rel| rel.rel_id)
.collect_vec(),
),
own_paths: Some("".to_string()),
with_sub_own_paths: true,
..Default::default()
},
main: Some(true),
..Default::default()
},
None,
None,
&funs,
&ctx.0,
)
.await?
.into_iter()
.map(|model| model.tag.clone())
.collect_vec();
// 如果出现了当前模板tag中需要检查的tag没有被当前模板关联,则说明当前关联模板不是可用状态
if !tags.into_iter().filter(|tag| !rel_model_tags.contains(tag)).collect_vec().is_empty() {
continue;
}
}
result.push(rel_template_id.clone());
}
let result = join_all(
req.0.rel_tag_by_template_ids
.iter()
.map(|(rel_template_id, current_tags)| async {
// 当前模板tag和需要支持的tag取交集,得到当前模板tag中需要检查的tag列表
let tags = current_tags.iter().filter(|current_tag| support_tags.contains(current_tag)).collect_vec();
if !tags.is_empty() {
// 当前模板关联的模型所支持的tag
let rel_model_tags = FlowModelServ::find_items(
&FlowModelFilterReq {
basic: RbumBasicFilterReq {
own_paths: Some("".to_string()),
with_sub_own_paths: true,
..Default::default()
},
rel: Some(RbumItemRelFilterReq {
optional: false,
rel_by_from: true,
tag: Some(FlowRelKind::FlowModelTemplate.to_string()),
from_rbum_kind: Some(RbumRelFromKind::Item),
rel_item_id: Some(rel_template_id.clone()),
..Default::default()
}),
main: Some(true),
..Default::default()
},
None,
None,
&funs,
&ctx.0,
)
.await
.unwrap()
.into_iter()
.map(|model| model.tag.clone())
.collect_vec();
// 如果出现了当前模板tag中需要检查的tag没有被当前模板关联,则说明当前关联模板不是可用状态
if !tags.into_iter().filter(|tag| !rel_model_tags.contains(tag)).collect_vec().is_empty() {
return None;
}
}
Some(rel_template_id.clone())
})
.collect_vec(),
)
.await
.into_iter()
.filter(|r| r.is_some())
.map(|r| r.unwrap_or_default())
.collect_vec();

TardisResp::ok(result)
}
Expand Down
6 changes: 2 additions & 4 deletions backend/middlewares/flow/src/api/ct/flow_ct_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ impl FlowCtModelApi {
.await?;
}
FlowInstServ::batch_update_when_switch_model(
&new_model,
req.0.rel_template_id.clone(),
&new_model.tag,
&new_model.current_version_id,
new_model.states.clone(),
&new_model.init_state_id,
None,
&funs,
&ctx.0,
)
Expand Down
4 changes: 4 additions & 0 deletions backend/middlewares/flow/src/domain/flow_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ pub struct Model {
#[index]
#[sea_orm(extra = "DEFAULT CURRENT_TIMESTAMP")]
pub create_time: chrono::DateTime<Utc>,
/// Creation time / 创建时间
#[index]
#[sea_orm(extra = "DEFAULT CURRENT_TIMESTAMP")]
pub update_time: Option<chrono::DateTime<Utc>>,

/// Finisher information / 完成者信息
pub finish_ctx: Option<FlowOperationContext>,
Expand Down
Loading

0 comments on commit 5a9863e

Please sign in to comment.