Bladeren bron

临时提交

rambo 3 maanden geleden
bovenliggende
commit
51a9e79c62
3 gewijzigde bestanden met toevoegingen van 517 en 417 verwijderingen
  1. 479 392
      python/api.py
  2. 1 1
      python/config.ini
  3. 37 24
      python/service/base_deal.py

+ 479 - 392
python/api.py

@@ -67,8 +67,10 @@ def parserGoodsDict2Aigc(return_data_check_before_detail):
     return goods_no_dict
 
 
-async def sendAsyncMessage(msg="", goods_arts=[], status="", msg_type="", data=None):
+async def sendAsyncMessage(msg="", goods_arts=[], status="", msg_type="", data=None,progress=None):
     """异步发送消息"""
+    if progress is not None:
+        progress["msg_type"] = msg_type
     data = {
         "code": 0,
         "msg": msg,
@@ -81,6 +83,7 @@ async def sendAsyncMessage(msg="", goods_arts=[], status="", msg_type="", data=N
                 "goods_art_nos": goods_arts,
             }
         ),
+        "progress": None if progress is None else progress,
         "msg_type": msg_type,
     }
     await message_queue.put(data)
@@ -589,11 +592,15 @@ async def handle_detail_background(
     goods_art_no_arrays = params.goods_art_no
     is_check = params.is_check
     is_only_cutout = params.is_only_cutout  # 是否仅抠图
+    online_stores = params.online_stores  # 上传第三方的店铺名称数组
+    is_detail = params.is_detail  # 上传第三方的店铺名称数组
+    is_product_scene = params.is_product_scene  # 上传第三方的店铺名称数组
+    is_upper_footer = params.is_upper_footer  # 上传第三方的店铺名称数组
     if is_only_cutout == 1:
         # 如果是仅抠图模式,避免进入到excel模式
         params.excel_path = ""
-    if params.excel_path != "" and params.excel_path != None:
-        return await fromExcelHandler(params)
+    # 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()))
@@ -642,16 +649,24 @@ async def handle_detail_background(
                     raise UnicornException(path)
     except Exception as e:
         raise UnicornException(str(e))
+    progress = [{"msg_type":"segment_progress","name":"抠图","status":"等待处理","current":0,"total":0,"error":0}]
+    if is_product_scene == 1:
+        progress.append({"msg_type":"scene_progress","name":"场景图","status":"等待处理","current":0,"total":0,"error":0})
+    if is_upper_footer == 1:
+        progress.append({"msg_type":"upper_footer_progress","name":"模特图","status":"等待处理","current":0,"total":0,"error":0})
+    if is_detail==1 or (params.excel_path != "" and params.excel_path != None):
+        progress.append({"msg_type":"detail_progress","name":"详情页(详情页切片、详情页拼接、详情页生成完成)","status":"等待处理","current":0,"total":0,"error":0})
+    if len(online_stores) > 0:
+        progress.append({"msg_type":"upload_goods_progress","name":"上传第三方商品","status":"等待处理","current":0,"total":0,"error":0})
     if is_check == 1:
         return {
             "code": 0,
             "msg": "检测通过",
-            "data": None,
+            "data": {"progress":progress},
         }
     asyncio.create_task(process_handle_detail(request, params))
     return {"code": 0, "msg": "任务已提交后台处理", "data": {"status": "processing"}}
 
-
 async def process_handle_detail(request: Request, params: HandlerDetail):
     obj = None
     token = "Bearer " + params.token
@@ -674,306 +689,70 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
         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(
-                    f"商品货号【{goods_art_no}】在商品档案资料中不存在,请检查货号是否正确"
-                )
-            if is_only_cutout != 1:
-                detail_counts = len(params.template_image_order.split(","))
-                image_counts = len(images)
-                if image_counts < detail_counts:
+    else:
+        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(
-                        f"货号:[{goods_art_no}],实际照片数量:{image_counts}张,小于详情图要求数量:{detail_counts}张"
+                        f"商品货号【{goods_art_no}】在商品档案资料中不存在,请检查货号是否正确"
                     )
-            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:
+                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}】存在没有拍摄完成的图片,请重拍或删除后重试"
+                            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)
-    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:
-    temp_class = {}
-    temp_name_list = []
-    for tempItem in params.temp_list:
-        temp_class[tempItem.template_id] = tempItem.template_local_classes
-        temp_name_list.append(tempItem.template_id)
-    cutOutMode = (
-        "1"
-        if settings.getSysConfigs("other_configs", "cutout_mode", "普通抠图")
-        == "普通抠图"
-        else "2"
-    )
-    config_data = {
-        "image_dir": limit_path,
-        "image_order": (
-            "俯视,侧视,后跟,鞋底,内里,组合,组合2,组合3,组合4,组合5"
-            if params.template_image_order == None or params.template_image_order == ""
-            else params.template_image_order
-        ),
-        "goods_art_no": "",
-        "goods_art_nos": goods_art_no_arrays,
-        "is_check_number": False,
-        "resize_image_view": "后跟",
-        "cutout_mode": cutOutMode,
-        "logo_path": params.logo_path,
-        "special_goods_art_no_folder_line": "",
-        "is_use_excel": False,  # 是否使用excel
-        "excel_path": "",  # excel路径
-        "is_check_color_is_all": False,
-        "cutout_is_pass": True,
-        "assigned_page_dict": {},
-        "detail_is_pass": True,
-        "upload_is_pass": False,
-        "upload_is_enable": settings.IS_UPLOAD_HLM,  # 是否上传到惠利玛商品库,通过config.ini得is_upload开启
-        "is_filter": False,
-        "temp_class": temp_class,
-        "temp_name": params.temp_name,
-        "temp_name_list": temp_name_list,
-        "target_error_folder": f"{limit_path}/软件-生成详情错误",
-        "success_handler": [],
-    }
-    print("image_dir=====>>>>>", config_data["image_dir"])
-    # 动态导入类
-    temp_class_dict = {}
-    for key, class_path in config_data["temp_class"].items():
-        module_path, class_name = class_path.rsplit(".", 1)
-        module = importlib.import_module(module_path)
-        cls = getattr(module, class_name)
-        temp_class_dict[key] = cls
-
-    config_data["temp_class"] = temp_class_dict
-    return_data = run_main.check_before_cutout(config_data)
-    cutout_res = run_main.check_for_cutout_image_first_call_back(return_data)
-    check_for_detail_first_res = None
-    if cutout_res == True:
-        sys_path = format(os.getcwd()).replace("\\", "/")
-        handler_result_folder = f"{sys_path}/{limit_path}"
-        for goods_art_item in goods_art_no_arrays:
+                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": goods_art_item,
-                    "success": True,
-                    "info": "处理成功",
-                }
-            )
-    if is_only_cutout == 1:
-        # return {
-        #     "code": 0,
-        #     "msg": "",
-        #     "data": {"output_folder": handler_result_folder, "list": handler_result},
-        # }
-        await sendAsyncMessage(
-            msg="处理结束",
-            data={"output_folder": handler_result_folder, "list": handler_result},
-            status="处理结束",
-            msg_type="detail_result_progress",
-        )
-        return True
-
-    try:
-        if is_product_scene == 1:
-            if product_scene_prompt == "" or product_scene_prompt == None:
-                raise UnicornException("请填写场景描述")
-        if is_upper_footer == 1:
-            if upper_footer_params == {} or upper_footer_params == None:
-                raise UnicornException("请选择模特")
-            man_id = upper_footer_params.get("man_id")
-            if not man_id:
-                raise UnicornException("请选择男模特")
-            women_id = upper_footer_params.get("women_id")
-            if not women_id:
-                raise UnicornException("请选择女模特")
-        return_data_check_before_detail = run_main.check_before_detail(config_data)
-        print("报错前返回的结果数据", return_data_check_before_detail)
-        if is_product_scene == 1:
-            goods_dict = parserGoodsDict2Aigc(return_data_check_before_detail)
-            new_goods_dict = {}
-            await sendAsyncMessage(
-                msg="开始处理场景图",
-                goods_arts=[goods_art_no for goods_art_no in goods_dict.keys()],
-                status="开始处理",
-                msg_type="scene_progress",
+                {"goods_art_no": "", "success": False, "info": str(e.msg)}
             )
