Commit abddacc0 authored by xianyang's avatar xianyang

优化查询日期时间段

parent 7c15d350
......@@ -4,10 +4,11 @@ from concurrent.futures.thread import ThreadPoolExecutor
import pandas as pd
from sqlalchemy.orm import Session
from core.config.env import env
from libs.business import TYPE_NAME, query_fi_account_type, GUILD_NAME
from libs.business import TYPE_NAME, GUILD_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, get_last_month, get_date_list, send_json_rpc_request, ymd_str_to_timestamp
from libs.functions import get_now_timestamp, time_str_to_timestamp, \
get_yesterday_timestamp, get_last_month, get_date_list, send_json_rpc_request, ymd_str_to_timestamp, \
judge_time_period
from libs.log_utils import Logger
from models import account as models
......@@ -375,6 +376,7 @@ class AccountStatistics(object):
u_sql = f"select id,uuid,order_number,type,reference_type,amount/1000 as amount,reference_number,create_time from {date} WHERE {' and '.join(condition)} ORDER BY create_time DESC"
else:
u_sql = f"select id,uuid,order_number,type,reference_type,amount/1000 as amount,reference_number,create_time from {date} ORDER BY create_time DESC"
Logger().logger.info(f"查询sql:{u_sql}")
result = LinkMysql(env.DB_HISTORY).query_mysql(u_sql)
return result
......@@ -429,7 +431,10 @@ class AccountStatistics(object):
total_list = []
yw_condition = self.public_query()
month, last_month, before_last_month = get_last_month()
if get_now_timestamp() - time_str_to_timestamp(self.start_time + ' 00:00:00') > 90 * 3600:
month, last_month, before_last_month = judge_time_period(self.start_time)
else:
month, last_month, before_last_month = get_last_month()
if self.unique == 'guild_account':
data, total = self.guild_calculation()
return data, total, 0
......
......@@ -79,6 +79,13 @@ def get_last_month():
return datetime.now().strftime("%Y%m"), last_month.strftime("%Y%m"), before_last_month.strftime("%Y%m")
def judge_time_period(start_day):
"""判断时间段有多少天"""
last_month = datetime.strptime(start_day, '%Y-%m-%d') + relativedelta(months=1)
before_last_month = datetime.strptime(start_day, '%Y-%m-%d') + relativedelta(months=2)
return datetime.strptime(start_day, '%Y-%m-%d').strftime("%Y%m"), last_month.strftime("%Y%m"), before_last_month.strftime("%Y%m")
def md5(s):
"""md5加密"""
sign_str = hashlib.md5()
......
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