feat:创建挂单数据库,和迁移文件
This commit is contained in:
1 parent
815cb2ac8b
commit
988247f3cd
7 files changed
+248
-3
No files matched your search
+1
-1
@@ -15,7 +15,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static final String DATABASE_PATH = "pj_cashier/database";
|
||||
private static final String DATABASE_NAME = "cash_register.db";
|
||||
private static final int DATABASE_VERSION = 2;
|
||||
private static final int DATABASE_VERSION = 3;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, getCustomDatabasePath(context), null, DATABASE_VERSION);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:floor/floor.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
@dao
|
||||
abstract class OrderHoldBillDao {
|
||||
@insert
|
||||
Future<int?> save(OrderHoldBillEntity entity);
|
||||
|
||||
@update
|
||||
Future<void> edit(OrderHoldBillEntity entity);
|
||||
|
||||
@delete
|
||||
Future<void> del(OrderHoldBillEntity entity);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ part 'database.g.dart';
|
||||
const entities = <Type>[
|
||||
BroadcastEntity,
|
||||
OrderEntity,
|
||||
OrderHoldBillEntity,
|
||||
CanteenSpuEntity,
|
||||
SupermarketSkuEntity,
|
||||
SupermarketSpuEntity,
|
||||
@@ -35,11 +36,12 @@ const typeConverters = <Type>[
|
||||
BoolConverter,
|
||||
];
|
||||
|
||||
@Database(version: 2, entities: entities)
|
||||
@Database(version: 3, entities: entities)
|
||||
@TypeConverters(typeConverters)
|
||||
abstract class AppDatabase extends FloorDatabase {
|
||||
BroadcastDao get getBroadcastDao;
|
||||
OrderDao get getOrderDao;
|
||||
OrderHoldBillDao get getOrderHoldBillDao;
|
||||
CanteenSpuDao get getCanteenSpuDao;
|
||||
SupermarketSkuDao get getSupermarketSkuDao;
|
||||
SupermarketSpuDao get getSupermarketSpuDao;
|
||||
@@ -73,6 +75,77 @@ abstract class AppDatabase extends FloorDatabase {
|
||||
'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,
|
||||
orderListJson TEXT,
|
||||
userJson TEXT,
|
||||
orderJson TEXT,
|
||||
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 hasOrderListJson = false;
|
||||
bool hasUserJson = false;
|
||||
bool hasOrderJson = false;
|
||||
bool hasCreateTime = false;
|
||||
for (final c in columns) {
|
||||
final name = c['name'];
|
||||
if (name == 'sysType') hasSysType = true;
|
||||
if (name == 'orderListJson') hasOrderListJson = true;
|
||||
if (name == 'userJson') hasUserJson = true;
|
||||
if (name == 'orderJson') hasOrderJson = true;
|
||||
if (name == 'createTime') hasCreateTime = true;
|
||||
}
|
||||
if (!hasSysType) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN sysType TEXT',
|
||||
);
|
||||
}
|
||||
if (!hasOrderListJson) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN orderListJson TEXT',
|
||||
);
|
||||
}
|
||||
if (!hasUserJson) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN userJson TEXT',
|
||||
);
|
||||
}
|
||||
if (!hasOrderJson) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN orderJson TEXT',
|
||||
);
|
||||
}
|
||||
if (!hasCreateTime) {
|
||||
await database.execute(
|
||||
'ALTER TABLE order_hold_bill ADD COLUMN createTime TEXT',
|
||||
);
|
||||
}
|
||||
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)",
|
||||
);
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,8 @@ class _$AppDatabase extends AppDatabase {
|
||||
|
||||
OrderDao? _getOrderDaoInstance;
|
||||
|
||||
OrderHoldBillDao? _getOrderHoldBillDaoInstance;
|
||||
|
||||
CanteenSpuDao? _getCanteenSpuDaoInstance;
|
||||
|
||||
SupermarketSkuDao? _getSupermarketSkuDaoInstance;
|
||||
@@ -102,7 +104,7 @@ class _$AppDatabase extends AppDatabase {
|
||||
Callback? callback,
|
||||
]) async {
|
||||
final databaseOptions = sqflite.OpenDatabaseOptions(
|
||||
version: 2,
|
||||
version: 3,
|
||||
onConfigure: (database) async {
|
||||
await database.execute('PRAGMA foreign_keys = ON');
|
||||
await callback?.onConfigure?.call(database);
|
||||
@@ -121,6 +123,8 @@ class _$AppDatabase extends AppDatabase {
|
||||
'CREATE TABLE IF NOT EXISTS `broadcast` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `content` TEXT NOT NULL, `broadcastCount` INTEGER NOT NULL, `broadcastMaxCount` INTEGER NOT NULL, `isBroadcast` INTEGER NOT NULL, `isDone` INTEGER NOT NULL, `isDoneTime` TEXT, `serviceCode` TEXT NOT NULL, `serviceOrderCode` TEXT NOT NULL, `userId` TEXT NOT NULL, `username` TEXT NOT NULL, `userMobile` TEXT NOT NULL, `productDesc` TEXT NOT NULL, `payPrice` INTEGER NOT NULL, `hourType` INTEGER, `enable` INTEGER NOT NULL, `createTime` TEXT NOT NULL)');
|
||||
await database.execute(
|
||||
'CREATE TABLE IF NOT EXISTS `order_record` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `uniqueCode` TEXT NOT NULL, `serviceUniqueCode` TEXT NOT NULL, `sysType` TEXT NOT NULL, `userCode` TEXT NOT NULL, `username` TEXT, `hourType` TEXT, `price` INTEGER NOT NULL, `extraPrice` INTEGER NOT NULL, `payPrice` INTEGER NOT NULL, `walletId` TEXT, `orderSourceTypeId` TEXT, `type` TEXT NOT NULL, `status` TEXT NOT NULL, `payType` TEXT NOT NULL, `productDesc` TEXT, `count` INTEGER NOT NULL, `weight` REAL NOT NULL, `payTime` TEXT, `createTime` TEXT NOT NULL)');
|
||||
await database.execute(
|
||||
'CREATE TABLE IF NOT EXISTS `order_hold_bill` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `sysType` TEXT NOT NULL, `orderListJson` TEXT, `userJson` TEXT, `orderJson` TEXT, `createTime` TEXT NOT NULL)');
|
||||
await database.execute(
|
||||
'CREATE TABLE IF NOT EXISTS `canteen_spu` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `serviceUniqueCode` TEXT NOT NULL, `classifyServiceUniqueCode` TEXT NOT NULL, `hourType` INTEGER, `saleDate` TEXT NOT NULL, `name` TEXT NOT NULL, `price` INTEGER NOT NULL, `image` TEXT, `isDefault` INTEGER NOT NULL, `status` INTEGER NOT NULL, `sort` INTEGER NOT NULL, `createTime` TEXT NOT NULL, `updateTime` TEXT NOT NULL)');
|
||||
await database.execute(
|
||||
@@ -159,6 +163,12 @@ class _$AppDatabase extends AppDatabase {
|
||||
return _getOrderDaoInstance ??= _$OrderDao(database, changeListener);
|
||||
}
|
||||
|
||||
@override
|
||||
OrderHoldBillDao get getOrderHoldBillDao {
|
||||
return _getOrderHoldBillDaoInstance ??=
|
||||
_$OrderHoldBillDao(database, changeListener);
|
||||
}
|
||||
|
||||
@override
|
||||
CanteenSpuDao get getCanteenSpuDao {
|
||||
return _getCanteenSpuDaoInstance ??=
|
||||
@@ -594,6 +604,76 @@ class _$OrderDao extends OrderDao {
|
||||
}
|
||||
}
|
||||
|
||||
class _$OrderHoldBillDao extends OrderHoldBillDao {
|
||||
_$OrderHoldBillDao(
|
||||
this.database,
|
||||
this.changeListener,
|
||||
) : _orderHoldBillEntityInsertionAdapter = InsertionAdapter(
|
||||
database,
|
||||
'order_hold_bill',
|
||||
(OrderHoldBillEntity item) => <String, Object?>{
|
||||
'id': item.id,
|
||||
'sysType': _sysTypeConverter.encode(item.sysType),
|
||||
'orderListJson': item.orderListJson,
|
||||
'userJson': item.userJson,
|
||||
'orderJson': item.orderJson,
|
||||
'createTime': _dateTimeConverter.encode(item.createTime)
|
||||
}),
|
||||
_orderHoldBillEntityUpdateAdapter = UpdateAdapter(
|
||||
database,
|
||||
'order_hold_bill',
|
||||
['id'],
|
||||
(OrderHoldBillEntity item) => <String, Object?>{
|
||||
'id': item.id,
|
||||
'sysType': _sysTypeConverter.encode(item.sysType),
|
||||
'orderListJson': item.orderListJson,
|
||||
'userJson': item.userJson,
|
||||
'orderJson': item.orderJson,
|
||||
'createTime': _dateTimeConverter.encode(item.createTime)
|
||||
}),
|
||||
_orderHoldBillEntityDeletionAdapter = DeletionAdapter(
|
||||
database,
|
||||
'order_hold_bill',
|
||||
['id'],
|
||||
(OrderHoldBillEntity item) => <String, Object?>{
|
||||
'id': item.id,
|
||||
'sysType': _sysTypeConverter.encode(item.sysType),
|
||||
'orderListJson': item.orderListJson,
|
||||
'userJson': item.userJson,
|
||||
'orderJson': item.orderJson,
|
||||
'createTime': _dateTimeConverter.encode(item.createTime)
|
||||
});
|
||||
|
||||
final sqflite.DatabaseExecutor database;
|
||||
|
||||
final StreamController<String> changeListener;
|
||||
|
||||
final InsertionAdapter<OrderHoldBillEntity>
|
||||
_orderHoldBillEntityInsertionAdapter;
|
||||
|
||||
final UpdateAdapter<OrderHoldBillEntity> _orderHoldBillEntityUpdateAdapter;
|
||||
|
||||
final DeletionAdapter<OrderHoldBillEntity>
|
||||
_orderHoldBillEntityDeletionAdapter;
|
||||
|
||||
@override
|
||||
Future<int> save(OrderHoldBillEntity entity) {
|
||||
return _orderHoldBillEntityInsertionAdapter.insertAndReturnId(
|
||||
entity, OnConflictStrategy.abort);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> edit(OrderHoldBillEntity entity) async {
|
||||
await _orderHoldBillEntityUpdateAdapter.update(
|
||||
entity, OnConflictStrategy.abort);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> del(OrderHoldBillEntity entity) async {
|
||||
await _orderHoldBillEntityDeletionAdapter.delete(entity);
|
||||
}
|
||||
}
|
||||
|
||||
class _$CanteenSpuDao extends CanteenSpuDao {
|
||||
_$CanteenSpuDao(
|
||||
this.database,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:floor/floor.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
part 'order_hold_bill_entity.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@Entity(tableName: "order_hold_bill")
|
||||
class OrderHoldBillEntity {
|
||||
/// 自增ID
|
||||
@PrimaryKey(autoGenerate: true)
|
||||
int? id;
|
||||
|
||||
/// 平台类型
|
||||
SysType sysType;
|
||||
|
||||
/// 订单列表json
|
||||
String? orderListJson;
|
||||
|
||||
/// 支付订单json
|
||||
String? userJson;
|
||||
|
||||
String? orderJson;
|
||||
|
||||
/// 创建时间
|
||||
DateTime createTime;
|
||||
|
||||
OrderHoldBillEntity({
|
||||
this.id,
|
||||
this.orderListJson,
|
||||
this.userJson,
|
||||
this.orderJson,
|
||||
required this.sysType,
|
||||
required this.createTime,
|
||||
});
|
||||
|
||||
factory OrderHoldBillEntity.fromJson(Map<String, dynamic> json) =>
|
||||
_$OrderHoldBillEntityFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$OrderHoldBillEntityToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'order_hold_bill_entity.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
OrderHoldBillEntity _$OrderHoldBillEntityFromJson(Map<String, dynamic> json) =>
|
||||
OrderHoldBillEntity(
|
||||
id: (json['id'] as num?)?.toInt(),
|
||||
orderListJson: json['orderListJson'] as String?,
|
||||
userJson: json['userJson'] as String?,
|
||||
orderJson: json['orderJson'] as String?,
|
||||
sysType: $enumDecode(_$SysTypeEnumMap, json['sysType']),
|
||||
createTime: DateTime.parse(json['createTime'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$OrderHoldBillEntityToJson(
|
||||
OrderHoldBillEntity instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'sysType': _$SysTypeEnumMap[instance.sysType]!,
|
||||
'orderListJson': instance.orderListJson,
|
||||
'userJson': instance.userJson,
|
||||
'orderJson': instance.orderJson,
|
||||
'createTime': instance.createTime.toIso8601String(),
|
||||
};
|
||||
|
||||
const _$SysTypeEnumMap = {
|
||||
SysType.SUPERMARKET: 'SUPERMARKET',
|
||||
SysType.CANTEEN: 'CANTEEN',
|
||||
};
|
||||
@@ -7,6 +7,7 @@ export './database/type_converter/type_converter.dart';
|
||||
export './database/dao/broadcast_dao.dart';
|
||||
export './database/dao/classify_dao.dart';
|
||||
export './database/dao/face_dao.dart';
|
||||
export './database/dao/order_hold_bill_dao.dart';
|
||||
export './database/dao/order_dao.dart';
|
||||
export './database/dao/print_history_dao.dart';
|
||||
export './database/dao/canteen_spu_dao.dart';
|
||||
@@ -21,6 +22,7 @@ export './database/entity/broadcast_entity.dart';
|
||||
export './database/entity/classify_entity.dart';
|
||||
export './database/entity/face_entity.dart';
|
||||
export './database/entity/order_entity.dart';
|
||||
export './database/entity/order_hold_bill_entity.dart';
|
||||
export './database/entity/print_history_entity.dart';
|
||||
export './database/entity/canteen_spu_entity.dart';
|
||||
export './database/entity/setting_entity.dart';
|
||||
|
||||
Reference in new issue
Block a user