Skip to content

Commit

Permalink
Merge pull request #547 from ZzIsGod1019/zz-flow-2.3
Browse files Browse the repository at this point in the history
flow: reach notify
  • Loading branch information
gudaoxuri authored Nov 24, 2023
2 parents f6b9221 + 094e1f1 commit 3f877d4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 60 deletions.
1 change: 1 addition & 0 deletions middleware/flow/src/dto/flow_external_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct FlowExternalReq {
pub original_sys_state: Option<FlowSysStateKind>,
pub owner_paths: String,
pub obj_ids: Vec<String>,
pub notify: Option<bool>,
pub params: Vec<FlowExternalParams>,
}

Expand Down
53 changes: 2 additions & 51 deletions middleware/flow/src/flow_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ use bios_basic::rbum::{
};
use bios_sdk_invoke::invoke_initializer;

use itertools::Itertools;
use serde_json::Value;
use tardis::{
basic::{dto::TardisContext, field::TrimString, result::TardisResult},
db::{
reldb_client::TardisActiveModel,
sea_orm::{
self,
sea_query::{Query, Table},
},
sea_orm::sea_query::Table,
},
log::info,
web::web_server::TardisWebServer,
Expand All @@ -33,7 +28,7 @@ use crate::{
flow_model_dto::FlowModelFilterReq,
flow_state_dto::FlowSysStateKind,
flow_transition_dto::{
FlowTransitionActionByVarChangeInfoChangedKind, FlowTransitionActionChangeInfo, FlowTransitionActionChangeKind, FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo,
FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo,
},
},
flow_config::{BasicInfo, FlowBasicInfoManager, FlowConfig},
Expand Down Expand Up @@ -77,7 +72,6 @@ pub async fn init_db(mut funs: TardisFunsInst) -> TardisResult<()> {
funs.begin().await?;
if check_initialized(&funs, &ctx).await? {
init_basic_info(&funs).await?;
// self::modify_post_actions(&funs, &ctx).await?;
} else {
let db_kind = TardisFuns::reldb().backend();
let compatible_type = TardisFuns::reldb().compatible_type();
Expand Down Expand Up @@ -125,49 +119,6 @@ async fn init_basic_info<'a>(funs: &TardisFunsInst) -> TardisResult<()> {
Ok(())
}

// @TODO temporary
pub async fn modify_post_actions(funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
#[derive(sea_orm::FromQueryResult)]
pub struct FlowTransactionPostAction {
id: String,
action_by_post_changes: Value,
}
let transactions = funs
.db()
.find_dtos::<FlowTransactionPostAction>(
Query::select()
.columns([
(flow_transition::Entity, flow_transition::Column::Id),
(flow_transition::Entity, flow_transition::Column::ActionByPostChanges),
])
.from(flow_transition::Entity),
)
.await?
.into_iter()
.filter(|res| !TardisFuns::json.json_to_obj::<Vec<FlowTransitionActionChangeInfo>>(res.action_by_post_changes.clone()).unwrap_or_default().is_empty())
.collect_vec();
for transaction in transactions {
let mut post_changes = TardisFuns::json.json_to_obj::<Vec<FlowTransitionActionChangeInfo>>(transaction.action_by_post_changes.clone()).unwrap_or_default();
for post_change in post_changes.iter_mut() {
if post_change.changed_kind.is_none() && post_change.kind == FlowTransitionActionChangeKind::Var {
if post_change.changed_val.is_some() {
post_change.changed_kind = Some(FlowTransitionActionByVarChangeInfoChangedKind::ChangeContent);
} else {
post_change.changed_kind = Some(FlowTransitionActionByVarChangeInfoChangedKind::Clean);
}
}
}
let flow_transition = flow_transition::ActiveModel {
id: sea_orm::ActiveValue::Set(transaction.id.clone()),
action_by_post_changes: sea_orm::ActiveValue::Set(TardisFuns::json.obj_to_json(&post_changes)?),
..Default::default()
};
funs.db().update_one(flow_transition, ctx).await?;
}

Ok(())
}

pub async fn init_rbum_data(funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let kind_state_id = add_kind(flow_constants::RBUM_KIND_STATE_CODE, flow_constants::RBUM_EXT_TABLE_STATE, funs, ctx).await?;
let kind_model_id = add_kind(flow_constants::RBUM_KIND_MODEL_CODE, flow_constants::RBUM_EXT_TABLE_MODEL, funs, ctx).await?;
Expand Down
10 changes: 5 additions & 5 deletions middleware/flow/src/serv/flow_external_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl FlowExternalServ {
target_sys_state: Option<FlowSysStateKind>,
original_state: Option<String>,
original_sys_state: Option<FlowSysStateKind>,
is_notify: bool,
params: Vec<FlowExternalParams>,
ctx: &TardisContext,
funs: &TardisFunsInst,
Expand Down Expand Up @@ -110,6 +111,7 @@ impl FlowExternalServ {
target_sys_state,
original_state,
original_sys_state,
notify: Some(is_notify),
params,
..Default::default()
};
Expand Down Expand Up @@ -138,6 +140,7 @@ impl FlowExternalServ {
target_sys_state: FlowSysStateKind,
original_state: String,
original_sys_state: FlowSysStateKind,
is_notify: bool,
ctx: &TardisContext,
funs: &TardisFunsInst,
) -> TardisResult<FlowExternalNotifyChangesResp> {
Expand All @@ -156,6 +159,7 @@ impl FlowExternalServ {
target_sys_state: Some(target_sys_state),
original_state: Some(original_state),
original_sys_state: Some(original_sys_state),
notify: Some(is_notify),
..Default::default()
};
debug!("do_notify_changes body: {:?}", body);
Expand Down Expand Up @@ -215,11 +219,7 @@ impl FlowExternalServ {
curr_bus_obj_id: "".to_string(),
owner_paths: own_paths.to_string(),
obj_ids: rel_business_obj_ids,
target_state: None,
target_sys_state: None,
original_state: None,
original_sys_state: None,
params: vec![],
..Default::default()
};
debug!("do_query_field body: {:?}", body);
let resp: FlowExternalResp<FlowExternalQueryFieldResp> = funs
Expand Down
14 changes: 10 additions & 4 deletions middleware/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,10 @@ impl FlowInstServ {
if next_flow_transition.is_none() {
return Err(funs.err().not_found("flow_inst", "transfer", "no transferable state", "404-flow-inst-transfer-state-not-found"));
}
let model_transition = flow_model.transitions();
let next_transition_detail = model_transition.iter().find(|trans| trans.id == transfer_req.flow_transition_id).unwrap().to_owned();
if FlowModelServ::check_post_action_ring(
flow_model.transitions().into_iter().find(|trans| trans.id == transfer_req.flow_transition_id).unwrap(),
next_transition_detail.clone(),
(false, vec![]),
funs,
ctx,
Expand Down Expand Up @@ -740,6 +742,7 @@ impl FlowInstServ {
Some(next_flow_state.sys_state.clone()),
Some(prev_flow_state.name.clone()),
Some(prev_flow_state.sys_state.clone()),
next_transition_detail.is_notify,
params,
ctx,
funs,
Expand Down Expand Up @@ -792,10 +795,9 @@ impl FlowInstServ {
// get updated instance detail
let flow_inst_detail = Self::get(flow_inst_id, funs, ctx).await?;

let model_transition = flow_model.transitions();
Self::do_request_webhook(
from_transition_id.and_then(|id: String| model_transition.iter().find(|model_transition| model_transition.id == id)),
model_transition.iter().find(|model_transition| model_transition.id == next_flow_transition.next_flow_transition_id),
Some(&next_transition_detail),
)
.await?;

Expand All @@ -809,6 +811,7 @@ impl FlowInstServ {
next_flow_state.sys_state,
prev_flow_state.name.clone(),
prev_flow_state.sys_state,
next_transition_detail.is_notify,
ctx,
funs,
)
Expand All @@ -818,7 +821,7 @@ impl FlowInstServ {
let post_changes =
model_transition.into_iter().find(|model_transition| model_transition.id == next_flow_transition.next_flow_transition_id).unwrap_or_default().action_by_post_changes();
if !post_changes.is_empty() {
Self::do_post_change(&flow_inst_detail, &flow_model, post_changes, updated_instance_list, ctx, funs).await?;
Self::do_post_change(&flow_inst_detail, &flow_model, post_changes, updated_instance_list, next_transition_detail.is_notify, ctx, funs).await?;
}
let next_flow_transitions = Self::do_find_next_transitions(&flow_inst_detail, &flow_model, None, &None, skip_filter, funs, ctx).await?.next_flow_transitions;

Expand Down Expand Up @@ -849,6 +852,7 @@ impl FlowInstServ {
current_model: &FlowModelDetailResp,
post_changes: Vec<FlowTransitionActionChangeInfo>,
updated_instance_list: &mut Vec<String>,
is_notify: bool,
ctx: &TardisContext,
funs: &TardisFunsInst,
) -> TardisResult<()> {
Expand Down Expand Up @@ -883,6 +887,7 @@ impl FlowInstServ {
None,
None,
None,
is_notify,
vec![FlowExternalParams {
rel_kind: None,
rel_tag: None,
Expand All @@ -907,6 +912,7 @@ impl FlowInstServ {
None,
None,
None,
is_notify,
vec![FlowExternalParams {
rel_kind: None,
rel_tag: None,
Expand Down

0 comments on commit 3f877d4

Please sign in to comment.