修改账号删除功能
This commit is contained in:
parent
0f6c06ada1
commit
a12f773517
|
|
@ -46,10 +46,8 @@ class DealAccount:
|
|||
return result
|
||||
return []
|
||||
|
||||
async def update_account_info(self, set_param: Dict[str, Any], params):
|
||||
async def update_account_info(self, set_param: Dict[str, Any], where_conditions, params):
|
||||
"""更新账户信息"""
|
||||
# params = {'name': '张三', 'age': 25}
|
||||
where_conditions = "account_id = %s"
|
||||
await self.db_pool.initialize()
|
||||
affected_rows = await self.db_pool.update(table='crawler_account_record_info', set_columns=set_param,
|
||||
where_conditions=where_conditions, params=params)
|
||||
|
|
|
|||
50
main.py
50
main.py
|
|
@ -8,7 +8,7 @@ from typing import Dict, Any, Optional, List
|
|||
from fastapi import FastAPI, HTTPException, Depends
|
||||
|
||||
from public_function.public_func import read_config
|
||||
from model.model import CrawlerTask, AccountDelete, DataReceive
|
||||
from model.model import CrawlerTask, DataReceive
|
||||
from model.model import AccountCreate, AccountUpdate, DeviceResetData
|
||||
|
||||
app = FastAPI()
|
||||
|
|
@ -82,14 +82,16 @@ async def add_account(account_data: AccountCreate, account_manager: Any = Depend
|
|||
print(account_data.dict())
|
||||
# 这里应该调用实际的添加账号方法
|
||||
result = await account_manager.add_account([account_data.dict()])
|
||||
if result:
|
||||
return {"code": 200, "message": "新增账号成功", "data": result}
|
||||
raise HTTPException(status_code=404, detail="新增账号失败")
|
||||
except Exception as e:
|
||||
print(f"新增账号失败: {e}")
|
||||
raise HTTPException(status_code=500, detail="新增账号失败,失败原因:{}".format(e))
|
||||
|
||||
|
||||
@app.post("/delete_account", summary="删除账号")
|
||||
async def delete_account(account_data: AccountDelete, account_manager: Any = Depends(get_account_manager)):
|
||||
@app.post("/update_account", summary="删除账号")
|
||||
async def update_account(account_data: AccountUpdate, account_manager: Any = Depends(get_account_manager)):
|
||||
"""
|
||||
删除爬虫账号
|
||||
- **account_id**: 账号ID
|
||||
|
|
@ -97,10 +99,16 @@ async def delete_account(account_data: AccountDelete, account_manager: Any = Dep
|
|||
- **app_name**: 应用名称
|
||||
"""
|
||||
try:
|
||||
print(account_data.dict())
|
||||
# 这里应该调用实际的添加账号方法
|
||||
result = await account_manager.delete_account(account_data.dict())
|
||||
return {"code": 200, "message": "删除账号成功", "data": result}
|
||||
data = account_data.dict()
|
||||
set_param = {"status": data["status"]}
|
||||
# params = {"account_id": data["account_id"], "app_name": data["app_name"]}
|
||||
params = (data["account_id"], data["app_name"])
|
||||
where_conditions = "account_id = %s and app_name = %s "
|
||||
# # 这里应该调用实际的添加账号方法
|
||||
result = await account_manager.update_account_info(set_param=set_param, where_conditions=where_conditions, params=params)
|
||||
if result:
|
||||
return {"code": 200, "message": "删除账号状态修改成功", "data": result}
|
||||
raise HTTPException(status_code=404, detail="删除账号状态修改失败")
|
||||
except Exception as e:
|
||||
print(f"新增账号失败: {e}")
|
||||
raise HTTPException(status_code=500, detail="删除账号失败,请重试,失败原因:{}".format(e))
|
||||
|
|
@ -136,20 +144,20 @@ async def crawler_task(task_data: CrawlerTask, task_manager: Any = Depends(get_t
|
|||
raise HTTPException(status_code=500, detail="获取数据失败;失败原因{}".format(e))
|
||||
|
||||
|
||||
@app.get("/device_reset", summary="爬虫任务调用接口")
|
||||
async def device_reset(task_data: CrawlerTask, reset_manager: Any = Depends(get_reset_manager)):
|
||||
"""设备重置接口"""
|
||||
try:
|
||||
params = task_data.dict()
|
||||
params['task_id'] = uuid.uuid4().hex
|
||||
# 将任务记录到mysql
|
||||
# result = await task_manager.task_distribution(params)
|
||||
# if result:
|
||||
# return {"code": 200, "message": "<UNK>", "data": result}
|
||||
raise HTTPException(status_code=404, detail="抓取商品数据失败,请重新尝试")
|
||||
except Exception as e:
|
||||
print(f"<UNK>: {e}")
|
||||
raise HTTPException(status_code=500, detail="获取数据失败;失败原因{}".format(e))
|
||||
# @app.get("/device_reset", summary="爬虫任务调用接口")
|
||||
# async def device_reset(task_data: CrawlerTask, reset_manager: Any = Depends(get_reset_manager)):
|
||||
# """设备重置接口"""
|
||||
# try:
|
||||
# params = task_data.dict()
|
||||
# params['task_id'] = uuid.uuid4().hex
|
||||
# # 将任务记录到mysql
|
||||
# # result = await task_manager.task_distribution(params)
|
||||
# # if result:
|
||||
# # return {"code": 200, "message": "<UNK>", "data": result}
|
||||
# raise HTTPException(status_code=404, detail="抓取商品数据失败,请重新尝试")
|
||||
# except Exception as e:
|
||||
# print(f"<UNK>: {e}")
|
||||
# raise HTTPException(status_code=500, detail="获取数据失败;失败原因{}".format(e))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -13,12 +13,8 @@ class AccountCreate(BaseModel):
|
|||
|
||||
class AccountUpdate(BaseModel):
|
||||
account_id: str = Field(..., description="账号ID")
|
||||
status: int = Field(..., ge=1, le=2, description="状态:1-空闲,2-使用中")
|
||||
|
||||
|
||||
class AccountDelete(BaseModel):
|
||||
account_id: str = Field(..., min_length=1, max_length=128, description="账号ID")
|
||||
app_name: str = Field(..., min_length=1, max_length=128, description="应用名称")
|
||||
status: int = Field(..., ge=1, le=3, description="状态:1-空闲,2-使用中,3-暂停使用")
|
||||
|
||||
|
||||
class CrawlerTask(BaseModel):
|
||||
|
|
|
|||
Loading…
Reference in New Issue