diff --git a/Cargo.toml b/Cargo.toml index e58556b..0858b74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] } tokio-cron-scheduler = { version = "0" } uuid = { version = "0", features = ["serde", "v4", "v5"] } -beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.94-snapshot" } -beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.80-snapshot" } +beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.95-snapshot" } +beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.81-snapshot" } [build-dependencies] diff --git a/src/compositions/member/composition.rs b/src/compositions/member/composition.rs index 0c7afd9..f1888ce 100644 --- a/src/compositions/member/composition.rs +++ b/src/compositions/member/composition.rs @@ -7,41 +7,378 @@ use beteran_common_rust as bcr; use diesel::{result::Error, sql_query, RunQueryDsl}; use std::fmt::Write; +static MEMBER_PARENTS_QUERY: &str = " +WITH RECURSIVE rec AS ( + + SELECT + m.id as m_id, + m.site_id as m_site_id, + m.member_class_id as m_member_class_id, + m.member_level_id as m_member_level_id, + m.username as m_username, + m.password as m_password, + m.nickname as m_nickname, + m.mobile_phone_number as m_mobile_phone_number, + m.state as m_state, + m.state_changed_at as m_state_changed_at, + m.parent_member_id as m_parent_member_id, + m.child_member_count as m_child_member_count, + m.last_signined_ip as m_last_signined_ip, + m.last_signined_at as m_last_signined_at, + m.created_at as m_created_at, + m.updated_at as m_updated_at, + m.deleted_at as m_deleted_at, + + s.id as s_id, + s.url as s_url, + s.name as s_name, + s.path as s_path, + s.show as s_show, + s.can_use as s_can_use, + s.memo as s_memo, + s.expires_at as s_expires_at, + s.created_at as s_created_at, + s.updated_at as s_updated_at, + + mc.id as mc_id, + mc.parent_id as mc_parent_id, + mc.name as mc_name, + mc.show as mc_show, + mc.created_at as mc_created_at, + mc.updated_at as mc_updated_at, + + ml.id as ml_id, + ml.name as ml_name, + ml.show as ml_show, + ml.sort_order as ml_sort_order, + ml.created_at as ml_created_at, + ml.updated_at as ml_updated_at, + + mgs.id as mgs_id, + mgs.member_id as mgs_member_id, + mgs.can_bet_casino as mgs_can_bet_casino, + mgs.can_bet_slot as mgs_can_bet_slot, + mgs.can_bet_powerball as mgs_can_bet_powerball, + mgs.can_bet_powerladder as mgs_can_bet_powerladder, + mgs.can_bet_eos as mgs_can_bet_eos, + mgs.can_bet_bogglepowerball as mgs_can_bet_bogglepowerball, + mgs.created_at as mgs_created_at, + mgs.updated_at as mgs_updated_at, + + mss.id as mss_id, + mss.member_id as mss_member_id, + mss.can_exchange as mss_can_exchange, + mss.can_first_charge_comp as mss_can_first_charge_comp, + mss.can_per_charge_comp as mss_can_per_charge_comp, + mss.manual_payment_type_for_partner as mss_manual_payment_type_for_partner, + mss.settlement_type as mss_settlement_type, + mss.rate_casino as mss_rate_casino, + mss.rate_casino_loosing as mss_rate_casino_loosing, + mss.rate_casino_bacara as mss_rate_casino_bacara, + mss.rate_casino_roulette as mss_rate_casino_roulette, + mss.rate_casino_dragon_tiger as mss_rate_casino_dragon_tiger, + mss.rate_slot as mss_rate_slot, + mss.rate_slot_loosing as mss_rate_slot_loosing, + mss.rate_powerball_single as mss_rate_powerball_single, + mss.rate_powerball_combo as mss_rate_powerball_combo, + mss.rate_powerladder_single as mss_rate_powerladder_single, + mss.rate_powerladder_combo as mss_rate_powerladder_combo, + mss.rate_eos_single as mss_rate_eos_single, + mss.rate_eos_combo as mss_rate_eos_combo, + mss.rate_bogglepowerball_single as mss_rate_bogglepowerball_single, + mss.rate_bogglepowerball_combo as mss_rate_bogglepowerball_combo, + mss.created_at as mss_created_at, + mss.updated_at as mss_updated_at, + + mba.id as mba_id, + mba.member_id as mba_member_id, + mba.bank_id as mba_bank_id, + mba.name as mba_name, + mba.account_number as mba_account_number, + mba.exchange_password as mba_exchange_password, + mba.memo as mba_memo, + mba.created_at as mba_created_at, + mba.updated_at as mba_updated_at, + + mba_b.id as mba_b_id, + mba_b.name as mba_b_name, + mba_b.sort_order as mba_b_sort_order, + mba_b.show as mba_b_show, + mba_b.can_use as mba_b_can_use, + mba_b.memo as mba_b_memo, + mba_b.created_at as mba_b_created_at, + mba_b.updated_at as mba_b_updated_at, + + 1 AS level + FROM + members m + INNER JOIN sites s + ON s.id = m.site_id + INNER JOIN member_classes mc + ON mc.id = m.member_class_id + INNER JOIN member_levels ml + ON ml.id = m.member_level_id + LEFT OUTER JOIN member_settlement_settings mss + ON mss.member_id = m.id + LEFT OUTER JOIN member_game_settings mgs + ON mgs.member_id = m.id + LEFT OUTER JOIN member_bank_accounts mba + ON mba.member_id = m.id + LEFT OUTER JOIN banks mba_b + ON mba_b.id = mba.bank_id + + WHERE + m.id = $1 + + UNION ALL + + SELECT + c_m.id as m_id, + c_m.site_id as m_site_id, + c_m.member_class_id as m_member_class_id, + c_m.member_level_id as m_member_level_id, + c_m.username as m_username, + c_m.password as m_password, + c_m.nickname as m_nickname, + c_m.mobile_phone_number as m_mobile_phone_number, + c_m.state as m_state, + c_m.state_changed_at as m_state_changed_at, + c_m.parent_member_id as m_parent_member_id, + c_m.child_member_count as m_child_member_count, + c_m.last_signined_ip as m_last_signined_ip, + c_m.last_signined_at as m_last_signined_at, + c_m.created_at as m_created_at, + c_m.updated_at as m_updated_at, + c_m.deleted_at as m_deleted_at, + + c_s.id as s_id, + c_s.url as s_url, + c_s.name as s_name, + c_s.path as s_path, + c_s.show as s_show, + c_s.can_use as s_can_use, + c_s.memo as s_memo, + c_s.expires_at as s_expires_at, + c_s.created_at as s_created_at, + c_s.updated_at as s_updated_at, + + c_mc.id as mc_id, + c_mc.parent_id as mc_parent_id, + c_mc.name as mc_name, + c_mc.show as mc_show, + c_mc.created_at as mc_created_at, + c_mc.updated_at as mc_updated_at, + + c_ml.id as ml_id, + c_ml.name as ml_name, + c_ml.show as ml_show, + c_ml.sort_order as ml_sort_order, + c_ml.created_at as ml_created_at, + c_ml.updated_at as ml_updated_at, + + c_mgs.id as mgs_id, + c_mgs.member_id as mgs_member_id, + c_mgs.can_bet_casino as mgs_can_bet_casino, + c_mgs.can_bet_slot as mgs_can_bet_slot, + c_mgs.can_bet_powerball as mgs_can_bet_powerball, + c_mgs.can_bet_powerladder as mgs_can_bet_powerladder, + c_mgs.can_bet_eos as mgs_can_bet_eos, + c_mgs.can_bet_bogglepowerball as mgs_can_bet_bogglepowerball, + c_mgs.created_at as mgs_created_at, + c_mgs.updated_at as mgs_updated_at, + + c_mss.id as mss_id, + c_mss.member_id as mss_member_id, + c_mss.can_exchange as mss_can_exchange, + c_mss.can_first_charge_comp as mss_can_first_charge_comp, + c_mss.can_per_charge_comp as mss_can_per_charge_comp, + c_mss.manual_payment_type_for_partner as mss_manual_payment_type_for_partner, + c_mss.settlement_type as mss_settlement_type, + c_mss.rate_casino as mss_rate_casino, + c_mss.rate_casino_loosing as mss_rate_casino_loosing, + c_mss.rate_casino_bacara as mss_rate_casino_bacara, + c_mss.rate_casino_roulette as mss_rate_casino_roulette, + c_mss.rate_casino_dragon_tiger as mss_rate_casino_dragon_tiger, + c_mss.rate_slot as mss_rate_slot, + c_mss.rate_slot_loosing as mss_rate_slot_loosing, + c_mss.rate_powerball_single as mss_rate_powerball_single, + c_mss.rate_powerball_combo as mss_rate_powerball_combo, + c_mss.rate_powerladder_single as mss_rate_powerladder_single, + c_mss.rate_powerladder_combo as mss_rate_powerladder_combo, + c_mss.rate_eos_single as mss_rate_eos_single, + c_mss.rate_eos_combo as mss_rate_eos_combo, + c_mss.rate_bogglepowerball_single as mss_rate_bogglepowerball_single, + c_mss.rate_bogglepowerball_combo as mss_rate_bogglepowerball_combo, + c_mss.created_at as mss_created_at, + c_mss.updated_at as mss_updated_at, + + c_mba.id as mba_id, + c_mba.member_id as mba_member_id, + c_mba.bank_id as mba_bank_id, + c_mba.name as mba_name, + c_mba.account_number as mba_account_number, + c_mba.exchange_password as mba_exchange_password, + c_mba.memo as mba_memo, + c_mba.created_at as mba_created_at, + c_mba.updated_at as mba_updated_at, + + c_mba_b.id as mba_b_id, + c_mba_b.name as mba_b_name, + c_mba_b.sort_order as mba_b_sort_order, + c_mba_b.show as mba_b_show, + c_mba_b.can_use as mba_b_can_use, + c_mba_b.memo as mba_b_memo, + c_mba_b.created_at as mba_b_created_at, + c_mba_b.updated_at as mba_b_updated_at, + + (p_m.level+1) + FROM + members c_m + INNER JOIN sites c_s + ON c_s.id = c_m.site_id + INNER JOIN member_classes c_mc + ON c_mc.id = c_m.member_class_id + INNER JOIN member_levels c_ml + ON c_ml.id = c_m.member_level_id + LEFT OUTER JOIN member_settlement_settings c_mss + ON c_mss.member_id = c_m.id + LEFT OUTER JOIN member_game_settings c_mgs + ON c_mgs.member_id = c_m.id + LEFT OUTER JOIN member_bank_accounts c_mba + ON c_mba.member_id = c_m.id + LEFT OUTER JOIN banks c_mba_b + ON c_mba_b.id = c_mba.bank_id + JOIN rec p_m + ON c_m.id = p_m.m_parent_member_id + ) + SELECT + DISTINCT + m_id, + m_site_id, + m_member_class_id, + m_member_level_id, + m_username, + m_password, + m_nickname, + m_mobile_phone_number, + m_state, + m_state_changed_at, + m_parent_member_id, + m_child_member_count, + m_last_signined_ip, + m_last_signined_at, + m_created_at, + m_updated_at, + m_deleted_at, + + s_id, + s_url, + s_name, + s_path, + s_show, + s_can_use, + s_memo, + s_expires_at, + s_created_at, + s_updated_at, + + mc_id, + mc_parent_id, + mc_name, + mc_show, + mc_created_at, + mc_updated_at, + + ml_id, + ml_name, + ml_show, + ml_sort_order, + ml_created_at, + ml_updated_at, + + mgs_id, + mgs_member_id, + mgs_can_bet_casino, + mgs_can_bet_slot, + mgs_can_bet_powerball, + mgs_can_bet_powerladder, + mgs_can_bet_eos, + mgs_can_bet_bogglepowerball, + mgs_created_at, + mgs_updated_at, + + mss_id, + mss_member_id, + mss_can_exchange, + mss_can_first_charge_comp, + mss_can_per_charge_comp, + mss_manual_payment_type_for_partner, + mss_settlement_type, + mss_rate_casino, + mss_rate_casino_loosing, + mss_rate_casino_bacara, + mss_rate_casino_roulette, + mss_rate_casino_dragon_tiger, + mss_rate_slot, + mss_rate_slot_loosing, + mss_rate_powerball_single, + mss_rate_powerball_combo, + mss_rate_powerladder_single, + mss_rate_powerladder_combo, + mss_rate_eos_single, + mss_rate_eos_combo, + mss_rate_bogglepowerball_single, + mss_rate_bogglepowerball_combo, + mss_created_at, + mss_updated_at, + + mba_id, + mba_member_id, + mba_bank_id, + mba_name, + mba_account_number, + mba_exchange_password, + mba_memo, + mba_created_at, + mba_updated_at, + + mba_b_id, + mba_b_name, + mba_b_sort_order, + mba_b_show, + mba_b_can_use, + mba_b_memo, + mba_b_created_at, + mba_b_updated_at, + + level + FROM + rec + WHERE + m_parent_member_id IS NOT NULL + ORDER BY + level DESC +"; + static MEMBER_COUNT_QUERY: &str = " SELECT COUNT(m.id) FROM members as m - INNER JOIN sites m_s - ON m_s.id = m.site_id - INNER JOIN member_classes m_mc - ON m_mc.id = m.member_class_id - INNER JOIN member_levels m_ml - ON m_ml.id = m.member_level_id - LEFT OUTER JOIN member_settlement_settings m_mss - ON m_mss.member_id = m.id - LEFT OUTER JOIN member_game_settings m_mgs - ON m_mgs.member_id = m.id - LEFT OUTER JOIN member_bank_accounts m_mba - ON m_mba.member_id = m.id - LEFT OUTER JOIN banks m_mba_b - ON m_mba_b.id = m_mba.bank_id - LEFT OUTER JOIN members pm - ON pm.id = m.parent_member_id - LEFT OUTER JOIN sites pm_s - ON pm_s.id = pm.site_id - LEFT OUTER JOIN member_classes pm_mc - ON pm_mc.id = pm.member_class_id - LEFT OUTER JOIN member_levels pm_ml - ON pm_ml.id = pm.member_level_id - LEFT OUTER JOIN member_settlement_settings pm_mss - ON pm_mss.member_id = pm.id - LEFT OUTER JOIN member_game_settings pm_mgs - ON pm_mgs.member_id = pm.id - LEFT OUTER JOIN member_bank_accounts pm_mba - ON pm_mba.member_id = pm.id - LEFT OUTER JOIN banks pm_mba_b - ON pm_mba_b.id = pm_mba.bank_id - "; + INNER JOIN sites s + ON s.id = m.site_id + INNER JOIN member_classes mc + ON mc.id = m.member_class_id + INNER JOIN member_levels ml + ON ml.id = m.member_level_id + LEFT OUTER JOIN member_settlement_settings mss + ON mss.member_id = m.id + LEFT OUTER JOIN member_game_settings mgs + ON mgs.member_id = m.id + LEFT OUTER JOIN member_bank_accounts mba + ON mba.member_id = m.id + LEFT OUTER JOIN banks mba_b + ON mba_b.id = mba.bank_id +"; static MEMBER_QUERY: &str = " SELECT @@ -62,217 +399,103 @@ static MEMBER_QUERY: &str = " m.created_at as m_created_at, m.updated_at as m_updated_at, m.deleted_at as m_deleted_at, + + s.id as s_id, + s.url as s_url, + s.name as s_name, + s.path as s_path, + s.show as s_show, + s.can_use as s_can_use, + s.memo as s_memo, + s.expires_at as s_expires_at, + s.created_at as s_created_at, + s.updated_at as s_updated_at, - m_s.id as m_s_id, - m_s.url as m_s_url, - m_s.name as m_s_name, - m_s.path as m_s_path, - m_s.show as m_s_show, - m_s.can_use as m_s_can_use, - m_s.memo as m_s_memo, - m_s.expires_at as m_s_expires_at, - m_s.created_at as m_s_created_at, - m_s.updated_at as m_s_updated_at, + mc.id as mc_id, + mc.parent_id as mc_parent_id, + mc.name as mc_name, + mc.show as mc_show, + mc.created_at as mc_created_at, + mc.updated_at as mc_updated_at, - m_mc.id as m_mc_id, - m_mc.parent_id as m_mc_parent_id, - m_mc.name as m_mc_name, - m_mc.show as m_mc_show, - m_mc.created_at as m_mc_created_at, - m_mc.updated_at as m_mc_updated_at, + ml.id as ml_id, + ml.name as ml_name, + ml.show as ml_show, + ml.sort_order as ml_sort_order, + ml.created_at as ml_created_at, + ml.updated_at as ml_updated_at, - m_ml.id as m_ml_id, - m_ml.name as m_ml_name, - m_ml.show as m_ml_show, - m_ml.sort_order as m_ml_sort_order, - m_ml.created_at as m_ml_created_at, - m_ml.updated_at as m_ml_updated_at, - - m_mgs.id as m_mgs_id, - m_mgs.member_id as m_mgs_member_id, - m_mgs.can_bet_casino as m_mgs_can_bet_casino, - m_mgs.can_bet_slot as m_mgs_can_bet_slot, - m_mgs.can_bet_powerball as m_mgs_can_bet_powerball, - m_mgs.can_bet_powerladder as m_mgs_can_bet_powerladder, - m_mgs.can_bet_eos as m_mgs_can_bet_eos, - m_mgs.can_bet_bogglepowerball as m_mgs_can_bet_bogglepowerball, - m_mgs.created_at as m_mgs_created_at, - m_mgs.updated_at as m_mgs_updated_at, + mgs.id as mgs_id, + mgs.member_id as mgs_member_id, + mgs.can_bet_casino as mgs_can_bet_casino, + mgs.can_bet_slot as mgs_can_bet_slot, + mgs.can_bet_powerball as mgs_can_bet_powerball, + mgs.can_bet_powerladder as mgs_can_bet_powerladder, + mgs.can_bet_eos as mgs_can_bet_eos, + mgs.can_bet_bogglepowerball as mgs_can_bet_bogglepowerball, + mgs.created_at as mgs_created_at, + mgs.updated_at as mgs_updated_at, - m_mss.id as m_mss_id, - m_mss.member_id as m_mss_member_id, - m_mss.can_exchange as m_mss_can_exchange, - m_mss.can_first_charge_comp as m_mss_can_first_charge_comp, - m_mss.can_per_charge_comp as m_mss_can_per_charge_comp, - m_mss.manual_payment_type_for_partner as m_mss_manual_payment_type_for_partner, - m_mss.settlement_type as m_mss_settlement_type, - m_mss.rate_casino as m_mss_rate_casino, - m_mss.rate_casino_loosing as m_mss_rate_casino_loosing, - m_mss.rate_casino_bacara as m_mss_rate_casino_bacara, - m_mss.rate_casino_roulette as m_mss_rate_casino_roulette, - m_mss.rate_casino_dragon_tiger as m_mss_rate_casino_dragon_tiger, - m_mss.rate_slot as m_mss_rate_slot, - m_mss.rate_slot_loosing as m_mss_rate_slot_loosing, - m_mss.rate_powerball_single as m_mss_rate_powerball_single, - m_mss.rate_powerball_combo as m_mss_rate_powerball_combo, - m_mss.rate_powerladder_single as m_mss_rate_powerladder_single, - m_mss.rate_powerladder_combo as m_mss_rate_powerladder_combo, - m_mss.rate_eos_single as m_mss_rate_eos_single, - m_mss.rate_eos_combo as m_mss_rate_eos_combo, - m_mss.rate_bogglepowerball_single as m_mss_rate_bogglepowerball_single, - m_mss.rate_bogglepowerball_combo as m_mss_rate_bogglepowerball_combo, - m_mss.created_at as m_mss_created_at, - m_mss.updated_at as m_mss_updated_at, - - m_mba.id as m_mba_id, - m_mba.member_id as m_mba_member_id, - m_mba.bank_id as m_mba_bank_id, - m_mba.name as m_mba_name, - m_mba.account_number as m_mba_account_number, - m_mba.exchange_password as m_mba_exchange_password, - m_mba.memo as m_mba_memo, - m_mba.created_at as m_mba_created_at, - m_mba.updated_at as m_mba_updated_at, - - m_mba_b.id as m_mba_b_id, - m_mba_b.name as m_mba_b_name, - m_mba_b.sort_order as m_mba_b_sort_order, - m_mba_b.show as m_mba_b_show, - m_mba_b.can_use as m_mba_b_can_use, - m_mba_b.memo as m_mba_b_memo, - m_mba_b.created_at as m_mba_b_created_at, - m_mba_b.updated_at as m_mba_b_updated_at, - - pm.id as pm_id, - pm.site_id as pm_site_id, - pm.member_class_id as pm_member_class_id, - pm.member_level_id as pm_member_level_id, - pm.username as pm_username, - pm.password as pm_password, - pm.nickname as pm_nickname, - pm.mobile_phone_number as pm_mobile_phone_number, - pm.state as pm_state, - pm.state_changed_at as pm_state_changed_at, - pm.parent_member_id as pm_parent_member_id, - pm.child_member_count as pm_child_member_count, - pm.last_signined_ip as pm_last_signined_ip, - pm.last_signined_at as pm_last_signined_at, - pm.created_at as pm_created_at, - pm.updated_at as pm_updated_at, - pm.deleted_at as pm_deleted_at, - - pm_s.id as pm_s_id, - pm_s.url as pm_s_url, - pm_s.name as pm_s_name, - pm_s.path as pm_s_path, - pm_s.show as pm_s_show, - pm_s.can_use as pm_s_can_use, - pm_s.memo as pm_s_memo, - pm_s.expires_at as pm_s_expires_at, - pm_s.created_at as pm_s_created_at, - pm_s.updated_at as pm_s_updated_at, - - pm_mc.id as pm_mc_id, - pm_mc.parent_id as pm_mc_parent_id, - pm_mc.name as pm_mc_name, - pm_mc.show as pm_mc_show, - pm_mc.created_at as pm_mc_created_at, - pm_mc.updated_at as pm_mc_updated_at, - - pm_ml.id as pm_ml_id, - pm_ml.name as pm_ml_name, - pm_ml.show as pm_ml_show, - pm_ml.sort_order as pm_ml_sort_order, - pm_ml.created_at as pm_ml_created_at, - pm_ml.updated_at as pm_ml_updated_at, - - pm_mgs.id as pm_mgs_id, - pm_mgs.member_id as pm_mgs_member_id, - pm_mgs.can_bet_casino as pm_mgs_can_bet_casino, - pm_mgs.can_bet_slot as pm_mgs_can_bet_slot, - pm_mgs.can_bet_powerball as pm_mgs_can_bet_powerball, - pm_mgs.can_bet_powerladder as pm_mgs_can_bet_powerladder, - pm_mgs.can_bet_eos as pm_mgs_can_bet_eos, - pm_mgs.can_bet_bogglepowerball as pm_mgs_can_bet_bogglepowerball, - pm_mgs.created_at as pm_mgs_created_at, - pm_mgs.updated_at as pm_mgs_updated_at, - - pm_mss.id as pm_mss_id, - pm_mss.member_id as pm_mss_member_id, - pm_mss.can_exchange as pm_mss_can_exchange, - pm_mss.can_first_charge_comp as pm_mss_can_first_charge_comp, - pm_mss.can_per_charge_comp as pm_mss_can_per_charge_comp, - pm_mss.manual_payment_type_for_partner as pm_mss_manual_payment_type_for_partner, - pm_mss.settlement_type as pm_mss_settlement_type, - pm_mss.rate_casino as pm_mss_rate_casino, - pm_mss.rate_casino_loosing as pm_mss_rate_casino_loosing, - pm_mss.rate_casino_bacara as pm_mss_rate_casino_bacara, - pm_mss.rate_casino_roulette as pm_mss_rate_casino_roulette, - pm_mss.rate_casino_dragon_tiger as pm_mss_rate_casino_dragon_tiger, - pm_mss.rate_slot as pm_mss_rate_slot, - pm_mss.rate_slot_loosing as pm_mss_rate_slot_loosing, - pm_mss.rate_powerball_single as pm_mss_rate_powerball_single, - pm_mss.rate_powerball_combo as pm_mss_rate_powerball_combo, - pm_mss.rate_powerladder_single as pm_mss_rate_powerladder_single, - pm_mss.rate_powerladder_combo as pm_mss_rate_powerladder_combo, - pm_mss.rate_eos_single as pm_mss_rate_eos_single, - pm_mss.rate_eos_combo as pm_mss_rate_eos_combo, - pm_mss.rate_bogglepowerball_single as pm_mss_rate_bogglepowerball_single, - pm_mss.rate_bogglepowerball_combo as pm_mss_rate_bogglepowerball_combo, - pm_mss.created_at as pm_mss_created_at, - pm_mss.updated_at as pm_mss_updated_at, - - pm_mba.id as pm_mba_id, - pm_mba.member_id as pm_mba_member_id, - pm_mba.bank_id as pm_mba_bank_id, - pm_mba.name as pm_mba_name, - pm_mba.account_number as pm_mba_account_number, - pm_mba.exchange_password as pm_mba_exchange_password, - pm_mba.memo as pm_mba_memo, - pm_mba.created_at as pm_mba_created_at, - pm_mba.updated_at as pm_mba_updated_at, - - pm_mba_b.id as pm_mba_b_id, - pm_mba_b.name as pm_mba_b_name, - pm_mba_b.sort_order as pm_mba_b_sort_order, - pm_mba_b.show as pm_mba_b_show, - pm_mba_b.can_use as pm_mba_b_can_use, - pm_mba_b.memo as pm_mba_b_memo, - pm_mba_b.created_at as pm_mba_b_created_at, - pm_mba_b.updated_at as pm_mba_b_updated_at + mss.id as mss_id, + mss.member_id as mss_member_id, + mss.can_exchange as mss_can_exchange, + mss.can_first_charge_comp as mss_can_first_charge_comp, + mss.can_per_charge_comp as mss_can_per_charge_comp, + mss.manual_payment_type_for_partner as mss_manual_payment_type_for_partner, + mss.settlement_type as mss_settlement_type, + mss.rate_casino as mss_rate_casino, + mss.rate_casino_loosing as mss_rate_casino_loosing, + mss.rate_casino_bacara as mss_rate_casino_bacara, + mss.rate_casino_roulette as mss_rate_casino_roulette, + mss.rate_casino_dragon_tiger as mss_rate_casino_dragon_tiger, + mss.rate_slot as mss_rate_slot, + mss.rate_slot_loosing as mss_rate_slot_loosing, + mss.rate_powerball_single as mss_rate_powerball_single, + mss.rate_powerball_combo as mss_rate_powerball_combo, + mss.rate_powerladder_single as mss_rate_powerladder_single, + mss.rate_powerladder_combo as mss_rate_powerladder_combo, + mss.rate_eos_single as mss_rate_eos_single, + mss.rate_eos_combo as mss_rate_eos_combo, + mss.rate_bogglepowerball_single as mss_rate_bogglepowerball_single, + mss.rate_bogglepowerball_combo as mss_rate_bogglepowerball_combo, + mss.created_at as mss_created_at, + mss.updated_at as mss_updated_at, + + mba.id as mba_id, + mba.member_id as mba_member_id, + mba.bank_id as mba_bank_id, + mba.name as mba_name, + mba.account_number as mba_account_number, + mba.exchange_password as mba_exchange_password, + mba.memo as mba_memo, + mba.created_at as mba_created_at, + mba.updated_at as mba_updated_at, + + mba_b.id as mba_b_id, + mba_b.name as mba_b_name, + mba_b.sort_order as mba_b_sort_order, + mba_b.show as mba_b_show, + mba_b.can_use as mba_b_can_use, + mba_b.memo as mba_b_memo, + mba_b.created_at as mba_b_created_at, + mba_b.updated_at as mba_b_updated_at FROM members as m - INNER JOIN sites m_s - ON m_s.id = m.site_id - INNER JOIN member_classes m_mc - ON m_mc.id = m.member_class_id - INNER JOIN member_levels m_ml - ON m_ml.id = m.member_level_id - LEFT OUTER JOIN member_settlement_settings m_mss - ON m_mss.member_id = m.id - LEFT OUTER JOIN member_game_settings m_mgs - ON m_mgs.member_id = m.id - LEFT OUTER JOIN member_bank_accounts m_mba - ON m_mba.member_id = m.id - LEFT OUTER JOIN banks m_mba_b - ON m_mba_b.id = m_mba.bank_id - LEFT OUTER JOIN members pm - ON pm.id = m.parent_member_id - LEFT OUTER JOIN sites pm_s - ON pm_s.id = pm.site_id - LEFT OUTER JOIN member_classes pm_mc - ON pm_mc.id = pm.member_class_id - LEFT OUTER JOIN member_levels pm_ml - ON pm_ml.id = pm.member_level_id - LEFT OUTER JOIN member_settlement_settings pm_mss - ON pm_mss.member_id = pm.id - LEFT OUTER JOIN member_game_settings pm_mgs - ON pm_mgs.member_id = pm.id - LEFT OUTER JOIN member_bank_accounts pm_mba - ON pm_mba.member_id = pm.id - LEFT OUTER JOIN banks pm_mba_b - ON pm_mba_b.id = pm_mba.bank_id - "; + INNER JOIN sites s + ON s.id = m.site_id + INNER JOIN member_classes mc + ON mc.id = m.member_class_id + INNER JOIN member_levels ml + ON ml.id = m.member_level_id + LEFT OUTER JOIN member_settlement_settings mss + ON mss.member_id = m.id + LEFT OUTER JOIN member_game_settings mgs + ON mgs.member_id = m.id + LEFT OUTER JOIN member_bank_accounts mba + ON mba.member_id = m.id + LEFT OUTER JOIN banks mba_b + ON mba_b.id = mba.bank_id +"; pub struct Composition {} @@ -309,16 +532,25 @@ impl Composition { MEMBER_QUERY ); - match sql_query(query) + let _m = match sql_query(query) .bind::(id) - .get_result::(conn) + .get_result::(conn) { - Ok(m) => Ok(Some(m)), + Ok(m) => m, Err(e) => match e { - diesel::result::Error::NotFound => Ok(None), - _ => Err(e), + diesel::result::Error::NotFound => { + return Ok(None); + } + _ => { + return Err(e); + } }, - } + }; + + Ok(Some(models::from_member_model( + &_m, + self.select_parent(conn, _m.parent_member_id)?, + ))) } /// @@ -336,16 +568,70 @@ impl Composition { MEMBER_QUERY ); - match sql_query(query) + let _m = match sql_query(query) .bind::(username) - .get_result::(conn) + .get_result::(conn) { - Ok(m) => Ok(Some(m)), + Ok(m) => m, Err(e) => match e { - diesel::result::Error::NotFound => Ok(None), - _ => Err(e), + diesel::result::Error::NotFound => { + return Ok(None); + } + _ => { + return Err(e); + } }, + }; + + Ok(Some(models::from_member_model( + &_m, + self.select_parent(conn, _m.parent_member_id)?, + ))) + } + + /// + pub fn select_parent( + &self, + conn: &diesel::PgConnection, + parent_member_id: Option, + ) -> Result, Error> { + let parent_member_id = match parent_member_id { + Some(i) => i, + None => { + return Ok(None); + } + }; + + let query = format!( + " + {} + ", + MEMBER_PARENTS_QUERY + ); + + let members = match sql_query(query) + .bind::(parent_member_id) + .get_results::(conn) + { + Ok(m) => m, + Err(e) => match e { + diesel::result::Error::NotFound => vec![], + _ => { + return Err(e); + } + }, + }; + + if members.is_empty() { + return Ok(None); } + + let mut p: Option = None; + for m in members { + p = Some(models::from_member_model(&m, p)); + } + + Ok(p) } fn get_pagination( @@ -618,12 +904,27 @@ impl Composition { println!("query: {}", query); - match sql_query(query).get_results::(conn) { - Ok(m) => Ok(m), + let _list = match sql_query(query).get_results::(conn) { + Ok(m) => m, Err(e) => match e { - diesel::result::Error::NotFound => Ok(vec![]), - _ => Err(e), + diesel::result::Error::NotFound => { + return Ok(vec![]); + } + _ => { + return Err(e); + } }, + }; + + let mut list: Vec = vec![]; + + for _m in _list { + list.push(models::from_member_model( + &_m, + self.select_parent(conn, _m.parent_member_id)?, + )); } + + Ok(list) } } diff --git a/src/compositions/member/models.rs b/src/compositions/member/models.rs index 78f0708..47bca25 100644 --- a/src/compositions/member/models.rs +++ b/src/compositions/member/models.rs @@ -1,26 +1,23 @@ //! //! use crate::repositories::{ - bank::models::Bank as _Bank, member::schema::MemberState as _MemberState, - member_class::models::MemberClass as _MemberClass, - member_game_setting::models::MemberGameSetting as _MemberGameSetting, - member_level::models::MemberLevel as _MemberLevel, - member_settlement_setting::models::MemberSettlementSetting as _MemberSettlementSetting, - site::models::Site as _Site, + bank::models::Bank, member::schema::MemberState, member_class::models::MemberClass, + member_game_setting::models::MemberGameSetting, member_level::models::MemberLevel, + member_settlement_setting::models::MemberSettlementSetting, site::models::Site, }; use diesel::deserialize::QueryableByName; /// #[derive(PartialEq, PartialOrd, Debug, Clone)] -pub struct ParentMemberModel { +pub struct _MemberModel { /// pub id: uuid::Uuid, /// - pub site: _Site, + pub site: Site, /// - pub member_class: _MemberClass, + pub member_class: MemberClass, /// - pub member_level: _MemberLevel, + pub member_level: MemberLevel, /// pub bank_account: Option, /// @@ -36,13 +33,13 @@ pub struct ParentMemberModel { /// pub mobile_phone_number: Option, /// - pub state: _MemberState, + pub state: MemberState, /// pub state_changed_at: Option, /// - pub member_game_setting: Option<_MemberGameSetting>, + pub member_game_setting: Option, /// - pub member_settlement_setting: Option<_MemberSettlementSetting>, + pub member_settlement_setting: Option, /// pub last_signined_ip: Option, /// @@ -55,310 +52,120 @@ pub struct ParentMemberModel { pub deleted_at: Option, } -/// -#[derive(PartialEq, PartialOrd, Debug, Clone)] -pub struct MemberModel { - /// - pub id: uuid::Uuid, - /// - pub site: _Site, - /// - pub member_class: _MemberClass, - /// - pub member_level: _MemberLevel, - /// - pub bank_account: Option, - /// - pub username: String, - /// - pub password: String, - /// - pub nickname: String, - /// - pub parent_member: Option, - /// - pub child_member_count: i64, - /// - pub mobile_phone_number: Option, - /// - pub state: _MemberState, - /// - pub state_changed_at: Option, - /// - pub member_game_setting: Option<_MemberGameSetting>, - /// - pub member_settlement_setting: Option<_MemberSettlementSetting>, - /// - pub last_signined_ip: Option, - /// - pub last_signined_at: Option, - /// - pub created_at: i64, - /// - pub updated_at: i64, - /// - pub deleted_at: Option, -} - -impl QueryableByName for MemberModel { +impl QueryableByName for _MemberModel { fn build>(row: &R) -> diesel::deserialize::Result { - let parent_member = match row - .get::, Option>( - "m_parent_member_id", - )? { - Some(_) => { - let site = _Site { - id: row.get("pm_s_id")?, - url: row.get("pm_s_url")?, - name: row.get("pm_s_name")?, - path: row.get("pm_s_path")?, - show: row.get("pm_s_show")?, - can_use: row.get("pm_s_can_use")?, - memo: row.get("pm_s_memo")?, - expires_at: row.get("pm_s_expires_at")?, - created_at: row.get("pm_s_created_at")?, - updated_at: row.get("pm_s_updated_at")?, - }; - - let member_class = _MemberClass { - id: row.get("pm_mc_id")?, - parent_id: row.get("pm_mc_parent_id")?, - name: row.get("pm_mc_name")?, - show: row.get("pm_mc_show")?, - created_at: row.get("pm_mc_created_at")?, - updated_at: row.get("pm_mc_updated_at")?, - }; - - let member_level = _MemberLevel { - id: row.get("pm_ml_id")?, - name: row.get("pm_ml_name")?, - show: row.get("pm_ml_show")?, - sort_order: row.get("pm_ml_sort_order")?, - created_at: row.get("pm_ml_created_at")?, - updated_at: row.get("pm_ml_updated_at")?, - }; - - let member_game_setting = match row - .get::, Option>( - "pm_mgs_id", - )? { - Some(_) => Some(_MemberGameSetting { - id: row.get("pm_mgs_id")?, - member_id: row.get("pm_mgs_member_id")?, - can_bet_casino: row.get("pm_mgs_can_bet_casino")?, - can_bet_slot: row.get("pm_mgs_can_bet_slot")?, - can_bet_powerball: row.get("pm_mgs_can_bet_powerball")?, - can_bet_powerladder: row.get("pm_mgs_can_bet_powerladder")?, - can_bet_eos: row.get("pm_mgs_can_bet_eos")?, - can_bet_bogglepowerball: row.get("pm_mgs_can_bet_bogglepowerball")?, - created_at: row.get("pm_mgs_created_at")?, - updated_at: row.get("pm_mgs_updated_at")?, - }), - None => None, - }; - - let member_settlement_setting = match row.get::, Option>("pm_mss_id")? - { - Some(_) => Some(_MemberSettlementSetting { - id: row.get("pm_mss_id")?, - member_id: row.get("pm_mss_member_id")?, - can_exchange: row.get("pm_mss_can_exchange")?, - can_first_charge_comp: row.get("pm_mss_can_first_charge_comp")?, - can_per_charge_comp: row.get("pm_mss_can_per_charge_comp")?, - manual_payment_type_for_partner: row.get("pm_mss_manual_payment_type_for_partner")?, - settlement_type: row.get("pm_mss_settlement_type")?, - rate_casino: row.get("pm_mss_rate_casino")?, - rate_casino_loosing: row.get("pm_mss_rate_casino_loosing")?, - rate_casino_bacara: row.get("pm_mss_rate_casino_bacara")?, - rate_casino_roulette: row.get("pm_mss_rate_casino_roulette")?, - rate_casino_dragon_tiger: row.get("pm_mss_rate_casino_dragon_tiger")?, - rate_slot: row.get("pm_mss_rate_slot")?, - rate_slot_loosing: row.get("pm_mss_rate_slot_loosing")?, - rate_powerball_single: row.get("pm_mss_rate_powerball_single")?, - rate_powerball_combo: row.get("pm_mss_rate_powerball_combo")?, - rate_powerladder_single: row.get("pm_mss_rate_powerladder_single")?, - rate_powerladder_combo: row.get("pm_mss_rate_powerladder_combo")?, - rate_eos_single: row.get("pm_mss_rate_eos_single")?, - rate_eos_combo: row.get("pm_mss_rate_eos_combo")?, - rate_bogglepowerball_single: row.get("pm_mss_rate_bogglepowerball_single")?, - rate_bogglepowerball_combo: row.get("pm_mss_rate_bogglepowerball_combo")?, - created_at: row.get("pm_mss_created_at")?, - updated_at: row.get("pm_mss_updated_at")?, - }), - None => None, - }; - - let member_bank_account = match row - .get::, Option>( - "pm_mba_id", - )? { - Some(_) => { - let bank = _Bank { - id: row.get("pm_mba_b_id")?, - name: row.get("pm_mba_b_name")?, - sort_order: row.get("pm_mba_b_sort_order")?, - show: row.get("pm_mba_b_show")?, - can_use: row.get("pm_mba_b_can_use")?, - memo: row.get("pm_mba_b_memo")?, - created_at: row.get("pm_mba_b_created_at")?, - updated_at: row.get("pm_mba_b_updated_at")?, - }; - - Some(MemberBankAccountModel { - id: row.get("pm_mba_id")?, - member_id: row.get("pm_mba_member_id")?, - bank, - name: row.get("pm_mba_name")?, - account_number: row.get("pm_mba_account_number")?, - exchange_password: row.get("pm_mba_exchange_password")?, - memo: row.get("pm_mba_memo")?, - created_at: row.get("pm_mba_created_at")?, - updated_at: row.get("pm_mba_updated_at")?, - }) - } - None => None, - }; - - Some(ParentMemberModel { - id: row.get("pm_id")?, - site, - member_class, - member_level, - username: row.get("pm_username")?, - password: row.get("pm_password")?, - nickname: row.get("pm_nickname")?, - mobile_phone_number: row.get("pm_mobile_phone_number")?, - state: row.get("pm_state")?, - state_changed_at: row.get("pm_state_changed_at")?, - parent_member_id: row.get("pm_parent_member_id")?, - child_member_count: row.get("pm_child_member_count")?, - member_game_setting, - member_settlement_setting, - bank_account: member_bank_account, - last_signined_ip: row.get("pm_last_signined_ip")?, - last_signined_at: row.get("pm_last_signined_at")?, - created_at: row.get("pm_created_at")?, - updated_at: row.get("pm_updated_at")?, - deleted_at: row.get("pm_deleted_at")?, - }) - } - None => None, + let site = Site { + id: row.get("s_id")?, + url: row.get("s_url")?, + name: row.get("s_name")?, + path: row.get("s_path")?, + show: row.get("s_show")?, + can_use: row.get("s_can_use")?, + memo: row.get("s_memo")?, + expires_at: row.get("s_expires_at")?, + created_at: row.get("s_created_at")?, + updated_at: row.get("s_updated_at")?, }; - let site = _Site { - id: row.get("m_s_id")?, - url: row.get("m_s_url")?, - name: row.get("m_s_name")?, - path: row.get("m_s_path")?, - show: row.get("m_s_show")?, - can_use: row.get("m_s_can_use")?, - memo: row.get("m_s_memo")?, - expires_at: row.get("m_s_expires_at")?, - created_at: row.get("m_s_created_at")?, - updated_at: row.get("m_s_updated_at")?, + let member_class = MemberClass { + id: row.get("mc_id")?, + parent_id: row.get("mc_parent_id")?, + name: row.get("mc_name")?, + show: row.get("mc_show")?, + created_at: row.get("mc_created_at")?, + updated_at: row.get("mc_updated_at")?, }; - let member_class = _MemberClass { - id: row.get("m_mc_id")?, - parent_id: row.get("m_mc_parent_id")?, - name: row.get("m_mc_name")?, - show: row.get("m_mc_show")?, - created_at: row.get("m_mc_created_at")?, - updated_at: row.get("m_mc_updated_at")?, - }; - - let member_level = _MemberLevel { - id: row.get("m_ml_id")?, - name: row.get("m_ml_name")?, - show: row.get("m_ml_show")?, - sort_order: row.get("m_ml_sort_order")?, - created_at: row.get("m_ml_created_at")?, - updated_at: row.get("m_ml_updated_at")?, + let member_level = MemberLevel { + id: row.get("ml_id")?, + name: row.get("ml_name")?, + show: row.get("ml_show")?, + sort_order: row.get("ml_sort_order")?, + created_at: row.get("ml_created_at")?, + updated_at: row.get("ml_updated_at")?, }; let member_game_setting = match row - .get::, Option>("m_mgs_id")? + .get::, Option>("mgs_id")? { - Some(_) => Some(_MemberGameSetting { - id: row.get("m_mgs_id")?, - member_id: row.get("m_mgs_member_id")?, - can_bet_casino: row.get("m_mgs_can_bet_casino")?, - can_bet_slot: row.get("m_mgs_can_bet_slot")?, - can_bet_powerball: row.get("m_mgs_can_bet_powerball")?, - can_bet_powerladder: row.get("m_mgs_can_bet_powerladder")?, - can_bet_eos: row.get("m_mgs_can_bet_eos")?, - can_bet_bogglepowerball: row.get("m_mgs_can_bet_bogglepowerball")?, - created_at: row.get("m_mgs_created_at")?, - updated_at: row.get("m_mgs_updated_at")?, + Some(_) => Some(MemberGameSetting { + id: row.get("mgs_id")?, + member_id: row.get("mgs_member_id")?, + can_bet_casino: row.get("mgs_can_bet_casino")?, + can_bet_slot: row.get("mgs_can_bet_slot")?, + can_bet_powerball: row.get("mgs_can_bet_powerball")?, + can_bet_powerladder: row.get("mgs_can_bet_powerladder")?, + can_bet_eos: row.get("mgs_can_bet_eos")?, + can_bet_bogglepowerball: row.get("mgs_can_bet_bogglepowerball")?, + created_at: row.get("mgs_created_at")?, + updated_at: row.get("mgs_updated_at")?, }), None => None, }; let member_settlement_setting = match row - .get::, Option>("m_mss_id")? + .get::, Option>("mss_id")? { - Some(_) => Some(_MemberSettlementSetting { - id: row.get("m_mss_id")?, - member_id: row.get("m_mss_member_id")?, - can_exchange: row.get("m_mss_can_exchange")?, - can_first_charge_comp: row.get("m_mss_can_first_charge_comp")?, - can_per_charge_comp: row.get("m_mss_can_per_charge_comp")?, - manual_payment_type_for_partner: row.get("m_mss_manual_payment_type_for_partner")?, - settlement_type: row.get("m_mss_settlement_type")?, - rate_casino: row.get("m_mss_rate_casino")?, - rate_casino_loosing: row.get("m_mss_rate_casino_loosing")?, - rate_casino_bacara: row.get("m_mss_rate_casino_bacara")?, - rate_casino_roulette: row.get("m_mss_rate_casino_roulette")?, - rate_casino_dragon_tiger: row.get("m_mss_rate_casino_dragon_tiger")?, - rate_slot: row.get("m_mss_rate_slot")?, - rate_slot_loosing: row.get("m_mss_rate_slot_loosing")?, - rate_powerball_single: row.get("m_mss_rate_powerball_single")?, - rate_powerball_combo: row.get("m_mss_rate_powerball_combo")?, - rate_powerladder_single: row.get("m_mss_rate_powerladder_single")?, - rate_powerladder_combo: row.get("m_mss_rate_powerladder_combo")?, - rate_eos_single: row.get("m_mss_rate_eos_single")?, - rate_eos_combo: row.get("m_mss_rate_eos_combo")?, - rate_bogglepowerball_single: row.get("m_mss_rate_bogglepowerball_single")?, - rate_bogglepowerball_combo: row.get("m_mss_rate_bogglepowerball_combo")?, - created_at: row.get("m_mss_created_at")?, - updated_at: row.get("m_mss_updated_at")?, + Some(_) => Some(MemberSettlementSetting { + id: row.get("mss_id")?, + member_id: row.get("mss_member_id")?, + can_exchange: row.get("mss_can_exchange")?, + can_first_charge_comp: row.get("mss_can_first_charge_comp")?, + can_per_charge_comp: row.get("mss_can_per_charge_comp")?, + manual_payment_type_for_partner: row.get("mss_manual_payment_type_for_partner")?, + settlement_type: row.get("mss_settlement_type")?, + rate_casino: row.get("mss_rate_casino")?, + rate_casino_loosing: row.get("mss_rate_casino_loosing")?, + rate_casino_bacara: row.get("mss_rate_casino_bacara")?, + rate_casino_roulette: row.get("mss_rate_casino_roulette")?, + rate_casino_dragon_tiger: row.get("mss_rate_casino_dragon_tiger")?, + rate_slot: row.get("mss_rate_slot")?, + rate_slot_loosing: row.get("mss_rate_slot_loosing")?, + rate_powerball_single: row.get("mss_rate_powerball_single")?, + rate_powerball_combo: row.get("mss_rate_powerball_combo")?, + rate_powerladder_single: row.get("mss_rate_powerladder_single")?, + rate_powerladder_combo: row.get("mss_rate_powerladder_combo")?, + rate_eos_single: row.get("mss_rate_eos_single")?, + rate_eos_combo: row.get("mss_rate_eos_combo")?, + rate_bogglepowerball_single: row.get("mss_rate_bogglepowerball_single")?, + rate_bogglepowerball_combo: row.get("mss_rate_bogglepowerball_combo")?, + created_at: row.get("mss_created_at")?, + updated_at: row.get("mss_updated_at")?, }), None => None, }; let member_bank_account = match row - .get::, Option>("m_mba_id")? + .get::, Option>("mba_id")? { Some(_) => { - let bank = _Bank { - id: row.get("m_mba_b_id")?, - name: row.get("m_mba_b_name")?, - sort_order: row.get("m_mba_b_sort_order")?, - show: row.get("m_mba_b_show")?, - can_use: row.get("m_mba_b_can_use")?, - memo: row.get("m_mba_b_memo")?, - created_at: row.get("m_mba_b_created_at")?, - updated_at: row.get("m_mba_b_updated_at")?, + let bank = Bank { + id: row.get("mba_b_id")?, + name: row.get("mba_b_name")?, + sort_order: row.get("mba_b_sort_order")?, + show: row.get("mba_b_show")?, + can_use: row.get("mba_b_can_use")?, + memo: row.get("mba_b_memo")?, + created_at: row.get("mba_b_created_at")?, + updated_at: row.get("mba_b_updated_at")?, }; Some(MemberBankAccountModel { - id: row.get("m_mba_id")?, - member_id: row.get("m_mba_member_id")?, + id: row.get("mba_id")?, + member_id: row.get("mba_member_id")?, bank, - name: row.get("m_mba_name")?, - account_number: row.get("m_mba_account_number")?, - exchange_password: row.get("m_mba_exchange_password")?, - memo: row.get("m_mba_memo")?, - created_at: row.get("m_mba_created_at")?, - updated_at: row.get("m_mba_updated_at")?, + name: row.get("mba_name")?, + account_number: row.get("mba_account_number")?, + exchange_password: row.get("mba_exchange_password")?, + memo: row.get("mba_memo")?, + created_at: row.get("mba_created_at")?, + updated_at: row.get("mba_updated_at")?, }) } None => None, }; - Ok(MemberModel { + Ok(_MemberModel { id: row.get("m_id")?, site, member_class, @@ -372,7 +179,7 @@ impl QueryableByName for MemberModel { member_game_setting, member_settlement_setting, bank_account: member_bank_account, - parent_member, + parent_member_id: row.get("m_parent_member_id")?, child_member_count: row.get("m_child_member_count")?, last_signined_ip: row.get("m_last_signined_ip")?, last_signined_at: row.get("m_last_signined_at")?, @@ -383,6 +190,76 @@ impl QueryableByName for MemberModel { } } +/// +#[derive(PartialEq, PartialOrd, Debug, Clone)] +pub struct MemberModel { + /// + pub id: uuid::Uuid, + /// + pub site: Site, + /// + pub member_class: MemberClass, + /// + pub member_level: MemberLevel, + /// + pub bank_account: Option, + /// + pub username: String, + /// + pub password: String, + /// + pub nickname: String, + /// + pub parent_member: Option>, + /// + pub child_member_count: i64, + /// + pub mobile_phone_number: Option, + /// + pub state: MemberState, + /// + pub state_changed_at: Option, + /// + pub member_game_setting: Option, + /// + pub member_settlement_setting: Option, + /// + pub last_signined_ip: Option, + /// + pub last_signined_at: Option, + /// + pub created_at: i64, + /// + pub updated_at: i64, + /// + pub deleted_at: Option, +} + +pub fn from_member_model(_m: &_MemberModel, p: Option) -> MemberModel { + MemberModel { + id: _m.id, + site: _m.site.clone(), + member_class: _m.member_class.clone(), + member_level: _m.member_level.clone(), + bank_account: _m.bank_account.clone(), + username: _m.username.clone(), + password: _m.password.clone(), + nickname: _m.nickname.clone(), + parent_member: p.map(Box::new), + child_member_count: _m.child_member_count, + mobile_phone_number: _m.mobile_phone_number.clone(), + state: _m.state, + state_changed_at: _m.state_changed_at, + member_game_setting: _m.member_game_setting.clone(), + member_settlement_setting: _m.member_settlement_setting.clone(), + last_signined_ip: _m.last_signined_ip.clone(), + last_signined_at: _m.last_signined_at, + created_at: _m.created_at, + updated_at: _m.updated_at, + deleted_at: _m.deleted_at, + } +} + #[derive(Eq, Hash, PartialEq, PartialOrd, Debug, Clone)] pub struct MemberBankAccountModel { /// @@ -390,7 +267,7 @@ pub struct MemberBankAccountModel { /// pub member_id: uuid::Uuid, /// - pub bank: _Bank, + pub bank: Bank, /// pub name: String, /// diff --git a/src/services/member/models.rs b/src/services/member/models.rs index 34f6219..a935f1e 100644 --- a/src/services/member/models.rs +++ b/src/services/member/models.rs @@ -51,11 +51,9 @@ impl From<&repositories::member::models::Member> for bpr::models::member::Member } } -impl From<&compositions::member::models::ParentMemberModel> - for bpr::models::member::ParentMemberModel -{ - fn from(d: &compositions::member::models::ParentMemberModel) -> Self { - bpr::models::member::ParentMemberModel { +impl From<&compositions::member::models::MemberModel> for bpr::models::member::MemberModel { + fn from(d: &compositions::member::models::MemberModel) -> Self { + bpr::models::member::MemberModel { id: d.id.to_string(), site: Some(bpr::models::site::Site::from(&d.site)), member_class: Some(bpr::models::member_class::MemberClass::from( @@ -68,7 +66,10 @@ impl From<&compositions::member::models::ParentMemberModel> .bank_account .as_ref() .map(bpr::models::member_bank_account::MemberBankAccountModel::from), - parent_member_id: d.parent_member_id.map(|v| v.to_string()), + parent_member: d + .parent_member + .as_ref() + .map(|v| Box::::from(v)), child_member_count: d.child_member_count as u64, username: d.username.clone(), nickname: d.nickname.clone(), @@ -92,9 +93,11 @@ impl From<&compositions::member::models::ParentMemberModel> } } -impl From<&compositions::member::models::MemberModel> for bpr::models::member::MemberModel { - fn from(d: &compositions::member::models::MemberModel) -> Self { - bpr::models::member::MemberModel { +impl From<&Box> + for Box +{ + fn from(d: &Box) -> Self { + Box::new(bpr::models::member::MemberModel { id: d.id.to_string(), site: Some(bpr::models::site::Site::from(&d.site)), member_class: Some(bpr::models::member_class::MemberClass::from( @@ -110,7 +113,7 @@ impl From<&compositions::member::models::MemberModel> for bpr::models::member::M parent_member: d .parent_member .as_ref() - .map(bpr::models::member::ParentMemberModel::from), + .map(|v| Box::::from(v)), child_member_count: d.child_member_count as u64, username: d.username.clone(), nickname: d.nickname.clone(), @@ -130,6 +133,6 @@ impl From<&compositions::member::models::MemberModel> for bpr::models::member::M created_at: d.created_at as u64, updated_at: d.updated_at as u64, deleted_at: d.deleted_at.map(|d| d as u64), - } + }) } }