|
|
@@ -15,7 +15,7 @@ from PIL import Image
|
|
|
from io import BytesIO
|
|
|
import os, re
|
|
|
from functools import partial
|
|
|
-
|
|
|
+from service.customer_template_service import CustomerTemplateService
|
|
|
# from multiprocessing import Process, Queue
|
|
|
import pickle
|
|
|
from .base_deal import BaseDealImage
|
|
|
@@ -390,7 +390,7 @@ class RunMain:
|
|
|
config_data["sign_text"] = "已结束抠图处理"
|
|
|
self.run_end_sign.emit(config_data)
|
|
|
|
|
|
- def check_before_detail(self, config_data,is_detail):
|
|
|
+ def check_before_detail(self, config_data,is_detail,template_type):
|
|
|
|
|
|
# =============
|
|
|
# 整体数据校验,返回错误内容,以及
|
|
|
@@ -474,16 +474,17 @@ class RunMain:
|
|
|
# 在访问 temp_class[temp_name].need_view 前增加检查
|
|
|
need_view_list = []
|
|
|
if is_detail == 1:
|
|
|
- if temp_name not in temp_class or temp_class[temp_name] is None:
|
|
|
- raise UnicornException(f"模板 {temp_name} 未正确初始化或不存在")
|
|
|
+ if template_type == 0:
|
|
|
+ if temp_name not in temp_class or temp_class[temp_name] is None:
|
|
|
+ raise UnicornException(f"模板 {temp_name} 未正确初始化或不存在")
|
|
|
|
|
|
- # 确保 temp_class[temp_name] 是可调用的
|
|
|
- if not callable(temp_class[temp_name]):
|
|
|
- raise UnicornException(f"模板 {temp_name} 不是有效的可调用对象")
|
|
|
- try:
|
|
|
- need_view_list = temp_class[temp_name].need_view
|
|
|
- except KeyError as ke:
|
|
|
- raise UnicornException("未选择详情页模板,请检查")
|
|
|
+ # 确保 temp_class[temp_name] 是可调用的
|
|
|
+ if not callable(temp_class[temp_name]):
|
|
|
+ raise UnicornException(f"模板 {temp_name} 不是有效的可调用对象")
|
|
|
+ try:
|
|
|
+ need_view_list = temp_class[temp_name].need_view
|
|
|
+ except KeyError as ke:
|
|
|
+ raise UnicornException("未选择详情页模板,请检查")
|
|
|
_all_dir_info_data = get_all_dir_info_and_pic_info(
|
|
|
image_dir, folder_name_list, need_view_list
|
|
|
)
|
|
|
@@ -753,13 +754,17 @@ class RunMain:
|
|
|
msg="开始处理抠图", goods_arts=goods_art_nos, status="开始处理",progress=progress
|
|
|
)
|
|
|
'''
|
|
|
- def check_for_detail_first_call_back(self, data):
|
|
|
+ def check_for_detail_first_call_back(self, data,request_parmas):
|
|
|
# 首次数据校验的信息返回
|
|
|
# self.show_message(text="22222222222222222222222")
|
|
|
# QMessageBox.critical(self, "警告", "1111111", QMessageBox.Ok)
|
|
|
code = data["code"]
|
|
|
config_data = data["data"]["config_data"]
|
|
|
target_error_folder = config_data["target_error_folder"]
|
|
|
+ # 模板类型,0系统模板,1自定义模板
|
|
|
+ template_type = request_parmas.template_type
|
|
|
+ # 自定义模板数据
|
|
|
+ customer_template_json = request_parmas.customer_template_json
|
|
|
print("635 check_for_detail_first_call_back")
|
|
|
print(data)
|
|
|
if code != 0:
|
|
|
@@ -824,7 +829,7 @@ class RunMain:
|
|
|
# self.set_state(state_value=1)
|
|
|
getAllData = data["data"]
|
|
|
base_temp_name = getAllData["temp_name"]
|
|
|
- set_temp_name = getAllData.get("template_name", "")
|
|
|
+ # set_temp_name = getAllData.get("template_name", "")
|
|
|
kwargs = {
|
|
|
"config_data": config_data,
|
|
|
"_goods_no_dict": data["data"]["goods_no_dict"],
|
|
|
@@ -846,6 +851,7 @@ class RunMain:
|
|
|
assigned_page_dict=kwargs["assigned_page_dict"],
|
|
|
excel_temp_goods_no_data=kwargs["excel_temp_goods_no_data"],
|
|
|
finally_goods_no_need_temps=kwargs["finally_goods_no_need_temps"],
|
|
|
+ request_parmas=request_parmas,
|
|
|
)
|
|
|
# self._w_3 = WorkerOneThread(func=new_func, name="_w_3")
|
|
|
# self._w_3.start()
|
|
|
@@ -865,6 +871,7 @@ class RunMain:
|
|
|
assigned_page_dict,
|
|
|
excel_temp_goods_no_data,
|
|
|
finally_goods_no_need_temps,
|
|
|
+ request_parmas
|
|
|
):
|
|
|
"""
|
|
|
excel_temp_goods_no_data: {}, # 表格数据可能存在多模板,数据结构为一个款号下的多个模板的数据列表
|
|
|
@@ -887,7 +894,6 @@ class RunMain:
|
|
|
print(json.dumps(_goods_no_dict))
|
|
|
|
|
|
print("==============_goods_no_dict 打印-end=================")
|
|
|
-
|
|
|
all_detail_path_list = []
|
|
|
out_put_dir_resp = ""
|
|
|
detail_total_progress = len(finally_goods_no_need_temps.items())
|
|
|
@@ -956,6 +962,7 @@ class RunMain:
|
|
|
temp_class=config_data["temp_class"],
|
|
|
target_error_folder=config_data["target_error_folder"],
|
|
|
image_dir=config_data["image_dir"],
|
|
|
+ request_parmas=request_parmas,
|
|
|
)
|
|
|
config_data["success_handler"].append(
|
|
|
{"goods_art_no": goods_no, "success": True, "info": "处理成功"}
|
|
|
@@ -974,6 +981,7 @@ class RunMain:
|
|
|
data={"goods_art_no": goods_no, "temp_name": _temp_name},
|
|
|
)
|
|
|
except BaseException as e:
|
|
|
+ print("详情页打印输出错误信息===>",e)
|
|
|
detail_error_progress+=1
|
|
|
detail_progress = {"status":"处理失败","goods_art_no":goods_no, "current":detail_finish_progress, "total":detail_total_progress, "error":detail_error_progress,"folder":""}
|
|
|
self.sendAsyncMessage(
|
|
|
@@ -989,7 +997,6 @@ class RunMain:
|
|
|
"info": "款:{}生成详情异常:{}".format(goods_no, e),
|
|
|
}
|
|
|
)
|
|
|
- print(e)
|
|
|
# raise UnicornException("款:{}生成详情异常:{}".format(goods_no, e))
|
|
|
config_data["success_handler"].append(
|
|
|
{
|
|
|
@@ -1060,7 +1067,12 @@ class RunMain:
|
|
|
temp_class,
|
|
|
target_error_folder,
|
|
|
image_dir,
|
|
|
+ request_parmas,
|
|
|
):
|
|
|
+ # 模板类型,0系统模板,1自定义模板
|
|
|
+ template_type = request_parmas.template_type
|
|
|
+ # 自定义模板数据
|
|
|
+ customer_template_json = request_parmas.customer_template_json
|
|
|
# if self.windows.state == 99:
|
|
|
# self.show_progress_detail("用户主动取消:{}".format(goods_no))
|
|
|
# return
|
|
|
@@ -1071,21 +1083,12 @@ class RunMain:
|
|
|
print("模板:", temp_name)
|
|
|
print("value:", value)
|
|
|
print("temp_class:", temp_class)
|
|
|
- if temp_name not in temp_class or temp_class[temp_name] is None:
|
|
|
- raise UnicornException(f"详情页模板 {temp_name} 未正确加载")
|
|
|
-
|
|
|
- if not callable(temp_class[temp_name]):
|
|
|
- raise UnicornException(f"详情页模板 {temp_name} 不是有效的可调用对象")
|
|
|
- if settings.IS_TEST:
|
|
|
- temp_class[temp_name](
|
|
|
- goods_no,
|
|
|
- value,
|
|
|
- out_put_dir=out_put_dir,
|
|
|
- windows=self.windows,
|
|
|
- assigned_page_list=assigned_page_list,
|
|
|
- )
|
|
|
- is_deal_success = True
|
|
|
- else:
|
|
|
+ if template_type == 0:
|
|
|
+ if temp_name not in temp_class or temp_class[temp_name] is None:
|
|
|
+ raise UnicornException(f"详情页模板 {temp_name} 未正确加载")
|
|
|
+
|
|
|
+ if not callable(temp_class[temp_name]):
|
|
|
+ raise UnicornException(f"详情页模板 {temp_name} 不是有效的可调用对象")
|
|
|
try:
|
|
|
# # 处理图片详情图生成
|
|
|
temp_class[temp_name](
|
|
|
@@ -1110,7 +1113,20 @@ class RunMain:
|
|
|
raise UnicornException(
|
|
|
"{}处理失败,失败原因:{}".format(goods_no, error_text)
|
|
|
)
|
|
|
-
|
|
|
+ else:
|
|
|
+ try:
|
|
|
+ is_deal_success = True
|
|
|
+ service = CustomerTemplateService()
|
|
|
+ goods_no = value["款号"]
|
|
|
+ save_path = f"{out_put_dir}/详情图-{goods_no}"
|
|
|
+ service.generateTemplate({goods_no:value},customer_template_json,temp_name,save_path)
|
|
|
+ except BaseException as e:
|
|
|
+ self.show_progress_detail("{}处理失败".format(goods_no))
|
|
|
+ error_text = "{}".format(e)
|
|
|
+ print("error_text",error_text)
|
|
|
+ print(
|
|
|
+ f"发生错误的文件: {e.__traceback__.tb_frame.f_globals['__file__']}"
|
|
|
+ )
|
|
|
self.n += 1
|
|
|
|
|
|
if not is_deal_success:
|