Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ideal-world/bios
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Sep 23, 2024
2 parents 9326b5c + 4257bf9 commit 8b4bdc9
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 198 deletions.
18 changes: 15 additions & 3 deletions backend/middlewares/flow/src/api/ci/flow_ci_inst_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::collections::HashMap;

use bios_basic::rbum::helper::rbum_scope_helper::check_without_owner_and_unsafe_fill_ctx;
use itertools::Itertools;
use tardis::chrono::Utc;
use tardis::log::debug;
use tardis::serde_json::Value;
use tardis::web::context_extractor::TardisContextExtractor;
Expand All @@ -13,8 +15,7 @@ use tardis::{log, tokio};

use crate::dto::flow_external_dto::FlowExternalCallbackOp;
use crate::dto::flow_inst_dto::{
FlowInstAbortReq, FlowInstBatchBindReq, FlowInstBatchBindResp, FlowInstBindReq, FlowInstDetailResp, FlowInstFindStateAndTransitionsReq, FlowInstFindStateAndTransitionsResp,
FlowInstModifyAssignedReq, FlowInstModifyCurrentVarsReq, FlowInstStartReq, FlowInstTransferReq, FlowInstTransferResp,
FlowInstAbortReq, FlowInstBatchBindReq, FlowInstBatchBindResp, FlowInstBindReq, FlowInstDetailResp, FlowInstFindNextTransitionsReq, FlowInstFindStateAndTransitionsReq, FlowInstFindStateAndTransitionsResp, FlowInstModifyAssignedReq, FlowInstModifyCurrentVarsReq, FlowInstStartReq, FlowInstTransferReq, FlowInstTransferResp, FlowInstTransitionInfo, FlowOperationContext
};
use crate::flow_constants;
use crate::helper::loop_check_helper;
Expand Down Expand Up @@ -46,7 +47,18 @@ impl FlowCiInstApi {
async fn get(&self, flow_inst_id: Path<String>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<FlowInstDetailResp> {
let funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
let result = FlowInstServ::get(&flow_inst_id.0, &funs, &ctx.0).await?;
let mut result = FlowInstServ::get(&flow_inst_id.0, &funs, &ctx.0).await?;
// @TODO 临时处理方式,后续需增加接口
result.transitions = Some(
FlowInstServ::find_next_transitions(&flow_inst_id.0, &FlowInstFindNextTransitionsReq {
vars: None,
}, &funs, &ctx.0).await?.into_iter().map(|tran| FlowInstTransitionInfo {
id: tran.next_flow_transition_id,
start_time: Utc::now(),
op_ctx: FlowOperationContext::default(),
output_message: Some(tran.next_flow_transition_name),
}).collect_vec()
);
ctx.0.execute_task().await?;
TardisResp::ok(result)
}
Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/dto/flow_inst_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub struct FlowInstTransitionInfo {
}

/// 操作上下文信息
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Default, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowOperationContext {
pub own_paths: String,
pub ak: String,
Expand Down
9 changes: 6 additions & 3 deletions backend/middlewares/flow/src/dto/flow_transition_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub struct FlowTransitionSortStateInfoReq {
}

/// 后置动作配置信息
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Default, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowTransitionPostActionInfo {
/// 后置动作类型,目前有状态修改和字段修改两种。
pub kind: FlowTransitionActionChangeKind,
Expand All @@ -318,6 +318,9 @@ pub struct FlowTransitionPostActionInfo {
pub changed_val: Option<Value>,
/// 修改方式(清空,更改内容,更改为其他字段的值,加减值等)
pub changed_kind: Option<FlowTransitionActionByVarChangeInfoChangedKind>,

/// 是否可修改(前端用于判断当前配置是否可编辑)
pub is_edit: Option<bool>,
}

impl From<FlowTransitionPostActionInfo> for FlowTransitionActionChangeAgg {
Expand Down Expand Up @@ -364,10 +367,11 @@ pub struct FlowTransitionActionChangeAgg {
}

/// 后置动作类型,目前有状态修改和字段修改两种。
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, EnumIter, sea_orm::DeriveActiveEnum)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Default, Serialize, poem_openapi::Enum, EnumIter, sea_orm::DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(Some(255))")]
pub enum FlowTransitionActionChangeKind {
/// 字段修改
#[default]
#[sea_orm(string_value = "var")]
Var,
/// 状态变更
Expand Down Expand Up @@ -543,7 +547,6 @@ impl TryFrom<FlowTransitionInitInfo> for FlowTransitionAddReq {
action_by_post_changes: Some(value.action_by_post_changes),
action_by_front_changes: Some(value.action_by_front_changes),
double_check: value.double_check,

sort: value.sort,
})
}
Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/serv/flow_config_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl FlowConfigServ {

pub async fn get_config(funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<Option<TardisPage<KvItemSummaryResp>>> {
let prefix = format!("{}:config:", flow_constants::DOMAIN_CODE);
let mut result = SpiKvClient::match_items_by_key_prefix(prefix.clone(), None, 1, 100, Some(true), funs, ctx).await?;
let mut result = SpiKvClient::match_items_by_key_prefix(prefix.clone(), None, 1, 100, Some(false), funs, ctx).await?;
result.as_mut().map(|configs| configs.records.iter_mut().map(|config| config.key = config.key.replace(&prefix, "")).collect::<Vec<_>>());
Ok(result)
}
Expand Down
75 changes: 58 additions & 17 deletions backend/middlewares/flow/src/serv/flow_model_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
FlowModelModifyReq, FlowModelSummaryResp,
},
flow_state_dto::{FlowStateAggResp, FlowStateDetailResp, FlowStateFilterReq, FlowStateRelModelExt, FlowStateRelModelModifyReq},
flow_transition_dto::{FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionInitInfo, FlowTransitionModifyReq},
flow_transition_dto::{FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionInitInfo, FlowTransitionModifyReq, FlowTransitionPostActionInfo},
},
flow_config::FlowBasicInfoManager,
flow_constants,
Expand Down Expand Up @@ -116,16 +116,18 @@ impl RbumItemCrudOperation<flow_model::ActiveModel, FlowModelAddReq, FlowModelMo
.collect::<TardisResult<Vec<()>>>()?;
}
if let Some(transitions) = &add_req.transitions {
Self::add_transitions(flow_model_id, transitions, funs, ctx).await?;
// check transition post action endless loop
let model_desp = Self::get_item(flow_model_id, &FlowModelFilterReq::default(), funs, ctx).await?;
if Self::check_post_action_ring(&model_desp, funs, ctx).await? {
return Err(funs.err().not_found(
"flow_model_Serv",
"after_add_item",
"this post action exist endless loop",
"500-flow-transition-endless-loop",
));
if !transitions.is_empty() {
Self::add_transitions(flow_model_id, transitions, funs, ctx).await?;
// check transition post action endless loop
let model_desp = Self::get_item(flow_model_id, &FlowModelFilterReq::default(), funs, ctx).await?;
if Self::check_post_action_ring(&model_desp, funs, ctx).await? {
return Err(funs.err().not_found(
"flow_model_Serv",
"after_add_item",
"this post action exist endless loop",
"500-flow-transition-endless-loop",
));
}
}
}
if add_req.template && add_req.rel_model_id.is_none() {
Expand Down Expand Up @@ -327,6 +329,15 @@ impl RbumItemCrudOperation<flow_model::ActiveModel, FlowModelAddReq, FlowModelMo
};
let child_model_transitions = child_model.transitions();
let mut modify_req_clone = modify_req.clone();
if let Some(ref mut add_transitions) = &mut modify_req_clone.add_transitions {
for add_transition in add_transitions.iter_mut() {
if let Some(ref mut action_by_post_changes) = &mut add_transition.action_by_post_changes {
for action_by_post_change in action_by_post_changes.iter_mut() {
action_by_post_change.is_edit = Some(false); // 引用复制时,置为不可编辑
}
}
}
}
if let Some(ref mut modify_transitions) = &mut modify_req_clone.modify_transitions {
for modify_transition in modify_transitions.iter_mut() {
let parent_model_transition = parent_model_transitions.iter().find(|trans| trans.id == modify_transition.id.to_string()).unwrap();
Expand Down Expand Up @@ -954,7 +965,25 @@ impl FlowModelServ {
name: state_name,
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(),
transitions: model_detail.transitions().into_iter().filter(|transition| transition.from_flow_state_id == state_id.clone()).map(|transition| {
let mut action_by_post_changes = vec![];
for action_by_post_change in transition.action_by_post_changes() {
if action_by_post_change.is_edit.is_none() {
action_by_post_changes.push(FlowTransitionPostActionInfo {
is_edit: Some(false), // 默认为不可编辑,若用户需要编辑,可手动处理数据
..action_by_post_change.clone()
});
} else {
action_by_post_changes.push(FlowTransitionPostActionInfo {
..action_by_post_change.clone()
});
}
}
FlowTransitionDetailResp {
action_by_post_changes: TardisFuns::json.obj_to_json(&action_by_post_changes).unwrap_or_default(),
..transition.clone()
}
}).collect_vec(),
};
states.push(state_detail);
}
Expand Down Expand Up @@ -1097,10 +1126,19 @@ impl FlowModelServ {
let result = match op {
FlowModelAssociativeOperationKind::Reference => {
if is_create_copy.unwrap_or(false) {
let mut add_transitions = rel_model.transitions().into_iter().map(FlowTransitionAddReq::from).collect_vec();
for add_transition in add_transitions.iter_mut() {
if let Some(ref mut action_by_post_changes) = &mut add_transition.action_by_post_changes {
for action_by_post_change in action_by_post_changes.iter_mut() {
action_by_post_change.is_edit = Some(false); // 引用复制时,置为不可编辑
}
}
}
Self::add_item(
&mut FlowModelAddReq {
rel_model_id: Some(rel_model_id.to_string()),
rel_template_ids: None,
transitions: Some(add_transitions),
..rel_model.clone().into()
},
funs,
Expand Down Expand Up @@ -1290,12 +1328,12 @@ impl FlowModelServ {
Ok(())
}

pub async fn bind_state(flow_model_id: &str, req: &FlowModelBindStateReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
async fn bind_state(flow_model_id: &str, req: &FlowModelBindStateReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let global_ctx = TardisContext {
own_paths: "".to_string(),
..ctx.clone()
};
if FlowStateServ::get_item(
if let Ok(state) = FlowStateServ::get_item(
&req.state_id,
&FlowStateFilterReq {
basic: RbumBasicFilterReq {
Expand All @@ -1307,9 +1345,12 @@ impl FlowModelServ {
funs,
&global_ctx,
)
.await
.is_err()
{
.await {
let model_detail = Self::get_item(flow_model_id, &FlowModelFilterReq::default(), funs, ctx).await?;
if !state.tags.is_empty() && !state.tags.split(',').collect_vec().contains(&model_detail.tag.as_str()) {
return Err(funs.err().internal_error("flow_model_serv", "bind_state", "The flow state is not found", "404-flow-state-not-found"));
}
} else {
return Err(funs.err().internal_error("flow_model_serv", "bind_state", "The flow state is not found", "404-flow-state-not-found"));
}
FlowRelServ::add_simple_rel(
Expand Down
Loading

0 comments on commit 8b4bdc9

Please sign in to comment.