diff --git a/blender/build_resize_model.py b/blender/build_resize_model.py index 19b3fe8..1557c8e 100644 --- a/blender/build_resize_model.py +++ b/blender/build_resize_model.py @@ -89,8 +89,8 @@ def imagePiex(filePath,piex): def main(): start = time.time() - get_printsize_url = 'https://mp.gray.api.suwa3d.com/api/printOrder/infoByOrderId' - upload_obj_volume_url = 'https://mp.gray.api.suwa3d.com/api/physical/add' # ?pid=1&order_id=1&faces=1&volume=1 + get_printsize_url = 'https://mp.api.suwa3d.com/api/printOrder/infoByOrderId' + upload_obj_volume_url = 'https://mp.api.suwa3d.com/api/physical/add' # ?pid=1&order_id=1&faces=1&volume=1 print(f'{get_printsize_url}?order_id={orderId}') res = requests.get(f'{get_printsize_url}?id={orderId}') diff --git a/blender/fill_dm_code_new.py b/blender/fill_dm_code_new.py index e8f2789..07c6243 100644 --- a/blender/fill_dm_code_new.py +++ b/blender/fill_dm_code_new.py @@ -18,7 +18,7 @@ enable('eyek_addon') #查询影棚ID def getPSid(pid): - res = requests.get("https://mp.gray.api.suwa3d.com/api/customerP3dLog/photoStudio",params={"pid":pid}) + res = requests.get("https://mp.api.suwa3d.com/api/customerP3dLog/photoStudio",params={"pid":pid}) res = json.loads(res.text) return str(res['data']) @@ -86,11 +86,12 @@ def down_obj_fromoss(pid, print_type=1, order_id=None): shutil.rmtree(path, ignore_errors=True) os.makedirs(path) - prefix = f'objs/print/{pid}/' + prefix = f'objs/print/{pid}' #根据order_id 获取文件在 oss 上的存储路径 if order_id is not None: - tempURL = "https://mp.gray.api.suwa3d.com/api/order/getOssSuffixByOrderId?orderId="+str(order_id) + tempURL = "https://mp.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id="+str(order_id) res = requests.get(tempURL) + print("ossPath res",res.json()) resCode = res.json()['code'] if int(resCode) != 1000: return -1 @@ -98,6 +99,9 @@ def down_obj_fromoss(pid, print_type=1, order_id=None): if res.json()['data'] != "": prefix = f'objs/print/{pid}/{res.json()["data"]}/{str(order_id)}/' + + print("最终的prefix",prefix) + # 下载分2种情况,一种是第一次打印,下载标准{pid}.obj,{pid}.mtl,{pid}Tex1.jpg,另一种是重打或加打,obj文件名可以从oss上任意获取一个,但是mtl和jpg文件名是固定的 res = oss_client.get_object_to_file(f'{prefix}/{pid}.mtl', os.path.join(path, f'{pid}.mtl')) last_modified = oss_client.get_object_meta(f"{prefix}/{pid}.mtl").last_modified @@ -157,7 +161,7 @@ def find_obj(pid, order_id): if f'{pid}.obj' in filename: find = True #进行图片分辨率的调整 - # get_printsize_url = 'https://mp.gray.api.suwa3d.com/api/printOrder/info' + # get_printsize_url = 'https://mp.api.suwa3d.com/api/printOrder/info' # res = requests.get(f'{get_printsize_url}?id={order_id}') # print('获取订单信息:', res.text) # if res.status_code == 200: @@ -455,7 +459,7 @@ def getInfoByPrintId(print_id): #判断是否包含 不存在 if tempMesg == "打印订单不存在": print(f"打印ID{print_id}打印订单不存在,跳过") - # res = requests.get(f'https://mp.gray.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') + # res = requests.get(f'https://mp.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') #os.system(f'blender -b -P fill_dm_code.py') return False @@ -494,7 +498,7 @@ def getQrPosition(print_id,pid,order_id): #跳过该笔订单 print(f"pid={pid},打印id={print_id} order_id={order_id},重新获取qr_position 为空,跳过脚底板的处理,执行下一笔任务") #移除该脚底板的面积处理 - res = requests.get(f'https://mp.gray.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') + res = requests.get(f'https://mp.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') return False else: qr_position = json.loads(qr_position) @@ -552,7 +556,7 @@ def main(workdir, r, print_id): if not os.path.exists(qr_path): #移除该脚底板的面积处理 print(f"pid={pid},打印id={print_id} order_id={order_id},生成的二维码为空,跳过脚底板的处理,执行下一笔任务") - res = requests.get(f'https://mp.gray.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') + res = requests.get(f'https://mp.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') #os.system(f'blender -b -P fill_dm_code.py') return @@ -597,7 +601,7 @@ def main(workdir, r, print_id): #判断是否存在 jpg_path,不存在就执行下一个任务 if not os.path.exists(jpg_path): #移除该脚底板的面积处理 - res = requests.get(f'https://mp.gray.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') + res = requests.get(f'https://mp.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') #os.system(f'blender -b -P fill_dm_code.py') bpy.ops.wm.quit_blender() return @@ -616,7 +620,7 @@ def main(workdir, r, print_id): #判断qr_path是否存在,不存在就执行下一个任务 if not os.path.exists(qr_path): #移除该脚底板的面积处理 - res = requests.get(f'https://mp.gray.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') + res = requests.get(f'https://mp.api.suwa3d.com/api/footCode/deleteByPid?pid={pid}') #os.system(f'blender -b -P fill_dm_code.py') bpy.ops.wm.quit_blender() return @@ -766,10 +770,10 @@ if __name__ == '__main__': low_y_limit = 25000 high_y_limit = 13000 - get_qr_position_url = 'https://mp.gray.api.suwa3d.com/api/printOrder/getFootCodePositionData' - upload_qr_position_url = 'https://mp.gray.api.suwa3d.com/api/printOrder/updateFootCodeStatus' - get_pid_by_printid_url = 'https://mp.gray.api.suwa3d.com/api/printOrder/getPidByPrintId' - get_short_url_by_print_id = 'https://mp.gray.api.suwa3d.com/api/footCode/qrcode' + get_qr_position_url = 'https://mp.api.suwa3d.com/api/printOrder/getFootCodePositionData' + upload_qr_position_url = 'https://mp.api.suwa3d.com/api/printOrder/updateFootCodeStatus' + get_pid_by_printid_url = 'https://mp.api.suwa3d.com/api/printOrder/getPidByPrintId' + get_short_url_by_print_id = 'https://mp.api.suwa3d.com/api/footCode/qrcode' # get_qr_position_url = 'http://172.31.1.254:8199/api/printOrder/getFootCodePositionData' # upload_qr_position_url = 'http://172.31.1.254:8199/api/printOrder/updateFootCodeStatus' # get_pid_by_printid_url = 'http://172.31.1.254:8199/api/printOrder/getPidByPrintId' diff --git a/build_print_obj.py b/build_print_obj.py index 1c073cc..53967f8 100644 --- a/build_print_obj.py +++ b/build_print_obj.py @@ -63,7 +63,7 @@ def down_obj_fromoss(pid, print_type=1, order_id=None,download_flag="print_build prefix = f'objs/print/{pid}/' #根据order_id 获取文件在 oss 上的存储路径 if order_id is not None: - tempURL = "https://mp.gray.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id="+str(order_id) + tempURL = "https://mp.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id="+str(order_id) print(tempURL) res = requests.get(tempURL) print(res.json()) @@ -160,7 +160,7 @@ def down_obj_fromoss(pid, print_type=1, order_id=None,download_flag="print_build # time.sleep(10) #根据pid获取orderId def getPidFromOrderId(orderId): - getPidFromOrderId_url = 'https://mp.gray.api.suwa3d.com/api/printOrder/infoByOrderId' + getPidFromOrderId_url = 'https://mp.api.suwa3d.com/api/printOrder/infoByOrderId' print(f'{getPidFromOrderId_url}?id={orderId}') res = requests.get(f'{getPidFromOrderId_url}?id={orderId}') resCode = res.json()['code'] @@ -229,7 +229,7 @@ def make3d4print_task(r): #根据 buy_type 判断 是否是冰箱贴 或者徽章 buyType = str(res['buy_type']) - if buyType == "2" or buyType == "3" or buyType == "4": + if buyType == "2" or buyType == "3": #or buyType == "4" 小尺寸需要缩放 #塞入到no_resize 队列 r.lpush("model:noresize", orderId) return @@ -381,12 +381,12 @@ if __name__ == '__main__': Endpoint = 'oss-cn-shanghai.aliyuncs.com' Bucket = 'suwa3d-securedata' oss_client = oss2.Bucket(oss2.Auth(AccessKeyId, AccessKeySecret), Endpoint, Bucket) - update_check_url = 'https://mp.gray.api.suwa3d.com/api/customerP3dLog/updateStatusToWaitingPlatformCheckingStatus' - update_team_check_url = 'https://mp.gray.api.suwa3d.com/api/customerP3dLog/updateStatusToWaitingTeamCheckingStatus' - update_status_printstatus_url = 'https://mp.gray.api.suwa3d.com/api/customerP3dLog/updateBuildPrintModelStatus' - update_makeprintobj_status_url = 'https://mp.gray.api.suwa3d.com/api/printOrder/updateMakePrintObjSucceed' - getRepairInfo_url = 'https://repair.gray.api.suwa3d.com/api/modelRepairOrder/teamCheckGLBInfo' - update_repair_status_url = 'https://repair.gray.api.suwa3d.com/api/modelRepairOrder/updateStatusToWaitingTeamCheckingStatus' + update_check_url = 'https://mp.api.suwa3d.com/api/customerP3dLog/updateStatusToWaitingPlatformCheckingStatus' + update_team_check_url = 'https://mp.api.suwa3d.com/api/customerP3dLog/updateStatusToWaitingTeamCheckingStatus' + update_status_printstatus_url = 'https://mp.api.suwa3d.com/api/customerP3dLog/updateBuildPrintModelStatus' + update_makeprintobj_status_url = 'https://mp.api.suwa3d.com/api/printOrder/updateMakePrintObjSucceed' + getRepairInfo_url = 'https://repair.api.suwa3d.com/api/modelRepairOrder/teamCheckGLBInfo' + update_repair_status_url = 'https://repair.api.suwa3d.com/api/modelRepairOrder/updateStatusToWaitingTeamCheckingStatus' if platform.system() == 'Windows': workdir = 'E:\\' else: diff --git a/no_resize_new.py b/no_resize_new.py new file mode 100644 index 0000000..cd4d5ae --- /dev/null +++ b/no_resize_new.py @@ -0,0 +1,252 @@ +from ctypes import util +import os, oss2, time, redis, requests, shutil, sys, subprocess, json, platform,random +from PIL import Image, ImageDraw, ImageFont +from retrying import retry +import atexit,platform +import get_preview_image +# if platform.system() == 'Windows': +# sys.path.append('libs\\') +sys.path.append('/home/acprint/code/libs/') +import common + +def create_redis_connection(): + """创建 Redis 连接,若连接失败则重试""" + while True: + try: + r = redis.Redis(host="106.14.158.208", password="kcV2000", port=6379, db=6) + # 尝试进行一次操作,检查连接是否有效 + r.ping() # ping 操作是一个简单的连接测试 + print("Redis连接成功!") + return r + except ConnectionError: + print("Redis连接失败,正在重试...") + time.sleep(5) + + +def main(r): + while True: + try: + #构建打印文件 + make3d4print_task(r) + except Exception as e: + print(f'出现异常:{e}') + time.sleep(15) + r = create_redis_connection() + continue + +#根据pid获取orderId +def getPidFromOrderId(orderId): + getPidFromOrderId_url = 'https://mp.api.suwa3d.com/api/printOrder/infoByOrderId' + print(f'{getPidFromOrderId_url}?id={orderId}') + res = requests.get(f'{getPidFromOrderId_url}?id={orderId}') + resCode = res.json()['code'] + if int(resCode) != 1000: + return -1 + print(res.text) + return res.json()['data'] + +def down_obj_fromoss(pid, print_type=1, order_id=None,download_flag="print_build"): + # print_type:// 打印状态 1:正常打印 2:重打 3:加打,4: 样品 + print('开始下载obj文件...' , pid) + + if not order_id is None: + path = os.path.join(workdir, 'print', f'{pid}_{order_id}') + + if not os.path.exists(path): os.makedirs(path) + + # 根据前缀获取文件列表 + prefix = f'objs/print/{pid}/' + #根据order_id 获取文件在 oss 上的存储路径 + if order_id is not None: + tempURL = "https://mp.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id="+str(order_id) + res = requests.get(tempURL) + resCode = res.json()['code'] + if int(resCode) != 1000: + return -1 + print(res.text) + if res.json()['data'] != "": + prefix = f'objs/print/{pid}/{res.json()["data"]}/{order_id}' + + print(f"prefix ======= {prefix}") + filelist = oss2.ObjectIteratorV2(oss_client, prefix=prefix) + find = False + findTex1Jpg = False + for file in filelist: + filename = file.key.split('/')[-1] + if filename == '': continue + if filename.endswith(f'{pid}.obj'): + find = True + + if download_flag == "print_build": + if filename != str(pid)+".obj" and filename != str(pid)+".mtl" and filename != str(pid)+"Tex1.jpg": + continue + localfile = os.path.join(path, filename) + res = oss_client.get_object_to_file(file.key, localfile) + print(f'下载文件:{file.key},状态:{res.status}') + + if not find: + filelist = oss2.ObjectIteratorV2(oss_client, prefix=prefix) + for file in filelist: + filename = file.key.split('/')[-1] + if filename == '': continue + if filename.endswith(f'.obj'): + find = True + + # if download_flag == "print_build": + # if filename != str(pid)+".obj" and filename != str(pid)+".mtl" and filename != str(pid)+"Tex1.jpg": + # continue + localfile = os.path.join(path, filename) + res = oss_client.get_object_to_file(file.key, localfile) + print(f'下载文件:{file.key},状态:{res.status}') + break + + if find: + os.rename(localfile, os.path.join(path,f"{pid}.obj")) + #重命名文件 + + #判断是否有Tex1.jpg + if not os.path.exists(os.path.join(path,f"{pid}Tex1.jpg")): + filelist = oss2.ObjectIteratorV2(oss_client, prefix=prefix) + for file in filelist: + filename = file.key.split('/')[-1] + if filename == '': continue + if filename.endswith(f'{pid}.jpg'): + findTex1Jpg = True + + + localfile = os.path.join(path, filename) + res = oss_client.get_object_to_file(file.key, localfile) + print(f'下载文件:{file.key},状态:{res.status}') + break + + if findTex1Jpg: + os.rename(localfile, os.path.join(path,f"{pid}Tex1.jpg")) + #重命名文件 + +def delete_files_in_directory(directory): + for file_name in os.listdir(directory): + file_path = os.path.join(directory, file_name) + try: + if os.path.isfile(file_path): + os.remove(file_path) + print(f"Deleted: {file_path}") + except Exception as e: + print(f"Error deleting {file_path}: {e}") + + +def make3d4print_task(r): + try: + if r.llen('model:noresize') == 0: + print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '暂无可处理的数据') + time.sleep(5) + except Exception as e: + time.sleep(5) + print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), 'redis连接异常,重新连接') + r = redis.Redis(host='106.14.158.208', password='kcV2000', port=6379, db=6) + return + orderId = r.lpop('model:noresize') + if orderId is None: return + + # arrOrder = orderIdStr.decode('utf-8').split('_') + # orderId = arrOrder[0] + # size = arrOrder[1] + + if type(orderId) != str: + orderId = orderId.decode('utf-8') + # orderId = 56077 + res = getPidFromOrderId(orderId) + if res == -1: + print("查询打印订单信息失败,重新开启进程") + #os.system(f'python auto_convert3d.py') + return + pid = str(res['pid']) + if pid == "88985": + return + if pid == "": + return + + down_obj_fromoss(pid, 1, orderId,download_flag="print_build") + + + path = os.path.join(workdir, 'print', f'{pid}_{orderId}') + + #获取打印尺寸信息 + get_printsize_url = 'https://mp.api.suwa3d.com/api/printOrder/infoByOrderId' + res = requests.get(f'{get_printsize_url}?id={orderId}') + print('获取打印尺寸:', res.text) + objName = "" + for f in res.json()['data']['fileList']: + if "undefined" in f: + continue + try: + objName = f + break + except Exception as e: + print("eeee",e) + return + + print("obj尺寸名称",objName) + + + # 如果指定文件夹目标文件存在,则先删除 + if os.path.exists(os.path.join(workdir, f'complate/objs/{pid}/order_{orderId}/')): + delete_files_in_directory(os.path.join(workdir, f'complate/objs/{pid}/order_{orderId}/')) + + for file in os.listdir(path): + # 跳过一些不需要上传的文件 + # if file in [f'{pid}.png',f'{pid}_old.jpg', f'{pid}.obj', f'{pid}_decimate.glb', f'{pid}_decimate.obj', f'{pid}_decimate.mtl', f'{pid}Tex1_decimate.jpg', f'{pid}_original.obj', f'{pid}_original.mtl']: continue + # print("当前目录",os.path.join(path, file)) + + #将文件移动到指定目录 + if not os.path.exists(os.path.join(workdir, f'complate/objs/{pid}/')): + os.makedirs(os.path.join(workdir, f'complate/objs/{pid}/'),mode=0o777, exist_ok=True) + + if not os.path.exists(os.path.join(workdir, f'complate/objs/{pid}/order_{orderId}/')): + os.makedirs(os.path.join(workdir, f'complate/objs/{pid}/order_{orderId}/'),mode=0o777, exist_ok=True) + + shutil.move(os.path.join(path, file), os.path.join(workdir, f'complate/objs/{pid}/order_{orderId}/')) + #判断是否是 Obj, 如果是的话要进行重命名 + try: + if file.endswith(f'{pid}.obj'): + os.rename(os.path.join(workdir, f'complate/objs/{pid}/order_{orderId}/{file}'), os.path.join(workdir, f'complate/objs/{pid}/order_{orderId}/{objName}')) + print("重命名成功") + except Exception as e: + print("AAAAAAAAAAAAAAAA",e) + + + print("BBBBBBBBBBBB") + res = requests.get(f'{update_makeprintobj_status_url}?id={orderId}') + print('更新打印状态:', res.text) + print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), f'orderId:{orderId} pid:{pid} 上传生成的模型 end') + #生成封面图片 + print('小票封面图处理中....') + get_preview_image.createImage(pid) + #os.system(f'python get_preview_image.py {pid}') + print(f"{pid}-已处理结束") + + + + +if __name__ == '__main__': + + # atexit.register(common.notify,"虚拟机,生成打印任务程序停止") + AccessKeyId = 'LTAI5tSReWm8hz7dSYxxth8f' + AccessKeySecret = '8ywTDF9upPAtvgXtLKALY2iMYHIxdS' + Endpoint = 'oss-cn-shanghai.aliyuncs.com' + Bucket = 'suwa3d-securedata' + oss_client = oss2.Bucket(oss2.Auth(AccessKeyId, AccessKeySecret), Endpoint, Bucket) + update_check_url = 'https://mp.api.suwa3d.com/api/customerP3dLog/updateStatusToWaitingPlatformCheckingStatus' + update_team_check_url = 'https://mp.api.suwa3d.com/api/customerP3dLog/updateStatusToWaitingTeamCheckingStatus' + update_status_printstatus_url = 'https://mp.api.suwa3d.com/api/customerP3dLog/updateBuildPrintModelStatus' + update_makeprintobj_status_url = 'https://mp.api.suwa3d.com/api/printOrder/updateMakePrintObjSucceed' + getRepairInfo_url = 'https://repair.api.suwa3d.com/api/modelRepairOrder/teamCheckGLBInfo' + update_repair_status_url = 'https://repair.api.suwa3d.com/api/modelRepairOrder/updateStatusToWaitingTeamCheckingStatus' + if platform.system() == 'Windows': + workdir = 'E:\\' + else: + workdir = '/data/datasets/' + + r = create_redis_connection() + #E:\\complate/objs/147852_54579/ + # os.remove(os.path.join(workdir, f'complate/objs/147852_54579/')) + main(r) \ No newline at end of file