Commit 5ebe5b3e authored by xianyang's avatar xianyang

优化公会质押金,新增首页查询

parent 13d3d23f
......@@ -5,6 +5,7 @@ from app.api.role import views as r_view
from app.api.account import views as a_view
from app.api.margin import views as m_view
from app.api.export import views as e_view
from app.api.home import views as h_view
api_router = APIRouter()
api_router.include_router(u_view.router, prefix="/users", tags=["users"])
......@@ -13,3 +14,4 @@ api_router.include_router(r_view.router, prefix="/role", tags=["role"])
api_router.include_router(a_view.router, prefix="/account", tags=["account"])
api_router.include_router(m_view.router, prefix="/margin", tags=["margin"])
api_router.include_router(e_view.router, prefix="/export", tags=["export"])
api_router.include_router(h_view.router, prefix="/home", tags=["home"])
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 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)
......@@ -61,8 +61,17 @@ class Env(BaseSettings):
PASSWORD: str = "fj123456"
# DB_HISTORY = "3yakj_v2"
# guild_url=""
oss_url='http://oss.3yakj.com/application_static_data'
oss_url = 'http://oss.3yakj.com/application_static_data'
CLEARING_CENTER_URL: str = 'http://106.55.103.148:6464/'
RABBITMQ: dict = {
"url": "http://106.55.103.148:16672/",
"host": "106.55.103.148",
"vhost": "/",
"port": 6672,
"username": "admin",
"password": "nimda",
"queue": "financial_consistency"
}
class TestingEnv(Env):
......
import json
import pymysql
import pika
from DBUtils.PooledDB import PooledDB
# 连接mysql
from core.config.env import env, red
class LinkMysql(object):
def __init__(self, db_info):
self.POOLMYSQL = PooledDB(
......@@ -46,3 +52,12 @@ class LinkMysql(object):
conn = self.POOLMYSQL.connection()
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
cursor.execute(sql)
# class RabbitMqConn(object):
# """rabbitmq 连接"""
# def __init__(self):
# rb = env.RABBITMQ
# rb_info = pika.PlainCredentials(rb.get('username'), rb.get('password'))
# self.connection = pika.BlockingConnection(parameters=pika.ConnectionParameters(rb.get('host'), rb.get('port'), rb.get('vhost'), rb_info))
# self.channel = self.connection.channel()
import time
from datetime import timedelta, datetime
from datetime import timedelta
import uvicorn
from fastapi import FastAPI, Depends
from fastapi import FastAPI
from jose import jwt
from app.api.api_v1 import api_router
from starlette.middleware.cors import CORSMiddleware
from fastapi import Request
from core.config.env import env
from core.dependencies.auth_dependen import create_access_token
from libs.functions import time_format
from libs.token_verify import oauth2_scheme
app = FastAPI()
......@@ -25,6 +21,7 @@ app.add_middleware(
allow_methods=['*'], # 设置允许跨域的http方法,比如 get、post、put等。
allow_headers=['*']) # 允许跨域的headers,可以用来鉴别来源等作用。
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
hs = request.headers
......
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