rambo 7 miesięcy temu
rodzic
commit
c05db813f0

+ 10 - 50
python/action.json

@@ -1,6 +1,6 @@
 [
     {
-        "mode_type": "执行左脚程序",
+        "tab_id": 1,
         "execution_type": "程序1",
         "action_name": "俯视",
         "action_index": 10,
@@ -20,7 +20,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行左脚程序",
+        "tab_id": 1,
         "execution_type": "程序1",
         "action_name": "侧视",
         "action_index": 20,
@@ -40,7 +40,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行左脚程序",
+        "tab_id": 1,
         "execution_type": "程序1",
         "action_name": "后跟",
         "action_index": 30,
@@ -60,7 +60,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行左脚程序",
+        "tab_id": 1,
         "execution_type": "程序2",
         "action_name": "鞋底",
         "action_index": 40,
@@ -80,7 +80,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行左脚程序",
+        "tab_id": 1,
         "execution_type": "程序2",
         "action_name": "内里",
         "action_index": 50,
@@ -100,27 +100,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行左脚程序",
-        "execution_type": "程序2",
-        "action_name": "初始化位置",
-        "action_index": 60,
-        "picture_index": 99,
-        "camera_height": 200,
-        "camera_angle": 12.0,
-        "is_system": false,
-        "number_focus": 1,
-        "take_picture": false,
-        "turntable_position": 300.0,
-        "turntable_angle": 0.0,
-        "shoe_upturn": false,
-        "pre_delay": 0.0,
-        "after_delay": 0.0,
-        "led_switch": true,
-        "is_wait": false,
-        "is_need_confirm": false
-    },
-    {
-        "mode_type": "执行右脚程序",
+        "tab_id": 2,
         "execution_type": "程序2",
         "action_name": "俯视",
         "action_index": 10,
@@ -140,7 +120,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行右脚程序",
+        "tab_id": 2,
         "execution_type": "程序2",
         "action_name": "侧视",
         "action_index": 20,
@@ -160,7 +140,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行右脚程序",
+        "tab_id": 2,
         "execution_type": "程序2",
         "action_name": "后跟",
         "action_index": 30,
@@ -180,7 +160,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行右脚程序",
+        "tab_id": 2,
         "execution_type": "程序2",
         "action_name": "鞋底",
         "action_index": 40,
@@ -200,7 +180,7 @@
         "is_need_confirm": false
     },
     {
-        "mode_type": "执行右脚程序",
+        "tab_id": 2,
         "execution_type": "程序2",
         "action_name": "内里",
         "action_index": 50,
@@ -218,25 +198,5 @@
         "led_switch": false,
         "is_wait": false,
         "is_need_confirm": false
-    },
-    {
-        "mode_type": "执行右脚程序",
-        "execution_type": "程序2",
-        "action_name": "初始化位置",
-        "action_index": 60,
-        "picture_index": 99,
-        "camera_height": 200,
-        "is_system": false,
-        "camera_angle": 12.0,
-        "number_focus": 1,
-        "take_picture": false,
-        "turntable_position": 300.0,
-        "turntable_angle": 0.0,
-        "shoe_upturn": false,
-        "pre_delay": 0.0,
-        "after_delay": 0.0,
-        "led_switch": true,
-        "is_wait": false,
-        "is_need_confirm": false
     }
 ]

+ 50 - 0
python/action_tabs.json

@@ -0,0 +1,50 @@
+[
+    {
+        "mode_type": 0,
+        "mode_name": "执行左脚程序"
+    },
+    {
+        "mode_type": 0,
+        "mode_name": "自定义配置1"
+    },
+    {
+        "mode_type": 0,
+        "mode_name": "自定义配置2"
+    },
+    {
+        "mode_type": 0,
+        "mode_name": "自定义配置3"
+    },
+    {
+        "mode_type": 0,
+        "mode_name": "自定义配置4"
+    },
+    {
+        "mode_type": 0,
+        "mode_name": "自定义配置5"
+    },
+    {
+        "mode_type": 1,
+        "mode_name": "执行右脚程序"
+    },
+    {
+        "mode_type": 1,
+        "mode_name": "自定义配置1"
+    },
+    {
+        "mode_type": 1,
+        "mode_name": "自定义配置2"
+    },
+    {
+        "mode_type": 1,
+        "mode_name": "自定义配置3"
+    },
+    {
+        "mode_type": 1,
+        "mode_name": "自定义配置4"
+    },
+    {
+        "mode_type": 1,
+        "mode_name": "自定义配置5"
+    }
+]

+ 49 - 9
python/api.py

@@ -16,7 +16,7 @@ import time, shutil, os
 from sqlalchemy import and_, asc, desc
 from functools import partial
 from service.deal_image import DealImage
