Skip to content

Commit

Permalink
spi-search: rename config item && flow: column_type change to Json (#623
Browse files Browse the repository at this point in the history
)

* feature: rename config item

* update

* flow: column_type change as Json
  • Loading branch information
ZzIsGod1019 authored Feb 28, 2024
1 parent ba8688c commit 5faecf1
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 35 deletions.
7 changes: 2 additions & 5 deletions middleware/flow/src/domain/flow_inst.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::dto::flow_inst_dto::FlowOperationContext;
use crate::dto::flow_inst_dto::{FlowInstTransitionInfo, FlowOperationContext};
use tardis::chrono::Utc;
use tardis::db::sea_orm;
use tardis::db::sea_orm::prelude::Json;
Expand Down Expand Up @@ -28,7 +28,6 @@ pub struct Model {
///
/// This variable list needs to be updated after each transfer
/// 每次流转后都需要更新此变量列表
/// TODO Vec<FlowVarSimpleInfo>
pub current_vars: Option<Json>,

/// Variable list when created / 创建时的变量列表(HashMap<String, Value>)
Expand All @@ -54,12 +53,10 @@ pub struct Model {
pub output_message: Option<String>,

/// Transfer information list / 流转信息列表
///
/// TODO Vec<FlowInstTransitionInfo>
#[index(full_text)]
#[sea_orm(column_type = "JsonBinary", nullable)]
#[tardis_entity(custom_type = "JsonBinary")]
pub transitions: Option<Json>,
pub transitions: Option<Vec<FlowInstTransitionInfo>>,

pub own_paths: String,

Expand Down
23 changes: 15 additions & 8 deletions middleware/flow/src/domain/flow_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use tardis::db::sea_orm::prelude::Json;
use tardis::db::sea_orm::*;
use tardis::{chrono, TardisCreateEntity, TardisEmptyBehavior, TardisEmptyRelation};

use crate::dto::flow_transition_dto::{FlowTransitionActionChangeInfo, FlowTransitionDoubleCheckInfo, FlowTransitionFrontActionInfo};
use crate::dto::flow_var_dto::FlowVarInfo;

/// Transfer / 流转
///
/// Used to define the flow of the process (migration of state)
Expand Down Expand Up @@ -71,8 +74,9 @@ pub struct Model {
///
/// List of variables to be captured when entering this transition
/// 当进入此流转时,需要采集的变量列表
/// TODO Vec<FlowVarInfo>
pub vars_collect: Json,
#[sea_orm(column_type = "Json")]
#[tardis_entity(custom_type = "Json")]
pub vars_collect: Vec<FlowVarInfo>,

/// External interface to be called when entering this transition
/// 进入此流转时,需要调用的外部接口
Expand All @@ -85,15 +89,18 @@ pub struct Model {
/// action similar to `Event` in BPMN
pub action_by_post_callback: String,

/// TODO Vec<FlowTransitionActionChangeInfo>
pub action_by_post_changes: Json,
#[sea_orm(column_type = "Json")]
#[tardis_entity(custom_type = "Json")]
pub action_by_post_changes: Vec<FlowTransitionActionChangeInfo>,

/// TODO Vec<FlowTransitionFrontActionInfo>
pub action_by_front_changes: Json,
#[sea_orm(column_type = "Json")]
#[tardis_entity(custom_type = "Json")]
pub action_by_front_changes: Vec<FlowTransitionFrontActionInfo>,

/// Secondary confirmation pop-up / 关于二次确认弹窗的配置
/// TODO FlowTransitionDoubleCheckInfo
pub double_check: Json,
#[sea_orm(column_type = "Json")]
#[tardis_entity(custom_type = "Json")]
pub double_check: FlowTransitionDoubleCheckInfo,

pub is_notify: bool,

Expand Down
6 changes: 3 additions & 3 deletions middleware/flow/src/dto/flow_transition_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl From<FlowTransitionDetailResp> for FlowTransitionAddReq {
}
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowTransitionDoubleCheckInfo {
pub is_open: bool,
pub content: Option<String>,
Expand All @@ -201,7 +201,7 @@ pub struct FlowTransitionSortStateInfoReq {
pub sort: i64,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowTransitionActionChangeInfo {
pub kind: FlowTransitionActionChangeKind,
pub describe: String,
Expand Down Expand Up @@ -363,7 +363,7 @@ pub struct FlowTransitionInitInfo {
pub sort: Option<i64>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowTransitionFrontActionInfo {
pub relevance_relation: FlowTransitionFrontActionInfoRelevanceRelation,
pub relevance_label: String,
Expand Down
6 changes: 3 additions & 3 deletions middleware/flow/src/dto/flow_var_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tardis::{
web::poem_openapi,
};

#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowVarSimpleInfo {
#[oai(validator(min_length = "2", max_length = "200"))]
pub name: String,
Expand All @@ -15,7 +15,7 @@ pub struct FlowVarSimpleInfo {
pub required: bool,
}

#[derive(Serialize, Deserialize, Debug, Default, Clone, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct FlowVarInfo {
#[oai(validator(min_length = "2", max_length = "200"))]
pub name: String,
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct FlowVarInfo {
pub parent_attr_name: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, poem_openapi::Object)]
pub struct DefaultValue {
pub value_type: DefaultValueType,
pub value: String,
Expand Down
2 changes: 1 addition & 1 deletion middleware/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ impl FlowInstServ {
id: Set(flow_inst_id.to_string()),
current_state_id: Set(next_flow_state.id.to_string()),
current_vars: Set(Some(TardisFuns::json.obj_to_json(&new_vars)?)),
transitions: Set(Some(TardisFuns::json.obj_to_json(&new_transitions)?)),
transitions: Set(Some(new_transitions.clone())),
..Default::default()
};
if next_flow_state.sys_state == FlowSysStateKind::Finish {
Expand Down
18 changes: 9 additions & 9 deletions middleware/flow/src/serv/flow_model_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::{
},
flow_state_dto::{FlowStateAddReq, FlowStateFilterReq, FlowStateRelModelExt, FlowSysStateKind},
flow_transition_dto::{
FlowTransitionActionChangeAgg, FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionDoubleCheckInfo, FlowTransitionInitInfo,
FlowTransitionActionChangeAgg, FlowTransitionActionChangeKind, FlowTransitionAddReq, FlowTransitionDetailResp, FlowTransitionInitInfo,
FlowTransitionModifyReq, FlowTransitionSortStatesReq,
},
},
Expand Down Expand Up @@ -382,14 +382,14 @@ impl FlowModelServ {
guard_by_spec_org_ids: Set(req.guard_by_spec_org_ids.as_ref().unwrap_or(&vec![]).clone()),
guard_by_other_conds: Set(req.guard_by_other_conds.as_ref().map(|conds| TardisFuns::json.obj_to_json(conds).unwrap()).unwrap_or(json!([]))),

vars_collect: Set(req.vars_collect.as_ref().map(|vars| TardisFuns::json.obj_to_json(vars).unwrap()).unwrap_or(json!([]))),
double_check: Set(TardisFuns::json.obj_to_json(&req.double_check).unwrap_or(json!(FlowTransitionDoubleCheckInfo::default()))),
vars_collect: Set(req.vars_collect.clone().unwrap_or_default()),
double_check: Set(req.double_check.clone().unwrap_or_default()),
is_notify: Set(req.is_notify.unwrap_or(true)),

action_by_pre_callback: Set(req.action_by_pre_callback.as_ref().unwrap_or(&"".to_string()).to_string()),
action_by_post_callback: Set(req.action_by_post_callback.as_ref().unwrap_or(&"".to_string()).to_string()),
action_by_post_changes: Set(TardisFuns::json.obj_to_json(&req.action_by_post_changes).unwrap_or(json!([]))),
action_by_front_changes: Set(TardisFuns::json.obj_to_json(&req.action_by_front_changes).unwrap_or(json!([]))),
action_by_post_changes: Set(req.action_by_post_changes.clone().unwrap_or_default()),
action_by_front_changes: Set(req.action_by_front_changes.clone().unwrap_or_default()),

rel_flow_model_id: Set(flow_model_id.to_string()),
sort: Set(req.sort.unwrap_or(0)),
Expand Down Expand Up @@ -495,7 +495,7 @@ impl FlowModelServ {
}

if let Some(vars_collect) = &req.vars_collect {
flow_transition.vars_collect = Set(TardisFuns::json.obj_to_json(vars_collect)?);
flow_transition.vars_collect = Set(vars_collect.clone());
}

if let Some(action_by_pre_callback) = &req.action_by_pre_callback {
Expand All @@ -505,13 +505,13 @@ impl FlowModelServ {
flow_transition.action_by_post_callback = Set(action_by_post_callback.to_string());
}
if let Some(action_by_front_changes) = &req.action_by_front_changes {
flow_transition.action_by_front_changes = Set(TardisFuns::json.obj_to_json(action_by_front_changes)?);
flow_transition.action_by_front_changes = Set(action_by_front_changes.clone());
}
if let Some(action_by_post_changes) = &req.action_by_post_changes {
flow_transition.action_by_post_changes = Set(TardisFuns::json.obj_to_json(action_by_post_changes)?);
flow_transition.action_by_post_changes = Set(action_by_post_changes.clone());
}
if let Some(double_check) = &req.double_check {
flow_transition.double_check = Set(TardisFuns::json.obj_to_json(double_check)?);
flow_transition.double_check = Set(double_check.clone());
}
if let Some(is_notify) = &req.is_notify {
flow_transition.is_notify = Set(*is_notify);
Expand Down
1 change: 0 additions & 1 deletion middleware/flow/tests/test_flow_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use bios_basic::spi::dto::spi_bs_dto::SpiBsAddReq;
use bios_basic::spi::spi_constants;
use bios_basic::test::init_rbum_test_container;
use bios_basic::test::test_http_client::TestHttpClient;
use bios_mw_event::event_initializer;
use bios_mw_flow::{flow_constants, flow_initializer};
use bios_spi_kv::{kv_constants, kv_initializer};
use tardis::basic::dto::TardisContext;
Expand Down
8 changes: 7 additions & 1 deletion spi/spi-search/src/search_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ use std::fmt::Debug;
pub struct SearchConfig {
pub rbum: RbumConfig,
pub event: Option<EventTopicConfig>,
pub word_length: Option<usize>,
pub split_strategy_rule_config: SplitStrategyRuleConfig,
}

#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[serde(default)]
pub struct SplitStrategyRuleConfig {
pub specify_word_length: Option<usize>,
}
7 changes: 3 additions & 4 deletions spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ const FUNCTION_EXT_SUFFIX_FLAG: &str = "_ext_";
const INNER_FIELD: [&str; 7] = ["key", "title", "content", "owner", "own_paths", "create_time", "update_time"];

pub async fn add(add_req: &mut SearchItemAddReq, funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult<()> {
info!("load SearchConfig: {:?}", funs.conf::<SearchConfig>().word_length);
let mut params = Vec::new();
params.push(Value::from(add_req.kind.to_string()));
params.push(Value::from(add_req.key.to_string()));
params.push(Value::from(add_req.title.as_str()));
if add_req.title.chars().count() > funs.conf::<SearchConfig>().word_length.unwrap_or(30) {
if add_req.title.chars().count() > funs.conf::<SearchConfig>().split_strategy_rule_config.specify_word_length.unwrap_or(30) {
params.push(Value::from(format!(
"{} {}",
add_req.title.as_str(),
Expand Down Expand Up @@ -76,7 +75,7 @@ pub async fn add(add_req: &mut SearchItemAddReq, funs: &TardisFunsInst, ctx: &Ta
let bs_inst = inst.inst::<TardisRelDBClient>();
let (mut conn, table_name) = search_pg_initializer::init_table_and_conn(bs_inst, &add_req.tag, ctx, true).await?;
conn.begin().await?;
let word_combinations_way = if add_req.title.chars().count() > funs.conf::<SearchConfig>().word_length.unwrap_or(30) {
let word_combinations_way = if add_req.title.chars().count() > funs.conf::<SearchConfig>().split_strategy_rule_config.specify_word_length.unwrap_or(30) {
"public.chinese_zh"
} else {
"simple"
Expand Down Expand Up @@ -112,7 +111,7 @@ pub async fn modify(tag: &str, key: &str, modify_req: &mut SearchItemModifyReq,
if let Some(title) = &modify_req.title {
sql_sets.push(format!("title = ${}", params.len() + 1));
params.push(Value::from(title));
let word_combinations_way = if title.chars().count() > funs.conf::<SearchConfig>().word_length.unwrap_or(30) {
let word_combinations_way = if title.chars().count() > funs.conf::<SearchConfig>().split_strategy_rule_config.specify_word_length.unwrap_or(30) {
"public.chinese_zh"
} else {
"simple"
Expand Down

0 comments on commit 5faecf1

Please sign in to comment.