Browse Source

Merge branch 'dev-python' of gitlab.pubdata.cn:liangyibo/CameraMachine into dev-python

# Conflicts:
#	python/api.py
zhangyh 8 months ago
parent
commit
be961a17b9

+ 230 - 124
python/action.json

@@ -1,124 +1,230 @@
-{
-    "type": "left",
-    "actions": [
-        {
-            "id": 1,
-            "mode_type": "执行左脚程序",
-            "execution_type": "程序1",
-            "action_name": "左脚俯拍鞋子",
-            "action_index": 20,
-            "picture_index": 99,
-            "camera_height": 100,
-            "camera_angle": 14.0,
-            "number_focus": 2,
-            "take_picture": true,
-            "turntable_position": 300.0,
-            "turntable_angle": -32.0,
-            "shoe_upturn": false,
-            "pre_delay": 0.0,
-            "after_delay": 0.0,
-            "led_switch": false,
-            "is_wait": false,
-            "is_need_confirm": false
-        },{
-            "id": 2,
-            "mode_type": "执行左脚程序",
-            "execution_type": "程序1",
-            "action_name": "侧视图",
-            "action_index": 10,
-            "picture_index": 99,
-            "camera_height": 0,
-            "camera_angle": 3.0,
-            "number_focus": 0,
-            "take_picture": true,
-            "turntable_position": 300.0,
-            "turntable_angle": 0.0,
-            "shoe_upturn": false,
-            "pre_delay": 0.0,
-            "after_delay": 0.0,
-            "led_switch": false,
-            "is_wait": false,
-            "is_need_confirm": false
-        },
-        {
-            "id": 3,
-            "mode_type": "执行左脚程序",
-            "execution_type": "程序1",
-            "action_name": "拍后跟",
-            "action_index": 30,
-            "picture_index": 99,
-            "camera_height": 0,
-            "camera_angle": 3.0,
-            "number_focus": 0,
-            "take_picture": true,
-            "turntable_position": 450.0,
-            "turntable_angle": 70.0,
-            "shoe_upturn": false,
-            "pre_delay": 0.0,
-            "after_delay": 0.0,
-            "led_switch": false,
-            "is_wait": false,
-            "is_need_confirm": false
-        },
-        {
-            "id": 4,
-            "mode_type": "执行左脚程序",
-            "execution_type": "程序2",
-            "action_name": "拍鞋底",
-            "action_index": 40,
-            "picture_index": 99,
-            "camera_height": 0,
-            "camera_angle": 3.0,
-            "number_focus": 0,
-            "take_picture": true,
-            "turntable_position": 100.0,
-            "turntable_angle": 0.0,
-            "shoe_upturn": true,
-            "pre_delay": 0.0,
-            "after_delay": 0.0,
-            "led_switch": false,
-            "is_wait": false,
-            "is_need_confirm": false
-        },
-        {
-            "id": 5,
-            "mode_type": "执行左脚程序",
-            "execution_type": "程序2",
-            "action_name": "拍内里",
-            "action_index": 50,
-            "picture_index": 99,
-            "camera_height": 0,
-            "camera_angle": 3.0,
-            "number_focus": 0,
-            "take_picture": true,
-            "turntable_position": 500.0,
-            "turntable_angle": 180.0,
-            "shoe_upturn": false,
-            "pre_delay": 0.0,
-            "after_delay": 0.0,
-            "led_switch": false,
-            "is_wait": false,
-            "is_need_confirm": false
-        },
-        {
-            "id": 6,
-            "mode_type": "执行左脚程序",
-            "execution_type": "程序2",
-            "action_name": "初始化位置",
-            "action_index": 60,
-            "picture_index": 99,
-            "camera_height": 200,
-            "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
-        }
-    ]
-}
+[
+    {
+        "mode_type": "执行左脚程序",
+        "execution_type": "程序1",
+        "action_name": "左脚俯拍鞋子",
+        "action_index": 20,
+        "picture_index": 99,
+        "camera_height": 200,
+        "camera_angle": 14.0,
+        "number_focus": 2,
+        "take_picture": true,
+        "turntable_position": 300.0,
+        "turntable_angle": -32.0,
+        "shoe_upturn": false,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "led_switch": false,
+        "is_wait": false,
+        "is_need_confirm": false
+    },
+    {
+        "mode_type": "执行左脚程序",
+        "execution_type": "程序1",
+        "action_name": "侧视图",
+        "action_index": 10,
+        "picture_index": 99,
+        "camera_height": 0,
+        "camera_angle": 3.0,
+        "number_focus": 0,
+        "take_picture": true,
+        "turntable_position": 300.0,
+        "turntable_angle": 0.0,
+        "shoe_upturn": false,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "led_switch": false,
+        "is_wait": false,
+        "is_need_confirm": false
+    },
+    {
+        "mode_type": "执行左脚程序",
+        "execution_type": "程序1",
+        "action_name": "拍后跟",
+        "action_index": 30,
+        "picture_index": 99,
+        "camera_height": 0,
+        "camera_angle": 3.0,
+        "number_focus": 0,
+        "take_picture": true,
+        "turntable_position": 450.0,
+        "turntable_angle": 70.0,
+        "shoe_upturn": false,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "led_switch": false,
+        "is_wait": false,
+        "is_need_confirm": false
+    },
+    {
+        "mode_type": "执行左脚程序",
+        "execution_type": "程序2",
+        "action_name": "拍鞋底",
+        "action_index": 40,
+        "picture_index": 99,
+        "camera_height": 0,
+        "camera_angle": 3.0,
+        "number_focus": 0,
+        "take_picture": true,
+        "turntable_position": 100.0,
+        "turntable_angle": 0.0,
+        "shoe_upturn": true,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "led_switch": false,
+        "is_wait": false,
+        "is_need_confirm": false
+    },
+    {
+        "mode_type": "执行左脚程序",
+        "execution_type": "程序2",
+        "action_name": "拍内里",
+        "action_index": 50,
+        "picture_index": 99,
+        "camera_height": 0,
+        "camera_angle": 3.0,
+        "number_focus": 0,
+        "take_picture": true,
+        "turntable_position": 500.0,
+        "turntable_angle": 180.0,
+        "shoe_upturn": false,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "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,
+        "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
+    },
+    {
+        "mode_type": "执行右脚程序",
+        "execution_type": "程序1",
+        "action_name": "右脚俯拍鞋子",
+        "action_index": 20,
+        "picture_index": 99,
+        "camera_height": 200,
+        "camera_angle": 14.0,
+        "number_focus": 2,
+        "take_picture": true,
+        "turntable_position": 300.0,
+        "turntable_angle": -32.0,
+        "shoe_upturn": false,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "led_switch": false,
+        "is_wait": false,
+        "is_need_confirm": false
+    },
+    {
+        "mode_type": "执行右脚程序",
+        "execution_type": "程序1",
+        "action_name": "侧视图",
+        "action_index": 10,
+        "picture_index": 99,
+        "camera_height": 0,
+        "camera_angle": 3.0,
+        "number_focus": 0,
+        "take_picture": true,
+        "turntable_position": 300.0,
+        "turntable_angle": 0.0,
+        "shoe_upturn": false,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "led_switch": false,
+        "is_wait": false,
+        "is_need_confirm": false
+    },
+    {
+        "mode_type": "执行右脚程序",
+        "execution_type": "程序1",
+        "action_name": "拍后跟",
+        "action_index": 30,
+        "picture_index": 99,
+        "camera_height": 0,
+        "camera_angle": 3.0,
+        "number_focus": 0,
+        "take_picture": true,
+        "turntable_position": 450.0,
+        "turntable_angle": 70.0,
+        "shoe_upturn": false,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "led_switch": false,
+        "is_wait": false,
+        "is_need_confirm": false
+    },
+    {
+        "mode_type": "执行右脚程序",
+        "execution_type": "程序2",
+        "action_name": "拍鞋底",
+        "action_index": 40,
+        "picture_index": 99,
+        "camera_height": 0,
+        "camera_angle": 3.0,
+        "number_focus": 0,
+        "take_picture": true,
+        "turntable_position": 100.0,
+        "turntable_angle": 0.0,
+        "shoe_upturn": true,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "led_switch": false,
+        "is_wait": false,
+        "is_need_confirm": false
+    },
+    {
+        "mode_type": "执行右脚程序",
+        "execution_type": "程序2",
+        "action_name": "拍内里",
+        "action_index": 50,
+        "picture_index": 99,
+        "camera_height": 0,
+        "camera_angle": 3.0,
+        "number_focus": 0,
+        "take_picture": true,
+        "turntable_position": 500.0,
+        "turntable_angle": 180.0,
+        "shoe_upturn": false,
+        "pre_delay": 0.0,
+        "after_delay": 0.0,
+        "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,
+        "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
+    }
+]

