Skip to content

Commit

Permalink
flow: add api sync_modified_field (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Dec 19, 2024
1 parent fe57706 commit 584bb1f
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 28 deletions.
16 changes: 15 additions & 1 deletion backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use crate::dto::flow_model_dto::{
FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceCiReq, FlowModelExistRelByTemplateIdsReq, FlowModelFilterReq, FlowModelFindRelStateResp,
FlowModelKind,
FlowModelKind, FlowModelSyncModifiedFieldReq,
};
use crate::flow_constants;
use crate::serv::flow_inst_serv::FlowInstServ;
Expand Down Expand Up @@ -355,4 +355,18 @@ impl FlowCiModelApi {
funs.commit().await?;
TardisResp::ok(Void)
}

/// Synchronize modified fields
///
/// 同步修改的字段
#[oai(path = "/sync_modified_field", method = "post")]
async fn sync_modified_field(&self, modify_req: Json<FlowModelSyncModifiedFieldReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
funs.begin().await?;
FlowModelServ::sync_modified_field(&modify_req.0, &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void)
}
}
2 changes: 2 additions & 0 deletions backend/middlewares/flow/src/dto/flow_inst_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ pub struct FlowInstOperateReq {
pub output_message: Option<String>,
/// 操作人
pub operator: Option<String>,
/// 日志文本
pub log_text: Option<String>,
}

/// 工作流实例过滤器
Expand Down
10 changes: 10 additions & 0 deletions backend/middlewares/flow/src/dto/flow_model_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,13 @@ pub struct FlowModelFindRelNameByTemplateIdsReq {
/// 关联的模板ID
pub rel_template_ids: Vec<String>,
}

