Skip to content

Commit

Permalink
Merge branch 'main' into split
Browse files Browse the repository at this point in the history
# Conflicts:
#	support/iam/src/console_interface/api/iam_ci_cert_api.rs
  • Loading branch information
李节龙 authored and 李节龙 committed Dec 8, 2023
2 parents 8efde75 + ed2d73e commit 212cc98
Show file tree
Hide file tree
Showing 27 changed files with 375 additions and 115 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ lazy_static = { version = "1" }
itertools = { version = "0" }
fancy-regex = { version = "0" }
run_script = { version = "0.10" }
testcontainers-modules = { version = "0.1"}
strum ={ version = "0.25", features = ["derive"] }
testcontainers-modules = { version = "0.1" }
strum = { version = "0.25", features = ["derive"] }
# tardis
tardis = { version = "=0.1.0-rc.3" }
# tardis = { path = "../tardis/tardis" }
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "9424e16" }
#spacegate
spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev = "40e7bf8d0b",features = [
spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev = "40e7bf8d0b", features = [
"ws",
"cache",
"k8s",
Expand All @@ -72,4 +72,4 @@ spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev =
# "ws",
# "cache",
# "k8s",
#] }
#] }
1 change: 1 addition & 0 deletions basic/src/spi/dto/spi_bs_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct SpiBsFilterReq {
pub rel2: Option<RbumItemRelFilterReq>,
pub private: Option<bool>,
pub kind_code: Option<String>,
pub kind_codes: Option<Vec<String>>,
pub kind_id: Option<String>,
pub domain_code: Option<String>,
}
Expand Down
7 changes: 7 additions & 0 deletions basic/src/spi/serv/spi_bs_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ impl RbumItemCrudOperation<spi_bs::ActiveModel, SpiBsAddReq, SpiBsModifyReq, Spi
if let Some(kind_code) = &filter.kind_code {
query.and_where(Expr::col((rbum_kind::Entity, rbum_domain::Column::Code)).eq(kind_code.to_string()));
}
if let Some(kind_codes) = &filter.kind_codes {
if kind_codes.len() == 1 {
query.and_where(Expr::col((rbum_kind::Entity, rbum_domain::Column::Code)).eq(kind_codes.first().unwrap().to_string()));
} else if !kind_codes.is_empty() {
query.and_where(Expr::col((rbum_kind::Entity, rbum_domain::Column::Code)).is_in(kind_codes));
}
}
if let Some(kind_id) = &filter.kind_id {
query.and_where(Expr::col((rbum_kind::Entity, rbum_domain::Column::Id)).eq(kind_id.to_string()));
}
Expand Down
1 change: 1 addition & 0 deletions middleware/flow/src/dto/flow_external_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct FlowExternalReq {
pub target_sys_state: Option<FlowSysStateKind>,
pub original_state: Option<String>,
pub original_sys_state: Option<FlowSysStateKind>,
pub transition_name: Option<String>,
pub owner_paths: String,
pub obj_ids: Vec<String>,
pub notify: Option<bool>,
Expand Down
2 changes: 2 additions & 0 deletions middleware/flow/src/dto/flow_transition_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ pub enum FlowTransitionActionByVarChangeInfoChangedKind {
ChangeContent,
#[sea_orm(string_value = "auto_get_operate_time")]
AutoGetOperateTime,
#[sea_orm(string_value = "auto_get_operator")]
AutoGetOperator,
#[sea_orm(string_value = "select_field")]
SelectField,
}
Expand Down
10 changes: 9 additions & 1 deletion middleware/flow/src/serv/flow_config_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ pub struct FlowConfigServ;
impl FlowConfigServ {
pub async fn modify_config(modify_req: &Vec<FlowConfigModifyReq>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
for req in modify_req {
SpiKvClient::add_or_modify_item(&format!("{}:config:{}", flow_constants::DOMAIN_CODE, req.code.clone()), &req.value, None, Some(RbumScopeLevelKind::Root.to_int()), funs, ctx).await?;
SpiKvClient::add_or_modify_item(
&format!("{}:config:{}", flow_constants::DOMAIN_CODE, req.code.clone()),
&req.value,
None,
Some(RbumScopeLevelKind::Root.to_int()),
funs,
ctx,
)
.await?;
}
Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions middleware/flow/src/serv/flow_external_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl FlowExternalServ {
target_sys_state: Option<FlowSysStateKind>,
original_state: Option<String>,
original_sys_state: Option<FlowSysStateKind>,
transition_name: Option<String>,
is_notify: bool,
params: Vec<FlowExternalParams>,
ctx: &TardisContext,
Expand Down Expand Up @@ -112,6 +113,7 @@ impl FlowExternalServ {
original_state,
original_sys_state,
notify: Some(is_notify),
transition_name,
params,
..Default::default()
};
Expand Down Expand Up @@ -140,6 +142,7 @@ impl FlowExternalServ {
target_sys_state: FlowSysStateKind,
original_state: String,
original_sys_state: FlowSysStateKind,
transition_name: String,
is_notify: bool,
ctx: &TardisContext,
funs: &TardisFunsInst,
Expand All @@ -159,6 +162,7 @@ impl FlowExternalServ {
target_sys_state: Some(target_sys_state),
original_state: Some(original_state),
original_sys_state: Some(original_sys_state),
transition_name: Some(transition_name),
notify: Some(is_notify),
..Default::default()
};
Expand Down
21 changes: 8 additions & 13 deletions middleware/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ impl FlowInstServ {
Some(next_flow_state.sys_state.clone()),
Some(prev_flow_state.name.clone()),
Some(prev_flow_state.sys_state.clone()),
Some(next_flow_transition.next_flow_state_name.clone()),
next_transition_detail.is_notify,
params,
ctx,
Expand Down Expand Up @@ -804,6 +805,7 @@ impl FlowInstServ {
next_flow_state.sys_state,
prev_flow_state.name.clone(),
prev_flow_state.sys_state,
next_transition_detail.name.clone(),
next_transition_detail.is_notify,
ctx,
funs,
Expand All @@ -814,16 +816,7 @@ impl FlowInstServ {
let post_changes =
model_transition.into_iter().find(|model_transition| model_transition.id == next_flow_transition.next_flow_transition_id).unwrap_or_default().action_by_post_changes();
if !post_changes.is_empty() {
Self::do_post_change(
&flow_inst_detail,
&flow_model,
post_changes,
updated_instance_list,
next_transition_detail.is_notify,
ctx,
funs,
)
.await?;
Self::do_post_change(&flow_inst_detail, &flow_model, &next_transition_detail, post_changes, updated_instance_list, ctx, funs).await?;
}
let next_flow_transitions = Self::do_find_next_transitions(&flow_inst_detail, &flow_model, None, &None, skip_filter, funs, ctx).await?.next_flow_transitions;

Expand Down Expand Up @@ -852,9 +845,9 @@ impl FlowInstServ {
async fn do_post_change(
current_inst: &FlowInstDetailResp,
current_model: &FlowModelDetailResp,
transition_detail: &FlowTransitionDetailResp,
post_changes: Vec<FlowTransitionActionChangeInfo>,
updated_instance_list: &mut Vec<String>,
is_notify: bool,
ctx: &TardisContext,
funs: &TardisFunsInst,
) -> TardisResult<()> {
Expand Down Expand Up @@ -889,7 +882,8 @@ impl FlowInstServ {
None,
None,
None,
is_notify,
Some(transition_detail.name.clone()),
transition_detail.is_notify,
vec![FlowExternalParams {
rel_kind: None,
rel_tag: None,
Expand All @@ -914,7 +908,8 @@ impl FlowInstServ {
None,
None,
None,
is_notify,
Some(transition_detail.name.clone()),
transition_detail.is_notify,
vec![FlowExternalParams {
rel_kind: None,
rel_tag: None,
Expand Down
7 changes: 6 additions & 1 deletion middleware/flow/src/serv/flow_model_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,12 @@ impl FlowModelServ {
Ok(())
}

async fn find_transitions(flow_model_id: &str, specified_state_ids: Option<&[String]>, funs: &TardisFunsInst, _ctx: &TardisContext) -> TardisResult<Vec<FlowTransitionDetailResp>> {
async fn find_transitions(
flow_model_id: &str,
specified_state_ids: Option<&[String]>,
funs: &TardisFunsInst,
_ctx: &TardisContext,
) -> TardisResult<Vec<FlowTransitionDetailResp>> {
let from_state_rbum_table = Alias::new("from_state_rbum");
let from_state_table = Alias::new("from_state");
let to_state_rbum_table = Alias::new("to_state_rbum");
Expand Down
29 changes: 20 additions & 9 deletions middleware/flow/src/serv/flow_state_serv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};

use bios_basic::rbum::{
dto::{
Expand Down Expand Up @@ -307,16 +307,27 @@ impl FlowStateServ {
ctx,
)
.await?;
let mut result = vec![];
let mut result = HashMap::new();
let insts = FlowInstServ::find_detail(req.inst_ids.clone(), funs, ctx).await?;
for (state_id, state_name) in states {
let inst_ids = insts.iter().filter(|inst| inst.current_state_id == state_id).map(|inst| inst.id.clone()).collect_vec();
result.push(FlowStateCountGroupByStateResp {
state_name,
count: inst_ids.len().to_string(),
inst_ids,
});
let mut inst_ids = insts.iter().filter(|inst| inst.current_state_id == state_id).map(|inst| inst.id.clone()).collect_vec();
result
.entry(state_name.clone())
.and_modify(|resp: &mut FlowStateCountGroupByStateResp| {
resp.inst_ids.append(&mut inst_ids);
resp.count = (resp.count.parse::<usize>().unwrap_or_default() + inst_ids.len()).to_string()
})
.or_insert(FlowStateCountGroupByStateResp {
state_name,
count: inst_ids.len().to_string(),
inst_ids,
});
// result.push(FlowStateCountGroupByStateResp {
// state_name,
// count: inst_ids.len().to_string(),
// inst_ids,
// });
}
Ok(result)
Ok(result.into_values().collect_vec())
}
}
9 changes: 8 additions & 1 deletion sdk/invoke/src/clients/spi_kv_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ pub struct KvItemDetailResp {
}

impl SpiKvClient {
pub async fn add_or_modify_item<T: ?Sized + Serialize>(key: &str, value: &T, info: Option<String>, scope_level: Option<i16>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
pub async fn add_or_modify_item<T: ?Sized + Serialize>(
key: &str,
value: &T,
info: Option<String>,
scope_level: Option<i16>,
funs: &TardisFunsInst,
ctx: &TardisContext,
) -> TardisResult<()> {
let kv_url: String = BaseSpiClient::module_url(InvokeModuleKind::Kv, funs).await?;
let headers = BaseSpiClient::headers(None, funs, ctx).await?;
let json = json!({
Expand Down
3 changes: 1 addition & 2 deletions spi/spi-conf/src/serv/placehodler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ enum Segment<'s> {
}

fn parse_content(content: &str) -> Vec<Segment<'_>> {
let mut new_content = String::new();
let matcher = place_holder_regex().find_iter(content);
let mut idx = 0;
let mut result = Vec::new();
Expand All @@ -32,7 +31,7 @@ fn parse_content(content: &str) -> Vec<Segment<'_>> {
result.push(Segment::Replace { key });
idx = mat.end();
}
new_content.push_str(&content[idx..]);
result.push(Segment::Raw(&content[idx..]));
result
}

Expand Down
10 changes: 9 additions & 1 deletion spi/spi-kv/src/api/ci/kv_ci_item_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};

use crate::dto::kv_item_dto::{
KvItemAddOrModifyReq, KvItemDetailResp, KvItemMatchReq, KvItemSummaryResp, KvNameAddOrModifyReq, KvNameFindResp, KvTagAddOrModifyReq, KvTagFindResp,
KvItemAddOrModifyReq, KvItemDeleteReq, KvItemDetailResp, KvItemMatchReq, KvItemSummaryResp, KvNameAddOrModifyReq, KvNameFindResp, KvTagAddOrModifyReq, KvTagFindResp,
};
use crate::serv::kv_item_serv;

Expand Down Expand Up @@ -81,6 +81,14 @@ impl KvCiItemApi {
TardisResp::ok(Void {})
}

/// Delete Item Body
#[oai(path = "/item/delete", method = "put")]
async fn delete_item_body(&self, delete_req: Json<KvItemDeleteReq>, ctx: TardisContextExtractor) -> TardisApiResult<Void> {
let funs = crate::get_tardis_inst();
kv_item_serv::delete_item(delete_req.0.key.to_string(), &funs, &ctx.0).await?;
TardisResp::ok(Void {})
}

/// Add Or Modify Key-Name
#[oai(path = "/scene/key-name", method = "put")]
async fn add_or_modify_key_name(&self, mut add_or_modify_req: Json<KvNameAddOrModifyReq>, ctx: TardisContextExtractor) -> TardisApiResult<Void> {
Expand Down
6 changes: 6 additions & 0 deletions spi/spi-kv/src/dto/kv_item_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ pub struct KvItemMatchReq {
pub page_size: u16,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct KvItemDeleteReq {
#[oai(validator(min_length = "2"))]
pub key: TrimString,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct KvNameAddOrModifyReq {
#[oai(validator(min_length = "2"))]
Expand Down
2 changes: 1 addition & 1 deletion spi/spi-kv/src/serv/pg/kv_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn add_or_modify_item(add_or_modify_req: &KvItemAddOrModifyReq, _funs:
Value::from(add_or_modify_req.info.as_ref().unwrap_or(&"".to_string()).as_str()),
Value::from(ctx.owner.clone()),
Value::from(ctx.own_paths.clone()),
Value::from(add_or_modify_req.scope_level.unwrap_or(-1)),
Value::from(add_or_modify_req.scope_level.unwrap_or(0)),
];
let mut update_opt_fragments: Vec<&str> = Vec::new();
update_opt_fragments.push("v = $2");
Expand Down
7 changes: 7 additions & 0 deletions spi/spi-plugin/src/api/ci/plugin_ci_bs_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl PluginCiBsApi {
name: Query<Option<String>>,
kind_id: Query<Option<String>>,
kind_code: Query<Option<String>>,
kind_codes: Query<Option<String>>,
app_tenant_id: Query<Option<String>>,
page_number: Query<u32>,
page_size: Query<u32>,
Expand All @@ -72,6 +73,11 @@ impl PluginCiBsApi {
rel_item_id: Some(app_tenant_id),
..Default::default()
});
let kind_codes: Option<Vec<String>> = if let Some(kind_codes) = kind_codes.0 {
Some(kind_codes.split(",").map(|kind_code| kind_code.to_string()).collect())
} else {
None
};
let result = SpiBsServ::paginate_items(
&SpiBsFilterReq {
basic: RbumBasicFilterReq {
Expand All @@ -81,6 +87,7 @@ impl PluginCiBsApi {
},
kind_id: kind_id.0,
kind_code: kind_code.0,
kind_codes: kind_codes.clone(),
domain_code: Some(funs.module_code().to_string()),
rel,
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst,
{
order_fragments.push(format!("{} {}", sort_item.field, sort_item.order.to_sql()));
} else {
order_fragments.push(format!("ext ->> '{}' {}", sort_item.field, sort_item.order.to_sql()));
order_fragments.push(format!("ext -> '{}' {}", sort_item.field, sort_item.order.to_sql()));
}
}
}
Expand Down
Loading

0 comments on commit 212cc98

Please sign in to comment.