Jármű navigáció @3h
This commit is contained in:
@@ -11,8 +11,10 @@ import 'package:terepi_seged/models/measured_point.dart';
|
||||
import 'package:terepi_seged/models/note_item.dart';
|
||||
import 'package:terepi_seged/models/note_item_audio.dart';
|
||||
import 'package:terepi_seged/models/note_item_photo.dart';
|
||||
import 'package:terepi_seged/models/source_point.dart';
|
||||
import 'package:terepi_seged/models/stakeout_point.dart';
|
||||
import 'package:terepi_seged/models/track.dart';
|
||||
import 'package:terepi_seged/models/vechicle_position_log.dart';
|
||||
import 'package:terepi_seged/services/device_identity_service.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import '../models/project.dart';
|
||||
@@ -44,7 +46,7 @@ class AppDatabase {
|
||||
final path = p.join(dbDir.path, 'terepi_seged.db');
|
||||
|
||||
return openDatabase(path,
|
||||
version: 5,
|
||||
version: 6,
|
||||
onConfigure: (db) => db.execute('PRAGMA foreign_keys = ON'),
|
||||
onCreate: _onCreate,
|
||||
onUpgrade: _onUpgrade);
|
||||
@@ -271,6 +273,8 @@ class AppDatabase {
|
||||
await _createContactsOutbox(db);
|
||||
await _addAppInstanceIdColumns(db);
|
||||
|
||||
await _createVibratorNavTables(db);
|
||||
|
||||
// Alap projekt létrehozása az első indításhoz
|
||||
final now = DateTime.now().toIso8601String();
|
||||
await db.insert('projects', {
|
||||
@@ -303,10 +307,11 @@ class AppDatabase {
|
||||
await _migrateToV4(db);
|
||||
}
|
||||
if (oldVersion < 5) {
|
||||
_createContactsOutbox(db);
|
||||
await _createContactsOutbox(db);
|
||||
}
|
||||
|
||||
await _addAppInstanceIdColumns(db);
|
||||
await _createVibratorNavTables(db);
|
||||
}
|
||||
|
||||
Future<void> _migrateToV4(Database db) async {
|
||||
@@ -1392,4 +1397,84 @@ class AppDatabase {
|
||||
// await db.execute('CREATE INDEX IF NOT EXISTS idx_contacts_outbox_project '
|
||||
// 'ON contacts_outbox(project_id)');
|
||||
// }
|
||||
|
||||
// ── Vibrátor navigáció: forráspontok + járműpozíció-napló ────────
|
||||
|
||||
Future<void> _createVibratorNavTables(Database db) async {
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS source_points (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
uuid TEXT NOT NULL UNIQUE,
|
||||
project_id INTEGER NOT NULL,
|
||||
line_id TEXT NOT NULL DEFAULT '',
|
||||
station INTEGER NOT NULL,
|
||||
plan_eov_y REAL NOT NULL,
|
||||
plan_eov_x REAL NOT NULL,
|
||||
plan_lat REAL NOT NULL,
|
||||
plan_lon REAL NOT NULL,
|
||||
source TEXT NOT NULL DEFAULT 'sps',
|
||||
import_batch TEXT,
|
||||
created_at TEXT NOT NULL
|
||||
)
|
||||
''');
|
||||
await db.execute('CREATE INDEX IF NOT EXISTS idx_source_points_project '
|
||||
'ON source_points(project_id, line_id, station)');
|
||||
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS vehicle_position_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
uuid TEXT NOT NULL UNIQUE,
|
||||
project_id INTEGER NOT NULL,
|
||||
vehicle_id TEXT NOT NULL,
|
||||
eov_y REAL NOT NULL,
|
||||
eov_x REAL NOT NULL,
|
||||
lat REAL NOT NULL,
|
||||
lon REAL NOT NULL,
|
||||
altitude REAL,
|
||||
speed_kmh REAL,
|
||||
heading REAL,
|
||||
fix_quality INTEGER,
|
||||
accuracy REAL,
|
||||
timestamp TEXT NOT NULL,
|
||||
device_id TEXT,
|
||||
app_instance_id TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('CREATE INDEX IF NOT EXISTS idx_vehicle_logs_project '
|
||||
'ON vehicle_position_logs(project_id, vehicle_id, timestamp)');
|
||||
}
|
||||
|
||||
Future<int> insertSourcePoints(List<SourcePoint> points) async {
|
||||
final db = await database;
|
||||
var count = 0;
|
||||
await db.transaction((txn) async {
|
||||
for (final p in points) {
|
||||
await txn.insert('source_points', p.toMap());
|
||||
count++;
|
||||
}
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
Future<List<SourcePoint>> listSourcePoints(int projectId) async {
|
||||
final db = await database;
|
||||
final rows = await db.query('source_points',
|
||||
where: 'project_id = ?',
|
||||
whereArgs: [projectId],
|
||||
orderBy: 'station ASC');
|
||||
return rows.map(SourcePoint.fromMap).toList();
|
||||
}
|
||||
|
||||
Future<void> insertVehiclePositionLog(VehiclePositionLog log) async {
|
||||
final db = await database;
|
||||
await db.insert('vehicle_position_logs', log.toMap());
|
||||
}
|
||||
|
||||
Future<List<VehiclePositionLog>> listVehiclePositionLogs(
|
||||
int projectId) async {
|
||||
final db = await database;
|
||||
final rows = await db.query('vehicle_position_logs',
|
||||
where: 'project_id = ?', whereArgs: [projectId]);
|
||||
return rows.map(VehiclePositionLog.fromMap).toList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user