-            for goods_art_no in goods_dict.keys():
-                print("处理场景图", goods_art_no)
-                goods_art_dict_info = goods_dict[goods_art_no]
-                first_goods_art_no_info = goods_art_dict_info.get("货号资料", [])[0]
-                first_pics = first_goods_art_no_info.get("pics")
-                ceshi_image_path = first_pics.get("侧视-抠图")
-                save_root_path = ceshi_image_path.split("阴影图处理")[0]
-                save_image_path = f"{save_root_path}场景图.jpg"
-                if os.path.isfile(save_image_path):
-                    goods_art_dict_info["场景图"] = save_image_path
-                    new_goods_dict[goods_art_no] = goods_art_dict_info
-                    continue
-                aigc_clazz.center_paste_image(ceshi_image_path, save_image_path)
-                try:
-                    image_path = aigc_clazz.generateProductScene(
-                        save_image_path, product_scene_prompt, save_image_path
-                    )
-                    # image_path = aigc_clazz.generateProductSceneQW(
-                    #     save_image_path, product_scene_prompt, save_image_path
-                    # )
-                    goods_art_dict_info["场景图"] = image_path
-                    new_goods_dict[goods_art_no] = goods_art_dict_info
-                    handler_result.append(
-                        {
-                            "goods_art_no": goods_art_no,
-                            "success": True,
-                            "info": "场景图处理成功",
-                        }
-                    )
-                    await sendAsyncMessage(
-                        msg="场景图处理完成",
-                        goods_arts=[goods_art_no],
-                        status="场景图处理完成",
-                        msg_type="scene_progress",
-                    )
-                except Exception as e:
-                    os.remove(save_image_path)
-                    handler_result.append(
-                        {
-                            "goods_art_no": goods_art_no,
-                            "success": False,
-                            "info": f"场景图处理失败:{e}",
-                        }
-                    )
-                    await sendAsyncMessage(
-                        msg="场景图处理失败",
-                        goods_arts=[goods_art_no],
-                        status="场景图处理失败",
-                        msg_type="scene_progress",
-                    )
-            if new_goods_dict is not None or new_goods_dict != {}:
-                return_data_check_before_detail["data"][
-                    "goods_no_dict"
-                ] = new_goods_dict
-        if is_upper_footer == 1:
-            goods_dict = parserGoodsDict2Aigc(return_data_check_before_detail)
-            new_goods_dict = {}
+            print(f"UnicornException 生成错误信息:{e}")
             await sendAsyncMessage(
-                msg="开始处理模特图",
-                goods_arts=list(goods_dict.keys()),
-                status="开始处理模特图",
-                msg_type="upper_footer_progress",
+                msg="处理结束",
+                data={"output_folder": handler_result_folder, "list": handler_result},
+                status="处理结束",
+                msg_type="detail_result_progress",
             )
