Commit be7c9152 authored by xianyang's avatar xianyang

优化

parent 16f0204d
......@@ -7,7 +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.business import TYPE_NAME, query_fi_account_type
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, get_last_month
......@@ -452,11 +452,12 @@ class AccountStatistics(object):
total = len(ultimately_data)
res = ultimately_data[int(self.page - 1) * self.size: self.page * self.size]
# 判断是列表还是导出接口
type_name = query_fi_account_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.get(i['reference_type']) else i[
i['reference_name'] = type_name[i['reference_type']] if type_name.get(i['reference_type']) else i[
'reference_type']
data_pd = pd.DataFrame(ultimately_data)
amount_total = data_pd['amount'].sum()
......@@ -481,7 +482,7 @@ class SpecificAccountQuery(object):
def condition_query(self, date, cond_list):
sql = f"select uuid,type,cast(amount as decimal(20,6))/1000 as amount,reference_type,create_time,amount_type from {date} WHERE {' and '.join(cond_list)} ORDER BY create_time DESC"
sql = f"select uuid,type,cast(amount as decimal(20,6))/1000 as amount,reference_type,order_number,create_time,amount_type from {date} WHERE {' and '.join(cond_list)} ORDER BY create_time DESC"
result = LinkMysql(env.DB_HISTORY).query_mysql(sql)
return result
......@@ -517,8 +518,9 @@ class SpecificAccountQuery(object):
res = self.total_list[int(self.page - 1) * self.size: self.page * self.size]
if not res:
return [], 0, 0
type_name = query_fi_account_type()
for i in res:
i['reference_name'] = TYPE_NAME[i['reference_type']] if TYPE_NAME.get(i['reference_type']) else i[
i['reference_name'] = type_name[i['reference_type']] if type_name.get(i['reference_type']) else i[
'reference_type']
data_pd = pd.DataFrame(self.total_list)
amount_total = data_pd['amount'].sum()
......
......@@ -153,7 +153,7 @@ def create_user(data: schemas.CreateType, token=Depends(login_required), db: Ses
res = crud.create_type(data)
if not res:
return HttpResultResponse(code=500, msg=res)
return HttpResultResponse(data=res.id)
return HttpResultResponse()
@router.get("/userInfo")
......
......@@ -2,7 +2,7 @@ from concurrent.futures.thread import ThreadPoolExecutor
from sqlalchemy.orm import Session
from core.config.env import env
from libs.business import TYPE_NAME
from libs.business import TYPE_NAME, query_fi_account_type
from libs.db_link import LinkMysql
from libs.functions import get_now_datetime
from libs.orm import QueryAllData
......@@ -79,7 +79,8 @@ class CalculationMonthlyBill(object):
assert_list = []
if name:
k_list = []
for k, v in TYPE_NAME.items():
type_name = query_fi_account_type()
for k, v in type_name.items():
if v == name or name in v:
k_list.append(k)
if len(k_list) > 1:
......@@ -92,31 +93,32 @@ class CalculationMonthlyBill(object):
if key_type:
assert_list.append(f" reference_type like '%{key_type}%'")
if assert_list:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where {' and '.join(assert_list)} GROUP BY reference_type, type ORDER BY reference_type"
sql = f"SELECT reference_type, type, SUM(amount)/1000 as money FROM {date} where {' and '.join(assert_list)} GROUP BY reference_type, type ORDER BY reference_type"
else:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} GROUP BY reference_type, type ORDER BY reference_type"
sql = f"SELECT reference_type, type, SUM(amount)/1000 as money FROM {date} GROUP BY reference_type, type ORDER BY reference_type"
try:
res_data = LinkMysql(env.DB_HISTORY).query_mysql(sql)
except Exception as e:
return [], 0
type_name = query_fi_account_type()
for res in res_data:
if res["reference_type"] in self.structure_key:
continue
if res["reference_type"] in TYPE_NAME:
name = TYPE_NAME[res["reference_type"]]
if res["reference_type"] in type_name:
name = type_name[res["reference_type"]]
else:
name = res["reference_type"]
out = [i['money'] for i in res_data if i['reference_type'] == res["reference_type"] and i['type'] == 0]
income = [i['money'] for i in res_data if i['reference_type'] == res["reference_type"] and i['type'] == 1]
out_value = float(out[0]) if out else 0
income_value = float(income[0]) if income else 0
out_value = out[0] if out else 0
income_value = income[0] if income else 0
a = {
"name": name,
"type": res["reference_type"],
"expenditure": out_value,
"income": income_value,
"is_error": 0 if out_value == income_value else 1,
"error_money": float('%.2f' % (out_value - income_value))
"error_money": float('%.3f' % (out_value - income_value))
}
self.structure_key.append(res["reference_type"])
self.structure_list.append(a)
......@@ -183,7 +185,8 @@ class MonthDataDerive(object):
assert_list = []
if name:
k_list = []
for k, v in TYPE_NAME.items():
type_name = query_fi_account_type()
for k, v in type_name.items():
if v == name or name in v:
k_list.append(k)
if len(k_list) > 1:
......@@ -203,8 +206,9 @@ class MonthDataDerive(object):
for res in res_data:
if res["reference_type"] in self.derive_key:
continue
if res["reference_type"] in TYPE_NAME:
name = TYPE_NAME[res["reference_type"]]
type_name = query_fi_account_type()
if res["reference_type"] in type_name:
name = type_name[res["reference_type"]]
else:
name = res["reference_type"]
out = [i['money'] for i in res_data if i['reference_type'] == res["reference_type"] and i['type'] == 0]
......@@ -284,3 +288,30 @@ class ReferenceTypeClassification():
for k, v in igs.to_dict().get('money').items():
res_list.append({"type": "入账", "name": k, "money": round(float(v), 3)})
return res_list
class AbnormalDataDetails(object):
"""业务类型汇总异常数据详情"""
def __init__(self, date, reference_type):
self.date = 'assets_log_' + date
self.reference_type = reference_type
def abnormal_task(self):
out_sql = f"select order_number from {self.date} where reference_type='{self.reference_type}' and type=0"
income_sql = f"select order_number from {self.date} where reference_type='{self.reference_type}' and type=1"
with ThreadPoolExecutor(max_workers=2) as pool:
out_res = pool.submit(LinkMysql(env.DB_HISTORY).query_mysql, out_sql)
income_res = pool.submit(LinkMysql(env.DB_HISTORY).query_mysql, income_sql)
out_data = out_res.result()
income_data = income_res.result()
out_order_number = [i['order_number'] for i in out_data]
income_order_number = [i['order_number'] for i in income_data]
error_order_number = list(set(out_order_number) ^ set(income_order_number))
if len(error_order_number) == 1:
error_sql = f"select uuid,type,reference_type,order_number,amount/1000 as amount,create_time from {self.date} where order_number='{error_order_number[0]}'"
elif len(error_order_number) > 1:
error_sql = f"select uuid,type,reference_type,order_number,amount/1000 as amount,create_time from {self.date} where order_number in{tuple(error_order_number)}"
else:
return []
res = LinkMysql(env.DB_HISTORY).query_mysql(error_sql)
return res
......@@ -107,3 +107,12 @@ def reference_type_total(date: str, type: str, token=Depends(login_required)):
return HttpResultResponse(code=500, msg='缺少必传参数')
result = crud.ReferenceTypeClassification(date, type).classification_summary()
return HttpResultResponse(data=result)
@router.get("/abnormal/data")
def abnormal_total(date: str, type: str, token=Depends(login_required)):
"""异常数据详情"""
if not all([date, type]):
return HttpResultResponse(code=500, msg='缺少必传参数')
result = crud.AbnormalDataDetails(date, type).abnormal_task()
return HttpResultResponse(data=result)
from core.config.env import env
from libs.db_link import LinkMysql
sql = f"SELECT keyName,keyValue,type FROM fi_account_type"
res_data = LinkMysql(env.DB_3YV2).query_mysql(sql)
TYPE_NAME = {}
for i in res_data:
if not TYPE_NAME.get(i['keyValue']):
TYPE_NAME[i['keyValue']] = i['keyName']
def query_fi_account_type():
fi_type = {}
sql = f"SELECT keyName,keyValue,type FROM fi_account_type"
res_data = LinkMysql(env.DB_3YV2).query_mysql(sql)
for i in res_data:
if not fi_type.get(i['keyValue']):
fi_type[i['keyValue']] = i['keyName']
return fi_type
TYPE_NAME = query_fi_account_type()
# TYPE_NAME_T = {
# "updateUserNameFee": "用户昵称修改",
......
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