feat:额外收费
This commit is contained in:
1 parent
2b956342f4
commit
e730b6923c
17 files changed
+461
-153
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:floor/floor.dart';
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
import 'package:pj_supermarket_cloud/common/services/database/databaseMigration.dart';
|
||||
|
||||
import 'package:sqflite/sqflite.dart' as sqflite;
|
||||
|
||||
@@ -32,11 +34,13 @@ const typeConverters = <Type>[
|
||||
SysTypeConverter,
|
||||
PrintStatusConverter,
|
||||
SupermarketNatureConverter,
|
||||
DiscountsTypeConverter,
|
||||
ListDiscountsConverter,
|
||||
ListIntConverter,
|
||||
BoolConverter,
|
||||
];
|
||||
|
||||
@Database(version: 3, entities: entities)
|
||||
@Database(version: 5, entities: entities)
|
||||
@TypeConverters(typeConverters)
|
||||
abstract class AppDatabase extends FloorDatabase {
|
||||
BroadcastDao get getBroadcastDao;
|
||||
@@ -53,130 +57,11 @@ abstract class AppDatabase extends FloorDatabase {
|
||||
FaceDao get getFaceDao;
|
||||
SettingDao get getSettingDao;
|
||||
|
||||
// 获取数据库迁移列表
|
||||
static List<Migration> _getDatabaseMigrations() {
|
||||
return [
|
||||
// 从版本1到版本2的迁移:添加productNamePy字段
|
||||
Migration(1, 2, (database) async {
|
||||
// 先检查列是否存在,不存在才添加
|
||||
final result = await database.rawQuery(
|
||||
"PRAGMA table_info(supermarket_spu)",
|
||||
);
|
||||
bool columnExists = false;
|
||||
for (var column in result) {
|
||||
if (column['name'] == 'productNamePy') {
|
||||
columnExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!columnExists) {
|
||||
await database.execute(
|
||||
'ALTER TABLE supermarket_spu ADD COLUMN productNamePy TEXT');
|
||||
}
|
||||
}),
|
||||
Migration(2, 3, (database) async {
|
||||
// 如果表不存在则创建,存在则校验列并补齐缺失项
|
||||
final tables = await database.rawQuery(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='order_hold_bill'",
|
||||
);
|
||||
if (tables.isEmpty) {
|
||||
await database.execute('''
|
||||
CREATE TABLE IF NOT EXISTS order_hold_bill (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
sysType TEXT NOT NULL,
|
||||
carListJson TEXT,
|
||||
userJson TEXT,
|
||||
price INTEGER DEFAULT 0 NOT NULL,
|
||||
extraPrice INTEGER DEFAULT 0 NOT NULL,
|
||||
payPrice INTEGER DEFAULT 0 NOT NULL,
|
||||
createTime TEXT NOT NULL
|
||||
)
|
||||
''');
|
||||
await database.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_order_hold_bill_sysType ON order_hold_bill(sysType)",
|
||||
);
|
||||
await database.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_order_hold_bill_createTime ON order_hold_bill(createTime)",
|
||||
);
|
||||
} else {
|
||||
final columns =
|
||||
await database.rawQuery("PRAGMA table_info(order_hold_bill)");
|
||||
bool hasSysType = false;
|
||||
bool hasCarListJson = false;
|
||||
bool hasOrderListJson = false;
|
||||
bool hasUserJson = false;
|
||||
bool hasPrice = false;
|
||||
bool hasExtraPrice = false;
|
||||
bool hasPayPrice = false;
|
||||
bool hasCreateTime = false;
|
||||
for (final c in columns) {
|
||||
final name = c['name'];
|
||||
if (name == 'sysType') hasSysType = true;
|
||||
if (name == 'carListJson') hasCarListJson = true;
|
||||
if (name == 'orderListJson') hasOrderListJson = true;
|
||||
if (name == 'userJson') hasUserJson = true;
|
||||
if (name == 'price') hasPrice = true;
|
||||
if (name == 'extraPrice') hasExtraPrice = true;
|
||||
if (name == 'payPrice') hasPayPrice = true;
|
||||
if (name == 'createTime') hasCreateTime = true;
|
||||
}
|
||||
if (!hasSysType) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN sysType TEXT',
|
||||
);
|
||||
}
|
||||
if (!hasCarListJson) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN carListJson TEXT',
|
||||
);
|
||||
if (hasOrderListJson) {
|
||||
// 旧列迁移到新列
|
||||
await database.execute(
|
||||
"UPDATE order_hold_bill SET carListJson = orderListJson WHERE carListJson IS NULL",
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!hasUserJson) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN userJson TEXT',
|
||||
);
|
||||
}
|
||||
if (!hasPrice) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN price INTEGER DEFAULT 0 NOT NULL',
|
||||
);
|
||||
}
|
||||
if (!hasExtraPrice) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN extraPrice INTEGER DEFAULT 0 NOT NULL',
|
||||
);
|
||||
}
|
||||
if (!hasPayPrice) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN payPrice INTEGER DEFAULT 0 NOT NULL',
|
||||
);
|
||||
}
|
||||
if (!hasCreateTime) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN createTime TEXT DEFAULT "" NOT NULL',
|
||||
);
|
||||
}
|
||||
await database.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_order_hold_bill_sysType ON order_hold_bill(sysType)",
|
||||
);
|
||||
await database.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_order_hold_bill_createTime ON order_hold_bill(createTime)",
|
||||
);
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
static Future<AppDatabase> getDataBase() async {
|
||||
final dbPath = await AppFileTool.getDatabasePath();
|
||||
final name = "$dbPath/${Constants.databaseName}";
|
||||
final dataBase = await $FloorAppDatabase
|
||||
.databaseBuilder("$dbPath/${Constants.databaseName}")
|
||||
.databaseBuilder(name)
|
||||
.addCallback(
|
||||
Callback(
|
||||
onCreate: (database, version) async {
|
||||
@@ -190,7 +75,7 @@ abstract class AppDatabase extends FloorDatabase {
|
||||
},
|
||||
),
|
||||
)
|
||||
.addMigrations(_getDatabaseMigrations())
|
||||
.addMigrations(DatabaseMigration.getDatabaseMigrations())
|
||||
.build();
|
||||
return dataBase;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user