-            for goods_art_no in goods_dict.keys():
-                goods_art_dict_info = goods_dict[goods_art_no]
-                first_goods_art_no_info = goods_art_dict_info.get("货号资料", [])[0]
-                first_pics = first_goods_art_no_info.get("pics")
-                gender = goods_art_dict_info.get("性别")
-                model_id = man_id if "男" in gender else women_id
-                ceshi_image_path = first_pics.get("侧视-抠图")
-                save_root_path = ceshi_image_path.split("阴影图处理")[0]
-                save_image_path = f"{save_root_path}模特图.jpg"
-                if os.path.isfile(save_image_path):
-                    goods_art_dict_info["模特图"] = save_image_path
-                    new_goods_dict[goods_art_no] = goods_art_dict_info
-                    continue
-                shutil.copy(ceshi_image_path, save_image_path)
-                try:
-                    image_path = aigc_clazz.generateUpperShoes(
-                        save_image_path, model_id, save_image_path
-                    )
-                    # image_path = aigc_clazz.generateModelShoesQW(
-                    #     save_image_path, model_id, save_image_path
-                    # )
-                    goods_art_dict_info["模特图"] = image_path
-                    new_goods_dict[goods_art_no] = goods_art_dict_info
-                    handler_result.append(
-                        {
-                            "goods_art_no": goods_art_no,
-                            "success": True,
-                            "info": "模特图处理成功",
-                        }
-                    )
-                    await sendAsyncMessage(
-                        msg="模特图处理成功",
-                        goods_arts=[goods_art_no],
-                        status="模特图处理成功",
-                        msg_type="upper_footer_progress",
-                    )
-                except Exception as e:
-                    os.remove(save_image_path)
-                    handler_result.append(
-                        {
-                            "goods_art_no": goods_art_no,
-                            "success": False,
-                            "info": f"模特图处理失败:{e}",
-                        }
-                    )
-                    await sendAsyncMessage(
-                        msg="模特图处理失败",
-                        goods_arts=[goods_art_no],
-                        status="模特图处理失败",
-                        msg_type="upper_footer_progress",
-                    )
-            if new_goods_dict is not None or new_goods_dict != {}:
-                return_data_check_before_detail["data"][
-                    "goods_no_dict"
-                ] = new_goods_dict
-        if is_detail == 0:
-            # return {
-            #     "code": 0,
-            #     "msg": "",
-            #     "data": {
-            #         "output_folder": handler_result_folder,
-            #         "list": handler_result,
-            #     },
-            # }
+            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},
@@ -981,113 +760,421 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
                 msg_type="detail_result_progress",
             )
             return True
