新增更新token,提交素材,前测模板管理
This commit is contained in:
@@ -66,7 +66,7 @@ async def create_template(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> Any:
|
||||
try:
|
||||
#新增一个判断,如果模板名称重复,提示用户修改
|
||||
#新增一个判断,如果模板名称重复,提示用户修改
|
||||
result = await db.execute(
|
||||
select(PreTestTemplate).where(
|
||||
PreTestTemplate.name == req.name,
|
||||
@@ -119,13 +119,13 @@ async def create_template(
|
||||
@router.get(
|
||||
"/list",
|
||||
summary="获取前测模板列表",
|
||||
description="获取当前用户的前测模板列表,支持按平台筛选和分页",
|
||||
description="获取当前用户的前测模板列表,支持按平台筛选和分页",
|
||||
response_model=PreTestTemplateListResponse,
|
||||
)
|
||||
async def list_templates(
|
||||
platform: Optional[str] = Query(None, description="投放平台筛选(AD/QIANCHUAN/LOCAL)"),
|
||||
page: int = Query(1, description="页码,默认1"),
|
||||
page_size: int = Query(10, description="每页数量,默认10,最大100"),
|
||||
page: int = Query(1, description="页码,默认1"),
|
||||
page_size: int = Query(10, description="每页数量,默认10,最大100"),
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> Any:
|
||||
@@ -300,20 +300,20 @@ async def delete_template(
|
||||
@router.get(
|
||||
"/getArea",
|
||||
summary="获取行政区域信息",
|
||||
description="获取指定级别的行政区域信息,支持一级、二级、三级区域,如果需要更新地区,执行:/api/pre-test-template/getArea?oauth_id=0019ecab9b8bc57d964&advertiser_id=1836693172153543",
|
||||
description="获取指定级别的行政区域信息,支持一级、二级、三级区域,如果需要更新地区,执行:/api/pre-test-template/getArea?oauth_id=0019ecab9b8bc57d964&advertiser_id=1836693172153543",
|
||||
)
|
||||
async def get_template_area(
|
||||
oauth_id: str = Query(None, description="授权ID选填,更新地区必填"),
|
||||
advertiser_id: str = Query(default="1836693172153543", description="授权ID选填,更新地区必填"),
|
||||
code: Optional[str] = Query("CN", description="行政区域编码,默认中国CN,选填"),
|
||||
level: Optional[str] = Query("ONE_LEVEL", description="行政区域层级,可选值:ONE_LEVEL(获取省份)、TWO_LEVEL(市级)、THREE_LEVEL(区级)"),
|
||||
parent_code: Optional[str] = Query(None, description="父级区域编码,获取二级时传一级编码,获取三级时传二级编码"),
|
||||
oauth_id: str = Query(None, description="授权ID选填,更新地区必填"),
|
||||
advertiser_id: str = Query(default="1836693172153543", description="授权ID选填,更新地区必填"),
|
||||
code: Optional[str] = Query("CN", description="行政区域编码,默认中国CN,选填"),
|
||||
level: Optional[str] = Query("ONE_LEVEL", description="行政区域层级,可选值:ONE_LEVEL(获取省份)、TWO_LEVEL(市级)、THREE_LEVEL(区级)"),
|
||||
parent_code: Optional[str] = Query(None, description="父级区域编码,获取二级时传一级编码,获取三级时传二级编码"),
|
||||
) -> Any:
|
||||
try:
|
||||
# 1. 先检查缓存是否存在
|
||||
area_list = get_cached_area_data()
|
||||
|
||||
# 2. 如果缓存不存在,调用接口获取数据并保存到缓存
|
||||
# 2. 如果缓存不存在,调用接口获取数据并保存到缓存
|
||||
if not area_list:
|
||||
area_list = await fetch_and_cache_area_data(oauth_id, advertiser_id, code)
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import os
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Optional, Dict
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from pydantic import BaseModel, Field
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.dependencies import get_current_user, get_db
|
||||
from app.models.user import User
|
||||
from app.models.pre_test_template import PreTestTemplate
|
||||
from app.services.upload_material_service import upload_material_to_platform
|
||||
from sqlalchemy import select
|
||||
from app.utils.douyinApi import DouyinApi
|
||||
|
||||
|
||||
router = APIRouter(prefix="/upload-material", tags=["上传素材"])
|
||||
|
||||
@@ -15,8 +19,8 @@ class UploadTask(BaseModel):
|
||||
advertiser_ids: list[str] = Field(..., description="广告主id数组,支持多条")
|
||||
resource_ids: list[str] = Field(..., description="资源id数组(generated_resources表主键)")
|
||||
oauth_id: str = Field(..., description="授权表id")
|
||||
is_pre_test: Optional[str] = Field(None, description="是否开启前测:是/否/0/1,预留字段")
|
||||
pre_test_template: Optional[str] = Field(None, description="前测模板id,预留字段")
|
||||
is_pre_test: Optional[str] = Field(None, description="是否开启前测:1=是/2=否")
|
||||
pre_test_template: Optional[str] = Field(None, description="前测模板id")
|
||||
|
||||
|
||||
class BatchUploadRequest(BaseModel):
|
||||
@@ -33,11 +37,35 @@ async def batch_upload_material(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> Any | dict:
|
||||
# try:
|
||||
# params = {
|
||||
# "advertiser_id": 1836693172153543,
|
||||
# "video_ids": ["tos-cn-i-sd07hgqsbj/2db9a53ee3ff4b6f8a2763b3bb463047"],
|
||||
# "diagnose_config": {"platform": "AD", "external_action": "AD_APP_ACTIVATE"},
|
||||
# }
|
||||
# response = await DouyinApi().pre_test_material("0019ecab9b8bc57d964", params)
|
||||
# return response
|
||||
# except Exception as e:
|
||||
# import traceback
|
||||
# return {
|
||||
# "code": 500,
|
||||
# "message": "请求失败",
|
||||
# "error": str(e),
|
||||
# "traceback": traceback.format_exc()
|
||||
# }
|
||||
if not req.tasks:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="上传任务列表不能为空",
|
||||
)
|
||||
return {
|
||||
"code": 0,
|
||||
"message": "批量上传完成",
|
||||
"summary": {
|
||||
"total_tasks": 0,
|
||||
"total_success_count": 0,
|
||||
"total_fail_count": 0,
|
||||
"total_requested": 0,
|
||||
},
|
||||
"details": [],
|
||||
"error": "上传任务列表不能为空"
|
||||
}
|
||||
|
||||
all_results = []
|
||||
total_success = 0
|
||||
@@ -56,9 +84,73 @@ async def batch_upload_material(
|
||||
|
||||
try:
|
||||
if not task.advertiser_ids:
|
||||
raise ValueError("广告主id数组不能为空")
|
||||
task_result["result"] = {
|
||||
"success": False,
|
||||
"error": "广告主id数组不能为空",
|
||||
"success_count": 0,
|
||||
"fail_count": 0,
|
||||
"total_count": 0,
|
||||
"results": [],
|
||||
}
|
||||
all_results.append(task_result)
|
||||
continue
|
||||
|
||||
if not task.resource_ids:
|
||||
raise ValueError("资源id数组不能为空")
|
||||
task_result["result"] = {
|
||||
"success": False,
|
||||
"error": "资源id数组不能为空",
|
||||
"success_count": 0,
|
||||
"fail_count": 0,
|
||||
"total_count": 0,
|
||||
"results": [],
|
||||
}
|
||||
all_results.append(task_result)
|
||||
continue
|
||||
|
||||
if (task.is_pre_test == "1") and (not task.pre_test_template):
|
||||
task_result["result"] = {
|
||||
"success": False,
|
||||
"error": "开启前测功能时,必须指定前测模板id",
|
||||
"success_count": 0,
|
||||
"fail_count": len(task.resource_ids) * len(task.advertiser_ids),
|
||||
"total_count": len(task.resource_ids) * len(task.advertiser_ids),
|
||||
"results": [{
|
||||
"resource_id": rid,
|
||||
"advertiser_id": aid,
|
||||
"filename": "",
|
||||
"success": False,
|
||||
"error": "开启前测功能时,必须指定前测模板id"
|
||||
} for rid in task.resource_ids for aid in task.advertiser_ids],
|
||||
}
|
||||
total_fail += len(task.resource_ids) * len(task.advertiser_ids)
|
||||
all_results.append(task_result)
|
||||
continue
|
||||
|
||||
if task.is_pre_test == "1":
|
||||
template = await db.execute(
|
||||
select(PreTestTemplate).where(PreTestTemplate.id == task.pre_test_template).
|
||||
where(PreTestTemplate.deleted_at.is_(None)).
|
||||
where(PreTestTemplate.user_id == current_user.id)
|
||||
)
|
||||
template = template.scalar_one_or_none()
|
||||
if not template:
|
||||
task_result["result"] = {
|
||||
"success": False,
|
||||
"error": "前测模板id不存在",
|
||||
"success_count": 0,
|
||||
"fail_count": len(task.resource_ids) * len(task.advertiser_ids),
|
||||
"total_count": len(task.resource_ids) * len(task.advertiser_ids),
|
||||
"results": [{
|
||||
"resource_id": rid,
|
||||
"advertiser_id": aid,
|
||||
"filename": "",
|
||||
"success": False,
|
||||
"error": "前测模板id不存在"
|
||||
} for rid in task.resource_ids for aid in task.advertiser_ids],
|
||||
}
|
||||
total_fail += len(task.resource_ids) * len(task.advertiser_ids)
|
||||
all_results.append(task_result)
|
||||
continue
|
||||
|
||||
result = await upload_material_to_platform(
|
||||
task.resource_ids,
|
||||
@@ -66,6 +158,7 @@ async def batch_upload_material(
|
||||
task.oauth_id,
|
||||
db,
|
||||
current_user.id,
|
||||
task.pre_test_template if task.is_pre_test == "1" else None,
|
||||
)
|
||||
|
||||
task_result["result"] = {
|
||||
@@ -75,23 +168,37 @@ async def batch_upload_material(
|
||||
total_success += result["success_count"]
|
||||
total_fail += result["fail_count"]
|
||||
|
||||
if task.is_pre_test and task.is_pre_test in ["是", "1", "true", True]:
|
||||
task_result["pre_test_reserved"] = {
|
||||
"status": "reserved",
|
||||
"message": "前测功能已预留,待后续开通",
|
||||
"template": task.pre_test_template,
|
||||
}
|
||||
|
||||
|
||||
except ValueError as e:
|
||||
task_result["result"] = {
|
||||
"success": False,
|
||||
"error": str(e),
|
||||
"success_count": 0,
|
||||
"fail_count": len(task.resource_ids) * len(task.advertiser_ids),
|
||||
"total_count": len(task.resource_ids) * len(task.advertiser_ids),
|
||||
"results": [{
|
||||
"resource_id": rid,
|
||||
"advertiser_id": aid,
|
||||
"filename": "",
|
||||
"success": False,
|
||||
"error": str(e)
|
||||
} for rid in task.resource_ids for aid in task.advertiser_ids],
|
||||
}
|
||||
total_fail += len(task.resource_ids) * len(task.advertiser_ids)
|
||||
except Exception as e:
|
||||
task_result["result"] = {
|
||||
"success": False,
|
||||
"error": f"上传失败: {str(e)}",
|
||||
"success_count": 0,
|
||||
"fail_count": len(task.resource_ids) * len(task.advertiser_ids),
|
||||
"total_count": len(task.resource_ids) * len(task.advertiser_ids),
|
||||
"results": [{
|
||||
"resource_id": rid,
|
||||
"advertiser_id": aid,
|
||||
"filename": "",
|
||||
"success": False,
|
||||
"error": f"上传失败: {str(e)}"
|
||||
} for rid in task.resource_ids for aid in task.advertiser_ids],
|
||||
}
|
||||
total_fail += len(task.resource_ids) * len(task.advertiser_ids)
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ async def juliang_callback(
|
||||
|
||||
await get_token(auth_code, user_id, app_id, db)
|
||||
return {
|
||||
"message": "授权成功",
|
||||
"message": "授权成功,这里需要跳转页面路径到 /user-oauth/oauth_list",
|
||||
"code": 0,
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ async def oauth_list(
|
||||
"account_name": oauth.account_name,
|
||||
"account_role": oauth.account_role,
|
||||
"account_username": oauth.account_username,
|
||||
"account_userid": oauth.account_userid,
|
||||
"user_id": oauth.user_id,
|
||||
"open_type": oauth.open_type,
|
||||
"port_type": oauth.port_type,
|
||||
|
||||
Reference in New Issue
Block a user