Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Oct 23, 2023
2 parents c226978 + 7ac557d commit 219a1f4
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 65 deletions.
2 changes: 1 addition & 1 deletion middleware/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl FlowCcInstApi {
let mut funs = flow_constants::get_tardis_inst();
FlowInstServ::check_transfer_vars(&flow_inst_id.0, &transfer_req.0, &funs, &ctx.0).await?;
funs.begin().await?;
let result = FlowInstServ::transfer(&flow_inst_id.0, &transfer_req.0, &funs, &ctx.0).await?;
let result = FlowInstServ::transfer(&flow_inst_id.0, &transfer_req.0, false, &funs, &ctx.0).await?;
funs.commit().await?;
TardisResp::ok(result)
}
Expand Down
16 changes: 13 additions & 3 deletions middleware/flow/src/api/ci/flow_ci_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use tardis::web::context_extractor::TardisContextExtractor;
use tardis::web::poem_openapi;
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};
use tardis::{log, tokio};

use crate::dto::flow_inst_dto::{FlowInstBatchBindReq, FlowInstBatchBindResp, FlowInstBindReq, FlowInstStartReq};
use crate::flow_constants;
Expand Down Expand Up @@ -53,9 +54,18 @@ impl FlowCiInstApi {
#[oai(path = "/trigger_front_action", method = "get")]
async fn trigger_front_action(&self) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
FlowInstServ::trigger_front_action(&funs).await?;
funs.commit().await?;
tokio::spawn(async move {
funs.begin().await.unwrap();
match FlowInstServ::trigger_front_action(&funs).await {
Ok(_) => {
log::trace!("[Flow.Inst] add log success")
}
Err(e) => {
log::warn!("[Flow.Inst] failed to add log:{e}")
}
}
funs.commit().await.unwrap();
});

TardisResp::ok(Void {})
}
Expand Down
26 changes: 19 additions & 7 deletions middleware/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,16 @@ impl FlowInstServ {
Ok(())
}

