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 Dec 3, 2024
2 parents 55a795a + e6e16c7 commit e685d5c
Show file tree
Hide file tree
Showing 54 changed files with 5,128 additions and 1,775 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ rust_decimal_macros = { version = "1" }
testcontainers-modules = { version = "0.11", features = ["redis"] }
strum = { version = "0.26", features = ["derive"] }
# tardis
tardis = { version = "0.1.0-rc.17" }
# tardis = { version = "0.1.0-rc.17" }
# tardis = { version = "0.2.0", path = "../tardis/tardis" }
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "9cc9b3e" }
tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "b6a63ac" }
# asteroid-mq = { git = "https://github.com/4t145/asteroid-mq.git", rev = "d59c64d" }
asteroid-mq = { git = "https://github.com/4t145/asteroid-mq.git", rev = "23cc708" }
# asteroid-mq = { version = "0.1.0-alpha.5" }
Expand Down
56 changes: 28 additions & 28 deletions backend/middlewares/flow/src/api/ca/flow_ca_model_api.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use std::collections::HashMap;

use bios_basic::rbum::{helper::rbum_scope_helper, rbum_enumeration::RbumScopeLevelKind};
use tardis::{
basic::dto::TardisContext,
web::{
context_extractor::TardisContextExtractor,
poem::{web::Json, Request},
poem_openapi,
web_resp::{TardisApiResult, TardisResp},
},
use tardis::web::{
context_extractor::TardisContextExtractor,
poem::{web::Json, Request},
poem_openapi,
web_resp::{TardisApiResult, TardisResp},
};

use crate::{
dto::flow_model_dto::{FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceReq, FlowModelSingleCopyOrReferenceReq},
dto::flow_model_dto::{FlowModelAggResp, FlowModelCopyOrReferenceReq, FlowModelKind, FlowModelSingleCopyOrReferenceReq},
flow_constants,
serv::{flow_inst_serv::FlowInstServ, flow_model_serv::FlowModelServ},
};
Expand All @@ -37,16 +33,18 @@ impl FlowCaModelApi {
funs.begin().await?;
let _orginal_models = FlowModelServ::clean_rel_models(None, None, None, &funs, &ctx.0).await?;
let mut result = HashMap::new();
let mock_ctx = match req.0.op {
FlowModelAssociativeOperationKind::Copy => ctx.0.clone(),
FlowModelAssociativeOperationKind::Reference => TardisContext {
own_paths: rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &ctx.0.own_paths).unwrap_or_default(),
..ctx.0.clone()
},
};
for (_, rel_model_id) in req.0.rel_model_ids {
let new_model = FlowModelServ::copy_or_reference_model(&rel_model_id, Some(ctx.0.own_paths.clone()), &req.0.op, Some(false), &funs, &mock_ctx).await?;
FlowInstServ::batch_update_when_switch_model(None, &new_model.tag, &new_model.id, new_model.states.clone(), &new_model.init_state_id, &funs, &ctx.0).await?;
let new_model = FlowModelServ::copy_or_reference_model(&rel_model_id, &req.0.op, FlowModelKind::AsModel, &funs, &ctx.0).await?;
FlowInstServ::batch_update_when_switch_model(
None,
&new_model.tag,
&new_model.current_version_id,
new_model.states.clone(),
&new_model.init_state_id,
&funs,
&ctx.0,
)
.await?;

result.insert(rel_model_id.clone(), new_model);
}
Expand All @@ -69,15 +67,17 @@ impl FlowCaModelApi {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let _orginal_models = FlowModelServ::clean_rel_models(None, None, Some(vec![req.0.tag.clone()]), &funs, &ctx.0).await?;
let mock_ctx = match req.0.op {
FlowModelAssociativeOperationKind::Copy => ctx.0.clone(),
FlowModelAssociativeOperationKind::Reference => TardisContext {
own_paths: rbum_scope_helper::get_path_item(RbumScopeLevelKind::L1.to_int(), &ctx.0.own_paths).unwrap_or_default(),
..ctx.0.clone()
},
};
let new_model = FlowModelServ::copy_or_reference_model(&req.0.rel_model_id, Some(ctx.0.own_paths.clone()), &req.0.op, Some(false), &funs, &mock_ctx).await?;
FlowInstServ::batch_update_when_switch_model(None, &new_model.tag, &new_model.id, new_model.states.clone(), &new_model.init_state_id, &funs, &ctx.0).await?;
let new_model = FlowModelServ::copy_or_reference_model(&req.0.rel_model_id, &req.0.op, FlowModelKind::AsModel, &funs, &ctx.0).await?;
FlowInstServ::batch_update_when_switch_model(
None,
&new_model.tag,
&new_model.current_version_id,
new_model.states.clone(),
&new_model.init_state_id,
&funs,
&ctx.0,
)
.await?;

funs.commit().await?;
ctx.0.execute_task().await?;
Expand Down
1 change: 1 addition & 0 deletions backend/middlewares/flow/src/api/cc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod flow_cc_inst_api;
pub mod flow_cc_model_api;
pub mod flow_cc_model_version_api;
pub mod flow_cc_state_api;
70 changes: 54 additions & 16 deletions backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};
use crate::dto::flow_external_dto::FlowExternalCallbackOp;
use crate::dto::flow_inst_dto::{
FlowInstAbortReq, FlowInstDetailResp, FlowInstFindNextTransitionResp, FlowInstFindNextTransitionsReq, FlowInstFindStateAndTransitionsReq, FlowInstFindStateAndTransitionsResp,
FlowInstModifyAssignedReq, FlowInstModifyCurrentVarsReq, FlowInstStartReq, FlowInstSummaryResp, FlowInstTransferReq, FlowInstTransferResp,
FlowInstModifyAssignedReq, FlowInstModifyCurrentVarsReq, FlowInstOperateReq, FlowInstStartReq, FlowInstSummaryResp, FlowInstTransferReq, FlowInstTransferResp,
};
use crate::flow_constants;
use crate::helper::loop_check_helper;
Expand All @@ -27,10 +27,8 @@ impl FlowCcInstApi {
/// 启动实例(返回实例ID)
#[oai(path = "/", method = "post")]
async fn start(&self, add_req: Json<FlowInstStartReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<String> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let funs = flow_constants::get_tardis_inst();
let result = FlowInstServ::start(&add_req.0, None, &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}
Expand Down Expand Up @@ -66,8 +64,10 @@ impl FlowCcInstApi {
async fn paginate(
&self,
flow_model_id: Query<Option<String>>,
rel_business_obj_id: Query<Option<String>>,
tag: Query<Option<String>>,
finish: Query<Option<bool>>,
main: Query<Option<bool>>,
current_state_id: Query<Option<String>>,
with_sub: Query<Option<bool>>,
page_number: Query<u32>,
Expand All @@ -76,7 +76,20 @@ impl FlowCcInstApi {
_request: &Request,
) -> TardisApiResult<TardisPage<FlowInstSummaryResp>> {
let funs = flow_constants::get_tardis_inst();
let result = FlowInstServ::paginate(flow_model_id.0, tag.0, finish.0, current_state_id.0, with_sub.0, page_number.0, page_size.0, &funs, &ctx.0).await?;
let result = FlowInstServ::paginate(
flow_model_id.0,
tag.0,
finish.0,
main.0,
current_state_id.0,
rel_business_obj_id.0,
with_sub.0,
page_number.0,
page_size.0,
&funs,
&ctx.0,
)
.await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}
Expand All @@ -93,7 +106,8 @@ impl FlowCcInstApi {
_request: &Request,
) -> TardisApiResult<Vec<FlowInstFindNextTransitionResp>> {
let funs = flow_constants::get_tardis_inst();
let result = FlowInstServ::find_next_transitions(&flow_inst_id.0, &next_req.0, &funs, &ctx.0).await?;
let inst = FlowInstServ::get(&flow_inst_id.0, &funs, &ctx.0).await?;
let result = FlowInstServ::find_next_transitions(&inst, &next_req.0, &funs, &ctx.0).await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}
Expand Down Expand Up @@ -125,18 +139,22 @@ impl FlowCcInstApi {
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<FlowInstTransferResp> {
let funs = flow_constants::get_tardis_inst();
let mut funs = flow_constants::get_tardis_inst();
let mut transfer = transfer_req.0;
FlowInstServ::check_transfer_vars(&flow_inst_id.0, &mut transfer, &funs, &ctx.0).await?;
let inst = FlowInstServ::get(&flow_inst_id.0, &funs, &ctx.0).await?;
FlowInstServ::check_transfer_vars(&inst, &mut transfer, &funs, &ctx.0).await?;
funs.begin().await?;
let result = FlowInstServ::transfer(
&flow_inst_id.0,
&inst,
&transfer,
false,
FlowExternalCallbackOp::Default,
loop_check_helper::InstancesTransition::default(),
&ctx.0,
&funs,
)
.await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(result)
}
Expand All @@ -156,21 +174,23 @@ impl FlowCcInstApi {
let mut result = vec![];
let flow_inst_ids: Vec<_> = flow_inst_ids.split(',').collect();
let raw_transfer_req = transfer_req.0;
let mut flow_inst_id_transfer_map = HashMap::new();
let mut flow_inst_transfer = vec![];
for flow_inst_id in &flow_inst_ids {
let mut transfer_req = raw_transfer_req.clone();
FlowInstServ::check_transfer_vars(flow_inst_id, &mut transfer_req, &funs, &ctx.0).await?;
flow_inst_id_transfer_map.insert(flow_inst_id, transfer_req);
let inst = FlowInstServ::get(flow_inst_id, &funs, &ctx.0).await?;
FlowInstServ::check_transfer_vars(&inst, &mut transfer_req, &funs, &ctx.0).await?;
flow_inst_transfer.push((inst, transfer_req));
}
for (flow_inst_id, transfer_req) in flow_inst_id_transfer_map {
for (inst, transfer_req) in flow_inst_transfer {
result.push(
FlowInstServ::transfer(
flow_inst_id,
&inst,
&transfer_req,
false,
FlowExternalCallbackOp::Default,
loop_check_helper::InstancesTransition::default(),
&ctx.0,
&funs,
)
.await?,
);
Expand All @@ -190,8 +210,10 @@ impl FlowCcInstApi {
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
let funs = flow_constants::get_tardis_inst();
let vars = HashMap::from([("current_assigned".to_string(), Value::String(modify_req.0.current_assigned))]);
FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, loop_check_helper::InstancesTransition::default(), &ctx.0).await?;
let inst = FlowInstServ::get(&flow_inst_id.0, &funs, &ctx.0).await?;
FlowInstServ::modify_current_vars(&inst, &vars, loop_check_helper::InstancesTransition::default(), &ctx.0).await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}
Expand All @@ -207,7 +229,23 @@ impl FlowCcInstApi {
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, loop_check_helper::InstancesTransition::default(), &ctx.0).await?;
let funs = flow_constants::get_tardis_inst();
let inst = FlowInstServ::get(&flow_inst_id.0, &funs, &ctx.0).await?;
FlowInstServ::modify_current_vars(&inst, &modify_req.0.vars, loop_check_helper::InstancesTransition::default(), &ctx.0).await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}

/// operate flow instance
///
/// 执行实例的操作
#[oai(path = "/:flow_inst_id/operate", method = "post")]
async fn operate(&self, flow_inst_id: Path<String>, operate_req: Json<FlowInstOperateReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
let inst = FlowInstServ::get(&flow_inst_id.0, &funs, &ctx.0).await?;
funs.begin().await?;
FlowInstServ::operate(&inst, &operate_req.0, &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}
Expand Down
Loading

0 comments on commit e685d5c

Please sign in to comment.