Commit 33f6e010 authored by xianyang's avatar xianyang

添加业务汇总,名称查询

parent d972b2ae
...@@ -72,13 +72,21 @@ class CalculationMonthlyBill(object): ...@@ -72,13 +72,21 @@ class CalculationMonthlyBill(object):
self.structure_list = [] self.structure_list = []
self.structure_key = [] self.structure_key = []
def month_statistics_task(self, date, key_type, page, size): def month_statistics_task(self, date, key_type, name, page, size):
"""主函数""" """主函数"""
db = env.MysqlDB db = env.MysqlDB
db["database"] = env.DB_HISTORY db["database"] = env.DB_HISTORY
if key_type: if key_type and not name:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{key_type}' GROUP BY reference_type, type ORDER BY reference_type" sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{key_type}' GROUP BY reference_type, type ORDER BY reference_type"
else: if name and not key_type:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{name}' GROUP BY reference_type, type ORDER BY reference_type"
for k, v in TYPE_NAME.items():
if v == name:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{k}' GROUP BY reference_type, type ORDER BY reference_type"
break
if name and key_type:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{key_type}' GROUP BY reference_type, type ORDER BY reference_type"
if not name and not key_type:
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(cast(amount as decimal(20,6)))/1000 as money FROM {date} GROUP BY reference_type, type ORDER BY reference_type"
try: try:
res_data = LinkMysql(db).query_mysql(sql) res_data = LinkMysql(db).query_mysql(sql)
......
...@@ -19,6 +19,7 @@ class ExportUpdateData(BaseModel): ...@@ -19,6 +19,7 @@ class ExportUpdateData(BaseModel):
class MonthStatistics(BaseModel): class MonthStatistics(BaseModel):
date: str = "" date: str = ""
type: str = "" type: str = ""
name: str = ""
page: int = None page: int = None
size: int = None size: int = None
......
...@@ -49,7 +49,7 @@ def month_query_total_export(param: schemas.MonthStatistics, token=Depends(login ...@@ -49,7 +49,7 @@ def month_query_total_export(param: schemas.MonthStatistics, token=Depends(login
if not param.date: if not param.date:
month_date = datetime.now().date() - relativedelta(months=1) month_date = datetime.now().date() - relativedelta(months=1)
param.date = month_date.strftime("%Y%m") param.date = month_date.strftime("%Y%m")
result, num = crud.CalculationMonthlyBill().month_statistics_task('assets_log_' + param.date, param.type, result, num = crud.CalculationMonthlyBill().month_statistics_task('assets_log_' + param.date, param.type, param.name,
param.page, param.size) param.page, param.size)
return HttpResultResponse(total=num, data=result) return HttpResultResponse(total=num, data=result)
......
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