diff --git a/backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs b/backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs index 5c419993..0ada439b 100644 --- a/backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs +++ b/backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs @@ -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; @@ -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, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult { + 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) + } } diff --git a/backend/middlewares/flow/src/dto/flow_inst_dto.rs b/backend/middlewares/flow/src/dto/flow_inst_dto.rs index ac690429..2d7112a8 100644 --- a/backend/middlewares/flow/src/dto/flow_inst_dto.rs +++ b/backend/middlewares/flow/src/dto/flow_inst_dto.rs @@ -467,6 +467,8 @@ pub struct FlowInstOperateReq { pub output_message: Option, /// 操作人 pub operator: Option, + /// 日志文本 + pub log_text: Option, } /// 工作流实例过滤器 diff --git a/backend/middlewares/flow/src/dto/flow_model_dto.rs b/backend/middlewares/flow/src/dto/flow_model_dto.rs index 7748f030..5a10e485 100644 --- a/backend/middlewares/flow/src/dto/flow_model_dto.rs +++ b/backend/middlewares/flow/src/dto/flow_model_dto.rs @@ -468,3 +468,13 @@ pub struct FlowModelFindRelNameByTemplateIdsReq { /// 关联的模板ID pub rel_template_ids: Vec, } + +/// 修改当前参数列表 +#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)] +pub struct FlowModelSyncModifiedFieldReq { + pub rel_template_id: Option, + pub tag: String, + /// 参数列表 + pub add_fields: Vec, + pub delete_fields: Vec, +} \ No newline at end of file diff --git a/backend/middlewares/flow/src/dto/flow_state_dto.rs b/backend/middlewares/flow/src/dto/flow_state_dto.rs index ebb2bc2d..4a8b33f6 100644 --- a/backend/middlewares/flow/src/dto/flow_state_dto.rs +++ b/backend/middlewares/flow/src/dto/flow_state_dto.rs @@ -75,6 +75,8 @@ pub struct FlowStateForm { pub referral: bool, /// 转办自定义人员权限 pub referral_guard_custom_conf: Option, + /// 新增默认字段配置 + pub add_default_field: Option, /// 字段配置 pub vars_collect: HashMap, /// 提交动作名称 @@ -113,6 +115,8 @@ pub struct FlowStateApproval { /// 转办自定义人员权限 pub referral_guard_custom: bool, pub referral_guard_custom_conf: Option, + /// 新增默认字段配置 + pub add_default_field: Option, /// 字段配置 pub vars_collect: HashMap, /// 多人审批策略方式 @@ -466,4 +470,4 @@ impl FromStr for FlowStateOperatorKind { _ => Err(TardisError::bad_request(&format!("invalid FlowStateOperatorKind: {}", s), "400-operator-invalid-param")), } } -} +} \ No newline at end of file diff --git a/backend/middlewares/flow/src/serv/clients/search_client.rs b/backend/middlewares/flow/src/serv/clients/search_client.rs index 3e6b892c..c52f9210 100644 --- a/backend/middlewares/flow/src/serv/clients/search_client.rs +++ b/backend/middlewares/flow/src/serv/clients/search_client.rs @@ -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::{ @@ -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 { @@ -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() }, @@ -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 { diff --git a/backend/middlewares/flow/src/serv/flow_external_serv.rs b/backend/middlewares/flow/src/serv/flow_external_serv.rs index 470a4c0d..80b3e18e 100644 --- a/backend/middlewares/flow/src/serv/flow_external_serv.rs +++ b/backend/middlewares/flow/src/serv/flow_external_serv.rs @@ -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::{ @@ -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; diff --git a/backend/middlewares/flow/src/serv/flow_inst_serv.rs b/backend/middlewares/flow/src/serv/flow_inst_serv.rs index cd318e00..2c66f041 100644 --- a/backend/middlewares/flow/src/serv/flow_inst_serv.rs +++ b/backend/middlewares/flow/src/serv/flow_inst_serv.rs @@ -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() { diff --git a/backend/middlewares/flow/src/serv/flow_model_serv.rs b/backend/middlewares/flow/src/serv/flow_model_serv.rs index 9f9f3ef5..2ef6c576 100644 --- a/backend/middlewares/flow/src/serv/flow_model_serv.rs +++ b/backend/middlewares/flow/src/serv/flow_model_serv.rs @@ -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, }, @@ -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; @@ -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? @@ -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() { @@ -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) @@ -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(()) + } } diff --git a/backend/middlewares/flow/src/serv/flow_model_version_serv.rs b/backend/middlewares/flow/src/serv/flow_model_version_serv.rs index 4880fd4e..87c766b7 100644 --- a/backend/middlewares/flow/src/serv/flow_model_version_serv.rs +++ b/backend/middlewares/flow/src/serv/flow_model_version_serv.rs @@ -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, @@ -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, @@ -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 { @@ -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,