dev
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
from fastapi.params import Param
|
from fastapi.params import Param
|
||||||
from api.core.Gzip import register_gzip_request
|
from api.core.Gzip import register_gzip_request
|
||||||
import json
|
import json
|
||||||
from fastapi import APIRouter, Path
|
from fastapi import APIRouter, Path, Query
|
||||||
from api.core.Response import response
|
from api.core.Response import response
|
||||||
from api.core.Redis import get_redis_info
|
from api.core.Redis import get_redis_info
|
||||||
from api.dp import RedisDep
|
from api.dp import RedisDep
|
||||||
import re
|
import re
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
from api.types.open import SkillDetailResponse, SkillsListResponse,SearchSkillResponse
|
from api.types.open import SkillDataSummaryResponse, SkillDetailResponse, SkillsListResponse, SearchSkillResponse
|
||||||
|
import os
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ def replace_placeholders(template):
|
|||||||
|
|
||||||
|
|
||||||
@router.get('/skills/', operation_id='skillsList')
|
@router.get('/skills/', operation_id='skillsList')
|
||||||
async def get_skills_list(redis: RedisDep, skillName: Annotated[str, Param(..., description='技能名称,支持模糊查询')])->SearchSkillResponse:
|
async def get_skills_list(redis: RedisDep, skillName: Annotated[str, Param(..., description='技能名称,支持模糊查询')]) -> SearchSkillResponse:
|
||||||
"""
|
"""
|
||||||
根据技能名称,获取对应的技能列表信息
|
根据技能名称,获取对应的技能列表信息
|
||||||
"""
|
"""
|
||||||
@@ -64,6 +65,7 @@ async def get_cn_skills_by_job(redis: RedisDep, jobId: Annotated[str, Path(...,
|
|||||||
skills_list = get_redis_info(redis, key, get_skills_by_job)
|
skills_list = get_redis_info(redis, key, get_skills_by_job)
|
||||||
return response(data=skills_list)
|
return response(data=skills_list)
|
||||||
|
|
||||||
|
|
||||||
@router.get('/{jobId}/{jobGrowId}/{skillId}/', operation_id='skillDetail')
|
@router.get('/{jobId}/{jobGrowId}/{skillId}/', operation_id='skillDetail')
|
||||||
async def get_cn_skill_info(redis: RedisDep, jobId: Annotated[str, Path(..., description='职业')], jobGrowId: Annotated[str, Path(..., description='转职')], skillId: Annotated[str, Path(..., description='技能')], level: Annotated[int, Param(..., description='技能等级')] = None) -> SkillDetailResponse:
|
async def get_cn_skill_info(redis: RedisDep, jobId: Annotated[str, Path(..., description='职业')], jobGrowId: Annotated[str, Path(..., description='转职')], skillId: Annotated[str, Path(..., description='技能')], level: Annotated[int, Param(..., description='技能等级')] = None) -> SkillDetailResponse:
|
||||||
"""
|
"""
|
||||||
@@ -98,3 +100,49 @@ async def get_cn_skill_info(redis: RedisDep, jobId: Annotated[str, Path(..., des
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return response(code=404, message=f'技能信息未找到: {jobId} {jobGrowId} {skillId}', data=None)
|
return response(code=404, message=f'技能信息未找到: {jobId} {jobGrowId} {skillId}', data=None)
|
||||||
return response(data=skill_info)
|
return response(data=skill_info)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get('/skillData/summary/', operation_id='skillDataSummary')
|
||||||
|
async def get_skill_data_summary(
|
||||||
|
redis: RedisDep,
|
||||||
|
job: Annotated[str, Param(..., description='职业')],
|
||||||
|
skills: Annotated[str, Param(..., description='技能列表字符串,逗号拼接技能名称,不传递或者传递为空时,查询所有')] = "",
|
||||||
|
weapons: Annotated[str, Param(..., description='武器类型列表字符串,逗号拼接武器类型名称,不传递或者传递为空时,查询所有')] = "",
|
||||||
|
) -> SkillDataSummaryResponse:
|
||||||
|
"""
|
||||||
|
获取技能数据汇总信息
|
||||||
|
"""
|
||||||
|
key = f'openapi:skillData:summary:{job}'
|
||||||
|
data = []
|
||||||
|
skills = skills.split(',') if skills else []
|
||||||
|
weapons = weapons.split(',') if weapons else []
|
||||||
|
try:
|
||||||
|
def get_skill_data_summary():
|
||||||
|
# This function should retrieve the skill data summary based on job
|
||||||
|
# For now, we return a placeholder dictionary
|
||||||
|
summary_dir = './openapi/summary/'
|
||||||
|
json_files = [f for f in os.listdir(summary_dir) if f.endswith('.json')]
|
||||||
|
res = []
|
||||||
|
for i in json_files:
|
||||||
|
print(i)
|
||||||
|
if job in i:
|
||||||
|
with open(os.path.join(summary_dir, i), encoding='utf-8') as f:
|
||||||
|
skill_data = json.load(f)
|
||||||
|
weapon = i.split('_')[-1].replace('.json', '')
|
||||||
|
print(weapon, i)
|
||||||
|
res.append({
|
||||||
|
"weapon": weapon if weapon else "通用",
|
||||||
|
'skills': skill_data
|
||||||
|
})
|
||||||
|
return res
|
||||||
|
job_summary = get_redis_info(redis, key, get_skill_data_summary)
|
||||||
|
for item in job_summary:
|
||||||
|
if (len(weapons) == 0 or item['weapon'] in weapons):
|
||||||
|
skills = list(filter(lambda x: x['技能名称'] in skills, item['skills'])) if len(skills) > 0 else item['skills']
|
||||||
|
for skill in skills:
|
||||||
|
skill['武器类型'] = item['weapon']
|
||||||
|
data.extend(skills or [])
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
print(f'File not found: {e}')
|
||||||
|
return response(data=[])
|
||||||
|
return response(data=data)
|
||||||
@@ -19,6 +19,7 @@ class SkillInfo(BaseModel):
|
|||||||
jobGrowName: str = Field(..., description='转职名称')
|
jobGrowName: str = Field(..., description='转职名称')
|
||||||
"""转职名称"""
|
"""转职名称"""
|
||||||
|
|
||||||
|
|
||||||
class SkillType(str, Enum):
|
class SkillType(str, Enum):
|
||||||
active = 'active'
|
active = 'active'
|
||||||
"""主动技能"""
|
"""主动技能"""
|
||||||
@@ -131,6 +132,7 @@ class SkillDetail(BaseModel):
|
|||||||
enhancement: list[IEnhancement] | None = Field(None, description='技能强化信息')
|
enhancement: list[IEnhancement] | None = Field(None, description='技能强化信息')
|
||||||
"""技能强化信息"""
|
"""技能强化信息"""
|
||||||
|
|
||||||
|
|
||||||
class SkillListItem(BaseModel):
|
class SkillListItem(BaseModel):
|
||||||
skillId: str = Field(..., description='技能ID')
|
skillId: str = Field(..., description='技能ID')
|
||||||
"""技能ID"""
|
"""技能ID"""
|
||||||
@@ -141,6 +143,22 @@ class SkillListItem(BaseModel):
|
|||||||
type: SkillType = Field(..., description='技能类型')
|
type: SkillType = Field(..., description='技能类型')
|
||||||
"""技能类型"""
|
"""技能类型"""
|
||||||
|
|
||||||
|
|
||||||
|
class SkillSummaryItem(BaseModel):
|
||||||
|
技能名称: str = Field(..., description='技能名称')
|
||||||
|
"""技能名称"""
|
||||||
|
Lv: int | None = Field(..., description='技能等级')
|
||||||
|
"""技能等级"""
|
||||||
|
基础百分比: float = Field(..., description='基础百分比')
|
||||||
|
等效百分比: float = Field(..., description='等效百分比')
|
||||||
|
原始冷却: float | str = Field(..., description='原始冷却')
|
||||||
|
实际冷却: float | str = Field(..., description='实际冷却')
|
||||||
|
理论秒伤: float | str | None = Field(..., description='理论秒伤')
|
||||||
|
SP: float | None = Field(..., description='SP')
|
||||||
|
武器类型: str = Field(..., description='武器类型')
|
||||||
|
|
||||||
|
|
||||||
SkillDetailResponse = Response[SkillDetail | None]
|
SkillDetailResponse = Response[SkillDetail | None]
|
||||||
SearchSkillResponse = Response[list[SkillInfo]]
|
SearchSkillResponse = Response[list[SkillInfo]]
|
||||||
SkillsListResponse = Response[list[SkillListItem]]
|
SkillsListResponse = Response[list[SkillListItem]]
|
||||||
|
SkillDataSummaryResponse = Response[list[SkillSummaryItem]]
|
||||||
|
|||||||
+1
-1
Submodule backend/openapi updated: 6e6128c8d0...9fa43a0999
Reference in New Issue
Block a user