|
|
@@ -21,6 +21,8 @@ from databases import DeviceConfig, SqlQuery, CRUD, select
|
|
|
from service.run_main import RunMain
|
|
|
import importlib
|
|
|
from service.auto_deal_pics.upload_pic import UploadPic
|
|
|
+from service.OnePicTest import OnePicTest
|
|
|
+
|
|
|
# from service.AutoDealPics import AutoDealPics
|
|
|
# for plugin in settings.plugins:
|
|
|
# module_path, class_name = plugin.rsplit(".", 1)
|
|
|
@@ -122,6 +124,7 @@ 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)
|
|
|
@@ -258,6 +261,8 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
"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
|
|
|
@@ -294,28 +299,30 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
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}/软件-生成详情错误",
|
|
|
- }
|
|
|
+ "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():
|
|
|
@@ -326,18 +333,21 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
|
|
|
config_data["temp_class"] = temp_class_dict
|
|
|
obj = None
|
|
|
- run_main = RunMain(obj,token)
|
|
|
+ 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)
|
|
|
+ return_data_check_before_detail = run_main.check_before_detail(
|
|
|
+ config_data
|
|
|
+ )
|
|
|
print(
|
|
|
- "return_data_check_before_detail======> 测试 ==>", return_data_check_before_detail
|
|
|
+ "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
|
|
|
- )
|
|
|
+ return_data_check_before_detail
|
|
|
+ )
|
|
|
if isinstance(check_for_detail_first_res, partial):
|
|
|
result = check_for_detail_first_res()
|
|
|
try:
|
|
|
@@ -353,22 +363,24 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
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,
|
|
|
- )
|
|
|
+ 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("\\", "/")
|
|
|
+ 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": "处理成功"}
|
|
|
- )
|
|
|
+ {"goods_art_no": goods_art_no, "success": True, "info": "处理成功"}
|
|
|
+ )
|
|
|
else:
|
|
|
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:
|
|
|
handler_result.append(
|
|
|
{"goods_art_no": goods_art_no, "success": False, "info": str(e)}
|
|
|
@@ -379,6 +391,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
"data": {"output_folder": handler_result_folder, "list": handler_result},
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@app.post("/get_device_configs", description="获取可执行程序命令列表")
|
|
|
def get_device_configs(params: ModelGetDeviceConfig):
|
|
|
mode_type = params.mode_type
|
|
|
@@ -408,6 +421,20 @@ def get_device_configs(params: ModelGetDeviceConfigDetail):
|
|
|
return {"code": 0, "msg": "", "data": model}
|
|
|
|
|
|
|
|
|
+@app.post("/device_config_detail_query", description="通过条件获取可执行程序详情")
|
|
|
+def get_device_configs(params: ModelGetDeviceConfigDetailQuery):
|
|
|
+ mode_type = params.mode_type
|
|
|
+ action_name = params.action_name
|
|
|
+ session = SqlQuery()
|
|
|
+ configModel = CRUD(DeviceConfig)
|
|
|
+ model = configModel.read(
|
|
|
+ session, conditions={"mode_type": mode_type, "action_name": action_name}
|
|
|
+ )
|
|
|
+ if model == None:
|
|
|
+ return {"code": 1, "msg": "数据不存在", "data": None}
|
|
|
+ return {"code": 0, "msg": "", "data": model}
|
|
|
+
|
|
|
+
|
|
|
@app.post("/remove_config", description="删除一条可执行命令")
|
|
|
def get_device_configs(params: ModelGetDeviceConfigDetail):
|
|
|
action_id = params.id
|
|
|
@@ -416,6 +443,8 @@ def get_device_configs(params: ModelGetDeviceConfigDetail):
|
|
|
model = configModel.read(session, conditions={"id": action_id})
|
|
|
if model == None:
|
|
|
return {"code": 1, "msg": "数据不存在", "data": None}
|
|
|
+ if model.is_system == True:
|
|
|
+ return {"code": 1, "msg": "系统配置不允许删除", "data": None}
|
|
|
configModel.delete(session, obj_id=action_id)
|
|
|
return {"code": 0, "msg": "删除成功", "data": None}
|
|
|
|
|
|
@@ -491,6 +520,22 @@ def get_photo_records(page: int = 1, size: int = 5):
|
|
|
}
|
|
|
|
|
|
|
|
|
+@app.get("/get_last_photo_record", description="获取最后一条拍照记录")
|
|
|
+def get_last_photo_record():
|
|
|
+
|
|
|
+ session = SqlQuery()
|
|
|
+ statement = (
|
|
|
+ select(PhotoRecord).where(PhotoRecord.image_path!=None).order_by(desc("photo_create_time"))
|
|
|
+ )
|
|
|
+ result = session.exec(statement).first()
|
|
|
+ session.close()
|
|
|
+ return {
|
|
|
+ "code": 0,
|
|
|
+ "msg": "",
|
|
|
+ "data": result,
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@app.get("/get_photo_record_detail", description="通过货号获取拍照记录详情")
|
|
|
def get_photo_records(goods_art_no: str = None):
|
|
|
if goods_art_no == None:
|
|
|
@@ -549,3 +594,21 @@ def save_sys_configs(params: SysConfigParams):
|
|
|
session, conditions={"key": params.key}, **kwargs
|
|
|
)
|
|
|
return {"code": 0, "msg": "操作成功", "data": save_device_config}
|
|
|
+
|
|
|
+
|
|
|
+@app.post("/create_main_image", description="创建主图测试")
|
|
|
+def create_main_image(params: MaineImageTest):
|
|
|
+ file_path = params.file_path
|
|
|
+ onePic = OnePicTest(pic_path=file_path)
|
|
|
+ # session = SqlQuery()
|
|
|
+ # sysConfig = CRUD(SysConfigs)
|
|
|
+ # model = sysConfig.read(session, conditions={"key": params.key})
|
|
|
+ # if model == None:
|
|
|
+ # return {"code": 1, "msg": "配置不存在", "data": None}
|
|
|
+ # # 走编辑逻辑
|
|
|
+ # kwargs = params.__dict__
|
|
|
+ # save_device_config = sysConfig.updateConditions(
|
|
|
+ # session, conditions={"key": params.key}, **kwargs
|
|
|
+ # )
|
|
|
+ main_out_path = onePic.HandlerMainImage()
|
|
|
+ return {"code": 0, "msg": "操作成功", "data": {"main_out_path": main_out_path}}
|