Commit fcac20f7 authored by xianyang's avatar xianyang

优化业务汇总条件导出

parent 419b8cda
...@@ -176,17 +176,21 @@ class MonthDataDerive(object): ...@@ -176,17 +176,21 @@ class MonthDataDerive(object):
return StreamingResponse(file, media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') return StreamingResponse(file, media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
def derive_data(self, date, key_type, name): def derive_data(self, date, key_type, name):
if key_type and not name: assert_list = []
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 name:
if name and not key_type: k_list = []
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(): for k, v in TYPE_NAME.items():
if v == name: if v == name or name in v:
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" k_list.append(k)
break if len(k_list) > 1:
if name and key_type: assert_list.append(f" reference_type in{tuple(k_list)}")
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 len(k_list) == 1:
if not name and not key_type: assert_list.append(f" reference_type='{k_list[0]}'")
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"
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(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(env.DB_HISTORY).query_mysql(sql) res_data = LinkMysql(env.DB_HISTORY).query_mysql(sql)
......
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