|
@@ -347,7 +347,59 @@ def group_by_style_number(data):
|
|
|
async def handle_detail_background(
|
|
async def handle_detail_background(
|
|
|
request: Request, params: HandlerDetail, background_tasks: BackgroundTasks
|
|
request: Request, params: HandlerDetail, background_tasks: BackgroundTasks
|
|
|
):
|
|
):
|
|
|
- # background_tasks.add_task(process_handle_detail, request, params)
|
|
|
|
|
|
|
+ goods_art_no_arrays = params.goods_art_no
|
|
|
|
|
+ is_only_cutout = params.is_only_cutout # 是否仅抠图
|
|
|
|
|
+ if is_only_cutout == 1:
|
|
|
|
|
+ # 如果是仅抠图模式,避免进入到excel模式
|
|
|
|
|
+ params.excel_path = ""
|
|
|
|
|
+ if params.excel_path != "" and params.excel_path != None:
|
|
|
|
|
+ return await fromExcelHandler(params)
|
|
|
|
|
+ path = ""
|
|
|
|
|
+ limit_path = "output/{}".format(
|
|
|
|
|
+ time.strftime("%Y-%m-%d", time.localtime(time.time()))
|
|
|
|
|
+ )
|
|
|
|
|
+ check_path(limit_path)
|
|
|
|
|
+ # 该数组表示是否需要后面的移动文件夹操作,减少重复抠图,提升抠图时间和速度
|
|
|
|
|
+ move_folder_array = check_move_goods_art_no_folder(
|
|
|
|
|
+ "output", goods_art_no_arrays, limit_path
|
|
|
|
|
+ )
|
|
|
|
|
+ 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(
|
|
|
|
|
+ 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:
|
|
|
|
|
+ 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 Exception as e:
|
|
|
|
|
+ raise UnicornException(str(e))
|
|
|
asyncio.create_task(process_handle_detail(request, params))
|
|
asyncio.create_task(process_handle_detail(request, params))
|
|
|
return {"code": 0, "msg": "任务已提交后台处理", "data": {"status": "processing"}}
|
|
return {"code": 0, "msg": "任务已提交后台处理", "data": {"status": "processing"}}
|
|
|
|
|
|