feat: 更新广播间隔、数据库版本及广播逻辑
- 将广播间隔从10分钟缩短至3分钟 - 更新数据库版本至2,并调整相关实体和查询逻辑 - 修复广播记录保存和查询时的字段初始化问题 - 在广播消息中添加时间段类型字段 - 优化广播记录的UI显示和操作逻辑
This commit is contained in:
1 parent
45c2ea384d
commit
cc98644cb5
13 files changed
+89
-44
No files matched your search
@@ -18,7 +18,7 @@ abstract class BroadcastDao {
|
||||
SELECT * FROM broadcast
|
||||
WHERE
|
||||
isDone = 0
|
||||
AND enable = true
|
||||
AND enable = 1
|
||||
AND broadcastCount < broadcastMaxCount
|
||||
AND strftime('%Y-%m-%d', createTime) = strftime('%Y-%m-%d', 'now', 'localtime')
|
||||
""")
|
||||
|
||||
@@ -35,7 +35,7 @@ const typeConverters = <Type>[
|
||||
BoolConverter,
|
||||
];
|
||||
|
||||
@Database(version: 1, entities: entities)
|
||||
@Database(version: 2, entities: entities)
|
||||
@TypeConverters(typeConverters)
|
||||
abstract class AppDatabase extends FloorDatabase {
|
||||
BroadcastDao get getBroadcastDao;
|
||||
|
||||
@@ -102,7 +102,7 @@ class _$AppDatabase extends AppDatabase {
|
||||
Callback? callback,
|
||||
]) async {
|
||||
final databaseOptions = sqflite.OpenDatabaseOptions(
|
||||
version: 1,
|
||||
version: 2,
|
||||
onConfigure: (database) async {
|
||||
await database.execute('PRAGMA foreign_keys = ON');
|
||||
await callback?.onConfigure?.call(database);
|
||||
@@ -223,6 +223,28 @@ class _$BroadcastDao extends BroadcastDao {
|
||||
_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,
|
||||
'hourType': item.hourType?.index,
|
||||
'enable': _boolConverter.encode(item.enable),
|
||||
'createTime': _dateTimeConverter.encode(item.createTime)
|
||||
}),
|
||||
_broadcastEntityUpdateAdapter = UpdateAdapter(
|
||||
database,
|
||||
'broadcast',
|
||||
['id'],
|
||||
(BroadcastEntity item) => <String, Object?>{
|
||||
'id': item.id,
|
||||
'content': item.content,
|
||||
@@ -250,22 +272,30 @@ class _$BroadcastDao extends BroadcastDao {
|
||||
|
||||
final InsertionAdapter<BroadcastEntity> _broadcastEntityInsertionAdapter;
|
||||
|
||||
final UpdateAdapter<BroadcastEntity> _broadcastEntityUpdateAdapter;
|
||||
|
||||
@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\')',
|
||||
'SELECT * FROM broadcast WHERE isDone = 0 AND enable = 1 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,
|
||||
broadcastCount: row['broadcastCount'] as int,
|
||||
broadcastMaxCount: row['broadcastMaxCount'] as int,
|
||||
isBroadcast: _boolConverter.decode(row['isBroadcast'] as int),
|
||||
isDone: _boolConverter.decode(row['isDone'] 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));
|
||||
payPrice: row['payPrice'] as int,
|
||||
hourType: row['hourType'] == null
|
||||
? null
|
||||
: ProductHourType.values[row['hourType'] as int],
|
||||
enable: _boolConverter.decode(row['enable'] as int)));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -276,7 +306,7 @@ class _$BroadcastDao extends BroadcastDao {
|
||||
) async {
|
||||
return _queryAdapter.queryList(
|
||||
'SELECT * FROM broadcast WHERE strftime(\'%Y-%m-%d\', createTime) = strftime(\'%Y-%m-%d\', \'now\', \'localtime\') AND (?1 = \'-1\' OR hourType = ?1) LIMIT ?2 OFFSET ?3',
|
||||
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),
|
||||
mapper: (Map<String, Object?> row) => BroadcastEntity(id: row['id'] as int?, content: row['content'] as String, broadcastCount: row['broadcastCount'] as int, broadcastMaxCount: row['broadcastMaxCount'] as int, isBroadcast: _boolConverter.decode(row['isBroadcast'] as int), isDone: _boolConverter.decode(row['isDone'] 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, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], enable: _boolConverter.decode(row['enable'] as int)),
|
||||
arguments: [hourType, pageSize, offset]);
|
||||
}
|
||||
|
||||
@@ -299,6 +329,12 @@ class _$BroadcastDao extends BroadcastDao {
|
||||
await _broadcastEntityInsertionAdapter.insertList(
|
||||
entitys, OnConflictStrategy.abort);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> edit(BroadcastEntity entity) async {
|
||||
await _broadcastEntityUpdateAdapter.update(
|
||||
entity, OnConflictStrategy.abort);
|
||||
}
|
||||
}
|
||||
|
||||
class _$OrderDao extends OrderDao {
|
||||
|
||||
@@ -15,7 +15,7 @@ class BroadcastEntity {
|
||||
String content;
|
||||
|
||||
/// 当前广播次数
|
||||
int broadcastCount = 0;
|
||||
int broadcastCount;
|
||||
|
||||
/// 最大广播次数
|
||||
int broadcastMaxCount;
|
||||
@@ -24,7 +24,7 @@ class BroadcastEntity {
|
||||
bool isBroadcast;
|
||||
|
||||
/// 是否完成
|
||||
bool isDone = false;
|
||||
bool isDone;
|
||||
|
||||
/// 完成时间
|
||||
DateTime? isDoneTime;
|
||||
@@ -51,7 +51,7 @@ class BroadcastEntity {
|
||||
ProductHourType? hourType;
|
||||
|
||||
/// 手动开关
|
||||
bool enable = true;
|
||||
bool enable;
|
||||
|
||||
/// 创建时间
|
||||
DateTime createTime;
|
||||
@@ -59,8 +59,10 @@ class BroadcastEntity {
|
||||
BroadcastEntity({
|
||||
this.id,
|
||||
required this.content,
|
||||
required this.broadcastCount,
|
||||
required this.broadcastMaxCount,
|
||||
required this.isBroadcast,
|
||||
required this.isDone,
|
||||
required this.createTime,
|
||||
required this.serviceCode,
|
||||
required this.userId,
|
||||
@@ -68,6 +70,8 @@ class BroadcastEntity {
|
||||
required this.userMobile,
|
||||
required this.productDesc,
|
||||
required this.payPrice,
|
||||
this.hourType,
|
||||
required this.enable,
|
||||
});
|
||||
|
||||
factory BroadcastEntity.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -10,8 +10,10 @@ BroadcastEntity _$BroadcastEntityFromJson(Map<String, dynamic> json) =>
|
||||
BroadcastEntity(
|
||||
id: (json['id'] as num?)?.toInt(),
|
||||
content: json['content'] as String,
|
||||
broadcastCount: (json['broadcastCount'] as num).toInt(),
|
||||
broadcastMaxCount: (json['broadcastMaxCount'] as num).toInt(),
|
||||
isBroadcast: json['isBroadcast'] as bool,
|
||||
isDone: json['isDone'] as bool,
|
||||
createTime: DateTime.parse(json['createTime'] as String),
|
||||
serviceCode: json['serviceCode'] as String,
|
||||
userId: json['userId'] as String,
|
||||
@@ -19,15 +21,11 @@ BroadcastEntity _$BroadcastEntityFromJson(Map<String, dynamic> json) =>
|
||||
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)
|
||||
..hourType =
|
||||
$enumDecodeNullable(_$ProductHourTypeEnumMap, json['hourType'])
|
||||
..enable = json['enable'] as bool;
|
||||
hourType: $enumDecodeNullable(_$ProductHourTypeEnumMap, json['hourType']),
|
||||
enable: json['enable'] as bool,
|
||||
)..isDoneTime = json['isDoneTime'] == null
|
||||
? null
|
||||
: DateTime.parse(json['isDoneTime'] as String);
|
||||
|
||||
Map<String, dynamic> _$BroadcastEntityToJson(BroadcastEntity instance) =>
|
||||
<String, dynamic>{
|
||||
|
||||
Reference in new issue
Block a user