diff --git a/src/service/historyReport.ts b/src/service/historyReport.ts new file mode 100644 index 0000000..ee8e9f1 --- /dev/null +++ b/src/service/historyReport.ts @@ -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 { + return DB.select(TABLE) +} + +/** 按 ID 查询 */ +export async function selectById(id: number): Promise { + return DB.selectById(TABLE, id) +} + +/** 按项目 ID 筛选历史报告 */ +export async function selectByProjectId(projectId: number): Promise { + return DB.selectByField(TABLE, 'project_id', projectId) +} + +/** 按设备 ID 查询 */ +export async function selectByDeviceId(deviceId: string): Promise { + return DB.selectByField(TABLE, 'device_id', deviceId) +} + +/** 新增历史报告 */ +export async function insert(data: HistoryReport): Promise { + return DB.insert(TABLE, data) +} + +/** 更新历史报告 */ +export async function update(id: number, data: Partial): Promise { + return DB.update(TABLE, data, `id = ${id}`) +} + +/** 删除历史报告 */ +export async function remove(id: number): Promise { + return DB.delete(TABLE, `id = ${id}`) +} diff --git a/src/service/index.ts b/src/service/index.ts index e9c8570..099a932 100644 --- a/src/service/index.ts +++ b/src/service/index.ts @@ -1,9 +1,12 @@ import DB from '@/utils/sqlite' +import { historyReportTableSql } from './historyReport' import { projectTableSql } from './project' import { rtkTrackTableSql } from './rtkTrack' import { warningRecordTableSql } from './warningRecord' import { workRecordTableSql } from './workRecord' +export { historyReportTableSql } from './historyReport' +export * as historyReportService from './historyReport' export { projectTableSql } from './project' // 导出所有 service 方法 export * as projectService from './project' @@ -21,6 +24,7 @@ const tableSqls = [ workRecordTableSql, rtkTrackTableSql, warningRecordTableSql, + historyReportTableSql, ] /** diff --git a/src/service/project.ts b/src/service/project.ts index 730acb9..08caa8b 100644 --- a/src/service/project.ts +++ b/src/service/project.ts @@ -17,7 +17,7 @@ export interface Project { project_name: string // 项目名称,必填 stake_range: string // 项目范围,可选 total_area: number // 项目总面积,可选 - status: 0 | 1 // 项目状态,0:未完成,1:已完成,默认0 + status: 0 | 1 | 2 // 项目状态,0:未完成,1:已完成,默认0,. 进行中2 created_at?: string // 创建时间,默认当前时间 updated_at?: string // 更新时间,默认当前时间 } diff --git a/src/service/rtkTrack.ts b/src/service/rtkTrack.ts index 3ef2388..42f257f 100644 --- a/src/service/rtkTrack.ts +++ b/src/service/rtkTrack.ts @@ -5,29 +5,29 @@ const TABLE = 'rtk_track' 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, + steel_wheel_temp REAL, + compaction_value REAL, 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 + id?: number // 主键,自增 + work_record_id: number // 所属作业记录 ID,关联 work_record.id + latitude?: number // 纬度 + longitude?: number // 经度 + speed?: number // 行驶速度 + heading?: number // 航向角度(度) + steel_wheel_temp?: number // 钢轮温度 + compaction_value?: number // 压实度 + created_at?: string // 创建时间,默认当前时间 } -/** 查询全部 */ +/** 查询全部 RTK 轨迹 */ export async function selectAll(): Promise { return DB.select(TABLE) } @@ -42,17 +42,17 @@ export async function selectByWorkRecordId(workRecordId: number): Promise { return DB.insert(TABLE, data) } -/** 更新 */ +/** 更新轨迹点 */ export async function update(id: number, data: Partial): Promise { return DB.update(TABLE, data, `id = ${id}`) } -/** 删除 */ +/** 删除轨迹点 */ export async function remove(id: number): Promise { return DB.delete(TABLE, `id = ${id}`) } diff --git a/src/service/seed.ts b/src/service/seed.ts index 7dba5fe..b222f28 100644 --- a/src/service/seed.ts +++ b/src/service/seed.ts @@ -2,23 +2,27 @@ import DB from '@/utils/sqlite' /** * 插入项目假数据(3条) + * 字段:project_name / stake_range / total_area / status(0未完成 1已完成 2进行中) */ async function seedProject() { const data = [ { project_name: '京雄高速河北段', - project_type: '高速公路', - status: 'online', + stake_range: 'K1+000 ~ K5+500', + total_area: 12500.0, + status: 2, }, { project_name: '雄安新区市政道路', - project_type: '市政工程', - status: 'online', + stake_range: 'A区 ~ C区', + total_area: 8600.5, + status: 0, }, { project_name: '白沟产业园场地', - project_type: '场地平整', - status: 'offline', + stake_range: '1号地块', + total_area: 5200.0, + status: 1, }, ] @@ -29,6 +33,7 @@ async function seedProject() { /** * 插入作业记录假数据(3条) + * 字段:project_id / start_time / end_time / compaction_area / pass_count */ async function seedWorkRecord() { const data = [ @@ -36,34 +41,22 @@ async function seedWorkRecord() { 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, + compaction_area: 1250.5, + pass_count: 6, }, { 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, + compaction_area: 1680.0, + pass_count: 8, }, { 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, + compaction_area: 980.3, + pass_count: 5, }, ] @@ -74,35 +67,36 @@ async function seedWorkRecord() { /** * 插入 RTK 轨迹假数据(3条) + * 字段:work_record_id / latitude / longitude / speed / heading / steel_wheel_temp / compaction_value */ 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, + steel_wheel_temp: 65.2, + compaction_value: 92.3, }, { 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, + steel_wheel_temp: 66.0, + compaction_value: 93.1, }, { 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, + steel_wheel_temp: 68.5, + compaction_value: 95.0, }, ] @@ -113,28 +107,40 @@ async function seedRtkTrack() { /** * 插入告警记录假数据(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() { const data = [ { project_id: 1, - warning_type: '超速', - warning_level: 'high', - message: '碾压速度超过设定阈值(6.5km/h)', + device_name: 'XS-65H', + exception_type: 0, + occurred_at: '2026-09-10 09:15:00', + site_description: '设备上报数据中断超过 30 秒', + disposal_record: '', + disposal_type: 0, is_read: 0, }, { project_id: 2, - warning_type: '漏压', - warning_level: 'medium', - message: 'K2+350处检测到漏压区域', + device_name: 'XS-65H', + exception_type: 1, + occurred_at: '2026-09-09 10:20:00', + site_description: '钢轮温度超过安全阈值', + disposal_record: '现场降温后恢复作业', + disposal_type: 1, is_read: 0, }, { project_id: 1, - warning_type: '偏航', - warning_level: 'low', - message: 'RTK信号偏移超过2cm', + device_name: 'RTK-01', + exception_type: 2, + occurred_at: '2026-09-10 14:05:00', + site_description: 'RTK 定位信号丢失,无法获取有效坐标', + disposal_record: '设备故障,已登记报修', + disposal_type: 2, 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 seedRtkTrack() await seedWarningRecord() + await seedHistoryReport() console.log('假数据插入完成') } catch (err) { diff --git a/src/service/warningRecord.ts b/src/service/warningRecord.ts index 8189363..e214e7d 100644 --- a/src/service/warningRecord.ts +++ b/src/service/warningRecord.ts @@ -1,3 +1,4 @@ +// 告警记录表 import DB from '@/utils/sqlite' const TABLE = 'warning_record' @@ -5,25 +6,31 @@ const TABLE = 'warning_record' 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, + device_name TEXT, + exception_type INTEGER, + occurred_at DATETIME, + site_description TEXT, + disposal_record TEXT, + disposal_type INTEGER, is_read INTEGER DEFAULT 0, 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 + id?: number // 主键,自增 + project_id: number // 所属项目 ID,关联 project.id + device_name?: string // 设备名称 + exception_type?: 0 | 1 | 2 // 异常类型,0:数据中断,1:高温异常,2:定位异常 + occurred_at?: string // 发生时间 + site_description?: 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 { return DB.select(TABLE) } @@ -38,12 +45,12 @@ export async function selectByProjectId(projectId: number): Promise { return DB.select(TABLE, '*', 'is_read = 0') } -/** 新增 */ +/** 新增告警记录 */ export async function insert(data: WarningRecord): Promise { return DB.insert(TABLE, data) } @@ -53,12 +60,12 @@ export async function markRead(id: number): Promise { return DB.update(TABLE, { is_read: 1 }, `id = ${id}`) } -/** 更新 */ +/** 更新告警记录 */ export async function update(id: number, data: Partial): Promise { return DB.update(TABLE, data, `id = ${id}`) } -/** 删除 */ +/** 删除告警记录 */ export async function remove(id: number): Promise { return DB.delete(TABLE, `id = ${id}`) } diff --git a/src/service/workRecord.ts b/src/service/workRecord.ts index 878d558..94afdaf 100644 --- a/src/service/workRecord.ts +++ b/src/service/workRecord.ts @@ -1,3 +1,4 @@ +// 工作记录表 import DB from '@/utils/sqlite' const TABLE = 'work_record' @@ -7,31 +8,23 @@ export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record ( project_id INTEGER, start_time DATETIME, end_time DATETIME, - speed REAL, - frequency REAL, - amplitude REAL, - compaction_value REAL, - gps_lat REAL, - gps_lng REAL, + compaction_area REAL, + pass_count INTEGER, 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 + id?: number // 主键,自增 + project_id: number // 所属项目 ID,关联 project.id + start_time?: string // 作业开始时间 + end_time?: string // 作业结束时间 + compaction_area?: number // 压实面积 + pass_count?: number // 碾压遍数 + created_at?: string // 创建时间,默认当前时间 } -/** 查询全部 */ +/** 查询全部作业记录 */ export async function selectAll(): Promise { return DB.select(TABLE) } @@ -46,17 +39,17 @@ export async function selectByProjectId(projectId: number): Promise { return DB.insert(TABLE, data) } -/** 更新 */ +/** 更新作业记录 */ export async function update(id: number, data: Partial): Promise { return DB.update(TABLE, data, `id = ${id}`) } -/** 删除 */ +/** 删除作业记录 */ export async function remove(id: number): Promise { return DB.delete(TABLE, `id = ${id}`) } diff --git a/src/store/modules/db.ts b/src/store/modules/db.ts index 6382bf7..2035030 100644 --- a/src/store/modules/db.ts +++ b/src/store/modules/db.ts @@ -1,3 +1,4 @@ +import type { HistoryReport } from '@/service/historyReport' import type { Project } from '@/service/project' import type { RtkTrack } from '@/service/rtkTrack' import type { WarningRecord } from '@/service/warningRecord' @@ -5,6 +6,7 @@ import type { WorkRecord } from '@/service/workRecord' import { defineStore } from 'pinia' import { ref } from 'vue' import { + historyReportService, projectService, rtkTrackService, warningRecordService, @@ -17,6 +19,7 @@ export const useDbStore = defineStore('db', () => { const workRecords = ref([]) const rtkTracks = ref([]) const warningRecords = ref([]) + const historyReports = ref([]) // --- Project --- async function loadProjects() { @@ -79,12 +82,31 @@ export const useDbStore = defineStore('db', () => { 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 { // State projects, workRecords, rtkTracks, warningRecords, + historyReports, // Project loadProjects, addProject, @@ -102,5 +124,10 @@ export const useDbStore = defineStore('db', () => { loadWarningRecords, loadUnreadWarnings, markWarningRead, + // HistoryReport + loadHistoryReports, + loadHistoryReportsByProject, + loadHistoryReportsByDevice, + addHistoryReport, } })