|
@@ -21,6 +21,7 @@ from service.run_main import RunMain
|
|
|
import importlib
|
|
import importlib
|
|
|
from service.auto_deal_pics.upload_pic import UploadPic
|
|
from service.auto_deal_pics.upload_pic import UploadPic
|
|
|
from service.OnePicTest import OnePicTest
|
|
from service.OnePicTest import OnePicTest
|
|
|
|
|
+from service.base import check_move_goods_art_no_folder
|
|
|
import hashlib
|
|
import hashlib
|
|
|
import win32api, win32gui, win32con
|
|
import win32api, win32gui, win32con
|
|
|
from win32gui import EnumWindows, GetWindowText
|
|
from win32gui import EnumWindows, GetWindowText
|
|
@@ -112,10 +113,18 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
temp_class[tempItem.template_id] = tempItem.template_local_classes
|
|
temp_class[tempItem.template_id] = tempItem.template_local_classes
|
|
|
temp_name_list.append(tempItem.template_id)
|
|
temp_name_list.append(tempItem.template_id)
|
|
|
goods_art_no_arrays = []
|
|
goods_art_no_arrays = []
|
|
|
|
|
+ for _, goods_row in excel_df.iterrows():
|
|
|
|
|
+ goods_art_no = str(goods_row["商品货号"])
|
|
|
|
|
+ goods_art_no_arrays.append(goods_art_no)
|
|
|
|
|
+ limit_path = "output/{}".format(
|
|
|
|
|
+ time.strftime("%Y-%m-%d", time.localtime(time.time()))
|
|
|
|
|
+ )
|
|
|
|
|
+ move_folder_array = check_move_goods_art_no_folder(
|
|
|
|
|
+ "output", goods_art_no_arrays, limit_path
|
|
|
|
|
+ )
|
|
|
for index, row in excel_df.iterrows():
|
|
for index, row in excel_df.iterrows():
|
|
|
goods_art_no_image_dir = str(row["文件夹名称"])
|
|
goods_art_no_image_dir = str(row["文件夹名称"])
|
|
|
goods_art_no = str(row["商品货号"])
|
|
goods_art_no = str(row["商品货号"])
|
|
|
- goods_art_no_arrays.append(goods_art_no)
|
|
|
|
|
print("货号数据", goods_art_no)
|
|
print("货号数据", goods_art_no)
|
|
|
goods_no = str(row["款号"])
|
|
goods_no = str(row["款号"])
|
|
|
a001_df = goods_art_dirs.get_group(goods_no)
|
|
a001_df = goods_art_dirs.get_group(goods_no)
|
|
@@ -128,35 +137,35 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
images = pr.read_all(session, conditions={"goods_art_no": goods_art_no})
|
|
images = pr.read_all(session, conditions={"goods_art_no": goods_art_no})
|
|
|
if not images:
|
|
if not images:
|
|
|
raise UnicornException("没有可用货号数据")
|
|
raise UnicornException("没有可用货号数据")
|
|
|
- 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:
|
|
|
|
|
- raise UnicornException(
|
|
|
|
|
- f"货号【{goods_art_no}】存在没有拍摄完成的图片,请重拍或删除后重试"
|
|
|
|
|
- )
|
|
|
|
|
- new_file_name = (
|
|
|
|
|
- str(itemImg.goods_art_no) + "_" + str(itemImg.id) + ".jpg"
|
|
|
|
|
|
|
+ # 货号目录不存在再去进行移动和创建操作
|
|
|
|
|
+ if move_folder_array.get(goods_art_no) == None:
|
|
|
|
|
+ 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:
|
|
|
|
|
+ raise UnicornException(
|
|
|
|
|
+ f"货号【{goods_art_no}】存在没有拍摄完成的图片,请重拍或删除后重试"
|
|
|
)
|
|
)
|
|
|
- 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_image_dir,
|
|
|
|
|
|
|
+ new_file_name = (
|
|
|
|
|
+ str(itemImg.goods_art_no) + "_" + str(itemImg.id) + ".jpg"
|
|
|
)
|
|
)
|
|
|
- if not resFlag:
|
|
|
|
|
- raise UnicornException(path)
|
|
|
|
|
- # if goods_art_no_image_dir not in path:
|
|
|
|
|
- # path = path + "/" + goods_art_no_image_dir
|
|
|
|
|
- path = os.path.dirname(path)
|
|
|
|
|
|
|
+ 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_image_dir,
|
|
|
|
|
+ )
|
|
|
|
|
+ if not resFlag:
|
|
|
|
|
+ raise UnicornException(path)
|
|
|
|
|
+ shutil.rmtree(image_dir)
|
|
|
|
|
+ # path = os.path.dirname(path)
|
|
|
try:
|
|
try:
|
|
|
- print("path", path)
|
|
|
|
|
config_data = {
|
|
config_data = {
|
|
|
- "image_dir": path,
|
|
|
|
|
|
|
+ "image_dir": limit_path, # 这个目录作为本次生成的图片目录非常重要 例:./output/当前日期
|
|
|
"image_order": params.template_image_order,
|
|
"image_order": params.template_image_order,
|
|
|
"goods_art_no": goods_art_no,
|
|
"goods_art_no": goods_art_no,
|
|
|
"goods_art_nos": goods_art_no_arrays,
|
|
"goods_art_nos": goods_art_no_arrays,
|
|
@@ -165,9 +174,7 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
"cutout_mode": settings.CUTOUT_MODE,
|
|
"cutout_mode": settings.CUTOUT_MODE,
|
|
|
"logo_path": params.logo_path,
|
|
"logo_path": params.logo_path,
|
|
|
"special_goods_art_no_folder_line": "",
|
|
"special_goods_art_no_folder_line": "",
|
|
|
- "is_use_excel": (
|
|
|
|
|
- False if params.excel_path == "" else True
|
|
|
|
|
- ), # 是否使用excel
|
|
|
|
|
|
|
+ "is_use_excel": (False if params.excel_path == "" else True), # 是否使用excel
|
|
|
"excel_path": params.excel_path, # excel路径
|
|
"excel_path": params.excel_path, # excel路径
|
|
|
"is_check_color_is_all": False,
|
|
"is_check_color_is_all": False,
|
|
|
"cutout_is_pass": True,
|
|
"cutout_is_pass": True,
|
|
@@ -179,7 +186,7 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
"temp_class": temp_class,
|
|
"temp_class": temp_class,
|
|
|
"temp_name": params.temp_name,
|
|
"temp_name": params.temp_name,
|
|
|
"temp_name_list": temp_name_list,
|
|
"temp_name_list": temp_name_list,
|
|
|
- "target_error_folder": f"{path}/软件-生成详情错误",
|
|
|
|
|
|
|
+ "target_error_folder": f"{limit_path}/软件-生成详情错误",
|
|
|
}
|
|
}
|
|
|
# 动态导入类
|
|
# 动态导入类
|
|
|
temp_class_dict = {}
|
|
temp_class_dict = {}
|
|
@@ -190,17 +197,15 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
temp_class_dict[key] = cls
|
|
temp_class_dict[key] = cls
|
|
|
|
|
|
|
|
config_data["temp_class"] = temp_class_dict
|
|
config_data["temp_class"] = temp_class_dict
|
|
|
|
|
+ # 此处对抠图进行批量处理,保证所有的图片在生成详情图之前已经完成抠图,以保证详情图生成的效率
|
|
|
return_data = run_main.check_before_cutout(config_data)
|
|
return_data = run_main.check_before_cutout(config_data)
|
|
|
cutout_res = run_main.check_for_cutout_image_first_call_back(return_data)
|
|
cutout_res = run_main.check_for_cutout_image_first_call_back(return_data)
|
|
|
- print("cutout_res", cutout_res)
|
|
|
|
|
check_for_detail_first_res = None
|
|
check_for_detail_first_res = None
|
|
|
if cutout_res:
|
|
if cutout_res:
|
|
|
- return_data_check_before_detail = run_main.check_before_detail(
|
|
|
|
|
- config_data
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return_data_check_before_detail = run_main.check_before_detail(config_data)
|
|
|
check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
|
- return_data_check_before_detail
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return_data_check_before_detail
|
|
|
|
|
+ )
|
|
|
if isinstance(check_for_detail_first_res, partial):
|
|
if isinstance(check_for_detail_first_res, partial):
|
|
|
result = check_for_detail_first_res()
|
|
result = check_for_detail_first_res()
|
|
|
try:
|
|
try:
|
|
@@ -216,34 +221,32 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
print("to_deal_dir", to_deal_dir)
|
|
print("to_deal_dir", to_deal_dir)
|
|
|
if os.path.exists(to_deal_dir):
|
|
if os.path.exists(to_deal_dir):
|
|
|
upload_pic = UploadPic(
|
|
upload_pic = UploadPic(
|
|
|
- windows=None,
|
|
|
|
|
- to_deal_dir=to_deal_dir,
|
|
|
|
|
- config_data=config_data,
|
|
|
|
|
- token=token,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ windows=None,
|
|
|
|
|
+ to_deal_dir=to_deal_dir,
|
|
|
|
|
+ config_data=config_data,
|
|
|
|
|
+ token=token,
|
|
|
|
|
+ )
|
|
|
upload_pic.run()
|
|
upload_pic.run()
|
|
|
out_put_dir = config_data["out_put_dir"]
|
|
out_put_dir = config_data["out_put_dir"]
|
|
|
- out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace(
|
|
|
|
|
- "\\", "/"
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace("\\", "/")
|
|
|
handler_result_folder = os.path.dirname(out_put_dir_path)
|
|
handler_result_folder = os.path.dirname(out_put_dir_path)
|
|
|
handler_result.append(
|
|
handler_result.append(
|
|
|
- {"goods_art_no": goods_art_no, "success": True, "info": "处理成功"}
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ {"goods_art_no": goods_art_no, "success": True, "info": "处理成功"}
|
|
|
|
|
+ )
|
|
|
else:
|
|
else:
|
|
|
handler_result.append(
|
|
handler_result.append(
|
|
|
- {"goods_art_no": goods_art_no, "success": False, "info": "处理失败"}
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ {"goods_art_no": goods_art_no, "success": False, "info": "处理失败"}
|
|
|
|
|
+ )
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
handler_result.append(
|
|
handler_result.append(
|
|
|
{"goods_art_no": goods_art_no, "success": False, "info": str(e)}
|
|
{"goods_art_no": goods_art_no, "success": False, "info": str(e)}
|
|
|
)
|
|
)
|
|
|
handler_result_folder = "/".join(handler_result_folder.split("/")[:-1])
|
|
handler_result_folder = "/".join(handler_result_folder.split("/")[:-1])
|
|
|
return {
|
|
return {
|
|
|
- "code": 0,
|
|
|
|
|
- "msg": "",
|
|
|
|
|
- "data": {"output_folder": handler_result_folder, "list": handler_result},
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ "code": 0,
|
|
|
|
|
+ "msg": "",
|
|
|
|
|
+ "data": {"output_folder": handler_result_folder, "list": handler_result},
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
def group_by_style_number(data):
|
|
def group_by_style_number(data):
|
|
@@ -303,10 +306,10 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
f"货号【{goods_art_no}】存在没有拍摄完成的图片,请重拍或删除后重试"
|
|
f"货号【{goods_art_no}】存在没有拍摄完成的图片,请重拍或删除后重试"
|
|
|
)
|
|
)
|
|
|
new_file_name = (
|
|
new_file_name = (
|
|
|
- str(itemImg.goods_art_no) + "_" + str(itemImg.id) + ".jpg"
|
|
|
|
|
|
|
+ str(itemImg.goods_art_no) + "_" + str(itemImg.id) + ".jpg"
|
|
|
)
|
|
)
|
|
|
if not os.path.exists(
|
|
if not os.path.exists(
|
|
|
- image_dir + "/" + os.path.basename(new_file_name)
|
|
|
|
|
|
|
+ image_dir + "/" + os.path.basename(new_file_name)
|
|
|
):
|
|
):
|
|
|
shutil.copy(itemImg.image_path, image_dir + "/" + new_file_name)
|
|
shutil.copy(itemImg.image_path, image_dir + "/" + new_file_name)
|
|
|
dealImage = DealImage(image_dir)
|
|
dealImage = DealImage(image_dir)
|
|
@@ -325,7 +328,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
"image_order": (
|
|
"image_order": (
|
|
|
"俯视,侧视,后跟,鞋底,内里"
|
|
"俯视,侧视,后跟,鞋底,内里"
|
|
|
if params.template_image_order == None
|
|
if params.template_image_order == None
|
|
|
- or params.template_image_order == ""
|
|
|
|
|
|
|
+ or params.template_image_order == ""
|
|
|
else params.template_image_order
|
|
else params.template_image_order
|
|
|
),
|
|
),
|
|
|
"goods_art_no": goods_art_no,
|
|
"goods_art_no": goods_art_no,
|
|
@@ -400,7 +403,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
"image_order": (
|
|
"image_order": (
|
|
|
"俯视,侧视,后跟,鞋底,内里"
|
|
"俯视,侧视,后跟,鞋底,内里"
|
|
|
if params.template_image_order is None
|
|
if params.template_image_order is None
|
|
|
- or params.template_image_order == ""
|
|
|
|
|
|
|
+ or params.template_image_order == ""
|
|
|
else params.template_image_order
|
|
else params.template_image_order
|
|
|
),
|
|
),
|
|
|
"goods_art_no": "",
|
|
"goods_art_no": "",
|
|
@@ -435,9 +438,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
temp_class_dict[key] = cls
|
|
temp_class_dict[key] = cls
|
|
|
|
|
|
|
|
config_data["temp_class"] = temp_class_dict
|
|
config_data["temp_class"] = temp_class_dict
|
|
|
- return_data_check_before_detail = run_main.check_before_detail(
|
|
|
|
|
- config_data
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return_data_check_before_detail = run_main.check_before_detail(config_data)
|
|
|
check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
|
return_data_check_before_detail
|
|
return_data_check_before_detail
|
|
|
)
|
|
)
|
|
@@ -475,9 +476,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
{"goods_art_no": "", "success": False, "info": "处理失败"}
|
|
{"goods_art_no": "", "success": False, "info": "处理失败"}
|
|
|
)
|
|
)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- handler_result.append(
|
|
|
|
|
- {"goods_art_no": "", "success": False, "info": str(e)}
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ handler_result.append({"goods_art_no": "", "success": False, "info": str(e)})
|
|
|
return {
|
|
return {
|
|
|
"code": 0,
|
|
"code": 0,
|
|
|
"msg": "",
|
|
"msg": "",
|