feat:预定广播
This commit is contained in:
1 parent
fa90df8d9d
commit
691fb68d53
13 files changed
+341
-1
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import 'package:floor/floor.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
// broadcast
|
||||
@dao
|
||||
abstract class BroadcastDao {
|
||||
@insert
|
||||
Future<void> save(BroadcastEntity entity);
|
||||
|
||||
@insert
|
||||
Future<void> batchSave(List<BroadcastEntity> entitys);
|
||||
|
||||
@Query("""
|
||||
SELECT * FROM broadcast
|
||||
WHERE
|
||||
isDone = 0
|
||||
AND enable = true
|
||||
AND broadcastCount < broadcastMaxCount
|
||||
AND strftime('%Y-%m-%d', createTime) = strftime('%Y-%m-%d', 'now', 'localtime')
|
||||
""")
|
||||
Future<List<BroadcastEntity>> getAll();
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import 'package:sqflite/sqflite.dart' as sqflite;
|
||||
part 'database.g.dart';
|
||||
|
||||
const entities = <Type>[
|
||||
BroadcastEntity,
|
||||
OrderEntity,
|
||||
CanteenSpuEntity,
|
||||
SupermarketSkuEntity,
|
||||
@@ -37,6 +38,7 @@ const typeConverters = <Type>[
|
||||
@Database(version: 1, entities: entities)
|
||||
@TypeConverters(typeConverters)
|
||||
abstract class AppDatabase extends FloorDatabase {
|
||||
BroadcastDao get getBroadcastDao;
|
||||
OrderDao get getOrderDao;
|
||||
CanteenSpuDao get getCanteenSpuDao;
|
||||
SupermarketSkuDao get getSupermarketSkuDao;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -28,6 +28,27 @@ class BroadcastEntity {
|
||||
/// 完成时间
|
||||
DateTime? isDoneTime;
|
||||
|
||||
/// 服务单号
|
||||
String serviceCode;
|
||||
|
||||
/// 用户id
|
||||
String userId;
|
||||
|
||||
/// 用户姓名
|
||||
String username;
|
||||
|
||||
/// 用户手机号
|
||||
String userMobile;
|
||||
|
||||
/// 商品介绍
|
||||
String productDesc;
|
||||
|
||||
/// 支付价格
|
||||
int payPrice;
|
||||
|
||||
/// 手动开关
|
||||
bool enable = true;
|
||||
|
||||
/// 创建时间
|
||||
DateTime createTime;
|
||||
|
||||
@@ -37,6 +58,12 @@ class BroadcastEntity {
|
||||
required this.broadcastMaxCount,
|
||||
required this.isBroadcast,
|
||||
required this.createTime,
|
||||
required this.serviceCode,
|
||||
required this.userId,
|
||||
required this.username,
|
||||
required this.userMobile,
|
||||
required this.productDesc,
|
||||
required this.payPrice,
|
||||
});
|
||||
|
||||
factory BroadcastEntity.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -13,12 +13,19 @@ BroadcastEntity _$BroadcastEntityFromJson(Map<String, dynamic> json) =>
|
||||
broadcastMaxCount: (json['broadcastMaxCount'] as num).toInt(),
|
||||
isBroadcast: json['isBroadcast'] as bool,
|
||||
createTime: DateTime.parse(json['createTime'] as String),
|
||||
serviceCode: json['serviceCode'] as String,
|
||||
userId: json['userId'] as String,
|
||||
username: json['username'] as String,
|
||||
userMobile: json['userMobile'] as String,
|
||||
productDesc: json['productDesc'] as String,
|
||||
payPrice: (json['payPrice'] as num).toInt(),
|
||||
)
|
||||
..broadcastCount = (json['broadcastCount'] as num).toInt()
|
||||
..isDone = json['isDone'] as bool
|
||||
..isDoneTime = json['isDoneTime'] == null
|
||||
? null
|
||||
: DateTime.parse(json['isDoneTime'] as String);
|
||||
: DateTime.parse(json['isDoneTime'] as String)
|
||||
..enable = json['enable'] as bool;
|
||||
|
||||
Map<String, dynamic> _$BroadcastEntityToJson(BroadcastEntity instance) =>
|
||||
<String, dynamic>{
|
||||
@@ -29,5 +36,12 @@ Map<String, dynamic> _$BroadcastEntityToJson(BroadcastEntity instance) =>
|
||||
'isBroadcast': instance.isBroadcast,
|
||||
'isDone': instance.isDone,
|
||||
'isDoneTime': instance.isDoneTime?.toIso8601String(),
|
||||
'serviceCode': instance.serviceCode,
|
||||
'userId': instance.userId,
|
||||
'username': instance.username,
|
||||
'userMobile': instance.userMobile,
|
||||
'productDesc': instance.productDesc,
|
||||
'payPrice': instance.payPrice,
|
||||
'enable': instance.enable,
|
||||
'createTime': instance.createTime.toIso8601String(),
|
||||
};
|
||||
Reference in new issue
Block a user