-from databases import DeviceConfig, SysConfigs, SqlQuery, CRUD, select
+from databases import DeviceConfig, SysConfigs, SqlQuery, CRUD, select,DeviceConfigTabs
 from service.run_main import RunMain
 import importlib
 from service.auto_deal_pics.upload_pic import UploadPic
@@ -382,14 +382,52 @@ async def handle_detail(request: Request, params: HandlerDetail):
     }
 
 
+@app.get("/get_device_tabs", description="获取可执行程序命令列表")
+def get_device_tabs(type:int):
+    session = SqlQuery()
+    statement = (
+        select(DeviceConfigTabs)
+        .where(DeviceConfigTabs.mode_type == type).order_by(asc("id"))
+    )
+    result = session.exec(statement).all()
+    session.close()
+    sys = CRUD(SysConfigs)
+    action_configs = sys.read(session, conditions={"key": "action_configs"})
+    session.close()
+    return {
+        "code": 0,
+        "msg": "",
+        "data": {"tabs": result, "select_configs": json.loads(action_configs.value)},
+    }
+
+
+@app.post("/update_tab_name", description="更改tab名称")
+def update_tab_name(params: DeviceConfigTabsReq):
+    if params.mode_name == "":
+        return {"code": 1, "msg": "名称不能为空", "data": {}}
+    session = SqlQuery()
+    tabModel = CRUD(DeviceConfigTabs)
+    kwargs = {"mode_name": params.mode_name}
+    tabModel.updateConditions(session, conditions={"id": params.id}, **kwargs)
+    session.close()
+    sys = CRUD(SysConfigs)
+    action_configs = sys.read(session, conditions={"key": "action_configs"})
+    session.close()
+    return {
+        "code": 0,
+        "msg": "",
+        "data": None,
+    }
+
+
 @app.post("/get_device_configs", description="获取可执行程序命令列表")
 def get_device_configs(params: ModelGetDeviceConfig):
-    mode_type = params.mode_type
+    tab_id = params.tab_id
     session = SqlQuery()
     configModel = CRUD(DeviceConfig)
     configList = configModel.read_all(
         session,
-        conditions={"mode_type": mode_type},
+        conditions={"tab_id": tab_id},
         order_by="action_index",
         ascending=True,
     )
@@ -413,11 +451,13 @@ def get_device_configs(params: ModelGetDeviceConfigDetail):
 
 @app.post("/device_config_detail_query", description="通过条件获取可执行程序详情")
 def get_device_configs(params: ModelGetDeviceConfigDetailQuery):
-    mode_type = params.mode_type
+    tab_id = params.tab_id
     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={"tab_id": tab_id, "action_name": action_name}
+    )
     if model == None:
         return {"code": 1, "msg": "数据不存在", "data": None}
     return {"code": 0, "msg": "", "data": model}
@@ -458,18 +498,18 @@ 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 == "":
+    tab_id = params.tab_id
+    if tab_id == None or tab_id == "":
         return {"code": 1, "msg": "参数错误", "data": None}
     session = SqlQuery()
     deviceConfig = CRUD(DeviceConfig)
-    res = deviceConfig.deleteConditions(session, conditions={"mode_type": mode_type})
+    res = deviceConfig.deleteConditions(session, conditions={"tab_id": tab_id})
     if res is False:
         return {"code": 1, "msg": "操作失败", "data": None}
     actions = json.load(open("action.json", encoding="utf-8"))
     act = []
     for item in actions:
-        if item.get("mode_type") == mode_type:
+        if item.get("tab_id") == tab_id:
             act.append(item)
     batch_insert_device_configs(session, act)
     return {"code": 0, "msg": "操作成功", "data": None}

+ 24 - 13
python/databases.py

@@ -7,7 +7,7 @@ import json
 from sqlalchemy import and_, desc, asc
 
 from sqlalchemy.dialects import sqlite
-from model import DeviceConfig, PhotoRecord, SysConfigs
+from model import DeviceConfig, PhotoRecord, SysConfigs, DeviceConfigTabs
 
 
 # 创建SQLite数据库引擎
@@ -37,11 +37,22 @@ def __get_session():
             session.close()
 
 
-def batch_insert_device_configs(session: Session, data_list: list):
+def batch_insert_device_configs(session: Session, action_tabs: list, data_list: list):
     """批量插入数据到设备配置表"""
