Skip to content

Commit

Permalink
flow: optimize api state_transitions (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Nov 23, 2023
1 parent 3dbf077 commit 722ce81
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
2 changes: 2 additions & 0 deletions middleware/flow/src/dto/flow_inst_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ pub struct FlowInstDetailResp {
pub current_state_id: String,
pub current_state_name: Option<String>,
pub current_state_color: Option<String>,
pub current_state_kind: Option<FlowSysStateKind>,
pub current_state_ext: Option<String>,

pub current_assigned: Option<String>,
pub current_vars: Option<HashMap<String, Value>>,
Expand Down
46 changes: 20 additions & 26 deletions middleware/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ impl FlowInstServ {
pub current_state_id: String,
pub current_state_name: Option<String>,
pub current_state_color: Option<String>,
pub current_state_kind: Option<FlowSysStateKind>,
pub current_state_ext: Option<String>,

pub current_assigned: Option<String>,
pub current_vars: Option<Value>,
Expand All @@ -330,6 +332,7 @@ impl FlowInstServ {
let rel_state_table = Alias::new("rel_state");
let flow_state_table = Alias::new("flow_state");
let rel_model_table = Alias::new("rel_model");
let rbum_rel_table = Alias::new("rbum_rel");
let mut query = Query::select();
query
.columns([
Expand All @@ -351,6 +354,8 @@ impl FlowInstServ {
])
.expr_as(Expr::col((rel_state_table.clone(), NAME_FIELD.clone())).if_null(""), Alias::new("current_state_name"))
.expr_as(Expr::col((flow_state_table.clone(), Alias::new("color"))).if_null(""), Alias::new("current_state_color"))
.expr_as(Expr::col((flow_state_table.clone(), Alias::new("sys_state"))).if_null(""), Alias::new("current_state_kind"))
.expr_as(Expr::col((rbum_rel_table.clone(), Alias::new("ext"))).if_null(""), Alias::new("current_state_ext"))
.expr_as(Expr::col((rel_model_table.clone(), NAME_FIELD.clone())).if_null(""), Alias::new("rel_flow_model_name"))
.from(flow_inst::Entity)
.join_as(
Expand All @@ -377,6 +382,15 @@ impl FlowInstServ {
.add(Expr::col((rel_model_table.clone(), REL_KIND_ID_FIELD.clone())).eq(FlowModelServ::get_rbum_kind_id().unwrap()))
.add(Expr::col((rel_model_table.clone(), REL_DOMAIN_ID_FIELD.clone())).eq(FlowModelServ::get_rbum_domain_id().unwrap())),
)
.join_as(
JoinType::LeftJoin,
rbum_rel_table.clone(),
rbum_rel_table.clone(),
Cond::all()
.add(Expr::col((rbum_rel_table.clone(), Alias::new("to_rbum_item_id"))).equals((flow_inst::Entity, flow_inst::Column::CurrentStateId)))
.add(Expr::col((rbum_rel_table.clone(), Alias::new("from_rbum_id"))).equals((flow_inst::Entity, flow_inst::Column::RelFlowModelId)))
.add(Expr::col((rbum_rel_table.clone(), Alias::new("tag"))).eq("FlowModelState".to_string())),
)
.and_where(Expr::col((flow_inst::Entity, flow_inst::Column::Id)).is_in(flow_inst_ids))
.and_where(Expr::col((flow_inst::Entity, flow_inst::Column::OwnPaths)).like(format!("{}%", ctx.own_paths)));

Expand All @@ -399,6 +413,8 @@ impl FlowInstServ {
current_state_id: inst.current_state_id,
current_state_name: inst.current_state_name,
current_state_color: inst.current_state_color,
current_state_kind: inst.current_state_kind,
current_state_ext: inst.current_state_ext,
current_assigned: inst.current_assigned,
current_vars: inst.current_vars.map(|current_vars| TardisFuns::json.json_to_obj(current_vars).unwrap()),
rel_business_obj_id: inst.rel_business_obj_id,
Expand Down Expand Up @@ -1107,7 +1123,7 @@ impl FlowInstServ {
spec_flow_transition_id: Option<String>,
req_vars: &Option<HashMap<String, Value>>,
skip_filter: bool,
funs: &TardisFunsInst,
_funs: &TardisFunsInst,
ctx: &TardisContext,
) -> TardisResult<FlowInstFindStateAndTransitionsResp> {
let flow_model_transitions = flow_model.transitions();
Expand Down Expand Up @@ -1188,36 +1204,14 @@ impl FlowInstServ {
double_check: model_transition.double_check(),
})
.collect_vec();
let current_flow_state = FlowStateServ::find_one_item(
&FlowStateFilterReq {
basic: RbumBasicFilterReq {
ids: Some(vec![flow_inst.current_state_id.to_string()]),
with_sub_own_paths: true,
own_paths: Some("".to_string()),
..Default::default()
},
..Default::default()
},
funs,
ctx,
)
.await?
.ok_or_else(|| funs.err().not_found("flow_inst", "do_find_next_transitions", "flow state is not found", "404-flow-state-not-found"))?;

let state_and_next_transitions = FlowInstFindStateAndTransitionsResp {
flow_inst_id: flow_inst.id.to_string(),
finish_time: flow_inst.finish_time,
current_flow_state_name: flow_inst.current_state_name.as_ref().unwrap_or(&"".to_string()).to_string(),
current_flow_state_kind: current_flow_state.sys_state.clone(),
current_flow_state_color: current_flow_state.color.clone(),
current_flow_state_ext: TardisFuns::json.str_to_obj::<FlowStateRelModelExt>(
&FlowRelServ::find_from_simple_rels(&FlowRelKind::FlowModelState, &flow_inst.rel_flow_model_id, None, None, funs, ctx)
.await?
.into_iter()
.find(|rel| current_flow_state.id == rel.rel_id)
.ok_or_else(|| funs.err().not_found("flow_inst", "do_find_next_transitions", "flow state is not found", "404-flow-state-not-found"))?
.ext,
)?,
current_flow_state_color: flow_inst.current_state_color.as_ref().unwrap_or(&"".to_string()).to_string(),
current_flow_state_kind: flow_inst.current_state_kind.as_ref().unwrap_or(&FlowSysStateKind::Start).clone(),
current_flow_state_ext: TardisFuns::json.str_to_obj::<FlowStateRelModelExt>(&flow_inst.current_state_ext.clone().unwrap_or_default())?,
next_flow_transitions: next_transitions,
};
Ok(state_and_next_transitions)
Expand Down
1 change: 1 addition & 0 deletions services/bios-all/config/locale/zh-cn.basic
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
400-rbum-cert-sk-vcode-only-one 凭证密钥与动态码只能二选一
400-rbum-cert-reset-sk-duplicate 重置密钥不能重复
400-rbum-cert-sk-contains-ak 密码不能包含用户名
400-rbum-cert-lock 账号已锁定
401-rbum-cert-lock 账号已锁定
409-rbum-cert-sk-expire 凭证密钥已过期
404-rbum-cert-conf-not-exist 找不到对应的凭证配置
Expand Down
4 changes: 2 additions & 2 deletions spi/spi-conf/src/conf_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::net::IpAddr;
use ipnet::IpNet;
use bios_basic::rbum::rbum_config::RbumConfig;
use ipnet::IpNet;
use serde::{Deserialize, Serialize};
use std::net::IpAddr;
use tardis::consts::{IP_LOCALHOST, IP_UNSPECIFIED};

use crate::dto::conf_auth_dto::RegisterRequest;
Expand Down
13 changes: 4 additions & 9 deletions support/iam/src/console_tenant/api/iam_ct_role_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl IamCtRoleApi {
TardisResp::ok(result)
}


/// 聚合查询租户及基础项目角色 Find Roles base app
#[oai(path = "/base_app", method = "get")]
async fn find_role_base_app(
Expand All @@ -133,9 +132,7 @@ impl IamCtRoleApi {
let funs = iam_constants::get_tardis_inst();
let app_result = IamRoleServ::find_items(
&IamRoleFilterReq {
basic: RbumBasicFilterReq {
..Default::default()
},
basic: RbumBasicFilterReq { ..Default::default() },
kind: Some(IamRoleKind::App),
in_base: Some(true),
..Default::default()
Expand All @@ -145,12 +142,10 @@ impl IamCtRoleApi {
&funs,
&ctx.0,
)
.await?;
.await?;
let tenant_result = IamRoleServ::find_items(
&IamRoleFilterReq {
basic: RbumBasicFilterReq {
..Default::default()
},
basic: RbumBasicFilterReq { ..Default::default() },
// kind: Some(IamRoleKind::Tenant),
in_base: Some(false),
..Default::default()
Expand All @@ -160,7 +155,7 @@ impl IamCtRoleApi {
&funs,
&ctx.0,
)
.await?;
.await?;
ctx.0.execute_task().await?;
let mut result = vec![];
result.extend(tenant_result);
Expand Down

0 comments on commit 722ce81

Please sign in to comment.