Commit c2d6a36b authored by xianyang's avatar xianyang

账户类型分类汇总,导出

parent 5ebe5b3e
......@@ -334,6 +334,13 @@ def out_income_combine(data):
return record_v_list
def query_account_data():
account_sql = f"select name,unique_tag,uuid from fi_account where unique_tag not " \
f"in('guild_account', 'anchor_account', 'user_account', 'knapsack_account')"
account = LinkMysql(env.DB_3YV2).query_mysql(account_sql)
return account
class AccountStatistics(object):
"""账户列表,查询"""
......@@ -587,3 +594,57 @@ class SpecificAccountQuery(object):
data_pd = pd.DataFrame(self.total_list)
amount_total = data_pd['amount'].sum()
return res, total, float(amount_total)
class HomePageDisplay(object):
def __init__(self, date, unique_tag):
self.date = 'assets_log_' + date
self.unique_tag = unique_tag
self.account = []
self.guild = []
self.income = 0
self.outcome = 0
def get_month_data(self):
acc_sql = "select unique_tag,uuid from fi_account"
guild_sql = "select uuid from guild"
with ThreadPoolExecutor(max_workers=2) as pool:
future1 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, acc_sql)
future2 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, guild_sql)
acc_data = future1.result()
guild_data = future2.result()
account = [i['uuid'] for i in acc_data]
guild = [i['uuid'] for i in guild_data]
assets_cond = []
if self.unique_tag == 'guild_account':
assets_cond.append(f" uuid in{tuple(guild)}")
elif self.unique_tag == 'user_account':
assets_cond.append(f" uuid not in{tuple(guild + account)} and amount_type in('consumable','withdrawable')")
elif self.unique_tag == 'knapsack_account':
assets_cond.append(f" amount_type='backpack'")
else:
acc_uuid = [i['uuid'] for i in acc_data if i['unique_tag'] == self.unique_tag]
if not acc_uuid:
print('没找到系统账户')
return []
assets_cond.append(f" uuid='{acc_uuid[0]}'")
assets_sql = f"select reference_type,type,sum(amount) as amount from {self.date} where {' and '.join(assets_cond)} GROUP BY reference_type,type"
total_data = LinkMysql(env.DB_HISTORY).query_mysql(assets_sql)
# 数据分类
res_list = []
for i in total_data:
op = {}
if TYPE_NAME.get(i['reference_type']):
op['name'] = TYPE_NAME.get(i['reference_type'])
else:
op['name'] = i['reference_type']
if i['type'] == 0:
op['type'] = '出账'
self.outcome = self.outcome + i['amount']
else:
op['type'] = '入账'
self.income = self.income + i['amount']
op['money'] = round(i['amount']/1000, 3)
res_list.append(op)
return res_list, self.outcome/1000, self.income/1000
......@@ -101,3 +101,9 @@ class RecoveryTable(BaseModel):
class RecoveryupdateTable(RecoveryTable):
id: int
class AccountClassifyData(BaseModel):
date: Optional[str] = ''
unique_tag: Optional[str] = ''
account_type: Optional[str] = ''
......@@ -4,7 +4,7 @@ from fastapi import Depends, APIRouter, Request, Query
from sqlalchemy.orm import Session
from app import get_db
from app.api.account import schemas, crud
from app.api.account.crud import AccountStatistics, SpecificAccountQuery
from app.api.account.crud import AccountStatistics, SpecificAccountQuery, HomePageDisplay
from app.api.statement import crud as statement_crud
from libs import functions
from libs.functions import get_date_list
......@@ -179,3 +179,39 @@ def query_guilds_info(uuid: str, token=Depends(login_required)):
return HttpResultResponse(code=500, msg=str(res))
success = json.loads(res.text)
return HttpResultResponse(data=success.get('data'))
@router.get("/total")
def read_account(date: Optional[str] = "",
unique_tag: Optional[str] = "",
account_type: Optional[str] = "",
token=Depends(login_required)):
"""月,业务类型,消费类型,出入账目统计"""
if not date or (not unique_tag and not account_type):
return HttpResultResponse(code=500, msg=HttpMessage.MISSING_PARAMETER)
if account_type and not unique_tag:
unique_tag = account_type
data, out, income = HomePageDisplay(date, unique_tag).get_month_data()
return HttpResultResponse(outcome=out, income=income, data=data)
@router.post("/total/excel")
def account_classify_excel(data: schemas.AccountClassifyData, request: Request,
token=Depends(login_required), db: Session = Depends(get_db)):
"""账户分类汇总导出"""
if not data.date or (not data.unique_tag and not data.account_type):
return HttpResultResponse(code=500, msg=HttpMessage.MISSING_PARAMETER)
if data.unique_tag:
unique_tag = data.unique_tag
else:
unique_tag = data.account_type
headers = request.get("headers")
data, outcome, income = HomePageDisplay(data.date, unique_tag).get_month_data()
return statement_crud.account_data_to_file(db, data, outcome, income, headers)
@router.get("/name/list")
def outon_account(token=Depends(login_required)):
"""系统账户列表"""
account_list = crud.query_account_data()
return HttpResultResponse(data=account_list)
import json
import threading
from concurrent.futures.thread import ThreadPoolExecutor
import pandas as pd
from core.config.env import env, red
from libs.db_link import LinkMysql
class HomePageDisplay(object):
def __init__(self, date, unique_tag, amount_type, reference_type, type):
self.date = 'assets_log_' + date
self.unique_tag = unique_tag
self.amount_type = amount_type
self.reference_type = reference_type
self.type = type
self.account = []
self.guild = []
self.total_money = 0
def mysql_query_data(self, assets_cond, page, size):
assets_sql = f"select amount from {self.date} where {' and '.join(assets_cond)} limit {page},{size}"
total_data = LinkMysql(env.DB_HISTORY).perform_mysql(assets_sql)
df = pd.DataFrame(total_data)
total = df['amount'].sum()
self.total_money = self.total_money + total
def get_month_data(self):
acc_sql = "select unique_tag,uuid from fi_account"
guild_sql = "select uuid from guild"
with ThreadPoolExecutor(max_workers=2) as pool:
future1 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, acc_sql)
future2 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, guild_sql)
acc_data = future1.result()
guild_data = future2.result()
account = [i['uuid'] for i in acc_data]
guild = [i['uuid'] for i in guild_data]
assets_cond = []
assets_cond.append(f" reference_type='{self.reference_type}'")
if self.unique_tag == 'guild_account':
assets_cond.append(f" uuid in{tuple(guild)}")
elif self.unique_tag == 'user_account':
if self.amount_type == 0:
amount_type = 'consumablel'
else:
amount_type = 'withdrawable'
assets_cond.append(f" uuid not in{tuple(guild + account)} and amount_type='{amount_type}'")
elif self.unique_tag == 'knapsack_account':
assets_cond.append(f" amount_type='backpack'")
else:
acc_uuid = [i['uuid'] for i in acc_data if i['unique_tag'] == self.unique_tag]
if not acc_uuid:
print('没找到系统账户')
return []
assets_cond.append(f" uuid='{acc_uuid[0]}'")
assets_sql = f"select amount from {self.date} where {' and '.join(assets_cond)}"
total_data = LinkMysql(env.DB_HISTORY).query_mysql(assets_sql)
df = pd.DataFrame(total_data)
df_total = df.sum()
total_dict = df_total.to_dict()
if total_data:
return total_dict.get('amount')/1000
return 0
from typing import Optional
from fastapi import APIRouter, Depends
from fastapi import APIRouter
from app.api.home.crud import HomePageDisplay
from libs.result_format import HttpResultResponse, HttpMessage
from libs.token_verify import login_required
router = APIRouter()
@router.get("/multidimensional/total")
def read_account(date: Optional[str] = "",
unique_tag: Optional[str] = "",
account_type: Optional[str] = "",
amount_type: Optional[str] = "",
reference_type: Optional[str] = "",
type: Optional[int] = None, token=Depends(login_required)):
"""月,业务类型,消费类型,出入账目统计"""
if not all([date, reference_type]) or type is None or (not unique_tag and not account_type):
return HttpResultResponse(code=500, msg=HttpMessage.MISSING_PARAMETER)
if account_type and not unique_tag:
unique_tag = account_type
total = HomePageDisplay(date, unique_tag, amount_type, reference_type, type).get_month_data()
return HttpResultResponse(data=total)
......@@ -3,7 +3,7 @@ import threading
import time
from concurrent.futures.thread import ThreadPoolExecutor
from datetime import datetime
import xlsxwriter
import openpyxl
import pandas as pd
from fastapi import Depends
......@@ -53,6 +53,49 @@ def data_to_file(db, data, name, header, field_list):
crud.create_export_data(db, params, user)
# 账户类型导出专用
def account_data_to_file(db, data, outcome, income, header):
user = query_token(db, header)
params = {"source": '账户类型汇总', "method": "data_to_file", "status": 1}
if len(data) == 0:
params["status"] = 3
try:
income_list = [i for i in data if i['type'] == '入账']
outcome_list = [i for i in data if i['type'] == '出账']
workbook = xlsxwriter.Workbook("账户类型汇总.xlsx")
worksheet = workbook.add_worksheet()
worksheet.merge_range("A1:B1", "出账")
worksheet.write(1, 0, '类型')
worksheet.write(1, 1, '金额(元)')
row = 2
col = 0
for x in outcome_list:
worksheet.write(row, col, x['name'])
worksheet.write(row, col + 1, x['money'])
row += 1
worksheet.write(row, 0, '合计')
worksheet.write(row, 1, income)
row += 2
worksheet.merge_range(f"A{row}:B{row}", "入账")
worksheet.write(1, 0, '类型')
worksheet.write(1, 1, '金额(元)')
for y in income_list:
worksheet.write(row, col, y['name'])
worksheet.write(row, col + 1, y['money'])
row += 1
worksheet.write(row, 0, '合计')
worksheet.write(row, 1, outcome)
workbook.close()
file = open("账户类型汇总.xlsx", 'rb')
# 记录导出
crud.create_export_data(db, params, user)
return StreamingResponse(file, media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
except Exception as e:
params["status"] = 2
crud.create_export_data(db, params, user)
class RechargeStatement(object):
"""充值报表"""
......
import json
import pymysql
import pika
from DBUtils.PooledDB import PooledDB
......
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