From 5bb380d8067f098ca4da4447bbbaa8b1eb3988e5 Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Wed, 20 Sep 2023 16:59:41 +0800 Subject: [PATCH 1/6] flow: fix bind state error --- middleware/flow/src/flow_initializer.rs | 58 ++++---- middleware/flow/src/serv/flow_model_serv.rs | 130 ++++++++---------- middleware/flow/tests/test_flow_scenes_fsm.rs | 61 +++++--- services/bios-all/config/locale/zh-cn.flow | 10 +- 4 files changed, 132 insertions(+), 127 deletions(-) diff --git a/middleware/flow/src/flow_initializer.rs b/middleware/flow/src/flow_initializer.rs index 7a49706a1..ff27cdcf0 100644 --- a/middleware/flow/src/flow_initializer.rs +++ b/middleware/flow/src/flow_initializer.rs @@ -198,11 +198,11 @@ pub async fn init_flow_model(funs: &TardisFunsInst, ctx: &TardisContext) -> Tard FlowModelServ::init_model( "TICKET", vec![ - ("待处理", FlowSysStateKind::Start, get_default_color(&FlowSysStateKind::Start)), - ("处理中", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("待确认", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("已关闭", FlowSysStateKind::Finish, get_default_color(&FlowSysStateKind::Finish)), - ("已撤销", FlowSysStateKind::Finish, get_default_color(&FlowSysStateKind::Finish)), + ("待处理", FlowSysStateKind::Start, ""), + ("处理中", FlowSysStateKind::Progress, ""), + ("待确认", FlowSysStateKind::Progress, ""), + ("已关闭", FlowSysStateKind::Finish, ""), + ("已撤销", FlowSysStateKind::Finish, ""), ], "待处理-处理中-待确认-已关闭-已撤销", vec![ @@ -294,10 +294,10 @@ pub async fn init_flow_model(funs: &TardisFunsInst, ctx: &TardisContext) -> Tard FlowModelServ::init_model( "REQ", vec![ - ("待开始", FlowSysStateKind::Start, get_default_color(&FlowSysStateKind::Start)), - ("进行中", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("已完成", FlowSysStateKind::Finish, get_default_color(&FlowSysStateKind::Finish)), - ("已关闭", FlowSysStateKind::Finish, get_default_color(&FlowSysStateKind::Finish)), + ("待开始", FlowSysStateKind::Start, ""), + ("进行中", FlowSysStateKind::Progress, ""), + ("已完成", FlowSysStateKind::Finish, ""), + ("已关闭", FlowSysStateKind::Finish, ""), ], "待开始-进行中-已完成-已关闭", vec![ @@ -397,12 +397,12 @@ pub async fn init_flow_model(funs: &TardisFunsInst, ctx: &TardisContext) -> Tard FlowModelServ::init_model( "PROJ", vec![ - ("待开始", FlowSysStateKind::Start, get_default_color(&FlowSysStateKind::Start)), - ("进行中", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("存在风险", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("已完成", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("已关闭", FlowSysStateKind::Finish, get_default_color(&FlowSysStateKind::Finish)), - ("已归档", FlowSysStateKind::Finish, get_default_color(&FlowSysStateKind::Finish)), + ("待开始", FlowSysStateKind::Start, ""), + ("进行中", FlowSysStateKind::Progress, ""), + ("存在风险", FlowSysStateKind::Progress, ""), + ("已完成", FlowSysStateKind::Progress, ""), + ("已关闭", FlowSysStateKind::Finish, ""), + ("已归档", FlowSysStateKind::Finish, ""), ], "待开始-进行中-存在风险-已完成-已关闭-已归档", vec![ @@ -582,11 +582,11 @@ pub async fn init_flow_model(funs: &TardisFunsInst, ctx: &TardisContext) -> Tard FlowModelServ::init_model( "ITER", vec![ - ("待开始", FlowSysStateKind::Start, get_default_color(&FlowSysStateKind::Start)), - ("进行中", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("存在风险", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("已完成", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("已关闭", FlowSysStateKind::Finish, get_default_color(&FlowSysStateKind::Finish)), + ("待开始", FlowSysStateKind::Start, ""), + ("进行中", FlowSysStateKind::Progress, ""), + ("存在风险", FlowSysStateKind::Progress, ""), + ("已完成", FlowSysStateKind::Progress, ""), + ("已关闭", FlowSysStateKind::Finish, ""), ], "待开始-进行中-存在风险-已完成-已关闭", vec![ @@ -726,11 +726,11 @@ pub async fn init_flow_model(funs: &TardisFunsInst, ctx: &TardisContext) -> Tard FlowModelServ::init_model( "TASK", vec![ - ("待开始", FlowSysStateKind::Start, get_default_color(&FlowSysStateKind::Start)), - ("进行中", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("存在风险", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("已完成", FlowSysStateKind::Progress, get_default_color(&FlowSysStateKind::Progress)), - ("已关闭", FlowSysStateKind::Finish, get_default_color(&FlowSysStateKind::Finish)), + ("待开始", FlowSysStateKind::Start, ""), + ("进行中", FlowSysStateKind::Progress, ""), + ("存在风险", FlowSysStateKind::Progress, ""), + ("已完成", FlowSysStateKind::Progress, ""), + ("已关闭", FlowSysStateKind::Finish, ""), ], "待开始-进行中-存在风险-已完成-已关闭", vec![ @@ -853,11 +853,3 @@ pub async fn init_flow_model(funs: &TardisFunsInst, ctx: &TardisContext) -> Tard Ok(()) } - -fn get_default_color(kind: &FlowSysStateKind) -> &str { - match kind { - FlowSysStateKind::Finish => "rgba(242, 158, 12, 1)", - FlowSysStateKind::Start => "rgba(242, 158, 12, 1)", - FlowSysStateKind::Progress => "rgba(67, 147, 248, 1)", - } -} diff --git a/middleware/flow/src/serv/flow_model_serv.rs b/middleware/flow/src/serv/flow_model_serv.rs index 0503d051b..f6e9b6fa4 100644 --- a/middleware/flow/src/serv/flow_model_serv.rs +++ b/middleware/flow/src/serv/flow_model_serv.rs @@ -275,34 +275,6 @@ impl FlowModelServ { } states_map.insert(state_name, state_id); } - let mut add_transitions = vec![]; - for transition in transitions { - add_transitions.push(FlowTransitionAddReq { - from_flow_state_id: states_map - .get(transition.from_flow_state_name.as_str()) - .ok_or_else(|| funs.err().internal_error("flow_model_serv", "init_model", "from_flow_state_name is illegal", ""))? - .to_string(), - to_flow_state_id: states_map - .get(transition.to_flow_state_name.as_str()) - .ok_or_else(|| funs.err().internal_error("flow_model_serv", "init_model", "to_flow_state_name is illegal", ""))? - .to_string(), - name: Some(transition.name.into()), - transfer_by_auto: transition.transfer_by_auto, - transfer_by_timer: transition.transfer_by_timer, - guard_by_creator: transition.guard_by_creator, - guard_by_his_operators: transition.guard_by_his_operators, - guard_by_assigned: transition.guard_by_assigned, - guard_by_spec_account_ids: transition.guard_by_spec_account_ids, - guard_by_spec_role_ids: transition.guard_by_spec_role_ids, - guard_by_spec_org_ids: transition.guard_by_spec_org_ids, - guard_by_other_conds: transition.guard_by_other_conds, - vars_collect: transition.vars_collect, - action_by_pre_callback: transition.action_by_pre_callback, - action_by_post_callback: transition.action_by_post_callback, - action_by_post_changes: Some(transition.action_by_post_changes), - double_check: transition.double_check, - }); - } // add model let model_id = Self::add_item( &mut FlowModelAddReq { @@ -311,7 +283,7 @@ impl FlowModelServ { rel_template_id: None, icon: None, info: None, - transitions: Some(add_transitions), + transitions: None, tag: Some(tag.to_string()), scope_level: None, disabled: None, @@ -339,6 +311,35 @@ impl FlowModelServ { ) .await?; } + let mut add_transitions = vec![]; + for transition in transitions { + add_transitions.push(FlowTransitionAddReq { + from_flow_state_id: states_map + .get(transition.from_flow_state_name.as_str()) + .ok_or_else(|| funs.err().internal_error("flow_model_serv", "init_model", "from_flow_state_name is illegal", ""))? + .to_string(), + to_flow_state_id: states_map + .get(transition.to_flow_state_name.as_str()) + .ok_or_else(|| funs.err().internal_error("flow_model_serv", "init_model", "to_flow_state_name is illegal", ""))? + .to_string(), + name: Some(transition.name.into()), + transfer_by_auto: transition.transfer_by_auto, + transfer_by_timer: transition.transfer_by_timer, + guard_by_creator: transition.guard_by_creator, + guard_by_his_operators: transition.guard_by_his_operators, + guard_by_assigned: transition.guard_by_assigned, + guard_by_spec_account_ids: transition.guard_by_spec_account_ids, + guard_by_spec_role_ids: transition.guard_by_spec_role_ids, + guard_by_spec_org_ids: transition.guard_by_spec_org_ids, + guard_by_other_conds: transition.guard_by_other_conds, + vars_collect: transition.vars_collect, + action_by_pre_callback: transition.action_by_pre_callback, + action_by_post_callback: transition.action_by_post_callback, + action_by_post_changes: Some(transition.action_by_post_changes), + double_check: transition.double_check, + }); + } + Self::add_transitions(&model_id, &add_transitions, funs, ctx).await?; Ok(()) } @@ -346,23 +347,7 @@ impl FlowModelServ { pub async fn add_transitions(flow_model_id: &str, add_req: &[FlowTransitionAddReq], funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { let flow_state_ids = FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, flow_model_id, None, None, funs, ctx).await?.iter().map(|rel| rel.rel_id.clone()).collect::>(); - let flow_state_ids_len = flow_state_ids.len(); - if FlowStateServ::count_items( - &FlowStateFilterReq { - basic: RbumBasicFilterReq { - ids: Some(flow_state_ids), - with_sub_own_paths: true, - enabled: Some(true), - ..Default::default() - }, - ..Default::default() - }, - funs, - ctx, - ) - .await? as usize - != flow_state_ids_len - { + if add_req.iter().any(|req| !flow_state_ids.contains(&req.from_flow_state_id) || !flow_state_ids.contains(&req.to_flow_state_id)) { return Err(funs.err().not_found( &Self::get_obj_name(), "add_transitions", @@ -406,7 +391,7 @@ impl FlowModelServ { funs.db().insert_many(flow_transitions, ctx).await } - pub async fn modify_transitions(flow_model_id: &str, modify_req: &Vec, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + pub async fn modify_transitions(flow_model_id: &str, modify_req: &[FlowTransitionModifyReq], funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { let flow_state_ids = modify_req .iter() .filter(|req| req.from_flow_state_id.is_some()) @@ -414,23 +399,19 @@ impl FlowModelServ { .chain(modify_req.iter().filter(|req| req.to_flow_state_id.is_some()).map(|req| req.to_flow_state_id.as_ref().unwrap().to_string())) .unique() .collect_vec(); - let flow_state_ids_len = flow_state_ids.len(); - if FlowStateServ::count_items( - &FlowStateFilterReq { - basic: RbumBasicFilterReq { - ids: Some(flow_state_ids), - with_sub_own_paths: true, - enabled: Some(true), - ..Default::default() - }, - ..Default::default() - }, - funs, - ctx, - ) - .await? as usize - != flow_state_ids_len - { + if modify_req.iter().any(|req| { + if let Some(from_flow_state_id) = &req.from_flow_state_id { + if !flow_state_ids.contains(from_flow_state_id) { + return true; + } + } + if let Some(to_flow_state_id) = &req.to_flow_state_id { + if !flow_state_ids.contains(to_flow_state_id) { + return true; + } + } + false + }) { return Err(funs.err().not_found( &Self::get_obj_name(), "modify_transitions", @@ -859,14 +840,8 @@ impl FlowModelServ { .ok_or_else(|| funs.err().internal_error("flow_model_serv", "add_custom_model", "default model is not exist", "404-flow-model-not-found"))? }; - // add model let mut transitions = parent_model.transitions(); - // sub role_id instead of role_id - for transition in &mut transitions { - for role_id in &mut transition.guard_by_spec_role_ids { - *role_id = FlowExternalServ::do_find_embed_subrole_id(role_id, ctx, funs).await.unwrap_or(role_id.to_string()); - } - } + // add model let model_id = Self::add_item( &mut FlowModelAddReq { name: parent_model.name.into(), @@ -875,7 +850,7 @@ impl FlowModelServ { init_state_id: parent_model.init_state_id, template: current_template_id.is_some(), rel_template_id: current_template_id, - transitions: Some(transitions.into_iter().map(|trans| trans.into()).collect_vec()), + transitions: None, rel_model_id: Some(parent_model.id.clone()), tag: Some(parent_model.tag), scope_level: None, @@ -895,6 +870,14 @@ impl FlowModelServ { for (i, state_id) in states.iter().enumerate() { FlowRelServ::add_simple_rel(&FlowRelKind::FlowModelState, &model_id, state_id, None, None, false, true, Some(i as i64), funs, ctx).await?; } + // add transition + // sub role_id instead of role_id + for transition in &mut transitions { + for role_id in &mut transition.guard_by_spec_role_ids { + *role_id = FlowExternalServ::do_find_embed_subrole_id(role_id, ctx, funs).await.unwrap_or(role_id.to_string()); + } + } + Self::add_transitions(&model_id, &transitions.into_iter().map(|trans| trans.into()).collect_vec(), funs, ctx).await?; Ok(model_id) } @@ -922,6 +905,9 @@ impl FlowModelServ { pub async fn bind_state(flow_rel_kind: &FlowRelKind, flow_model_id: &str, req: &FlowModelBindStateReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { let flow_state_id = &req.state_id; + if FlowStateServ::get_item(flow_state_id, &FlowStateFilterReq::default(), funs, ctx).await.is_err() { + return Err(funs.err().internal_error("flow_model_serv", "bind_state", "The flow state is not found", "404-flow-state-not-found")); + } let sort = req.sort; let current_model = Self::get_item( flow_model_id, diff --git a/middleware/flow/tests/test_flow_scenes_fsm.rs b/middleware/flow/tests/test_flow_scenes_fsm.rs index 546b5ce96..5beca69bb 100644 --- a/middleware/flow/tests/test_flow_scenes_fsm.rs +++ b/middleware/flow/tests/test_flow_scenes_fsm.rs @@ -393,30 +393,24 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli }, ) .await; + let share_template_id = "share_template_id".to_string(); + let share_template_models: HashMap = flow_client.get(&format!("/cc/model/get_models?tag_ids=REQ&temp_id={}", share_template_id)).await; + let req_share_model_id = share_template_models.get("REQ").unwrap().id.clone(); + let req_share_model_agg: FlowModelAggResp = flow_client.get(&format!("/cc/model/{}", req_share_model_id)).await; let _: Void = flow_client .post( - &format!("/cc/model/{}/bind_state", &proj_model_id), + &format!("/cc/model/{}/bind_state", &req_share_model_id), &FlowModelBindStateReq { state_id: custom_state_id.clone(), sort: 1, }, ) .await; - let share_template_id = "share_template_id".to_string(); - let share_template_models: HashMap = flow_client.get(&format!("/cc/model/get_models?tag_ids=REQ&temp_id={}", share_template_id)).await; - let req_share_model_id = share_template_models.get("REQ").unwrap().id.clone(); - let req_share_model_agg: FlowModelAggResp = flow_client.get(&format!("/cc/model/{}", req_share_model_id)).await; let _: Void = flow_client .patch( &format!("/cc/model/{}", req_share_model_id), &FlowModelModifyReq { scope_level: Some(RbumScopeLevelKind::Root), - add_transitions: Some(vec![FlowTransitionAddReq { - from_flow_state_id: req_share_model_agg.init_state_id.clone(), - name: Some("111".to_string().into()), - to_flow_state_id: custom_state_id.clone(), - ..Default::default() - }]), ..Default::default() }, ) @@ -435,13 +429,26 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli }, ) .await; - let share_mdoel_id = result.pop().unwrap().model_id.unwrap(); - + let share_model_id = result.pop().unwrap().model_id.unwrap(); + let _: Void = flow_client + .patch( + &format!("/cc/model/{}", share_model_id), + &FlowModelModifyReq { + add_transitions: Some(vec![FlowTransitionAddReq { + from_flow_state_id: req_share_model_agg.init_state_id.clone(), + name: Some("111".to_string().into()), + to_flow_state_id: custom_state_id.clone(), + ..Default::default() + }]), + ..Default::default() + }, + ) + .await; let share_template_models: HashMap = flow_client.get("/cc/model/get_models?tag_ids=REQ").await; - assert_eq!(share_mdoel_id.as_str(), share_template_models.get("REQ").unwrap().id.as_str()); + assert_eq!(share_model_id.as_str(), share_template_models.get("REQ").unwrap().id.as_str()); - let share_mdoel_agg: FlowModelAggResp = flow_client.get(&format!("/cc/model/{}", share_mdoel_id)).await; - assert_eq!(share_mdoel_agg.scope_level, RbumScopeLevelKind::Private); + let share_model_agg: FlowModelAggResp = flow_client.get(&format!("/cc/model/{}", share_model_id)).await; + assert_eq!(share_model_agg.scope_level, RbumScopeLevelKind::Private); let req_share_inst_id: String = flow_client .post( "/cc/inst", @@ -469,7 +476,27 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli ) .await; assert_eq!(transfer.new_flow_state_id, custom_state_id.clone()); - + let state_and_next_transitions: Vec = flow_client + .put( + "/cc/inst/batch/state_transitions", + &vec![FlowInstFindStateAndTransitionsReq { + flow_inst_id: req_share_inst_id.clone(), + vars: None, + }], + ) + .await; + assert_eq!(state_and_next_transitions.len(), 1); + assert_eq!(state_and_next_transitions[0].current_flow_state_name, "测试"); + let state_bind_error = flow_client + .post_resp::( + &format!("/cc/model/{}/bind_state", &share_model_id), + &FlowModelBindStateReq { + state_id: custom_state_id.clone(), + sort: 1, + }, + ) + .await; + assert_eq!(state_bind_error.code, "500-flow-flow_model_serv-bind_state"); // reset share model ctx.own_paths = "t1".to_string(); flow_client.set_auth(&ctx)?; diff --git a/services/bios-all/config/locale/zh-cn.flow b/services/bios-all/config/locale/zh-cn.flow index af9a51f1c..037630971 100644 --- a/services/bios-all/config/locale/zh-cn.flow +++ b/services/bios-all/config/locale/zh-cn.flow @@ -1,14 +1,14 @@ 400-flow-inst-vars-field-missing 缺少必填字段信息 409-flow-state-already-used 状态已被使用 -404-external-data-url-not-exist 工作流对外接口未配置 +404-external-data-url-not-exist 工作流对外接口未配置 404-flow-state-add-not-legal 要添加的状态不合法(权限错误、已禁用等) 404-flow-transition-rel-model-not-legal 转换关联的模型不合法 404-flow-inst-not-found 找不到实例 404-flow-model-not-found 找不到模型 404-flow-transition-not-found 找不到模型 -404-rel-not-found 找不到关联状态 +404-rel-not-found 找不到关联状态 404-flow-inst-rel-model-not-found 找不到实例关联的模型 404-flow-inst-transfer-state-not-found 没有可流转的状态 -500-external-illegal-response 对外接口响应异常 -500-flow-transition-endless-loop 状态流转出现死循环 -409-rbum-rel-exist 状态关联已存在 \ No newline at end of file +500-external-illegal-response 对外接口响应异常 +500-flow-transition-endless-loop 状态流转出现死循环 +409-rbum-rel-exist 状态关联已存在 \ No newline at end of file From 6b26ddda705fd0e5217e6f404dd94b83060e6f8e Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Mon, 25 Sep 2023 23:17:03 -0700 Subject: [PATCH 2/6] flow: add resort trans api && set front condition config --- .../flow/src/api/cc/flow_cc_model_api.rs | 11 ++++ middleware/flow/src/domain/flow_transition.rs | 5 ++ .../flow/src/dto/flow_transition_dto.rs | 64 +++++++++++++++---- middleware/flow/src/serv/flow_inst_serv.rs | 3 +- middleware/flow/src/serv/flow_model_serv.rs | 52 +++++++++++++-- middleware/flow/tests/test_flow_scenes_fsm.rs | 10 +++ services/spi-conf/src/main.rs | 1 - .../src/serv/pg/stats_pg_record_serv.rs | 2 +- 8 files changed, 129 insertions(+), 19 deletions(-) diff --git a/middleware/flow/src/api/cc/flow_cc_model_api.rs b/middleware/flow/src/api/cc/flow_cc_model_api.rs index e0f804b25..64ceadc88 100644 --- a/middleware/flow/src/api/cc/flow_cc_model_api.rs +++ b/middleware/flow/src/api/cc/flow_cc_model_api.rs @@ -12,6 +12,7 @@ use crate::dto::flow_model_dto::{ FlowModelAddCustomModelReq, FlowModelAddCustomModelResp, FlowModelAddReq, FlowModelAggResp, FlowModelBindStateReq, FlowModelFilterReq, FlowModelFindRelStateResp, FlowModelModifyReq, FlowModelSortStatesReq, FlowModelSummaryResp, FlowModelUnbindStateReq, FlowTemplateModelResp, }; +use crate::dto::flow_transition_dto::FlowTransitionSortStatesReq; use crate::flow_constants; use crate::serv::flow_model_serv::FlowModelServ; use crate::serv::flow_rel_serv::FlowRelKind; @@ -144,6 +145,16 @@ impl FlowCcModelApi { TardisResp::ok(Void {}) } + /// Resort state / 动作重新排序 + #[oai(path = "/:flow_model_id/resort_transition", method = "post")] + async fn resort_transition(&self, flow_model_id: Path, req: Json, ctx: TardisContextExtractor) -> TardisApiResult { + let mut funs = flow_constants::get_tardis_inst(); + funs.begin().await?; + FlowModelServ::resort_transition(&flow_model_id.0, &req.0, &funs, &ctx.0).await?; + funs.commit().await?; + TardisResp::ok(Void {}) + } + /// add custom model by template_id / 添加自定义模型 #[oai(path = "/add_custom_model", method = "post")] async fn add_custom_model(&self, req: Json, ctx: TardisContextExtractor) -> TardisApiResult> { diff --git a/middleware/flow/src/domain/flow_transition.rs b/middleware/flow/src/domain/flow_transition.rs index b58aa58cd..1a283f854 100644 --- a/middleware/flow/src/domain/flow_transition.rs +++ b/middleware/flow/src/domain/flow_transition.rs @@ -88,12 +88,17 @@ pub struct Model { /// TODO Vec pub action_by_post_changes: Json, + /// TODO Vec + pub action_by_front_changes: Json, + /// Secondary confirmation pop-up / 关于二次确认弹窗的配置 /// TODO FlowTransitionDoubleCheckInfo pub double_check: Json, pub rel_flow_model_id: String, + pub sort: i64, + #[fill_ctx(own_paths)] pub own_paths: String, diff --git a/middleware/flow/src/dto/flow_transition_dto.rs b/middleware/flow/src/dto/flow_transition_dto.rs index 71b829657..3d29a1210 100644 --- a/middleware/flow/src/dto/flow_transition_dto.rs +++ b/middleware/flow/src/dto/flow_transition_dto.rs @@ -25,14 +25,15 @@ pub struct FlowTransitionAddReq { pub guard_by_spec_org_ids: Option>, pub guard_by_other_conds: Option>>, + pub double_check: Option, pub vars_collect: Option>, pub action_by_pre_callback: Option, pub action_by_post_callback: Option, - pub action_by_post_changes: Option>, + pub action_by_front_changes: Option>, - pub double_check: Option, + pub sort: Option, } #[derive(Serialize, Deserialize, Debug, poem_openapi::Object)] @@ -58,13 +59,14 @@ pub struct FlowTransitionModifyReq { pub guard_by_other_conds: Option>>, pub vars_collect: Option>, + pub double_check: Option, pub action_by_pre_callback: Option, pub action_by_post_callback: Option, - pub action_by_post_changes: Option>, + pub action_by_front_changes: Option>, - pub double_check: Option, + pub sort: Option, } #[derive(Serialize, Deserialize, Default, Debug, Clone, poem_openapi::Object, sea_orm::FromQueryResult)] @@ -92,15 +94,15 @@ pub struct FlowTransitionDetailResp { pub guard_by_other_conds: Value, pub vars_collect: Value, + pub double_check: Value, pub action_by_pre_callback: String, pub action_by_post_callback: String, - pub action_by_post_changes: Value, - - pub double_check: Value, + pub action_by_front_changes: Value, pub rel_flow_model_id: String, + pub sort: i64, } impl FlowTransitionDetailResp { @@ -128,6 +130,14 @@ impl FlowTransitionDetailResp { } } + pub fn action_by_front_changes(&self) -> Vec { + if self.action_by_front_changes.is_array() && !&self.action_by_front_changes.as_array().unwrap().is_empty() { + TardisFuns::json.json_to_obj(self.action_by_front_changes.clone()).unwrap_or_default() + } else { + vec![] + } + } + pub fn double_check(&self) -> Option { if self.double_check.is_object() { Some(TardisFuns::json.json_to_obj(self.double_check.clone()).unwrap_or_default()) @@ -142,6 +152,7 @@ impl From for FlowTransitionAddReq { let guard_by_other_conds = value.guard_by_other_conds(); let vars_collect = value.vars_collect(); let action_by_post_changes = value.action_by_post_changes(); + let action_by_front_changes = value.action_by_front_changes(); let double_check = value.double_check(); FlowTransitionAddReq { from_flow_state_id: value.from_flow_state_id, @@ -160,7 +171,9 @@ impl From for FlowTransitionAddReq { action_by_pre_callback: Some(value.action_by_pre_callback), action_by_post_callback: Some(value.action_by_post_callback), action_by_post_changes: Some(action_by_post_changes), + action_by_front_changes: Some(action_by_front_changes), double_check, + sort: Some(value.sort), } } } @@ -171,6 +184,17 @@ pub struct FlowTransitionDoubleCheckInfo { pub content: Option, } +#[derive(Serialize, Deserialize, Debug, Default, poem_openapi::Object)] +pub struct FlowTransitionSortStatesReq { + pub sort_states: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Default, poem_openapi::Object)] +pub struct FlowTransitionSortStateInfoReq { + pub id: String, + pub sort: i64, +} + #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object)] pub struct FlowTransitionActionChangeInfo { pub kind: FlowTransitionActionChangeKind, @@ -264,8 +288,6 @@ pub struct StateChangeConditionItem { pub enum StateChangeConditionOp { And, Or, - Eq, - Neq, } #[derive(Default)] @@ -285,11 +307,31 @@ pub struct FlowTransitionInitInfo { pub guard_by_other_conds: Option>>, pub vars_collect: Option>, + pub double_check: Option, pub action_by_pre_callback: Option, pub action_by_post_callback: Option, - pub action_by_post_changes: Vec, + pub action_by_front_changes: Vec, - pub double_check: Option, + pub sort: Option, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object)] +pub struct FlowTransitionFrontActionInfo { + pub describe: String, + pub change_condition: FlowTransitionFrontConditionOp, + pub left_name: String, + pub right_val: Option, + pub right_name: Option, + pub right_time: Option, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Enum)] +pub enum FlowTransitionFrontConditionOp { + EQ, + GT, + LT, + GE, + LE, } diff --git a/middleware/flow/src/serv/flow_inst_serv.rs b/middleware/flow/src/serv/flow_inst_serv.rs index 9d402e268..49dc1215d 100644 --- a/middleware/flow/src/serv/flow_inst_serv.rs +++ b/middleware/flow/src/serv/flow_inst_serv.rs @@ -891,7 +891,6 @@ impl FlowInstServ { continue; } } - _ => {} } } } @@ -932,7 +931,7 @@ impl FlowInstServ { .iter() .filter(|inst_result| { if let Some(obj_current_state_id) = obj_current_state_id.clone() { - if !obj_current_state_id.contains(&inst_result.current_state_id) { + if !obj_current_state_id.is_empty() && !obj_current_state_id.contains(&inst_result.current_state_id) { return false; } } diff --git a/middleware/flow/src/serv/flow_model_serv.rs b/middleware/flow/src/serv/flow_model_serv.rs index f6e9b6fa4..478fd75ce 100644 --- a/middleware/flow/src/serv/flow_model_serv.rs +++ b/middleware/flow/src/serv/flow_model_serv.rs @@ -36,7 +36,7 @@ use crate::{ flow_state_dto::{FlowStateAddReq, FlowStateFilterReq, FlowSysStateKind}, flow_transition_dto::{ FlowTransitionActionChangeAgg, FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo, - FlowTransitionModifyReq, + FlowTransitionModifyReq, FlowTransitionSortStatesReq, }, }, flow_config::FlowBasicInfoManager, @@ -336,7 +336,9 @@ impl FlowModelServ { action_by_pre_callback: transition.action_by_pre_callback, action_by_post_callback: transition.action_by_post_callback, action_by_post_changes: Some(transition.action_by_post_changes), + action_by_front_changes: Some(transition.action_by_front_changes), double_check: transition.double_check, + sort: transition.sort, }); } Self::add_transitions(&model_id, &add_transitions, funs, ctx).await?; @@ -376,15 +378,15 @@ impl FlowModelServ { guard_by_other_conds: Set(req.guard_by_other_conds.as_ref().map(|conds| TardisFuns::json.obj_to_json(conds).unwrap()).unwrap_or(json!([]))), vars_collect: Set(req.vars_collect.as_ref().map(|vars| TardisFuns::json.obj_to_json(vars).unwrap()).unwrap_or(json!([]))), + double_check: Set(TardisFuns::json.obj_to_json(&req.double_check).unwrap_or(json!(FlowTransitionDoubleCheckInfo::default()))), action_by_pre_callback: Set(req.action_by_pre_callback.as_ref().unwrap_or(&"".to_string()).to_string()), action_by_post_callback: Set(req.action_by_post_callback.as_ref().unwrap_or(&"".to_string()).to_string()), - action_by_post_changes: Set(TardisFuns::json.obj_to_json(&req.action_by_post_changes).unwrap_or(json!([]))), - - double_check: Set(TardisFuns::json.obj_to_json(&req.double_check).unwrap_or(json!(FlowTransitionDoubleCheckInfo::default()))), + action_by_front_changes: Set(TardisFuns::json.obj_to_json(&req.action_by_front_changes).unwrap_or(json!([]))), rel_flow_model_id: Set(flow_model_id.to_string()), + sort: Set(req.sort.unwrap_or(0)), ..Default::default() }) .collect_vec(); @@ -496,12 +498,18 @@ impl FlowModelServ { if let Some(action_by_post_callback) = &req.action_by_post_callback { flow_transition.action_by_post_callback = Set(action_by_post_callback.to_string()); } + if let Some(action_by_front_changes) = &req.action_by_front_changes { + flow_transition.action_by_front_changes = Set(TardisFuns::json.obj_to_json(action_by_front_changes)?); + } if let Some(action_by_post_changes) = &req.action_by_post_changes { flow_transition.action_by_post_changes = Set(TardisFuns::json.obj_to_json(action_by_post_changes)?); } if let Some(double_check) = &req.double_check { flow_transition.double_check = Set(TardisFuns::json.obj_to_json(double_check)?); } + if let Some(sort) = &req.sort { + flow_transition.sort = Set(*sort); + } flow_transition.update_time = Set(Utc::now()); funs.db().update_one(flow_transition, ctx).await?; } @@ -563,8 +571,10 @@ impl FlowModelServ { (flow_transition::Entity, flow_transition::Column::ActionByPreCallback), (flow_transition::Entity, flow_transition::Column::ActionByPostCallback), (flow_transition::Entity, flow_transition::Column::ActionByPostChanges), + (flow_transition::Entity, flow_transition::Column::ActionByFrontChanges), (flow_transition::Entity, flow_transition::Column::DoubleCheck), (flow_transition::Entity, flow_transition::Column::RelFlowModelId), + (flow_transition::Entity, flow_transition::Column::Sort), ]) .expr_as( Expr::col((from_state_rbum_table.clone(), NAME_FIELD.clone())).if_null(""), @@ -605,6 +615,7 @@ impl FlowModelServ { Cond::all().add(Expr::col((to_state_table.clone(), ID_FIELD.clone())).equals((flow_transition::Entity, flow_transition::Column::FromFlowStateId))), ) .and_where(Expr::col((flow_transition::Entity, flow_transition::Column::RelFlowModelId)).eq(flow_model_id)) + .order_by((flow_transition::Entity, flow_transition::Column::Sort), Order::Asc) .order_by((flow_transition::Entity, flow_transition::Column::CreateTime), Order::Asc) .order_by((flow_transition::Entity, flow_transition::Column::Id), Order::Asc); let flow_transitions: Vec = funs.db().find_dtos(&query).await?; @@ -1035,6 +1046,39 @@ impl FlowModelServ { Ok(()) } + pub async fn resort_transition(flow_model_id: &str, sort_req: &FlowTransitionSortStatesReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + // @TODO wait tardis updated + let modify_trans = sort_req + .sort_states + .iter() + .map(|sort_req| FlowTransitionModifyReq { + id: sort_req.id.clone().into(), + name: None, + from_flow_state_id: None, + to_flow_state_id: None, + transfer_by_auto: None, + transfer_by_timer: None, + guard_by_creator: None, + guard_by_his_operators: None, + guard_by_assigned: None, + guard_by_spec_account_ids: None, + guard_by_spec_role_ids: None, + guard_by_spec_org_ids: None, + guard_by_other_conds: None, + vars_collect: None, + double_check: None, + action_by_pre_callback: None, + action_by_post_callback: None, + action_by_post_changes: None, + action_by_front_changes: None, + sort: Some(sort_req.sort), + }) + .collect_vec(); + Self::modify_transitions(flow_model_id, &modify_trans, funs, ctx).await?; + + Ok(()) + } + async fn find_transitions_by_state_id( flow_model_id: &str, current_state_id: Option>, diff --git a/middleware/flow/tests/test_flow_scenes_fsm.rs b/middleware/flow/tests/test_flow_scenes_fsm.rs index 5beca69bb..7ee46e701 100644 --- a/middleware/flow/tests/test_flow_scenes_fsm.rs +++ b/middleware/flow/tests/test_flow_scenes_fsm.rs @@ -218,6 +218,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli ]), action_by_pre_callback: None, action_by_post_callback: None, + action_by_front_changes: None, action_by_post_changes: Some(vec![FlowTransitionActionChangeInfo { kind: FlowTransitionActionChangeKind::State, describe: "".to_string(), @@ -240,6 +241,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli is_open: true, content: Some("再次确认该操作生效".to_string()), }), + sort: None, }, FlowTransitionModifyReq { id: trans_complate.id.clone().into(), @@ -258,6 +260,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli vars_collect: None, action_by_pre_callback: None, action_by_post_callback: None, + action_by_front_changes: None, action_by_post_changes: Some(vec![FlowTransitionActionChangeInfo { kind: FlowTransitionActionChangeKind::Var, describe: "".to_string(), @@ -270,6 +273,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli changed_val: Some(json!("xxx".to_string())), }]), double_check: None, + sort: None, }, FlowTransitionModifyReq { id: trans_close.id.clone().into(), @@ -289,7 +293,9 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli action_by_pre_callback: None, action_by_post_callback: None, action_by_post_changes: None, + action_by_front_changes: None, double_check: None, + sort: None, }, ]), ..Default::default() @@ -319,6 +325,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli vars_collect: None, action_by_pre_callback: None, action_by_post_callback: None, + action_by_front_changes: None, action_by_post_changes: Some(vec![FlowTransitionActionChangeInfo { kind: FlowTransitionActionChangeKind::State, describe: "".to_string(), @@ -331,6 +338,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli changed_val: None, }]), double_check: None, + sort: None, }]), ..Default::default() }, @@ -359,6 +367,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli vars_collect: None, action_by_pre_callback: None, action_by_post_callback: None, + action_by_front_changes: None, action_by_post_changes: Some(vec![FlowTransitionActionChangeInfo { kind: FlowTransitionActionChangeKind::State, describe: "".to_string(), @@ -371,6 +380,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli changed_val: None, }]), double_check: None, + sort: None, }]), ..Default::default() }, diff --git a/services/spi-conf/src/main.rs b/services/spi-conf/src/main.rs index b6e1369be..0d2ebf8e3 100644 --- a/services/spi-conf/src/main.rs +++ b/services/spi-conf/src/main.rs @@ -1,4 +1,3 @@ - use tardis::basic::result::TardisResult; use tardis::tokio; use tardis::TardisFuns; diff --git a/spi/spi-stats/src/serv/pg/stats_pg_record_serv.rs b/spi/spi-stats/src/serv/pg/stats_pg_record_serv.rs index 04392973a..65c71f229 100644 --- a/spi/spi-stats/src/serv/pg/stats_pg_record_serv.rs +++ b/spi/spi-stats/src/serv/pg/stats_pg_record_serv.rs @@ -61,7 +61,7 @@ pub(crate) async fn get_fact_record_latest( .map(|result| { let result = serde_json::Value::from_query_result_optional(result, "")?; let mut value = result.unwrap_or_default(); - value.as_object_mut().map(|obj|obj.remove("rn")); + value.as_object_mut().map(|obj| obj.remove("rn")); Ok(value) }) .collect::>>()?; From aabc0ba8f65e27ef1200ed9a0f7fca85a280518e Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Wed, 27 Sep 2023 20:15:47 -0700 Subject: [PATCH 3/6] flow:update --- .../flow/src/api/cc/flow_cc_model_api.rs | 15 ++- middleware/flow/src/dto/flow_model_dto.rs | 7 +- middleware/flow/src/dto/flow_state_dto.rs | 6 ++ .../flow/src/dto/flow_transition_dto.rs | 3 + middleware/flow/src/serv/flow_inst_serv.rs | 6 +- middleware/flow/src/serv/flow_model_serv.rs | 102 +++++++++++++++--- middleware/flow/src/serv/flow_rel_serv.rs | 4 +- middleware/flow/tests/test_flow_scenes_fsm.rs | 4 + 8 files changed, 127 insertions(+), 20 deletions(-) diff --git a/middleware/flow/src/api/cc/flow_cc_model_api.rs b/middleware/flow/src/api/cc/flow_cc_model_api.rs index 64ceadc88..eddc11447 100644 --- a/middleware/flow/src/api/cc/flow_cc_model_api.rs +++ b/middleware/flow/src/api/cc/flow_cc_model_api.rs @@ -12,6 +12,7 @@ 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::flow_constants; use crate::serv::flow_model_serv::FlowModelServ; @@ -135,7 +136,7 @@ impl FlowCcModelApi { TardisResp::ok(Void {}) } - /// Resort state / 状态重新排序 + /// Resort states / 状态重新排序 #[oai(path = "/:flow_model_id/resort_state", method = "post")] async fn resort_state(&self, flow_model_id: Path, req: Json, ctx: TardisContextExtractor) -> TardisApiResult { let mut funs = flow_constants::get_tardis_inst(); @@ -145,7 +146,7 @@ impl FlowCcModelApi { TardisResp::ok(Void {}) } - /// Resort state / 动作重新排序 + /// Resort transitions / 动作重新排序 #[oai(path = "/:flow_model_id/resort_transition", method = "post")] async fn resort_transition(&self, flow_model_id: Path, req: Json, ctx: TardisContextExtractor) -> TardisApiResult { let mut funs = flow_constants::get_tardis_inst(); @@ -178,4 +179,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, state_id: Path, req: Json, ctx: TardisContextExtractor) -> TardisApiResult { + 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?; + funs.commit().await?; + TardisResp::ok(Void {}) + } } diff --git a/middleware/flow/src/dto/flow_model_dto.rs b/middleware/flow/src/dto/flow_model_dto.rs index f352dbce6..90e0c7123 100644 --- a/middleware/flow/src/dto/flow_model_dto.rs +++ b/middleware/flow/src/dto/flow_model_dto.rs @@ -12,7 +12,10 @@ use tardis::{ TardisFuns, }; -use super::flow_transition_dto::{FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionModifyReq}; +use super::{ + flow_state_dto::FlowStateRelModelExt, + flow_transition_dto::{FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionModifyReq}, +}; #[derive(Serialize, Deserialize, Debug, poem_openapi::Object)] pub struct FlowModelAddReq { @@ -161,7 +164,7 @@ pub struct FlowStateAggResp { pub id: String, pub name: String, pub is_init: bool, - pub sort: i64, + pub ext: FlowStateRelModelExt, pub transitions: Vec, } diff --git a/middleware/flow/src/dto/flow_state_dto.rs b/middleware/flow/src/dto/flow_state_dto.rs index 7a97c70b7..67812339f 100644 --- a/middleware/flow/src/dto/flow_state_dto.rs +++ b/middleware/flow/src/dto/flow_state_dto.rs @@ -181,3 +181,9 @@ pub struct FlowStateCountGroupByStateResp { pub count: String, pub inst_ids: Vec, } + +#[derive(Serialize, Deserialize, Debug, Default, poem_openapi::Object, sea_orm::FromQueryResult)] +pub struct FlowStateRelModelExt { + pub sort: i64, + pub show_btns: Option>, +} diff --git a/middleware/flow/src/dto/flow_transition_dto.rs b/middleware/flow/src/dto/flow_transition_dto.rs index 3d29a1210..532cdc00b 100644 --- a/middleware/flow/src/dto/flow_transition_dto.rs +++ b/middleware/flow/src/dto/flow_transition_dto.rs @@ -206,6 +206,7 @@ pub struct FlowTransitionActionChangeInfo { pub current: bool, pub var_name: String, pub changed_val: Option, + pub changed_current_time: Option, } impl From for FlowTransitionActionChangeAgg { @@ -230,6 +231,7 @@ impl From for FlowTransitionActionChangeAgg { obj_tag: value.obj_tag, var_name: value.var_name, changed_val: value.changed_val, + changed_current_time: value.changed_current_time, }), state_change_info: None, }, @@ -260,6 +262,7 @@ pub struct FlowTransitionActionByVarChangeInfo { pub obj_tag: Option, pub var_name: String, pub changed_val: Option, + pub changed_current_time: Option, } #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)] diff --git a/middleware/flow/src/serv/flow_inst_serv.rs b/middleware/flow/src/serv/flow_inst_serv.rs index 49dc1215d..95e2b5e50 100644 --- a/middleware/flow/src/serv/flow_inst_serv.rs +++ b/middleware/flow/src/serv/flow_inst_serv.rs @@ -13,6 +13,7 @@ use bios_basic::{ }, }; use itertools::Itertools; +use serde_json::json; use tardis::{ basic::{dto::TardisContext, result::TardisResult}, chrono::{DateTime, Utc}, @@ -778,7 +779,10 @@ impl FlowInstServ { let post_change = FlowTransitionActionChangeAgg::from(post_change); match post_change.kind { FlowTransitionActionChangeKind::Var => { - if let Some(change_info) = post_change.var_change_info { + if let Some(mut change_info) = post_change.var_change_info { + if change_info.changed_current_time.is_some() && change_info.changed_current_time.unwrap() { + change_info.changed_val = Some(json!(Utc::now().to_string())); + } let rel_tag = change_info.obj_tag.unwrap_or_default(); if !rel_tag.is_empty() { let mut resp = diff --git a/middleware/flow/src/serv/flow_model_serv.rs b/middleware/flow/src/serv/flow_model_serv.rs index 478fd75ce..c49f0bbfc 100644 --- a/middleware/flow/src/serv/flow_model_serv.rs +++ b/middleware/flow/src/serv/flow_model_serv.rs @@ -33,7 +33,7 @@ use crate::{ FlowModelAddReq, FlowModelAggResp, FlowModelBindStateReq, FlowModelDetailResp, FlowModelFilterReq, FlowModelFindRelStateResp, FlowModelModifyReq, FlowModelSortStatesReq, FlowModelSummaryResp, FlowModelUnbindStateReq, FlowStateAggResp, FlowTemplateModelResp, }, - flow_state_dto::{FlowStateAddReq, FlowStateFilterReq, FlowSysStateKind}, + flow_state_dto::{FlowStateAddReq, FlowStateFilterReq, FlowStateRelModelExt, FlowSysStateKind}, flow_transition_dto::{ FlowTransitionActionChangeAgg, FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo, FlowTransitionModifyReq, FlowTransitionSortStatesReq, @@ -297,6 +297,10 @@ impl FlowModelServ { // add rel for (i, (state_name, _, _)) in states.iter().enumerate() { + let ext = FlowStateRelModelExt { + sort: i as i64, + ..Default::default() + }; FlowRelServ::add_simple_rel( &FlowRelKind::FlowModelState, &model_id, @@ -305,7 +309,7 @@ impl FlowModelServ { None, false, false, - Some(i as i64), + Some(json!(ext).to_string()), funs, ctx, ) @@ -663,15 +667,21 @@ impl FlowModelServ { let state_ids = FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, flow_model_id, None, None, funs, ctx) .await? .iter() - .sorted_by_key(|rel| rel.ext.as_str().parse::().unwrap_or_default()) - .map(|rel| (rel.rel_id.clone(), rel.rel_name.clone(), rel.ext.as_str().parse::().unwrap_or_default())) + .sorted_by_key(|rel| TardisFuns::json.str_to_obj::(&rel.ext).unwrap_or_default().sort) + .map(|rel| { + ( + rel.rel_id.clone(), + rel.rel_name.clone(), + TardisFuns::json.str_to_obj::(&rel.ext).unwrap_or_default(), + ) + }) .collect::>(); let mut states = Vec::new(); - for (state_id, state_name, sort) in state_ids { + for (state_id, state_name, ext) in state_ids { let state_detail = FlowStateAggResp { id: state_id.clone(), name: state_name, - sort, + ext, is_init: model_detail.init_state_id == state_id, transitions: model_detail.transitions().into_iter().filter(|transition| transition.from_flow_state_id == state_id.clone()).collect_vec(), }; @@ -875,11 +885,23 @@ impl FlowModelServ { let states = FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, &parent_model.id, None, None, funs, &global_ctx) .await? .iter() - .sorted_by_key(|rel| rel.ext.as_str().parse::().unwrap_or_default()) - .map(|rel| rel.rel_id.clone()) + .sorted_by_key(|rel| TardisFuns::json.str_to_obj::(&rel.ext).unwrap_or_default().sort) + .map(|rel| (rel.rel_id.clone(), TardisFuns::json.str_to_obj::(&rel.ext).unwrap_or_default())) .collect::>(); - for (i, state_id) in states.iter().enumerate() { - FlowRelServ::add_simple_rel(&FlowRelKind::FlowModelState, &model_id, state_id, None, None, false, true, Some(i as i64), funs, ctx).await?; + for (state_id, ext) in states.iter() { + FlowRelServ::add_simple_rel( + &FlowRelKind::FlowModelState, + &model_id, + state_id, + None, + None, + false, + true, + Some(json!(ext).to_string()), + funs, + ctx, + ) + .await?; } // add transition // sub role_id instead of role_id @@ -942,7 +964,20 @@ impl FlowModelServ { "404-flow-model-not-found", )); } - FlowRelServ::add_simple_rel(flow_rel_kind, flow_model_id, flow_state_id, None, None, false, true, Some(sort), funs, ctx).await?; + let ext = FlowStateRelModelExt { sort, ..Default::default() }; + FlowRelServ::add_simple_rel( + flow_rel_kind, + flow_model_id, + flow_state_id, + None, + None, + false, + true, + Some(json!(ext).to_string()), + funs, + ctx, + ) + .await?; Self::modify_item( flow_model_id, @@ -1017,7 +1052,19 @@ impl FlowModelServ { pub async fn resort_state(flow_rel_kind: &FlowRelKind, flow_model_id: &str, sort_req: &FlowModelSortStatesReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { let sort_states = &sort_req.sort_states; + let states = FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, flow_model_id, None, None, funs, ctx).await?; for sort_state in sort_states { + let show_btns = TardisFuns::json + .str_to_obj::( + &states + .iter() + .find(|state| state.rel_id == sort_state.state_id) + .ok_or_else(|| funs.err().internal_error("flow_model_serv", "resort_state", "rel not found", "404-rel-not-found"))? + .ext, + ) + .unwrap_or_default() + .show_btns; + let ext = FlowStateRelModelExt { sort: sort_state.sort, show_btns }; FlowRelServ::modify_simple_rel( flow_rel_kind, flow_model_id, @@ -1025,7 +1072,7 @@ impl FlowModelServ { &mut RbumRelModifyReq { tag: None, note: None, - ext: Some(sort_state.sort.to_string()), + ext: Some(json!(ext).to_string()), }, funs, ctx, @@ -1046,6 +1093,35 @@ impl FlowModelServ { Ok(()) } + pub async fn modify_rel_state(flow_model_id: &str, state_id: &str, new_ext: &FlowStateRelModelExt, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + let mut ext = TardisFuns::json.str_to_obj::( + &FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, flow_model_id, None, None, funs, ctx) + .await? + .into_iter() + .find(|rel| rel.rel_id == state_id) + .ok_or_else(|| funs.err().internal_error("flow_model_serv", "modify_rel_state", "rel not found", "404-rel-not-found"))? + .ext, + )?; + if let Some(show_btns) = new_ext.show_btns.clone() { + ext.show_btns = Some(show_btns); + } + FlowRelServ::modify_simple_rel( + &FlowRelKind::FlowModelState, + flow_model_id, + state_id, + &mut RbumRelModifyReq { + tag: None, + note: None, + ext: Some(json!(ext).to_string()), + }, + funs, + ctx, + ) + .await?; + + Ok(()) + } + pub async fn resort_transition(flow_model_id: &str, sort_req: &FlowTransitionSortStatesReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { // @TODO wait tardis updated let modify_trans = sort_req @@ -1182,7 +1258,7 @@ impl FlowModelServ { let state_ids = FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, flow_model_id, None, None, funs, ctx) .await? .iter() - .sorted_by_key(|rel| rel.ext.as_str().parse::().unwrap_or_default()) + .sorted_by_key(|rel| TardisFuns::json.str_to_obj::(&rel.ext).unwrap_or_default().sort) .map(|rel| rel.rel_id.clone()) .collect::>(); Ok(FlowStateServ::find_detail_items( diff --git a/middleware/flow/src/serv/flow_rel_serv.rs b/middleware/flow/src/serv/flow_rel_serv.rs index e8bf22178..9b4d5420c 100644 --- a/middleware/flow/src/serv/flow_rel_serv.rs +++ b/middleware/flow/src/serv/flow_rel_serv.rs @@ -34,7 +34,7 @@ impl FlowRelServ { end_timestamp: Option, ignore_exist_error: bool, to_is_outside: bool, - sort: Option, + ext: Option, funs: &TardisFunsInst, ctx: &TardisContext, ) -> TardisResult<()> { @@ -56,7 +56,7 @@ impl FlowRelServ { to_rbum_item_id: flow_state_id.to_string(), to_own_paths: ctx.own_paths.to_string(), to_is_outside, - ext: sort.map(|sort| sort.to_string()), + ext, }, attrs: vec![], envs: if start_timestamp.is_some() || end_timestamp.is_some() { diff --git a/middleware/flow/tests/test_flow_scenes_fsm.rs b/middleware/flow/tests/test_flow_scenes_fsm.rs index 7ee46e701..4d3cdc947 100644 --- a/middleware/flow/tests/test_flow_scenes_fsm.rs +++ b/middleware/flow/tests/test_flow_scenes_fsm.rs @@ -236,6 +236,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli current: true, var_name: "".to_string(), changed_val: None, + changed_current_time: None, }]), double_check: Some(FlowTransitionDoubleCheckInfo { is_open: true, @@ -271,6 +272,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli current: false, var_name: "id".to_string(), changed_val: Some(json!("xxx".to_string())), + changed_current_time: None, }]), double_check: None, sort: None, @@ -336,6 +338,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli current: true, var_name: "".to_string(), changed_val: None, + changed_current_time: None, }]), double_check: None, sort: None, @@ -378,6 +381,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli current: true, var_name: "".to_string(), changed_val: None, + changed_current_time: None, }]), double_check: None, sort: None, From 0abf530795ac89c810a7dd7ee55caed95b43700e Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Fri, 6 Oct 2023 19:21:47 -0700 Subject: [PATCH 4/6] flow:update --- .../flow/src/dto/flow_transition_dto.rs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/middleware/flow/src/dto/flow_transition_dto.rs b/middleware/flow/src/dto/flow_transition_dto.rs index 532cdc00b..6290f2cc1 100644 --- a/middleware/flow/src/dto/flow_transition_dto.rs +++ b/middleware/flow/src/dto/flow_transition_dto.rs @@ -1,4 +1,4 @@ -use bios_basic::dto::BasicQueryCondInfo; +use bios_basic::{dto::BasicQueryCondInfo, basic_enumeration::BasicQueryOpKind}; use serde::{Deserialize, Serialize}; use tardis::{basic::field::TrimString, db::sea_orm, serde_json::Value, web::poem_openapi, TardisFuns}; @@ -322,19 +322,22 @@ pub struct FlowTransitionInitInfo { #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object)] pub struct FlowTransitionFrontActionInfo { - pub describe: String, - pub change_condition: FlowTransitionFrontConditionOp, - pub left_name: String, - pub right_val: Option, - pub right_name: Option, - pub right_time: Option, + pub relevance_relation: BasicQueryOpKind, + pub relevance_label: String, + pub left_value: String, + pub left_label: String, + pub right_value: FlowTransitionFrontActionRightValue, + pub select_field: Option, + pub change_content: Option, + pub real_time: Option, } #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Enum)] -pub enum FlowTransitionFrontConditionOp { - EQ, - GT, - LT, - GE, - LE, +pub enum FlowTransitionFrontActionRightValue { + #[oai(rename = "select_field")] + SelectField, + #[oai(rename = "change_content")] + ChangeContent, + #[oai(rename = "real_time")] + RealTime, } From 6ea0181634491a3b8a437a410588329b7b1bb257 Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Sat, 7 Oct 2023 20:17:43 -0700 Subject: [PATCH 5/6] flow: add inst api: modify vars & complete testing --- .../flow/src/api/cc/flow_cc_inst_api.rs | 13 +++++ middleware/flow/src/dto/flow_inst_dto.rs | 9 ++- .../flow/src/dto/flow_transition_dto.rs | 9 +-- middleware/flow/src/serv/flow_inst_serv.rs | 47 +++++++++++++-- middleware/flow/tests/test_flow_scenes_fsm.rs | 57 +++++++++++++++++-- spi/spi-log/src/serv/pg/log_pg_initializer.rs | 2 +- spi/spi-log/src/serv/pg/log_pg_item_serv.rs | 10 ++-- 7 files changed, 125 insertions(+), 22 deletions(-) diff --git a/middleware/flow/src/api/cc/flow_cc_inst_api.rs b/middleware/flow/src/api/cc/flow_cc_inst_api.rs index 3cd4fbd19..55a3f3fc6 100644 --- a/middleware/flow/src/api/cc/flow_cc_inst_api.rs +++ b/middleware/flow/src/api/cc/flow_cc_inst_api.rs @@ -1,3 +1,6 @@ +use std::collections::HashMap; + +use serde_json::Value; use tardis::web::context_extractor::TardisContextExtractor; use tardis::web::poem_openapi; use tardis::web::poem_openapi::param::{Path, Query}; @@ -106,4 +109,14 @@ impl FlowCcInstApi { funs.commit().await?; TardisResp::ok(Void {}) } + + /// Modify list of variables / 同步当前变量列表 + #[oai(path = "/:flow_inst_id/modify_current_vars", method = "patch")] + async fn modify_current_vars(&self, flow_inst_id: Path, modify_req: Json>, ctx: TardisContextExtractor) -> TardisApiResult { + let mut funs = flow_constants::get_tardis_inst(); + funs.begin().await?; + FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0, &funs, &ctx.0).await?; + funs.commit().await?; + TardisResp::ok(Void {}) + } } diff --git a/middleware/flow/src/dto/flow_inst_dto.rs b/middleware/flow/src/dto/flow_inst_dto.rs index 2d4f490c9..a292a7542 100644 --- a/middleware/flow/src/dto/flow_inst_dto.rs +++ b/middleware/flow/src/dto/flow_inst_dto.rs @@ -9,7 +9,11 @@ use tardis::{ web::poem_openapi, }; -use super::{flow_state_dto::FlowSysStateKind, flow_transition_dto::FlowTransitionDoubleCheckInfo, flow_var_dto::FlowVarInfo}; +use super::{ + flow_state_dto::{FlowStateRelModelExt, FlowSysStateKind}, + flow_transition_dto::FlowTransitionDoubleCheckInfo, + flow_var_dto::FlowVarInfo, +}; #[derive(Serialize, Deserialize, Debug, poem_openapi::Object)] pub struct FlowInstStartReq { @@ -143,7 +147,6 @@ pub struct FlowInstFindNextTransitionResp { pub next_flow_state_color: String, pub vars_collect: Option>, - pub double_check: Option, } @@ -159,6 +162,7 @@ pub struct FlowInstFindStateAndTransitionsResp { pub current_flow_state_name: String, pub current_flow_state_kind: FlowSysStateKind, pub current_flow_state_color: String, + pub current_flow_state_ext: FlowStateRelModelExt, pub finish_time: Option>, pub next_flow_transitions: Vec, } @@ -178,6 +182,7 @@ pub struct FlowInstTransferResp { pub new_flow_state_id: String, pub new_flow_state_name: String, pub new_flow_state_color: String, + pub new_flow_state_ext: FlowStateRelModelExt, pub finish_time: Option>, pub vars: Option>, diff --git a/middleware/flow/src/dto/flow_transition_dto.rs b/middleware/flow/src/dto/flow_transition_dto.rs index 6290f2cc1..75a4c02d2 100644 --- a/middleware/flow/src/dto/flow_transition_dto.rs +++ b/middleware/flow/src/dto/flow_transition_dto.rs @@ -1,4 +1,4 @@ -use bios_basic::{dto::BasicQueryCondInfo, basic_enumeration::BasicQueryOpKind}; +use bios_basic::{basic_enumeration::BasicQueryOpKind, dto::BasicQueryCondInfo}; use serde::{Deserialize, Serialize}; use tardis::{basic::field::TrimString, db::sea_orm, serde_json::Value, web::poem_openapi, TardisFuns}; @@ -322,14 +322,15 @@ pub struct FlowTransitionInitInfo { #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object)] pub struct FlowTransitionFrontActionInfo { - pub relevance_relation: BasicQueryOpKind, - pub relevance_label: String, + pub op: BasicQueryOpKind, + pub op_label: String, pub left_value: String, pub left_label: String, pub right_value: FlowTransitionFrontActionRightValue, pub select_field: Option, + pub select_field_label: Option, pub change_content: Option, - pub real_time: Option, + pub change_content_label: Option, } #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Enum)] diff --git a/middleware/flow/src/serv/flow_inst_serv.rs b/middleware/flow/src/serv/flow_inst_serv.rs index 95e2b5e50..fccb3ad12 100644 --- a/middleware/flow/src/serv/flow_inst_serv.rs +++ b/middleware/flow/src/serv/flow_inst_serv.rs @@ -39,7 +39,7 @@ use crate::{ FlowInstTransitionInfo, FlowOperationContext, }, flow_model_dto::{FlowModelDetailResp, FlowModelFilterReq}, - flow_state_dto::{FlowStateFilterReq, FlowSysStateKind}, + flow_state_dto::{FlowStateFilterReq, FlowStateRelModelExt, FlowSysStateKind}, flow_transition_dto::{ FlowTransitionActionByStateChangeInfo, FlowTransitionActionChangeAgg, FlowTransitionActionChangeInfo, FlowTransitionActionChangeKind, FlowTransitionDetailResp, StateChangeConditionOp, @@ -48,7 +48,10 @@ use crate::{ serv::{flow_model_serv::FlowModelServ, flow_state_serv::FlowStateServ}, }; -use super::flow_external_serv::FlowExternalServ; +use super::{ + flow_external_serv::FlowExternalServ, + flow_rel_serv::{FlowRelKind, FlowRelServ}, +}; pub struct FlowInstServ; @@ -758,6 +761,14 @@ impl FlowInstServ { prev_flow_state_id: prev_flow_state.id, prev_flow_state_name: prev_flow_state.name, prev_flow_state_color: prev_flow_state.color, + new_flow_state_ext: TardisFuns::json.str_to_obj::( + &FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, &flow_model.id, None, None, funs, ctx) + .await? + .into_iter() + .find(|rel| next_flow_state.id == rel.rel_id) + .ok_or_else(|| funs.err().not_found("flow_inst", "do_find_next_transitions", "flow state is not found", "404-flow-state-not-found"))? + .ext, + )?, new_flow_state_id: next_flow_state.id, new_flow_state_name: next_flow_state.name, new_flow_state_color: next_flow_state.color, @@ -1116,14 +1127,23 @@ impl FlowInstServ { funs, ctx, ) - .await?; + .await? + .ok_or_else(|| funs.err().not_found("flow_inst", "do_find_next_transitions", "flow state is not found", "404-flow-state-not-found"))?; let state_and_next_transitions = FlowInstFindStateAndTransitionsResp { flow_inst_id: flow_inst.id.to_string(), finish_time: flow_inst.finish_time, current_flow_state_name: flow_inst.current_state_name.as_ref().unwrap_or(&"".to_string()).to_string(), - current_flow_state_kind: current_flow_state.as_ref().map(|state| state.sys_state.clone()).unwrap_or(FlowSysStateKind::Finish), - current_flow_state_color: current_flow_state.as_ref().map(|state| state.color.clone()).unwrap_or_default(), + current_flow_state_kind: current_flow_state.sys_state.clone(), + current_flow_state_color: current_flow_state.color.clone(), + current_flow_state_ext: TardisFuns::json.str_to_obj::( + &FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, &flow_inst.rel_flow_model_id, None, None, funs, ctx) + .await? + .into_iter() + .find(|rel| current_flow_state.id == rel.rel_id) + .ok_or_else(|| funs.err().not_found("flow_inst", "do_find_next_transitions", "flow state is not found", "404-flow-state-not-found"))? + .ext, + )?, next_flow_transitions: next_transitions, }; Ok(state_and_next_transitions) @@ -1148,4 +1168,21 @@ impl FlowInstServ { Ok(false) } } + + pub async fn modify_current_vars(flow_inst_id: &str, current_vars: &HashMap, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + let flow_inst_detail = Self::get(flow_inst_id, funs, ctx).await?; + let mut new_vars: HashMap = HashMap::new(); + if let Some(old_current_vars) = &flow_inst_detail.current_vars { + new_vars.extend(old_current_vars.clone()); + } + new_vars.extend(current_vars.clone()); + let flow_inst = flow_inst::ActiveModel { + id: Set(flow_inst_id.to_string()), + current_vars: Set(Some(TardisFuns::json.obj_to_json(&new_vars)?)), + ..Default::default() + }; + funs.db().update_one(flow_inst, ctx).await?; + + Ok(()) + } } diff --git a/middleware/flow/tests/test_flow_scenes_fsm.rs b/middleware/flow/tests/test_flow_scenes_fsm.rs index 4d3cdc947..567780880 100644 --- a/middleware/flow/tests/test_flow_scenes_fsm.rs +++ b/middleware/flow/tests/test_flow_scenes_fsm.rs @@ -1,5 +1,7 @@ use std::collections::HashMap; +use bios_basic::basic_enumeration::BasicQueryOpKind; +use bios_basic::dto::BasicQueryCondInfo; use bios_basic::rbum::rbum_enumeration::RbumScopeLevelKind; use bios_basic::test::test_http_client::TestHttpClient; @@ -14,8 +16,9 @@ use bios_mw_flow::dto::flow_model_dto::{ }; use bios_mw_flow::dto::flow_state_dto::{FlowStateAddReq, FlowStateSummaryResp, FlowSysStateKind}; use bios_mw_flow::dto::flow_transition_dto::{ - FlowTransitionActionChangeInfo, FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDoubleCheckInfo, FlowTransitionModifyReq, StateChangeCondition, - StateChangeConditionItem, StateChangeConditionOp, + FlowTransitionActionChangeInfo, FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDoubleCheckInfo, FlowTransitionFrontActionInfo, + FlowTransitionFrontActionRightValue, FlowTransitionModifyReq, FlowTransitionSortStateInfoReq, FlowTransitionSortStatesReq, StateChangeCondition, StateChangeConditionItem, + StateChangeConditionOp, }; use bios_mw_flow::dto::flow_var_dto::{FlowVarInfo, RbumDataTypeKind, RbumWidgetTypeKind}; @@ -179,6 +182,31 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli let trans_complate = req_model_agg.states.iter().find(|state| state.name == "进行中").unwrap().transitions.iter().find(|trans| trans.name == "完成").unwrap(); let trans_close = req_model_agg.states.iter().find(|state| state.name == "进行中").unwrap().transitions.iter().find(|trans| trans.name == "关闭").unwrap(); + let _: Void = flow_client + .patch( + &format!("/cc/model/{}", req_model_id), + &json!({ + "modify_transitions": [ + { + "id": trans_start.id.clone(), + "action_by_front_changes": [ + { + "op": "in", + "op_label": "包含", + "left_value": "status", + "left_label": "状态", + "right_value": "select_field", + "select_field": "status", + "change_content": null, + "select_field_label": "status", + "change_content_label": null + } + ] + } + ] + }), + ) + .await; let _: Void = flow_client .patch( &format!("/cc/model/{}", req_model_id), @@ -218,7 +246,6 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli ]), action_by_pre_callback: None, action_by_post_callback: None, - action_by_front_changes: None, action_by_post_changes: Some(vec![FlowTransitionActionChangeInfo { kind: FlowTransitionActionChangeKind::State, describe: "".to_string(), @@ -242,6 +269,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli is_open: true, content: Some("再次确认该操作生效".to_string()), }), + action_by_front_changes: None, sort: None, }, FlowTransitionModifyReq { @@ -304,6 +332,23 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli }, ) .await; + let _: Void = flow_client + .post( + &format!("/cc/model/{}/resort_transition", &req_model_id), + &FlowTransitionSortStatesReq { + sort_states: vec![ + FlowTransitionSortStateInfoReq { + id: req_model_agg.states.iter().find(|state| state.name == "待开始").unwrap().transitions.iter().find(|trans| trans.name == "开始").unwrap().id.clone(), + sort: 2, + }, + FlowTransitionSortStateInfoReq { + id: req_model_agg.states.iter().find(|state| state.name == "待开始").unwrap().transitions.iter().find(|trans| trans.name == "关闭").unwrap().id.clone(), + sort: 1, + }, + ], + }, + ) + .await; // 3-3. check post action endless loop let proj_trans = proj_model_agg.states.iter().find(|state| state.name == "进行中").unwrap().transitions.iter().find(|trans| trans.name == "有风险").unwrap(); let _: Void = flow_client @@ -619,8 +664,10 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli let next_transitions: Vec = flow_client.put(&format!("/cc/inst/{}/transition/next", req_inst_id1), &FlowInstFindNextTransitionsReq { vars: None }).await; assert_eq!(next_transitions.len(), 2); - assert!(next_transitions.iter().any(|trans| trans.next_flow_transition_name.contains("开始"))); - assert!(next_transitions.iter().any(|trans| trans.next_flow_transition_name.contains("关闭"))); + assert_eq!(next_transitions[0].next_flow_transition_name, "关闭"); + assert_eq!(next_transitions[1].next_flow_transition_name, "开始-modify"); + // assert!(next_transitions.iter().any(|trans| trans.next_flow_transition_name.contains("开始"))); + // assert!(next_transitions.iter().any(|trans| trans.next_flow_transition_name.contains("关闭"))); // Find the state and transfer information of the specified instances in batch let state_and_next_transitions: Vec = flow_client .put( diff --git a/spi/spi-log/src/serv/pg/log_pg_initializer.rs b/spi/spi-log/src/serv/pg/log_pg_initializer.rs index 7b76df210..d5b7fc8ba 100644 --- a/spi/spi-log/src/serv/pg/log_pg_initializer.rs +++ b/spi/spi-log/src/serv/pg/log_pg_initializer.rs @@ -36,5 +36,5 @@ pub async fn init_table_and_conn(bs_inst: TypedSpiBsInst<'_, TardisRelDBClient>, None, None, ) - .await + .await } diff --git a/spi/spi-log/src/serv/pg/log_pg_item_serv.rs b/spi/spi-log/src/serv/pg/log_pg_item_serv.rs index c6412f133..cef2b198b 100644 --- a/spi/spi-log/src/serv/pg/log_pg_item_serv.rs +++ b/spi/spi-log/src/serv/pg/log_pg_item_serv.rs @@ -1,8 +1,8 @@ use tardis::{ basic::{dto::TardisContext, result::TardisResult}, db::{reldb_client::TardisRelDBClient, sea_orm::Value}, - TardisFuns, - TardisFunsInst, web::web_resp::TardisPage, + web::web_resp::TardisPage, + TardisFuns, TardisFunsInst, }; use bios_basic::{basic_enumeration::BasicQueryOpKind, dto::BasicQueryCondInfo, helper::db_helper, spi::spi_funs::SpiBsInst}; @@ -47,7 +47,7 @@ VALUES ), params, ) - .await?; + .await?; conn.commit().await?; Ok(id) } @@ -127,7 +127,7 @@ pub async fn find(find_req: &mut LogItemFindReq, funs: &TardisFunsInst, ctx: &Ta Err(funs.err().not_found( "item", "log", - &format!("The ext field=[{}] value=[{}] operation=[{}] is not legal.", &ext.field, ext.value, &ext.op, ), + &format!("The ext field=[{}] value=[{}] operation=[{}] is not legal.", &ext.field, ext.value, &ext.op,), "404-spi-log-op-not-legal", )) }; @@ -274,7 +274,7 @@ ORDER BY ts DESC where_fragments.join(" AND "), page_fragments ) - .as_str(), + .as_str(), sql_vals, ) .await?; From f3b4e4bcff184226ab38bae55c247465faa8717c Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Sat, 7 Oct 2023 23:31:45 -0700 Subject: [PATCH 6/6] flow:update --- middleware/flow/src/dto/flow_transition_dto.rs | 4 ++-- middleware/flow/tests/test_flow_scenes_fsm.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/middleware/flow/src/dto/flow_transition_dto.rs b/middleware/flow/src/dto/flow_transition_dto.rs index 75a4c02d2..689e68acc 100644 --- a/middleware/flow/src/dto/flow_transition_dto.rs +++ b/middleware/flow/src/dto/flow_transition_dto.rs @@ -322,8 +322,8 @@ pub struct FlowTransitionInitInfo { #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object)] pub struct FlowTransitionFrontActionInfo { - pub op: BasicQueryOpKind, - pub op_label: String, + pub relevance_relation: BasicQueryOpKind, + pub relevance_label: String, pub left_value: String, pub left_label: String, pub right_value: FlowTransitionFrontActionRightValue, diff --git a/middleware/flow/tests/test_flow_scenes_fsm.rs b/middleware/flow/tests/test_flow_scenes_fsm.rs index 567780880..afc4d154d 100644 --- a/middleware/flow/tests/test_flow_scenes_fsm.rs +++ b/middleware/flow/tests/test_flow_scenes_fsm.rs @@ -191,8 +191,8 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli "id": trans_start.id.clone(), "action_by_front_changes": [ { - "op": "in", - "op_label": "包含", + "relevance_relation": "in", + "relevance_label": "包含", "left_value": "status", "left_label": "状态", "right_value": "select_field",