|
|
@ -1,4 +1,5 @@ |
|
|
import 'dart:async'; |
|
|
import 'dart:async'; |
|
|
|
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
import 'package:path/path.dart'; |
|
|
import 'package:path/path.dart'; |
|
|
import 'package:sqflite/sqflite.dart'; |
|
|
import 'package:sqflite/sqflite.dart'; |
|
|
|
|
|
|
|
|
@ -6,6 +7,7 @@ class DatabaseHelper { |
|
|
static final DatabaseHelper _instance = DatabaseHelper._internal(); |
|
|
static final DatabaseHelper _instance = DatabaseHelper._internal(); |
|
|
factory DatabaseHelper() => _instance; |
|
|
factory DatabaseHelper() => _instance; |
|
|
static Database? _database; |
|
|
static Database? _database; |
|
|
|
|
|
static String _userId = ''; |
|
|
|
|
|
|
|
|
DatabaseHelper._internal(); |
|
|
DatabaseHelper._internal(); |
|
|
|
|
|
|
|
|
@ -16,15 +18,35 @@ class DatabaseHelper { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<Database> _initDatabase() async { |
|
|
Future<Database> _initDatabase() async { |
|
|
|
|
|
final GetStorage storage = GetStorage(); |
|
|
|
|
|
Map? userInfo = storage.read("user_info"); |
|
|
|
|
|
if (userInfo != null) { |
|
|
|
|
|
_userId = userInfo['user']['uid']; |
|
|
|
|
|
} |
|
|
String path = join( |
|
|
String path = join( |
|
|
await getDatabasesPath(), |
|
|
await getDatabasesPath(), |
|
|
'database.db', |
|
|
_userId.isNotEmpty ? '${_userId}database.db' : 'database.db', |
|
|
); |
|
|
); |
|
|
return await openDatabase(path, version: 1, onCreate: _createDB); |
|
|
return await openDatabase(path, version: 1, onCreate: _createDB); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> _createDB(Database db, int version) async { |
|
|
Future<void> _createDB(Database db, int version) async { |
|
|
final batch = db.batch(); |
|
|
final batch = db.batch(); |
|
|
|
|
|
// 用户信息 |
|
|
|
|
|
batch.execute(''' |
|
|
|
|
|
CREATE TABLE IF NOT EXISTS user ( |
|
|
|
|
|
id TEXT PRIMARY KEY, |
|
|
|
|
|
synctime INTEGER, |
|
|
|
|
|
) |
|
|
|
|
|
'''); |
|
|
|
|
|
// 操作记录 |
|
|
|
|
|
batch.execute(''' |
|
|
|
|
|
CREATE TABLE IF NOT EXISTS operationrecord ( |
|
|
|
|
|
id INTEGER PRIMARY KEY, |
|
|
|
|
|
method TEXT, |
|
|
|
|
|
data TEXT, |
|
|
|
|
|
) |
|
|
|
|
|
'''); |
|
|
// 商务会议助手列表 |
|
|
// 商务会议助手列表 |
|
|
batch.execute(''' |
|
|
batch.execute(''' |
|
|
CREATE TABLE IF NOT EXISTS meeting ( |
|
|
CREATE TABLE IF NOT EXISTS meeting ( |
|
|
@ -82,6 +104,10 @@ class DatabaseHelper { |
|
|
prompt TEXT |
|
|
prompt TEXT |
|
|
) |
|
|
) |
|
|
'''); |
|
|
'''); |
|
|
|
|
|
batch.insert('user', { |
|
|
|
|
|
'id': _userId, |
|
|
|
|
|
'synctime': 0, |
|
|
|
|
|
}); |
|
|
// 商务会议助手插入默认模版 |
|
|
// 商务会议助手插入默认模版 |
|
|
batch.insert('meetingcategorytemplate', { |
|
|
batch.insert('meetingcategorytemplate', { |
|
|
'id': 1, |
|
|
'id': 1, |
|
|
|