|
|
@@ -14,6 +14,8 @@ from sqlalchemy import and_, asc, desc
|
|
|
|
|
|
from service.deal_image import DealImage
|
|
|
from databases import DeviceConfig, SqlQuery, CRUD, select
|
|
|
+
|
|
|
+
|
|
|
@app.get("/")
|
|
|
async def index():
|
|
|
# await socket_manager.send_message(msg="测试")
|
|
|
@@ -22,8 +24,8 @@ async def index():
|
|
|
|
|
|
@app.get("/send_test")
|
|
|
async def index():
|
|
|
- data = {"data1":1,"data2":2,"data3":3,"data4":4}
|
|
|
- await socket_manager.send_message(msg="测试",data=data)
|
|
|
+ data = {"data1": 1, "data2": 2, "data3": 3, "data4": 4}
|
|
|
+ await socket_manager.send_message(msg="测试", data=data)
|
|
|
return {"message": "Hello World"}
|
|
|
|
|
|
|
|
|
@@ -37,40 +39,42 @@ async def scanSerials():
|
|
|
|
|
|
@app.get("/test_conndevice")
|
|
|
def test_conndevice():
|
|
|
- device_control = DeviceControl()
|
|
|
- p_list = []
|
|
|
- temp_ports_dict = {}
|
|
|
+ device_control = DeviceControl()
|
|
|
+ p_list = []
|
|
|
+ temp_ports_dict = {}
|
|
|
# while 1:
|
|
|
- time.sleep(1)
|
|
|
- ports_dict = device_control.scan_serial_port()
|
|
|
- temp_ports_dict = ports_dict
|
|
|
-
|
|
|
- if not ports_dict:
|
|
|
- # 全部清空 移除所有串口
|
|
|
- if p_list:
|
|
|
- _p = p_list.pop()
|
|
|
+ time.sleep(1)
|
|
|
+ ports_dict = device_control.scan_serial_port()
|
|
|
+ temp_ports_dict = ports_dict
|
|
|
+
|
|
|
+ if not ports_dict:
|
|
|
+ # 全部清空 移除所有串口
|
|
|
+ if p_list:
|
|
|
+ _p = p_list.pop()
|
|
|
+ device_control.remove_port(_p)
|
|
|
+ # continue
|
|
|
+
|
|
|
+ if ports_dict:
|
|
|
+ # print(plist)
|
|
|
+ for index, _i in enumerate(p_list):
|
|
|
+ if _i not in ports_dict:
|
|
|
+ _p = p_list.pop(index)
|
|
|
device_control.remove_port(_p)
|
|
|
- # continue
|
|
|
-
|
|
|
- if ports_dict:
|
|
|
- # print(plist)
|
|
|
- for index, _i in enumerate(p_list):
|
|
|
- if _i not in ports_dict:
|
|
|
- _p = p_list.pop(index)
|
|
|
- device_control.remove_port(_p)
|
|
|
|
|
|
- for _port_name, _port_value in ports_dict.items():
|
|
|
- if _port_name not in p_list:
|
|
|
- try:
|
|
|
- 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_lineno) # 发生异常所在的行数
|
|
|
- print("串口不存在{} {}".format(_port_name, e))
|
|
|
+ for _port_name, _port_value in ports_dict.items():
|
|
|
+ if _port_name not in p_list:
|
|
|
+ try:
|
|
|
+ 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_lineno) # 发生异常所在的行数
|
|
|
+ print("串口不存在{} {}".format(_port_name, e))
|
|
|
|
|
|
- # threading.Thread(target=self.add_port, args=(_port_name, _port_value)).start()
|
|
|
- # self.add_port(_p)
|
|
|
+ # threading.Thread(target=self.add_port, args=(_port_name, _port_value)).start()
|
|
|
+ # self.add_port(_p)
|
|
|
|
|
|
|
|
|
@app.api_route(
|
|
|
@@ -112,12 +116,11 @@ async def handle_detail(request: Request):
|
|
|
image_dir = "{}/data".format(os.getcwd())
|
|
|
dealImage = DealImage(image_dir)
|
|
|
dealImage.header = request.headers
|
|
|
- print('>>>>>>>>>>>>>>>>>请求参数')
|
|
|
+ print(">>>>>>>>>>>>>>>>>请求参数")
|
|
|
print(dealImage.header)
|
|
|
result = dealImage.dealMoveImage(image_dir=image_dir, callback_func=None)
|
|
|
return result
|
|
|
|
|
|
-
|
|
|
#
|
|
|
# params = json.dump(request.query_params)
|
|
|
# #{'image_dir': 'D:/phpstudy_pro/WWW/auto_photo/output/2024-11-18', 'image_order': '俯视,侧视,后跟,鞋底,内里', 'is_check_number': True, 'resize_image_view': '后跟', 'cutout_mode': '1', 'logo_path': '', 'special_goods_art_no_folder_line': '', 'is_use_excel': True, 'excel_path': '', 'is_check_color_is_all': True, 'assigned_page_dict': {}, 'temp_class': {'huilima-2': <class 'detail_template.huilima.detail_huilima2.DetailPicGet'>, 'huilima-3': <class 'detail_template.huilima.detail_huilima3.DetailPicGet'>, 'huilima-4': <class 'detail_template.huilima.detail_huilima4.DetailPicGet'>, 'huilima-1': <class 'detail_template.huilima.detail_huilima1.DetailPicGet'>}, 'temp_name': 'huilima-2', 'temp_name_list': ['huilima-2', 'huilima-3', 'huilima-4', 'huilima-1'], 'target_error_folder': 'D:/phpstudy_pro/WWW/auto_photo/output/2024-11-18/软件-生成详情错误'}
|
|
|
@@ -145,13 +148,17 @@ async def handle_detail(request: Request):
|
|
|
# 'target_error_folder': 'D:/phpstudy_pro/WWW/auto_photo/output/2024-11-18/软件-生成详情错误'
|
|
|
# }
|
|
|
|
|
|
+
|
|
|
@app.post("/get_device_configs", description="获取可执行程序命令列表")
|
|
|
def get_device_configs(params: ModelGetDeviceConfig):
|
|
|
mode_type = params.mode_type
|
|
|
session = SqlQuery()
|
|
|
configModel = CRUD(DeviceConfig)
|
|
|
configList = configModel.read_all(
|
|
|
- session, conditions={"mode_type": mode_type}, order_by="action_index", ascending=True
|
|
|
+ session,
|
|
|
+ conditions={"mode_type": mode_type},
|
|
|
+ order_by="action_index",
|
|
|
+ ascending=True,
|
|
|
)
|
|
|
return {"code": 0, "msg": "", "data": {"list": configList}}
|
|
|
|
|
|
@@ -201,7 +208,7 @@ def save_device_config(params: SaveDeviceConfig):
|
|
|
@app.post("/reset_config", description="创建或修改一条可执行命令")
|
|
|
def reset_config(params: ModelGetDeviceConfig):
|
|
|
mode_type = params.mode_type
|
|
|
- if mode_type == None or mode_type == "":
|
|
|
+ if mode_type == None or mode_type == "":
|
|
|
return {"code": 1, "msg": "参数错误", "data": None}
|
|
|
session = SqlQuery()
|
|
|
deviceConfig = CRUD(DeviceConfig)
|
|
|
@@ -218,7 +225,7 @@ def reset_config(params: ModelGetDeviceConfig):
|
|
|
|
|
|
|
|
|
@app.get("/get_photo_records", description="获取拍照记录")
|
|
|
-def get_photo_records(page: int=1,size:int=5):
|
|
|
+def get_photo_records(page: int = 1, size: int = 5):
|
|
|
|
|
|
session = SqlQuery()
|
|
|
photos = CRUD(PhotoRecord)
|
|
|
@@ -232,7 +239,9 @@ def get_photo_records(page: int=1,size:int=5):
|
|
|
list = []
|
|
|
result = session.exec(statement).all()
|
|
|
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,
|
|
|
@@ -250,7 +259,8 @@ def get_photo_records(page: int=1,size:int=5):
|
|
|
|
|
|
@app.get("/get_photo_record_detail", description="通过货号获取拍照记录详情")
|
|
|
def get_photo_records(goods_art_no: str = None):
|
|
|
- if goods_art_no == None: return {"code": 1, "msg": "参数错误", "data": None}
|
|
|
+ if goods_art_no == None:
|
|
|
+ return {"code": 1, "msg": "参数错误", "data": None}
|
|
|
session = SqlQuery()
|
|
|
photos = CRUD(PhotoRecord)
|
|
|
items = photos.read_all(session, conditions={"goods_art_no": goods_art_no})
|
|
|
@@ -275,3 +285,31 @@ def delect_goods_arts(params: PhotoRecordDelete):
|
|
|
"msg": "操作成功",
|
|
|
"data": None,
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+@app.get("/get_sys_config", description="查询系统配置")
|
|
|
+def get_sys_config(key: str = None):
|
|
|
+ if key == None:
|
|
|
+ return {"code": 1, "msg": "参数错误", "data": None}
|
|
|
+ session = SqlQuery()
|
|
|
+ photos = CRUD(SysConfigs)
|
|
|
+ item = photos.read(session, conditions={"key": key})
|
|
|
+ session.close()
|
|
|
+ return {
|
|
|
+ "code": 0,
|
|
|
+ "msg": "",
|
|
|
+ "data": json.loads(item.value),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+@app.post("/update_sys_configs", description="创建或修改系统配置")
|
|
|
+def save_sys_configs(params: SysConfigParams):
|
|
|
+ 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)
|
|
|
+ return {"code": 0, "msg": "操作成功", "data": save_device_config}
|