From 84be8ec219992c5beaa55a3f98509b7c41c60a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F?= <250213850@qq.com> Date: Mon, 18 Apr 2022 17:10:09 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A8=A1=E5=9D=97=E4=BA=8B=E4=BB=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=92=8C=E6=98=BE=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api_v1/endpoints/query.py | 44 +++++++++++++++++++++++++++++++---- crud/__init__.py | 3 ++- crud/crud_event_list.py | 25 ++++++++++++++++++++ schemas/__init__.py | 3 ++- schemas/event_list.py | 10 ++++++++ schemas/sql.py | 2 +- 6 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 crud/crud_event_list.py create mode 100644 schemas/event_list.py diff --git a/api/api_v1/endpoints/query.py b/api/api_v1/endpoints/query.py index c781eb6..0da81d0 100644 --- a/api/api_v1/endpoints/query.py +++ b/api/api_v1/endpoints/query.py @@ -5,7 +5,7 @@ from urllib.parse import quote import os import pandas as pd import numpy as np -from fastapi import APIRouter, Depends, Request +from fastapi import APIRouter, Depends, Request,File from fastapi.encoders import jsonable_encoder from motor.motor_asyncio import AsyncIOMotorDatabase from fastapi.responses import StreamingResponse @@ -1395,8 +1395,13 @@ async def user_property_model( ckdb: CKDrive = Depends(get_ck_db) ): """用户的详情""" - event_dict={'pay':'充值','create_account':'创建角色','login':'登录','ta_app_end':'离开游戏','guide':'新手引导','level_up':'玩家等级', - 'vip_level':'vip等级','sign':'签到','summon':'招募','ask_for_join_guild':'加入联盟','leave_guild':'离开联盟','create_guild':'创建联盟'} + if data_in.event_list == []: + return schemas.Msg(code=-9, msg='请配置用户搜索模块事件', data=[]) + event_dict={} + for i in data_in.event_list: + event_dict[i['event']]=i['event_name'] + # event_dict={'pay':'充值','create_account':'创建角色','login':'登录','ta_app_end':'离开游戏','guide':'新手引导','level_up':'玩家等级', + # 'vip_level':'vip等级','sign':'签到','summon':'招募','ask_for_join_guild':'加入联盟','leave_guild':'离开联盟','create_guild':'创建联盟'} sql=f"""select `#account_id`,`#ip`,`#distinct_id`,rmbmoney,owner_name,lv,zhanli,channel, channel,svrindex,maxmapid,name,`exp`,vip,jinbi,last_account_login_time,binduid from {game}.`user` where `#account_id` = '{data_in.account_id}'""" #获取用户基本详情 @@ -1508,6 +1513,35 @@ async def event_list( ) -> schemas.Msg: """个人详情中的事件列表""" #获取事件名 - event_list = await ckdb.distinct(game, 'event', '#event_name') + #event_list = await ckdb.distinct(game, 'event', '#event_name') + event_list = await crud.event_list.get_list(db,game) + if event_list == []: + return schemas.Msg(code=0, msg='请配置用户搜索模块事件', data=[]) + else: + res=event_list[0]['details'] + return schemas.Msg(code=0, msg='ok', data=res) - return schemas.Msg(code=0, msg='ok', data=event_list) +@router.post("/add_event_list") +async def add_select_map( + request: Request, + game: str, + file: bytes = File(...), + db: AsyncIOMotorDatabase = Depends(get_database), + current_user: schemas.UserDB = Depends(deps.get_current_user) +) -> schemas.Msg: + """添加对应游戏事件选择映射""" + dfs = pd.read_excel(file, engine='openpyxl', sheet_name=None) + for attr_name, df in dfs.items(): + #将id这列转换成字符串类型 + if len(df) >0: + ColNames = df.columns.tolist() + event = df.to_dict('records') + details=[] + for i in event: + details_dict={} + details_dict['event']=i[ColNames[0]] + details_dict['event_name']=i[ColNames[1]] + details.append(details_dict) + data_in = schemas.Event_list(game=game, details=details) + await crud.event_list.save(db, data_in) + return schemas.Msg(code=0, msg='ok', data=1) diff --git a/crud/__init__.py b/crud/__init__.py index 6135aab..8094eaa 100644 --- a/crud/__init__.py +++ b/crud/__init__.py @@ -19,4 +19,5 @@ from .crud_proid_map import proid_map from .crud_api_board import api_board from .crud_url_list import url_list from .crud_user_url import user_url -from .crud_api_module import api_module \ No newline at end of file +from .crud_api_module import api_module +from .crud_event_list import event_list \ No newline at end of file diff --git a/crud/crud_event_list.py b/crud/crud_event_list.py new file mode 100644 index 0000000..ae86697 --- /dev/null +++ b/crud/crud_event_list.py @@ -0,0 +1,25 @@ +from motor.motor_asyncio import AsyncIOMotorDatabase + +import schemas +from crud.base import CRUDBase + +__all__ = 'event_list', + + +class EventMap(CRUDBase): + async def save(self, db: AsyncIOMotorDatabase, data_in: schemas.Event_list): + where = {'game': data_in.game} + return await self.update_one(db, where, {'$set': data_in.dict(skip_defaults=True)}, upsert=True) + + async def get_list(self, db: AsyncIOMotorDatabase, game: str): + where = {'game': game} + res = await self.find_many(db, where,{'_id': 0}) + return res + + async def get_select(self, db: AsyncIOMotorDatabase, data_in: schemas.SelectAttr, game: str): + where = {'game': game, **data_in.dict()} + res = await self.find_one(db, where, {'_id': 0}) + return res + + +event_list = EventMap('event_list') diff --git a/schemas/__init__.py b/schemas/__init__.py index ed4965c..c297ede 100644 --- a/schemas/__init__.py +++ b/schemas/__init__.py @@ -23,4 +23,5 @@ from .proid_map import * from .api_board import * from .url_list import * from .user_url import * -from .api_module import * \ No newline at end of file +from .api_module import * +from .event_list import * \ No newline at end of file diff --git a/schemas/event_list.py b/schemas/event_list.py new file mode 100644 index 0000000..5a69502 --- /dev/null +++ b/schemas/event_list.py @@ -0,0 +1,10 @@ +from typing import List, Dict +from pydantic import BaseModel + +class Event_list(BaseModel): + game:str + details:List[Dict] + +class Details(BaseModel): + event:str + event_name:str \ No newline at end of file diff --git a/schemas/sql.py b/schemas/sql.py index 71f304a..3085f93 100644 --- a/schemas/sql.py +++ b/schemas/sql.py @@ -30,4 +30,4 @@ class Ck_solo_user(BaseModel): account_id : str # #account_id start_time: str # 开始时间 例:2022-04-02 end_time: str # 结束时间 - event_list: List[str] #事件名 \ No newline at end of file + event_list: List[Dict] =None#事件名 \ No newline at end of file