Commit c8acd0cf authored by xianyang's avatar xianyang

新增业务数据异常接口

parent e3d007ed
......@@ -118,7 +118,7 @@ class CalculationMonthlyDetails(object):
return res_data
@staticmethod
def acquired_total(db, date, reference_type, is_out,):
def acquired_total(db, date, reference_type, is_out):
sql = f"SELECT reference_type FROM {date} where reference_type='{reference_type}' and type={is_out}"
result = LinkMysql(db).query_mysql(sql)
return len(result)
......@@ -127,13 +127,29 @@ class CalculationMonthlyDetails(object):
database = env.MysqlDB
database["database"] = env.DB_HISTORY
with ThreadPoolExecutor(max_workers=4) as pool:
with ThreadPoolExecutor(max_workers=2) as pool:
future1 = pool.submit(self.data_query, database, 'assets_log_' + param.date, param.key, param.is_income, param.page, param.size)
future2 = pool.submit(self.acquired_total, database, 'assets_log_' + param.date, param.key, param.is_income)
data = future1.result()
num = future2.result()
return data, num
@staticmethod
def query_error_data(date, reference_type):
database = env.MysqlDB
database["database"] = env.DB_HISTORY
group_sql = f"SELECT order_id, COUNT(order_id) as num FROM {date} where reference_type='{reference_type}' GROUP BY order_id"
result = LinkMysql(database).query_mysql(group_sql)
error_list = [str(i.get("order_id")) for i in result if i.get("num") != 2]
if len(error_list) == 1:
sql = f"SELECT uuid,reference_type,order_number,order_id,type,cast(amount as decimal(20,6))/1000 as money,amount_type,create_time FROM {date} where order_id={error_list[0]}"
if len(error_list) > 1:
sql = f"SELECT uuid,reference_type,order_number,order_id,type,cast(amount as decimal(20,6))/1000 as money,amount_type,create_time FROM {date} where order_id in({','.join(error_list)})"
if len(error_list) == 0:
return []
result = LinkMysql(database).query_mysql(sql)
return result
class MonthDataDerive(object):
"""月度导出"""
......
......@@ -61,6 +61,15 @@ def month_query_total_export(param: schemas.MonthDetails):
return HttpResultResponse(total=num, data=result)
@router.post("/error/data")
def month_query_error_data(param: schemas.MonthDetails):
"""月度计算,异常数据"""
if not param.date:
return HttpResultResponse(msg='查询月份不能为空')
result = crud.CalculationMonthlyDetails().query_error_data('assets_log_' + param.date, param.key)
return HttpResultResponse(total=len(result), data=result)
@router.post("/month")
def month_to_export(param: schemas.MonthStatistics):
"""月度表导出"""
......
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