feat: initial commit - massive-cloud point cloud processing system

This commit is contained in:
2026-05-27 09:51:42 +00:00
commit 16811100d1
391 changed files with 78338 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
CREATE TABLE `users` (
`id` int AUTO_INCREMENT NOT NULL,
`openId` varchar(64) NOT NULL,
`name` text,
`email` varchar(320),
`loginMethod` varchar(64),
`role` enum('user','admin') NOT NULL DEFAULT 'user',
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
`lastSignedIn` timestamp NOT NULL DEFAULT (now()),
CONSTRAINT `users_id` PRIMARY KEY(`id`),
CONSTRAINT `users_openId_unique` UNIQUE(`openId`)
);

View File

@@ -0,0 +1,76 @@
CREATE TABLE `analysis_results` (
`id` int AUTO_INCREMENT NOT NULL,
`projectId` int NOT NULL,
`cadModelId` int,
`type` enum('error_analysis','measurement','compression') NOT NULL,
`status` enum('pending','processing','completed','error') NOT NULL DEFAULT 'pending',
`resultData` json,
`errorStats` json,
`measurements` json,
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `analysis_results_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `cad_models` (
`id` int AUTO_INCREMENT NOT NULL,
`projectId` int NOT NULL,
`name` varchar(255) NOT NULL,
`format` varchar(32) NOT NULL,
`fileSize` bigint NOT NULL,
`fileUrl` text,
`fileKey` varchar(512),
`vertexCount` int DEFAULT 0,
`faceCount` int DEFAULT 0,
`boundingBox` json,
`status` enum('uploading','processing','ready','error') NOT NULL DEFAULT 'uploading',
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `cad_models_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `lod_nodes` (
`id` int AUTO_INCREMENT NOT NULL,
`projectId` int NOT NULL,
`level` int NOT NULL,
`nodeIndex` varchar(64) NOT NULL,
`pointCount` int NOT NULL,
`fileUrl` text,
`fileKey` varchar(512),
`boundingBox` json NOT NULL,
`createdAt` timestamp NOT NULL DEFAULT (now()),
CONSTRAINT `lod_nodes_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `point_cloud_chunks` (
`id` int AUTO_INCREMENT NOT NULL,
`projectId` int NOT NULL,
`chunkIndex` int NOT NULL,
`fileName` varchar(255) NOT NULL,
`fileSize` bigint NOT NULL,
`pointCount` bigint DEFAULT 0,
`fileUrl` text,
`fileKey` varchar(512),
`status` enum('pending','uploading','uploaded','processing','ready','error') NOT NULL DEFAULT 'pending',
`boundingBox` json,
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `point_cloud_chunks_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `projects` (
`id` int AUTO_INCREMENT NOT NULL,
`userId` int NOT NULL,
`name` varchar(255) NOT NULL,
`description` text,
`status` enum('uploading','processing','ready','error') NOT NULL DEFAULT 'uploading',
`totalPoints` bigint DEFAULT 0,
`totalChunks` int DEFAULT 0,
`uploadedChunks` int DEFAULT 0,
`totalSize` bigint DEFAULT 0,
`lodLevels` int DEFAULT 0,
`boundingBox` json,
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `projects_id` PRIMARY KEY(`id`)
);

View File

@@ -0,0 +1,68 @@
-- 迁移:引入车系/车型/检测任务/分析结果层级结构
-- 旧表保留不动(数据兼容),新表全部创建
-- 车系
CREATE TABLE IF NOT EXISTS `vehicle_series` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(100) NOT NULL,
`description` TEXT,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- 车型
CREATE TABLE IF NOT EXISTS `vehicle_models` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`seriesId` INT NOT NULL,
`name` VARCHAR(100) NOT NULL,
`description` TEXT,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- 车型 CAD 文件(低频变更,一对多)
CREATE TABLE IF NOT EXISTS `model_cad_files` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`modelId` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`format` VARCHAR(32) NOT NULL,
`fileSize` BIGINT NOT NULL,
`filePath` VARCHAR(512) NOT NULL,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- 检测任务(每次上车检测 = 一条记录)
CREATE TABLE IF NOT EXISTS `inspection_tasks` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`modelId` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`inspector` VARCHAR(100),
`notes` TEXT,
`status` ENUM('pending','processing','completed','error') NOT NULL DEFAULT 'pending',
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`completedAt` TIMESTAMP NULL
);
-- 任务点云文件(每次检测可有多个点云文件)
CREATE TABLE IF NOT EXISTS `task_pointcloud_files` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`taskId` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`fileSize` BIGINT NOT NULL,
`filePath` VARCHAR(512) NOT NULL,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- 任务分析结果(可多次运行,支持回放)
CREATE TABLE IF NOT EXISTS `task_analysis_results` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`taskId` INT NOT NULL,
`type` ENUM('error_analysis','measurement','compression') NOT NULL,
`status` ENUM('pending','processing','completed','error') NOT NULL DEFAULT 'pending',
`errorStats` JSON,
`measurements` JSON,
`resultData` JSON,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

View File

@@ -0,0 +1,62 @@
-- 修复:若 0002 曾因错误的迁移过滤未真正建表,本文件再次执行 CREATE IF NOT EXISTS(幂等)。
-- 与 0002 内容相同,作为新迁移文件以便已标记 0002 完成的环境补建表。
CREATE TABLE IF NOT EXISTS `vehicle_series` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(100) NOT NULL,
`description` TEXT,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS `vehicle_models` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`seriesId` INT NOT NULL,
`name` VARCHAR(100) NOT NULL,
`description` TEXT,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS `model_cad_files` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`modelId` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`format` VARCHAR(32) NOT NULL,
`fileSize` BIGINT NOT NULL,
`filePath` VARCHAR(512) NOT NULL,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS `inspection_tasks` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`modelId` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`inspector` VARCHAR(100),
`notes` TEXT,
`status` ENUM('pending','processing','completed','error') NOT NULL DEFAULT 'pending',
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`completedAt` TIMESTAMP NULL
);
CREATE TABLE IF NOT EXISTS `task_pointcloud_files` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`taskId` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`fileSize` BIGINT NOT NULL,
`filePath` VARCHAR(512) NOT NULL,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS `task_analysis_results` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`taskId` INT NOT NULL,
`type` ENUM('error_analysis','measurement','compression') NOT NULL,
`status` ENUM('pending','processing','completed','error') NOT NULL DEFAULT 'pending',
`errorStats` JSON,
`measurements` JSON,
`resultData` JSON,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

