Commit 9fd00077 authored by xianyang's avatar xianyang

优化测试账户详情

parent a7f97615
......@@ -7,6 +7,7 @@ from sqlalchemy import and_, func
from sqlalchemy.orm import Session
from app.api.account import schemas
from core.config.env import env
from libs.business import TYPE_NAME
from libs.db_link import LinkMysql
from libs.functions import wrapper_out, get_now_timestamp, uuid, get_before_timestamp, time_str_to_timestamp, \
get_yesterday_timestamp, search
......@@ -170,45 +171,37 @@ def get_finance_info(unique_tag, page, size, start_time, end_time, is_list=None)
else:
count_sql = f"select calculation_time from v3_guild_account_statistics_copy GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v3_guild_account_statistics_copy GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
elif unique_tag == 'anchor_account':
if finance_condition:
condition = [i.replace('create_time', 'date') for i in finance_condition]
count_sql = f"select calculation_time from v3_user_account_statistics where type=2 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance, income,pay as outcome,date as create_time from v3_user_account_statistics where type=2 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select calculation_time from v3_user_account_statistics where type=2 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance, income,pay as outcome,date as create_time from v3_user_account_statistics where type=2 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
elif unique_tag == 'user_account':
if finance_condition:
condition = [i.replace('create_time', 'calculation_time') for i in finance_condition]
count_sql = f"select calculation_time from finance_data_calculation_sum where type=1 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=1 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
count_sql = f"select calculation_time from finance_data_calculation_sum_copy where type=1 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum_copy where type=1 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select calculation_time from finance_data_calculation_sum where type=1 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=1 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
count_sql = f"select calculation_time from finance_data_calculation_sum_copy where type=1 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum_copy where type=1 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
elif unique_tag == 'knapsack_account':
if finance_condition:
condition = [i.replace('create_time', 'calculation_time') for i in finance_condition]
count_sql = f"select calculation_time from finance_data_calculation_sum where type=4 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=4 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
count_sql = f"select calculation_time from finance_data_calculation_sum_copy where type=4 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum_copy where type=4 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select calculation_time from finance_data_calculation_sum where type=4 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=4 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
count_sql = f"select calculation_time from finance_data_calculation_sum_copy where type=4 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum_copy where type=4 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
elif unique_tag == 'pledgeDeduction':
if finance_condition:
condition = [i.replace('create_time', 'calculation_time') for i in finance_condition]
count_sql = f"select calculation_time from finance_data_calculation_sum where type=5 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=5 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
count_sql = f"select calculation_time from finance_data_calculation_sum_copy where type=5 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum_copy where type=5 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select calculation_time from finance_data_calculation_sum where type=5 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=5 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
count_sql = f"select calculation_time from finance_data_calculation_sum_copy where type=5 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum_copy where type=5 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
if finance_condition:
count_sql = f"select create_time from v2_system_account_statistics where {' and '.join(finance_condition)} GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v2_system_account_statistics where {' and '.join(finance_condition)} GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
count_sql = f"select create_time from v2_system_account_statistics_copy where {' and '.join(finance_condition)} GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v2_system_account_statistics_copy where {' and '.join(finance_condition)} GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select create_time from v2_system_account_statistics GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v2_system_account_statistics GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
count_sql = f"select create_time from v2_system_account_statistics_copy GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v2_system_account_statistics_copy GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
with ThreadPoolExecutor(max_workers=2) as pool:
future1 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, count_sql)
future2 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, data_sql)
......@@ -236,12 +229,12 @@ def get_finance_details(page, size, uuid, start_time, end_time, type, gift_type,
year_month = datetime.now().strftime('%Y%m')
if details_condition:
count_sql = f"select count(id) as num from assets_log_{year_month} where {' and '.join(details_condition)}"
data_sql = f"select id,order_number,reference_type,amount/1000 as amount,create_time from assets_log_{year_month} where {' and '.join(details_condition)} order by id DESC limit {(int(page) - 1) * size},{size}"
data_sql = f"select id,order_number,type,reference_type,amount/1000 as amount,create_time from assets_log_{year_month} where {' and '.join(details_condition)} order by id DESC limit {(int(page) - 1) * size},{size}"
amount_sql = f"select sum(cast(amount as decimal(20,6)))/1000 as total_amount from assets_log_{year_month} where {' and '.join(details_condition)}"
else:
count_sql = f"select count(id) as num from assets_log_{year_month}"
data_sql = f"select id,order_number,reference_type,amount/1000 as amount,create_time from assets_log_{year_month} order by id DESC limit {(int(page) - 1) * size},{size}"
data_sql = f"select id,order_number,type,reference_type,amount/1000 as amount,create_time from assets_log_{year_month} order by id DESC limit {(int(page) - 1) * size},{size}"
amount_sql = f"select sum(cast(amount as decimal(20,6)))/1000 as total_amount from assets_log_{year_month}"
with ThreadPoolExecutor(max_workers=3) as pool:
future1 = pool.submit(LinkMysql(env.DB_HISTORY).query_mysql, count_sql)
......@@ -255,6 +248,8 @@ def get_finance_details(page, size, uuid, start_time, end_time, type, gift_type,
if is_list:
if not res:
return [], 0, 0
for i in res:
i['reference_name'] = TYPE_NAME[i['reference_type']] if TYPE_NAME[i['reference_type']] else i['reference_type']
return res, total[0]['num'], amount_res[0]['total_amount']
else:
return res
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment