dongchangxi 5 months ago
parent
commit
2ca9aa0da4
  1. 49
      timer/test_external_order.py

49
timer/test_external_order.py

@ -76,11 +76,60 @@ def down_obj_from_oss(workdir, pid, action):
return obj_filename return obj_filename
def checkDownloadFile(pid):
mtlfilePath = os.path.join(config.workdir, "print", pid,f"{pid}.mtl")
objfilePath = os.path.join(config.workdir, "print", pid,f"{pid}.obj")
#读取该笔文件的mtl文件
with open(mtlfilePath, 'r') as file:
mtlContent = file.read()
#检测mtl文件是否正常
if mtlContent == "":
return False
#判断mtl 包含几个 newmtl
newmtlCount = mtlContent.count('newmtl')
if newmtlCount > 1:
return False
#判断mtlContent是否包含 {pid}Tex1.jpg
if f'{pid}Tex1.jpg' not in mtlContent:
return False
#检测obj文件 里 是否包含 o {pid},
isContain = False
with open(objfilePath, 'r') as file:
for line in file:
if line.startswith(f'o {pid}'):
isContain = True
print(f'{pid}的obj文件检测没问题')
break
if isContain == False:
print(f'{pid}的obj文件检测出现问题了, 没有找到o {pid} 的行')
return False
return isContain
#加载obj文件 #加载obj文件
def reload_obj(pid,order_ids): def reload_obj(pid,order_ids):
#下载obj文件 #下载obj文件
down_obj_from_oss(config.workdir, pid, "print") down_obj_from_oss(config.workdir, pid, "print")
#检测mtl 文件是否正常,
isNormal = checkDownloadFile(pid)
if isNormal == False:
print(f'{pid}的mtl文件检测出现问题,不执行该笔任务,调用取消的接口')
for order_id in order_ids:
url = f"https://mp.api.suwa3d.com/api/order/cancelExternalOrder?id={order_id}&typename=system"
response = requests.get(url)
response = response.json()
if response['code'] != 1000:
continue
print(f'取消订单{order_id}成功')
return
for order_id in order_ids: for order_id in order_ids:
print(order_id) print(order_id)
#url 请求 #url 请求

Loading…
Cancel
Save