fix(admin/skills): 支持删除从市场导入的 MarketApp 技能
This commit is contained in:
1 parent
cc35c61fbd
commit
7fb7c07f57
1 file changed
+41
-4
@@ -534,11 +534,10 @@ async def delete_skill(
|
||||
admin_user=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""删除技能"""
|
||||
"""删除技能(支持 EvolutionSkill 和 MarketApp 两种来源)"""
|
||||
# 1) 先尝试 EvolutionSkill
|
||||
skill = db.query(EvolutionSkill).filter(EvolutionSkill.id == skill_id).first()
|
||||
if not skill:
|
||||
raise HTTPException(status_code=404, detail="技能不存在")
|
||||
|
||||
if skill:
|
||||
skill_name = skill.skill_name
|
||||
user_id = skill.user_id
|
||||
|
||||
@@ -561,6 +560,17 @@ async def delete_skill(
|
||||
# 删除团队共享记录
|
||||
db.query(TeamSharedSkill).filter(TeamSharedSkill.skill_id == skill_id).delete()
|
||||
|
||||
# 同步清理市场应用表中的同名技能
|
||||
market_app = db.query(MarketApp).filter(
|
||||
MarketApp.type == "skill",
|
||||
MarketApp.name == skill_name,
|
||||
).first()
|
||||
if market_app:
|
||||
db.query(AppInstallation).filter(AppInstallation.app_id == market_app.id).delete()
|
||||
db.query(AppPurchase).filter(AppPurchase.app_id == market_app.id).delete()
|
||||
db.query(AppReview).filter(AppReview.app_id == market_app.id).delete()
|
||||
db.delete(market_app)
|
||||
|
||||
db.delete(skill)
|
||||
db.commit()
|
||||
|
||||
@@ -574,6 +584,33 @@ async def delete_skill(
|
||||
|
||||
return {"code": 0, "message": f"技能 {skill_name} 已删除"}
|
||||
|
||||
# 2) 再尝试 MarketApp 中导入的技能(type=skill)
|
||||
market_app = db.query(MarketApp).filter(
|
||||
MarketApp.type == "skill",
|
||||
MarketApp.id == skill_id,
|
||||
).first()
|
||||
if market_app:
|
||||
skill_name = market_app.name
|
||||
# 清理关联记录
|
||||
db.query(AppInstallation).filter(AppInstallation.app_id == market_app.id).delete()
|
||||
db.query(AppPurchase).filter(AppPurchase.app_id == market_app.id).delete()
|
||||
db.query(AppReview).filter(AppReview.app_id == market_app.id).delete()
|
||||
db.delete(market_app)
|
||||
db.commit()
|
||||
|
||||
LogService.log_operation(
|
||||
user_id=admin_user.id,
|
||||
username=admin_user.username,
|
||||
action="delete_skill",
|
||||
target="market_apps",
|
||||
detail=f"删除市场技能 {skill_name}",
|
||||
)
|
||||
|
||||
return {"code": 0, "message": f"技能 {skill_name} 已删除"}
|
||||
|
||||
# 3) 都未找到
|
||||
raise HTTPException(status_code=404, detail="技能不存在")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 修改技能状态
|
||||
|
||||
Reference in new issue
Block a user