feat: add huike_push_info for PushInfo extra accessors; update notifications

Made-with: Cursor
This commit is contained in:
2026-04-24 09:17:32 +08:00
parent 86b1a988a9
commit 2d7a46a927
8 changed files with 160 additions and 55 deletions
Generated
+10
View File
@@ -1083,6 +1083,7 @@ dependencies = [
"htykc_models", "htykc_models",
"htyuc_models", "htyuc_models",
"htyuc_remote", "htyuc_remote",
"huike_push_info",
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",
@@ -1242,6 +1243,7 @@ dependencies = [
"htyuc_models", "htyuc_models",
"htyuc_remote", "htyuc_remote",
"htyws_models", "htyws_models",
"huike_push_info",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
@@ -1267,6 +1269,14 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "huike_push_info"
version = "0.1.0"
dependencies = [
"htycommons",
"serde_json",
]
[[package]] [[package]]
name = "humantime" name = "humantime"
version = "2.3.0" version = "2.3.0"
+2
View File
@@ -1,5 +1,6 @@
[workspace] [workspace]
members = [ members = [
"huike_push_info",
"htyws", "htyws",
"htyws_models", "htyws_models",
"htykc_models", "htykc_models",
@@ -23,6 +24,7 @@ authors = ["阿男 <l.weinan@gmail.com>", "buddy"]
edition = "2021" edition = "2021"
[workspace.dependencies] [workspace.dependencies]
huike_push_info = { path = "huike_push_info" }
htycommons = { git = "https://github.com/alchemy-studio/AuthCore.git" } htycommons = { git = "https://github.com/alchemy-studio/AuthCore.git" }
htyuc_models = { git = "https://github.com/alchemy-studio/AuthCore.git" } htyuc_models = { git = "https://github.com/alchemy-studio/AuthCore.git" }
htyuc_remote = { git = "https://github.com/alchemy-studio/AuthCore.git" } htyuc_remote = { git = "https://github.com/alchemy-studio/AuthCore.git" }
+1
View File
@@ -7,6 +7,7 @@ edition = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
huike_push_info = { workspace = true }
htycommons = { workspace = true } htycommons = { workspace = true }
htyuc_models = { workspace = true } htyuc_models = { workspace = true }
htyuc_remote = { workspace = true } htyuc_remote = { workspace = true }
+15 -14
View File
@@ -3,6 +3,7 @@ use htycommons::common::{current_local_datetime, HtyErr, HtyErrCode};
use htycommons::db::{DbState, UNREAD}; use htycommons::db::{DbState, UNREAD};
use htycommons::jwt::jwt_decode_token; use htycommons::jwt::jwt_decode_token;
use htycommons::models::*; use htycommons::models::*;
use huike_push_info::PushInfoExt;
use htycommons::web::{AuthorizationHeader, HtyHostHeader, HtySudoerTokenHeader}; use htycommons::web::{AuthorizationHeader, HtyHostHeader, HtySudoerTokenHeader};
use htycommons::wx::{ use htycommons::wx::{
ReqWxMessageData2keywordTemplate, ReqWxMessageData3Things2Template, ReqWxMessageData2keywordTemplate, ReqWxMessageData3Things2Template,
@@ -332,7 +333,7 @@ async fn build_wx_push_message_for_create_or_update_clazz(
value: val_thing1.replace( value: val_thing1.replace(
"STUDENT_NAME", "STUDENT_NAME",
push_info push_info
.student_name .student_name()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("student_name is required"))? .ok_or_else(|| anyhow!("student_name is required"))?
.as_str(), .as_str(),
@@ -343,7 +344,7 @@ async fn build_wx_push_message_for_create_or_update_clazz(
value: val_thing2.replace( value: val_thing2.replace(
"KECHENG_NAME", "KECHENG_NAME",
push_info push_info
.clazz_name .clazz_name()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("clazz_name is required"))? .ok_or_else(|| anyhow!("clazz_name is required"))?
.as_str(), .as_str(),
@@ -354,7 +355,7 @@ async fn build_wx_push_message_for_create_or_update_clazz(
value: val_thing4.replace( value: val_thing4.replace(
"TEACHER_NAME", "TEACHER_NAME",
push_info push_info
.teacher_name .teacher_name()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("teacher_name is required"))? .ok_or_else(|| anyhow!("teacher_name is required"))?
.as_str(), .as_str(),
@@ -369,7 +370,7 @@ async fn build_wx_push_message_for_create_or_update_clazz(
.replace( .replace(
"START_FROM", "START_FROM",
push_info push_info
.start_from .start_from()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("start_from is required"))? .ok_or_else(|| anyhow!("start_from is required"))?
.as_str(), .as_str(),
@@ -377,7 +378,7 @@ async fn build_wx_push_message_for_create_or_update_clazz(
.replace( .replace(
"END_BY", "END_BY",
push_info push_info
.end_by .end_by()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("end_by is required"))? .ok_or_else(|| anyhow!("end_by is required"))?
.as_str(), .as_str(),
@@ -453,7 +454,7 @@ async fn build_wx_push_message_for_delete_clazz(
value: val_thing2.replace( value: val_thing2.replace(
"STUDENT_NAME", "STUDENT_NAME",
push_info push_info
.student_name .student_name()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("student_name is required"))? .ok_or_else(|| anyhow!("student_name is required"))?
.as_str(), .as_str(),
@@ -464,7 +465,7 @@ async fn build_wx_push_message_for_delete_clazz(
value: val_thing3.replace( value: val_thing3.replace(
"KECHENG_NAME", "KECHENG_NAME",
push_info push_info
.clazz_name .clazz_name()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("clazz_name is required"))? .ok_or_else(|| anyhow!("clazz_name is required"))?
.as_str(), .as_str(),
@@ -475,7 +476,7 @@ async fn build_wx_push_message_for_delete_clazz(
value: val_thing10.replace( value: val_thing10.replace(
"TEACHER_NAME", "TEACHER_NAME",
push_info push_info
.teacher_name .teacher_name()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("teacher_name is required"))? .ok_or_else(|| anyhow!("teacher_name is required"))?
.as_str(), .as_str(),
@@ -487,7 +488,7 @@ async fn build_wx_push_message_for_delete_clazz(
.replace( .replace(
"START_FROM", "START_FROM",
push_info push_info
.start_from .start_from()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("start_from is required"))? .ok_or_else(|| anyhow!("start_from is required"))?
.as_str(), .as_str(),
@@ -495,7 +496,7 @@ async fn build_wx_push_message_for_delete_clazz(
.replace( .replace(
"END_BY", "END_BY",
push_info push_info
.end_by .end_by()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("end_by is required"))? .ok_or_else(|| anyhow!("end_by is required"))?
.as_str(), .as_str(),
@@ -582,7 +583,7 @@ async fn build_wx_push_message_for_teacher_comment_clazz(
.replace( .replace(
"TEACHER_NAME", "TEACHER_NAME",
push_info push_info
.teacher_name .teacher_name()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("teacher_name is required"))? .ok_or_else(|| anyhow!("teacher_name is required"))?
.as_str(), .as_str(),
@@ -590,7 +591,7 @@ async fn build_wx_push_message_for_teacher_comment_clazz(
.replace( .replace(
"START_FROM", "START_FROM",
push_info push_info
.start_from .start_from()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("start_from is required"))? .ok_or_else(|| anyhow!("start_from is required"))?
.as_str(), .as_str(),
@@ -598,7 +599,7 @@ async fn build_wx_push_message_for_teacher_comment_clazz(
.replace( .replace(
"END_BY", "END_BY",
push_info push_info
.end_by .end_by()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("end_by is required"))? .ok_or_else(|| anyhow!("end_by is required"))?
.as_str(), .as_str(),
@@ -606,7 +607,7 @@ async fn build_wx_push_message_for_teacher_comment_clazz(
.replace( .replace(
"KECHENG_NAME", "KECHENG_NAME",
push_info push_info
.clazz_name .clazz_name()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("clazz_name is required"))? .ok_or_else(|| anyhow!("clazz_name is required"))?
.as_str(), .as_str(),
+1
View File
@@ -7,6 +7,7 @@ edition = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
huike_push_info = { workspace = true }
htycommons = { workspace = true } htycommons = { workspace = true }
htyuc_models = { workspace = true } htyuc_models = { workspace = true }
htyuc_remote = { workspace = true } htyuc_remote = { workspace = true }
+41 -41
View File
@@ -9,6 +9,7 @@ use htycommons::common::{current_local_datetime, HtyErr, HtyErrCode};
use htycommons::db::{extract_conn, fetch_db_conn, DbState, UNREAD}; use htycommons::db::{extract_conn, fetch_db_conn, DbState, UNREAD};
use htycommons::jwt::jwt_decode_token; use htycommons::jwt::jwt_decode_token;
use htycommons::models::*; use htycommons::models::*;
use huike_push_info::PushInfoExt;
use htycommons::wx::{ use htycommons::wx::{
ReqWxMessageData2keywordTemplate, ReqWxMessageData3KeywordTemplate, ReqWxMessageData2keywordTemplate, ReqWxMessageData3KeywordTemplate,
ReqWxMessageData4KeywordTemplate, ReqWxMessageDataValue, ReqWxMiniProgram, ReqWxPushMessage, ReqWxMessageData4KeywordTemplate, ReqWxMessageDataValue, ReqWxMiniProgram, ReqWxPushMessage,
@@ -317,7 +318,7 @@ pub async fn raw_notify(
} }
"create_resource_note_group" => { "create_resource_note_group" => {
let resource_note_group_id = let resource_note_group_id =
push_info.resource_note_group_id.clone().ok_or(HtyErr { push_info.resource_note_group_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("resource_note_group_id is none".to_string()), reason: Some("resource_note_group_id is none".to_string()),
})?; })?;
@@ -326,8 +327,8 @@ pub async fn raw_notify(
extract_conn(fetch_db_conn(&db_pool)?).deref_mut(), extract_conn(fetch_db_conn(&db_pool)?).deref_mut(),
)?; )?;
let course_name = push_info.qumu_name.clone(); let course_name = push_info.qumu_name();
let course_section_name = push_info.qumu_section_name.clone(); let course_section_name = push_info.qumu_section_name();
let push_message = build_wx_push_message_for_create_resource_note_group( let push_message = build_wx_push_message_for_create_resource_note_group(
&notify_type, &notify_type,
@@ -368,7 +369,7 @@ pub async fn raw_notify(
); );
} }
"create_piyue" => { "create_piyue" => {
let piyue_id = push_info.piyue_id.clone().ok_or(HtyErr { let piyue_id = push_info.piyue_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("piyue_id is none".to_string()), reason: Some("piyue_id is none".to_string()),
})?; })?;
@@ -410,7 +411,7 @@ pub async fn raw_notify(
); );
} }
"create_lianxi" => { "create_lianxi" => {
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr { let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("lianxi_id is none".to_string()), reason: Some("lianxi_id is none".to_string()),
})?; })?;
@@ -453,7 +454,7 @@ pub async fn raw_notify(
); );
} }
"delete_lianxi" => { "delete_lianxi" => {
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr { let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("lianxi_id is none".to_string()), reason: Some("lianxi_id is none".to_string()),
})?; })?;
@@ -496,7 +497,7 @@ pub async fn raw_notify(
); );
} }
"create_daka" => { "create_daka" => {
let daka_id = push_info.daka_id.clone().ok_or(HtyErr { let daka_id = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -505,7 +506,7 @@ pub async fn raw_notify(
extract_conn(fetch_db_conn(&db_pool)?).deref_mut(), extract_conn(fetch_db_conn(&db_pool)?).deref_mut(),
)?; )?;
let real_name = user_send_from.real_name.clone().unwrap_or_default(); let real_name = user_send_from.real_name.clone().unwrap_or_default();
let remark = push_info.remark.clone(); let remark = push_info.remark();
let push_message = build_wx_push_message_for_create_daka( let push_message = build_wx_push_message_for_create_daka(
&to_user_openid, &to_user_openid,
&real_name, &real_name,
@@ -541,7 +542,7 @@ pub async fn raw_notify(
); );
} }
"update_daka" => { "update_daka" => {
let daka_id = push_info.daka_id.clone().ok_or(HtyErr { let daka_id = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -584,7 +585,7 @@ pub async fn raw_notify(
); );
} }
"delete_daka" => { "delete_daka" => {
let daka_id = push_info.daka_id.clone().ok_or(HtyErr { let daka_id = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -627,7 +628,7 @@ pub async fn raw_notify(
); );
} }
"create_jihua" => { "create_jihua" => {
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -670,7 +671,7 @@ pub async fn raw_notify(
); );
} }
"update_jihua" => { "update_jihua" => {
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -713,7 +714,7 @@ pub async fn raw_notify(
); );
} }
"delete_jihua" => { "delete_jihua" => {
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -805,7 +806,7 @@ async fn build_wx_push_message_for_student_comment_piyue(
extract_conn(fetch_db_conn(&db_pool)?).deref_mut(), extract_conn(fetch_db_conn(&db_pool)?).deref_mut(),
)?; )?;
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr { let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("lianxi_id is none".to_string()), reason: Some("lianxi_id is none".to_string()),
})?; })?;
@@ -817,7 +818,7 @@ async fn build_wx_push_message_for_student_comment_piyue(
let course_section = let course_section =
lianxi.find_linked_course_section(extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?; lianxi.find_linked_course_section(extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
let lianxi_parent_text = if let Some(jihua_id) = &push_info.jihua_id { let lianxi_parent_text = if let Some(jihua_id) = push_info.jihua_id().as_ref() {
let jihua = let jihua =
Jihua::find_by_id(jihua_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?; Jihua::find_by_id(jihua_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
format!( format!(
@@ -825,7 +826,7 @@ async fn build_wx_push_message_for_student_comment_piyue(
jihua.start_date.format("%Y-%m-%d").to_string(), jihua.start_date.format("%Y-%m-%d").to_string(),
jihua.end_date.format("%Y-%m-%d").to_string() jihua.end_date.format("%Y-%m-%d").to_string()
) )
} else if let Some(daka_id) = &push_info.daka_id { } else if let Some(daka_id) = push_info.daka_id().as_ref() {
// daka // daka
let daka = Daka::find_by_id(daka_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?; let daka = Daka::find_by_id(daka_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
format!( format!(
@@ -971,7 +972,7 @@ async fn build_wx_push_message_for_student_comment_daka(
extract_conn(fetch_db_conn(&db_pool)?).deref_mut(), extract_conn(fetch_db_conn(&db_pool)?).deref_mut(),
)?; )?;
let id_daka = push_info.daka_id.clone().ok_or(HtyErr { let id_daka = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -1091,7 +1092,7 @@ async fn build_wx_push_message_for_student_comment_jihua(
extract_conn(fetch_db_conn(&db_pool)?).deref_mut(), extract_conn(fetch_db_conn(&db_pool)?).deref_mut(),
)?; )?;
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -1210,7 +1211,7 @@ async fn build_wx_push_message_for_teacher_comment_piyue(
extract_conn(fetch_db_conn(&db_pool)?).deref_mut(), extract_conn(fetch_db_conn(&db_pool)?).deref_mut(),
)?; )?;
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr { let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("lianxi_id is none".to_string()), reason: Some("lianxi_id is none".to_string()),
})?; })?;
@@ -1226,7 +1227,7 @@ async fn build_wx_push_message_for_teacher_comment_piyue(
course_section course_section
); );
let lianxi_parent_text = if let Some(jihua_id) = &push_info.jihua_id { let lianxi_parent_text = if let Some(jihua_id) = push_info.jihua_id().as_ref() {
let jihua = let jihua =
Jihua::find_by_id(jihua_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?; Jihua::find_by_id(jihua_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
format!( format!(
@@ -1234,7 +1235,7 @@ async fn build_wx_push_message_for_teacher_comment_piyue(
jihua.start_date.format("%Y-%m-%d").to_string(), jihua.start_date.format("%Y-%m-%d").to_string(),
jihua.end_date.format("%Y-%m-%d").to_string() jihua.end_date.format("%Y-%m-%d").to_string()
) )
} else if let Some(daka_id) = &push_info.daka_id { } else if let Some(daka_id) = push_info.daka_id().as_ref() {
// daka // daka
let daka = Daka::find_by_id(daka_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?; let daka = Daka::find_by_id(daka_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
format!( format!(
@@ -1378,7 +1379,7 @@ async fn build_wx_push_message_for_teacher_comment_jihua(
extract_conn(fetch_db_conn(&db_pool)?).deref_mut(), extract_conn(fetch_db_conn(&db_pool)?).deref_mut(),
)?; )?;
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -1489,7 +1490,7 @@ async fn build_wx_push_message_for_teacher_comment_daka(
extract_conn(fetch_db_conn(&db_pool)?).deref_mut(), extract_conn(fetch_db_conn(&db_pool)?).deref_mut(),
)?; )?;
let id_daka = push_info.daka_id.clone().ok_or(HtyErr { let id_daka = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -2480,9 +2481,8 @@ async fn build_wx_push_message_for_create_piyue(
value: val_first.replace( value: val_first.replace(
"PIYUE_TITLE", "PIYUE_TITLE",
in_push_info in_push_info
.clone() .first()
.first .unwrap_or_else(|| "同学,您提交的练习老师批阅啦".to_string())
.unwrap_or("同学,您提交的练习老师批阅啦".to_string())
.as_str(), .as_str(),
), ),
}; };
@@ -2878,7 +2878,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
match notify_type.as_str() { match notify_type.as_str() {
"student_comment_piyue" => { "student_comment_piyue" => {
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr { let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("lianxi_id is none".to_string()), reason: Some("lianxi_id is none".to_string()),
})?; })?;
@@ -2945,7 +2945,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
} }
} }
"teacher_comment_piyue" => { "teacher_comment_piyue" => {
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr { let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("lianxi_id is none".to_string()), reason: Some("lianxi_id is none".to_string()),
})?; })?;
@@ -3011,7 +3011,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
} }
} }
"create_jihua" => { "create_jihua" => {
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -3039,7 +3039,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.jihua_end_at = Some(in_jihua.end_date); content.jihua_end_at = Some(in_jihua.end_date);
} }
"update_jihua" => { "update_jihua" => {
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -3067,7 +3067,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.jihua_end_at = Some(in_jihua.end_date); content.jihua_end_at = Some(in_jihua.end_date);
} }
"delete_jihua" => { "delete_jihua" => {
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -3095,7 +3095,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.jihua_end_at = Some(in_jihua.end_date); content.jihua_end_at = Some(in_jihua.end_date);
} }
"create_daka" => { "create_daka" => {
let daka_id = push_info.daka_id.clone().ok_or(HtyErr { let daka_id = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -3121,7 +3121,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.daka_duration_days = Some(in_daka.duration_days); content.daka_duration_days = Some(in_daka.duration_days);
} }
"update_daka" => { "update_daka" => {
let daka_id = push_info.daka_id.clone().ok_or(HtyErr { let daka_id = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -3147,7 +3147,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.daka_duration_days = Some(in_daka.duration_days); content.daka_duration_days = Some(in_daka.duration_days);
} }
"delete_daka" => { "delete_daka" => {
let daka_id = push_info.daka_id.clone().ok_or(HtyErr { let daka_id = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -3173,7 +3173,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.daka_duration_days = Some(in_daka.duration_days); content.daka_duration_days = Some(in_daka.duration_days);
} }
"student_comment_jihua" => { "student_comment_jihua" => {
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -3201,7 +3201,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.jihua_end_at = Some(in_jihua.end_date); content.jihua_end_at = Some(in_jihua.end_date);
} }
"teacher_comment_jihua" => { "teacher_comment_jihua" => {
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr { let jihua_id = push_info.jihua_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -3229,7 +3229,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.jihua_end_at = Some(in_jihua.end_date); content.jihua_end_at = Some(in_jihua.end_date);
} }
"student_comment_daka" => { "student_comment_daka" => {
let id_daka = push_info.daka_id.clone().ok_or(HtyErr { let id_daka = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("daka_id is none".to_string()), reason: Some("daka_id is none".to_string()),
})?; })?;
@@ -3257,7 +3257,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
content.daka_duration_days = Some(in_daka.duration_days); content.daka_duration_days = Some(in_daka.duration_days);
} }
"teacher_comment_daka" => { "teacher_comment_daka" => {
let id_daka = push_info.daka_id.clone().ok_or(HtyErr { let id_daka = push_info.daka_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("jihua_id is none".to_string()), reason: Some("jihua_id is none".to_string()),
})?; })?;
@@ -3286,7 +3286,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
// nothing need to be stored because we already have push_info stored into hty_tongzhi. // nothing need to be stored because we already have push_info stored into hty_tongzhi.
} }
"create_piyue" => { "create_piyue" => {
let piyue_id = push_info.piyue_id.clone().ok_or(HtyErr { let piyue_id = push_info.piyue_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("piyue_id is none".to_string()), reason: Some("piyue_id is none".to_string()),
})?; })?;
@@ -3363,7 +3363,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
} }
} }
"create_lianxi" => { "create_lianxi" => {
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr { let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("lianxi_id is none".to_string()), reason: Some("lianxi_id is none".to_string()),
})?; })?;
@@ -3436,7 +3436,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
} }
} }
"delete_lianxi" => { "delete_lianxi" => {
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr { let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
code: HtyErrCode::NullErr, code: HtyErrCode::NullErr,
reason: Some("lianxi_id is none".to_string()), reason: Some("lianxi_id is none".to_string()),
})?; })?;
+10
View File
@@ -0,0 +1,10 @@
[package]
name = "huike_push_info"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
description = "Huike-specific accessors for htycommons::PushInfo::extra (business keys stay out of AuthCore)."
[dependencies]
htycommons = { workspace = true }
serde_json = { workspace = true }
+80
View File
@@ -0,0 +1,80 @@
//! Accessors for domain keys stored in [`htycommons::models::PushInfo::extra`].
#![forbid(unsafe_code)]
use htycommons::models::PushInfo;
use serde_json::{Map, Value};
fn value_to_opt_string(v: &Value) -> Option<String> {
match v {
Value::Null => None,
Value::String(s) => Some(s.clone()),
Value::Number(n) => Some(n.to_string()),
Value::Bool(b) => Some(b.to_string()),
Value::Array(_) | Value::Object(_) => Some(v.to_string()),
}
}
fn map_get_str(map: &Map<String, Value>, key: &str) -> Option<String> {
map.get(key).and_then(value_to_opt_string)
}
/// Read business / template keys from the flattened `extra` map (Jsonb round-trip compatible).
pub trait PushInfoExt {
fn extra_map(&self) -> &Map<String, Value>;
fn daka_id(&self) -> Option<String> {
map_get_str(self.extra_map(), "daka_id")
}
fn jihua_id(&self) -> Option<String> {
map_get_str(self.extra_map(), "jihua_id")
}
fn lianxi_id(&self) -> Option<String> {
map_get_str(self.extra_map(), "lianxi_id")
}
fn piyue_id(&self) -> Option<String> {
map_get_str(self.extra_map(), "piyue_id")
}
fn qumu_name(&self) -> Option<String> {
map_get_str(self.extra_map(), "qumu_name")
}
fn qumu_section_name(&self) -> Option<String> {
map_get_str(self.extra_map(), "qumu_section_name")
}
fn resource_note_group_id(&self) -> Option<String> {
map_get_str(self.extra_map(), "resource_note_group_id")
}
fn remark(&self) -> Option<String> {
map_get_str(self.extra_map(), "remark")
}
fn first(&self) -> Option<String> {
map_get_str(self.extra_map(), "first")
}
fn reject_reason(&self) -> Option<String> {
map_get_str(self.extra_map(), "reject_reason")
}
fn clazz_id(&self) -> Option<String> {
map_get_str(self.extra_map(), "clazz_id").or_else(|| map_get_str(self.extra_map(), "kecheng_id"))
}
fn clazz_name(&self) -> Option<String> {
map_get_str(self.extra_map(), "clazz_name")
.or_else(|| map_get_str(self.extra_map(), "kecheng_name"))
}
fn student_name(&self) -> Option<String> {
map_get_str(self.extra_map(), "student_name")
}
fn teacher_name(&self) -> Option<String> {
map_get_str(self.extra_map(), "teacher_name")
}
fn start_from(&self) -> Option<String> {
map_get_str(self.extra_map(), "start_from")
}
fn end_by(&self) -> Option<String> {
map_get_str(self.extra_map(), "end_by")
}
}
impl PushInfoExt for PushInfo {
fn extra_map(&self) -> &Map<String, Value> {
&self.extra
}
}