feat:订餐预约播报
This commit is contained in:
1 parent
2f72e7a3c0
commit
d1a6ac4c6c
7 files changed
+64
-38
No files matched your search
@@ -434,6 +434,9 @@ class ServiceBroadcastToday {
|
||||
/// 支付价格
|
||||
int payPrice;
|
||||
|
||||
/// 创建时间
|
||||
String createTime;
|
||||
|
||||
ServiceBroadcastToday({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
@@ -451,6 +454,7 @@ class ServiceBroadcastToday {
|
||||
this.hourType,
|
||||
required this.productDesc,
|
||||
required this.payPrice,
|
||||
required this.createTime,
|
||||
});
|
||||
|
||||
factory ServiceBroadcastToday.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -265,6 +265,7 @@ ServiceBroadcastToday _$ServiceBroadcastTodayFromJson(
|
||||
hourType: json['hourType'] as String?,
|
||||
productDesc: json['productDesc'] as String,
|
||||
payPrice: (json['payPrice'] as num).toInt(),
|
||||
createTime: json['createTime'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServiceBroadcastTodayToJson(
|
||||
@@ -286,6 +287,7 @@ Map<String, dynamic> _$ServiceBroadcastTodayToJson(
|
||||
'hourType': instance.hourType,
|
||||
'productDesc': instance.productDesc,
|
||||
'payPrice': instance.payPrice,
|
||||
'createTime': instance.createTime,
|
||||
};
|
||||
|
||||
ServiceBroadcastTodayPage _$ServiceBroadcastTodayPageFromJson(
|
||||
|
||||
@@ -7,13 +7,14 @@ import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
// broadcast
|
||||
@dao
|
||||
abstract class BroadcastDao {
|
||||
Future<int> toggleEnable(bool enable) async {
|
||||
Future<int> toggleEnable(bool enable, ProductHourType hourType) async {
|
||||
final app = Get.find<AppControl>();
|
||||
final database = app.dataBase.database;
|
||||
final sql = '''
|
||||
UPDATE broadcast SET enable = ${enable ? 1 : 0}
|
||||
WHERE
|
||||
isDone = 0
|
||||
AND (:hourType = '-1' OR hourType = :hourType)
|
||||
AND strftime('%Y-%m-%d', createTime) = strftime('%Y-%m-%d', 'now', 'localtime')
|
||||
''';
|
||||
return await database.rawUpdate(sql, []);
|
||||
@@ -35,6 +36,17 @@ abstract class BroadcastDao {
|
||||
return await database.rawDelete(sql, [...codes]);
|
||||
}
|
||||
|
||||
Future<int> delAll() async {
|
||||
final appC = Get.find<AppControl>();
|
||||
final database = appC.dataBase.database;
|
||||
final sql = '''
|
||||
DELETE FROM broadcast
|
||||
WHERE
|
||||
strftime('%Y-%m-%d', createTime) = strftime('%Y-%m-%d', 'now', 'localtime')
|
||||
''';
|
||||
return await database.rawDelete(sql, []);
|
||||
}
|
||||
|
||||
@insert
|
||||
Future<void> save(BroadcastEntity entity);
|
||||
|
||||
@@ -58,9 +70,10 @@ abstract class BroadcastDao {
|
||||
isDone = 0
|
||||
AND enable = 1
|
||||
AND broadcastCount < broadcastMaxCount
|
||||
AND (:hourType = '-1' OR hourType = :hourType)
|
||||
AND strftime('%Y-%m-%d', createTime) = strftime('%Y-%m-%d', 'now', 'localtime')
|
||||
""")
|
||||
Future<List<BroadcastEntity>> getAll();
|
||||
Future<List<BroadcastEntity>> getAll(String hourType);
|
||||
|
||||
@Query("""
|
||||
SELECT * FROM broadcast
|
||||
|
||||
@@ -282,27 +282,11 @@ class _$BroadcastDao extends BroadcastDao {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<BroadcastEntity>> getAll() async {
|
||||
Future<List<BroadcastEntity>> getAll(String hourType) async {
|
||||
return _queryAdapter.queryList(
|
||||
'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,
|
||||
hourType: row['hourType'] == null
|
||||
? null
|
||||
: ProductHourType.values[row['hourType'] as int],
|
||||
enable: _boolConverter.decode(row['enable'] as int)));
|
||||
'SELECT * FROM broadcast WHERE isDone = 0 AND enable = 1 AND broadcastCount < broadcastMaxCount AND (?1 = \'-1\' OR hourType = ?1) 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, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], enable: _boolConverter.decode(row['enable'] as int)),
|
||||
arguments: [hourType]);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:mqtt_client/mqtt_client.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
@@ -117,7 +118,10 @@ class SyncCheckTool {
|
||||
if (!isNetwork) return;
|
||||
logger.i("|$_tag|$logMsg,$inSeconds秒一次,开始执行");
|
||||
try {
|
||||
await SyncTakeFoodBroadcastTool.doCheckBroadcast();
|
||||
final setting = await AppSettingTool.getSysSetting();
|
||||
await SyncTakeFoodBroadcastTool.doCheckBroadcast(
|
||||
setting.hourType ?? ProductHourType.TOTAL,
|
||||
);
|
||||
} catch (e) {
|
||||
logger.i("|$_tag|$logMsg,$inSeconds秒一次,执行失败,error:$e");
|
||||
} finally {
|
||||
|
||||
@@ -35,11 +35,14 @@ abstract class SyncTakeFoodBroadcastTool {
|
||||
);
|
||||
await broadcastDao.save(saveObj);
|
||||
logger.i("|$_tag|添加到广播记录到本地数据库,json:|${saveObj.toJson()}|");
|
||||
await SyncTakeFoodBroadcastTool.doCheckBroadcast();
|
||||
final setting = await AppSettingTool.getSysSetting();
|
||||
await SyncTakeFoodBroadcastTool.doCheckBroadcast(
|
||||
setting.hourType ?? ProductHourType.TOTAL,
|
||||
);
|
||||
}
|
||||
|
||||
// 检查广播
|
||||
static Future<void> doCheckBroadcast() async {
|
||||
static Future<void> doCheckBroadcast(ProductHourType hourType) async {
|
||||
if (_isBroadcast) {
|
||||
logger.i("|$_tag|检查打印,正在广播中");
|
||||
return;
|
||||
@@ -48,7 +51,7 @@ abstract class SyncTakeFoodBroadcastTool {
|
||||
final appC = Get.find<AppControl>();
|
||||
final broadcastDao = appC.dataBase.getBroadcastDao;
|
||||
try {
|
||||
final list = await broadcastDao.getAll();
|
||||
final list = await broadcastDao.getAll(hourType.code);
|
||||
if (ObjectUtil.isEmptyList(list)) {
|
||||
_isBroadcast = false;
|
||||
logger.i("|$_tag|检查广播,没有需要广播的订单信息");
|
||||
@@ -65,10 +68,16 @@ abstract class SyncTakeFoodBroadcastTool {
|
||||
: list.length;
|
||||
// 获取当前组的元素
|
||||
final currentGroup = list.sublist(start, end);
|
||||
String msg = "请手机尾号,";
|
||||
// 使用 Set 去重
|
||||
final Set<String> uniqueContents = {};
|
||||
for (final v in currentGroup) {
|
||||
msg += "${v.content},";
|
||||
uniqueContents.add(v.content);
|
||||
}
|
||||
String msg = "请手机尾号";
|
||||
for (final content in uniqueContents) {
|
||||
msg += "$content,";
|
||||
}
|
||||
// 逗号会影响语音播报断句
|
||||
msg = msg.substring(0, msg.length - 1);
|
||||
msg += "的用户,尽快取餐";
|
||||
// 播报当前组
|
||||
@@ -121,13 +130,13 @@ abstract class SyncTakeFoodBroadcastTool {
|
||||
if (ObjectUtil.isEmptyList(serviceList.records)) return false;
|
||||
final appC = Get.find<AppControl>();
|
||||
final broadcastDao = appC.dataBase.getBroadcastDao;
|
||||
final serviceCodes =
|
||||
serviceList.records?.map((e) => e.id.toString()).toList();
|
||||
if (ObjectUtil.isEmptyList(serviceCodes)) {
|
||||
return result;
|
||||
}
|
||||
// final serviceCodes =
|
||||
// serviceList.records?.map((e) => e.id.toString()).toList();
|
||||
// if (ObjectUtil.isEmptyList(serviceCodes)) {
|
||||
// return result;
|
||||
// }
|
||||
// 根据服务码查询本地数据库
|
||||
await broadcastDao.delByServiceCodes(serviceCodes!);
|
||||
await broadcastDao.delAll();
|
||||
final saveList = serviceList.records!
|
||||
.map((e) => _convertServiceBroadcastTodayToBroadcastEntity(e))
|
||||
.toList();
|
||||
@@ -154,7 +163,7 @@ abstract class SyncTakeFoodBroadcastTool {
|
||||
hourType:
|
||||
ProductHourType.values.fromCode(obj.hourType) ?? ProductHourType.NOON,
|
||||
enable: true,
|
||||
createTime: DateTime.now(),
|
||||
createTime: DateUtil.getDateTime(obj.createTime) ?? DateTime.now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -128,30 +128,40 @@ class CanteenReserveController extends GetxController {
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
// 立即执行一次广播
|
||||
SyncTakeFoodBroadcastTool.doCheckBroadcast();
|
||||
SyncTakeFoodBroadcastTool.doCheckBroadcast(hourType.value);
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
|
||||
/// 关闭全部广播
|
||||
Future<void> closeBroadcast() async {
|
||||
final isSure = await appMessageDialog(
|
||||
Get.context!,
|
||||
"是否关闭所有${hourType.value.title}广播",
|
||||
);
|
||||
if (!isSure) return;
|
||||
EasyLoading.show(
|
||||
status: '关闭中...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
final broadcastDao = appC.dataBase.getBroadcastDao;
|
||||
await broadcastDao.toggleEnable(false);
|
||||
await broadcastDao.toggleEnable(false, hourType.value);
|
||||
await _getReservePage();
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
|
||||
/// 打开全部广播
|
||||
Future<void> openBroadcast() async {
|
||||
final isSure = await appMessageDialog(
|
||||
Get.context!,
|
||||
"是否打卡所有${hourType.value.title}广播",
|
||||
);
|
||||
if (!isSure) return;
|
||||
EasyLoading.show(
|
||||
status: '打开中...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
final broadcastDao = appC.dataBase.getBroadcastDao;
|
||||
await broadcastDao.toggleEnable(true);
|
||||
await broadcastDao.toggleEnable(true, hourType.value);
|
||||
await _getReservePage();
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user