Commit 5ef4ee00 authored by xianyang's avatar xianyang

业务类型汇总添加缓存

parent 110d8850
import json
import math
import threading
import time
from concurrent.futures.thread import ThreadPoolExecutor
import pandas as pd
from sqlalchemy.orm import Session
from core.config.env import env
from core.config.env import env, red
from libs.business import TYPE_NAME, GUILD_NAME
from libs.db_link import LinkMysql
from libs.functions import get_now_timestamp, time_str_to_timestamp, \
......@@ -750,6 +751,8 @@ class HomePageDisplay(object):
def get_month_data(self):
is_data = red.get('account_sum-' + self.unique_tag + '-' + str(self.date))
if not is_data:
acc_sql = "select unique_tag,uuid from fi_account"
guild_sql = "select uuid from guild"
count_sql = f"select count(id) as num from {self.date}"
......@@ -777,15 +780,19 @@ class HomePageDisplay(object):
Logger(20).logger.info('没找到系统账户')
return [], 0, 0
assets_cond.append(f" uuid='{acc_uuid[0]}'")
ths_count = math.ceil(count[0]['num']/10000000)
ths_count = math.ceil(count[0]['num']/5000000)
ths = []
for x in range(ths_count):
assets_sql = f"select reference_type,type,sum(amount) as amount from {self.date} where {' and '.join(assets_cond)} GROUP BY reference_type,type LIMIT {x * 10000000},{(x+1) * 10000000}"
assets_sql = f"select reference_type,type,sum(cast(amount as FLOAT(3))) as amount from {self.date} where {' and '.join(assets_cond)} GROUP BY reference_type,type LIMIT {x * 5000000},{(x+1) * 5000000}"
ths.append(threading.Thread(target=self.th_task, args=[assets_sql]))
for y in range(ths_count):
ths[y].start()
for z in range(ths_count):
ths[z].join()
redis_dict = {"my_data": self.bus_data}
red.set('account_sum-' + self.unique_tag + '-' + str(self.date), json.dumps(redis_dict), 3600)
else:
self.bus_data = json.loads(is_data)['my_data']
# 数据分类
income = []
outcome = []
......
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