feat:预定广播

This commit is contained in:
dzc committed 2025-04-21 11:32:09 +08:00
1 parent fa90df8d9d
commit 691fb68d53
13 files changed
+341 -1

No files matched your search

@@ -72,6 +72,8 @@ class _$AppDatabase extends AppDatabase {
changeListener = listener ?? StreamController<String>.broadcast();
}
BroadcastDao? _getBroadcastDaoInstance;
OrderDao? _getOrderDaoInstance;
CanteenSpuDao? _getCanteenSpuDaoInstance;
@@ -115,6 +117,8 @@ class _$AppDatabase extends AppDatabase {
await callback?.onUpgrade?.call(database, startVersion, endVersion);
},
onCreate: (database, version) async {
await database.execute(
'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, `userId` TEXT NOT NULL, `username` TEXT NOT NULL, `userMobile` TEXT NOT NULL, `productDesc` TEXT NOT NULL, `payPrice` INTEGER NOT NULL, `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(
@@ -144,6 +148,12 @@ class _$AppDatabase extends AppDatabase {
return sqfliteDatabaseFactory.openDatabase(path, options: databaseOptions);
}
@override
BroadcastDao get getBroadcastDao {
return _getBroadcastDaoInstance ??=
_$BroadcastDao(database, changeListener);
}
@override
OrderDao get getOrderDao {
return _getOrderDaoInstance ??= _$OrderDao(database, changeListener);
@@ -205,6 +215,71 @@ class _$AppDatabase extends AppDatabase {
}
}
class _$BroadcastDao extends BroadcastDao {
_$BroadcastDao(
this.database,
this.changeListener,
) : _queryAdapter = QueryAdapter(database),
_broadcastEntityInsertionAdapter = InsertionAdapter(
database,
'broadcast',
(BroadcastEntity item) => <String, Object?>{
'id': item.id,
'content': item.content,
'broadcastCount': item.broadcastCount,
'broadcastMaxCount': item.broadcastMaxCount,
'isBroadcast': _boolConverter.encode(item.isBroadcast),
'isDone': _boolConverter.encode(item.isDone),
'isDoneTime': _dateTimeEmptyConverter.encode(item.isDoneTime),
'serviceCode': item.serviceCode,
'userId': item.userId,
'username': item.username,
'userMobile': item.userMobile,
'productDesc': item.productDesc,
'payPrice': item.payPrice,
'enable': _boolConverter.encode(item.enable),
'createTime': _dateTimeConverter.encode(item.createTime)
});
final sqflite.DatabaseExecutor database;
final StreamController<String> changeListener;
final QueryAdapter _queryAdapter;
final InsertionAdapter<BroadcastEntity> _broadcastEntityInsertionAdapter;
@override
Future<List<BroadcastEntity>> getAll() async {
return _queryAdapter.queryList(
'SELECT * FROM broadcast WHERE isDone = 0 AND enable = true AND broadcastCount < broadcastMaxCount AND strftime(\'%Y-%m-%d\', createTime) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\')',
mapper: (Map<String, Object?> row) => BroadcastEntity(
id: row['id'] as int?,
content: row['content'] as String,
broadcastMaxCount: row['broadcastMaxCount'] as int,
isBroadcast: _boolConverter.decode(row['isBroadcast'] as int),
createTime: _dateTimeConverter.decode(row['createTime'] as String),
serviceCode: row['serviceCode'] as String,
userId: row['userId'] as String,
username: row['username'] as String,
userMobile: row['userMobile'] as String,
productDesc: row['productDesc'] as String,
payPrice: row['payPrice'] as int));
}
@override
Future<void> save(BroadcastEntity entity) async {
await _broadcastEntityInsertionAdapter.insert(
entity, OnConflictStrategy.abort);
}
@override
Future<void> batchSave(List<BroadcastEntity> entitys) async {
await _broadcastEntityInsertionAdapter.insertList(
entitys, OnConflictStrategy.abort);
}
}
class _$OrderDao extends OrderDao {
_$OrderDao(
this.database,