From 6e4f01dbe5c5c9ebc6aeb64138e7fa8fd8481428 Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Tue, 5 Dec 2023 15:10:56 +0800 Subject: [PATCH] flow: update external dto (#557) --- middleware/flow/src/dto/flow_external_dto.rs | 1 + .../flow/src/dto/flow_transition_dto.rs | 2 ++ .../flow/src/serv/flow_external_serv.rs | 4 +++ middleware/flow/src/serv/flow_inst_serv.rs | 21 +++++--------- middleware/flow/src/serv/flow_state_serv.rs | 29 +++++++++++++------ 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/middleware/flow/src/dto/flow_external_dto.rs b/middleware/flow/src/dto/flow_external_dto.rs index 63735641d..4e7ac1741 100644 --- a/middleware/flow/src/dto/flow_external_dto.rs +++ b/middleware/flow/src/dto/flow_external_dto.rs @@ -17,6 +17,7 @@ pub struct FlowExternalReq { pub target_sys_state: Option, pub original_state: Option, pub original_sys_state: Option, + pub transition_name: Option, pub owner_paths: String, pub obj_ids: Vec, pub notify: Option, diff --git a/middleware/flow/src/dto/flow_transition_dto.rs b/middleware/flow/src/dto/flow_transition_dto.rs index 07fbf52dd..b040d9fa6 100644 --- a/middleware/flow/src/dto/flow_transition_dto.rs +++ b/middleware/flow/src/dto/flow_transition_dto.rs @@ -284,6 +284,8 @@ pub enum FlowTransitionActionByVarChangeInfoChangedKind { ChangeContent, #[sea_orm(string_value = "auto_get_operate_time")] AutoGetOperateTime, + #[sea_orm(string_value = "auto_get_operator")] + AutoGetOperator, #[sea_orm(string_value = "select_field")] SelectField, } diff --git a/middleware/flow/src/serv/flow_external_serv.rs b/middleware/flow/src/serv/flow_external_serv.rs index e05de3c64..96592eec2 100644 --- a/middleware/flow/src/serv/flow_external_serv.rs +++ b/middleware/flow/src/serv/flow_external_serv.rs @@ -76,6 +76,7 @@ impl FlowExternalServ { target_sys_state: Option, original_state: Option, original_sys_state: Option, + transition_name: Option, is_notify: bool, params: Vec, ctx: &TardisContext, @@ -112,6 +113,7 @@ impl FlowExternalServ { original_state, original_sys_state, notify: Some(is_notify), + transition_name, params, ..Default::default() }; @@ -140,6 +142,7 @@ impl FlowExternalServ { target_sys_state: FlowSysStateKind, original_state: String, original_sys_state: FlowSysStateKind, + transition_name: String, is_notify: bool, ctx: &TardisContext, funs: &TardisFunsInst, @@ -159,6 +162,7 @@ impl FlowExternalServ { target_sys_state: Some(target_sys_state), original_state: Some(original_state), original_sys_state: Some(original_sys_state), + transition_name: Some(transition_name), notify: Some(is_notify), ..Default::default() }; diff --git a/middleware/flow/src/serv/flow_inst_serv.rs b/middleware/flow/src/serv/flow_inst_serv.rs index e8d3d95ea..5badd8259 100644 --- a/middleware/flow/src/serv/flow_inst_serv.rs +++ b/middleware/flow/src/serv/flow_inst_serv.rs @@ -735,6 +735,7 @@ impl FlowInstServ { Some(next_flow_state.sys_state.clone()), Some(prev_flow_state.name.clone()), Some(prev_flow_state.sys_state.clone()), + Some(next_flow_transition.next_flow_state_name.clone()), next_transition_detail.is_notify, params, ctx, @@ -804,6 +805,7 @@ impl FlowInstServ { next_flow_state.sys_state, prev_flow_state.name.clone(), prev_flow_state.sys_state, + next_transition_detail.name.clone(), next_transition_detail.is_notify, ctx, funs, @@ -814,16 +816,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, - next_transition_detail.is_notify, - ctx, - funs, - ) - .await?; + Self::do_post_change(&flow_inst_detail, &flow_model, &next_transition_detail, post_changes, updated_instance_list, 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; @@ -852,9 +845,9 @@ impl FlowInstServ { async fn do_post_change( current_inst: &FlowInstDetailResp, current_model: &FlowModelDetailResp, + transition_detail: &FlowTransitionDetailResp, post_changes: Vec, updated_instance_list: &mut Vec, - is_notify: bool, ctx: &TardisContext, funs: &TardisFunsInst, ) -> TardisResult<()> { @@ -889,7 +882,8 @@ impl FlowInstServ { None, None, None, - is_notify, + Some(transition_detail.name.clone()), + transition_detail.is_notify, vec![FlowExternalParams { rel_kind: None, rel_tag: None, @@ -914,7 +908,8 @@ impl FlowInstServ { None, None, None, - is_notify, + Some(transition_detail.name.clone()), + transition_detail.is_notify, vec![FlowExternalParams { rel_kind: None, rel_tag: None, diff --git a/middleware/flow/src/serv/flow_state_serv.rs b/middleware/flow/src/serv/flow_state_serv.rs index 571f70924..33489f1ff 100644 --- a/middleware/flow/src/serv/flow_state_serv.rs +++ b/middleware/flow/src/serv/flow_state_serv.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use bios_basic::rbum::{ dto::{ @@ -307,16 +307,27 @@ impl FlowStateServ { ctx, ) .await?; - let mut result = vec![]; + let mut result = HashMap::new(); let insts = FlowInstServ::find_detail(req.inst_ids.clone(), funs, ctx).await?; for (state_id, state_name) in states { - let inst_ids = insts.iter().filter(|inst| inst.current_state_id == state_id).map(|inst| inst.id.clone()).collect_vec(); - result.push(FlowStateCountGroupByStateResp { - state_name, - count: inst_ids.len().to_string(), - inst_ids, - }); + let mut inst_ids = insts.iter().filter(|inst| inst.current_state_id == state_id).map(|inst| inst.id.clone()).collect_vec(); + result + .entry(state_name.clone()) + .and_modify(|resp: &mut FlowStateCountGroupByStateResp| { + resp.inst_ids.append(&mut inst_ids); + resp.count = (resp.count.parse::().unwrap_or_default() + inst_ids.len()).to_string() + }) + .or_insert(FlowStateCountGroupByStateResp { + state_name, + count: inst_ids.len().to_string(), + inst_ids, + }); + // result.push(FlowStateCountGroupByStateResp { + // state_name, + // count: inst_ids.len().to_string(), + // inst_ids, + // }); } - Ok(result) + Ok(result.into_values().collect_vec()) } }