|
|
@@ -8,16 +8,15 @@ from serial.tools import list_ports
|
|
|
from model import PhotoRecord
|
|
|
import settings, datetime
|
|
|
import pandas as pd
|
|
|
-
|
|
|
from utils.hlm_http_request import forward_request
|
|
|
from utils.utils_func import check_path
|
|
|
from sockets.socket_client import socket_manager
|
|
|
from mcu.DeviceControl import DeviceControl
|
|
|
-import time, shutil
|
|
|
+import time, shutil, os
|
|
|
from sqlalchemy import and_, asc, desc
|
|
|
from functools import partial
|
|
|
from service.deal_image import DealImage
|
|
|
-from databases import DeviceConfig, SqlQuery, CRUD, select
|
|
|
+from databases import DeviceConfig, SysConfigs, SqlQuery, CRUD, select
|
|
|
from service.run_main import RunMain
|
|
|
import importlib
|
|
|
from service.auto_deal_pics.upload_pic import UploadPic
|
|
|
@@ -82,9 +81,7 @@ def test_conndevice():
|
|
|
p_list.append(_port_name)
|
|
|
device_control.add_port_by_linkage(_port_name)
|
|
|
except BaseException as e:
|
|
|
- print(
|
|
|
- e.__traceback__.tb_frame.f_globals["__file__"]
|
|
|
- ) # 发生异常所在的文件
|
|
|
+ print(e.__traceback__.tb_frame.f_globals["__file__"]) # 发生异常所在的文件
|
|
|
print(e.__traceback__.tb_lineno) # 发生异常所在的行数
|
|
|
print("串口不存在{} {}".format(_port_name, e))
|
|
|
|
|
|
@@ -92,9 +89,7 @@ def test_conndevice():
|
|
|
# self.add_port(_p)
|
|
|
|
|
|
|
|
|
-@app.api_route(
|
|
|
- "/forward_request", methods=["GET", "POST"], description="代理转发hlm项目得请求"
|
|
|
-)
|
|
|
+@app.api_route("/forward_request", methods=["GET", "POST"], description="代理转发hlm项目得请求")
|
|
|
async def forwardRequest(request: HlmForwardRequest):
|
|
|
"""
|
|
|
转发HTTP请求到目标URL
|
|
|
@@ -115,9 +110,7 @@ async def forwardRequest(request: HlmForwardRequest):
|
|
|
if not target_url:
|
|
|
raise UnicornException("目标url地址不能为空")
|
|
|
# 调用 hlm_http_request 中的 forward_request 函数
|
|
|
- response = forward_request(
|
|
|
- target_url, params=params, method=method, headers=headers
|
|
|
- )
|
|
|
+ response = forward_request(target_url, params=params, method=method, headers=headers)
|
|
|
return response
|
|
|
except requests.RequestException as e:
|
|
|
raise UnicornException(e)
|
|
|
@@ -149,9 +142,7 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
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)
|
|
|
- ):
|
|
|
+ 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(
|
|
|
@@ -177,9 +168,7 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
"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
|
|
|
+ "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,
|
|
|
@@ -208,9 +197,7 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
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,
|
|
|
@@ -240,21 +227,13 @@ def fromExcelHandler(params: HandlerDetail):
|
|
|
)
|
|
|
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": "处理成功"}
|
|
|
- )
|
|
|
+ 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": "处理失败"}
|
|
|
- )
|
|
|
+ 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.append({"goods_art_no": goods_art_no, "success": False, "info": str(e)})
|
|
|
handler_result_folder = "/".join(handler_result_folder.split("/")[:-1])
|
|
|
return {
|
|
|
"code": 0,
|
|
|
@@ -283,9 +262,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
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)
|
|
|
- ):
|
|
|
+ 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(
|
|
|
@@ -307,9 +284,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
"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
|
|
|
+ "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,
|
|
|
@@ -338,9 +313,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
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,
|
|
|
@@ -370,21 +343,13 @@ async def handle_detail(request: Request, params: HandlerDetail):
|
|
|
)
|
|
|
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": "处理成功"}
|
|
|
- )
|
|
|
+ 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": "处理失败"}
|
|
|
- )
|
|
|
+ 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.append({"goods_art_no": goods_art_no, "success": False, "info": str(e)})
|
|
|
return {
|
|
|
"code": 0,
|
|
|
"msg": "",
|
|
|
@@ -427,9 +392,7 @@ def get_device_configs(params: ModelGetDeviceConfigDetailQuery):
|
|
|
action_name = params.action_name
|
|
|
session = SqlQuery()
|
|
|
configModel = CRUD(DeviceConfig)
|
|
|
- model = configModel.read(
|
|
|
- session, conditions={"mode_type": mode_type, "action_name": action_name}
|
|
|
- )
|
|
|
+ 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}
|
|
|
@@ -504,9 +467,7 @@ def get_photo_records(page: int = 1, size: int = 5):
|
|
|
result = session.exec(statement).all()
|
|
|
print("group 完成 ", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
|
|
for item in result:
|
|
|
- list_item = photos.read_all(
|
|
|
- session, conditions={"goods_art_no": item.goods_art_no}
|
|
|
- )
|
|
|
+ list_item = photos.read_all(session, conditions={"goods_art_no": item.goods_art_no})
|
|
|
list.append(
|
|
|
{
|
|
|
"goods_art_no": item.goods_art_no,
|
|
|
@@ -527,9 +488,7 @@ def get_photo_records(page: int = 1, size: int = 5):
|
|
|
def get_last_photo_record():
|
|
|
|
|
|
session = SqlQuery()
|
|
|
- statement = (
|
|
|
- select(PhotoRecord).where(PhotoRecord.image_path!=None).order_by(desc("photo_create_time"))
|
|
|
- )
|
|
|
+ statement = select(PhotoRecord).where(PhotoRecord.image_path != None).order_by(desc("photo_create_time"))
|
|
|
result = session.exec(statement).first()
|
|
|
session.close()
|
|
|
return {
|
|
|
@@ -593,9 +552,7 @@ def save_sys_configs(params: SysConfigParams):
|
|
|
return {"code": 1, "msg": "配置不存在", "data": None}
|
|
|
# 走编辑逻辑
|
|
|
kwargs = params.__dict__
|
|
|
- save_device_config = sysConfig.updateConditions(
|
|
|
- session, conditions={"key": params.key}, **kwargs
|
|
|
- )
|
|
|
+ save_device_config = sysConfig.updateConditions(session, conditions={"key": params.key}, **kwargs)
|
|
|
return {"code": 0, "msg": "操作成功", "data": save_device_config}
|
|
|
|
|
|
|
|
|
@@ -615,3 +572,75 @@ def create_main_image(params: MaineImageTest):
|
|
|
# )
|
|
|
main_out_path = onePic.HandlerMainImage()
|
|
|
return {"code": 0, "msg": "操作成功", "data": {"main_out_path": main_out_path}}
|
|
|
+
|
|
|
+
|
|
|
+def insertEmptyLogoList(session):
|
|
|
+ """插入空logo列表"""
|
|
|
+ data = {"key": "logo_configs", "value": "[]"}
|
|
|
+ config = SysConfigs(**data)
|
|
|
+ session.add(config)
|
|
|
+ session.commit()
|
|
|
+ session.close()
|
|
|
+ item = SysConfigs()
|
|
|
+ item.key = "logo_configs"
|
|
|
+ item.value = "[]"
|
|
|
+ return item
|
|
|
+
|
|
|
+
|
|
|
+@app.get("/logo_list", description="logo列表")
|
|
|
+def logo_list():
|
|
|
+ session = SqlQuery()
|
|
|
+ photos = CRUD(SysConfigs)
|
|
|
+ item = photos.read(session, conditions={"key": "logo_configs"})
|
|
|
+ if item == None:
|
|
|
+ item = insertEmptyLogoList(session)
|
|
|
+ session.close()
|
|
|
+ return {
|
|
|
+ "code": 0,
|
|
|
+ "msg": "",
|
|
|
+ "data": json.loads(item.value),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+@app.post("/add_logo", description="添加logo")
|
|
|
+def add_logo(params: LogoParams):
|
|
|
+ logo_path = params.logo_path
|
|
|
+ session = SqlQuery()
|
|
|
+ sysConfig = CRUD(SysConfigs)
|
|
|
+ item = sysConfig.read(session, conditions={"key": "logo_configs"})
|
|
|
+ if item == None:
|
|
|
+ item = insertEmptyLogoList(session)
|
|
|
+ logo_list = json.loads(item.value)
|
|
|
+ if os.path.isfile(logo_path) == False:
|
|
|
+ return {"code": 1, "msg": "logo文件不存在", "data": None}
|
|
|
+ logo_dir = "{}/data/logo/".format(os.getcwd()).replace("\\", "/")
|
|
|
+ check_path(logo_dir)
|
|
|
+ fpath, fname = os.path.split(logo_path)
|
|
|
+ logo_path_info = logo_dir + fname
|
|
|
+ shutil.copy(logo_path, logo_path_info) # 复制文件
|
|
|
+ if len(logo_list)>0:
|
|
|
+ for item in logo_list:
|
|
|
+ if logo_path_info == item:
|
|
|
+ continue
|
|
|
+ logo_list.append(logo_path_info)
|
|
|
+ else:
|
|
|
+ logo_list.append(logo_path_info)
|
|
|
+ data = {"key": "logo_configs", "value": json.dumps(logo_list)}
|
|
|
+ sysConfig.updateConditions(session, conditions={"key": "logo_configs"}, **data)
|
|
|
+ return {
|
|
|
+ "code": 0,
|
|
|
+ "msg": "",
|
|
|
+ "data": {"logo":logo_path_info},
|
|
|
+ }
|
|
|
+
|
|
|
+@app.post("/delete_logo", description="删除logo")
|
|
|
+def delete_logo(params: LogoParamsupdate):
|
|
|
+ session = SqlQuery()
|
|
|
+ sysConfig = CRUD(SysConfigs)
|
|
|
+ model = sysConfig.read(session, conditions={"key": "logo_configs"})
|
|
|
+ if model == None:
|
|
|
+ insertEmptyLogoList(session)
|
|
|
+ # 走编辑逻辑
|
|
|
+ kwargs = params.__dict__
|
|
|
+ save_device_config = sysConfig.updateConditions(session, conditions={"key": "logo_configs"}, **kwargs)
|
|
|
+ return {"code": 0, "msg": "操作成功", "data": save_device_config}
|