|
|
@@ -7,7 +7,7 @@ from logger import logger
|
|
|
from serial.tools import list_ports
|
|
|
from model import PhotoRecord
|
|
|
import settings
|
|
|
-
|
|
|
+import pandas as pd
|
|
|
|
|
|
from utils.hlm_http_request import forward_request
|
|
|
from utils.utils_func import check_path
|
|
|
@@ -122,12 +122,147 @@ async def forwardRequest(request: HlmForwardRequest):
|
|
|
except Exception as e:
|
|
|
raise UnicornException(e)
|
|
|
|
|
|
+def fromExcelHandler(params: HandlerDetail):
|
|
|
+ excel_path = params.excel_path
|
|
|
+ excel_df = pd.read_excel(excel_path, sheet_name=0, header=0)
|
|
|
+ handler_result = []
|
|
|
+ handler_result_folder = ""
|
|
|
+ if "文件夹名称" not in excel_df.columns:
|
|
|
+ raise UnicornException("缺失 [文件夹名称] 列")
|
|
|
+ if "商品货号" not in excel_df.columns:
|
|
|
+ raise UnicornException("缺失 [商品货号] 列")
|
|
|
+ for index, row in excel_df.iterrows():
|
|
|
+ goods_art_no_image_dir = row["文件夹名称"]
|
|
|
+ goods_art_no = row["商品货号"]
|
|
|
+ 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("\\", "/")
|
|
|
+ check_path(image_dir)
|
|
|
+ for itemImg in images:
|
|
|
+ if not os.path.exists(
|
|
|
+ image_dir + "/" + os.path.basename(itemImg.image_path)
|
|
|
+ ):
|
|
|
+ shutil.copy(itemImg.image_path, image_dir)
|
|
|
+ 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)
|
|
|
+ temp_class = {}
|
|
|
+ temp_name_list = []
|
|
|
+ for tempItem in params.temp_list:
|
|
|
+ temp_class[tempItem.template_id] = tempItem.template_local_classes
|
|
|
+ temp_name_list.append(tempItem.template_id)
|
|
|
+ config_data = {
|
|
|
+ "image_dir": path,
|
|
|
+ "image_order": params.template_image_order,
|
|
|
+ "goods_art_no": goods_art_no,
|
|
|
+ "is_check_number": False,
|
|
|
+ "resize_image_view": "后跟",
|
|
|
+ "cutout_mode": settings.CUTOUT_MODE,
|
|
|
+ "logo_path": params.logo_path,
|
|
|
+ "special_goods_art_no_folder_line": "",
|
|
|
+ "is_use_excel": (
|
|
|
+ False if params.excel_path == "" else True
|
|
|
+ ), # 是否使用excel
|
|
|
+ "excel_path": params.excel_path, # excel路径
|
|
|
+ "is_check_color_is_all": False,
|
|
|
+ "cutout_is_pass": True,
|
|
|
+ "assigned_page_dict": {},
|
|
|
+ "detail_is_pass": True,
|
|
|
+ "upload_is_pass": False,
|
|
|
+ "upload_is_enable": False,
|
|
|
+ "is_filter": False,
|
|
|
+ "temp_class": temp_class,
|
|
|
+ "temp_name": params.temp_name,
|
|
|
+ "temp_name_list": temp_name_list,
|
|
|
+ "target_error_folder": f"{path}/软件-生成详情错误",
|
|
|
+ }
|
|
|
+ # 动态导入类
|
|
|
+ temp_class_dict = {}
|
|
|
+ for key, class_path in config_data["temp_class"].items():
|
|
|
+ module_path, class_name = class_path.rsplit(".", 1)
|
|
|
+ module = importlib.import_module(module_path)
|
|
|
+ cls = getattr(module, class_name)
|
|
|
+ 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
|
|
|
+ if cutout_res == True:
|
|
|
+ return_data_check_before_detail = run_main.check_before_detail(
|
|
|
+ config_data
|
|
|
+ )
|
|
|
+ print(
|
|
|
+ "return_data_check_before_detail======> 测试 ==>",
|
|
|
+ return_data_check_before_detail,
|
|
|
+ )
|
|
|
+ check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
|
+ return_data_check_before_detail
|
|
|
+ )
|
|
|
+ if isinstance(check_for_detail_first_res, partial):
|
|
|
+ result = check_for_detail_first_res()
|
|
|
+ try:
|
|
|
+ config_data = result["config_data"]
|
|
|
+ except:
|
|
|
+ config_data = result
|
|
|
+ if config_data["sign_text"] == "已结束详情处理":
|
|
|
+ # at_pic = AutoDealPics()
|
|
|
+ print("config_data", config_data)
|
|
|
+ if config_data["upload_is_enable"]:
|
|
|
+ to_deal_dir = "{}/软件-详情图生成".format(config_data["image_dir"])
|
|
|
+ check_path(to_deal_dir)
|
|
|
+ print("to_deal_dir", to_deal_dir)
|
|
|
+ if os.path.exists(to_deal_dir):
|
|
|
+ upload_pic = UploadPic(
|
|
|
+ windows=None,
|
|
|
+ to_deal_dir=to_deal_dir,
|
|
|
+ config_data=config_data,
|
|
|
+ token=token,
|
|
|
+ )
|
|
|
+ upload_pic.run()
|
|
|
+ out_put_dir = config_data["out_put_dir"]
|
|
|
+ out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace(
|
|
|
+ "\\", "/"
|
|
|
+ )
|
|
|
+ handler_result_folder = os.path.dirname(out_put_dir_path)
|
|
|
+ handler_result.append(
|
|
|
+ {"goods_art_no": goods_art_no, "success": True, "info": "处理成功"}
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ handler_result.append(
|
|
|
+ {"goods_art_no": goods_art_no, "success": False, "info": "处理失败"}
|
|
|
+ )
|
|
|
+ except Exception as e:
|
|
|
+ handler_result.append(
|
|
|
+ {"goods_art_no": goods_art_no, "success": False, "info": str(e)}
|
|
|
+ )
|
|
|
+ handler_result_folder = "/".join(handler_result_folder.split("/")[:-1])
|
|
|
+ return {
|
|
|
+ "code": 0,
|
|
|
+ "msg": "",
|
|
|
+ "data": {"output_folder": handler_result_folder, "list": handler_result},
|
|
|
+ }
|
|
|
@app.post("/handle_detail")
|
|
|
async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
goods_art_no_array = params.goods_art_no
|
|
|
handler_result = []
|
|
|
handler_result_folder = ""
|
|
|
+ if params.excel_path != "" or params.excel_path != None:
|
|
|
+ return fromExcelHandler(params)
|
|
|
for goods_art_no in goods_art_no_array:
|
|
|
try:
|
|
|
if not goods_art_no:
|
|
|
@@ -195,6 +330,9 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
check_for_detail_first_res = None
|
|
|
if cutout_res == True:
|
|
|
return_data_check_before_detail = run_main.check_before_detail(config_data)
|
|
|
+ print(
|
|
|
+ "return_data_check_before_detail======> 测试 ==>", return_data_check_before_detail
|
|
|
+ )
|
|
|
check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
|
return_data_check_before_detail
|
|
|
)
|