重构UniversalAPIManager以支持Dify工作流API 添加DifyWorkflowRequest模型和控制器方法 优化API密钥管理和请求处理逻辑 修改JWT验证方式从HTTPBearer到Header 更新API配置以支持新的Dify端点
176 lines
6.3 KiB
Python
176 lines
6.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
||
from typing import Optional
|
||
|
||
from app.controllers.user_valuation import user_valuation_controller
|
||
from app.schemas.valuation import (
|
||
UserValuationCreate,
|
||
UserValuationQuery,
|
||
UserValuationList,
|
||
UserValuationOut,
|
||
UserValuationDetail
|
||
)
|
||
from app.models.user import AppUser
|
||
|
||
from app.schemas.base import Success, SuccessExtra
|
||
from app.utils.app_user_jwt import get_current_app_user
|
||
|
||
app_valuations_router = APIRouter(tags=["用户端估值评估"])
|
||
|
||
|
||
@app_valuations_router.post("/", summary="创建估值评估")
|
||
async def create_valuation(
|
||
data: UserValuationCreate,
|
||
current_user: AppUser = Depends(get_current_app_user)
|
||
):
|
||
"""
|
||
用户创建估值评估申请
|
||
"""
|
||
try:
|
||
result = await user_valuation_controller.create_valuation(
|
||
user_id=current_user.id,
|
||
data=data
|
||
)
|
||
# 使用model_dump_json()来正确序列化datetime,然后解析为dict
|
||
import json
|
||
result_dict = json.loads(result.model_dump_json())
|
||
# 开始计算 估值 信息
|
||
# 1 # 经济价值B1模块: EconomicValueB1Calculator | BasicValueB11Calculator | TrafficFactorB12Calculator | PolicyMultiplierB13Calculator
|
||
# 1.1 EconomicValueB1Calculator
|
||
# input_data = {
|
||
# # 基础价值B11相关参数
|
||
# 'three_year_income': data.three_year_income,
|
||
# 'patent_score': data.pa, # 专利分
|
||
# 'popularity_score': data.popularity_score, # 普及地域分值
|
||
# 'infringement_score': data.infringement_score, # 侵权分
|
||
# 'innovation_ratio': data.innovation_ratio,
|
||
# 'esg_score':data.esg_score,
|
||
# 'industry_coefficient':data.industry_coefficient,
|
||
|
||
# # 流量因子B12相关参数
|
||
# 'search_index_s1': 4500.0,
|
||
# 'industry_average_s2': 5000.0,
|
||
# # 'social_media_spread_s3': social_media_spread_s3,
|
||
# 'likes': 4, # 点赞
|
||
# 'comments': 5, # 评论
|
||
# 'shares': 6, # 转发
|
||
# 'followers': 7, # 粉丝数
|
||
|
||
# 'click_count': 1000,# 点击量
|
||
# 'view_count': 100, # 内容浏览量
|
||
|
||
# # 政策乘数B13相关参数
|
||
# 'policy_match_score': 10.0, # 政策匹配度
|
||
# 'implementation_stage': 10.0, # 实施阶段评分
|
||
# 'funding_support': 10.0 # 资金支持度
|
||
# }
|
||
# 1.2 BasicValueB11Calculator
|
||
# 1.3 TrafficFactorB12Calculator
|
||
# 1.4 PolicyMultiplierB13Calculator
|
||
|
||
# 2 # 文化价值B2模块: CulturalValueB2Calculator | LivingHeritageB21Calculator | PatternGeneB22Calculator
|
||
# 2.1 CulturalValueB2Calculator
|
||
# 2.2 LivingHeritageB21Calculator
|
||
# 2.3 PatternGeneB22Calculator
|
||
|
||
# 3 # 风险调整系数B3模块: RiskAdjustmentB3Calculator
|
||
# 3.1 RiskAdjustmentB3Calculator
|
||
|
||
# 4 # 市场估值C模块: MarketValueCCalculator | MarketBiddingC1Calculator | HeatCoefficientC2Calculator | ScarcityMultiplierC3Calculator | TemporalDecayC4Calculator
|
||
# 4.1 MarketValueCCalculator
|
||
# 4.2 MarketBiddingC1Calculator
|
||
# 4.3 HeatCoefficientC2Calculator
|
||
# 4.4 ScarcityMultiplierC3Calculator
|
||
# 4.5 TemporalDecayC4Calculator
|
||
|
||
# 5 # 最终估值A模块: FinalValueACalculator
|
||
# 5.1 FinalValueACalculator
|
||
return Success(data=result_dict, msg="估值评估申请提交成功")
|
||
except Exception as e:
|
||
raise HTTPException(
|
||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||
detail=f"创建估值评估失败: {str(e)}"
|
||
)
|
||
|
||
|
||
@app_valuations_router.get("/", summary="获取我的估值评估列表")
|
||
async def get_my_valuations(
|
||
query: UserValuationQuery = Depends(),
|
||
current_user: AppUser = Depends(get_current_app_user)
|
||
|
||
):
|
||
"""
|
||
获取当前用户的估值评估列表
|
||
"""
|
||
try:
|
||
result = await user_valuation_controller.get_user_valuations(
|
||
user_id=current_user.id,
|
||
query=query
|
||
)
|
||
# 使用model_dump_json()来正确序列化datetime,然后解析为dict列表
|
||
import json
|
||
serialized_items = [json.loads(item.model_dump_json()) for item in result.items]
|
||
return SuccessExtra(
|
||
data=serialized_items,
|
||
total=result.total,
|
||
page=result.page,
|
||
page_size=result.size,
|
||
pages=result.pages,
|
||
msg="获取估值评估列表成功"
|
||
)
|
||
except Exception as e:
|
||
raise HTTPException(
|
||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||
detail=f"获取估值评估列表失败: {str(e)}"
|
||
)
|
||
|
||
|
||
@app_valuations_router.get("/{valuation_id}", summary="获取估值评估详情")
|
||
async def get_valuation_detail(
|
||
valuation_id: int,
|
||
current_user: AppUser = Depends(get_current_app_user)
|
||
):
|
||
"""
|
||
获取指定估值评估的详细信息
|
||
"""
|
||
try:
|
||
result = await user_valuation_controller.get_user_valuation_detail(
|
||
user_id=current_user.id,
|
||
valuation_id=valuation_id
|
||
)
|
||
|
||
if not result:
|
||
raise HTTPException(
|
||
status_code=status.HTTP_404_NOT_FOUND,
|
||
detail="估值评估记录不存在"
|
||
)
|
||
|
||
# 使用model_dump_json()来正确序列化datetime,然后解析为dict
|
||
import json
|
||
result_dict = json.loads(result.model_dump_json())
|
||
return Success(data=result_dict, msg="获取估值评估详情成功")
|
||
except HTTPException:
|
||
raise
|
||
except Exception as e:
|
||
raise HTTPException(
|
||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||
detail=f"获取估值评估详情失败: {str(e)}"
|
||
)
|
||
|
||
|
||
@app_valuations_router.get("/statistics/overview", summary="获取我的估值评估统计")
|
||
async def get_my_valuation_statistics(
|
||
current_user: AppUser = Depends(get_current_app_user)
|
||
):
|
||
"""
|
||
获取当前用户的估值评估统计信息
|
||
"""
|
||
try:
|
||
result = await user_valuation_controller.get_user_valuation_statistics(
|
||
user_id=current_user.id
|
||
)
|
||
return Success(data=result, msg="获取统计信息成功")
|
||
except Exception as e:
|
||
raise HTTPException(
|
||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||
detail=f"获取统计信息失败: {str(e)}"
|
||
) |