diff --git a/android/app/src/main/java/io/flutter/plugins/facediscern/database/DatabaseHelper.java b/android/app/src/main/java/io/flutter/plugins/facediscern/database/DatabaseHelper.java index 6bc4c4a..75b48d8 100644 --- a/android/app/src/main/java/io/flutter/plugins/facediscern/database/DatabaseHelper.java +++ b/android/app/src/main/java/io/flutter/plugins/facediscern/database/DatabaseHelper.java @@ -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); diff --git a/lib/common/services/database/dao/order_hold_bill_dao.dart b/lib/common/services/database/dao/order_hold_bill_dao.dart new file mode 100644 index 0000000..fd2d922 --- /dev/null +++ b/lib/common/services/database/dao/order_hold_bill_dao.dart @@ -0,0 +1,15 @@ +import 'package:floor/floor.dart'; + +import 'package:pj_supermarket_cloud/common/index.dart'; + +@dao +abstract class OrderHoldBillDao { + @insert + Future save(OrderHoldBillEntity entity); + + @update + Future edit(OrderHoldBillEntity entity); + + @delete + Future del(OrderHoldBillEntity entity); +} diff --git a/lib/common/services/database/database.dart b/lib/common/services/database/database.dart index aca2f6d..ca309c8 100644 --- a/lib/common/services/database/database.dart +++ b/lib/common/services/database/database.dart @@ -10,6 +10,7 @@ part 'database.g.dart'; const entities = [ BroadcastEntity, OrderEntity, + OrderHoldBillEntity, CanteenSpuEntity, SupermarketSkuEntity, SupermarketSpuEntity, @@ -35,11 +36,12 @@ const typeConverters = [ 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)", + ); + } + }), ]; } diff --git a/lib/common/services/database/database.g.dart b/lib/common/services/database/database.g.dart index 38a2c1a..f32060f 100644 --- a/lib/common/services/database/database.g.dart +++ b/lib/common/services/database/database.g.dart @@ -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) => { + '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) => { + '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) => { + '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 changeListener; + + final InsertionAdapter + _orderHoldBillEntityInsertionAdapter; + + final UpdateAdapter _orderHoldBillEntityUpdateAdapter; + + final DeletionAdapter + _orderHoldBillEntityDeletionAdapter; + + @override + Future save(OrderHoldBillEntity entity) { + return _orderHoldBillEntityInsertionAdapter.insertAndReturnId( + entity, OnConflictStrategy.abort); + } + + @override + Future edit(OrderHoldBillEntity entity) async { + await _orderHoldBillEntityUpdateAdapter.update( + entity, OnConflictStrategy.abort); + } + + @override + Future del(OrderHoldBillEntity entity) async { + await _orderHoldBillEntityDeletionAdapter.delete(entity); + } +} + class _$CanteenSpuDao extends CanteenSpuDao { _$CanteenSpuDao( this.database, diff --git a/lib/common/services/database/entity/order_hold_bill_entity.dart b/lib/common/services/database/entity/order_hold_bill_entity.dart new file mode 100644 index 0000000..b95eccf --- /dev/null +++ b/lib/common/services/database/entity/order_hold_bill_entity.dart @@ -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 json) => + _$OrderHoldBillEntityFromJson(json); + + Map toJson() => _$OrderHoldBillEntityToJson(this); +} diff --git a/lib/common/services/database/entity/order_hold_bill_entity.g.dart b/lib/common/services/database/entity/order_hold_bill_entity.g.dart new file mode 100644 index 0000000..a647007 --- /dev/null +++ b/lib/common/services/database/entity/order_hold_bill_entity.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'order_hold_bill_entity.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +OrderHoldBillEntity _$OrderHoldBillEntityFromJson(Map 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 _$OrderHoldBillEntityToJson( + OrderHoldBillEntity instance) => + { + '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', +}; diff --git a/lib/common/services/index.dart b/lib/common/services/index.dart index 571bc1e..5f8f7a9 100644 --- a/lib/common/services/index.dart +++ b/lib/common/services/index.dart @@ -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';