Skip to content

Commit

Permalink
flow: fix bug (instance update failed)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 committed Dec 10, 2024
1 parent fd720c3 commit f778972
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
4 changes: 2 additions & 2 deletions backend/middlewares/flow/src/api/cc/flow_cc_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl FlowCcModelApi {
.sort_states
.into_iter()
.map(|state| FlowModelVersionModifyState {
id: state.state_id.clone(),
id: Some(state.state_id.clone()),
modify_rel: Some(FlowStateRelModelModifyReq {
id: state.state_id,
sort: Some(state.sort),
Expand Down Expand Up @@ -362,7 +362,7 @@ impl FlowCcModelApi {
&mut FlowModelModifyReq {
modify_version: Some(FlowModelVersionModifyReq {
modify_states: Some(vec![FlowModelVersionModifyState {
id: req.0.id.clone(),
id: Some(req.0.id.clone()),
modify_rel: Some(req.0),
modify_state: None,
add_transitions: None,
Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/dto/flow_model_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl FlowModelDetailResp {
}

pub fn rel_transition(&self) -> Option<FlowModelRelTransitionExt> {
self.rel_transition.clone().map(|rel_transition| TardisFuns::json.json_to_obj(rel_transition.clone()).unwrap())
self.rel_transition.clone().map(|rel_transition| TardisFuns::json.json_to_obj(rel_transition).unwrap_or_default())
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/dto/flow_model_version_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct FlowModelVersionBindState {
#[derive(Clone, Serialize, Deserialize, Debug, Default, poem_openapi::Object)]
pub struct FlowModelVersionModifyState {
/// 若存在则表示,绑定已有状态节点
pub id: String,
pub id: Option<String>,
pub modify_state: Option<FlowStateModifyReq>,
pub modify_rel: Option<FlowStateRelModelModifyReq>,
/// 添加动作
Expand Down
19 changes: 14 additions & 5 deletions backend/middlewares/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ impl FlowInstServ {
..Default::default()
};
funs.db().update_one(flow_inst, ctx).await?;

let flow_inst_detail = Self::get(flow_inst_id, funs, ctx).await?;
if !flow_inst_detail.main {
FlowSearchClient::modify_business_obj_search(&flow_inst_detail.rel_business_obj_id, &flow_inst_detail.tag, funs, ctx).await?;
}
Ok(())
}

Expand Down Expand Up @@ -588,7 +593,7 @@ impl FlowInstServ {
)
.await;
// 若当前数据项存在未结束的审批流,则清空其中的transitions
let unfinished_approve_flow_insts = Self::find_details(
let unfinished_approve_flow_inst_ids = Self::find_details(
&FlowInstFilterReq {
rel_business_obj_ids: Some(flow_insts.iter().map(|flow_inst| flow_inst.rel_business_obj_id.clone()).collect_vec()),
main: Some(false),
Expand All @@ -600,13 +605,13 @@ impl FlowInstServ {
)
.await?
.into_iter()
.map(|inst| inst.id.clone())
.map(|inst| flow_insts.iter().find(|flow_inst| flow_inst.rel_business_obj_id == inst.rel_business_obj_id).unwrap().id.clone())
.collect_vec();
let _ = state_and_next_transitions.iter_mut().map(|item| {
if unfinished_approve_flow_insts.contains(&item.flow_inst_id) {
for item in state_and_next_transitions.iter_mut() {
if unfinished_approve_flow_inst_ids.contains(&item.flow_inst_id) {
item.next_flow_transitions.clear();
}
});
}
Ok(state_and_next_transitions)
}

Expand Down Expand Up @@ -869,6 +874,10 @@ impl FlowInstServ {

funs.db().update_one(flow_inst, ctx).await?;

if next_flow_state.sys_state == FlowSysStateKind::Finish && !flow_inst_detail.main {
FlowSearchClient::modify_business_obj_search(&flow_inst_detail.rel_business_obj_id, &flow_inst_detail.tag, funs, ctx).await?;
}

Self::when_leave_state(flow_inst_detail, &prev_flow_state.id, &flow_model_version.rel_model_id, funs, ctx).await?;
Self::when_enter_state(flow_inst_detail, &next_flow_state.id, &flow_model_version.rel_model_id, funs, ctx).await?;

Expand Down
18 changes: 14 additions & 4 deletions backend/middlewares/flow/src/serv/flow_model_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ impl RbumItemCrudOperation<flow_model::ActiveModel, FlowModelAddReq, FlowModelMo
}
let rel_transition =
FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelTransition, flow_model_id, None, None, funs, ctx).await?.into_iter().map(|rel| rel.ext).collect_vec().pop();
flow_model.rel_transition = rel_transition.map(|rel_transition| TardisFuns::json.obj_to_json(&rel_transition).unwrap_or_default());
flow_model.rel_transition = rel_transition.map(|rel_transition| TardisFuns::json.str_to_json(&rel_transition).unwrap_or_default());

Ok(flow_model)
}
Expand Down Expand Up @@ -633,7 +633,7 @@ impl RbumItemCrudOperation<flow_model::ActiveModel, FlowModelAddReq, FlowModelMo

let rel_transition =
FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelTransition, &item.id, None, None, funs, ctx).await?.into_iter().map(|rel| rel.ext).collect_vec().pop();
item.rel_transition = rel_transition.map(|rel_transition| TardisFuns::json.obj_to_json(&rel_transition).unwrap_or_default());
item.rel_transition = rel_transition.map(|rel_transition| TardisFuns::json.str_to_json(&rel_transition).unwrap_or_default());
}
Ok(res)
}
Expand Down Expand Up @@ -1648,7 +1648,17 @@ impl FlowModelServ {
Self::delete_item(&model.id, funs, ctx).await?;
}
}

// clean non-main flow model
for model_id in Self::find_id_items(&FlowModelFilterReq {
basic: RbumBasicFilterReq {
enabled: Some(true),
..Default::default()
},
main: Some(false),
..Default::default()
}, None, None, funs, ctx).await? {
Self::delete_item(&model_id, funs, ctx).await?;
}
Ok(models)
}

Expand Down Expand Up @@ -1759,7 +1769,7 @@ impl FlowModelServ {
modify_states
.into_iter()
.map(|(id, modify_transitions)| FlowModelVersionModifyState {
id: id.clone(),
id: Some(id.clone()),
modify_state: None,
modify_rel: None,
add_transitions: None,
Expand Down
13 changes: 7 additions & 6 deletions backend/middlewares/flow/src/serv/flow_model_version_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,17 @@ impl
}
if let Some(modify_states) = &modify_req.modify_states {
for modify_state in modify_states {
let state_id = &modify_state.id;
if let Some(mut modify_state) = modify_state.modify_state.clone() {
FlowStateServ::modify_item(state_id, &mut modify_state, funs, ctx).await?;
if let Some(state_id) = &modify_state.id {
if let Some(mut modify_state) = modify_state.modify_state.clone() {
FlowStateServ::modify_item(state_id, &mut modify_state, funs, ctx).await?;
}
if let Some(add_transitions) = &modify_state.add_transitions {
FlowTransitionServ::add_transitions(id, state_id, add_transitions, funs, ctx).await?;
}
}
if let Some(modify_rel) = &modify_state.modify_rel {
FlowStateServ::modify_rel_state_ext(id, modify_rel, funs, ctx).await?;
}
if let Some(add_transitions) = &modify_state.add_transitions {
FlowTransitionServ::add_transitions(id, &modify_state.id, add_transitions, funs, ctx).await?;
}
if let Some(modify_transitions) = &modify_state.modify_transitions {
FlowTransitionServ::modify_transitions(id, modify_transitions, funs, ctx).await?;
}
Expand Down
4 changes: 2 additions & 2 deletions backend/middlewares/flow/tests/test_flow_scenes_fsm1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ pub async fn test(flow_client: &mut TestHttpClient, search_client: &mut TestHttp
}]),
modify_states: Some(vec![
FlowModelVersionModifyState {
id: start_state_id.clone(),
id: Some(start_state_id.clone()),
modify_transitions: Some(vec![FlowTransitionModifyReq {
id: start_transition_id.into(),
to_flow_state_id: Some(form_state_id.clone()),
Expand All @@ -539,7 +539,7 @@ pub async fn test(flow_client: &mut TestHttpClient, search_client: &mut TestHttp
..Default::default()
},
FlowModelVersionModifyState {
id: finish_state_id.clone(),
id: Some(finish_state_id.clone()),
modify_rel: Some(FlowStateRelModelModifyReq {
id: finish_state_id.clone(),
sort: Some(2),
Expand Down

0 comments on commit f778972

Please sign in to comment.