-    for data in data_list:
-        device_config = DeviceConfig(**data)
-        session.add(device_config)
+    for idx, tab in enumerate(action_tabs):
+        crud = CRUD(DeviceConfigTabs)
+        device_tab = DeviceConfigTabs(
+            mode_type=tab.get("mode_type"),
+            mode_name=tab.get("mode_name"),
+        )
+        create_obj = crud.create(session, obj_in=device_tab)
+        for data in data_list:
+            data["tab_id"] = create_obj.id
+            data["is_system"] = False
+            if idx  in [0, 6]:
+                data["is_system"] = True
+            device_config = DeviceConfig(**data)
+            session.add(device_config)
     session.commit()
     session.close()
 
@@ -122,14 +133,14 @@ class CRUD:
     ):
         query = select(self.model)
         if conditions:
-            query = query.where(
-                and_(
-                    *(
-                        getattr(self.model, key) == value
-                        for key, value in conditions.items()
-                    )
-                )
-            )
+            for key, value in conditions.items():
+                column = getattr(self.model, key)
+                if isinstance(value, list):
+                    # 如果值是列表,使用 IN 查询
+                    query = query.where(column.in_(value))
+                else:
+                    # 否则使用等于条件
+                    query = query.where(column == value)
         if order_by:
             if ascending:
                 query = query.order_by(asc(getattr(self.model, order_by)))

+ 6 - 3
python/mcu/DeviceControl.py

@@ -133,8 +133,6 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         )
         self.msg_type = "mcu"
 
-    
-
     def setOtherMaxMinValue(self,item, value):
         value = int(value)
         parameter_limits = {
@@ -1371,10 +1369,12 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             return
         image_counts = 0
         if config_list:
+            action_names = []
             for idx, item in enumerate(config_list):
                 is_take_picture = item["take_picture"]
                 action_id = item["id"]
                 if is_take_picture:
+                    action_names.append(item["action_name"])
                     image_counts += 1
                     # 批量插入
                     image_deal_mode = 0 if action_info == "执行左脚程序" else 1
@@ -1394,7 +1394,10 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 data={
                     "goods_art_no": goods_art_no,
                     "image_counts": image_counts,
-                    "current_time":datetime.datetime.now(settings.TIME_ZONE).strftime("%Y-%m-%d %H:%M:%S"),
+                    "action_names": action_names,
+                    "current_time": datetime.datetime.now(settings.TIME_ZONE).strftime(
+                        "%Y-%m-%d %H:%M:%S"
+                    ),
                 },
             )
             self.controlDevice("laser_position", 0)

+ 1 - 0
python/model/__init__.py

@@ -1,3 +1,4 @@
 from .device_config import DeviceConfig
 from .photo_record import PhotoRecord
 from .sys_configs import SysConfigs
+from .device_config_tabs import DeviceConfigTabs

+ 1 - 1
python/model/device_config.py

@@ -6,7 +6,7 @@ from sqlmodel import Field, SQLModel
 class DeviceConfig(SQLModel, table=True):
     __tablename__ = "device_config"
     id: Optional[int] = Field(default=None, primary_key=True)
-    mode_type: Optional[str] = Field(default="执行左脚程序", index=True, max_length=128)
+    tab_id: Optional[int] = Field(default=None, index=True, max_length=11)
     action_name: Optional[str] = Field(
         default=None, index=True, max_length=128, description="动作名称"
     )

+ 12 - 0
python/model/device_config_tabs.py

@@ -0,0 +1,12 @@
+from typing import Optional
+from datetime import datetime
+from sqlmodel import Field, SQLModel
+# 定义DeviceConfig模型类
+
+class DeviceConfigTabs(SQLModel, table=True):
+    __tablename__ = "device_config_tabs"
+    id: Optional[int] = Field(default=None, primary_key=True)
+    mode_name: Optional[str] = Field(default="执行左脚程序", index=True, max_length=128)
+    mode_type: Optional[int] = Field(
+        default=0, index=True, max_length=128, description="动作类型;0左脚;1右脚"
+    )

+ 10 - 5
python/models.py

@@ -10,8 +10,8 @@ class HlmForwardRequest(BaseModel):
 
 class ModelGetDeviceConfig(BaseModel):
     """获取可执行程序命令列表"""