+ 46 - 0
python/api.py

@@ -1,3 +1,4 @@
+from natsort.natsort import order_by_index
 from models import *
 import requests
 import json
@@ -8,6 +9,7 @@ from sockets.socket_client import socket_manager
 from mcu.DeviceControl import DeviceControl
 import time
 from service.base_deal import  BaseDealImage
+from databases import DeviceConfig,SqlQuery,CRUD
 
 @app.get("/")
 async def index():
@@ -136,3 +138,47 @@ async def forwardRequest(request: HlmForwardRequest):
             'temp_name_list': ['huilima-2', 'huilima-3', 'huilima-4', 'huilima-1'],
             '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
+    )
+    return {"code": 0, "msg": "", "data": {"list": configList}}
+
+
+@app.post("/device_config_detail", description="获取可执行程序详情")
+def get_device_configs(params: ModelGetDeviceConfigDetail):
+    action_id = params.id
+    session = SqlQuery()
+    configModel = CRUD(DeviceConfig)
+    configList = configModel.read(session, obj_id=action_id)
+    return {"code": 0, "msg": "", "data": configList}
+
+
+@app.post("/remove_config", description="删除一条可执行命令")
+def get_device_configs(params: ModelGetDeviceConfigDetail):
+    action_id = params.id
+    session = SqlQuery()
+    configModel = CRUD(DeviceConfig)
+    configList = configModel.delete(session, obj_id=action_id)
+    return {"code": 0, "msg": "删除成功", "data": None}
+
+
+@app.post("/save_device_config", description="创建或修改一条可执行命令")
+def save_device_config(params: SaveDeviceConfig):
+    action_id = params.id
+    session = SqlQuery()
+    deviceConfig = CRUD(DeviceConfig)
+    if action_id == None or action_id == 0:
+        # 走新增逻辑
+        params.id = None
+        save_device_config = deviceConfig.create(session, obj_in=params)
+    else:
+        # 走编辑逻辑
+        kwargs = params.__dict__
+        save_device_config = deviceConfig.update(session, obj_id=action_id, **kwargs)
+    return {"code": 0, "msg": "操作成功", "data": save_device_config}

