synchronization of member is modified
This commit is contained in:
parent
3ad73b26d3
commit
4c785f2542
|
@ -73,8 +73,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
synchronizations::vendor::synchronizer::Synchronizer::new(pool.clone(), api_config.clone());
|
synchronizations::vendor::synchronizer::Synchronizer::new(pool.clone(), api_config.clone());
|
||||||
let game_synchronizer =
|
let game_synchronizer =
|
||||||
synchronizations::game::synchronizer::Synchronizer::new(pool.clone(), api_config.clone());
|
synchronizations::game::synchronizer::Synchronizer::new(pool.clone(), api_config.clone());
|
||||||
let member_synchronizer =
|
let member_synchronizer = synchronizations::member::synchronizer::Synchronizer::new(
|
||||||
synchronizations::member::synchronizer::Synchronizer::new(pool.clone(), api_config.clone());
|
connection_server_broker.clone(),
|
||||||
|
pool.clone(),
|
||||||
|
api_config.clone(),
|
||||||
|
);
|
||||||
let member_account_synchronizer =
|
let member_account_synchronizer =
|
||||||
synchronizations::member_account::synchronizer::Synchronizer::new(
|
synchronizations::member_account::synchronizer::Synchronizer::new(
|
||||||
pool.clone(),
|
pool.clone(),
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
use crate::api;
|
use crate::api;
|
||||||
use crate::core;
|
use crate::core;
|
||||||
use crate::repositories;
|
use crate::repositories;
|
||||||
|
use beteran_protobuf_rust as bpr;
|
||||||
use diesel::{
|
use diesel::{
|
||||||
r2d2::{ConnectionManager, Pool},
|
r2d2::{ConnectionManager, Pool},
|
||||||
PgConnection,
|
PgConnection,
|
||||||
};
|
};
|
||||||
|
use prost::Message;
|
||||||
|
use std::net::IpAddr;
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
///
|
///
|
||||||
pub struct Synchronizer {
|
pub struct Synchronizer {
|
||||||
|
connection_broker: nats::asynk::Connection,
|
||||||
pool: Pool<ConnectionManager<PgConnection>>,
|
pool: Pool<ConnectionManager<PgConnection>>,
|
||||||
api_config: core::config::ApiConfig,
|
api_config: core::config::ApiConfig,
|
||||||
synchronization_history_repository: repositories::synchronization_history::repository::Repository,
|
synchronization_history_repository: repositories::synchronization_history::repository::Repository,
|
||||||
|
@ -24,6 +30,7 @@ impl std::fmt::Debug for Synchronizer {
|
||||||
impl std::clone::Clone for Synchronizer {
|
impl std::clone::Clone for Synchronizer {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
connection_broker: self.connection_broker.clone(),
|
||||||
pool: self.pool.clone(),
|
pool: self.pool.clone(),
|
||||||
api_config: self.api_config.clone(),
|
api_config: self.api_config.clone(),
|
||||||
synchronization_history_repository:
|
synchronization_history_repository:
|
||||||
|
@ -37,10 +44,12 @@ impl std::clone::Clone for Synchronizer {
|
||||||
impl Synchronizer {
|
impl Synchronizer {
|
||||||
///
|
///
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
connection_broker: nats::asynk::Connection,
|
||||||
pool: Pool<ConnectionManager<PgConnection>>,
|
pool: Pool<ConnectionManager<PgConnection>>,
|
||||||
api_config: core::config::ApiConfig,
|
api_config: core::config::ApiConfig,
|
||||||
) -> Synchronizer {
|
) -> Synchronizer {
|
||||||
Synchronizer {
|
Synchronizer {
|
||||||
|
connection_broker,
|
||||||
pool,
|
pool,
|
||||||
api_config: api_config.clone(),
|
api_config: api_config.clone(),
|
||||||
synchronization_history_repository:
|
synchronization_history_repository:
|
||||||
|
@ -60,15 +69,88 @@ impl Synchronizer {
|
||||||
let res = self.member_api.list_members(req).await?;
|
let res = self.member_api.list_members(req).await?;
|
||||||
|
|
||||||
for u in res.users {
|
for u in res.users {
|
||||||
let modify_member = repositories::member::models::ModifyMember {
|
if self
|
||||||
balance: u.cash,
|
.member_repository
|
||||||
balance_bota: u.cash_bota,
|
.select(&conn, u.id)
|
||||||
oriental_play: u.oriental_play,
|
.expect("member_repository.select")
|
||||||
};
|
.is_none()
|
||||||
|
{
|
||||||
|
let ss_get_member_by_username_req = bpr::ss::member::GetMemberByUsernameRequest {
|
||||||
|
client: Some(bpr::models::core::network::Client {
|
||||||
|
client_ip: self
|
||||||
|
.connection_broker
|
||||||
|
.client_ip()
|
||||||
|
.unwrap_or(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)))
|
||||||
|
.to_string(),
|
||||||
|
site_url: None,
|
||||||
|
access_token: None,
|
||||||
|
}),
|
||||||
|
request: Some(bpr::ss::member::get_member_by_username_request::Request {
|
||||||
|
username: u.site_username.clone(),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ss_get_member_by_username_res_msg = self
|
||||||
|
.connection_broker
|
||||||
|
.request(
|
||||||
|
bpr::ss::member::SUBJECT_GET_MEMBER_BY_USERNAME,
|
||||||
|
ss_get_member_by_username_req.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("SUBJECT_GET_MEMBER_BY_USERNAME");
|
||||||
|
|
||||||
|
let ss_get_member_by_username_res = bpr::ss::member::GetMemberByUsernameResponse::decode(
|
||||||
|
ss_get_member_by_username_res_msg.data.as_slice(),
|
||||||
|
)
|
||||||
|
.expect("GetMemberByUsernameResponse");
|
||||||
|
|
||||||
|
if let Some(e) = ss_get_member_by_username_res.error {
|
||||||
|
println!(
|
||||||
|
"bpr::ss::member::SUBJECT_GET_MEMBER_BY_USERNAME error: {}",
|
||||||
|
e
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
match ss_get_member_by_username_res.result {
|
||||||
|
Some(r) => match r.member {
|
||||||
|
Some(m) => {
|
||||||
|
let member_id = uuid::Uuid::from_str(m.id.as_str()).expect("uuid::Uuid");
|
||||||
|
|
||||||
|
self
|
||||||
|
.member_repository
|
||||||
|
.insert(
|
||||||
|
&conn,
|
||||||
|
&repositories::member::models::NewMember {
|
||||||
|
id: u.id,
|
||||||
|
member_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("member insert");
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
println!("member is not exist: {}", u.site_username);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
println!("member is not exist: {}", u.site_username);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
.member_repository
|
.member_repository
|
||||||
.update(&conn, u.id, &modify_member)
|
.update(
|
||||||
|
&conn,
|
||||||
|
u.id,
|
||||||
|
&repositories::member::models::ModifyMember {
|
||||||
|
balance: u.cash,
|
||||||
|
balance_bota: u.cash_bota,
|
||||||
|
oriental_play: u.oriental_play,
|
||||||
|
},
|
||||||
|
)
|
||||||
.expect("member update");
|
.expect("member update");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user