-    mode_type: Optional[str] =Field(
-        default="执行左脚程序", description="类型,【执行左脚程序】或者【执行右脚程序】"
+    tab_id: int =Field(
+        default=1, description="类型,【执行左脚程序】或者【执行右脚程序】"
     )
 
 
@@ -26,7 +26,7 @@ class ModelGetDeviceConfigDetail(BaseModel):
 class ModelGetDeviceConfigDetailQuery(BaseModel):
     """获取可执行程序命令列表"""
 
-    mode_type: Optional[str] = Field(default="执行左脚程序", index=True, max_length=128)
+    tab_id: int = Field(default=1, index=True, max_length=128)
     action_name: Optional[str] = Field(default="", index=True, max_length=128)
 
 
@@ -94,7 +94,12 @@ class LogoParams(BaseModel):
     """logo参数"""
 
     logo_path: str = Field(default="", description="logo地址路径")
-    
+
 class LogoParamsupdate(BaseModel):
     """系统配置"""
-    path: str = Field(default=None, description="要删除得文件路径")
+    path: str = Field(default=None, description="要删除得文件路径")
+
+
+class DeviceConfigTabsReq(BaseModel):
+    id: int = Field(default=None, primary_key=True)
+    mode_name: str = Field(default="", description="Tab名称")

+ 2 - 1
python/settings.py

@@ -20,8 +20,9 @@ device_config_crud = CRUD(DeviceConfig)
 all_devices = device_config_crud.read_all(session)
 if len(all_devices) == 0:
     # 如果配置表中一条数据都没有,就将初始化数据全部插入到数据表中
+    action_tabs = json.load(open("action_tabs.json", encoding="utf-8"))
     actions = json.load(open("action.json", encoding="utf-8"))
-    batch_insert_device_configs(session, actions)
+    batch_insert_device_configs(session, action_tabs, actions)
 sys_config_crud = CRUD(SysConfigs)
 all_sys_configs = sys_config_crud.read_all(session)
 if len(all_sys_configs) == 0:

+ 11 - 2
python/sockets/message_handler.py

@@ -3,7 +3,7 @@ from models import WebSocket
 import json, asyncio
 from mcu.DeviceControl import DeviceControl, checkMcuConnection
 from mcu.BlueToothMode import BlueToothMode
-from databases import DeviceConfig,SqlQuery,CRUD,PhotoRecord
+from databases import DeviceConfig, SqlQuery, CRUD, PhotoRecord, SysConfigs
 from mcu.capture.module_digicam import DigiCam
 
 # socket消息发送逻辑处理方法
@@ -95,6 +95,15 @@ async def handlerSend(
                 await manager.send_personal_message(data, websocket)
                 return
             session = SqlQuery()
+            sys_configs = CRUD(SysConfigs)
+            action_configs = sys_configs.read(
+                session, conditions={"key": "action_configs"}
+            )
+            action_configs_json = json.loads(action_configs.value)
+            action_flag = "left"
+            if "右" in action_info:
+                action_flag = "right"
+            tab_id = action_configs_json.get(action_flag)
             photoRecord = CRUD(PhotoRecord)
             goods_art_record = photoRecord.read(session,conditions={"goods_art_no": goods_art_no})
             if goods_art_record != None:
@@ -106,7 +115,7 @@ async def handlerSend(
                 await manager.send_personal_message(data, websocket)
                 return
             crud = CRUD(DeviceConfig)
-            condtions = {"mode_type": action_info, "action_status": True}
+            condtions = {"tab_id": tab_id}
             all_devices = crud.read_all(
                 session, conditions=condtions, order_by="action_index", ascending=True
             )

+ 2 - 2
python/sys_configs.json

@@ -12,7 +12,7 @@
         "value": "{\"product_type\":\"鞋类\",\"cutout_mode\":\"普通抠图\",\"device_speed\":\"二档\",\"running_mode\":\"普通模式\"}"
     },
     {
-        "key": "logo_configs",
-        "value": "[]"
+        "key": "action_configs",
+        "value": "{\"left\":1,\"right\":7}"
     }
 ]

+ 9 - 19
python/temp.py

@@ -1,21 +1,11 @@
-# from databases import CRUD, SqlQuery, PhotoRecord, insert_photo_records
-# from datetime import datetime
+from databases import CRUD, SqlQuery, PhotoRecord, insert_photo_records, DeviceConfig,DeviceConfigTabs
+from datetime import datetime
 
-# session = SqlQuery()
-# crud = CRUD(PhotoRecord)
-# record = crud.read(session=session, order_by="id", ascending=False)
-# if record == None:
-#     # 发送失败消息
-#     pass
-# else:
-#     insert_photo_records(
-#         record.image_deal_mode, record.goods_art_no, record.image_index+1
-#     )
-import time, shutil
-from utils.utils_func import check_path
-dst_path = "C:/Development/project/python/CameraMachine/build/extraResources/py/data/"
-check_path(dst_path)
-shutil.copy(
-    "C:\Development\project\python\auto_photo\data\DSC_0438.jpg",
-    dst_path,
+session = SqlQuery()
+crud = CRUD(DeviceConfigTabs)
+device_tab = DeviceConfigTabs(
+    mode_type=0,
+    mode_name='test',
 )
+create_obj = crud.create(session, obj_in=device_tab)
+print(create_obj.id)