-        await sendAsyncMessage(
-            msg="开始处理详情页",
-            goods_arts=[],
-            status="开始处理详情页",
-            msg_type="detail_progress",
-        )
-        check_for_detail_first_res = run_main.check_for_detail_first_call_back(
-            return_data_check_before_detail
+        # try:
+        temp_class = {}
+        temp_name_list = []
+        for tempItem in params.temp_list:
+            temp_class[tempItem.template_id] = tempItem.template_local_classes
+            temp_name_list.append(tempItem.template_id)
+        cutOutMode = (
+            "1"
+            if settings.getSysConfigs("other_configs", "cutout_mode", "普通抠图")
+            == "普通抠图"
+            else "2"
         )
-        if isinstance(check_for_detail_first_res, partial):
-            result = check_for_detail_first_res()
-            try:
-                config_data = result["config_data"]
-            except:
-                config_data = result
-        if config_data["sign_text"] == "已结束详情处理":
+        config_data = {
+            "image_dir": limit_path,
+            "image_order": (
+                "俯视,侧视,后跟,鞋底,内里,组合,组合2,组合3,组合4,组合5"
+                if params.template_image_order == None or params.template_image_order == ""
+                else params.template_image_order
+            ),
+            "goods_art_no": "",
+            "goods_art_nos": goods_art_no_arrays,
+            "is_check_number": False,
+            "resize_image_view": "后跟",
+            "cutout_mode": cutOutMode,
+            "logo_path": params.logo_path,
+            "special_goods_art_no_folder_line": "",
+            "is_use_excel": False,  # 是否使用excel
+            "excel_path": "",  # excel路径
+            "is_check_color_is_all": False,
+            "cutout_is_pass": True,
+            "assigned_page_dict": {},
+            "detail_is_pass": True,
+            "upload_is_pass": False,
+            "upload_is_enable": settings.IS_UPLOAD_HLM,  # 是否上传到惠利玛商品库,通过config.ini得is_upload开启
+            "is_filter": False,
+            "temp_class": temp_class,
+            "temp_name": params.temp_name,
+            "temp_name_list": temp_name_list,
+            "target_error_folder": f"{limit_path}/软件-生成详情错误",
+            "success_handler": [],
+        }
+        print("image_dir=====>>>>>", config_data["image_dir"])
+        # 动态导入类
+        temp_class_dict = {}
+        for key, class_path in config_data["temp_class"].items():
+            module_path, class_name = class_path.rsplit(".", 1)
+            module = importlib.import_module(module_path)
+            cls = getattr(module, class_name)
+            temp_class_dict[key] = cls
+
+        config_data["temp_class"] = temp_class_dict
+        return_data = run_main.check_before_cutout(config_data)
+        cutout_res = run_main.check_for_cutout_image_first_call_back(return_data)
+        check_for_detail_first_res = None
+        if cutout_res == True:
+            sys_path = format(os.getcwd()).replace("\\", "/")
+            handler_result_folder = f"{sys_path}/{limit_path}"
+            for goods_art_item in goods_art_no_arrays:
+                handler_result.append(
+                    {
+                        "goods_art_no": goods_art_item,
+                        "success": True,
+                        "info": "处理成功",
+                    }
+                )
+        if len(move_folder_array.keys()) == len(goods_art_no_arrays):
+            progress = {"status":"抠图完成",
+                    "current":len(goods_art_no_arrays),
+                    "total":len(goods_art_no_arrays),
+                    "error":0}
             await sendAsyncMessage(
-                msg="详情页处理结束",
-                goods_arts=[],
-                status="详情页处理结束",
-                msg_type="detail_progress",
+                msg="抠图完成",
+                data={"output_folder": handler_result_folder, "list": handler_result},
+                status="抠图完成",
+                msg_type="segment_progress",
+                progress=progress
             )
-            print("config_data", config_data)
-            out_put_dir = config_data.get("out_put_dir")
-            if out_put_dir == None:
-                handler_result_folder = ""
-                if len(config_data["success_handler"]) > 0:
-                    for good_art in config_data["success_handler"]:
-                        handler_result.append(good_art)
-                else:
-                    for good_art in goods_art_no_arrays:
-                        handler_result.append(
-                            {
-                                "goods_art_no": good_art,
-                                "success": False,
-                                "info": "处理失败",
-                            }
-                        )
+        if is_only_cutout == 1:
+            await sendAsyncMessage(
+                msg="处理结束",
+                data={"output_folder": handler_result_folder, "list": handler_result},
+                status="处理结束",
+                msg_type="detail_result_progress",
+            )
+            return True
+
+        try:
+            if is_product_scene == 1:
+                if product_scene_prompt == "" or product_scene_prompt == None:
+                    raise UnicornException("请填写场景描述")
+            if is_upper_footer == 1:
+                if upper_footer_params == {} or upper_footer_params == None:
+                    raise UnicornException("请选择模特")
+                man_id = upper_footer_params.get("man_id")
+                if not man_id:
+                    raise UnicornException("请选择男模特")
+                women_id = upper_footer_params.get("women_id")
+                if not women_id:
+                    raise UnicornException("请选择女模特")
+            return_data_check_before_detail = run_main.check_before_detail(config_data)
+            success_handler =  return_data_check_before_detail.get("data").get("config_data").get("success_handler",[])
+            failed_items = [item for item in success_handler if item.get('success') == False]
+            print("failed_items",failed_items)
+            if len(failed_items) > 0:
+                    await sendAsyncMessage(
+                        msg="处理结束",
+                        data={"output_folder": handler_result_folder, "list": failed_items},
+                        status="处理结束",
+                        msg_type="detail_result_progress",
+                    )
+            if len(failed_items)!=0 and len(failed_items) == len(success_handler):
+                    # 如果全部错误  直接终止
+                    return True
             else:
-                out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace(
-                    "\\", "/"
-                )
-                handler_result_folder = os.path.dirname(out_put_dir_path)
-                if len(config_data["success_handler"]) == 0:
-                    for good_art in goods_art_no_arrays:
-                        handler_result.append(
-                            {
-                                "goods_art_no": good_art,
-                                "success": False,
-                                "info": "处理失败",
-                            }
-                        )
-                else:
-                    if len(online_stores) > 0:
-                        result_goods_no_dict = return_data_check_before_detail["data"][
+                if is_product_scene == 1:
+                    goods_dict = parserGoodsDict2Aigc(return_data_check_before_detail)
+                    new_goods_dict = {}
+                    product_scene_total_progress = len(goods_dict.keys())
+                    product_scene_finish_progress = 0
+                    product_scene_error_progress = 0
+                    product_scene_progress = {"status":"开始处理场景图", "current":product_scene_finish_progress, "total":product_scene_total_progress, "error":product_scene_error_progress}
+                    print("product_scene_progress",goods_dict,product_scene_progress)
+                    await sendAsyncMessage(
+                        msg="开始处理场景图",
+                        goods_arts=[goods_art_no for goods_art_no in goods_dict.keys()],
+                        status="开始处理",
+                        msg_type="scene_progress",
+                        progress=product_scene_progress
+                    )
+                    for goods_art_no in goods_dict.keys():
+                        print("处理场景图", goods_art_no)
+                        goods_art_dict_info = goods_dict[goods_art_no]
+                        first_goods_art_no_info = goods_art_dict_info.get("货号资料", [])[0]
+                        first_pics = first_goods_art_no_info.get("pics")
+                        ceshi_image_path = first_pics.get("侧视-抠图")
+                        save_root_path = ceshi_image_path.split("阴影图处理")[0]
+                        save_image_path = f"{save_root_path}场景图.jpg"
+                        if os.path.isfile(save_image_path):
+                            goods_art_dict_info["场景图"] = save_image_path
+                            new_goods_dict[goods_art_no] = goods_art_dict_info
+                            continue
+                        aigc_clazz.center_paste_image(ceshi_image_path, save_image_path)
+                        try:
+                            image_path = aigc_clazz.generateProductScene(
+                                save_image_path, product_scene_prompt, save_image_path
+                            )
+                            # image_path = aigc_clazz.generateProductSceneQW(
+                            #     save_image_path, product_scene_prompt, save_image_path
+                            # )
+                            goods_art_dict_info["场景图"] = image_path
+                            new_goods_dict[goods_art_no] = goods_art_dict_info
+                            handler_result.append(
+                                {
+                                    "goods_art_no": goods_art_no,
+                                    "success": True,
+                                    "info": "场景图处理成功",
+                                }
+                            )
+                            product_scene_finish_progress+=1
+                            product_scene_progress = {"status":"正在处理场景图", "current":product_scene_finish_progress, "total":product_scene_total_progress, "error":product_scene_error_progress}
+                            await sendAsyncMessage(
+                                msg="场景图处理完成",
+                                goods_arts=[goods_art_no],
+                                status="场景图处理完成",
+                                msg_type="scene_progress",
+                                progress=product_scene_progress
+                            )
+                        except Exception as e:
+                            os.remove(save_image_path)
+                            handler_result.append(
+                                {
+                                    "goods_art_no": goods_art_no,
+                                    "success": False,
+                                    "info": f"场景图处理失败:{e}",
+                                }
+                            )
+                            product_scene_error_progress +=1
+                            product_scene_progress = {"status":"正在处理场景图", "current":product_scene_finish_progress, "total":product_scene_total_progress, "error":product_scene_error_progress}
+                            await sendAsyncMessage(
+                                msg="场景图处理失败",
+                                goods_arts=[goods_art_no],
+                                status="场景图处理失败",
+                                msg_type="scene_progress",
+                                progress=product_scene_progress
+                            )
+                    product_scene_progress = {"status":"正在处理场景图", "current":product_scene_finish_progress, "total":product_scene_total_progress, "error":product_scene_error_progress}
+                    await sendAsyncMessage(
+                                msg="场景图处理结束",
+                                goods_arts=[],
+                                status="场景图处理结束",
+                                msg_type="scene_progress",
+                                progress=product_scene_progress
+                            )
+                    if new_goods_dict is not None or new_goods_dict != {}:
+                        return_data_check_before_detail["data"][
                             "goods_no_dict"
-                        ]
-                        for goods_idx, goods_no_dict in enumerate(
-                            result_goods_no_dict.keys()
-                        ):
-                            all_detail_path_list = config_data["all_detail_path_list"]
-                            for detail_path in all_detail_path_list:
-                                if goods_no_dict in detail_path:
-                                    detail_path_replace = detail_path.replace("\\", "/")
-                                    result_goods_no_dict[goods_no_dict][
-                                        "detail_path"
-                                    ] = f"{detail_path_replace}/详情页.jpg"
-                        await sendAsyncMessage(
-                            msg="开始上传商品数据",
-                            goods_arts=[],
-                            status="开始上传商品数据",
-                            msg_type="upload_goods_progress",
-                        )
+                        ] = new_goods_dict
+                if is_upper_footer == 1:
+                    goods_dict = parserGoodsDict2Aigc(return_data_check_before_detail)
+                    new_goods_dict = {}
+                    upper_footer_total_progress = len(goods_dict.keys())
+                    upper_footer_finish_progress = 0
+                    upper_footer_error_progress = 0
+                    upper_footer_progress = {"status":"开始处理模特图", "current":upper_footer_finish_progress, "total":upper_footer_total_progress, "error":upper_footer_error_progress}
+                    await sendAsyncMessage(
+                        msg="开始处理模特图",
+                        goods_arts=list(goods_dict.keys()),
+                        status="开始处理模特图",
+                        msg_type="upper_footer_progress",
+                        progress=upper_footer_progress
+                    )
+                    for goods_art_no in goods_dict.keys():
+                        goods_art_dict_info = goods_dict[goods_art_no]
+                        first_goods_art_no_info = goods_art_dict_info.get("货号资料", [])[0]
+                        first_pics = first_goods_art_no_info.get("pics")
+                        gender = goods_art_dict_info.get("性别")
+                        model_id = man_id if "男" in gender else women_id
+                        ceshi_image_path = first_pics.get("侧视-抠图")
+                        save_root_path = ceshi_image_path.split("阴影图处理")[0]
+                        save_image_path = f"{save_root_path}模特图.jpg"
+                        if os.path.isfile(save_image_path):
+                            goods_art_dict_info["模特图"] = save_image_path
+                            new_goods_dict[goods_art_no] = goods_art_dict_info
+                            continue
+                        shutil.copy(ceshi_image_path, save_image_path)
                         try:
-                            onlineData.uploadGoods2ThirdParty(
-                                result_goods_no_dict, online_stores=online_stores
+                            image_path = aigc_clazz.generateUpperShoes(
+                                save_image_path, model_id, save_image_path
+                            )
+                            # image_path = aigc_clazz.generateModelShoesQW(
+                            #     save_image_path, model_id, save_image_path
+                            # )
+                            goods_art_dict_info["模特图"] = image_path
+                            new_goods_dict[goods_art_no] = goods_art_dict_info
+                            handler_result.append(
+                                {
+                                    "goods_art_no": goods_art_no,
+                                    "success": True,
+                                    "info": "模特图处理成功",
+                                }
+                            )
+                            upper_footer_finish_progress+=1
+                            upper_footer_progress = {"status":"正在处理模特图", "current":upper_footer_finish_progress, "total":upper_footer_total_progress, "error":upper_footer_error_progress}
+                            await sendAsyncMessage(
+                                msg="模特图处理成功",
+                                goods_arts=[goods_art_no],
+                                status="模特图处理成功",
+                                msg_type="upper_footer_progress",
+                                progress=upper_footer_progress
                             )
                         except Exception as e:
-                            print(f"上传任务出现错误:{e}")
-                        await sendAsyncMessage(
-                            msg="商品上传第三方成功",
-                            goods_arts=[],
-                            status="商品上传第三方成功",
-                            msg_type="upload_goods_progress",
+                            os.remove(save_image_path)
+                            handler_result.append(
+                                {
+                                    "goods_art_no": goods_art_no,
+                                    "success": False,
+                                    "info": f"模特图处理失败:{e}",
+                                }
+                            )
+                            upper_footer_error_progress+=1
+                            upper_footer_progress = {"status":"正在处理模特图", "current":upper_footer_finish_progress, "total":upper_footer_total_progress, "error":upper_footer_error_progress}
+                            await sendAsyncMessage(
+                                msg="模特图处理失败",
+                                goods_arts=[goods_art_no],
+                                status="模特图处理失败",
+                                msg_type="upper_footer_progress",
+                                progress=upper_footer_progress
+                            )
+                    upper_footer_progress = {"status":"模特图处理结束", "current":upper_footer_finish_progress, "total":upper_footer_total_progress, "error":upper_footer_error_progress}
+                    await sendAsyncMessage(
+                                msg="模特图处理结束",
+                                goods_arts=[],
+                                status="模特图处理结束",
+                                msg_type="scene_progress",
+                                progress=upper_footer_progress
+                            )
+                    if new_goods_dict is not None or new_goods_dict != {}:
+                        return_data_check_before_detail["data"][
+                            "goods_no_dict"
+                        ] = new_goods_dict
+                if is_detail == 0:
+                    await sendAsyncMessage(
+                        msg="处理结束",
+                        data={"output_folder": handler_result_folder, "list": handler_result},
+                        status="处理结束",
+                        msg_type="detail_result_progress",
+                    )
+                    return True
+                detail_total_progress = len(goods_dict.keys())
+                detail_finish_progress = 0
+                detail_error_progress = 0
+                detail_progress = {"status":"开始处理详情页", "current":detail_finish_progress, "total":detail_total_progress, "error":detail_error_progress}
+                await sendAsyncMessage(
+                    msg="开始处理详情页",
+                    goods_arts=[],
+                    status="开始处理详情页",
+                    msg_type="detail_progress",
+                    progress=detail_progress
+                )
+                check_for_detail_first_res = run_main.check_for_detail_first_call_back(
+                    return_data_check_before_detail
+                )
+                if isinstance(check_for_detail_first_res, partial):
+                    result = check_for_detail_first_res()
+                    try:
+                        config_data = result["config_data"]
+                    except:
+                        config_data = result
+                if config_data["sign_text"] == "已结束详情处理":
+                    detail_finish_progress = len(config_data["success_handler"])
+                    detail_error_progress = detail_total_progress - detail_finish_progress
+                    detail_progress = {"status":"详情页处理结束", "current":detail_finish_progress, "total":detail_total_progress, "error":detail_error_progress}
+                    await sendAsyncMessage(
+                        msg="详情页处理结束",
+                        goods_arts=[],
+                        status="详情页处理结束",
+                        msg_type="detail_progress",
+                        progress=detail_progress
+                    )
+                    print("config_data", config_data)
+                    out_put_dir = config_data.get("out_put_dir")
+                    if out_put_dir == None:
+                        handler_result_folder = ""
+                        if len(config_data["success_handler"]) > 0:
+                            for good_art in config_data["success_handler"]:
+                                handler_result.append(good_art)
+                        else:
+                            for good_art in goods_art_no_arrays:
+                                handler_result.append(
+                                    {
+                                        "goods_art_no": good_art,
+                                        "success": False,
+                                        "info": "处理失败",
+                                    }
+                                )
+                    else:
+                        out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace(
+                            "\\", "/"
                         )
-                    handler_result = config_data["success_handler"]
-        else:
+                        handler_result_folder = os.path.dirname(out_put_dir_path)
+                        if len(config_data["success_handler"]) == 0:
+                            for good_art in goods_art_no_arrays:
+                                handler_result.append(
+                                    {
+                                        "goods_art_no": good_art,
+                                        "success": False,
+                                        "info": "处理失败",
+                                    }
+                                )
+                        else:
+                            if len(online_stores) > 0:
+                                result_goods_no_dict = return_data_check_before_detail["data"][
+                                    "goods_no_dict"
+                                ]
+                                for goods_idx, goods_no_dict in enumerate(
+                                    result_goods_no_dict.keys()
+                                ):
+                                    all_detail_path_list = config_data["all_detail_path_list"]
+                                    for detail_path in all_detail_path_list:
+                                        if goods_no_dict in detail_path:
+                                            detail_path_replace = detail_path.replace("\\", "/")
+                                            result_goods_no_dict[goods_no_dict][
+                                                "detail_path"
+                                            ] = f"{detail_path_replace}/详情页.jpg"
+                                upload_total_progress = len(goods_dict.keys())
+                                upload_finish_progress = 0
+                                upload_error_progress = 0
+                                upload_progress = {"status":"开始上传商品数据", "current":upload_finish_progress, "total":upload_total_progress, "error":upload_error_progress}
+                                await sendAsyncMessage(
+                                    msg="开始上传商品数据",
+                                    goods_arts=[],
+                                    status="开始上传商品数据",
+                                    msg_type="upload_goods_progress",
+                                    progress=upload_progress
+                                )
+                                try:
+                                    onlineData.uploadGoods2ThirdParty(
+                                        result_goods_no_dict, online_stores=online_stores
+                                    )
+                                except Exception as e:
+                                    upload_error_progress = upload_total_progress
+                                    print(f"上传任务出现错误:{e}")
+                                upload_finish_progress = upload_total_progress
+                                if upload_error_progress > 0:
+                                    upload_finish_progress = 0
+                                upload_progress = {"status":"开始上传商品数据", "current":upload_finish_progress, "total":upload_total_progress, "error":upload_error_progress}
+                                await sendAsyncMessage(
+                                    msg="商品上传第三方成功",
+                                    goods_arts=[],
+                                    status="商品上传第三方成功",
+                                    msg_type="upload_goods_progress",
+                                    progress=upload_progress
+                                )
+                            handler_result = config_data["success_handler"]
+                else:
+                    handler_result.append(
+                        {"goods_art_no": "", "success": False, "info": "处理失败"}
+                    )
+        except UnicornException as e:
+            handler_result_folder = ""
             handler_result.append(
-                {"goods_art_no": "", "success": False, "info": "处理失败"}
+                {"goods_art_no": "", "success": False, "info": str(e.msg)}
             )
-    except UnicornException as e:
-        handler_result_folder = ""
-        handler_result.append(
-            {"goods_art_no": "", "success": False, "info": str(e.msg)}
+            print(f"UnicornException 生成错误信息:{e}")
+        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",
         )
-        print(f"UnicornException 生成错误信息:{e}")
-    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
+        return True
 
 
 @app.get("/get_device_tabs", description="获取可执行程序命令列表")

+ 1 - 1
python/config.ini

@@ -4,7 +4,7 @@ app_name=智慧拍-后端应用
 # 应用版本号
 version=1.0.0
 # 应用host地址
-host=127.0.0.1
+host=10.56.42.45
 # 应用服务启动名称
 app_run=api:app
 # 端口号

+ 37 - 24
python/service/base_deal.py

@@ -24,8 +24,7 @@ import copy, asyncio
 from settings import sendSocketMessage
 from utils.common import message_queue
 
-
-def sendAsyncMessage(msg="", goods_arts=[], status=""):
+def sendAsyncMessage(msg="", goods_arts=[], status="",progress={}):
     """异步发送消息"""
     data = {
         "code": 0,
@@ -34,6 +33,14 @@ def sendAsyncMessage(msg="", goods_arts=[], status=""):
         "data": {
             "status": status,
             "goods_art_nos": goods_arts,
+            "progress":{
+                "msg_type":"segment_progress",
+                "name":"抠图",
+                "status":progress.get("status"),
+                "current":progress.get("current",0),
+                "total":progress.get("total",0),
+                "error":progress.get("error",0)
+            }
         },
         "msg_type": "segment_progress",
     }
@@ -508,8 +515,15 @@ class BaseDealImage(object):
             goods_art_item["folder_name"]
             for goods_art_item in all_goods_art_no_folder_data
         ]
+        total_progress = len(all_goods_art_no_folder_data)
+        finish_progress = 0
+        error_progress = 0
+        progress = {"status":"正在处理",
+                "current":finish_progress,
+                "total":total_progress,
+                "error":error_progress}
         sendAsyncMessage(
-            msg="开始处理抠图", goods_arts=goods_art_nos, status="开始处理"
+            msg="开始处理抠图", goods_arts=goods_art_nos, status="开始处理",progress=progress
         )
         error_goods_art_no_folder = []
         for goods_art_no_folder_data in all_goods_art_no_folder_data:
@@ -525,6 +539,7 @@ class BaseDealImage(object):
                 msg="正在抠图",
                 goods_arts=[goods_art_floder_name],
                 status="处理中",
+                progress=progress
             )
             for pic_file_name in images:
                 if windows:
@@ -572,11 +587,6 @@ class BaseDealImage(object):
                                     callback_func(
                                         "货号图{} 抠图处理超时~".format(file_name)
                                     )
-                                    # sendAsyncMessage(
-                                    #     msg="抠图处理超时",
-                                    #     goods_arts=[file_name],
-                                    #     status="抠图处理超时",
-                                    # )
                                     error_goods_art_no_folder.append(folder_path)
                                     im = None
                                 except BaseException as e:
@@ -586,11 +596,6 @@ class BaseDealImage(object):
                                         )
                                     )
                                     error_goods_art_no_folder.append(folder_path)
