|
@@ -383,40 +383,65 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
|
|
|
move_folder_array = check_move_goods_art_no_folder(
|
|
move_folder_array = check_move_goods_art_no_folder(
|
|
|
"output", goods_art_no_arrays, limit_path
|
|
"output", goods_art_no_arrays, limit_path
|
|
|
)
|
|
)
|
|
|
- for goods_art_no in goods_art_no_arrays:
|
|
|
|
|
- if not goods_art_no:
|
|
|
|
|
- raise UnicornException("货号不能为空")
|
|
|
|
|
- session = SqlQuery()
|
|
|
|
|
- pr = CRUD(PhotoRecord)
|
|
|
|
|
- images = pr.read_all(session, conditions={"goods_art_no": goods_art_no})
|
|
|
|
|
- if not images:
|
|
|
|
|
- raise UnicornException("没有可用货号数据")
|
|
|
|
|
- if is_only_cutout != 1:
|
|
|
|
|
- detail_counts = len(params.template_image_order.split(","))
|
|
|
|
|
- image_counts = len(images)
|
|
|
|
|
- if image_counts < detail_counts:
|
|
|
|
|
- raise UnicornException(
|
|
|
|
|
- f"货号:[{goods_art_no}],实际照片数量:{image_counts}张,小于详情图要求数量:{detail_counts}张"
|
|
|
|
|
- )
|
|
|
|
|
- if move_folder_array.get(goods_art_no) == None:
|
|
|
|
|
- image_dir = "{}/data/".format(os.getcwd()).replace("\\", "/")
|
|
|
|
|
- check_path(image_dir)
|
|
|
|
|
- for idx, itemImg in enumerate(images):
|
|
|
|
|
- if itemImg.image_path == "" or itemImg.image_path == None:
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ for goods_art_no in goods_art_no_arrays:
|
|
|
|
|
+ if not goods_art_no:
|
|
|
|
|
+ raise UnicornException("货号不能为空")
|
|
|
|
|
+ session = SqlQuery()
|
|
|
|
|
+ pr = CRUD(PhotoRecord)
|
|
|
|
|
+ images = pr.read_all(session, conditions={"goods_art_no": goods_art_no})
|
|
|
|
|
+ if not images:
|
|
|
|
|
+ raise UnicornException("没有可用货号数据")
|
|
|
|
|
+ if is_only_cutout != 1:
|
|
|
|
|
+ detail_counts = len(params.template_image_order.split(","))
|
|
|
|
|
+ image_counts = len(images)
|
|
|
|
|
+ if image_counts < detail_counts:
|
|
|
raise UnicornException(
|
|
raise UnicornException(
|
|
|
- f"货号【{goods_art_no}】存在没有拍摄完成的图片,请重拍或删除后重试"
|
|
|
|
|
|
|
+ f"货号:[{goods_art_no}],实际照片数量:{image_counts}张,小于详情图要求数量:{detail_counts}张"
|
|
|
)
|
|
)
|
|
|
- new_file_name = str(itemImg.goods_art_no) + "_" + str(idx) + ".jpg"
|
|
|
|
|
- if not os.path.exists(
|
|
|
|
|
- image_dir + "/" + os.path.basename(new_file_name)
|
|
|
|
|
- ):
|
|
|
|
|
- shutil.copy(itemImg.image_path, image_dir + new_file_name)
|
|
|
|
|
- dealImage = DealImage(image_dir)
|
|
|
|
|
- resFlag, path = dealImage.dealMoveImage(
|
|
|
|
|
- image_dir=image_dir, callback_func=None, goods_art_no=goods_art_no
|
|
|
|
|
- )
|
|
|
|
|
- if not resFlag:
|
|
|
|
|
- raise UnicornException(path)
|
|
|
|
|
|
|
+ if move_folder_array.get(goods_art_no) == None:
|
|
|
|
|
+ image_dir = "{}/data/".format(os.getcwd()).replace("\\", "/")
|
|
|
|
|
+ check_path(image_dir)
|
|
|
|
|
+ for idx, itemImg in enumerate(images):
|
|
|
|
|
+ if itemImg.image_path == "" or itemImg.image_path == None:
|
|
|
|
|
+ raise UnicornException(
|
|
|
|
|
+ f"货号【{goods_art_no}】存在没有拍摄完成的图片,请重拍或删除后重试"
|
|
|
|
|
+ )
|
|
|
|
|
+ new_file_name = str(itemImg.goods_art_no) + "_" + str(idx) + ".jpg"
|
|
|
|
|
+ if not os.path.exists(
|
|
|
|
|
+ image_dir + "/" + os.path.basename(new_file_name)
|
|
|
|
|
+ ):
|
|
|
|
|
+ shutil.copy(itemImg.image_path, image_dir + new_file_name)
|
|
|
|
|
+ dealImage = DealImage(image_dir)
|
|
|
|
|
+ resFlag, path = dealImage.dealMoveImage(
|
|
|
|
|
+ image_dir=image_dir, callback_func=None, goods_art_no=goods_art_no
|
|
|
|
|
+ )
|
|
|
|
|
+ if not resFlag:
|
|
|
|
|
+ raise UnicornException(path)
|
|
|
|
|
+ except UnicornException as e:
|
|
|
|
|
+ handler_result_folder = ""
|
|
|
|
|
+ handler_result.append(
|
|
|
|
|
+ {"goods_art_no": "", "success": False, "info": str(e.msg)}
|
|
|
|
|
+ )
|
|
|
|
|
+ print(f"UnicornException 生成错误信息:{e}")
|
|
|
|
|
+ await sendAsyncMessage(
|
|
|
|
|
+ msg="处理结束",
|
|
|
|
|
+ data={"output_folder": handler_result_folder, "list": handler_result},
|
|
|
|
|
+ status="处理结束",
|
|
|
|
|
+ msg_type="detail_result_progress",
|
|
|
|
|
+ )
|
|
|
|
|
+ return True
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(f"详情图生成错误信息:{e}")
|
|
|
|
|
+ handler_result_folder = ""
|
|
|
|
|
+ handler_result.append({"goods_art_no": "", "success": False, "info": str(e)})
|
|
|
|
|
+ await sendAsyncMessage(
|
|
|
|
|
+ msg="处理结束",
|
|
|
|
|
+ data={"output_folder": handler_result_folder, "list": handler_result},
|
|
|
|
|
+ status="处理结束",
|
|
|
|
|
+ msg_type="detail_result_progress",
|
|
|
|
|
+ )
|
|
|
|
|
+ return True
|
|
|
# try:
|
|
# try:
|
|
|
temp_class = {}
|
|
temp_class = {}
|
|
|
temp_name_list = []
|
|
temp_name_list = []
|