+ 1 - 1
python/config.ini

@@ -10,7 +10,7 @@ app_run=api:app
 # 端口号
 port=7074
 debug=true
-env=prod
+env=dev
 # 线程数
 works=1
 [log]

BIN
python/database.db


+ 131 - 0
python/databases.py

@@ -0,0 +1,131 @@
+from networkx.algorithms.components import connected
+from sqlmodel import Field, Session, SQLModel, create_engine, select
+from typing import Dict
+from datetime import datetime
+from typing import Optional
+import json
+from sqlalchemy import and_, asc,desc
+from model import DeviceConfig, PhotoRecord
+
+
+# 创建SQLite数据库引擎
+sqlite_file_name = "database.db"
+sqlite_url = f"sqlite:///{sqlite_file_name}"
+engine = create_engine(sqlite_url, echo=True)
+
+# 创建表
+def create_all_database():
+    SQLModel.metadata.create_all(engine)
+# 创建会话
+def __get_session():
+    with Session(engine) as session:
+        yield session
+
+
+def batch_insert_device_configs(session: Session, data_list: list):
+    '''批量插入数据到设备配置表'''
+    for data in data_list:
+        device_config = DeviceConfig(**data)
+        session.add(device_config)
+    session.commit()
+
+
+# 创建一个通用的 CRUD 类
+class CRUD:
+    def __init__(self, model):
+        self.model = model
+
+    def create(self, session: Session, obj_in):
+        obj_in_data = dict(obj_in)
+        db_obj = self.model(**obj_in_data)
+        session.add(db_obj)
+        session.commit()
+        session.refresh(db_obj)
+        return db_obj
+
+    def read(self, session: Session, obj_id: int):
+        return session.get(self.model, obj_id)
+
+    def read_all(
+        self,
+        session: Session,
+        conditions: Optional[Dict] = None,
+        order_by: Optional[str] = None,
+        ascending: bool = True,
+    ):
+        query = select(self.model)
+        if conditions:
+            query = query.where(and_(*(getattr(self.model, key) == value for key, value in conditions.items())))
+        if order_by:
+            if ascending:
+                query = query.order_by(asc(getattr(self.model, order_by)))
+            else:
+                query = query.order_by(desc(getattr(self.model, order_by)))
+        return session.exec(query).all()
+
+    def update(self, session: Session, obj_id: int, **kwargs):
+        db_obj = session.get(self.model, obj_id)
+        for key, value in kwargs.items():
+            if value == None or value =="":
+                continue
+            setattr(db_obj, key, value)
+        session.commit()
+        session.refresh(db_obj)
+        return db_obj
+
+    def delete(self, session: Session, obj_id: int):
+        db_obj = session.get(self.model, obj_id)
+        session.delete(db_obj)
+        session.commit()
+
+def SqlQuery():
+    return next(__get_session())
+
+# 使用示例
+if __name__ == "__main__":
+    pass
+    # 使用 next 函数从生成器中获取 Session 对象
+    # session = SqlQuery()
+
+    # 创建 CRUD 实例
+    # device_config_crud = CRUD(DeviceConfig)
+
+    # 创建新记录
+    # new_device_config = DeviceConfig(
+    #     mode_type="example_mode",
+    #     execution_type="example_execution",
+    #     action_name="example_action",
+    #     action_index=1,
+    #     picture_index=1,
+    #     camera_height=100,
+    #     camera_angle=45.5,
+    #     number_focus=2,
+    #     take_picture=True,
+    #     turntable_position=10.0,
+    #     turntable_angle=30.5,
+    #     shoe_upturn=False,
+    #     pre_delay=1.5,
+    #     after_delay=2.5,
+    #     led_switch=True,
+    #     is_wait=False,
+    # )
+    # created_device_config = device_config_crud.create(session, new_device_config)
+    # print(f"Created Device Config: {created_device_config}")
+
+    # 读取记录
+    # read_device = device_config_crud.read(session, 1)
+    # print(f"Read Device Config: {read_device.model_dump()}")
+
+    # 读取所有记录
+    # all_devices = device_config_crud.read_all(session, conditions={"id": 2})
+    # print(f"All Device Configs: {[device.model_dump() for device in all_devices]}")
+
+    # # 更新记录
+    # updated_device = device_config_crud.update(
+    #     session, created_device_config.id, mode_type="updated_mode"
+    # )
+    # print(f"Updated Device Config: {updated_device}")
+
+    # # 删除记录
+    # device_config_crud.delete(session, created_device_config.id)
+    # print("Device Config deleted.")

