feat 数据库表_历史报告

This commit is contained in:
Ironsp
2026-09-14 11:42:54 +08:00
parent cc18a19e7e
commit 830aca7088
8 changed files with 270 additions and 91 deletions

View File

@@ -0,0 +1,78 @@
// 历史报告表
import DB from '@/utils/sqlite'
const TABLE = 'history_report'
export const historyReportTableSql = `CREATE TABLE IF NOT EXISTS history_report (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER,
report_name TEXT NOT NULL,
device_id TEXT,
construction_area TEXT,
start_time DATETIME,
end_time DATETIME,
duration REAL,
compaction_area REAL,
pass_count INTEGER,
qualified_rate REAL,
avg_speed REAL,
avg_paving_temp REAL,
avg_compaction REAL,
exception_count INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES project(id)
)`
export interface HistoryReport {
id?: number // 主键,自增
project_id: number // 所属项目 ID,关联 project.id
report_name: string // 历史报告名称,必填
device_id?: string // 设备 ID
construction_area?: string // 施工区域
start_time?: string // 作业开始时间
end_time?: string // 作业结束时间
duration?: number // 作业时长
compaction_area?: number // 压实面积
pass_count?: number // 碾压遍数
qualified_rate?: number // 施工合格率
avg_speed?: number // 平均行驶速度
avg_paving_temp?: number // 平均摊铺温度
avg_compaction?: number // 平均压实度
exception_count?: number // 异常次数,默认 0
created_at?: string // 创建时间,默认当前时间
}
/** 查询全部历史报告 */
export async function selectAll(): Promise<HistoryReport[]> {
return DB.select(TABLE)
}
/** 按 ID 查询 */
export async function selectById(id: number): Promise<HistoryReport | null> {
return DB.selectById(TABLE, id)
}
/** 按项目 ID 筛选历史报告 */
export async function selectByProjectId(projectId: number): Promise<HistoryReport[]> {
return DB.selectByField(TABLE, 'project_id', projectId)
}
/** 按设备 ID 查询 */
export async function selectByDeviceId(deviceId: string): Promise<HistoryReport[]> {
return DB.selectByField(TABLE, 'device_id', deviceId)
}
/** 新增历史报告 */
export async function insert(data: HistoryReport): Promise<any> {
return DB.insert(TABLE, data)
}
/** 更新历史报告 */
export async function update(id: number, data: Partial<HistoryReport>): Promise<any> {
return DB.update(TABLE, data, `id = ${id}`)
}
/** 删除历史报告 */
export async function remove(id: number): Promise<any> {
return DB.delete(TABLE, `id = ${id}`)
}

View File

