|
@@ -34,6 +34,7 @@ from fastapi import BackgroundTasks
|
|
|
import functools
|
|
import functools
|
|
|
import traceback
|
|
import traceback
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def log_exception_with_context(context_message=""):
|
|
def log_exception_with_context(context_message=""):
|
|
|
"""装饰器:为函数添加异常日志上下文"""
|
|
"""装饰器:为函数添加异常日志上下文"""
|
|
|
|
|
|
|
@@ -66,16 +67,20 @@ def parserGoodsDict2Aigc(return_data_check_before_detail):
|
|
|
return goods_no_dict
|
|
return goods_no_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def sendAsyncMessage(msg="", goods_arts=[], status="",msg_type="",data=None):
|
|
|
|
|
|
|
+async def sendAsyncMessage(msg="", goods_arts=[], status="", msg_type="", data=None):
|
|
|
"""异步发送消息"""
|
|
"""异步发送消息"""
|
|
|
data = {
|
|
data = {
|
|
|
"code": 0,
|
|
"code": 0,
|
|
|
"msg": msg,
|
|
"msg": msg,
|
|
|
"status": 2,
|
|
"status": 2,
|
|
|
- "data": data if data is not None else {
|
|
|
|
|
- "status": status,
|
|
|
|
|
- "goods_art_nos": goods_arts,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ "data": (
|
|
|
|
|
+ data
|
|
|
|
|
+ if data is not None
|
|
|
|
|
+ else {
|
|
|
|
|
+ "status": status,
|
|
|
|
|
+ "goods_art_nos": goods_arts,
|
|
|
|
|
+ }
|
|
|
|
|
+ ),
|
|
|
"msg_type": msg_type,
|
|
"msg_type": msg_type,
|
|
|
}
|
|
}
|
|
|
await message_queue.put(data)
|
|
await message_queue.put(data)
|
|
@@ -593,7 +598,9 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
|
|
|
msg_type="scene_progress",
|
|
msg_type="scene_progress",
|
|
|
)
|
|
)
|
|
|
if new_goods_dict is not None or new_goods_dict != {}:
|
|
if new_goods_dict is not None or new_goods_dict != {}:
|
|
|
- return_data_check_before_detail["data"]["goods_no_dict"] = new_goods_dict
|
|
|
|
|
|
|
+ return_data_check_before_detail["data"][
|
|
|
|
|
+ "goods_no_dict"
|
|
|
|
|
+ ] = new_goods_dict
|
|
|
if is_upper_footer == 1:
|
|
if is_upper_footer == 1:
|
|
|
goods_dict = parserGoodsDict2Aigc(return_data_check_before_detail)
|
|
goods_dict = parserGoodsDict2Aigc(return_data_check_before_detail)
|
|
|
new_goods_dict = {}
|
|
new_goods_dict = {}
|
|
@@ -677,7 +684,7 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
|
|
|
status="开始处理详情页",
|
|
status="开始处理详情页",
|
|
|
msg_type="detail_progress",
|
|
msg_type="detail_progress",
|
|
|
)
|
|
)
|
|
|
- check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
|
|
|
|
|
+ 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):
|
|
if isinstance(check_for_detail_first_res, partial):
|
|
@@ -749,7 +756,7 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
|
|
|
result_goods_no_dict, online_stores=online_stores
|
|
result_goods_no_dict, online_stores=online_stores
|
|
|
)
|
|
)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print(f'上传任务出现错误:{e}')
|
|
|
|
|
|
|
+ print(f"上传任务出现错误:{e}")
|
|
|
await sendAsyncMessage(
|
|
await sendAsyncMessage(
|
|
|
msg="商品上传第三方成功",
|
|
msg="商品上传第三方成功",
|
|
|
goods_arts=[],
|
|
goods_arts=[],
|
|
@@ -1192,3 +1199,77 @@ def close_other_window():
|
|
|
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
|
|
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
|
|
|
return {"code": 0, "msg": "关闭成功", "data": {"status": True}}
|
|
return {"code": 0, "msg": "关闭成功", "data": {"status": True}}
|
|
|
return {"code": 0, "msg": "关闭失败", "data": {"status": False}}
|
|
return {"code": 0, "msg": "关闭失败", "data": {"status": False}}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@app.post("/sync_sys_configs", description="同步线上配置到本地")
|
|
|
|
|
+def sync_sys_configs(params: SyncLocalConfigs):
|
|
|
|
|
+ hlm_token = params.token
|
|
|
|
|
+ headers = {
|
|
|
|
|
+ "Authorization": f"Bearer {hlm_token}",
|
|
|
|
|
+ "content-type": "application/json",
|
|
|
|
|
+ }
|
|
|
|
|
+ url = settings.DOMAIN + "/api/ai_image/camera_machine/get_all_user_configs"
|
|
|
|
|
+ result = requests.get(url=url, headers=headers)
|
|
|
|
|
+ sys_configs = result.json().get("data", {}).get("configs")
|
|
|
|
|
+ session = SqlQuery()
|
|
|
|
|
+ sysConfigs = CRUD(SysConfigs)
|
|
|
|
|
+ if sys_configs:
|
|
|
|
|
+ sysConfigs.deleteConditions(session, {})
|
|
|
|
|
+ configList = []
|
|
|
|
|
+ for config_keys in sys_configs.keys():
|
|
|
|
|
+ sys_configs[config_keys]
|
|
|
|
|
+ configList.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "key": config_keys,
|
|
|
|
|
+ "value": json.dumps(sys_configs[config_keys], ensure_ascii=False),
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ batch_insert_sys_configs(session, configList)
|
|
|
|
|
+ else:
|
|
|
|
|
+ all_configs = sysConfigs.read_all(session)
|
|
|
|
|
+ localConfigData = {}
|
|
|
|
|
+ for local_config in all_configs:
|
|
|
|
|
+ localConfigData[local_config.key] = json.loads(local_config.value)
|
|
|
|
|
+ data_json = json.dumps({"configs": localConfigData}, ensure_ascii=False)
|
|
|
|
|
+ # 同步本地到线上
|
|
|
|
|
+ url = settings.DOMAIN + "/api/ai_image/camera_machine/update_all_user_configs"
|
|
|
|
|
+ requests.post(url=url, headers=headers, data=data_json)
|
|
|
|
|
+ return {"code": 0, "msg": "操作成功", "data": None}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@app.post("/sync_actions", description="同步左右脚配置到本地")
|
|
|
|
|
+def sync_action_configs(params: SyncLocalConfigs):
|
|
|
|
|
+ hlm_token = params.token
|
|
|
|
|
+ headers = {
|
|
|
|
|
+ "Authorization": f"Bearer {hlm_token}",
|
|
|
|
|
+ "content-type": "application/json",
|
|
|
|
|
+ }
|
|
|
|
|
+ url = settings.DOMAIN + "/api/ai_image/camera_machine/get_all_user_tabs"
|
|
|
|
|
+ result = requests.get(url=url, headers=headers)
|
|
|
|
|
+ session = SqlQuery()
|
|
|
|
|
+ deviceConfigs = CRUD(DeviceConfig)
|
|
|
|
|
+ deviceConfigTabs = CRUD(DeviceConfigTabs)
|
|
|
|
|
+ tabs = result.json().get("data", {}).get("tabs")
|
|
|
|
|
+ actions = result.json().get("data", {}).get("actions")
|
|
|
|
|
+ if tabs:
|
|
|
|
|
+ # 先删除再创建
|
|
|
|
|
+ deviceConfigTabs.deleteConditions(session, {})
|
|
|
|
|
+ deviceConfigs.deleteConditions(session, {})
|
|
|
|
|
+ batch_insert_device_configsNew(session, tabs, actions)
|
|
|
|
|
+ else:
|
|
|
|
|
+ all_actions = deviceConfigs.read_all(session)
|
|
|
|
|
+ all_tabs = deviceConfigTabs.read_all(session)
|
|
|
|
|
+ all_tabs_json = [item.model_dump(mode='json') for item in all_tabs]
|
|
|
|
|
+ all_actions_json = [item.model_dump(mode="json") for item in all_actions]
|
|
|
|
|
+ data_json = json.dumps(
|
|
|
|
|
+ {"tabs": all_tabs_json, "actions": all_actions_json}, ensure_ascii=False
|
|
|
|
|
+ )
|
|
|
|
|
+ sync_url = settings.DOMAIN + "/api/ai_image/camera_machine/sync_actions"
|
|
|
|
|
+ result = requests.post(url=sync_url, headers=headers, data=data_json)
|
|
|
|
|
+ tabs = result.json().get("data", {}).get("tabs")
|
|
|
|
|
+ actions = result.json().get("data", {}).get("actions")
|
|
|
|
|
+ if tabs:
|
|
|
|
|
+ deviceConfigTabs.deleteConditions(session, {})
|
|
|
|
|
+ deviceConfigs.deleteConditions(session, {})
|
|
|
|
|
+ batch_insert_device_configsNew(session, tabs, actions)
|
|
|
|
|
+ return {"code": 0, "msg": "操作成功", "data": None}
|