-                                    # sendAsyncMessage(
-                                    #     msg=f"抠图处理失败,原因{e}",
-                                    #     goods_arts=[file_name],
-                                    #     status="抠图处理失败",
-                                    # )
                                     im = None
 
                             if not im:
@@ -598,24 +603,20 @@ class BaseDealImage(object):
                                     "货号图{} 抠图处理失败~".format(file_name)
                                 )
                                 error_goods_art_no_folder.append(folder_path)
-                                # sendAsyncMessage(
-                                #     msg=f"抠图处理失败",
-                                #     goods_arts=[file_name],
-                                #     status="抠图处理失败",
-                                # )
                                 continue
                             else:
-                                # sendAsyncMessage(
-                                #     msg=f"完成抠图处理",
-                                #     goods_arts=[file_name],
-                                #     status="完成抠图处理",
-                                # )
                                 callback_func("货号图{} 抠图完成~".format(file_name))
             if goods_art_floder_name not in error_goods_art_no_folder:
+                finish_progress+=1
+                progress = {"status":"正在处理",
+                "current":finish_progress,
+                "total":total_progress,
+                "error":error_progress}
                 sendAsyncMessage(
                     msg="抠图完成",
                     goods_arts=[goods_art_floder_name],
                     status="抠图完成",
+                    progress=progress
                 )
             if cutout_mode == "2":
                 dealCutout = DealCutout(windows=None, token=self.token)
