0e6b3b1811
按 ROADMAP §3.1 治理批次推进的后端设计审查整改:
- 批次 0(安全):/api/status/{task_id} 补 JWT 鉴权与任务归属校验;
pythonocc_available 真实探测;bcrypt 超 72 字节显式拒绝;
SECRET_KEY/RUSTFS_* 惰性校验,代码侧弱默认移除
- 批次 1(部署正确性):主处理链路改走 RustFS(分派入参 stp_file_id 化,
worker 按 object_key 下载);AUTO_MIGRATE 开关 + 迁移目录 alembic/→migrations/
修复包遮蔽(自动迁移此前从未真正生效);OCC 镜像改 conda 原生执行 +
基础镜像 tag 锁定;compose 关键项改 ${VAR:?} 强制显式配置
- 批次 2(任务一致性):删除 Redis 进程内存回退,PG 为任务状态单一事实源;
批量元数据入库(processing_tasks.batch_id,迁移 a3f8c2d91e47);
型腔失败任务标 failed 不再静默 completed;事务边界收口
(数据本体写 flush-only、失败先回滚再置 failed、进度更新保留即时 commit)
- 批次 3(API 与代码结构):592 行 advanced_router 拆为 design/cost/machining/
export 四子路由,请求体全量 Pydantic 化;ROUTE_MODULES + route_registry
(/api/health 呈现 degraded,DEBUG fail fast);纯计算端点统一 to_thread;
StorageIntegrationService 按职责三拆;MAX_FILE_SIZE 接线生效、
celery 复用 Settings.redis_url;管理员重置密码改 JSON body(端到端断裂修复);
openapi.json 重导出(76 paths)+ 前端 gen:api
- 批次 4(架构演进):共享 ORM 按模块拆分(shared/models/base.py + identity.py、
moldinsight/models/、inventory/models/,删除三条无使用方的跨模块
relationship,跨模块桥接收敛为裸 FK 硬规则,无兼容 facade);
OCC executor 重建补 cancel_futures=True(消除旧队列被慢恢复线程
并行消化的数据竞争);OCC 吞吐方案设计先行
(docs/topics/performance/OCC_THROUGHPUT.md);顺手清偿 D15
(vite.config.ts 未用参数致 npm run build 失败)
测试基线:125 passed, 2 skipped(pytest + sqlite+aiosqlite;归属边界、
路由契约、配置治理、鉴权回归等随批新增)
文档同步:STATUS / TECH_DEBT / ROADMAP / ARCHITECTURE / API_CONTRACT /
OPERATIONS / AGENTS
Co-Authored-By: Claude Code <noreply@anthropic.com>
81 lines
3.3 KiB
Python
81 lines
3.3 KiB
Python
"""inventory 仓储域模型:仓库/库存/库存流水。"""
|
|
from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, Numeric, ForeignKey, UniqueConstraint, CheckConstraint
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from shared.models.base import Base
|
|
|
|
|
|
class Warehouse(Base):
|
|
"""仓库表"""
|
|
__tablename__ = "warehouses"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
code = Column(String(50), unique=True, index=True)
|
|
name = Column(String(200), nullable=False)
|
|
address = Column(Text, nullable=True)
|
|
manager = Column(String(100), nullable=True)
|
|
phone = Column(String(50), nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
is_default = Column(Boolean, default=False)
|
|
created_at = Column(DateTime, default=func.now())
|
|
|
|
inventories = relationship("Inventory", back_populates="warehouse")
|
|
|
|
def __repr__(self):
|
|
return f"<Warehouse(id={self.id}, name='{self.name}')>"
|
|
|
|
|
|
class Inventory(Base):
|
|
"""库存表"""
|
|
__tablename__ = "inventory"
|
|
__table_args__ = (
|
|
UniqueConstraint("product_id", "warehouse_id", name="uq_inventory_product_warehouse"),
|
|
CheckConstraint("quantity >= 0 AND locked_quantity >= 0 AND locked_quantity <= quantity", name="ck_inventory_qty_nonnegative"),
|
|
)
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
product_id = Column(Integer, ForeignKey("products.id"), nullable=False, index=True)
|
|
warehouse_id = Column(Integer, ForeignKey("warehouses.id"), nullable=False, index=True)
|
|
quantity = Column(Numeric(12, 4), default=0)
|
|
locked_quantity = Column(Numeric(12, 4), default=0)
|
|
batch_number = Column(String(50), nullable=True)
|
|
location = Column(String(100), nullable=True)
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
|
|
|
product = relationship("Product", back_populates="inventory")
|
|
warehouse = relationship("Warehouse", back_populates="inventories")
|
|
|
|
def __repr__(self):
|
|
return f"<Inventory(product_id={self.product_id}, quantity={self.quantity})>"
|
|
|
|
@property
|
|
def available_quantity(self):
|
|
return self.quantity - self.locked_quantity
|
|
|
|
|
|
class StockMovement(Base):
|
|
"""库存变动记录表"""
|
|
__tablename__ = "stock_movements"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
product_id = Column(Integer, ForeignKey("products.id"), nullable=False, index=True)
|
|
warehouse_id = Column(Integer, ForeignKey("warehouses.id"), nullable=False)
|
|
movement_type = Column(String(20), nullable=False)
|
|
quantity = Column(Numeric(12, 4), nullable=False)
|
|
before_quantity = Column(Numeric(12, 4), default=0)
|
|
after_quantity = Column(Numeric(12, 4), default=0)
|
|
reference_type = Column(String(50), nullable=True)
|
|
reference_id = Column(Integer, nullable=True)
|
|
reference_no = Column(String(50), nullable=True)
|
|
unit_price = Column(Numeric(12, 2), nullable=True)
|
|
total_amount = Column(Numeric(12, 2), nullable=True)
|
|
remark = Column(Text, nullable=True)
|
|
operator_id = Column(Integer, ForeignKey("users.id"), nullable=True)
|
|
created_at = Column(DateTime, default=func.now(), index=True)
|
|
|
|
product = relationship("Product", back_populates="stock_movements")
|
|
|
|
def __repr__(self):
|
|
return f"<StockMovement(id={self.id}, type='{self.movement_type}', qty={self.quantity})>"
|