feat 建表

This commit is contained in:
Ironsp
2026-09-08 16:46:06 +08:00
parent bbde4c4a66
commit 3d304ec8c9
6 changed files with 128 additions and 197 deletions

32
src/service/index.ts Normal file
View File

@@ -0,0 +1,32 @@
import DB from '@/utils/sqlite'
import { projectTableSql } from './project'
import { rtkTrackTableSql } from './rtkTrack'
import { warningRecordTableSql } from './warningRecord'
import { workRecordTableSql } from './workRecord'
export { projectTableSql } from './project'
export { rtkTrackTableSql } from './rtkTrack'
export { warningRecordTableSql } from './warningRecord'
export { workRecordTableSql } from './workRecord'
/**
* 初始化数据库表
*/
export async function initTables() {
const sqls = [
projectTableSql,
workRecordTableSql,
rtkTrackTableSql,
warningRecordTableSql,
]
try {
await DB.transaction(sqls)
console.log('数据库表初始化成功')
}
catch (err) {
console.error('数据库表初始化失败:', err)
throw err
}
}

16
src/service/project.ts Normal file
View File

@@ -0,0 +1,16 @@
/**
* 项目信息表
* 字段说明:
* - id:项目唯一标识符
* - project_name:项目名称
* - project_type:项目类型
* - status:项目状态(默认值为 'offline')
*/
export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_name TEXT NOT NULL,
project_type TEXT,
status TEXT DEFAULT 'offline',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
)`

24
src/service/rtkTrack.ts Normal file
View File

@@ -0,0 +1,24 @@
/**
* RTK 轨迹数据表
* 字段说明:
* - id:轨迹唯一标识符
* - work_record_id:作业记录 ID
* - timestamp:时间戳
* - latitude:纬度
* - longitude:经度
* - altitude:高度
* - speed:速度
* - heading:方向
*/
export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
id INTEGER PRIMARY KEY AUTOINCREMENT,
work_record_id INTEGER,
timestamp DATETIME,
latitude REAL,
longitude REAL,
altitude REAL,
speed REAL,
heading REAL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (work_record_id) REFERENCES work_record(id)
)`

View File

@@ -0,0 +1,21 @@
/**
* 告警记录表
* 字段说明:
* - id:告警记录唯一标识符
* - project_id:项目 ID
* - warning_type:告警类型
* - warning_level:告警等级
* - message:告警信息
* - is_read:是否已读(0 表示未读,1 表示已读,默认值为 0)
* - created_at:创建时间(默认值为当前时间)
*/
export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER,
warning_type TEXT,
warning_level TEXT,
message TEXT,
is_read INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES project(id)
)`

30
src/service/workRecord.ts Normal file
View File

@@ -0,0 +1,30 @@
/**
* 作业记录表
* 字段说明:
* -id:作业记录唯一标识符
* -project_id:所属项目ID
* -start_time:作业开始时间
* -end_time:作业结束时间
* -speed:作业速度
* -frequency:作业频率
* -amplitude:作业振幅
* -compaction_value:压实度值
* -gps_lat:GPS纬度
* -gps_lng:GPS经度
* -created_at:记录创建时间(默认值为当前时间)
* -FOREIGN KEY (project_id) REFERENCES project(id):外键约束,关联到项目表中的id字段
*/
export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER,
start_time DATETIME,
end_time DATETIME,
speed REAL,
frequency REAL,
amplitude REAL,
compaction_value REAL,
gps_lat REAL,
gps_lng REAL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES project(id)
)`