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
+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 = 1;
|
||||
private static final int DATABASE_VERSION = 2;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, getCustomDatabasePath(context), null, DATABASE_VERSION);
|
||||
|
||||
@@ -94,6 +94,9 @@ class MqttTakeFoodBroadcastMsg {
|
||||
/// 支付价格
|
||||
int payPrice;
|
||||
|
||||
/// 时间段类型
|
||||
String hourType;
|
||||
|
||||
MqttTakeFoodBroadcastMsg({
|
||||
required this.topic,
|
||||
required this.userId,
|
||||
@@ -105,6 +108,7 @@ class MqttTakeFoodBroadcastMsg {
|
||||
required this.broadcastMaxCount,
|
||||
required this.productDesc,
|
||||
required this.payPrice,
|
||||
required this.hourType,
|
||||
});
|
||||
|
||||
factory MqttTakeFoodBroadcastMsg.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -60,6 +60,7 @@ MqttTakeFoodBroadcastMsg _$MqttTakeFoodBroadcastMsgFromJson(
|
||||
broadcastMaxCount: (json['broadcastMaxCount'] as num).toInt(),
|
||||
productDesc: json['productDesc'] as String,
|
||||
payPrice: (json['payPrice'] as num).toInt(),
|
||||
hourType: json['hourType'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$MqttTakeFoodBroadcastMsgToJson(
|
||||
@@ -75,4 +76,5 @@ Map<String, dynamic> _$MqttTakeFoodBroadcastMsgToJson(
|
||||
'broadcastMaxCount': instance.broadcastMaxCount,
|
||||
'productDesc': instance.productDesc,
|
||||
'payPrice': instance.payPrice,
|
||||
'hourType': instance.hourType,
|
||||
};
|
||||
@@ -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>{
|
||||
|
||||
@@ -114,8 +114,12 @@ class AppMqTool {
|
||||
break;
|
||||
case MqtActionEnum.TAKE_FOOD_BROADCAST:
|
||||
mqUpdateEventBus.fire(MqtActionEnum.TAKE_FOOD_BROADCAST);
|
||||
final msg = MqttTakeFoodBroadcastMsg.fromJson(json.decode(orgStr));
|
||||
SyncTakeFoodBroadcastTool.addTask(msg);
|
||||
try {
|
||||
final msg = MqttTakeFoodBroadcastMsg.fromJson(json.decode(orgStr));
|
||||
SyncTakeFoodBroadcastTool.addTask(msg);
|
||||
} catch (e, stack) {
|
||||
logger.e("|$_tag|定餐广播执行错误orgStr|$orgStr|error|$e|stack|$stack|");
|
||||
}
|
||||
return;
|
||||
case MqtActionEnum.FACE:
|
||||
return;
|
||||
|
||||
@@ -21,7 +21,7 @@ class SyncCheckTool {
|
||||
|
||||
Duration printInterval = const Duration(seconds: 60 * 10);
|
||||
|
||||
Duration broadcastInterval = const Duration(seconds: 60 * 10);
|
||||
Duration broadcastInterval = const Duration(seconds: 60 * 3);
|
||||
|
||||
Timer? mqTimer;
|
||||
|
||||
|
||||
@@ -13,18 +13,23 @@ abstract class SyncTakeFoodBroadcastTool {
|
||||
final broadcastDao = appC.dataBase.getBroadcastDao;
|
||||
final saveObj = BroadcastEntity(
|
||||
content: msg.content,
|
||||
broadcastCount: 0,
|
||||
broadcastMaxCount: msg.broadcastMaxCount,
|
||||
isBroadcast: true,
|
||||
isDone: false,
|
||||
productDesc: msg.productDesc,
|
||||
serviceCode: msg.id,
|
||||
userId: msg.userId,
|
||||
username: msg.username,
|
||||
userMobile: msg.userMobile,
|
||||
payPrice: msg.payPrice,
|
||||
hourType:
|
||||
ProductHourType.values.fromCode(msg.hourType) ?? ProductHourType.NOON,
|
||||
enable: true,
|
||||
createTime: DateTime.now(),
|
||||
);
|
||||
await broadcastDao.save(saveObj);
|
||||
logger.i("|$_tag|添加到打印记录到本地数据库,json:|${saveObj.toJson()}|");
|
||||
logger.i("|$_tag|添加到广播记录到本地数据库,json:|${saveObj.toJson()}|");
|
||||
await SyncTakeFoodBroadcastTool.doCheckBroadcast();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:forui/forui.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -57,6 +56,7 @@ class CanteenReserveController extends GetxController {
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
hourTypeC.dispose();
|
||||
}
|
||||
|
||||
Future<void> doPage({int? page}) async {
|
||||
@@ -109,7 +109,7 @@ class CanteenReserveController extends GetxController {
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
final broadcastDao = appC.dataBase.getBroadcastDao;
|
||||
v.broadcastCount = 0;
|
||||
v.broadcastCount = 10;
|
||||
await broadcastDao.edit(v);
|
||||
await _getReservePage();
|
||||
EasyLoading.dismiss();
|
||||
|
||||
@@ -63,7 +63,7 @@ class CanteenReservePage extends GetView<CanteenReserveController> {
|
||||
DataColumn2(
|
||||
label: Text("用户", textAlign: TextAlign.center),
|
||||
headingRowAlignment: MainAxisAlignment.center,
|
||||
fixedWidth: 230.w,
|
||||
fixedWidth: 300.w,
|
||||
),
|
||||
DataColumn2(
|
||||
label: Text("商品", textAlign: TextAlign.center),
|
||||
@@ -76,29 +76,24 @@ class CanteenReservePage extends GetView<CanteenReserveController> {
|
||||
fixedWidth: 230.w,
|
||||
),
|
||||
DataColumn2(
|
||||
label: Text("当前广播次数", textAlign: TextAlign.center),
|
||||
headingRowAlignment: MainAxisAlignment.center,
|
||||
fixedWidth: 230.w,
|
||||
),
|
||||
DataColumn2(
|
||||
label: Text("最大广播次数", textAlign: TextAlign.center),
|
||||
label: Text("广播次数", textAlign: TextAlign.center),
|
||||
headingRowAlignment: MainAxisAlignment.center,
|
||||
fixedWidth: 230.w,
|
||||
),
|
||||
DataColumn2(
|
||||
label: Text("是否开启广播", textAlign: TextAlign.center),
|
||||
headingRowAlignment: MainAxisAlignment.center,
|
||||
fixedWidth: 230.w,
|
||||
fixedWidth: 200.w,
|
||||
),
|
||||
DataColumn2(
|
||||
label: Text("下单时间", textAlign: TextAlign.center),
|
||||
headingRowAlignment: MainAxisAlignment.center,
|
||||
fixedWidth: 230.w,
|
||||
fixedWidth: 300.w,
|
||||
),
|
||||
DataColumn2(
|
||||
label: Text("操作", textAlign: TextAlign.center),
|
||||
headingRowAlignment: MainAxisAlignment.center,
|
||||
fixedWidth: 230.w,
|
||||
fixedWidth: 300.w,
|
||||
),
|
||||
],
|
||||
rows: controller.reserveList
|
||||
@@ -126,12 +121,6 @@ class CanteenReservePage extends GetView<CanteenReserveController> {
|
||||
textAlign: TextAlign.center,
|
||||
).center(),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
"${v.broadcastMaxCount}",
|
||||
textAlign: TextAlign.center,
|
||||
).center(),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
v.enable ? "是" : "否",
|
||||
@@ -148,7 +137,8 @@ class CanteenReservePage extends GetView<CanteenReserveController> {
|
||||
<Widget>[
|
||||
FButton(
|
||||
label: Text(
|
||||
v.enable ? "关闭播报" : '开启播报',
|
||||
// v.enable ? "关闭播报" : '开启播报',
|
||||
"${v.enable}",
|
||||
style: theme.typography.sm.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
@@ -158,7 +148,7 @@ class CanteenReservePage extends GetView<CanteenReserveController> {
|
||||
),
|
||||
FButton(
|
||||
label: Text(
|
||||
'充值播报次数',
|
||||
'重置播报次数',
|
||||
style: theme.typography.sm.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
@@ -166,7 +156,9 @@ class CanteenReservePage extends GetView<CanteenReserveController> {
|
||||
style: FButtonStyle.outline,
|
||||
onPress: () => controller.reset(v),
|
||||
),
|
||||
].toRow(),
|
||||
].toRow(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user