Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flow: complete code (check approval cond) #878

Merged
merged 16 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ impl FlowCcInstApi {
/// 启动实例(返回实例ID)
#[oai(path = "/", method = "post")]
async fn start(&self, add_req: Json<FlowInstStartReq>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<String> {
let funs = flow_constants::get_tardis_inst();
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
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 @@ -211,10 +213,12 @@ impl FlowCcInstApi {
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
let funs = flow_constants::get_tardis_inst();
let mut funs = flow_constants::get_tardis_inst();
let vars = HashMap::from([("current_assigned".to_string(), Value::String(modify_req.0.current_assigned))]);
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?;
funs.begin().await?;
FlowInstServ::modify_current_vars(&inst, &vars, loop_check_helper::InstancesTransition::default(), &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}
Expand All @@ -230,9 +234,11 @@ impl FlowCcInstApi {
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
let funs = flow_constants::get_tardis_inst();
let mut 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?;
funs.begin().await?;
FlowInstServ::modify_current_vars(&inst, &modify_req.0.vars, loop_check_helper::InstancesTransition::default(), &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}
Expand Down
12 changes: 8 additions & 4 deletions backend/middlewares/flow/src/api/ci/flow_ci_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ impl FlowCiInstApi {
mut ctx: TardisContextExtractor,
request: &Request,
) -> TardisApiResult<Void> {
let funs = flow_constants::get_tardis_inst();
let mut funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
let vars = HashMap::from([("assigned_to".to_string(), Value::String(modify_req.0.current_assigned))]);
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?;
funs.begin().await?;
FlowInstServ::modify_current_vars(&inst, &vars, loop_check_helper::InstancesTransition::default(), &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}
Expand All @@ -202,10 +204,12 @@ impl FlowCiInstApi {
mut ctx: TardisContextExtractor,
request: &Request,
) -> TardisApiResult<Void> {
let funs = flow_constants::get_tardis_inst();
let mut funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
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?;
funs.begin().await?;
FlowInstServ::modify_current_vars(&inst, &modify_req.0.vars, loop_check_helper::InstancesTransition::default(), &funs, &ctx.0).await?;
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}
Expand Down
76 changes: 0 additions & 76 deletions backend/middlewares/flow/src/api/cs/flow_cs_config_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,80 +47,4 @@ impl FlowCsConfigApi {
ctx.0.execute_task().await?;
TardisResp::ok(result)
}

/// Get Config / 获取配置
#[oai(path = "/update_instance_state", method = "get")]
async fn update_instance_state(&self, ctx: TardisContextExtractor) -> TardisApiResult<Void> {
tokio::spawn(async move {
let global_ctx = TardisContext::default();
let funs = flow_constants::get_tardis_inst();
let tag_search_map = HashMap::from([
("CTS", "idp_test"),
("ISSUE", "idp_test"),
("ITER", "idp_project"),
("MS", "idp_project"),
("PROJ", "idp_project"),
("REQ", "idp_project"),
("TASK", "idp_project"),
("TICKET", "ticket"),
("TP", "idp_test"),
("TS", "idp_test"),
]);
let states = FlowStateServ::find_id_name_items(
&FlowStateFilterReq {
basic: RbumBasicFilterReq {
ignore_scope: true,
with_sub_own_paths: true,
..Default::default()
},
..Default::default()
},
None,
None,
&funs,
&global_ctx,
)
.await
.unwrap();
let mut page = 1;
loop {
let insts = FlowInstServ::paginate(None, None, None, None, None, None, Some(true), page, 200, &funs, &global_ctx).await.unwrap().records;
if insts.is_empty() {
break;
}
for inst in insts {
let state_name = states.get(&inst.current_state_id).cloned().unwrap_or_default();
if let Some(table) = tag_search_map.get(&inst.tag.as_str()) {
SpiSearchClient::modify_item_and_name(
table,
&inst.rel_business_obj_id,
&SearchItemModifyReq {
kind: None,
title: None,
name: None,
content: None,
owner: None,
own_paths: None,
create_time: None,
update_time: None,
ext: Some(json!({
"status": state_name,
})),
ext_override: None,
visit_keys: None,
kv_disable: None,
},
&funs,
&global_ctx,
)
.await
.unwrap_or_default();
}
}
page += 1;
}
});
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}
}
4 changes: 4 additions & 0 deletions backend/middlewares/flow/src/domain/flow_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pub struct Model {
#[index]
pub rel_flow_version_id: String,

/// Instance code / 实例编码
#[index(unique)]
pub code: Option<String>,

/// Business object Id / 关联的业务对象Id
#[index]
pub rel_business_obj_id: String,
Expand Down
44 changes: 29 additions & 15 deletions backend/middlewares/flow/src/dto/flow_inst_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use tardis::{
};

use super::{
flow_state_dto::{FlowGuardConf, FlowStateKind, FlowStateOperatorKind, FlowStateRelModelExt, FlowStateVar, FlowSysStateKind},
flow_transition_dto::FlowTransitionDoubleCheckInfo,
flow_var_dto::FlowVarInfo,
flow_model_dto::FlowModelRelTransitionExt, flow_state_dto::{FlowGuardConf, FlowStateKind, FlowStateOperatorKind, FlowStateRelModelExt, FlowStateVar, FlowSysStateKind}, flow_transition_dto::FlowTransitionDoubleCheckInfo, flow_var_dto::FlowVarInfo
};

#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
Expand Down Expand Up @@ -74,6 +72,8 @@ pub struct FlowInstAbortReq {
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct FlowInstSummaryResp {
pub id: String,

pub code: String,
/// Associated [flow_model](super::flow_model_version_dto::FlowModelVersionDetailResp) id
///
/// 关联的[工作流模板](super::flow_model_version_dto::FlowModelVersionDetailResp) id
Expand Down Expand Up @@ -102,16 +102,21 @@ pub struct FlowInstSummaryResp {
pub finish_abort: bool,
/// 输出信息
pub output_message: Option<String>,
/// 触发的动作
pub rel_transition: Option<FlowModelRelTransitionExt>,

pub own_paths: String,

pub tag: String,
}

/// 工作流详细信息
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct FlowInstDetailResp {
pub id: String,

pub code: String,

/// Associated [flow_model](super::flow_model_dto::FlowModelDetailResp) id
///
/// 关联的[工作流模板](super::flow_model_dto::FlowModelDetailResp) id
Expand Down Expand Up @@ -180,30 +185,32 @@ pub struct FlowInstDetailResp {
pub output_message: Option<String>,
/// 动作列表
pub transitions: Option<Vec<FlowInstTransitionInfo>>,

/// 数据对象
pub artifacts: Option<FlowInstArtifacts>,

/// 评论
pub comments: Option<Vec<FlowInstCommentInfo>>,
/// 触发的动作
pub rel_transition: Option<FlowModelRelTransitionExt>,

pub own_paths: String,
}

// 状态配置
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct FLowInstStateConf {
pub operators: HashMap<FlowStateOperatorKind, String>,
pub form_conf: Option<FLowInstStateFormConf>,
pub approval_conf: Option<FLowInstStateApprovalConf>,
}

// 状态录入配置
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct FLowInstStateFormConf {
pub form_vars_collect_conf: HashMap<String, FlowStateVar>,
}

// 状态审批配置
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct FLowInstStateApprovalConf {
pub approval_vars_collect_conf: Option<HashMap<String, FlowStateVar>>,
pub form_vars_collect: HashMap<String, Value>,
Expand All @@ -213,9 +220,11 @@ pub struct FLowInstStateApprovalConf {
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug, Default, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowInstArtifacts {
pub guard_conf: FlowGuardConf, // 当前操作人权限
pub prohibit_guard_by_spec_account_ids: Option<Vec<String>>, // 禁止操作的指定用户ID
pub prohibit_guard_by_spec_account_ids: Option<Vec<String>>, // 禁止操作的指定用户ID
pub approval_result: HashMap<String, HashMap<String, Vec<String>>>, // 当前审批结果
pub approval_total: Option<HashMap<String, usize>>, // 审批总数
pub form_state_map: HashMap<String, HashMap<String, Value>>, // 录入节点映射 key为节点ID,对应的value为节点中的录入的参数
pub curr_vars: Option<HashMap<String, Value>>, // 当前参数列表
pub prev_non_auto_state_id: Option<String>, // 上一个非自动节点ID
pub prev_non_auto_account_id: Option<String>, // 上一个节点操作人ID
}
Expand All @@ -225,7 +234,7 @@ pub struct FlowInstArtifacts {
pub struct FlowInstArtifactsModifyReq {
pub guard_conf: Option<FlowGuardConf>, // 当前操作人权限
pub add_prohibit_guard_conf_account_id: Option<String>, // 增加禁止操作人ID
pub delete_prohibit_guard_conf_account_id: Option<String>, // 删除禁止操作人ID
pub delete_prohibit_guard_conf_account_id: Option<String>, // 删除禁止操作人ID
pub add_guard_conf_account_id: Option<String>, // 增加操作人ID
pub delete_guard_conf_account_id: Option<String>, // 删除操作人ID
pub add_approval_result: Option<(String, FlowApprovalResultKind)>, // 增加审批结果
Expand All @@ -234,6 +243,8 @@ pub struct FlowInstArtifactsModifyReq {
pub clear_approval_result: Option<String>, // 清除节点审批信息
pub prev_non_auto_state_id: Option<String>, // 上一个非自动节点ID
pub prev_non_auto_account_id: Option<String>, // 上一个节点操作人ID
pub curr_approval_total: Option<usize>, // 当前审批总数
pub curr_vars: Option<HashMap<String, Value>>, // 当前参数列表
}

/// 审批结果类型
Expand Down Expand Up @@ -448,8 +459,10 @@ pub struct FlowInstModifyCurrentVarsReq {
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct FlowInstOperateReq {
pub operate: FlowStateOperatorKind,
/// 参数列表
/// 修改参数列表
pub vars: Option<HashMap<String, Value>>,
/// 全量参数列表
pub all_vars: Option<HashMap<String, Value>>,
/// 输出信息
pub output_message: Option<String>,
/// 操作人
Expand Down Expand Up @@ -481,6 +494,7 @@ pub struct FlowInstFilterReq {
#[derive(sea_orm::FromQueryResult)]
pub struct FlowInstSummaryResult {
pub id: String,
pub code: String,
pub rel_flow_version_id: String,
pub rel_flow_model_id: String,
pub rel_flow_model_name: String,
Expand All @@ -497,6 +511,8 @@ pub struct FlowInstSummaryResult {
pub finish_abort: Option<bool>,
pub output_message: Option<String>,

pub rel_transition: Option<String>,

pub own_paths: String,

pub tag: String,
Expand Down Expand Up @@ -529,7 +545,7 @@ pub struct FlowInstSearchReq {
// Search conditions
pub query: FlowInstFilterReq,
// Advanced search
pub query_kind: Option<FlowInstQueryKind>,
pub query_kind: Option<Vec<FlowInstQueryKind>>,
// Sort
// When the record set is very large, it will seriously affect the performance, it is not recommended to use.
pub sort: Option<Vec<FlowInstSearchSortReq>>,
Expand All @@ -538,8 +554,6 @@ pub struct FlowInstSearchReq {

#[derive(Serialize, Deserialize, Debug, poem_openapi::Enum, Eq, Hash, PartialEq, Clone)]
pub enum FlowInstQueryKind {
/// 全部
All,
/// 待录入
Form,
/// 待审批
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 @@ -178,7 +178,7 @@ pub struct FlowModelSummaryResp {
pub rel_transition: Option<Value>,
}

#[derive(Serialize, Deserialize, Debug, Default, Clone, poem_openapi::Object, sea_orm::FromQueryResult)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Default, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowModelRelTransitionExt {
pub id: String,
pub name: String,
Expand Down
4 changes: 2 additions & 2 deletions backend/middlewares/flow/src/dto/flow_state_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub struct FlowStateCountersignConf {
/// 类型
pub kind: FlowStateCountersignKind,
/// 多数人通过比例
pub most_percent: Option<i8>,
pub most_percent: Option<usize>,
/// 审批人权限配置
pub guard_custom_conf: Option<FlowGuardConf>,
/// 指定人通过即通过
Expand Down Expand Up @@ -438,7 +438,7 @@ pub struct FLowStateIdAndName {
}

/// 可操作类型
#[derive(Display, Serialize, Deserialize, Hash, Eq, PartialEq, Debug, poem_openapi::Enum, Clone)]
#[derive(Display, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Debug, poem_openapi::Enum)]
pub enum FlowStateOperatorKind {
/// 转办
Referral,
Expand Down
20 changes: 19 additions & 1 deletion backend/middlewares/flow/src/dto/flow_transition_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,30 @@ pub enum FlowTransitionFrontActionInfoRelevanceRelation {
}

impl FlowTransitionFrontActionInfoRelevanceRelation {
pub fn check_conform(&self, left_value: String, right_value: String) -> bool {
pub fn check_conform(&self, mut left_value: String, right_value: String) -> bool {
use itertools::Itertools;

if left_value.is_empty() || left_value == "null" || right_value == "null" {
return false;
}
// 单项判断(例如等于,不等于,大于,小于),如果参数是单元素数组,则取出数据,否则说明格式错误直接返回false
if *self == FlowTransitionFrontActionInfoRelevanceRelation::Eq
|| *self == FlowTransitionFrontActionInfoRelevanceRelation::Ne
|| *self == FlowTransitionFrontActionInfoRelevanceRelation::Gt
|| *self == FlowTransitionFrontActionInfoRelevanceRelation::Ge
|| *self == FlowTransitionFrontActionInfoRelevanceRelation::Lt
|| *self == FlowTransitionFrontActionInfoRelevanceRelation::Le
{
let left_values = TardisFuns::json.str_to_obj::<Vec<Value>>(&left_value).unwrap_or_default();
if left_values.len() == 1 {
left_value = left_values
.first().cloned()
.unwrap_or_default().as_str()
.unwrap_or("").to_string();
} else {
return false;
}
}
match self {
FlowTransitionFrontActionInfoRelevanceRelation::Eq => left_value == right_value,
FlowTransitionFrontActionInfoRelevanceRelation::Ne => left_value != right_value,
Expand Down
Loading
Loading