ソースを参照

excel同款多色生成问题

rambo 5 ヶ月 前
コミット
0f4108740b

+ 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,

+ 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