View File

@@ -0,0 +1,10 @@
-- 为 task_analysis_results.type 增加 smooth_heatmap(与 drizzle/schema.ts 一致)
-- 启动时由 server/_core/index.ts runMigrations 自动执行
ALTER TABLE task_analysis_results
MODIFY COLUMN type ENUM(
'error_analysis',
'measurement',
'compression',
'smooth_heatmap'
) NOT NULL;

View File

@@ -0,0 +1,9 @@
-- 任务分析类型:装配检测(STEP + 最近零件 + 统计 / 可选顶点热力)
ALTER TABLE task_analysis_results
MODIFY COLUMN type ENUM(
'error_analysis',
'measurement',
'compression',
'smooth_heatmap',
'assembly_inspection'
) NOT NULL;

View File

@@ -0,0 +1,10 @@
-- 任务分析类型:CAD 偏差热力(STL/OBJ + 点云距离着色)
ALTER TABLE task_analysis_results
MODIFY COLUMN type ENUM(
'error_analysis',
'measurement',
'compression',
'smooth_heatmap',
'assembly_inspection',
'obj_deviation'
) NOT NULL;

View File

@@ -0,0 +1,20 @@
-- 通用算法插件(Route B)接入:
-- 1. task_analysis_results.type 新增枚举值 'plugin',所有插件运行的结果都以此类型记录;
-- 2. 新增 pluginId / schemaVersion 列,方便回放、复现、版本检查。
ALTER TABLE task_analysis_results
MODIFY COLUMN type ENUM(
'error_analysis',
'measurement',
'compression',
'smooth_heatmap',
'assembly_inspection',
'obj_deviation',
'plugin'
) NOT NULL;
ALTER TABLE task_analysis_results
ADD COLUMN pluginId VARCHAR(64) NULL AFTER type,
ADD COLUMN schemaVersion INT NULL AFTER pluginId;
-- 为按插件 ID 查询历史结果建立索引
CREATE INDEX idx_task_analysis_plugin_id ON task_analysis_results (pluginId);