@@ -1,9 +1,12 @@
import DB from '@/utils/sqlite' import DB from '@/utils/sqlite'
import { historyReportTableSql } from './historyReport'
import { projectTableSql } from './project' import { projectTableSql } from './project'
import { rtkTrackTableSql } from './rtkTrack' import { rtkTrackTableSql } from './rtkTrack'
import { warningRecordTableSql } from './warningRecord' import { warningRecordTableSql } from './warningRecord'
import { workRecordTableSql } from './workRecord' import { workRecordTableSql } from './workRecord'
export { historyReportTableSql } from './historyReport'
export * as historyReportService from './historyReport'
export { projectTableSql } from './project' export { projectTableSql } from './project'
// 导出所有 service 方法 // 导出所有 service 方法
export * as projectService from './project' export * as projectService from './project'
@@ -21,6 +24,7 @@ const tableSqls = [
workRecordTableSql, workRecordTableSql,
rtkTrackTableSql, rtkTrackTableSql,
warningRecordTableSql, warningRecordTableSql,
historyReportTableSql,
] ]
/** /**

View File

@@ -17,7 +17,7 @@ export interface Project {
project_name: string // 项目名称,必填 project_name: string // 项目名称,必填
stake_range: string // 项目范围,可选 stake_range: string // 项目范围,可选
total_area: number // 项目总面积,可选 total_area: number // 项目总面积,可选
status: 0 | 1 // 项目状态,0:未完成,1:已完成,默认0 status: 0 | 1 | 2 // 项目状态,0:未完成,1:已完成,默认0,. 进行中2
created_at?: string // 创建时间,默认当前时间 created_at?: string // 创建时间,默认当前时间
updated_at?: string // 更新时间,默认当前时间 updated_at?: string // 更新时间,默认当前时间
} }

View File

@@ -5,29 +5,29 @@ const TABLE = 'rtk_track'
export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track ( export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
work_record_id INTEGER, work_record_id INTEGER,
timestamp DATETIME,
latitude REAL, latitude REAL,
longitude REAL, longitude REAL,
altitude REAL,
speed REAL, speed REAL,
heading REAL, heading REAL,
steel_wheel_temp REAL,
compaction_value REAL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP, created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (work_record_id) REFERENCES work_record(id) FOREIGN KEY (work_record_id) REFERENCES work_record(id)
)` )`
export interface RtkTrack { export interface RtkTrack {
id?: number id?: number // 主键,自增
work_record_id: number work_record_id: number // 所属作业记录 ID,关联 work_record.id
timestamp?: string latitude?: number // 纬度
latitude?: number longitude?: number // 经度
longitude?: number speed?: number // 行驶速度
altitude?: number heading?: number // 航向角度(度)
speed?: number steel_wheel_temp?: number // 钢轮温度
heading?: number compaction_value?: number // 压实度
created_at?: string created_at?: string // 创建时间,默认当前时间
} }
/** 查询全部 */ /** 查询全部 RTK 轨迹 */
export async function selectAll(): Promise<RtkTrack[]> { export async function selectAll(): Promise<RtkTrack[]> {
return DB.select(TABLE) return DB.select(TABLE)
} }
@@ -42,17 +42,17 @@ export async function selectByWorkRecordId(workRecordId: number): Promise<RtkTra
return DB.selectByField(TABLE, 'work_record_id', workRecordId) return DB.selectByField(TABLE, 'work_record_id', workRecordId)
} }
/** 新增 */ /** 新增轨迹点 */
export async function insert(data: RtkTrack): Promise<any> { export async function insert(data: RtkTrack): Promise<any> {
return DB.insert(TABLE, data) return DB.insert(TABLE, data)
} }
/** 更新 */ /** 更新轨迹点 */
export async function update(id: number, data: Partial<RtkTrack>): Promise<any> { export async function update(id: number, data: Partial<RtkTrack>): Promise<any> {
return DB.update(TABLE, data, `id = ${id}`) return DB.update(TABLE, data, `id = ${id}`)
} }
/** 删除 */ /** 删除轨迹点 */
export async function remove(id: number): Promise<any> { export async function remove(id: number): Promise<any> {
return DB.delete(TABLE, `id = ${id}`) return DB.delete(TABLE, `id = ${id}`)
} }

View File

