1
1
use std:: { collections:: HashSet , sync:: Arc } ;
2
2
3
- use crate :: { reach_send_channel :: * , reach_config :: ReachConfig , reach_consts :: * , domain :: * , dto :: * , reach_init :: get_reach_send_channel_map , serv:: * } ;
4
- use bios_basic:: rbum:: helper:: rbum_scope_helper;
3
+ use crate :: { domain :: * , dto :: * , reach_config :: ReachConfig , reach_consts :: * , reach_init :: get_reach_send_channel_map , reach_send_channel :: * , serv:: * } ;
4
+ use bios_basic:: rbum:: { helper:: rbum_scope_helper, serv :: rbum_crud_serv :: RbumCrudOperation } ;
5
5
use bios_sdk_invoke:: clients:: iam_client:: IamClient ;
6
6
use tardis:: {
7
7
basic:: { dto:: TardisContext , result:: TardisResult } ,
8
+ chrono:: Utc ,
8
9
db:: sea_orm:: { sea_query:: Query , * } ,
9
10
log, tokio, TardisFunsInst ,
10
11
} ;
@@ -28,6 +29,7 @@ impl Default for MessageSendListener {
28
29
29
30
impl MessageSendListener {
30
31
async fn execute_send_account ( & self , message : message:: Model , template : message_template:: Model ) -> TardisResult < ( ) > {
32
+ let content_replace: ContentReplace = message. content_replace . parse ( ) ?;
31
33
let cfg = self . funs . conf :: < ReachConfig > ( ) ;
32
34
let _lock = self . sync . lock ( ) . await ;
33
35
let ctx = TardisContext {
@@ -44,7 +46,7 @@ impl MessageSendListener {
44
46
return Ok ( ( ) ) ;
45
47
}
46
48
let mut to = HashSet :: new ( ) ;
47
-
49
+ let start_time = Utc :: now ( ) ;
48
50
let owner_path = rbum_scope_helper:: get_pre_paths ( RBUM_SCOPE_LEVEL_TENANT as i16 , & message. own_paths ) . unwrap_or_default ( ) ;
49
51
for account_id in message. to_res_ids . split ( ACCOUNT_SPLIT ) {
50
52
if let Ok ( mut resp) = iam_client. get_account ( account_id, & owner_path) . await {
@@ -55,12 +57,47 @@ impl MessageSendListener {
55
57
to. insert ( phone) ;
56
58
}
57
59
}
58
- match self . channel . send ( message. rel_reach_channel , & template, & message . content_replace . parse ( ) ? , & to) . await {
60
+ match self . channel . send ( message. rel_reach_channel , & template, & content_replace, & to) . await {
59
61
Ok ( _) => {
60
62
ReachMessageServ :: update_status ( & message. id , ReachStatusKind :: Sending , ReachStatusKind :: SendSuccess , & self . funs , & ctx) . await ?;
63
+ for rel_account_id in to {
64
+ ReachMessageLogServ :: add_rbum (
65
+ & mut ReachMsgLogAddReq {
66
+ rbum_add_req : Default :: default ( ) ,
67
+ dnd_time : Default :: default ( ) ,
68
+ rel_account_id,
69
+ dnd_strategy : ReachDndStrategyKind :: Ignore ,
70
+ start_time,
71
+ end_time : Utc :: now ( ) ,
72
+ failure : false ,
73
+ fail_message : Default :: default ( ) ,
74
+ rel_reach_message_id : message. id . clone ( ) ,
75
+ } ,
76
+ & self . funs ,
77
+ & ctx,
78
+ ) . await ?;
79
+ }
61
80
}
62
81
Err ( e) => {
63
82
ReachMessageServ :: update_status ( & message. id , ReachStatusKind :: Sending , ReachStatusKind :: Fail , & self . funs , & ctx) . await ?;
83
+ for rel_account_id in to {
84
+ ReachMessageLogServ :: add_rbum (
85
+ & mut ReachMsgLogAddReq {
86
+ rbum_add_req : Default :: default ( ) ,
87
+ dnd_time : Default :: default ( ) ,
88
+ rel_account_id,
89
+ dnd_strategy : ReachDndStrategyKind :: Ignore ,
90
+ start_time,
91
+ end_time : Utc :: now ( ) ,
92
+ failure : true ,
93
+ fail_message : e. to_string ( ) ,
94
+ rel_reach_message_id : message. id . clone ( ) ,
95
+ } ,
96
+ & self . funs ,
97
+ & ctx,
98
+ ) . await ?;
99
+ }
100
+
64
101
return Err ( e) ;
65
102
}
66
103
}
0 commit comments