feat: initial commit and ignore qwen files
This commit is contained in:
29
backend/app/models/__init__.py
Normal file
29
backend/app/models/__init__.py
Normal file
@ -0,0 +1,29 @@
|
||||
"""ORM 模型导出模块"""
|
||||
from app.models.inventory import MaterialBase, BomTable, StockProduct, TransOutbound, StockBuy
|
||||
from app.models.production import (
|
||||
PmsProject,
|
||||
PmsWorkOrder,
|
||||
PmsMaterialRequisition,
|
||||
PmsMaterialApproval,
|
||||
PmsUserPreference,
|
||||
ProjectStatus,
|
||||
WorkOrderStatus,
|
||||
ApprovalStatus,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# 库存表(只读)
|
||||
"MaterialBase",
|
||||
"BomTable",
|
||||
"StockProduct",
|
||||
"TransOutbound",
|
||||
# 生产系统新表
|
||||
"PmsProject",
|
||||
"PmsWorkOrder",
|
||||
"PmsMaterialRequisition",
|
||||
"PmsMaterialApproval",
|
||||
"PmsUserPreference",
|
||||
"ProjectStatus",
|
||||
"WorkOrderStatus",
|
||||
"ApprovalStatus",
|
||||
]
|
||||
78
backend/app/models/inventory.py
Normal file
78
backend/app/models/inventory.py
Normal file
@ -0,0 +1,78 @@
|
||||
"""库存系统 ORM 模型(只读,从现有数据库逆向生成)"""
|
||||
from sqlalchemy import Column, Integer, String, Numeric, Boolean, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class SysUser(Base):
|
||||
"""系统用户表(只读,从旧库映射)"""
|
||||
__tablename__ = "sys_user"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
username = Column(String(100), unique=True, nullable=False, index=True)
|
||||
password = Column(String(255), nullable=False)
|
||||
real_name = Column(String(100))
|
||||
department = Column(String(100))
|
||||
is_active = Column(Integer, default=1)
|
||||
|
||||
|
||||
class MaterialBase(Base):
|
||||
"""物料基础表(只读)"""
|
||||
__tablename__ = "material_base"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
spec_model = Column(String(255))
|
||||
unit = Column(String(50))
|
||||
|
||||
|
||||
class BomTable(Base):
|
||||
"""BOM物料清单表(只读)"""
|
||||
__tablename__ = "bom_table"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
parent_id = Column(Integer, ForeignKey("material_base.id"), nullable=False)
|
||||
child_id = Column(Integer, ForeignKey("material_base.id"), nullable=False)
|
||||
dosage = Column(Numeric(10, 4), nullable=False)
|
||||
bom_no = Column(String(100), nullable=True)
|
||||
version = Column(String(50), nullable=True)
|
||||
is_enabled = Column(Boolean, default=True)
|
||||
|
||||
parent = relationship("MaterialBase", foreign_keys=[parent_id])
|
||||
child = relationship("MaterialBase", foreign_keys=[child_id])
|
||||
|
||||
|
||||
class StockProduct(Base):
|
||||
"""库存产品表(只读)"""
|
||||
__tablename__ = "stock_product"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
base_id = Column(Integer, ForeignKey("material_base.id"), nullable=False)
|
||||
stock_quantity = Column(Numeric(10, 2), default=0)
|
||||
work_order_id = Column(Integer, nullable=True)
|
||||
|
||||
material = relationship("MaterialBase", foreign_keys=[base_id])
|
||||
|
||||
|
||||
class TransOutbound(Base):
|
||||
"""出库记录表(只读)"""
|
||||
__tablename__ = "trans_outbound"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
outbound_no = Column(String(100), unique=True, nullable=False)
|
||||
stock_id = Column(Integer, ForeignKey("stock_product.id"), nullable=False)
|
||||
quantity = Column(Numeric(10, 2), nullable=False)
|
||||
consumer_name = Column(String(255))
|
||||
|
||||
stock = relationship("StockProduct", foreign_keys=[stock_id])
|
||||
|
||||
|
||||
class StockBuy(Base):
|
||||
"""原材料库存表(只读)"""
|
||||
__tablename__ = "stock_buy"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
base_id = Column(Integer, ForeignKey("material_base.id"), nullable=False)
|
||||
stock_quantity = Column(Numeric(10, 2), default=0)
|
||||
|
||||
material = relationship("MaterialBase", foreign_keys=[base_id])
|
||||
116
backend/app/models/production.py
Normal file
116
backend/app/models/production.py
Normal file
@ -0,0 +1,116 @@
|
||||
"""生产系统 ORM 模型(新建表)"""
|
||||
from sqlalchemy import Column, Integer, String, Date, DateTime, ForeignKey, Enum as SQLEnum, JSON
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
import enum
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class ProjectStatus(str, enum.Enum):
|
||||
"""项目状态枚举"""
|
||||
DRAFT = "draft"
|
||||
ACTIVE = "active"
|
||||
COMPLETED = "completed"
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class WorkOrderStatus(str, enum.Enum):
|
||||
"""工单状态枚举"""
|
||||
PENDING = "pending"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class ApprovalStatus(str, enum.Enum):
|
||||
"""缺料审批状态枚举"""
|
||||
PENDING = "PENDING"
|
||||
APPROVED = "APPROVED"
|
||||
REJECTED = "REJECTED"
|
||||
|
||||
|
||||
class PmsProject(Base):
|
||||
"""项目表"""
|
||||
__tablename__ = "pms_project"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
project_no = Column(String(50), unique=True, nullable=False, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
start_date = Column(Date, nullable=True)
|
||||
end_date = Column(Date, nullable=True)
|
||||
status = Column(
|
||||
SQLEnum(ProjectStatus),
|
||||
default=ProjectStatus.DRAFT,
|
||||
nullable=False
|
||||
)
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
||||
|
||||
work_orders = relationship("PmsWorkOrder", back_populates="project")
|
||||
|
||||
|
||||
class PmsWorkOrder(Base):
|
||||
"""工单表"""
|
||||
__tablename__ = "pms_work_order"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
work_order_no = Column(String(50), unique=True, nullable=False, index=True)
|
||||
project_id = Column(Integer, ForeignKey("pms_project.id"), nullable=False)
|
||||
target_base_id = Column(Integer, ForeignKey("material_base.id"), nullable=False)
|
||||
target_quantity = Column(Integer, nullable=False, default=0)
|
||||
assignee_name = Column(String(100), nullable=True)
|
||||
status = Column(
|
||||
SQLEnum(WorkOrderStatus),
|
||||
default=WorkOrderStatus.PENDING,
|
||||
nullable=False
|
||||
)
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
||||
|
||||
project = relationship("PmsProject", back_populates="work_orders")
|
||||
material = relationship("MaterialBase", foreign_keys=[target_base_id])
|
||||
material_requisitions = relationship("PmsMaterialRequisition", back_populates="work_order")
|
||||
|
||||
|
||||
class PmsMaterialRequisition(Base):
|
||||
"""领料映射表"""
|
||||
__tablename__ = "pms_material_requisition"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
work_order_id = Column(Integer, ForeignKey("pms_work_order.id"), nullable=False)
|
||||
inventory_outbound_no = Column(String(100), nullable=False)
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
|
||||
work_order = relationship("PmsWorkOrder", back_populates="material_requisitions")
|
||||
|
||||
|
||||
class PmsMaterialApproval(Base):
|
||||
"""缺料审批表"""
|
||||
__tablename__ = "pms_material_approval"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
work_order_id = Column(Integer, ForeignKey("pms_work_order.id"), nullable=False)
|
||||
missing_material_id = Column(Integer, ForeignKey("material_base.id"), nullable=False)
|
||||
required_qty = Column(Integer, nullable=False)
|
||||
reason = Column(String(500), nullable=True)
|
||||
status = Column(
|
||||
SQLEnum(ApprovalStatus),
|
||||
default=ApprovalStatus.PENDING,
|
||||
nullable=False
|
||||
)
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
|
||||
work_order = relationship("PmsWorkOrder")
|
||||
material = relationship("MaterialBase", foreign_keys=[missing_material_id])
|
||||
|
||||
|
||||
class PmsUserPreference(Base):
|
||||
"""用户偏好表"""
|
||||
__tablename__ = "pms_user_preference"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, nullable=False, index=True) # 对应 SysUser.id
|
||||
default_bom_target_id = Column(Integer, nullable=True) # 默认关注的成品ID
|
||||
favorite_target_ids = Column(JSON, nullable=True) # 常看成品ID列表,PostgreSQL JSON 数组
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
||||
Reference in New Issue
Block a user