Skip to content

Commit

Permalink
flow: update dto (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Oct 9, 2023
1 parent ec4ed92 commit 01b0194
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 16 deletions.
9 changes: 3 additions & 6 deletions middleware/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
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};
Expand All @@ -9,7 +6,7 @@ use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};

use crate::dto::flow_inst_dto::{
FlowInstAbortReq, FlowInstDetailResp, FlowInstFindNextTransitionResp, FlowInstFindNextTransitionsReq, FlowInstFindStateAndTransitionsReq, FlowInstFindStateAndTransitionsResp,
FlowInstModifyAssignedReq, FlowInstStartReq, FlowInstSummaryResp, FlowInstTransferReq, FlowInstTransferResp,
FlowInstModifyAssignedReq, FlowInstModifyCurrentVarsReq, FlowInstStartReq, FlowInstSummaryResp, FlowInstTransferReq, FlowInstTransferResp,
};
use crate::flow_constants;
use crate::serv::flow_inst_serv::FlowInstServ;
Expand Down Expand Up @@ -112,10 +109,10 @@ impl FlowCcInstApi {

/// Modify list of variables / 同步当前变量列表
#[oai(path = "/:flow_inst_id/modify_current_vars", method = "patch")]
async fn modify_current_vars(&self, flow_inst_id: Path<String>, modify_req: Json<HashMap<String, Value>>, ctx: TardisContextExtractor) -> TardisApiResult<Void> {
async fn modify_current_vars(&self, flow_inst_id: Path<String>, modify_req: Json<FlowInstModifyCurrentVarsReq>, ctx: TardisContextExtractor) -> TardisApiResult<Void> {
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?;
FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, &funs, &ctx.0).await?;
funs.commit().await?;
TardisResp::ok(Void {})
}
Expand Down
5 changes: 5 additions & 0 deletions middleware/flow/src/dto/flow_inst_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,8 @@ pub struct FlowInstTransferResp {
pub struct FlowInstModifyAssignedReq {
pub current_assigned: String,
}

#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct FlowInstModifyCurrentVarsReq {
pub vars: HashMap<String, Value>,
}
59 changes: 56 additions & 3 deletions middleware/flow/src/dto/flow_transition_dto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bios_basic::{basic_enumeration::BasicQueryOpKind, dto::BasicQueryCondInfo};
use bios_basic::dto::BasicQueryCondInfo;
use serde::{Deserialize, Serialize};
use strum::Display;
use tardis::{basic::field::TrimString, db::sea_orm, serde_json::Value, web::poem_openapi, TardisFuns};

use super::flow_var_dto::FlowVarInfo;
Expand Down Expand Up @@ -322,18 +323,70 @@ pub struct FlowTransitionInitInfo {

#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object)]
pub struct FlowTransitionFrontActionInfo {
pub relevance_relation: BasicQueryOpKind,
pub relevance_relation: FlowTransitionFrontActionInfoRelevanceRelation,
pub relevance_label: String,
pub left_value: String,
pub left_label: String,
pub right_value: FlowTransitionFrontActionRightValue,
pub select_field: Option<String>,
pub select_field_label: Option<String>,
pub change_content: Option<String>,
pub change_content: Option<Value>,
pub change_content_label: Option<String>,
}

#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
pub enum FlowTransitionFrontActionInfoRelevanceRelation {
#[serde(rename = "=")]
#[oai(rename = "=")]
Eq,
#[serde(rename = "!=")]
#[oai(rename = "!=")]
Ne,
#[serde(rename = ">")]
#[oai(rename = ">")]
Gt,
#[serde(rename = ">=")]
#[oai(rename = ">=")]
Ge,
#[serde(rename = "<")]
#[oai(rename = "<")]
Lt,
#[serde(rename = "<=")]
#[oai(rename = "<=")]
Le,
#[serde(rename = "like")]
#[oai(rename = "like")]
Like,
#[serde(rename = "not_like")]
#[oai(rename = "not_like")]
NotLike,
#[serde(rename = "in")]
#[oai(rename = "in")]
In,
#[serde(rename = "not_in")]
#[oai(rename = "not_in")]
NotIn,
}

impl FlowTransitionFrontActionInfoRelevanceRelation {
pub fn check_conform(&self, left_value: String, right_value: String) -> bool {
match self {
FlowTransitionFrontActionInfoRelevanceRelation::Eq => left_value == right_value,
FlowTransitionFrontActionInfoRelevanceRelation::Ne => left_value != right_value,
FlowTransitionFrontActionInfoRelevanceRelation::Gt => left_value > right_value,
FlowTransitionFrontActionInfoRelevanceRelation::Ge => left_value >= right_value,
FlowTransitionFrontActionInfoRelevanceRelation::Lt => left_value < right_value,
FlowTransitionFrontActionInfoRelevanceRelation::Le => left_value <= right_value,
FlowTransitionFrontActionInfoRelevanceRelation::Like => left_value.contains(&right_value),
FlowTransitionFrontActionInfoRelevanceRelation::NotLike => !left_value.contains(&right_value),
FlowTransitionFrontActionInfoRelevanceRelation::In => TardisFuns::json.str_to_obj::<Vec<String>>(&right_value).unwrap_or_default().contains(&left_value),
FlowTransitionFrontActionInfoRelevanceRelation::NotIn => !TardisFuns::json.str_to_obj::<Vec<String>>(&right_value).unwrap_or_default().contains(&left_value),
}
}
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Enum)]
#[serde(rename_all = "snake_case")]
pub enum FlowTransitionFrontActionRightValue {
#[oai(rename = "select_field")]
SelectField,
Expand Down
77 changes: 76 additions & 1 deletion middleware/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::{
flow_state_dto::{FlowStateFilterReq, FlowStateRelModelExt, FlowSysStateKind},
flow_transition_dto::{
FlowTransitionActionByStateChangeInfo, FlowTransitionActionChangeAgg, FlowTransitionActionChangeInfo, FlowTransitionActionChangeKind, FlowTransitionDetailResp,
StateChangeConditionOp,
FlowTransitionFrontActionInfo, FlowTransitionFrontActionRightValue, StateChangeConditionOp,
},
},
serv::{flow_model_serv::FlowModelServ, flow_state_serv::FlowStateServ},
Expand Down Expand Up @@ -1185,4 +1185,79 @@ impl FlowInstServ {

Ok(())
}

async fn do_front_change(flow_inst_detail: &FlowInstDetailResp, ctx: &TardisContext, funs: &TardisFunsInst) -> TardisResult<()> {
let flow_model = FlowModelServ::get_item(
&flow_inst_detail.rel_flow_model_id,
&FlowModelFilterReq {
basic: RbumBasicFilterReq {
with_sub_own_paths: true,
own_paths: Some("".to_string()),
..Default::default()
},
..Default::default()
},
funs,
ctx,
)
.await?;
let flow_transitions = flow_model
.transitions()
.into_iter()
.filter(|trans| trans.from_flow_state_id == flow_inst_detail.current_state_id && !trans.action_by_front_changes().is_empty())
.collect_vec();
if flow_transitions.is_empty() {
return Ok(());
}

Ok(())
}

async fn check_front_conditions(
flow_inst_detail: &FlowInstDetailResp,
conditions: Vec<FlowTransitionFrontActionInfo>,
ctx: &TardisContext,
funs: &TardisFunsInst,
) -> TardisResult<bool> {
if flow_inst_detail.current_vars.is_none() {
return Ok(false);
}
let current_vars = flow_inst_detail.current_vars.clone().unwrap();
for condition in conditions {
if !Self::do_check_front_condition(&current_vars, &condition)? {
return Ok(false);
}
}

Ok(true)
}

fn do_check_front_condition(current_vars: &HashMap<String, Value>, condition: &FlowTransitionFrontActionInfo) -> TardisResult<bool> {
match condition.right_value {
FlowTransitionFrontActionRightValue::ChangeContent => {
if let Some(left_value) = current_vars.get(&condition.left_value) {
Ok(condition.relevance_relation.check_conform(left_value.to_string(), condition.change_content.clone().unwrap_or_default().to_string()))
} else {
Ok(false)
}
}
FlowTransitionFrontActionRightValue::SelectField => {
if let (Some(left_value), Some(right_value)) = (
current_vars.get(&condition.left_value),
current_vars.get(&condition.select_field.clone().unwrap_or_default()),
) {
Ok(condition.relevance_relation.check_conform(left_value.to_string(), right_value.to_string()))
} else {
Ok(false)
}
}
FlowTransitionFrontActionRightValue::RealTime => {
if let Some(left_value) = current_vars.get(&condition.left_value) {
Ok(condition.relevance_relation.check_conform(left_value.to_string(), Utc::now().to_string()))
} else {
Ok(false)
}
}
}
}
}
9 changes: 3 additions & 6 deletions middleware/flow/tests/test_flow_scenes_fsm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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;

Expand All @@ -16,9 +14,8 @@ 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, FlowTransitionFrontActionInfo,
FlowTransitionFrontActionRightValue, FlowTransitionModifyReq, FlowTransitionSortStateInfoReq, FlowTransitionSortStatesReq, StateChangeCondition, StateChangeConditionItem,
StateChangeConditionOp,
FlowTransitionActionChangeInfo, FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDoubleCheckInfo, FlowTransitionModifyReq, FlowTransitionSortStateInfoReq,
FlowTransitionSortStatesReq, StateChangeCondition, StateChangeConditionItem, StateChangeConditionOp,
};

use bios_mw_flow::dto::flow_var_dto::{FlowVarInfo, RbumDataTypeKind, RbumWidgetTypeKind};
Expand Down Expand Up @@ -191,7 +188,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli
"id": trans_start.id.clone(),
"action_by_front_changes": [
{
"relevance_relation": "in",
"relevance_relation": "=",
"relevance_label": "包含",
"left_value": "status",
"left_label": "状态",
Expand Down

0 comments on commit 01b0194

Please sign in to comment.