|
@@ -14,6 +14,7 @@ from service.base import check_move_goods_art_no_folder
|
|
|
from service.deal_image import DealImage
|
|
from service.deal_image import DealImage
|
|
|
import settings
|
|
import settings
|
|
|
from middleware import UnicornException
|
|
from middleware import UnicornException
|
|
|
|
|
+from service.online_request.module_online_data import CategoryLink
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
from functools import partial
|
|
from functools import partial
|
|
|
from logger import logger
|
|
from logger import logger
|
|
@@ -24,6 +25,40 @@ from mcu.one_data_set_control import OneDataSet
|
|
|
executor = ThreadPoolExecutor(max_workers=4)
|
|
executor = ThreadPoolExecutor(max_workers=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def get_tab_id_by_category(session, goods_art_no, default_tab_id):
|
|
|
|
|
+ """
|
|
|
|
|
+ 通过货号请求线上分类,匹配sys_configs中key=category_links的配置来替换tab_id
|
|
|
|
|
+ :param session: 数据库会话
|
|
|
|
|
+ :param goods_art_no: 货号
|
|
|
|
|
+ :param default_tab_id: 默认tab_id(action_configs中的原值)
|
|
|
|
|
+ :return: 匹配到的tab_id;分类为空或未匹配到时返回default_tab_id
|
|
|
|
|
+ """
|
|
|
|
|
+ try:
|
|
|
|
|
+ # 请求线上接口,通过货号匹配分类名称
|
|
|
|
|
+ category_link = CategoryLink("Bearer " + (settings.USER_TOKEN or ""))
|
|
|
|
|
+ category_name = category_link.get_category_name(goods_art_no)
|
|
|
|
|
+ # 分类名称为空,继续使用上一行的tab_id
|
|
|
|
|
+ if not category_name:
|
|
|
|
|
+ return default_tab_id
|
|
|
|
|
+ # 读取sys_configs中category_links配置,格式:[{"category_name":"","tab_name":"","tab_id":123}]
|
|
|
|
|
+ sys_configs = CRUD(SysConfigs)
|
|
|
|
|
+ item = sys_configs.read(session, conditions={"key": "category_links"})
|
|
|
|
|
+ if item == None:
|
|
|
|
|
+ return default_tab_id
|
|
|
|
|
+ links = json.loads(item.value)
|
|
|
|
|
+ for link in links:
|
|
|
|
|
+ # 分类名称匹配成功,用配置中的tab_id覆盖上一行变量
|
|
|
|
|
+ if link.get("category_name") == category_name:
|
|
|
|
|
+ print("分类关联匹配成功:", category_name, "->", link.get("tab_id"))
|
|
|
|
|
+ return link.get("tab_id")
|
|
|
|
|
+ # 未匹配到分类,继续使用上一行的tab_id
|
|
|
|
|
+ return default_tab_id
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ # 异常不影响拍摄流程,回退到默认tab_id
|
|
|
|
|
+ logger.error(f"匹配分类关联异常: goods_art_no={goods_art_no}, error={str(e)}")
|
|
|
|
|
+ return default_tab_id
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
async def handlerCutOut(
|
|
async def handlerCutOut(
|
|
|
manager=None, run_main=None, config_data={}, websocket=None, msg_type=""
|
|
manager=None, run_main=None, config_data={}, websocket=None, msg_type=""
|
|
|
):
|
|
):
|
|
@@ -280,6 +315,7 @@ async def handlerSend(
|
|
|
msg_type = "run_mcu"
|
|
msg_type = "run_mcu"
|
|
|
action_info = data.get("action", "执行左脚程序")
|
|
action_info = data.get("action", "执行左脚程序")
|
|
|
goods_art_no = data.get("goods_art_no", None)
|
|
goods_art_no = data.get("goods_art_no", None)
|
|
|
|
|
+ company_id = data.get("company_id", None)
|
|
|
weight = data.get("weight", None)
|
|
weight = data.get("weight", None)
|
|
|
goods_art_no = goods_art_no.strip()
|
|
goods_art_no = goods_art_no.strip()
|
|
|
if goods_art_no == None or goods_art_no == "":
|
|
if goods_art_no == None or goods_art_no == "":
|
|
@@ -306,6 +342,11 @@ async def handlerSend(
|
|
|
if "右" in action_info:
|
|
if "右" in action_info:
|
|
|
action_flag = "right"
|
|
action_flag = "right"
|
|
|
tab_id = action_configs_json.get(action_flag)
|
|
tab_id = action_configs_json.get(action_flag)
|
|
|
|
|
+ # 指定企业开启分类关联匹配:dev环境-安恒(34398);prod环境-45064
|
|
|
|
|
+ # 通过货号匹配线上分类关联(category_links),匹配成功则覆盖tab_id,否则沿用默认tab_id
|
|
|
|
|
+ category_company_map = {"dev": 34398, "prod": 45064}
|
|
|
|
|
+ if company_id == category_company_map.get(settings.APPENV):
|
|
|
|
|
+ tab_id = get_tab_id_by_category(session, goods_art_no, tab_id)
|
|
|
photoRecord = CRUD(PhotoRecord)
|
|
photoRecord = CRUD(PhotoRecord)
|
|
|
goods_art_record = photoRecord.read(
|
|
goods_art_record = photoRecord.read(
|
|
|
session, conditions={"goods_art_no": goods_art_no, "delete_time": None}
|
|
session, conditions={"goods_art_no": goods_art_no, "delete_time": None}
|