版本回退
This commit is contained in:
@@ -124,68 +124,68 @@ def delete_account(request: AccountDeleteRequest, db: Session = Depends(get_db))
|
|||||||
message="账号删除成功",
|
message="账号删除成功",
|
||||||
data=None
|
data=None
|
||||||
)
|
)
|
||||||
# 获取今日上传的数据接口
|
# # 获取今日上传的数据接口
|
||||||
@router.post("/get_uplaod_data", response_model=AccountListResponse)
|
# @router.post("/get_uplaod_data", response_model=AccountListResponse)
|
||||||
def get_account(request: AccountGetRequest, db: Session = Depends(get_db)):
|
# def get_account(request: AccountGetRequest, db: Session = Depends(get_db)):
|
||||||
"""根据多种条件查询账号,并合并外部接口的 is_ok 字段"""
|
# """根据多种条件查询账号,并合并外部接口的 is_ok 字段"""
|
||||||
# 1. 从数据库查询账号列表
|
# # 1. 从数据库查询账号列表
|
||||||
accounts = AccountService.search_accounts(
|
# accounts = AccountService.search_accounts(
|
||||||
db,
|
# db,
|
||||||
account_id=request.account_id,
|
# account_id=request.account_id,
|
||||||
username=request.username,
|
# username=request.username,
|
||||||
project_name=request.project_name,
|
# project_name=request.project_name,
|
||||||
status=request.status,
|
# status=request.status,
|
||||||
today_updated=request.today_updated,
|
# today_updated=request.today_updated,
|
||||||
yh_id=request.yh_id,
|
# yh_id=request.yh_id,
|
||||||
cl_name=request.cl_name
|
# cl_name=request.cl_name
|
||||||
)
|
# )
|
||||||
|
|
||||||
# 2. 调用外部接口获取 today_data,构建 user_name -> is_ok 映射
|
# # 2. 调用外部接口获取 today_data,构建 user_name -> is_ok 映射
|
||||||
user_is_ok_map = {} # 存储映射关系,提升匹配效率
|
# user_is_ok_map = {} # 存储映射关系,提升匹配效率
|
||||||
url = "https://engineering.yuxindazhineng.com/index/index/get_over_data"
|
# url = "https://engineering.yuxindazhineng.com/index/index/get_over_data"
|
||||||
payload = {"user_id": "68c0dbfdb7cbcd616e7c5ab5"}
|
# payload = {"user_id": "68c0dbfdb7cbcd616e7c5ab5"}
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
# 发送POST请求并解析JSON响应
|
# # 发送POST请求并解析JSON响应
|
||||||
response = requests.request("POST", url, data=payload).json()
|
# response = requests.request("POST", url, data=payload).json()
|
||||||
if response['code'] == 0:
|
# if response['code'] == 0:
|
||||||
today_data = response['data']
|
# today_data = response['data']
|
||||||
|
|
||||||
# 遍历 today_data,构建映射字典
|
# # 遍历 today_data,构建映射字典
|
||||||
for item in today_data:
|
# for item in today_data:
|
||||||
# 校验字段是否存在,避免 KeyError 异常
|
# # 校验字段是否存在,避免 KeyError 异常
|
||||||
if 'user_name' in item and 'is_ok' in item:
|
# if 'user_name' in item and 'is_ok' in item:
|
||||||
user_name = item['user_name']
|
# user_name = item['user_name']
|
||||||
is_ok = item['is_ok']
|
# is_ok = item['is_ok']
|
||||||
user_is_ok_map[user_name] = is_ok # 键:user_name,值:is_ok
|
# user_is_ok_map[user_name] = is_ok # 键:user_name,值:is_ok
|
||||||
|
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
# 捕获接口调用/解析异常,不阻断核心业务(数据库查询结果正常返回)
|
# # 捕获接口调用/解析异常,不阻断核心业务(数据库查询结果正常返回)
|
||||||
print(f"外部接口调用失败或数据解析异常:{str(e)}")
|
# print(f"外部接口调用失败或数据解析异常:{str(e)}")
|
||||||
|
|
||||||
# 3. 遍历 accounts,给每个账号对象添加 is_ok 字段(关键步骤)
|
# # 3. 遍历 accounts,给每个账号对象添加 is_ok 字段(关键步骤)
|
||||||
for account in accounts:
|
# for account in accounts:
|
||||||
# 匹配 username(数据库)和 user_name(外部接口)
|
# # 匹配 username(数据库)和 user_name(外部接口)
|
||||||
current_username = account.username
|
# current_username = account.username
|
||||||
# 从映射字典中获取 is_ok,无匹配则默认赋值 0(可根据业务调整默认值)
|
# # 从映射字典中获取 is_ok,无匹配则默认赋值 0(可根据业务调整默认值)
|
||||||
is_ok_value = user_is_ok_map.get(current_username, 0)
|
# is_ok_value = user_is_ok_map.get(current_username, 0)
|
||||||
|
|
||||||
# 给 account 对象添加 is_ok 字段(兼容 Pydantic 模型,需满足对应配置)
|
# # 给 account 对象添加 is_ok 字段(兼容 Pydantic 模型,需满足对应配置)
|
||||||
account.is_ok = is_ok_value
|
# account.is_ok = is_ok_value
|
||||||
|
|
||||||
# 4. 处理空结果返回
|
# # 4. 处理空结果返回
|
||||||
if not accounts:
|
# if not accounts:
|
||||||
return AccountListResponse(
|
# return AccountListResponse(
|
||||||
code=ResponseCode.ACCOUNT_NOT_FOUND,
|
# code=ResponseCode.ACCOUNT_NOT_FOUND,
|
||||||
message=ResponseMessage.ACCOUNT_NOT_FOUND,
|
# message=ResponseMessage.ACCOUNT_NOT_FOUND,
|
||||||
total=0,
|
# total=0,
|
||||||
data=[]
|
# data=[]
|
||||||
)
|
# )
|
||||||
|
|
||||||
# 5. 正常返回结果(包含 is_ok 字段的 accounts)
|
# # 5. 正常返回结果(包含 is_ok 字段的 accounts)
|
||||||
return AccountListResponse(
|
# return AccountListResponse(
|
||||||
code=ResponseCode.SUCCESS,
|
# code=ResponseCode.SUCCESS,
|
||||||
message="查询成功",
|
# message="查询成功",
|
||||||
total=len(accounts),
|
# total=len(accounts),
|
||||||
data=accounts
|
# data=accounts
|
||||||
)
|
# )
|
||||||
@@ -17,9 +17,9 @@ class Account(Base):
|
|||||||
max_variation = Column(Integer, default=1, comment="变化量的绝对值,单位是毫米")
|
max_variation = Column(Integer, default=1, comment="变化量的绝对值,单位是毫米")
|
||||||
yh_id = Column(String(1000), comment="宇恒一号用户id")
|
yh_id = Column(String(1000), comment="宇恒一号用户id")
|
||||||
cl_name = Column(String(100), nullable=True, comment="测量人员")
|
cl_name = Column(String(100), nullable=True, comment="测量人员")
|
||||||
device_name = Column(String(1000), comment="设备名称")
|
# device_name = Column(String(1000), comment="设备名称")
|
||||||
device_port = Column(String(1000), comment="设备端口")
|
# device_port = Column(String(1000), comment="设备端口")
|
||||||
device_ip = Column(String(1000), comment="设备局域网内ip地址")
|
# device_ip = Column(String(1000), comment="设备局域网内ip地址")
|
||||||
|
|
||||||
|
|
||||||
# 模型转字典
|
# 模型转字典
|
||||||
|
|||||||
Reference in New Issue
Block a user