Skip to content

Commit

Permalink
flow: improve log
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 committed Dec 14, 2024
1 parent ba6f4ad commit 36a9dd9
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 117 deletions.
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 {})
}
}
10 changes: 7 additions & 3 deletions backend/middlewares/flow/src/dto/flow_inst_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ pub struct FlowInstArtifacts {
pub guard_conf: FlowGuardConf, // 当前操作人权限
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 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 @@ -242,7 +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_approval_total: Option<usize>, // 当前审批总数
pub curr_vars: Option<HashMap<String, Value>>, // 当前参数列表
}

/// 审批结果类型
Expand Down Expand Up @@ -457,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
18 changes: 16 additions & 2 deletions backend/middlewares/flow/src/serv/clients/flow_log_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub struct LogParamContent {
pub operand_id: Option<String>,
pub operand_kind: Option<String>,
pub operand_name: Option<String>,
pub output_message: Option<String>,
pub output_result: Option<String>,
pub flow_message: Option<String>,
pub flow_result: Option<String>,
}

#[derive(Serialize, Default, Debug, Clone)]
Expand Down Expand Up @@ -184,4 +184,18 @@ impl FlowLogClient {
]);
flow_tag_map.get(tag).map_or("".to_string(), |val| val.to_string())
}

pub fn get_junp_kind(tag: &str) -> String {
let flow_tag_map = HashMap::from([
("MS", "idp_feed_ms"),
("ITER", "idp_feed_iter "),
("REQ", "idp_feed_req"),
("TASK", "idp_feed_task"),
("ISSUE", "idp_test_issue"),
("CTS", "idp_test_cts"),
("TP", "idp_test_plan"),
("TS", "idp_test_stage"),
]);
flow_tag_map.get(tag).map_or("".to_string(), |val| val.to_string())
}
}
37 changes: 22 additions & 15 deletions backend/middlewares/flow/src/serv/clients/search_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ use bios_sdk_invoke::{
event_client::{get_topic, EventCenterClient, SPI_RPC_TOPIC},
spi_search_client::SpiSearchClient,
},
dto::search_item_dto::{SearchItemAddReq, SearchItemModifyReq, SearchItemVisitKeysReq},
dto::search_item_dto::{SearchItemAddReq, SearchItemModifyReq, SearchItemSearchReq, SearchItemSearchResp, SearchItemVisitKeysReq},
};
use itertools::Itertools;
use serde_json::json;
use tardis::{
basic::{dto::TardisContext, field::TrimString, result::TardisResult},
tokio, TardisFuns, TardisFunsInst,
basic::{dto::TardisContext, field::TrimString, result::TardisResult}, tokio, web::web_resp::TardisPage, TardisFuns, TardisFunsInst
};

use crate::{
Expand All @@ -36,18 +35,7 @@ pub struct FlowSearchClient;

impl FlowSearchClient {
pub async fn modify_business_obj_search(rel_business_obj_id: &str, tag: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
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 tag_search_map = Self::get_tag_search_map();
let rel_version_ids = FlowInstServ::find_details(
&FlowInstFilterReq {
rel_business_obj_ids: Some(vec![rel_business_obj_id.to_string()]),
Expand Down Expand Up @@ -264,4 +252,23 @@ impl FlowSearchClient {
}
Ok(())
}

pub async fn search(search_req: &SearchItemSearchReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<Option<TardisPage<SearchItemSearchResp>>> {
SpiSearchClient::search(search_req, funs, ctx).await
}

pub fn get_tag_search_map() -> HashMap<String, String> {
HashMap::from([
("CTS".to_string(), "idp_test".to_string()),
("ISSUE".to_string(), "idp_test".to_string()),
("ITER".to_string(), "idp_project".to_string()),
("MS".to_string(), "idp_project".to_string()),
("PROJ".to_string(), "idp_project".to_string()),
("REQ".to_string(), "idp_project".to_string()),
("TASK".to_string(), "idp_project".to_string()),
("TICKET".to_string(), "ticket".to_string()),
("TP".to_string(), "idp_test".to_string()),
("TS".to_string(), "idp_test".to_string()),
])
}
}
20 changes: 0 additions & 20 deletions backend/middlewares/flow/src/serv/flow_external_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,6 @@ impl FlowExternalServ {
}
}

pub async fn do_find_embed_subrole_id(role_id: &str, ctx: &TardisContext, funs: &TardisFunsInst) -> TardisResult<String> {
let iam_url = &funs.conf::<FlowConfig>().iam_url;

let header = Self::headers(None, funs, ctx).await?;
let resp = funs
.web_client()
.get::<TardisResp<String>>(&format!("{iam_url}/cc/role/get_embed_subrole_id?id={role_id}"), header)
.await?
.body
.ok_or_else(|| funs.err().internal_error("flow_external", "do_find_embed_subrole_id", "illegal response", "500-external-illegal-response"))?;
if resp.code != *"200" {
return Err(funs.err().internal_error("flow_external", "do_find_embed_subrole_id", "illegal response", "500-external-illegal-response"));
}
if let Some(data) = resp.data {
Ok(data)
} else {
Err(funs.err().internal_error("flow_external", "do_find_embed_subrole_id", "illegal response", "500-external-illegal-response"))
}
}

async fn get_external_url(tag: &str, ctx: &TardisContext, funs: &TardisFunsInst) -> TardisResult<String> {
let external_url = SpiKvClient::get_item(format!("{}:config:{}", flow_constants::DOMAIN_CODE, tag), None, funs, ctx)
.await?
Expand Down
10 changes: 9 additions & 1 deletion frontend/sdks/invoke/src/clients/spi_search_client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use tardis::basic::dto::TardisContext;
use tardis::basic::result::TardisResult;
use tardis::web::web_resp::{TardisPage, TardisResp};
use tardis::TardisFunsInst;

use crate::dto::search_item_dto::{SearchEventItemDeleteReq, SearchEventItemModifyReq, SearchItemAddReq, SearchItemModifyReq};
use crate::dto::search_item_dto::{SearchEventItemDeleteReq, SearchEventItemModifyReq, SearchItemAddReq, SearchItemModifyReq, SearchItemSearchReq, SearchItemSearchResp};
use crate::invoke_enumeration::InvokeModuleKind;

use super::base_spi_client::BaseSpiClient;
Expand Down Expand Up @@ -74,6 +75,13 @@ impl SpiSearchClient {
SpiKvClient::delete_item(&format!("__k_n__:{tag}:{key}"), funs, ctx).await?;
Ok(())
}

pub async fn search(search_req: &SearchItemSearchReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<Option<TardisPage<SearchItemSearchResp>>> {
let search_url = BaseSpiClient::module_url(InvokeModuleKind::Search, funs).await?;
let headers = BaseSpiClient::headers(None, funs, ctx).await?;
let resp = funs.web_client().put::<SearchItemSearchReq, TardisResp<TardisPage<SearchItemSearchResp>>>(format!("{search_url}/ci/item/search"), search_req, headers.clone()).await?;
BaseSpiClient::package_resp(resp)
}
}
#[cfg(feature = "event")]
impl EventCenterClient {
Expand Down
Loading

0 comments on commit 36a9dd9

Please sign in to comment.