跳到主要内容

工件模型文档

概述

本文档详细分析了邮轮穿舱件管理系统中的工件相关数据模型,包括工件基本信息、工件详细信息、图像映射关系等核心数据模型。系统采用混合数据库架构,结合关系型数据库(PostgreSQL)和文档数据库(MongoDB)来存储不同类型的数据。

数据模型架构

系统架构图

flowchart TD
subgraph PostgreSQL数据库
A[Workpiece模型]
B[Image模型]
C[ImageMapping模型]
end

subgraph MongoDB数据库
D[WorkpieceInfo文档]
end

subgraph 业务逻辑层
E[WorkpieceService]
F[WorkpieceInfoService]
G[ImageMappingService]
end

A --> E
D --> F
B --> G
C --> G
E --> F
E --> G

核心模型关系

erDiagram
WORKPIECE ||--o{ IMAGE_MAPPING : "一对多"
IMAGE ||--o{ IMAGE_MAPPING : "一对多"
WORKPIECE ||--|| WORKPIECE_INFO : "一对一"

WORKPIECE {
int workpiece_id PK
int workpiece_status
int inspect_reference
int maintainance_reference
int created_by
int updated_by
datetime created_at
datetime updated_at
}

IMAGE_MAPPING {
int workpiece_id FK
int image_id FK
int created_by
int updated_by
datetime created_at
datetime updated_at
}

IMAGE {
int id PK
string key
int created_by
int updated_by
datetime created_at
datetime updated_at
}

WORKPIECE_INFO {
string wp_id PK
string wp_firestop_code
string wp_matrial
string wp_size
string wp_fire_rating
string wp_watertightness
string wp_main_vertical_zone
string wp_installation_location
string wp_z_coordinate
string wp_frame_station
string wp_longitudinal_stiffener
string wp_sap1
string wp_sap2
string wp_standard_drawing_catalogue
string wp_extra
}

核心数据模型详解

1. Workpiece模型(工件基本信息)

Workpiece模型存储工件的基本信息和状态管理,使用PostgreSQL数据库。

类定义:

class Workpiece(Model):
workpiece_id = fields.IntField(description="工件ID", primary_key=True)
workpiece_status = fields.IntField(description="工件状态", null=True, default=0)
inspect_reference = fields.IntField(description="视检参考工单ID", null=True, default=0)
maintainance_reference = fields.IntField(description="维护参考工单ID", null=True, default=0)
created_by = fields.IntField(description="创建人", null=True, default=-1)
updated_by = fields.IntField(description="更新人", null=True, default=-1)
created_at = fields.DatetimeField(description="创建时间", null=False, auto_now_add=True)
updated_at = fields.DatetimeField(description="更新时间", null=False, auto_now=True)

class Meta:
table = "workpieces"

字段说明:

字段名类型描述约束
workpiece_idIntField工件ID主键
workpiece_statusIntField工件状态可为空,默认0
inspect_referenceIntField视检参考工单ID可为空,默认0
maintainance_referenceIntField维护参考工单ID可为空,默认0
created_byIntField创建人可为空,默认-1
updated_byIntField更新人可为空,默认-1
created_atDatetimeField创建时间自动添加
updated_atDatetimeField更新时间自动更新

参考源文件:

2. WorkpieceInfo模型(工件详细信息)

WorkpieceInfo模型存储工件的详细技术信息,使用MongoDB文档数据库。

类定义:

class WorkpieceInfo(Document):
wp_id: str
wp_firestop_code: str
wp_matrial: str
wp_size: str
wp_fire_rating: str
wp_watertightness: str
wp_main_vertical_zone: str
wp_installation_location: str
wp_z_coordinate: str
wp_frame_station: str
wp_longitudinal_stiffener: str
wp_sap1: str
wp_sap2: str
wp_standard_drawing_catalogue: str
wp_extra: str

class Settings:
name = "workpiece_info" # MongoDB collection name

字段说明:

字段名类型描述中文映射
wp_idstr工件ID工件ID
wp_firestop_codestr防火板代号防火板代号
wp_matrialstr材料材料
wp_sizestr规格规格
wp_fire_ratingstr防火等级防火等级
wp_watertightnessstr水密等级水密等级
wp_main_vertical_zonestr主竖区主竖区
wp_installation_locationstr安装位置安装位置
wp_z_coordinatestrZ坐标Z坐标
wp_frame_stationstr肋位肋位
wp_longitudinal_stiffenerstr纵桁纵桁
wp_sap1strSAP1SAP1
wp_sap2strSAP2SAP2
wp_standard_drawing_cataloguestr图册章节图册章节
wp_extrastr额外信息额外信息

参考源文件:

3. ImageMapping模型(图像映射关系)

ImageMapping模型建立工件与图片之间的多对多映射关系。

类定义:

class ImageMapping(Model):
workpiece_id = fields.IntField(description="工件ID AKA Product ID", null=False)
image_id = fields.IntField(description="图片ID AKA Image ID", null=False)
created_by = fields.IntField(description="创建人", null=True, default=-1)
updated_by = fields.IntField(description="更新人", null=True, default=-1)
created_at = fields.DatetimeField(description="创建时间", null=False, auto_now_add=True)
updated_at = fields.DatetimeField(description="更新时间", null=False, auto_now=True)

class Meta:
table = "image_mapping"

字段说明:

字段名类型描述约束
workpiece_idIntField工件ID非空
image_idIntField图片ID非空
created_byIntField创建人可为空,默认-1
updated_byIntField更新人可为空,默认-1
created_atDatetimeField创建时间自动添加
updated_atDatetimeField更新时间自动更新

参考源文件:

4. Image模型(图片信息)

Image模型存储图片的基本信息,包括OSS存储路径。

类定义:

class Image(Model):
id = fields.IntField(description="图片ID", null=False, pk=True)
key = fields.CharField(description="图片OSS Key", null=False, max_length=255)
created_by = fields.IntField(description="创建人", null=True, default=-1)
updated_by = fields.IntField(description="更新人", null=True, default=-1)
created_at = fields.DatetimeField(description="创建时间", null=False, auto_now_add=True)
updated_at = fields.DatetimeField(description="更新时间", null=False, auto_now=True)

class Meta:
table = "image"

参考源文件:

数据流分析

工件创建流程

sequenceDiagram
participant Client as 客户端
participant Router as 路由层
participant WPService as WorkpieceService
participant WPInfoService as WorkpieceInfoService
participant DB as 数据库

Client->>Router: 创建工件请求
Router->>WPService: create_workpiece()
WPService->>DB: 创建Workpiece记录
DB-->>WPService: 返回workpiece_id
WPService->>WPInfoService: create_workpiece_info()
WPInfoService->>DB: 创建WorkpieceInfo文档
DB-->>WPInfoService: 确认创建成功
WPInfoService-->>WPService: 返回结果
WPService-->>Router: 返回完整工件信息
Router-->>Client: 创建成功响应

图像关联流程

flowchart TD
A[上传图片] --> B[创建Image记录]
B --> C[获取workpiece_id]
C --> D[创建ImageMapping记录]
D --> E[建立工件-图片关联]
E --> F[返回关联结果]

架构设计模式

1. 混合数据库模式

系统采用关系型数据库存储结构化数据(Workpiece、Image、ImageMapping),使用文档数据库存储半结构化数据(WorkpieceInfo)。这种设计充分利用了两种数据库的优势:

  • PostgreSQL:适合事务性操作和复杂查询
  • MongoDB:适合存储灵活的文档结构

2. 数据分离模式

将工件的核心状态信息与详细技术信息分离存储:

  • Workpiece表:存储状态、引用关系等核心业务数据
  • WorkpieceInfo文档:存储技术规格、位置信息等详细数据

3. 多对多关联模式

通过ImageMapping表实现工件与图片的多对多关联,支持一个工件关联多张图片,一张图片关联多个工件。

性能优化考虑

1. 索引策略

  • Workpiece表的workpiece_id主键索引
  • ImageMapping表的复合索引(workpiece_id, image_id)
  • Image表的id主键索引

2. 查询优化

  • 使用JOIN查询优化工件与图片的关联查询
  • MongoDB的文档查询优化技术规格检索

3. 缓存策略

  • 高频访问的工件基本信息可考虑缓存
  • 图片元数据可实施缓存策略

索引

工件模型系统采用了现代化的混合数据库架构,通过合理的数据分离和关联设计,实现了高效、灵活的工件信息管理。系统支持工件的全生命周期管理,包括基本信息维护、技术规格存储、图像关联等功能,为邮轮穿舱件管理提供了坚实的数据基础。

参考源文件汇总: