feat: add huike_push_info for PushInfo extra accessors; update notifications
Made-with: Cursor
This commit is contained in:
+41
-41
@@ -9,6 +9,7 @@ use htycommons::common::{current_local_datetime, HtyErr, HtyErrCode};
|
||||
use htycommons::db::{extract_conn, fetch_db_conn, DbState, UNREAD};
|
||||
use htycommons::jwt::jwt_decode_token;
|
||||
use htycommons::models::*;
|
||||
use huike_push_info::PushInfoExt;
|
||||
use htycommons::wx::{
|
||||
ReqWxMessageData2keywordTemplate, ReqWxMessageData3KeywordTemplate,
|
||||
ReqWxMessageData4KeywordTemplate, ReqWxMessageDataValue, ReqWxMiniProgram, ReqWxPushMessage,
|
||||
@@ -317,7 +318,7 @@ pub async fn raw_notify(
|
||||
}
|
||||
"create_resource_note_group" => {
|
||||
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,
|
||||
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(),
|
||||
)?;
|
||||
|
||||
let course_name = push_info.qumu_name.clone();
|
||||
let course_section_name = push_info.qumu_section_name.clone();
|
||||
let course_name = push_info.qumu_name();
|
||||
let course_section_name = push_info.qumu_section_name();
|
||||
|
||||
let push_message = build_wx_push_message_for_create_resource_note_group(
|
||||
¬ify_type,
|
||||
@@ -368,7 +369,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
reason: Some("piyue_id is none".to_string()),
|
||||
})?;
|
||||
@@ -410,7 +411,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
reason: Some("lianxi_id is none".to_string()),
|
||||
})?;
|
||||
@@ -453,7 +454,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
reason: Some("lianxi_id is none".to_string()),
|
||||
})?;
|
||||
@@ -496,7 +497,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
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(),
|
||||
)?;
|
||||
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(
|
||||
&to_user_openid,
|
||||
&real_name,
|
||||
@@ -541,7 +542,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
reason: Some("daka_id is none".to_string()),
|
||||
})?;
|
||||
@@ -584,7 +585,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
reason: Some("daka_id is none".to_string()),
|
||||
})?;
|
||||
@@ -627,7 +628,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
reason: Some("jihua_id is none".to_string()),
|
||||
})?;
|
||||
@@ -670,7 +671,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
reason: Some("jihua_id is none".to_string()),
|
||||
})?;
|
||||
@@ -713,7 +714,7 @@ pub async fn raw_notify(
|
||||
);
|
||||
}
|
||||
"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,
|
||||
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(),
|
||||
)?;
|
||||
|
||||
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr {
|
||||
let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
|
||||
code: HtyErrCode::NullErr,
|
||||
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 =
|
||||
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 =
|
||||
Jihua::find_by_id(jihua_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
|
||||
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.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
|
||||
let daka = Daka::find_by_id(daka_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
|
||||
format!(
|
||||
@@ -971,7 +972,7 @@ async fn build_wx_push_message_for_student_comment_daka(
|
||||
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,
|
||||
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(),
|
||||
)?;
|
||||
|
||||
let jihua_id = push_info.jihua_id.clone().ok_or(HtyErr {
|
||||
let jihua_id = push_info.jihua_id().ok_or(HtyErr {
|
||||
code: HtyErrCode::NullErr,
|
||||
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(),
|
||||
)?;
|
||||
|
||||
let lianxi_id = push_info.lianxi_id.clone().ok_or(HtyErr {
|
||||
let lianxi_id = push_info.lianxi_id().ok_or(HtyErr {
|
||||
code: HtyErrCode::NullErr,
|
||||
reason: Some("lianxi_id is none".to_string()),
|
||||
})?;
|
||||
@@ -1226,7 +1227,7 @@ async fn build_wx_push_message_for_teacher_comment_piyue(
|
||||
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 =
|
||||
Jihua::find_by_id(jihua_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
|
||||
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.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
|
||||
let daka = Daka::find_by_id(daka_id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
|
||||
format!(
|
||||
@@ -1378,7 +1379,7 @@ async fn build_wx_push_message_for_teacher_comment_jihua(
|
||||
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,
|
||||
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(),
|
||||
)?;
|
||||
|
||||
let id_daka = push_info.daka_id.clone().ok_or(HtyErr {
|
||||
let id_daka = push_info.daka_id().ok_or(HtyErr {
|
||||
code: HtyErrCode::NullErr,
|
||||
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(
|
||||
"PIYUE_TITLE",
|
||||
in_push_info
|
||||
.clone()
|
||||
.first
|
||||
.unwrap_or("同学,您提交的练习老师批阅啦".to_string())
|
||||
.first()
|
||||
.unwrap_or_else(|| "同学,您提交的练习老师批阅啦".to_string())
|
||||
.as_str(),
|
||||
),
|
||||
};
|
||||
@@ -2878,7 +2878,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
|
||||
|
||||
match notify_type.as_str() {
|
||||
"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,
|
||||
reason: Some("lianxi_id is none".to_string()),
|
||||
})?;
|
||||
@@ -2945,7 +2945,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
|
||||
}
|
||||
}
|
||||
"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,
|
||||
reason: Some("lianxi_id is none".to_string()),
|
||||
})?;
|
||||
@@ -3011,7 +3011,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
|
||||
}
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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);
|
||||
}
|
||||
"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,
|
||||
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.
|
||||
}
|
||||
"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,
|
||||
reason: Some("piyue_id is none".to_string()),
|
||||
})?;
|
||||
@@ -3363,7 +3363,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
|
||||
}
|
||||
}
|
||||
"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,
|
||||
reason: Some("lianxi_id is none".to_string()),
|
||||
})?;
|
||||
@@ -3436,7 +3436,7 @@ fn build_req_hty_tongzhi<T: Serialize>(
|
||||
}
|
||||
}
|
||||
"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,
|
||||
reason: Some("lianxi_id is none".to_string()),
|
||||
})?;
|
||||
|
||||
Reference in New Issue
Block a user