+ 9 - 1
python/index.py

@@ -21,6 +21,7 @@ def handle_shutdown(signum, frame):
 
 async def run_server():
     # 启动uvicorn服务器
+    isDebug = True if IS_DEBUG == "true" else False
     config = uvicorn.Config(
         APP_RUN,
         host=APP_HOST,
@@ -40,5 +41,12 @@ if __name__ == "__main__":
     signal.signal(signal.SIGTERM, handle_shutdown)
     print("python server is running at port:", PORT)
     print("python server is running at port:", APP_RUN)
+    # asyncio.run(main())
     isDebug = True if IS_DEBUG == "true" else False
-    asyncio.run(main())
+    uvicorn.run(
+        app=APP_RUN,
+        host=APP_HOST,
+        port=int(PORT),
+        reload=isDebug,
+        loop="auto",
+    )

+ 2 - 2
python/mcu/ProgramItem.py

@@ -24,7 +24,7 @@ class ProgramItem(BaseClass):
         print(action_data)
         self.action_id = self.get_value(action_data, "id")
         self.mode_type = self.get_value(action_data, "mode_type")
-        self.action_type = self.get_value(action_data, "execution_type", "程序1")
+        # self.action_type = self.get_value(action_data, "execution_type", "程序1")
         self.action_name = self.get_value(action_data, "action_name", "")
         self.is_wait = self.get_value(action_data, "is_wait", False)
         self.is_need_confirm = self.get_value(action_data, "is_need_confirm", False)
@@ -265,7 +265,7 @@ class ProgramItem(BaseClass):
             self.capture_one.photograph(is_af=is_af)
             self.last_photograph_time = time.time()  # 记录最近一次拍照时间
         # print("{} 拍照时间:{}".format(self.action_name, time.time() - start_time))
-        print("{}-{}已完成".format(self.action_type, self.action_name))
+        print("{}-{}已完成".format(self.mode_type, self.action_name))
 
         if True:
             if self.after_delay_time:

+ 15 - 2
python/middleware.py

@@ -8,8 +8,9 @@ from fastapi.middleware.cors import CORSMiddleware
 from starlette.exceptions import HTTPException
 from settings import *
 import random
-import os
+import os, json
 from pydantic import BaseModel, validator, conint, constr, Field
+from databases import create_all_database, DeviceConfig, CRUD, SqlQuery,batch_insert_device_configs
 
 # 关闭文档
 app = FastAPI()
@@ -32,11 +33,24 @@ app.add_middleware(
 )
 
 
+@app.on_event("startup")
+def on_startup():
+    create_all_database()
+    session = SqlQuery()
+    device_config_crud = CRUD(DeviceConfig)
+    all_devices = device_config_crud.read_all(session, conditions={"id": 2})
+    if len(all_devices) == 0:
+        # 如果配置表中一条数据都没有,就将初始化数据全部插入到数据表中
+        actions = json.load(open("action.json", encoding="utf-8"))
+        batch_insert_device_configs(session,actions)
+
+
 class UnicornException(Exception):
     def __init__(self, msg: str, code: int = -1):
         self.msg = msg
         self.code = code
 
+
 @app.exception_handler(UnicornException)
 async def error_throw(request: Request, exc: UnicornException):
 
@@ -58,4 +72,3 @@ async def global_exception_handler(request, exc):
     return JSONResponse(
         {"code": exc.status_code, "err_msg": err_msg, "status": "Failed"}
     )
-

+ 2 - 0
python/model/__init__.py

@@ -0,0 +1,2 @@
+from .device_config import DeviceConfig
+from .photo_record import PhotoRecord

+ 31 - 0
python/model/device_config.py

@@ -0,0 +1,31 @@
+from typing import Optional
+from datetime import datetime
+from sqlmodel import Field, SQLModel
+# 定义DeviceConfig模型类
+
+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)
+    action_name: Optional[str] = Field(
+        default=None, index=True, max_length=128, description="动作名称"
+    )
+    action_status: Optional[bool] = Field(default=True,description="是否启用;true或者false")
+    action_index: Optional[int] = Field(default=999,description="排序,默认999")
+    camera_height: Optional[int] = Field(default=None, description="相机高度;步长1;最小0;最大400")
+    camera_angle: Optional[float] = Field(default=None, description="相机倾角;步长0.1,最小-40;最大40")
+    number_focus: Optional[int] = Field(default=None, description="对焦次数;最小0;最大1")
+    take_picture: Optional[bool] = Field(default=False, description="是否拍照")
+    turntable_position: Optional[float] = Field(default=None, description="转盘位置;步长1,最小0;最大800")
+    turntable_angle: Optional[float] = Field(default=None, description="转盘角度;步长1;最小-720;最大720")
+    shoe_upturn: Optional[bool] = Field(default=None, description="鞋子翻转;")
+    pre_delay: Optional[float] = Field(default=None, description="拍照前延迟;步长1;最小0;最大99")
+    after_delay: Optional[float] = Field(
+        default=None, description="拍照后延迟;步长1;最小0;最大99"
+    )
+    led_switch: Optional[bool] = Field(default=False, description="Led灯光开关;")
+    is_wait: Optional[bool] = Field(default=False, description="没用;")
+    is_need_confirm: Optional[bool] = Field(default=False, description="没用;")
+    update_time: Optional[datetime] = Field(default=None)
+    create_time: Optional[datetime] = Field(default_factory=datetime.utcnow)
+    delete_time: Optional[datetime] = Field(default=None)

