|
@@ -1,18 +1,19 @@
|
|
|
from natsort.natsort import order_by_index
|
|
from natsort.natsort import order_by_index
|
|
|
|
|
+from sqlalchemy import func
|
|
|
from models import *
|
|
from models import *
|
|
|
import requests
|
|
import requests
|
|
|
import json
|
|
import json
|
|
|
from logger import logger
|
|
from logger import logger
|
|
|
from serial.tools import list_ports
|
|
from serial.tools import list_ports
|
|
|
-
|
|
|
|
|
|
|
+from model import PhotoRecord
|
|
|
from utils.hlm_http_request import forward_request
|
|
from utils.hlm_http_request import forward_request
|
|
|
from sockets.socket_client import socket_manager
|
|
from sockets.socket_client import socket_manager
|
|
|
from mcu.DeviceControl import DeviceControl
|
|
from mcu.DeviceControl import DeviceControl
|
|
|
import time
|
|
import time
|
|
|
-# from service.base_deal import BaseDealImage
|
|
|
|
|
-from databases import DeviceConfig,SqlQuery,CRUD
|
|
|
|
|
-from service.deal_image import DealImage
|
|
|
|
|
|
|
+from sqlalchemy import and_, asc, desc
|
|
|
|
|
|
|
|
|
|
+from service.deal_image import DealImage
|
|
|
|
|
+from databases import DeviceConfig, SqlQuery, CRUD, select
|
|
|
@app.get("/")
|
|
@app.get("/")
|
|
|
async def index():
|
|
async def index():
|
|
|
# await socket_manager.send_message(msg="测试")
|
|
# await socket_manager.send_message(msg="测试")
|
|
@@ -117,33 +118,32 @@ async def handle_detail(request: Request):
|
|
|
return result
|
|
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/软件-生成详情错误'}
|
|
|
|
|
- #
|
|
|
|
|
- # config_data = {
|
|
|
|
|
- # 'image_dir': params['image_dir'],
|
|
|
|
|
- # 'image_order': params['image_order'],
|
|
|
|
|
- # 'is_check_number': params['is_check_number'],
|
|
|
|
|
- # 'resize_image_view': params['resize_image_view'],
|
|
|
|
|
- # 'cutout_mode': '1',
|
|
|
|
|
- # 'logo_path': params['logo_path'],
|
|
|
|
|
- # 'special_goods_art_no_folder_line': '',
|
|
|
|
|
- # 'is_use_excel': params['is_use_excel'],
|
|
|
|
|
- # 'excel_path': params['excel_path'],
|
|
|
|
|
- # 'is_check_color_is_all': params['is_check_color_is_all'],
|
|
|
|
|
- # 'assigned_page_dict': {},
|
|
|
|
|
- # 'temp_class': {
|
|
|
|
|
- # 'huilima-2': 'detail_template.huilima.detail_huilima2.DetailPicGet',
|
|
|
|
|
- # 'huilima-3': 'detail_template.huilima.detail_huilima3.DetailPicGet',
|
|
|
|
|
- # 'huilima-4': 'detail_template.huilima.detail_huilima4.DetailPicGet',
|
|
|
|
|
- # 'huilima-1': '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/软件-生成详情错误'
|
|
|
|
|
- # }
|
|
|
|
|
|
|
+ #
|
|
|
|
|
+ # 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/软件-生成详情错误'}
|
|
|
|
|
+ #
|
|
|
|
|
+ # config_data = {
|
|
|
|
|
+ # 'image_dir': params['image_dir'],
|
|
|
|
|
+ # 'image_order': params['image_order'],
|
|
|
|
|
+ # 'is_check_number': params['is_check_number'],
|
|
|
|
|
+ # 'resize_image_view': params['resize_image_view'],
|
|
|
|
|
+ # 'cutout_mode': '1',
|
|
|
|
|
+ # 'logo_path': params['logo_path'],
|
|
|
|
|
+ # 'special_goods_art_no_folder_line': '',
|
|
|
|
|
+ # 'is_use_excel': params['is_use_excel'],
|
|
|
|
|
+ # 'excel_path': params['excel_path'],
|
|
|
|
|
+ # 'is_check_color_is_all': params['is_check_color_is_all'],
|
|
|
|
|
+ # 'assigned_page_dict': {},
|
|
|
|
|
+ # 'temp_class': {
|
|
|
|
|
+ # 'huilima-2': 'detail_template.huilima.detail_huilima2.DetailPicGet',
|
|
|
|
|
+ # 'huilima-3': 'detail_template.huilima.detail_huilima3.DetailPicGet',
|
|
|
|
|
+ # 'huilima-4': 'detail_template.huilima.detail_huilima4.DetailPicGet',
|
|
|
|
|
+ # 'huilima-1': '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/软件-生成详情错误'
|
|
|
|
|
+ # }
|
|
|
|
|
|
|
|
@app.post("/get_device_configs", description="获取可执行程序命令列表")
|
|
@app.post("/get_device_configs", description="获取可执行程序命令列表")
|
|
|
def get_device_configs(params: ModelGetDeviceConfig):
|
|
def get_device_configs(params: ModelGetDeviceConfig):
|
|
@@ -161,8 +161,10 @@ def get_device_configs(params: ModelGetDeviceConfigDetail):
|
|
|
action_id = params.id
|
|
action_id = params.id
|
|
|
session = SqlQuery()
|
|
session = SqlQuery()
|
|
|
configModel = CRUD(DeviceConfig)
|
|
configModel = CRUD(DeviceConfig)
|
|
|
- configList = configModel.read(session, obj_id=action_id)
|
|
|
|
|
- return {"code": 0, "msg": "", "data": configList}
|
|
|
|
|
|
|
+ model = configModel.read(session, conditions={"id": action_id})
|
|
|
|
|
+ if model == None:
|
|
|
|
|
+ return {"code": 1, "msg": "数据不存在", "data": None}
|
|
|
|
|
+ return {"code": 0, "msg": "", "data": model}
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/remove_config", description="删除一条可执行命令")
|
|
@app.post("/remove_config", description="删除一条可执行命令")
|
|
@@ -170,7 +172,10 @@ def get_device_configs(params: ModelGetDeviceConfigDetail):
|
|
|
action_id = params.id
|
|
action_id = params.id
|
|
|
session = SqlQuery()
|
|
session = SqlQuery()
|
|
|
configModel = CRUD(DeviceConfig)
|
|
configModel = CRUD(DeviceConfig)
|
|
|
- configList = configModel.delete(session, obj_id=action_id)
|
|
|
|
|
|
|
+ model = configModel.read(session, conditions={"id": action_id})
|
|
|
|
|
+ if model == None:
|
|
|
|
|
+ return {"code": 1, "msg": "数据不存在", "data": None}
|
|
|
|
|
+ configModel.delete(session, obj_id=action_id)
|
|
|
return {"code": 0, "msg": "删除成功", "data": None}
|
|
return {"code": 0, "msg": "删除成功", "data": None}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -184,7 +189,86 @@ def save_device_config(params: SaveDeviceConfig):
|
|
|
params.id = None
|
|
params.id = None
|
|
|
save_device_config = deviceConfig.create(session, obj_in=params)
|
|
save_device_config = deviceConfig.create(session, obj_in=params)
|
|
|
else:
|
|
else:
|
|
|
|
|
+ model = deviceConfig.read(session, conditions={"id": action_id})
|
|
|
|
|
+ if model == None:
|
|
|
|
|
+ return {"code": 1, "msg": "数据不存在", "data": None}
|
|
|
# 走编辑逻辑
|
|
# 走编辑逻辑
|
|
|
kwargs = params.__dict__
|
|
kwargs = params.__dict__
|
|
|
save_device_config = deviceConfig.update(session, obj_id=action_id, **kwargs)
|
|
save_device_config = deviceConfig.update(session, obj_id=action_id, **kwargs)
|
|
|
return {"code": 0, "msg": "操作成功", "data": save_device_config}
|
|
return {"code": 0, "msg": "操作成功", "data": save_device_config}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@app.post("/reset_config", description="创建或修改一条可执行命令")
|
|
|
|
|
+def reset_config(params: ModelGetDeviceConfig):
|
|
|
|
|
+ mode_type = params.mode_type
|
|
|
|
|
+ if mode_type == None or mode_type == "":
|
|
|
|
|
+ return {"code": 1, "msg": "参数错误", "data": None}
|
|
|
|
|
+ session = SqlQuery()
|
|
|
|
|
+ deviceConfig = CRUD(DeviceConfig)
|
|
|
|
|
+ res = deviceConfig.deleteConditions(session, conditions={"mode_type": mode_type})
|
|
|
|
|
+ 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:
|
|
|
|
|
+ act.append(item)
|
|
|
|
|
+ batch_insert_device_configs(session, act)
|
|
|
|
|
+ return {"code": 0, "msg": "操作成功", "data": None}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@app.get("/get_photo_records", description="获取拍照记录")
|
|
|
|
|
+def get_photo_records(page: int=1,size:int=5):
|
|
|
|
|
+
|
|
|
|
|
+ session = SqlQuery()
|
|
|
|
|
+ photos = CRUD(PhotoRecord)
|
|
|
|
|
+ statement = (
|
|
|
|
|
+ select(PhotoRecord)
|
|
|
|
|
+ .offset((page - 1) * size)
|
|
|
|
|
+ .limit(size)
|
|
|
|
|
+ .order_by(desc("id"))
|
|
|
|
|
+ .group_by("goods_art_no")
|
|
|
|
|
+ )
|
|
|
|
|
+ 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.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "goods_art_no": item.goods_art_no,
|
|
|
|
|
+ "action_time": item.create_time,
|
|
|
|
|
+ "items": list_item,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ return {
|
|
|
|
|
+ "code": 0,
|
|
|
|
|
+ "msg": "",
|
|
|
|
|
+ "data": {"list": list, "page": page, "size": size},
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@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}
|
|
|
|
|
+ session = SqlQuery()
|
|
|
|
|
+ photos = CRUD(PhotoRecord)
|
|
|
|
|
+ items = photos.read_all(session, conditions={"goods_art_no": goods_art_no})
|
|
|
|
|
+ return {
|
|
|
|
|
+ "code": 0,
|
|
|
|
|
+ "msg": "",
|
|
|
|
|
+ "data": {"list": items},
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@app.post("/delect_goods_arts", description="通过货号删除记录")
|
|
|
|
|
+def delect_goods_arts(params: PhotoRecordDelete):
|
|
|
|
|
+
|
|
|
|
|
+ session = SqlQuery()
|
|
|
|
|
+ photos = CRUD(PhotoRecord)
|
|
|
|
|
+ for item in params.goods_art_nos:
|
|
|
|
|
+ photos.deleteConditions(session, conditions={"goods_art_no": item})
|
|
|
|
|
+ return {
|
|
|
|
|
+ "code": 0,
|
|
|
|
|
+ "msg": "操作成功",
|
|
|
|
|
+ "data": None,
|
|
|
|
|
+ }
|