diff --git a/src/components/home/list.vue b/src/components/home/list.vue
index 5bd6684..832986c 100644
--- a/src/components/home/list.vue
+++ b/src/components/home/list.vue
@@ -1,17 +1,51 @@
+
+
- G6高速改扩建项目
+ {{ item.project_name }}
- K1+200-K1+800
+ {{ item.stake_range || '-' }}
-
- 作业中
+
+ {{ statusText }}
@@ -20,7 +54,7 @@
作业时长
- 8h
+ {{ durationText }}
@@ -28,7 +62,7 @@
压实面积
- 28.5m²
+ {{ areaText }}
@@ -36,11 +70,11 @@
碾压遍数
- 10遍
+ {{ passText }}
-
+
开始项目
@@ -55,6 +89,12 @@
diff --git a/src/components/project/item.vue b/src/components/project/item.vue
index 07ba5e1..e45d85c 100644
--- a/src/components/project/item.vue
+++ b/src/components/project/item.vue
@@ -10,18 +10,18 @@ defineProps<{
function getStatusText(status: number) {
const map: Record = {
- 0: '作业中',
- 1: '暂停中',
- 2: '已结束',
+ 0: '未完成',
+ 1: '已结束',
+ 2: '进行中',
}
return map[status] || '未知'
}
function getStatusColor(status: number) {
const map: Record = {
- 0: '#52c41a',
- 1: '#faad14',
- 2: '#999999',
+ 0: '#faad14',
+ 1: '#999999',
+ 2: '#52c41a',
}
return map[status] || '#999999'
}
@@ -79,7 +79,7 @@ function getStatusColor(status: number) {
-
+
开始项目
diff --git a/src/pages/project/index.vue b/src/pages/project/index.vue
index 70d96fc..1646448 100644
--- a/src/pages/project/index.vue
+++ b/src/pages/project/index.vue
@@ -1,4 +1,8 @@
@@ -63,9 +97,12 @@ function handleCreate() {
+
+ 暂无项目
+
diff --git a/src/service/index.ts b/src/service/index.ts
index 1b12167..8cce39d 100644
--- a/src/service/index.ts
+++ b/src/service/index.ts
@@ -28,8 +28,8 @@ const tableSqls = [
/** 当前代码期望的各表字段(用于检测旧库结构) */
const expectedColumns: Record = {
- project: ['id', 'project_name', 'stake_range', 'total_area', 'status', 'created_at', 'updated_at'],
- work_record: ['id', 'project_id', 'start_time', 'end_time', 'compaction_area', 'pass_count', 'created_at'],
+ project: ['id', 'project_name', 'stake_range', 'total_area', 'start_time', 'end_time', 'total_duration', 'total_compaction_area', 'total_pass_count', 'status', 'created_at', 'updated_at'],
+ work_record: ['id', 'project_id', 'start_time', 'end_time', 'duration', 'compaction_area', 'pass_count', 'exception_count', 'created_at'],
rtk_track: ['id', 'work_record_id', 'latitude', 'longitude', 'speed', 'heading', 'steel_wheel_temp', 'compaction_value', 'created_at'],
warning_record: ['id', 'project_id', 'device_name', 'exception_type', 'exception_level', 'occurred_at', 'site_description', 'disposal_record', 'disposal_type', 'is_read', 'created_at'],
history_report: ['id', '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', 'created_at'],
diff --git a/src/service/project.ts b/src/service/project.ts
index 08caa8b..b5be3a4 100644
--- a/src/service/project.ts
+++ b/src/service/project.ts
@@ -7,6 +7,11 @@ export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
project_name TEXT NOT NULL,
stake_range TEXT,
total_area REAL,
+ start_time DATETIME,
+ end_time DATETIME,
+ total_duration REAL DEFAULT 0,
+ total_compaction_area REAL DEFAULT 0,
+ total_pass_count INTEGER DEFAULT 0,
status INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
@@ -17,7 +22,12 @@ export interface Project {
project_name: string // 项目名称,必填
stake_range: string // 项目范围,可选
total_area: number // 项目总面积,可选
- status: 0 | 1 | 2 // 项目状态,0:未完成,1:已完成,默认0,. 进行中2
+ start_time?: string // 项目开始时间
+ end_time?: string // 项目结束时间
+ total_duration?: number // 目前作业进行总时长,默认 0
+ total_compaction_area?: number // 当前总共的压实面积,默认 0
+ total_pass_count?: number // 当前总共的碾压遍数,默认 0
+ status: 0 | 1 | 2 // 项目状态,0:未完成,1:已完成,2:作业中, 默认0
created_at?: string // 创建时间,默认当前时间
updated_at?: string // 更新时间,默认当前时间
}
diff --git a/src/service/seed.ts b/src/service/seed.ts
index 67cbdee..0619b77 100644
--- a/src/service/seed.ts
+++ b/src/service/seed.ts
@@ -1,4 +1,5 @@
import DB from '@/utils/sqlite'
+import { insert as insertWorkRecord } from './workRecord'
/**
* 插入项目假数据(3条)
@@ -33,7 +34,8 @@ async function seedProject() {
/**
* 插入作业记录假数据(3条)
- * 字段:project_id / start_time / end_time / compaction_area / pass_count
+ * 走 workRecord.insert,事务同步累加 project 汇总字段
+ * 字段:project_id / start_time / end_time / duration / compaction_area / pass_count
*/
async function seedWorkRecord() {
const data = [
@@ -41,6 +43,7 @@ async function seedWorkRecord() {
project_id: 1,
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,
},
@@ -48,6 +51,7 @@ async function seedWorkRecord() {
project_id: 1,
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,
},
@@ -55,13 +59,14 @@ async function seedWorkRecord() {
project_id: 2,
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,
},
]
for (const item of data) {
- await DB.insert('work_record', item)
+ await insertWorkRecord(item)
}
}
diff --git a/src/service/workRecord.ts b/src/service/workRecord.ts
index 94afdaf..2a5e86e 100644
--- a/src/service/workRecord.ts
+++ b/src/service/workRecord.ts
@@ -1,4 +1,4 @@
-// 工作记录表
+// 当日工作记录表
import DB from '@/utils/sqlite'
const TABLE = 'work_record'
@@ -8,8 +8,10 @@ export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
project_id INTEGER,
start_time DATETIME,
end_time DATETIME,
+ duration REAL,
compaction_area REAL,
pass_count INTEGER,
+ exception_count INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES project(id)
)`
@@ -19,11 +21,57 @@ export interface WorkRecord {
project_id: number // 所属项目 ID,关联 project.id
start_time?: string // 作业开始时间
end_time?: string // 作业结束时间
+ duration?: number // 作业时长
compaction_area?: number // 压实面积
pass_count?: number // 碾压遍数
+ exception_count?: number // 异常次数,默认 0
created_at?: string // 创建时间,默认当前时间
}
+function escapeValue(value: any): string {
+ if (value === null || value === undefined)
+ return 'NULL'
+ if (typeof value === 'number')
+ return String(value)
+ if (typeof value === 'boolean')
+ return value ? '1' : '0'
+ return `'${String(value).replace(/'/g, '\'\'')}'`
+}
+
+function buildInsertSql(data: Record): string {
+ const keys = Object.keys(data)
+ const values = keys.map(k => escapeValue(data[k]))
+ return `INSERT INTO ${TABLE} (${keys.join(', ')}) VALUES (${values.join(', ')})`
+}
+
+function buildUpdateSql(data: Record, where: string): string {
+ const sets = Object.keys(data).map(k => `${k} = ${escapeValue(data[k])}`)
+ return `UPDATE ${TABLE} SET ${sets.join(', ')} WHERE ${where}`
+}
+
+/** 按增量回写项目汇总字段(时长 / 压实面积 / 碾压遍数) */
+function buildProjectDeltaSql(
+ projectId: number,
+ durationDelta: number,
+ compactionDelta: number,
+ passDelta: number,
+): string | null {
+ if (durationDelta === 0 && compactionDelta === 0 && passDelta === 0)
+ return null
+
+ const now = escapeValue(new Date().toISOString())
+ return `UPDATE project SET
+ total_duration = COALESCE(total_duration, 0) + (${durationDelta}),
+ total_compaction_area = COALESCE(total_compaction_area, 0) + (${compactionDelta}),
+ total_pass_count = COALESCE(total_pass_count, 0) + (${passDelta}),
+ updated_at = ${now}
+ WHERE id = ${projectId}`
+}
+
+function num(value: number | undefined | null): number {
+ return value ?? 0
+}
+
/** 查询全部作业记录 */
export async function selectAll(): Promise {
return DB.select(TABLE)
@@ -39,17 +87,85 @@ export async function selectByProjectId(projectId: number): Promise {
- return DB.insert(TABLE, data)
+/** 新增作业记录,并事务累加项目汇总 */
+export async function insert(data: WorkRecord): Promise {
+ const sqls = [buildInsertSql(data)]
+ const projectSql = buildProjectDeltaSql(
+ data.project_id,
+ num(data.duration),
+ num(data.compaction_area),
+ num(data.pass_count),
+ )
+ if (projectSql)
+ sqls.push(projectSql)
+ await DB.transaction(sqls)
}
-/** 更新作业记录 */
-export async function update(id: number, data: Partial): Promise {
- return DB.update(TABLE, data, `id = ${id}`)
+/** 更新作业记录,并事务按差值回写项目汇总 */
+export async function update(id: number, data: Partial): Promise {
+ const old = await selectById(id)
+ if (!old)
+ throw new Error(`作业记录不存在: ${id}`)
+
+ const sqls = [buildUpdateSql(data, `id = ${id}`)]
+ const oldProjectId = old.project_id
+ const newProjectId = data.project_id ?? oldProjectId
+
+ if (newProjectId !== oldProjectId) {
+ const removeSql = buildProjectDeltaSql(
+ oldProjectId,
+ -num(old.duration),
+ -num(old.compaction_area),
+ -num(old.pass_count),
+ )
+ const addSql = buildProjectDeltaSql(
+ newProjectId,
+ data.duration !== undefined ? num(data.duration) : num(old.duration),
+ data.compaction_area !== undefined ? num(data.compaction_area) : num(old.compaction_area),
+ data.pass_count !== undefined ? num(data.pass_count) : num(old.pass_count),
+ )
+ if (removeSql)
+ sqls.push(removeSql)
+ if (addSql)
+ sqls.push(addSql)
+ }
+ else {
+ const durationDelta = data.duration !== undefined
+ ? num(data.duration) - num(old.duration)
+ : 0
+ const compactionDelta = data.compaction_area !== undefined
+ ? num(data.compaction_area) - num(old.compaction_area)
+ : 0
+ const passDelta = data.pass_count !== undefined
+ ? num(data.pass_count) - num(old.pass_count)
+ : 0
+ const projectSql = buildProjectDeltaSql(
+ oldProjectId,
+ durationDelta,
+ compactionDelta,
+ passDelta,
+ )
+ if (projectSql)
+ sqls.push(projectSql)
+ }
+
+ await DB.transaction(sqls)
}
-/** 删除作业记录 */
-export async function remove(id: number): Promise {
- return DB.delete(TABLE, `id = ${id}`)
+/** 删除作业记录,并事务扣减项目汇总 */
+export async function remove(id: number): Promise {
+ const old = await selectById(id)
+ if (!old)
+ return
+
+ const sqls = [`DELETE FROM ${TABLE} WHERE id = ${id}`]
+ const projectSql = buildProjectDeltaSql(
+ old.project_id,
+ -num(old.duration),
+ -num(old.compaction_area),
+ -num(old.pass_count),
+ )
+ if (projectSql)
+ sqls.push(projectSql)
+ await DB.transaction(sqls)
}