Browse Source

Merge branch 'dev-python'

rambo 5 months ago
parent
commit
aaa58294ec

+ 14 - 4
python/api.py

@@ -88,6 +88,7 @@ async def forwardRequest(request: HlmForwardRequest):
 
 def fromExcelHandler(params: HandlerDetail):
     excel_path = params.excel_path
+    token = "Bearer " + params.token
     excel_df = pd.read_excel(excel_path, sheet_name=0, header=0)
     handler_result = []
     handler_result_folder = ""
@@ -95,19 +96,28 @@ def fromExcelHandler(params: HandlerDetail):
         raise UnicornException("缺失 [文件夹名称] 列")
     if "商品货号" not in excel_df.columns:
         raise UnicornException("缺失 [商品货号] 列")
+    if "款号" not in excel_df.columns:
+        raise UnicornException("缺失 [款号] 列")
+    goods_art_dirs = excel_df.groupby(excel_df["款号"])
+    obj = None
+    run_main = RunMain(obj, token)
     for index, row in excel_df.iterrows():
         goods_art_no_image_dir = str(row["文件夹名称"])
         goods_art_no = str(row["商品货号"])
+        print("货号数据", goods_art_no)
+        goods_no = str(row["款号"])
+        a001_df = goods_art_dirs.get_group(goods_no)
+        goods_art_nos = a001_df["商品货号"].tolist()
+        print("goods_art_nos", goods_art_nos)
         try:
             if not goods_art_no:
                 raise UnicornException("货号不能为空")
-            token = "Bearer " + params.token
             session = SqlQuery()
             pr = CRUD(PhotoRecord)
             images = pr.read_all(session, conditions={"goods_art_no": goods_art_no})
             if not images:
                 raise UnicornException("没有可用货号数据")
-            image_dir = "{}/data/".format(os.getcwd()).replace("\\", "/")
+            image_dir = "{}/data/{}".format(os.getcwd(), goods_no).replace("\\", "/")
             check_path(image_dir)
             for itemImg in images:
                 if itemImg.image_path == "" or itemImg.image_path == None:
@@ -140,6 +150,7 @@ def fromExcelHandler(params: HandlerDetail):
                 "image_dir": path,
                 "image_order": params.template_image_order,
                 "goods_art_no": goods_art_no,
+                "goods_art_nos": goods_art_nos,
                 "is_check_number": False,
                 "resize_image_view": "后跟",
                 "cutout_mode": settings.CUTOUT_MODE,
@@ -170,8 +181,6 @@ def fromExcelHandler(params: HandlerDetail):
                 temp_class_dict[key] = cls
 
             config_data["temp_class"] = temp_class_dict
-            obj = None
-            run_main = RunMain(obj, token)
             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
@@ -280,6 +289,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
                     else params.template_image_order
                 ),
                 "goods_art_no": goods_art_no,
+                "goods_art_nos": [goods_art_no],
                 "is_check_number": False,
                 "resize_image_view": "后跟",
                 "cutout_mode": settings.CUTOUT_MODE,

+ 85 - 14
python/custom_plugins/plugins/detail_template/xinnuo/detail_xinnuo3.py

@@ -103,18 +103,26 @@ class DetailPicGet(DetailBase):
             pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width/1.1)
             pp_png_1 = pp_png_1.resize(value=pp_bg.width /1.1)
 
-            if self.check_shoe_is_right_by_pixel(im=pp_png_1.im)==False:
+            if self.check_shoe_is_right_by_pixel(im=pp_png_1.im)==True:
                 pp_jpg_1 = pp_jpg_1.transpose()
                 pp_png_1 = pp_png_1.transpose()
 
