Browse Source

Merge branch 'dev-python'

rambo 5 months ago
parent
commit
8004dd4170

+ 20 - 16
python/custom_plugins/plugins/detail_template/xinjunlue/detail_xinjunlue1.py

@@ -9,7 +9,7 @@ import os
 from PIL import ImageFont, ImageDraw
 import sys
 import settings
-
+from middleware import UnicornException
 # from PIL import Image, ImageDraw, ImageFont
 
 # from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
@@ -72,21 +72,21 @@ class DetailPicGet(DetailBase):
         ]
         img = self.add_pic(self.deal_pic_func_list)
         file_path = self.get_text_value("图片路径")
-        # file_path = file_path.replace("\\", "/")
+        if file_path == None or file_path == "":
+            raise UnicornException("图片路径不能为空")
         parent_folder = os.path.dirname(file_path)
-        if os.path.exists(parent_folder) == False:
-            # 确保目标目录存在
-            os.makedirs(parent_folder, exist_ok=True)
-        print("file_path是否存在",parent_folder, os.path.exists(parent_folder))
-        file_extension = file_path.split(".")[-1]
-        format_mapping = {"jpg": "JPEG", "png": "PNG", "webp": "WEBP", "avif": "AVIF"}
-        file_format = format_mapping[file_extension]
-        img.save(file_path, format=file_format)
-        img.show()
-        # if test:
-        #     self.run_test()
-        # else:
-        #     self.run_all()
+        try:
+            if os.path.exists(parent_folder) == False:
+                # 确保目标目录存在
+                os.makedirs(parent_folder, exist_ok=True)
+            file_extension = file_path.split(".")[-1]
+            format_mapping = {"jpg": "JPEG", "png": "PNG", "webp": "WEBP", "avif": "AVIF"}
+            file_format = format_mapping[file_extension.lower()]
+            img.save(file_path, format=file_format)
+        except KeyError:
+            raise UnicornException(f"不支持的文件格式: {file_extension}")
+        except Exception as e:
+            raise UnicornException(f"保存图片时发生错误: {e},请检查路径")
 
     def run_test(self):
         detailed_images = []
@@ -111,6 +111,8 @@ class DetailPicGet(DetailBase):
         font = ImageFont.truetype("msyh.ttc", 20)
         dataList = [
             "款号",
+            "楦号",
+            "颜色",
             "面料",
             "内里",
             "垫脚",
@@ -128,7 +130,7 @@ class DetailPicGet(DetailBase):
             if info == None or info == "":
                 continue
             _pp = PictureProcessing()
-            text = f"{item}: {self.get_text_value(item)}"
+            text = f"{item}: {info}"
             duanluo = ""
             sum_width = 0
             line_count = 0
@@ -186,6 +188,7 @@ class DetailPicGet(DetailBase):
             "JEFFREY CAMPBELL",
             "Supplier",
             "款号",  # Fty No
+            "颜色",  # Fty No
             "Material",
             "Lining&Sock",
             "码数",  # Size
@@ -204,6 +207,7 @@ class DetailPicGet(DetailBase):
                 "JEFFREY CAMPBELL": "",
                 "Supplier": "Supplier:",
                 "款号": "Fty No:",
+                "颜色": "Color:",
                 "Material": "Material:",
                 "Lining&Sock": "Lining&Sock:",
                 "码数": "Size:",