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