@@ -2,23 +2,27 @@ import DB from '@/utils/sqlite'
/** /**
* 插入项目假数据(3条) * 插入项目假数据(3条)
* 字段:project_name / stake_range / total_area / status(0未完成 1已完成 2进行中)
*/ */
async function seedProject() { async function seedProject() {
const data = [ const data = [
{ {
project_name: '京雄高速河北段', project_name: '京雄高速河北段',
project_type: '高速公路', stake_range: 'K1+000 ~ K5+500',
status: 'online', total_area: 12500.0,
status: 2,
}, },
{ {
project_name: '雄安新区市政道路', project_name: '雄安新区市政道路',
project_type: '市政工程', stake_range: 'A区 ~ C区',
status: 'online', total_area: 8600.5,
status: 0,
}, },
{ {
project_name: '白沟产业园场地', project_name: '白沟产业园场地',
project_type: '场地平整', stake_range: '1号地块',
status: 'offline', total_area: 5200.0,
status: 1,
}, },
] ]
@@ -29,6 +33,7 @@ async function seedProject() {
/** /**
* 插入作业记录假数据(3条) * 插入作业记录假数据(3条)
* 字段:project_id / start_time / end_time / compaction_area / pass_count
*/ */
async function seedWorkRecord() { async function seedWorkRecord() {
const data = [ const data = [
@@ -36,34 +41,22 @@ async function seedWorkRecord() {
project_id: 1, project_id: 1,
start_time: '2026-09-10 08:00:00', start_time: '2026-09-10 08:00:00',
end_time: '2026-09-10 12:00:00', end_time: '2026-09-10 12:00:00',
speed: 5.2, compaction_area: 1250.5,
frequency: 28.5, pass_count: 6,
amplitude: 1.8,
compaction_value: 92.3,
gps_lat: 38.9697,
gps_lng: 115.9697,
}, },
{ {
project_id: 1, project_id: 1,
start_time: '2026-09-10 13:00:00', start_time: '2026-09-10 13:00:00',
end_time: '2026-09-10 17:30:00', end_time: '2026-09-10 17:30:00',
speed: 4.8, compaction_area: 1680.0,
frequency: 30.0, pass_count: 8,
amplitude: 2.0,
compaction_value: 95.1,
gps_lat: 38.9712,
gps_lng: 115.9712,
}, },
{ {
project_id: 2, project_id: 2,
start_time: '2026-09-09 07:30:00', start_time: '2026-09-09 07:30:00',
end_time: '2026-09-09 11:30:00', end_time: '2026-09-09 11:30:00',
speed: 6.0, compaction_area: 980.3,
frequency: 25.0, pass_count: 5,
amplitude: 1.5,
compaction_value: 88.7,
gps_lat: 38.9534,
gps_lng: 115.9534,
}, },
] ]
@@ -74,35 +67,36 @@ async function seedWorkRecord() {
/** /**
* 插入 RTK 轨迹假数据(3条) * 插入 RTK 轨迹假数据(3条)
* 字段:work_record_id / latitude / longitude / speed / heading / steel_wheel_temp / compaction_value
*/ */
async function seedRtkTrack() { async function seedRtkTrack() {
const data = [ const data = [
{ {
work_record_id: 1, work_record_id: 1,
timestamp: '2026-09-10 08:00:05',
latitude: 38.9697, latitude: 38.9697,
longitude: 115.9697, longitude: 115.9697,
altitude: 15.2,
speed: 5.1, speed: 5.1,
heading: 90.0, heading: 90.0,
steel_wheel_temp: 65.2,
compaction_value: 92.3,
}, },
{ {
work_record_id: 1, work_record_id: 1,
timestamp: '2026-09-10 08:00:10',
latitude: 38.9698, latitude: 38.9698,
longitude: 115.9699, longitude: 115.9699,
altitude: 15.3,
speed: 5.2, speed: 5.2,
heading: 92.5, heading: 92.5,
steel_wheel_temp: 66.0,
compaction_value: 93.1,
}, },
{ {
work_record_id: 2, work_record_id: 2,
timestamp: '2026-09-10 13:00:05',
latitude: 38.9712, latitude: 38.9712,
longitude: 115.9712, longitude: 115.9712,
altitude: 16.0,
speed: 4.7, speed: 4.7,
heading: 180.0, heading: 180.0,
steel_wheel_temp: 68.5,
compaction_value: 95.0,
}, },
] ]
@@ -113,28 +107,40 @@ async function seedRtkTrack() {
/** /**
* 插入告警记录假数据(3条) * 插入告警记录假数据(3条)
* 字段:project_id / device_name / exception_type(0数据中断 1高温异常 2定位异常)
* occurred_at / site_description / disposal_record
* disposal_type(0未处理 1现场恢复 2需要保修) / is_read
*/ */
async function seedWarningRecord() { async function seedWarningRecord() {
const data = [ const data = [
{ {
project_id: 1, project_id: 1,
warning_type: '超速', device_name: 'XS-65H',
warning_level: 'high', exception_type: 0,
message: '碾压速度超过设定阈值(6.5km/h)', occurred_at: '2026-09-10 09:15:00',
site_description: '设备上报数据中断超过 30 秒',
disposal_record: '',
disposal_type: 0,
is_read: 0, is_read: 0,
}, },
{ {
project_id: 2, project_id: 2,
warning_type: '漏压', device_name: 'XS-65H',
warning_level: 'medium', exception_type: 1,
message: 'K2+350处检测到漏压区域', occurred_at: '2026-09-09 10:20:00',
site_description: '钢轮温度超过安全阈值',
disposal_record: '现场降温后恢复作业',
disposal_type: 1,
is_read: 0, is_read: 0,
}, },
{ {
project_id: 1, project_id: 1,
warning_type: '偏航', device_name: 'RTK-01',
warning_level: 'low', exception_type: 2,
message: 'RTK信号偏移超过2cm', occurred_at: '2026-09-10 14:05:00',
site_description: 'RTK 定位信号丢失,无法获取有效坐标',
disposal_record: '设备故障,已登记报修',
disposal_type: 2,
is_read: 1, is_read: 1,
}, },
] ]
@@ -144,6 +150,69 @@ async function seedWarningRecord() {
} }
} }
/**
* 插入历史报告假数据(3条)
* 字段:project_id / report_name / device_id / construction_area
* start_time / end_time / duration / compaction_area / pass_count
* qualified_rate / avg_speed / avg_paving_temp / avg_compaction / exception_count
*/
async function seedHistoryReport() {
const data = [
{
project_id: 1,
report_name: '京雄高速K1段碾压报告',
device_id: 'XS-65H-001',
construction_area: 'K1+000 ~ K1+500',
start_time: '2026-09-10 08:00:00',
end_time: '2026-09-10 12:00:00',
duration: 4,
compaction_area: 1250.5,
pass_count: 6,
qualified_rate: 96.5,
avg_speed: 5.2,
avg_paving_temp: 145.0,
avg_compaction: 92.3,
exception_count: 1,
},
{
project_id: 1,
report_name: '京雄高速K2段碾压报告',
device_id: 'XS-65H-001',
construction_area: 'K2+000 ~ K2+350',
start_time: '2026-09-10 13:00:00',
end_time: '2026-09-10 17:30:00',
duration: 4.5,
compaction_area: 1680.0,
pass_count: 8,
qualified_rate: 98.2,
avg_speed: 4.8,
avg_paving_temp: 150.0,
avg_compaction: 95.1,
exception_count: 0,
},
{
project_id: 2,
report_name: '雄安市政道路碾压报告',
device_id: 'XS-65H-002',
construction_area: 'A区施工段',
start_time: '2026-09-09 07:30:00',
end_time: '2026-09-09 11:30:00',
duration: 4,
compaction_area: 980.3,
pass_count: 5,
qualified_rate: 94.0,
avg_speed: 6.0,
avg_paving_temp: 138.5,
avg_compaction: 88.7,
exception_count: 2,
},
]
for (const item of data) {
await DB.insert('history_report', item)
}
}
/** /**
* 初始化所有假数据 * 初始化所有假数据
*/ */
@@ -154,6 +223,7 @@ export async function seedAll() {
await seedWorkRecord() await seedWorkRecord()
await seedRtkTrack() await seedRtkTrack()
await seedWarningRecord() await seedWarningRecord()
await seedHistoryReport()
console.log('假数据插入完成') console.log('假数据插入完成')
} }
catch (err) { catch (err) {

View File

@@ -1,3 +1,4 @@
// 告警记录表
import DB from '@/utils/sqlite' import DB from '@/utils/sqlite'
const TABLE = 'warning_record' const TABLE = 'warning_record'
@@ -5,25 +6,31 @@ const TABLE = 'warning_record'
export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record ( export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER, project_id INTEGER,
warning_type TEXT, device_name TEXT,
warning_level TEXT, exception_type INTEGER,
message TEXT, occurred_at DATETIME,
site_description TEXT,
disposal_record TEXT,
disposal_type INTEGER,
is_read INTEGER DEFAULT 0, is_read INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP, created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES project(id) FOREIGN KEY (project_id) REFERENCES project(id)
)` )`
export interface WarningRecord { export interface WarningRecord {
id?: number id?: number // 主键,自增
project_id: number project_id: number // 所属项目 ID,关联 project.id
warning_type?: string device_name?: string // 设备名称
warning_level?: string exception_type?: 0 | 1 | 2 // 异常类型,0:数据中断,1:高温异常,2:定位异常
message?: string occurred_at?: string // 发生时间
is_read?: number site_description?: string // 现场描述
created_at?: string disposal_record?: string // 现场处置记录
disposal_type?: 0 | 1 | 2 // 处置类型,0:未处理,1:现场恢复,2:需要保修
is_read?: number // 是否已读,0:未读,1:已读,默认 0
created_at?: string // 创建时间,默认当前时间
} }
/** 查询全部 */ /** 查询全部告警记录 */
export async function selectAll(): Promise<WarningRecord[]> { export async function selectAll(): Promise<WarningRecord[]> {
return DB.select(TABLE) return DB.select(TABLE)
} }
@@ -38,12 +45,12 @@ export async function selectByProjectId(projectId: number): Promise<WarningRecor
return DB.selectByField(TABLE, 'project_id', projectId) return DB.selectByField(TABLE, 'project_id', projectId)
} }
/** 查询未读 */ /** 查询未读告警 */
export async function selectUnread(): Promise<WarningRecord[]> { export async function selectUnread(): Promise<WarningRecord[]> {
return DB.select(TABLE, '*', 'is_read = 0') return DB.select(TABLE, '*', 'is_read = 0')
} }
/** 新增 */ /** 新增告警记录 */
export async function insert(data: WarningRecord): Promise<any> { export async function insert(data: WarningRecord): Promise<any> {
return DB.insert(TABLE, data) return DB.insert(TABLE, data)
} }
@@ -53,12 +60,12 @@ export async function markRead(id: number): Promise<any> {
return DB.update(TABLE, { is_read: 1 }, `id = ${id}`) return DB.update(TABLE, { is_read: 1 }, `id = ${id}`)
} }
/** 更新 */ /** 更新告警记录 */
export async function update(id: number, data: Partial<WarningRecord>): Promise<any> { export async function update(id: number, data: Partial<WarningRecord>): Promise<any> {
return DB.update(TABLE, data, `id = ${id}`) return DB.update(TABLE, data, `id = ${id}`)
} }
/** 删除 */ /** 删除告警记录 */
export async function remove(id: number): Promise<any> { export async function remove(id: number): Promise<any> {
return DB.delete(TABLE, `id = ${id}`) return DB.delete(TABLE, `id = ${id}`)
} }

View File

@@ -1,3 +1,4 @@
// 工作记录表
import DB from '@/utils/sqlite' import DB from '@/utils/sqlite'
const TABLE = 'work_record' const TABLE = 'work_record'
@@ -7,31 +8,23 @@ export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
project_id INTEGER, project_id INTEGER,
start_time DATETIME, start_time DATETIME,
end_time DATETIME, end_time DATETIME,
speed REAL, compaction_area REAL,
frequency REAL, pass_count INTEGER,
amplitude REAL,
compaction_value REAL,
gps_lat REAL,
gps_lng REAL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP, created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES project(id) FOREIGN KEY (project_id) REFERENCES project(id)
)` )`
export interface WorkRecord { export interface WorkRecord {
id?: number id?: number // 主键,自增
project_id: number project_id: number // 所属项目 ID,关联 project.id
start_time?: string start_time?: string // 作业开始时间
end_time?: string end_time?: string // 作业结束时间
speed?: number compaction_area?: number // 压实面积
frequency?: number pass_count?: number // 碾压遍数
amplitude?: number created_at?: string // 创建时间,默认当前时间
compaction_value?: number
gps_lat?: number
gps_lng?: number
created_at?: string
} }
/** 查询全部 */ /** 查询全部作业记录 */
export async function selectAll(): Promise<WorkRecord[]> { export async function selectAll(): Promise<WorkRecord[]> {
return DB.select(TABLE) return DB.select(TABLE)
} }
@@ -46,17 +39,17 @@ export async function selectByProjectId(projectId: number): Promise<WorkRecord[]
return DB.selectByField(TABLE, 'project_id', projectId) return DB.selectByField(TABLE, 'project_id', projectId)
} }
/** 新增 */ /** 新增作业记录 */
export async function insert(data: WorkRecord): Promise<any> { export async function insert(data: WorkRecord): Promise<any> {
return DB.insert(TABLE, data) return DB.insert(TABLE, data)
} }
/** 更新 */ /** 更新作业记录 */
export async function update(id: number, data: Partial<WorkRecord>): Promise<any> { export async function update(id: number, data: Partial<WorkRecord>): Promise<any> {
return DB.update(TABLE, data, `id = ${id}`) return DB.update(TABLE, data, `id = ${id}`)
} }
/** 删除 */ /** 删除作业记录 */
export async function remove(id: number): Promise<any> { export async function remove(id: number): Promise<any> {
return DB.delete(TABLE, `id = ${id}`) return DB.delete(TABLE, `id = ${id}`)
} }

View File

@@ -1,3 +1,4 @@
import type { HistoryReport } from '@/service/historyReport'
import type { Project } from '@/service/project' import type { Project } from '@/service/project'
import type { RtkTrack } from '@/service/rtkTrack' import type { RtkTrack } from '@/service/rtkTrack'
import type { WarningRecord } from '@/service/warningRecord' import type { WarningRecord } from '@/service/warningRecord'
@@ -5,6 +6,7 @@ import type { WorkRecord } from '@/service/workRecord'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { ref } from 'vue' import { ref } from 'vue'
import { import {
historyReportService,
projectService, projectService,
rtkTrackService, rtkTrackService,
warningRecordService, warningRecordService,
@@ -17,6 +19,7 @@ export const useDbStore = defineStore('db', () => {
const workRecords = ref<WorkRecord[]>([]) const workRecords = ref<WorkRecord[]>([])
const rtkTracks = ref<RtkTrack[]>([]) const rtkTracks = ref<RtkTrack[]>([])
const warningRecords = ref<WarningRecord[]>([]) const warningRecords = ref<WarningRecord[]>([])
const historyReports = ref<HistoryReport[]>([])
// --- Project --- // --- Project ---
async function loadProjects() { async function loadProjects() {
@@ -79,12 +82,31 @@ export const useDbStore = defineStore('db', () => {
await loadWarningRecords() await loadWarningRecords()
} }
// --- HistoryReport ---
async function loadHistoryReports() {
historyReports.value = await historyReportService.selectAll()
}
async function loadHistoryReportsByProject(projectId: number) {
historyReports.value = await historyReportService.selectByProjectId(projectId)
}
async function loadHistoryReportsByDevice(deviceId: string) {
historyReports.value = await historyReportService.selectByDeviceId(deviceId)
}
async function addHistoryReport(data: HistoryReport) {
await historyReportService.insert(data)
await loadHistoryReports()
}
return { return {
// State // State
projects, projects,
workRecords, workRecords,
rtkTracks, rtkTracks,
warningRecords, warningRecords,
historyReports,
// Project // Project
loadProjects, loadProjects,
addProject, addProject,
@@ -102,5 +124,10 @@ export const useDbStore = defineStore('db', () => {
loadWarningRecords, loadWarningRecords,
loadUnreadWarnings, loadUnreadWarnings,
markWarningRead, markWarningRead,
// HistoryReport
loadHistoryReports,
loadHistoryReportsByProject,
loadHistoryReportsByDevice,
addHistoryReport,
} }
}) })