|
|
@@ -118,106 +118,121 @@ async def forwardRequest(request: HlmForwardRequest):
|
|
|
|
|
|
@app.post("/handle_detail")
|
|
|
async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
- goods_art_no = params.goods_art_no
|
|
|
- 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())
|
|
|
- for itemImg in images:
|
|
|
- if not os.path.exists(image_dir + "/" + os.path.basename(itemImg.image_path)):
|
|
|
- shutil.copy(itemImg.image_path, image_dir)
|
|
|
- check_path(image_dir)
|
|
|
- dealImage = DealImage(image_dir)
|
|
|
- resFlag, path = dealImage.dealMoveImage(
|
|
|
- image_dir=image_dir, callback_func=None, goods_art_no=goods_art_no
|
|
|
- )
|
|
|
- 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": "0",
|
|
|
- "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()
|
|
|
+ goods_art_no_array = params.goods_art_no
|
|
|
+ handler_result = []
|
|
|
+ handler_result_folder = ""
|
|
|
+ for goods_art_no in goods_art_no_array:
|
|
|
try:
|
|
|
- config_data = result["config_data"]
|
|
|
- except:
|
|
|
- config_data = result
|
|
|
- print("config_data", config_data)
|
|
|
- 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,
|
|
|
+ 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())
|
|
|
+ for itemImg in images:
|
|
|
+ if not os.path.exists(image_dir + "/" + os.path.basename(itemImg.image_path)):
|
|
|
+ shutil.copy(itemImg.image_path, image_dir)
|
|
|
+ check_path(image_dir)
|
|
|
+ dealImage = DealImage(image_dir)
|
|
|
+ resFlag, path = dealImage.dealMoveImage(
|
|
|
+ image_dir=image_dir, callback_func=None, goods_art_no=goods_art_no
|
|
|
+ )
|
|
|
+ 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": "0",
|
|
|
+ "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)
|
|
|
+ check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
|
+ return_data_check_before_detail
|
|
|
)
|
|
|
- upload_pic.run()
|
|
|
- out_put_dir = config_data["out_put_dir"]
|
|
|
- out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace("\\", "/")
|
|
|
- return {
|
|
|
- "code": 0,
|
|
|
- "msg": "详情处理完成",
|
|
|
- "data": {"out_put_dir": out_put_dir_path},
|
|
|
- }
|
|
|
- else:
|
|
|
- return {
|
|
|
- "code": 1,
|
|
|
- "msg": "处理失败,请联系管理员",
|
|
|
- "data": None}
|
|
|
+ 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:
|
|
|
+ # return {
|
|
|
+ # "code": 1,
|
|
|
+ # "msg": "处理失败,请联系管理员",
|
|
|
+ # "data": None}
|
|
|
+ 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)}
|
|
|
+ )
|
|
|
+ return {
|
|
|
+ "code": 0,
|
|
|
+ "msg": "",
|
|
|
+ "data": {"output_folder": handler_result_folder, "list": handler_result},
|
|
|
+ }
|
|
|
|
|
|
@app.post("/get_device_configs", description="获取可执行程序命令列表")
|
|
|
def get_device_configs(params: ModelGetDeviceConfig):
|