+ 14 - 0
python/model/photo_record.py

@@ -0,0 +1,14 @@
+from sqlmodel import SQLModel, Field
+from datetime import datetime
+
+class PhotoRecord(SQLModel, table=True):
+    __tablename__ = "photo_record"
+
+    id: int = Field(default=None, primary_key=True, index=True)
+    goods_art_no: str = Field(max_length=128, nullable=False)
+    image_index: int = Field(default=None)
+    image_deal_mode: int = Field(default=None)
+    photo_create_time: datetime = Field(default=None)
+    update_time: datetime = Field(default=None)
+    create_time: datetime = Field(default_factory=datetime.utcnow)
+    delete_time: datetime = Field(default=None)

+ 40 - 0
python/models.py

@@ -1,6 +1,46 @@
+from sqlalchemy import false
 from middleware import *
+import datetime
+
 class HlmForwardRequest(BaseModel):
     method: str = Field(default="GET", description="请求方法")
     headers: dict = Field(default={}, description="请求头")
     target_url: str = Field(default="", description="目标地址")
     query_params:str = Field(default="", description="请求参数")
+
+
+class ModelGetDeviceConfig(BaseModel):
+    """获取可执行程序命令列表"""
+    mode_type: Optional[str] =Field(
+        default="执行左脚程序", description="类型,【执行左脚程序】或者【执行右脚程序】"
+    )
+
+
+class ModelGetDeviceConfigDetail(BaseModel):
+    """获取可执行程序命令列表"""
+
+    id: int = Field(
+        default=None, description="可执行程序得id"
+    )
+
+
+class SaveDeviceConfig(BaseModel):
+    """获取可执行程序命令列表"""
+
+    id: Optional[int] = Field(default=None, primary_key=True)
+    mode_type: Optional[str] = Field(default="", index=True, max_length=128)
+    action_name: Optional[str] = Field(default="", index=True, max_length=128)
+    action_index: Optional[int] = Field(default=None)
+    action_status: Optional[bool] = Field(default=None)
+    camera_height: Optional[int] = Field(default=None)
+    camera_angle: Optional[float] = Field(default=None)
+    number_focus: Optional[int] = Field(default=None)
+    take_picture: Optional[bool] = Field(default=None)
+    turntable_position: Optional[float] = Field(default=None)
+    turntable_angle: Optional[float] = Field(default=None)
+    shoe_upturn: Optional[bool] = Field(default=None)
+    pre_delay: Optional[float] = Field(default=None)
+    after_delay: Optional[float] = Field(default=None)
+    led_switch: Optional[bool] = Field(default=None)
+    is_wait: Optional[bool] = Field(default=False)
+    is_need_confirm: Optional[bool] = Field(default=False)