pub async fn transfer(flow_inst_id: &str, transfer_req: &FlowInstTransferReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<FlowInstTransferResp> {
pub async fn transfer(
flow_inst_id: &str,
transfer_req: &FlowInstTransferReq,
skip_filter: bool,
funs: &TardisFunsInst,
ctx: &TardisContext,
) -> TardisResult<FlowInstTransferResp> {
// record updated instance id
let mut updated_instance_list: Vec<String> = Vec::new();
let result = Self::do_transfer(flow_inst_id, transfer_req, &mut updated_instance_list, false, funs, ctx).await;
let result = Self::do_transfer(flow_inst_id, transfer_req, &mut updated_instance_list, skip_filter, funs, ctx).await;

for updated_instance_id in updated_instance_list {
Self::do_front_change(&updated_instance_id, ctx, funs).await?;
Expand Down Expand Up @@ -814,7 +820,7 @@ impl FlowInstServ {
FlowTransitionActionChangeKind::Var => {
if let Some(mut change_info) = post_change.var_change_info {
if change_info.changed_kind.is_some() && change_info.changed_kind.unwrap() == FlowTransitionActionByVarChangeInfoChangedKind::AutoGetOperateTime {
change_info.changed_val = Some(json!(Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true)));
change_info.changed_val = Some(json!(Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true)));
}
let rel_tag = change_info.obj_tag.unwrap_or_default();
if !rel_tag.is_empty() {
Expand Down Expand Up @@ -1253,6 +1259,7 @@ impl FlowInstServ {
message: None,
vars: None,
},
true,
funs,
ctx,
)
Expand Down Expand Up @@ -1308,7 +1315,7 @@ impl FlowInstServ {
}
FlowTransitionFrontActionRightValue::RealTime => {
if let Some(left_value) = current_vars.get(&condition.left_value) {
Ok(condition.relevance_relation.check_conform(left_value.as_str().unwrap_or_default().to_string(), Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true)))
Ok(condition.relevance_relation.check_conform(left_value.as_str().unwrap_or_default().to_string(), Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true)))
} else {
Ok(false)
}
Expand Down Expand Up @@ -1357,6 +1364,7 @@ impl FlowInstServ {
#[derive(sea_orm::FromQueryResult)]
pub struct FlowInstanceResult {
id: String,
own_paths: String,
}

let global_ctx = TardisContext::default();
Expand Down Expand Up @@ -1385,19 +1393,23 @@ impl FlowInstServ {
.db()
.find_dtos::<FlowInstanceResult>(
Query::select()
.columns([flow_inst::Column::Id])
.columns([flow_inst::Column::Id, flow_inst::Column::OwnPaths])
.from(flow_inst::Entity)
.and_where(Expr::col(flow_inst::Column::RelFlowModelId).eq(&flow_transition.rel_flow_model_id))
.and_where(Expr::col(flow_inst::Column::CurrentStateId).eq(&flow_transition.from_flow_state_id)),
)
.await?;
for flow_inst in flow_insts {
let new_vars = Self::get_new_vars(&flow_inst.id, funs, &global_ctx).await?;
let ctx = TardisContext {
own_paths: flow_inst.own_paths,
..global_ctx.clone()
};
let new_vars = Self::get_new_vars(&flow_inst.id, funs, &ctx).await?;
Self::modify_current_vars(
&flow_inst.id,
&TardisFuns::json.json_to_obj::<HashMap<String, Value>>(new_vars).unwrap_or_default(),
funs,
&global_ctx,
&ctx,
)
.await?;
}
Expand Down
64 changes: 34 additions & 30 deletions middleware/flow/tests/test_flow_scenes_fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use tardis::basic::dto::TardisContext;
use tardis::basic::result::TardisResult;
use tardis::log::info;
use tardis::serde_json::json;
use tardis::tokio;
use tardis::web::poem_openapi::types::Type;
use tardis::web::web_resp::{TardisPage, Void};
use tardis::TardisFuns;
Expand Down Expand Up @@ -179,33 +180,6 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli
let trans_complate = req_model_agg.states.iter().find(|state| state.name == "进行中").unwrap().transitions.iter().find(|trans| trans.name == "完成").unwrap();
let trans_close = req_model_agg.states.iter().find(|state| state.name == "进行中").unwrap().transitions.iter().find(|trans| trans.name == "关闭").unwrap();

let _: Void = flow_client
.patch(
&format!("/cc/model/{}", req_model_id),
&json!({
"modify_transitions": [
{
"id": trans_complate.id.clone(),
"action_by_front_changes": [
{
"relevance_relation": "in",
"relevance_label": "包含",
"left_value": "status",
"left_label": "状态",
"right_value": "change_content",
"select_field": "status",
"change_content": [
"xxx"
],
"select_field_label": "status",
"change_content_label": "x"
}
]
}
]
}),
)
.await;
let _: Void = flow_client
.patch(
&format!("/cc/model/{}", req_model_id),
Expand Down Expand Up @@ -764,7 +738,7 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli
.await;
assert_eq!(state_and_next_transitions[0].next_flow_transitions.len(), 1);
// handle front change
let current_vars = HashMap::from([("status".to_string(), json!("xxx"))]);
let current_vars = HashMap::from([("status".to_string(), json!("xxx")), ("handle_time".to_string(), json!("2023-10-10"))]);
let _: Void = flow_client
.patch(
&format!("/cc/inst/{}/modify_current_vars", req_inst_id2),
Expand All @@ -780,9 +754,39 @@ pub async fn test(flow_client: &mut TestHttpClient, _kv_client: &mut TestHttpCli
}],
)
.await;
assert_eq!(state_and_next_transitions[0].current_flow_state_name, "已完成");
//
let _: Void = flow_client
.patch(
&format!("/cc/model/{}", models.get("REQ").unwrap().id),
&json!({
"modify_transitions": [
{
"id": state_and_next_transitions[0].next_flow_transitions[0].next_flow_transition_id.clone(),
"action_by_front_changes": [
{
"relevance_relation": "<",
"relevance_label": "包含",
"left_value": "handle_time",
"left_label": "状态",
"right_value": "real_time"
}
]
}
]
}),
)
.await;
let _: Void = flow_client.get("/ci/inst/trigger_front_action").await;

tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
let state_and_next_transitions: Vec<FlowInstFindStateAndTransitionsResp> = flow_client
.put(
"/cc/inst/batch/state_transitions",
&vec![FlowInstFindStateAndTransitionsReq {
flow_inst_id: req_inst_id2.clone(),
vars: None,
}],
)
.await;
assert_eq!(state_and_next_transitions[0].current_flow_state_name, "已完成");
Ok(())
}
8 changes: 4 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 @@ -8,8 +8,8 @@ use tardis::{
sea_orm::{FromQueryResult, Value},
},
serde_json::{self, json, Map},
TardisFuns,
TardisFunsInst, web::web_resp::TardisPage,
web::web_resp::TardisPage,
TardisFuns, TardisFunsInst,
};

use bios_basic::{basic_enumeration::BasicQueryOpKind, dto::BasicQueryCondInfo, helper::db_helper, spi::spi_funs::SpiBsInst};
Expand Down Expand Up @@ -1099,7 +1099,7 @@ pub async fn query_metrics(query_req: &SearchQueryMetricsReq, funs: &TardisFunsI
if group.in_ext.unwrap_or(true) {
if group.multi_values.unwrap_or(false) {
sql_part_inner_selects.push(format!("jsonb_array_elements(fact.ext -> '{}') AS {}", &group.code, &group.code));
}else {
} else {
sql_part_inner_selects.push(format!("fact.ext ->> '{}' AS {}", &group.code, &group.code));
}
} else {
Expand All @@ -1112,7 +1112,7 @@ pub async fn query_metrics(query_req: &SearchQueryMetricsReq, funs: &TardisFunsI
// (column name with fun, alias name, show name)
let mut sql_part_group_infos = vec![];
for group in &query_req.group {
if let Some(column_name_with_fun) = group.data_type.to_pg_group(&format!("_.{}", &group.code), &group.time_window) {
if let Some(column_name_with_fun) = group.data_type.to_pg_group(&format!("_.{}", &group.code), &group.time_window) {
let alias_name = format!(
"{}{}{FUNCTION_SUFFIX_FLAG}{}",
group.code,
Expand Down
2 changes: 1 addition & 1 deletion support/reach/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use reach_api_cc::*;
mod reach_api_ct;
pub use reach_api_ct::*;

mod reach_api_ci;
mod reach_api_ci;
pub use reach_api_ci::*;
use tardis::{basic::result::TardisResult, web::web_server::TardisWebServer};

Expand Down
4 changes: 2 additions & 2 deletions support/reach/src/api/reach_api_cc/reach_api_cc_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use tardis::web::poem_openapi;
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};

use crate::reach_send_channel::{GenericTemplate, SendChannelMap};
use crate::dto::*;
use crate::reach_config::ReachConfig;
use crate::reach_consts::*;
use crate::dto::*;
use crate::reach_init::REACH_SEND_CHANNEL_MAP;
#[cfg(feature = "simple-client")]
use crate::reach_invoke::Client;
use crate::reach_send_channel::{GenericTemplate, SendChannelMap};
use crate::serv::*;

#[derive(Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use tardis::web::poem_openapi;
use tardis::web::poem_openapi::param::Query;
use tardis::web::web_resp::{TardisApiResult, TardisResp};

use crate::reach_consts::get_tardis_inst;
use crate::dto::*;
use crate::reach_consts::get_tardis_inst;
#[cfg(feature = "simple-client")]
use crate::reach_invoke::Client;
use crate::serv::*;
Expand Down
2 changes: 1 addition & 1 deletion support/reach/src/api/reach_api_ci/reach_api_ci_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use tardis::web::poem_openapi;
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};

use crate::reach_consts::*;
use crate::dto::*;
use crate::reach_consts::*;
#[cfg(feature = "simple-client")]
use crate::reach_invoke::Client;
use crate::serv::*;
Expand Down
2 changes: 1 addition & 1 deletion support/reach/src/api/reach_api_ct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub use reach_api_ct_msg_signature::ReachMsgSignatureCtApi;
mod reach_api_ct_msg_template;
pub use reach_api_ct_msg_template::ReachMessageTemplateCtApi;
mod reach_api_ct_trigger_global;
use tardis::basic::{error::TardisError, result::TardisResult};
pub use reach_api_ct_trigger_global::ReachTriggerGlobalConfigCtApi;
use tardis::basic::{error::TardisError, result::TardisResult};
mod reach_api_ct_trigger_instance;
pub use reach_api_ct_trigger_instance::ReachTriggerInstanceConfigCtApi;

Expand Down
2 changes: 1 addition & 1 deletion support/reach/src/api/reach_api_ct/reach_api_ct_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use tardis::web::poem_openapi::param::{Path, Query};
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp};

use crate::reach_consts::get_tardis_inst;
use crate::dto::*;
use crate::reach_consts::get_tardis_inst;
#[cfg(feature = "simple-client")]
use crate::reach_invoke::Client;
use crate::serv::*;
Expand Down
2 changes: 1 addition & 1 deletion support/reach/src/api/reach_api_ct/reach_api_ct_msg_log.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::reach_consts::get_tardis_inst;
use crate::dto::*;
use crate::reach_consts::get_tardis_inst;
#[cfg(feature = "simple-client")]
use crate::reach_invoke::Client;
use crate::serv::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use tardis::web::poem_openapi::payload::Json;
use tardis::web::poem_openapi;
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp};

use crate::reach_consts::get_tardis_inst;
use crate::dto::*;
use crate::reach_consts::get_tardis_inst;
use crate::serv::*;

#[cfg(feature = "simple-client")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use tardis::web::poem_openapi::payload::Json;
use tardis::web::poem_openapi;
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp};

use crate::reach_consts::get_tardis_inst;
use crate::dto::*;
use crate::reach_consts::get_tardis_inst;
use crate::serv::*;

#[cfg(feature = "simple-client")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use tardis::web::poem::web::Json;
use tardis::web::poem_openapi;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};

use crate::reach_consts::get_tardis_inst;
use crate::dto::*;
use crate::reach_consts::get_tardis_inst;
use crate::serv::*;

#[cfg(feature = "simple-client")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use tardis::web::poem_openapi::param::Query;
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};

use crate::reach_consts::get_tardis_inst;
use crate::dto::*;
use crate::reach_consts::get_tardis_inst;
use crate::serv::*;

#[cfg(feature = "simple-client")]
Expand Down
6 changes: 3 additions & 3 deletions support/reach/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#![warn(clippy::unwrap_used)]

mod api;
pub mod reach_send_channel;
pub mod reach_config;
pub mod reach_consts;
mod domain;
pub mod dto;
pub mod reach_config;
pub mod reach_consts;
mod reach_init;
pub mod reach_send_channel;

#[cfg(feature = "simple-client")]
pub mod reach_invoke;
Expand Down
2 changes: 1 addition & 1 deletion support/reach/src/reach_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use tardis::{

use crate::{
api,
reach_send_channel::SendChannelMap,
reach_config::ReachConfig,
reach_consts::{get_tardis_inst, DOMAIN_CODE, DOMAIN_REACH_ID, RBUM_EXT_TABLE_REACH_MESSAGE, RBUM_KIND_CODE_REACH_MESSAGE, REACH_INIT_OWNER},
reach_send_channel::SendChannelMap,
serv::ReachTriggerSceneService,
task,
};
Expand Down
6 changes: 4 additions & 2 deletions support/reach/src/task/message_send_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ impl MessageSendListener {
},
&self.funs,
&ctx,
).await?;
)
.await?;
}
}
Err(e) => {
Expand All @@ -98,7 +99,8 @@ impl MessageSendListener {
},
&self.funs,
&ctx,
).await?;
)
.await?;
}

return Err(e);
Expand Down
Loading

0 comments on commit 219a1f4

Please sign in to comment.