View File

@@ -0,0 +1,14 @@
-- 任务级 CAD 文件表
-- 每个检测任务可关联任意个 CAD 文件,与车型级 model_cad_files 独立
CREATE TABLE IF NOT EXISTS `task_cad_files` (
`id` INT NOT NULL AUTO_INCREMENT,
`taskId` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`format` VARCHAR(32) NOT NULL,
`fileSize` BIGINT NOT NULL,
`filePath` VARCHAR(512) NOT NULL,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `idx_task_cad_files_taskId` (`taskId`)
);

View File

@@ -0,0 +1,110 @@
{
"version": "5",
"dialect": "mysql",
"id": "e1df4303-2037-42c4-9321-4fde8be8074f",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"openId": {
"name": "openId",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"email": {
"name": "email",
"type": "varchar(320)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"loginMethod": {
"name": "loginMethod",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"role": {
"name": "role",
"type": "enum('user','admin')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'user'"
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
},
"lastSignedIn": {
"name": "lastSignedIn",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"users_id": {
"name": "users_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {
"users_openId_unique": {
"name": "users_openId_unique",
"columns": [
"openId"
]
}
},
"checkConstraint": {}
}
},
"views": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"tables": {},
"indexes": {}
}
}

View File

@@ -0,0 +1,619 @@
{
"version": "5",
"dialect": "mysql",
"id": "10e4dd76-1a2e-4769-a699-39f605426199",
"prevId": "e1df4303-2037-42c4-9321-4fde8be8074f",
"tables": {
"analysis_results": {
"name": "analysis_results",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"projectId": {
"name": "projectId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"cadModelId": {
"name": "cadModelId",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"type": {
"name": "type",
"type": "enum('error_analysis','measurement','compression')",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"status": {
"name": "status",
"type": "enum('pending','processing','completed','error')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'pending'"
},
"resultData": {
"name": "resultData",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"errorStats": {
"name": "errorStats",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"measurements": {
"name": "measurements",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"analysis_results_id": {
"name": "analysis_results_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"cad_models": {
"name": "cad_models",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"projectId": {
"name": "projectId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"format": {
"name": "format",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileSize": {
"name": "fileSize",
"type": "bigint",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileUrl": {
"name": "fileUrl",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"fileKey": {
"name": "fileKey",
"type": "varchar(512)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"vertexCount": {
"name": "vertexCount",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"faceCount": {
"name": "faceCount",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"boundingBox": {
"name": "boundingBox",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"status": {
"name": "status",
"type": "enum('uploading','processing','ready','error')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'uploading'"
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"cad_models_id": {
"name": "cad_models_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"lod_nodes": {
"name": "lod_nodes",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"projectId": {
"name": "projectId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"level": {
"name": "level",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"nodeIndex": {
"name": "nodeIndex",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"pointCount": {
"name": "pointCount",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileUrl": {
"name": "fileUrl",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"fileKey": {
"name": "fileKey",
"type": "varchar(512)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"boundingBox": {
"name": "boundingBox",
"type": "json",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"lod_nodes_id": {
"name": "lod_nodes_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"point_cloud_chunks": {
"name": "point_cloud_chunks",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"projectId": {
"name": "projectId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"chunkIndex": {
"name": "chunkIndex",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileName": {
"name": "fileName",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileSize": {
"name": "fileSize",
"type": "bigint",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"pointCount": {
"name": "pointCount",
"type": "bigint",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"fileUrl": {
"name": "fileUrl",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"fileKey": {
"name": "fileKey",
"type": "varchar(512)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"status": {
"name": "status",
"type": "enum('pending','uploading','uploaded','processing','ready','error')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'pending'"
},
"boundingBox": {
"name": "boundingBox",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"point_cloud_chunks_id": {
"name": "point_cloud_chunks_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"projects": {
"name": "projects",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"userId": {
"name": "userId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"status": {
"name": "status",
"type": "enum('uploading','processing','ready','error')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'uploading'"
},
"totalPoints": {
"name": "totalPoints",
"type": "bigint",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"totalChunks": {
"name": "totalChunks",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"uploadedChunks": {
"name": "uploadedChunks",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"totalSize": {
"name": "totalSize",
"type": "bigint",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"lodLevels": {
"name": "lodLevels",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"boundingBox": {
"name": "boundingBox",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"projects_id": {
"name": "projects_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"openId": {
"name": "openId",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"email": {
"name": "email",
"type": "varchar(320)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"loginMethod": {
"name": "loginMethod",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"role": {
"name": "role",
"type": "enum('user','admin')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'user'"
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
},
"lastSignedIn": {
"name": "lastSignedIn",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"users_id": {
"name": "users_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {
"users_openId_unique": {
"name": "users_openId_unique",
"columns": [
"openId"
]
}
},
"checkConstraint": {}
}
},
"views": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"tables": {},
"indexes": {}
}
}

View File

@@ -0,0 +1,20 @@
{
"version": "7",
"dialect": "mysql",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1769499539551,
"tag": "0000_groovy_crusher_hogan",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1769499731540,
"tag": "0001_tan_jamie_braddock",
"breakpoints": true
}
]
}

View File

1
drizzle/relations.ts Normal file
View File

@@ -0,0 +1 @@
import {} from "./schema";

143
drizzle/schema.ts Normal file
View File

@@ -0,0 +1,143 @@
import { int, mysqlEnum, mysqlTable, text, timestamp, varchar, bigint, json } from "drizzle-orm/mysql-core";
// ─── 用户表(保持不变) ────────────────────────────────────────────────────────
export const users = mysqlTable("users", {
id: int("id").autoincrement().primaryKey(),
openId: varchar("openId", { length: 64 }).notNull().unique(),
name: text("name"),
email: varchar("email", { length: 320 }),
loginMethod: varchar("loginMethod", { length: 64 }),
role: mysqlEnum("role", ["user", "admin"]).default("user").notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
lastSignedIn: timestamp("lastSignedIn").defaultNow().notNull(),
});
export type User = typeof users.$inferSelect;
export type InsertUser = typeof users.$inferInsert;
// ─── 车系 ─────────────────────────────────────────────────────────────────────
// 例:复兴号、和谐号
export const vehicleSeries = mysqlTable("vehicle_series", {
id: int("id").autoincrement().primaryKey(),
name: varchar("name", { length: 100 }).notNull(),
description: text("description"),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
});
export type VehicleSeries = typeof vehicleSeries.$inferSelect;
export type InsertVehicleSeries = typeof vehicleSeries.$inferInsert;
// ─── 车型 ─────────────────────────────────────────────────────────────────────
// 例:CR400AF,归属于某车系
export const vehicleModels = mysqlTable("vehicle_models", {
id: int("id").autoincrement().primaryKey(),
seriesId: int("seriesId").notNull(),
name: varchar("name", { length: 100 }).notNull(),
description: text("description"),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
});
export type VehicleModel = typeof vehicleModels.$inferSelect;
export type InsertVehicleModel = typeof vehicleModels.$inferInsert;
// ─── 车型 CAD 文件 ─────────────────────────────────────────────────────────────
// 一个车型可关联多个 CAD 文件(车头、车身、转向架等),低频变更
export const modelCadFiles = mysqlTable("model_cad_files", {
id: int("id").autoincrement().primaryKey(),
modelId: int("modelId").notNull(),
name: varchar("name", { length: 255 }).notNull(),
format: varchar("format", { length: 32 }).notNull(),
fileSize: bigint("fileSize", { mode: "number" }).notNull(),
filePath: varchar("filePath", { length: 512 }).notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
});
export type ModelCadFile = typeof modelCadFiles.$inferSelect;
export type InsertModelCadFile = typeof modelCadFiles.$inferInsert;
// ─── 任务 CAD 文件 ─────────────────────────────────────────────────────────────
// 每个任务可关联任意个 CAD 文件(与车型级 CAD 独立,用于本次检测的实测参考)
export const taskCadFiles = mysqlTable("task_cad_files", {
id: int("id").autoincrement().primaryKey(),
taskId: int("taskId").notNull(),
name: varchar("name", { length: 255 }).notNull(),
format: varchar("format", { length: 32 }).notNull(),
fileSize: bigint("fileSize", { mode: "number" }).notNull(),
filePath: varchar("filePath", { length: 512 }).notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
});
export type TaskCadFile = typeof taskCadFiles.$inferSelect;
export type InsertTaskCadFile = typeof taskCadFiles.$inferInsert;
// ─── 检测任务 ─────────────────────────────────────────────────────────────────
// 每次出厂/维保检测对应一条任务记录,归属于某车型
export const inspectionTasks = mysqlTable("inspection_tasks", {
id: int("id").autoincrement().primaryKey(),
modelId: int("modelId").notNull(),
name: varchar("name", { length: 255 }).notNull(),
inspector: varchar("inspector", { length: 100 }),
notes: text("notes"),
status: mysqlEnum("status", ["pending", "processing", "completed", "error"]).default("pending").notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
completedAt: timestamp("completedAt"),
});
export type InspectionTask = typeof inspectionTasks.$inferSelect;
export type InsertInspectionTask = typeof inspectionTasks.$inferInsert;
// ─── 任务点云文件 ──────────────────────────────────────────────────────────────
// 每次检测上传的点云文件(可多个),归属于某检测任务
export const taskPointcloudFiles = mysqlTable("task_pointcloud_files", {
id: int("id").autoincrement().primaryKey(),
taskId: int("taskId").notNull(),
name: varchar("name", { length: 255 }).notNull(),
fileSize: bigint("fileSize", { mode: "number" }).notNull(),
filePath: varchar("filePath", { length: 512 }).notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
});
export type TaskPointcloudFile = typeof taskPointcloudFiles.$inferSelect;
export type InsertTaskPointcloudFile = typeof taskPointcloudFiles.$inferInsert;
// ─── 任务分析结果 ──────────────────────────────────────────────────────────────
// 对某检测任务运行分析后保存的结果,支持回放
export const taskAnalysisResults = mysqlTable("task_analysis_results", {
id: int("id").autoincrement().primaryKey(),
taskId: int("taskId").notNull(),
type: mysqlEnum("type", [
"error_analysis",
"measurement",
"compression",
"smooth_heatmap",
"assembly_inspection",
"obj_deviation",
// 通用算法插件统一以 'plugin' 类型记录;具体算法以 pluginId 区分
"plugin",
]).notNull(),
/** 仅 type='plugin' 时使用:manifest.id(如 coupler-panel) */
pluginId: varchar("pluginId", { length: 64 }),
/** 算法 result.json 的 schema 版本,便于回放时严格校验 */
schemaVersion: int("schemaVersion"),
status: mysqlEnum("status", ["pending", "processing", "completed", "error"]).default("pending").notNull(),
errorStats: json("errorStats"), // { min, max, mean, stdDev, totalPoints, withinTolerance, outOfTolerance }
measurements: json("measurements"), // [{ name, value, unit, tolerance, status }]
resultData: json("resultData"), // 其他分析数据(如压缩比等)
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
});
export type TaskAnalysisResult = typeof taskAnalysisResults.$inferSelect;
export type InsertTaskAnalysisResult = typeof taskAnalysisResults.$inferInsert;