-            pp_png_1_bg = PictureProcessing("RGBA", (pp_jpg_1.width*1.4, pp_jpg_1.width*1.4), (255,255,255,0))
-            pp_png_1_bg = pp_png_1_bg.paste_img(
-                top_img=pp_png_1,base="nc", value=(0, 0)
-            )
-            pp_png_1_bg = pp_png_1_bg.rotate(0)
+            # pp_png_1_bg = PictureProcessing("RGBA", (pp_jpg_1.width*1.4, pp_jpg_1.width*1.4), (255,255,255,0))
+            # pp_png_1_bg = pp_png_1_bg.paste_img(
+            #     top_img=pp_png_1,base="nc", value=(0, 0)
+            # )
+            # pp_png_1_bg = pp_png_1_bg.rotate(0)
+            #
+            # pp_bg = pp_bg.paste_img(
+            #     top_img=pp_png_1_bg,base="cc", value=(25, 340)
+            # )
 
-            pp_bg = pp_bg.paste_img(
-                top_img=pp_png_1_bg,base="cc", value=(25, 340)
+            pp_bg = pp_bg.to_overlay_pic_advance(
+                mode="pixel",
+                top_img=pp_jpg_1,
+                base="cc",
+                value=(25, 50),
+                top_png_img=pp_png_1,
             )
 
         return pp_bg
@@ -149,7 +157,7 @@ class DetailPicGet(DetailBase):
         gengao = self.get_text_value("跟高")
 
         pp_bg.get_text_image_advanced(
-            value=(264, 681),
+            value=(264, 680),
             font=font,
             text=xiemian,
             align="left",
@@ -161,7 +169,7 @@ class DetailPicGet(DetailBase):
             max_len_one_line=6
         )
         pp_bg.get_text_image_advanced(
-            value=(611, 681),
+            value=(611, 680),
             font=font,
             text=neili,
             align="left",
@@ -173,7 +181,7 @@ class DetailPicGet(DetailBase):
             max_len_one_line=6
         )
         pp_bg.get_text_image_advanced(
-            value=(611, 760),
+            value=(611, 758),
             font=font,
             text=xiedi,
             align="left",
@@ -185,7 +193,7 @@ class DetailPicGet(DetailBase):
             max_len_one_line=6
         )
         pp_bg.get_text_image_advanced(
-            value=(264, 760),
+            value=(264, 758),
             font=font,
             text=xiedian,
             align="left",
@@ -448,8 +456,12 @@ class DetailPicGet(DetailBase):
         pp_bg = PictureProcessing(image_path,1600)
         goods_art_no_list = list(self.data.keys())
 
-        # pp_bg_new = copy.deepcopy(pp_bg)
+        font = ImageFont.truetype(
+            r"resources\ttf\puhui\Regular.ttf", 18
+        )
 
+        # pp_bg_new = copy.deepcopy(pp_bg)
+        bg_height=179
         pp_jpg_1, pp_png_1 = self.image_one_pic(
             return_orign=True,
             goods_art_no=goods_art_no_list[0],
@@ -465,6 +477,20 @@ class DetailPicGet(DetailBase):
             pp_bg = pp_bg.to_overlay_pic_advance(
                 top_img=pp_jpg_1, top_png_img=pp_png_1, base="nc", value=(0, 270)
             )
+            bg_height=683
+
+            pp_bg.get_text_image_advanced(
+                value=(310,610),
+                font=font,
+                text="正面45°/ FRONT45°",
+                align="center",
+                # anchor="ma",
+                spacing=5,
+                return_mode="image",
+                margins=(0, 0, 0, 0),
+                max_len_one_line=20
+            )
+
 
         pp_jpg_1, pp_png_1 = self.image_one_pic(
             return_orign=True,
@@ -481,6 +507,18 @@ class DetailPicGet(DetailBase):
             pp_bg = pp_bg.to_overlay_pic_advance(
                 top_img=pp_jpg_1, top_png_img=pp_png_1, base="nc", value=(0, 720)
             )
+            bg_height=1086
+            pp_bg.get_text_image_advanced(
+                value=(315,1020),
+                font=font,
+                text="背面45°/ BACK45°",
+                align="center",
+                # anchor="ma",
+                spacing=5,
+                return_mode="image",
+                margins=(0, 0, 0, 0),
+                max_len_one_line=20
+            )
 
         pp_jpg_1, pp_png_1 = self.image_one_pic(
             return_orign=True,
@@ -505,6 +543,19 @@ class DetailPicGet(DetailBase):
                 top_img=pp_jpg_2, top_png_img=pp_png_2, base="nc", value=(80, 1150)
             )
 
+            bg_height=1600
+            pp_bg.get_text_image_advanced(
+                value=(350,1530),
+                font=font,
+                text="侧面/ SIDE",
+                align="center",
+                # anchor="ma",
+                spacing=5,
+                return_mode="image",
+                margins=(0, 0, 0, 0),
+                max_len_one_line=20
+            )
+
         pp_jpg_1, pp_png_1 = self.image_one_pic(
             return_orign=True,
             goods_art_no=goods_art_no_list[0],
@@ -520,8 +571,28 @@ class DetailPicGet(DetailBase):
             pp_bg = pp_bg.to_overlay_pic_advance(
                 top_img=pp_jpg_1, top_png_img=pp_png_1, base="nc", value=(0, 1750)
             )
+            bg_height=2395
+            pp_bg.get_text_image_advanced(
+                value=(353,2270),
+                font=font,
+                text="顶面/ TOP",
+                align="center",
+                # anchor="ma",
+                spacing=5,
+                return_mode="image",
+                margins=(0, 0, 0, 0),
+                max_len_one_line=20
+            )
+
+
+        temp_pp1_bg=PictureProcessing("RGB",(pp_bg.width,bg_height),(255,255,255))
+
+
+        temp_pp1_bg=temp_pp1_bg.paste_img(
+            mode="pixel",top_img=pp_bg,base="nw",value=(0, 0)
+        )
 
-        detailed_images.append(pp_bg)
+        detailed_images.append(temp_pp1_bg)
 
         return self.pp_pic_subsection(
             PictureProcessing(im=self.add_pic(detailed_images))

BIN
python/resources/detail_temp/xinnuo/3/6.jpg


+ 69 - 0
python/service/data.py

@@ -201,6 +201,75 @@ class DataModeGenerateDetail(DataBaseModel):
         # 数据转字典
         return_dict = {}
         message = ""
+        for index, row in need_df.iterrows():
+            if settings.PROJECT == "红蜻蜓":
+                if row["商品货号"] and row["款号"] and row["编号"]:
+                    return_dict[row["文件夹名称"]] = {
+                        "type": "goods_art_no",
+                        "name": row["文件夹名称"].upper(),
+                        "文件夹名称": row["文件夹名称"],
+                        "template_name": row["模板名称"],
+                        "data": row.to_dict(),
+                    }
+                else:
+                    message = "商品货号、款号、编号必须有值"
+            else:
+                if row["商品货号"] and row["款号"]:
+                    return_dict[row["文件夹名称"]] = {
+                        "type": "goods_art_no",
+                        "name": row["文件夹名称"].upper(),
+                        "文件夹名称": row["文件夹名称"],
+                        "template_name": row["模板名称"],
+                        "data": row.to_dict(),
+                    }
+
+        print("return_dict", return_dict)
+
+        if not return_dict:
+            message += "\n没有找到任何匹配的数据"
+            return {"code": 99, "message": message, "data": return_dict}
+        else:
+            return {"code": 0, "message": message, "data": return_dict}
+
+    def get_basic_goods_art_data_form_excel_bak(self, folder_name_list, excel_path, keys):
+
+        # =====创建虚拟表格并进行连表处理
+        need_df = pd.DataFrame(columns=["文件夹名称"])
+        for folder_name in folder_name_list:
+            new_row = {
+                "文件夹名称": str(folder_name),
+            }
+            need_df = need_df._append(new_row, ignore_index=True)
+
+        need_df = need_df.fillna(value="")
+
+        # 打开表格并进行匹配
+        _df = pd.read_excel(excel_path, sheet_name=0, header=0)
+        # 去重数据
+        duplicates = _df.duplicated(subset=["文件夹名称"], keep="first")
+        _df = _df.loc[~duplicates]
+        _df = _df.fillna(value="")
+        _df = _df.astype(str)
+
+        # 数据匹配关联,左关联
+        need_df = pd.merge(
+            need_df,
+            _df,
+            on=["文件夹名称"],
+            how="left",
+            indicator=False,
+        )
+        # 补全字段
+        header_list = need_df.columns.values.tolist()
+        for key in keys:
+            if key not in header_list:
+                need_df[key] = ""
+
+        need_df = need_df.fillna(value="")
+        need_df = need_df.astype(str)
+        # 数据转字典
+        return_dict = {}
+        message = ""
         print("need_df.iterrows()   <=============>      ", need_df.to_json())
         for index, row in need_df.iterrows():
             if settings.PROJECT == "红蜻蜓":

+ 3 - 3
python/service/detail_func.py

@@ -4,7 +4,7 @@ import settings
 import shutil
 
 
-def get_all_dir_info(image_dir, goods_art_no):
+def get_all_dir_info(image_dir, goods_art_nos):
     # 遍历货号获取所有货号--可能为编号
     folder_name_list = []
     for folder_name in os.listdir(image_dir):
@@ -19,8 +19,8 @@ def get_all_dir_info(image_dir, goods_art_no):
                 os.rmdir(_path)
             continue
         print("folder_name====>", folder_name)
-        print("goods_art_no====>", goods_art_no)
-        if goods_art_no == folder_name:
+        print("goods_art_no====>", goods_art_nos)
+        if folder_name in goods_art_nos:
             folder_name_list.append(folder_name)
 
     return folder_name_list

+ 1 - 1
python/service/init_load_source.py

@@ -17,7 +17,7 @@ class init_load_source:
         if response_data:
             for relative_file_path, value in response_data['data'].items():
                 if "new_custom_plugins" in relative_file_path and os.path.exists("lib") == False:
-                    print("主目录不存在,不下载")
+                    # print("主目录不存在,不下载")
                     continue
                 if (
                     "new_custom_plugins" in relative_file_path

+ 5 - 3
python/service/run_main.py

@@ -363,14 +363,15 @@ class RunMain():
         is_use_excel = config_data["is_use_excel"]
         excel_path = config_data["excel_path"]
         temp_class = config_data["temp_class"]
-        goods_art_no = config_data["goods_art_no"]
+        goods_art_nos = config_data["goods_art_nos"]
         is_check_color_is_all = config_data["is_check_color_is_all"]
         detail_is_pass = config_data["detail_is_pass"]
         error_folder_list = []
         # 遍历货号获取所有货号--可能为编号
         folder_name_list = get_all_dir_info(
-            image_dir=image_dir, goods_art_no=goods_art_no
+            image_dir=image_dir, goods_art_nos=goods_art_nos
         )
+        print("folder_name_list--folder_name_list===========>>>>", folder_name_list)
         if not folder_name_list:
             return_data["message"] += "不存在任何货号/编号文件夹\n"
             print("不存在任何货号/编号文件夹")
@@ -401,7 +402,7 @@ class RunMain():
                     keys,
                 )
             )
-
+            print("打印=======>>>>>>>_result=============>", _result)
         if _result["code"] == 0:
             remote_data = _result["data"]
         else:
@@ -870,6 +871,7 @@ class RunMain():
                         if goods_no in excel_temp_goods_no_data:
                             if _temp_name in excel_temp_goods_no_data[goods_no]:
                                 # 将表格中的特定的模板的行,替换到goods_no的data中,因为不同的模板有数据特殊性
+                                print("xxxxxx====>", excel_temp_goods_no_data[goods_no])
                                 for _key, _key_value in excel_temp_goods_no_data[goods_no][_temp_name].items():
                                     if _key in temp_info_data:
                                         temp_info_data[_key] = _key_value