@@ -630,7 +631,11 @@ class BaseDealImage(object):
                         if len(dealCutout.resultData) != len(cutImageList):
                             error_goods_art_no_folder.append(folder_path)
                         break
-
+        error_progress = len(error_goods_art_no_folder)
+        progress = {"status":"抠图完成",
+                "current":finish_progress,
+                "total":total_progress,
+                "error":error_progress}
         if error_goods_art_no_folder:
             print("以下货号抠图失败~\n {}".format(error_goods_art_no_folder))
             callback_func("以下货号抠图失败~\n {}".format(error_goods_art_no_folder))
@@ -638,14 +643,22 @@ class BaseDealImage(object):
                 msg=f"抠图处理失败",
                 goods_arts=error_goods_art_no_folder,
                 status="抠图处理失败",
+                progress=progress
             )
         else:
             sendAsyncMessage(
                 msg=f"完成抠图处理",
                 goods_arts=goods_art_nos,
                 status="完成抠图处理",
+                progress=progress
             )
             callback_func("完成抠图处理")
+        sendAsyncMessage(
+                    msg="抠图完成",
+                    goods_arts=[],
+                    status="抠图完成",
+                    progress=progress
+                )
 
     def checkCutoutImage(self, image_dir: str, todo_goods_art_no_folder_name_list=None):
         """