提交
This commit is contained in:
1 parent
66609c0e21
commit
0b50eff3d8
93 files changed
+40172
-30060
No files matched your search
@@ -1,7 +1,6 @@
|
||||
"""库位节点编号路径与储物格完整编号计算、快照级联刷新。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
from typing import Dict, List, Optional, Union
|
||||
|
||||
@@ -14,15 +13,32 @@ from app.models.models import (
|
||||
BizStorageFacilitySlot,
|
||||
)
|
||||
|
||||
_NODE_CODE_PATTERN = re.compile(r"^[A-Za-z0-9]+$")
|
||||
SLOT_LAYOUT_ROW_STRIDE = 1000
|
||||
|
||||
|
||||
def encode_slot_layout_order(row: int, col: int) -> int:
|
||||
"""将货架行列位置编码为 order_num(row*1000+col)。"""
|
||||
row_i = int(row)
|
||||
col_i = int(col)
|
||||
if row_i < 1 or col_i < 1:
|
||||
raise ValueError("行列序号必须从 1 开始")
|
||||
if col_i >= SLOT_LAYOUT_ROW_STRIDE:
|
||||
raise ValueError(f"列数不能超过 {SLOT_LAYOUT_ROW_STRIDE - 1}")
|
||||
return row_i * SLOT_LAYOUT_ROW_STRIDE + col_i
|
||||
|
||||
|
||||
def decode_slot_layout_order(order_num: int) -> tuple[int, int]:
|
||||
"""解析 order_num 中的行列位置;非布局编码时返回 (0, order)。"""
|
||||
order = int(order_num or 0)
|
||||
if order >= SLOT_LAYOUT_ROW_STRIDE:
|
||||
return order // SLOT_LAYOUT_ROW_STRIDE, order % SLOT_LAYOUT_ROW_STRIDE
|
||||
return 0, order
|
||||
|
||||
|
||||
def validate_node_code(node_code: str) -> str:
|
||||
code = (node_code or "").strip()
|
||||
if not code:
|
||||
raise ValueError("节点编号不能为空")
|
||||
if not _NODE_CODE_PATTERN.match(code):
|
||||
raise ValueError("节点编号只能包含字母和数字,不能包含连字符")
|
||||
return ""
|
||||
if len(code) > 32:
|
||||
raise ValueError("节点编号长度不能超过 32 个字符")
|
||||
return code
|
||||
@@ -38,6 +54,8 @@ def assert_sibling_node_code_unique(
|
||||
) -> None:
|
||||
pid = (parent_id or "0").strip() or "0"
|
||||
code = validate_node_code(node_code)
|
||||
if not code:
|
||||
return
|
||||
q = db.query(BizStorageFacility).filter(
|
||||
BizStorageFacility.parent_id == pid,
|
||||
BizStorageFacility.node_code == code,
|
||||
|
||||
Reference in new issue
Block a user