/// 修改当前参数列表
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct FlowModelSyncModifiedFieldReq {
pub rel_template_id: Option<String>,
pub tag: String,
/// 参数列表
pub add_fields: Vec<String>,
pub delete_fields: Vec<String>,
}
6 changes: 5 additions & 1 deletion backend/middlewares/flow/src/dto/flow_state_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub struct FlowStateForm {
pub referral: bool,
/// 转办自定义人员权限
pub referral_guard_custom_conf: Option<FlowGuardConf>,
/// 新增默认字段配置
pub add_default_field: Option<FlowStateVar>,
/// 字段配置
pub vars_collect: HashMap<String, FlowStateVar>,
/// 提交动作名称
Expand Down Expand Up @@ -113,6 +115,8 @@ pub struct FlowStateApproval {
/// 转办自定义人员权限
pub referral_guard_custom: bool,
pub referral_guard_custom_conf: Option<FlowGuardConf>,
/// 新增默认字段配置
pub add_default_field: Option<FlowStateVar>,
/// 字段配置
pub vars_collect: HashMap<String, FlowStateVar>,
/// 多人审批策略方式
Expand Down Expand Up @@ -466,4 +470,4 @@ impl FromStr for FlowStateOperatorKind {
_ => Err(TardisError::bad_request(&format!("invalid FlowStateOperatorKind: {}", s), "400-operator-invalid-param")),
}
}
}
}
9 changes: 6 additions & 3 deletions backend/middlewares/flow/src/serv/clients/search_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bios_sdk_invoke::{
use itertools::Itertools;
use serde_json::json;
use tardis::{
basic::{dto::TardisContext, field::TrimString, result::TardisResult}, tokio, web::web_resp::TardisPage, TardisFuns, TardisFunsInst
basic::{dto::TardisContext, field::TrimString, result::TardisResult}, log::debug, tokio, web::web_resp::TardisPage, TardisFuns, TardisFunsInst
};

use crate::{
Expand Down Expand Up @@ -262,6 +262,7 @@ impl FlowSearchClient {
&& guard_conf.guard_by_spec_org_ids.is_empty()
&& guard_conf.guard_by_spec_role_ids.is_empty()
{
debug!("flow search_guard_account_num result : 0");
return Ok(Some(0));
}
let mut search_ctx_req = SearchItemSearchCtxReq {
Expand All @@ -278,7 +279,7 @@ impl FlowSearchClient {
if !guard_conf.guard_by_spec_role_ids.is_empty() {
search_ctx_req.roles = Some(guard_conf.guard_by_spec_role_ids.clone());
}
Ok(SpiSearchClient::search(&SearchItemSearchReq {
let result = SpiSearchClient::search(&SearchItemSearchReq {
tag: "iam_account".to_string(),
ctx: search_ctx_req,
query: SearchItemQueryReq { ..Default::default() },
Expand All @@ -289,7 +290,9 @@ impl FlowSearchClient {
size: 1,
fetch_total: true,
},
}, funs, ctx).await?.map(|result| result.total_size))
}, funs, ctx).await?.map(|result| result.total_size);
debug!("flow search_guard_account_num result : {:?}", result);
Ok(result)
}

pub fn get_tag_search_map() -> HashMap<String, String> {
Expand Down
4 changes: 2 additions & 2 deletions backend/middlewares/flow/src/serv/flow_external_serv.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bios_sdk_invoke::{clients::spi_kv_client::SpiKvClient, invoke_constants::TARDIS_CONTEXT};
use itertools::Itertools;
use tardis::{
basic::{dto::TardisContext, result::TardisResult}, log::debug, tokio, web::web_resp::TardisResp, TardisFuns, TardisFunsInst
basic::{dto::TardisContext, result::TardisResult}, log::debug, tokio, TardisFuns, TardisFunsInst
};

use crate::{
Expand All @@ -12,7 +12,7 @@ use crate::{
},
flow_state_dto::FlowSysStateKind,
flow_transition_dto::{FlowTransitionActionByVarChangeInfoChangedKind, FlowTransitionDetailResp, TagRelKind},
}, flow_config::FlowConfig, flow_constants
}, flow_constants
};

pub struct FlowExternalServ;
Expand Down
1 change: 1 addition & 0 deletions backend/middlewares/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,7 @@ impl FlowInstServ {
sub_kind: Some(FlowLogClient::get_junp_kind(&flow_inst_detail.tag)),
flow_message: operate_req.output_message.clone(),
flow_result: Some(operate_req.operate.to_string().to_uppercase()),
detail: operate_req.log_text.clone(),
..Default::default()
};
if operate_req.vars.is_none() {
Expand Down
83 changes: 69 additions & 14 deletions backend/middlewares/flow/src/serv/flow_model_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ use crate::{
dto::{
flow_model_dto::{
FlowModelAddReq, FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelBindNewStateReq, FlowModelBindStateReq, FlowModelDetailResp, FlowModelFilterReq,
FlowModelFindRelStateResp, FlowModelKind, FlowModelModifyReq, FlowModelRelTransitionExt, FlowModelStatus, FlowModelSummaryResp,
FlowModelFindRelStateResp, FlowModelKind, FlowModelModifyReq, FlowModelRelTransitionExt, FlowModelStatus, FlowModelSummaryResp, FlowModelSyncModifiedFieldReq,
},
flow_model_version_dto::{
FlowModelVersionAddReq, FlowModelVersionBindState, FlowModelVersionDetailResp, FlowModelVersionFilterReq, FlowModelVersionModifyReq, FlowModelVersionModifyState,
FlowModelVesionState,
},
flow_state_dto::{FLowStateIdAndName, FlowStateAddReq, FlowStateAggResp, FlowStateKind, FlowStateRelModelExt, FlowSysStateKind},
flow_state_dto::{FLowStateIdAndName, FlowStateAddReq, FlowStateAggResp, FlowStateKind, FlowStateModifyReq, FlowStateRelModelExt, FlowStateVar, FlowSysStateKind},
flow_transition_dto::{
FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionInitInfo, FlowTransitionModifyReq, FlowTransitionPostActionInfo, FlowTransitionSortStatesReq,
},
Expand All @@ -48,10 +48,7 @@ use super::{
clients::{
flow_log_client::{FlowLogClient, LogParamContent, LogParamTag},
search_client::FlowSearchClient,
},
flow_model_version_serv::FlowModelVersionServ,
flow_rel_serv::{FlowRelKind, FlowRelServ},
flow_transition_serv::FlowTransitionServ,
}, flow_model_version_serv::FlowModelVersionServ, flow_rel_serv::{FlowRelKind, FlowRelServ}, flow_state_serv::FlowStateServ, flow_transition_serv::FlowTransitionServ
};

pub struct FlowModelServ;
Expand Down Expand Up @@ -1600,6 +1597,7 @@ impl FlowModelServ {
..ctx.clone()
};
let models = Self::find_rel_model_map(rel_template_id.clone(), true, funs, ctx).await?;
let mut non_main_model_ids = vec![];
if let Some(rel_template_id) = rel_template_id.clone() {
let rel_model_ids = FlowRelServ::find_to_simple_rels(&FlowRelKind::FlowModelTemplate, &rel_template_id, None, None, funs, &global_ctx)
.await?
Expand Down Expand Up @@ -1653,6 +1651,14 @@ impl FlowModelServ {
)
.await?;
}
non_main_model_ids = Self::find_id_items(&FlowModelFilterReq {
basic: RbumBasicFilterReq {
enabled: Some(true),
..Default::default()
},
main: Some(false),
..Default::default()
}, None, None, funs, ctx).await?
}
for (tag, model) in models.iter() {
if let Some(spec_tags) = spec_tags.clone() {
Expand All @@ -1670,14 +1676,7 @@ impl FlowModelServ {
}
}
// 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? {
for model_id in non_main_model_ids {
Self::delete_item(&model_id, funs, ctx).await?;
}
Ok(models)
Expand Down Expand Up @@ -1851,4 +1850,60 @@ impl FlowModelServ {
None => Err(funs.err().not_found("flow_model_serv", "find_editing_verion", "model not found", "404-flow-model-not-found")),
}
}

pub async fn sync_modified_field(req: &FlowModelSyncModifiedFieldReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
let models = Self::find_detail_items(&FlowModelFilterReq {
basic: RbumBasicFilterReq {
enabled: Some(true),
..Default::default()
},
main: Some(false),
rel_template_id: req.rel_template_id.clone(),
tags: Some(vec![req.tag.clone()]),
..Default::default()
}, None, None, funs, ctx).await?;
for model in models {
let states = model.states();
for state in states {
let add_default_conf = match state.state_kind {
FlowStateKind::Form => {
state.kind_conf.clone().unwrap_or_default().form.unwrap_or_default().add_default_field.unwrap_or_default()
},
FlowStateKind::Approval => {
state.kind_conf.clone().unwrap_or_default().approval.unwrap_or_default().add_default_field.unwrap_or_default()
},
_ => { FlowStateVar::default()},
};
let mut kind_conf = state.kind_conf.clone().unwrap_or_default();
for add_field in req.add_fields.clone() {
match state.state_kind {
FlowStateKind::Form => {
kind_conf.form.as_mut().map(|form| form.vars_collect.insert(add_field, add_default_conf.clone()));
},
FlowStateKind::Approval => {
kind_conf.approval.as_mut().map(|form| form.vars_collect.insert(add_field, add_default_conf.clone()));
},
_ => { },
}
}
for delete_field in &req.delete_fields {
match state.state_kind {
FlowStateKind::Form => {
kind_conf.form.as_mut().map(|form| form.vars_collect.remove(delete_field));
},
FlowStateKind::Approval => {
kind_conf.approval.as_mut().map(|form| form.vars_collect.remove(delete_field));
},
_ => { },
}
}
FlowStateServ::modify_item(&state.id, &mut FlowStateModifyReq {
kind_conf: Some(kind_conf),
..Default::default()
}, funs, ctx).await?;
}
}

Ok(())
}
}
13 changes: 6 additions & 7 deletions backend/middlewares/flow/src/serv/flow_model_version_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ use bios_basic::rbum::{
};
use itertools::Itertools;
use tardis::{
basic::{dto::TardisContext, result::TardisResult},
db::sea_orm::{
basic::{dto::TardisContext, result::TardisResult}, chrono::Utc, db::sea_orm::{
prelude::Expr,
sea_query::{Alias, SelectStatement},
EntityName, Set,
},
futures::future::join_all,
serde_json::json,
TardisFuns, TardisFunsInst,
}, futures::future::join_all, serde_json::json, TardisFuns, TardisFunsInst
};

use crate::{
domain::flow_model_version,
dto::{
flow_model_dto::{FlowModelBindNewStateReq, FlowModelBindStateReq, FlowModelFilterReq, FlowModelModifyReq},
flow_model_dto::{FlowModelBindNewStateReq, FlowModelBindStateReq, FlowModelFilterReq, FlowModelModifyReq, FlowModelStatus},
flow_model_version_dto::{
FlowModelVersionAddReq, FlowModelVersionBindState, FlowModelVersionDetailResp, FlowModelVersionFilterReq, FlowModelVersionModifyReq, FlowModelVersionSummaryResp,
FlowModelVesionState,
Expand Down Expand Up @@ -106,6 +102,7 @@ impl
&version_detail.rel_model_id,
&mut FlowModelModifyReq {
current_version_id: Some(flow_version_id.to_string()),
status: Some(FlowModelStatus::Enabled),
..Default::default()
},
funs,
Expand Down Expand Up @@ -135,6 +132,7 @@ impl
}
let mut flow_mode_version = flow_model_version::ActiveModel {
id: Set(id.to_string()),
update_time: Set(Utc::now()),
..Default::default()
};
if let Some(status) = &modify_req.status {
Expand All @@ -155,6 +153,7 @@ impl
&version_detail.rel_model_id,
&mut FlowModelModifyReq {
current_version_id: Some(id.to_string()),
status: Some(FlowModelStatus::Enabled),
..Default::default()
},
funs,
Expand Down

0 comments on commit 584bb1f

Please sign in to comment.