feat 添加mock数据
This commit is contained in:
@@ -5,9 +5,16 @@ import { warningRecordTableSql } from './warningRecord'
|
||||
import { workRecordTableSql } from './workRecord'
|
||||
|
||||
export { projectTableSql } from './project'
|
||||
// 导出所有 service 方法
|
||||
export * as projectService from './project'
|
||||
export { rtkTrackTableSql } from './rtkTrack'
|
||||
export * as rtkTrackService from './rtkTrack'
|
||||
export { seedAll } from './seed'
|
||||
|
||||
export { warningRecordTableSql } from './warningRecord'
|
||||
export * as warningRecordService from './warningRecord'
|
||||
export { workRecordTableSql } from './workRecord'
|
||||
export * as workRecordService from './workRecord'
|
||||
|
||||
const tableSqls = [
|
||||
projectTableSql,
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
/**
|
||||
* 项目信息表: 项目名称,压路机名称, (平板)设备ID, 开始时间, 结束时间,
|
||||
* 字段说明:
|
||||
* - id:项目唯一标识符
|
||||
* - project_name:项目名称
|
||||
* - project_type:项目类型
|
||||
* - status:项目状态(默认值为 'offline')
|
||||
*/
|
||||
import DB from '@/utils/sqlite'
|
||||
|
||||
const TABLE = 'project'
|
||||
|
||||
export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
project_name TEXT NOT NULL,
|
||||
@@ -14,3 +10,42 @@ export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)`
|
||||
|
||||
export interface Project {
|
||||
id?: number
|
||||
project_name: string
|
||||
project_type?: string
|
||||
status?: string
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 查询全部项目 */
|
||||
export async function selectAll(): Promise<Project[]> {
|
||||
return DB.select(TABLE)
|
||||
}
|
||||
|
||||
/** 按 ID 查询 */
|
||||
export async function selectById(id: number): Promise<Project | null> {
|
||||
return DB.selectById(TABLE, id)
|
||||
}
|
||||
|
||||
/** 按状态查询 */
|
||||
export async function selectByStatus(status: string): Promise<Project[]> {
|
||||
return DB.selectByField(TABLE, 'status', status)
|
||||
}
|
||||
|
||||
/** 新增项目 */
|
||||
export async function insert(data: Project): Promise<any> {
|
||||
return DB.insert(TABLE, data)
|
||||
}
|
||||
|
||||
/** 更新项目 */
|
||||
export async function update(id: number, data: Partial<Project>): Promise<any> {
|
||||
return DB.update(TABLE, data, `id = ${id}`)
|
||||
}
|
||||
|
||||
/** 删除项目 */
|
||||
export async function remove(id: number): Promise<any> {
|
||||
return DB.delete(TABLE, `id = ${id}`)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
/**
|
||||
* RTK 轨迹数据表: 作业记录ID, 时间戳, , 压实度, 纬度, 经度, 高度, 速度, 方向, 创建时间, 外键约束
|
||||
* 字段说明:
|
||||
* - id:轨迹唯一标识符
|
||||
* - work_record_id:作业记录 ID
|
||||
* - timestamp:时间戳
|
||||
* - latitude:纬度
|
||||
* - longitude:经度
|
||||
* - altitude:高度
|
||||
* - speed:速度
|
||||
* - heading:方向
|
||||
* - created_at:记录创建时间(默认值为当前时间)
|
||||
*/
|
||||
import DB from '@/utils/sqlite'
|
||||
|
||||
const TABLE = 'rtk_track'
|
||||
|
||||
export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
work_record_id INTEGER,
|
||||
@@ -23,3 +14,45 @@ export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (work_record_id) REFERENCES work_record(id)
|
||||
)`
|
||||
|
||||
export interface RtkTrack {
|
||||
id?: number
|
||||
work_record_id: number
|
||||
timestamp?: string
|
||||
latitude?: number
|
||||
longitude?: number
|
||||
altitude?: number
|
||||
speed?: number
|
||||
heading?: number
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
/** 查询全部 */
|
||||
export async function selectAll(): Promise<RtkTrack[]> {
|
||||
return DB.select(TABLE)
|
||||
}
|
||||
|
||||
/** 按 ID 查询 */
|
||||
export async function selectById(id: number): Promise<RtkTrack | null> {
|
||||
return DB.selectById(TABLE, id)
|
||||
}
|
||||
|
||||
/** 按作业记录 ID 查询 */
|
||||
export async function selectByWorkRecordId(workRecordId: number): Promise<RtkTrack[]> {
|
||||
return DB.selectByField(TABLE, 'work_record_id', workRecordId)
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
export async function insert(data: RtkTrack): Promise<any> {
|
||||
return DB.insert(TABLE, data)
|
||||
}
|
||||
|
||||
/** 更新 */
|
||||
export async function update(id: number, data: Partial<RtkTrack>): Promise<any> {
|
||||
return DB.update(TABLE, data, `id = ${id}`)
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
export async function remove(id: number): Promise<any> {
|
||||
return DB.delete(TABLE, `id = ${id}`)
|
||||
}
|
||||
|
||||
163
src/service/seed.ts
Normal file
163
src/service/seed.ts
Normal file
@@ -0,0 +1,163 @@
|
||||
import DB from '@/utils/sqlite'
|
||||
|
||||
/**
|
||||
* 插入项目假数据(3条)
|
||||
*/
|
||||
async function seedProject() {
|
||||
const data = [
|
||||
{
|
||||
project_name: '京雄高速河北段',
|
||||
project_type: '高速公路',
|
||||
status: 'online',
|
||||
},
|
||||
{
|
||||
project_name: '雄安新区市政道路',
|
||||
project_type: '市政工程',
|
||||
status: 'online',
|
||||
},
|
||||
{
|
||||
project_name: '白沟产业园场地',
|
||||
project_type: '场地平整',
|
||||
status: 'offline',
|
||||
},
|
||||
]
|
||||
|
||||
for (const item of data) {
|
||||
await DB.insert('project', item)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入作业记录假数据(3条)
|
||||
*/
|
||||
async function seedWorkRecord() {
|
||||
const data = [
|
||||
{
|
||||
project_id: 1,
|
||||
start_time: '2026-09-10 08:00:00',
|
||||
end_time: '2026-09-10 12:00:00',
|
||||
speed: 5.2,
|
||||
frequency: 28.5,
|
||||
amplitude: 1.8,
|
||||
compaction_value: 92.3,
|
||||
gps_lat: 38.9697,
|
||||
gps_lng: 115.9697,
|
||||
},
|
||||
{
|
||||
project_id: 1,
|
||||
start_time: '2026-09-10 13:00:00',
|
||||
end_time: '2026-09-10 17:30:00',
|
||||
speed: 4.8,
|
||||
frequency: 30.0,
|
||||
amplitude: 2.0,
|
||||
compaction_value: 95.1,
|
||||
gps_lat: 38.9712,
|
||||
gps_lng: 115.9712,
|
||||
},
|
||||
{
|
||||
project_id: 2,
|
||||
start_time: '2026-09-09 07:30:00',
|
||||
end_time: '2026-09-09 11:30:00',
|
||||
speed: 6.0,
|
||||
frequency: 25.0,
|
||||
amplitude: 1.5,
|
||||
compaction_value: 88.7,
|
||||
gps_lat: 38.9534,
|
||||
gps_lng: 115.9534,
|
||||
},
|
||||
]
|
||||
|
||||
for (const item of data) {
|
||||
await DB.insert('work_record', item)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入 RTK 轨迹假数据(3条)
|
||||
*/
|
||||
async function seedRtkTrack() {
|
||||
const data = [
|
||||
{
|
||||
work_record_id: 1,
|
||||
timestamp: '2026-09-10 08:00:05',
|
||||
latitude: 38.9697,
|
||||
longitude: 115.9697,
|
||||
altitude: 15.2,
|
||||
speed: 5.1,
|
||||
heading: 90.0,
|
||||
},
|
||||
{
|
||||
work_record_id: 1,
|
||||
timestamp: '2026-09-10 08:00:10',
|
||||
latitude: 38.9698,
|
||||
longitude: 115.9699,
|
||||
altitude: 15.3,
|
||||
speed: 5.2,
|
||||
heading: 92.5,
|
||||
},
|
||||
{
|
||||
work_record_id: 2,
|
||||
timestamp: '2026-09-10 13:00:05',
|
||||
latitude: 38.9712,
|
||||
longitude: 115.9712,
|
||||
altitude: 16.0,
|
||||
speed: 4.7,
|
||||
heading: 180.0,
|
||||
},
|
||||
]
|
||||
|
||||
for (const item of data) {
|
||||
await DB.insert('rtk_track', item)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入告警记录假数据(3条)
|
||||
*/
|
||||
async function seedWarningRecord() {
|
||||
const data = [
|
||||
{
|
||||
project_id: 1,
|
||||
warning_type: '超速',
|
||||
warning_level: 'high',
|
||||
message: '碾压速度超过设定阈值(6.5km/h)',
|
||||
is_read: 0,
|
||||
},
|
||||
{
|
||||
project_id: 2,
|
||||
warning_type: '漏压',
|
||||
warning_level: 'medium',
|
||||
message: 'K2+350处检测到漏压区域',
|
||||
is_read: 0,
|
||||
},
|
||||
{
|
||||
project_id: 1,
|
||||
warning_type: '偏航',
|
||||
warning_level: 'low',
|
||||
message: 'RTK信号偏移超过2cm',
|
||||
is_read: 1,
|
||||
},
|
||||
]
|
||||
|
||||
for (const item of data) {
|
||||
await DB.insert('warning_record', item)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化所有假数据
|
||||
*/
|
||||
export async function seedAll() {
|
||||
try {
|
||||
console.log('开始插入假数据...')
|
||||
await seedProject()
|
||||
await seedWorkRecord()
|
||||
await seedRtkTrack()
|
||||
await seedWarningRecord()
|
||||
console.log('假数据插入完成')
|
||||
}
|
||||
catch (err) {
|
||||
console.error('假数据插入失败:', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* 告警记录表
|
||||
* 字段说明:
|
||||
* - id:告警记录唯一标识符
|
||||
* - project_id:项目 ID
|
||||
* - warning_type:告警类型
|
||||
* - warning_level:告警等级
|
||||
* - message:告警信息
|
||||
* - is_read:是否已读(0 表示未读,1 表示已读,默认值为 0)
|
||||
* - created_at:创建时间(默认值为当前时间)
|
||||
*/
|
||||
import DB from '@/utils/sqlite'
|
||||
|
||||
const TABLE = 'warning_record'
|
||||
|
||||
export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
project_id INTEGER,
|
||||
@@ -19,3 +12,53 @@ export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (project_id) REFERENCES project(id)
|
||||
)`
|
||||
|
||||
export interface WarningRecord {
|
||||
id?: number
|
||||
project_id: number
|
||||
warning_type?: string
|
||||
warning_level?: string
|
||||
message?: string
|
||||
is_read?: number
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
/** 查询全部 */
|
||||
export async function selectAll(): Promise<WarningRecord[]> {
|
||||
return DB.select(TABLE)
|
||||
}
|
||||
|
||||
/** 按 ID 查询 */
|
||||
export async function selectById(id: number): Promise<WarningRecord | null> {
|
||||
return DB.selectById(TABLE, id)
|
||||
}
|
||||
|
||||
/** 按项目 ID 查询 */
|
||||
export async function selectByProjectId(projectId: number): Promise<WarningRecord[]> {
|
||||
return DB.selectByField(TABLE, 'project_id', projectId)
|
||||
}
|
||||
|
||||
/** 查询未读 */
|
||||
export async function selectUnread(): Promise<WarningRecord[]> {
|
||||
return DB.select(TABLE, '*', 'is_read = 0')
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
export async function insert(data: WarningRecord): Promise<any> {
|
||||
return DB.insert(TABLE, data)
|
||||
}
|
||||
|
||||
/** 标记已读 */
|
||||
export async function markRead(id: number): Promise<any> {
|
||||
return DB.update(TABLE, { is_read: 1 }, `id = ${id}`)
|
||||
}
|
||||
|
||||
/** 更新 */
|
||||
export async function update(id: number, data: Partial<WarningRecord>): Promise<any> {
|
||||
return DB.update(TABLE, data, `id = ${id}`)
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
export async function remove(id: number): Promise<any> {
|
||||
return DB.delete(TABLE, `id = ${id}`)
|
||||
}
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
/**
|
||||
* 作业记录表
|
||||
* 字段说明:
|
||||
* -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字段
|
||||
*/
|
||||
import DB from '@/utils/sqlite'
|
||||
|
||||
const TABLE = 'work_record'
|
||||
|
||||
export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
project_id INTEGER,
|
||||
@@ -28,3 +16,47 @@ export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (project_id) REFERENCES project(id)
|
||||
)`
|
||||
|
||||
export interface WorkRecord {
|
||||
id?: number
|
||||
project_id: number
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
speed?: number
|
||||
frequency?: number
|
||||
amplitude?: number
|
||||
compaction_value?: number
|
||||
gps_lat?: number
|
||||
gps_lng?: number
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
/** 查询全部 */
|
||||
export async function selectAll(): Promise<WorkRecord[]> {
|
||||
return DB.select(TABLE)
|
||||
}
|
||||
|
||||
/** 按 ID 查询 */
|
||||
export async function selectById(id: number): Promise<WorkRecord | null> {
|
||||
return DB.selectById(TABLE, id)
|
||||
}
|
||||
|
||||
/** 按项目 ID 查询 */
|
||||
export async function selectByProjectId(projectId: number): Promise<WorkRecord[]> {
|
||||
return DB.selectByField(TABLE, 'project_id', projectId)
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
export async function insert(data: WorkRecord): Promise<any> {
|
||||
return DB.insert(TABLE, data)
|
||||
}
|
||||
|
||||
/** 更新 */
|
||||
export async function update(id: number, data: Partial<WorkRecord>): Promise<any> {
|
||||
return DB.update(TABLE, data, `id = ${id}`)
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
export async function remove(id: number): Promise<any> {
|
||||
return DB.delete(TABLE, `id = ${id}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user