BIN
python/requestments.txt


+ 27 - 0
python/service/base_deal.py

@@ -17,6 +17,9 @@ from image_pic_deal import OnePicDeal
 from natsort import natsorted
 import os
 import  shutil
+import exifread
+import datetime
+from databases import DeviceConfig,SqlQuery,CRUD
 
 """
 照片自动货号匹配 将图片放置在指定文件夹下,并自动对应不同的货号进行整理
@@ -804,6 +807,30 @@ class BaseDealImage(object):
                 # self.set_progress()
                 self.lock.release()
 
+    def get_goods_art_no(self, date_time_original):
+        time_array = time.strptime(date_time_original, "%Y:%m:%d %H:%M:%S")
+
+        time_array = time.mktime(time_array)
+        datetime_obj = datetime.fromtimestamp(time_array)
+
+        session = SqlQuery()
+        configModel = CRUD(DeviceConfig)
+        configList = configModel.read_all(
+            session, conditions={"mode_type": mode_type}, order_by="action_index", ascending=True
+        )
+
+        result = (
+            self.session.query(PhotoRecord)
+            .filter(PhotoRecord.photo_create_time == datetime_obj)
+            .order_by(PhotoRecord.id.desc())
+            .first()
+        )
+        if result:
+            return result.goods_art_no, result.image_index, result.image_deal_mode
+        else:
+            return None
+
+
     def dealMoveImage(self, image_dir: str, callback_func=None) -> dict:
         if not self.check_path(image_dir=image_dir + "/历史"):
             return {'code': 1, 'msg': '文件夹创建失败', 'data': {}}

+ 1 - 1
python/setup.py

@@ -11,7 +11,7 @@ options = {
     "build_exe": {
         "build_exe": "./dist/",
         "excludes": ["*.txt"],
-        "include_files": ["config.ini"],
+        "include_files": ["config.ini","action.json"],
         "optimize": 2,
     }
 }

+ 18 - 7
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
 # socket消息发送逻辑处理方法
 async def handlerSend(
     manager: ConnectionManager, receiveData: str, websocket: WebSocket
@@ -54,14 +54,25 @@ async def handlerSend(
                 return
             device_ctrl = DeviceControl(websocket_manager=manager)
             device_ctrl.controlDevice(device_name, value)
-        case "run_mcu_config":
-            action = json.load(open('action.json',encoding='utf-8'))
-            left_actions = action.get("actions")
-            # data = manager.jsonMessage(code=0, msg="json消息", data=left_actions)
-            # await manager.send_personal_message(data, websocket)
+        case "run_mcu":
+            action_info = data.get("action", "执行左脚程序")
+            goods_art_no = data.get("goods_art_no", None)
+            if goods_art_no == None:
+                data = manager.jsonMessage(code=1, msg="goods_art_no不能为空")
+                await manager.send_personal_message(data, websocket)
+                return
+            session = SqlQuery()
+            crud = CRUD(DeviceConfig)
+            all_devices = crud.read_all(session, conditions={"mode_type": action_info})
+            if len(all_devices) == 0:
+                data = manager.jsonMessage(code=1, msg="当前没有可用配置")
+                await manager.send_personal_message(data, websocket)
+                return
+            action_list = [device.model_dump() for device in all_devices]
+            print("action_list", action_list)
             device_ctrl = DeviceControl(websocket_manager=manager)
             loop.create_task(
-                device_ctrl.run_mcu_config(left_actions, "123456789"),
+                device_ctrl.run_mcu_config(action_list, goods_art_no),
                 name="run_mcu_config",
             )
         case _: