feat:取餐、订餐、广播

This commit is contained in:
dzc committed 2025-04-27 17:18:26 +08:00
1 parent d5bfd91bc1
commit e5100b46b1
10 files changed
+313 -4

No files matched your search

@@ -11,6 +11,11 @@ abstract class SyncTakeFoodBroadcastTool {
static Future<void> addTask(MqttTakeFoodBroadcastMsg msg) async {
final appC = Get.find<AppControl>();
final broadcastDao = appC.dataBase.getBroadcastDao;
// 完成就删除掉
if (msg.isDone) {
await broadcastDao.del(msg.id);
return;
}
final saveObj = BroadcastEntity(
content: msg.content,
broadcastCount: 0,
@@ -72,6 +77,12 @@ abstract class SyncTakeFoodBroadcastTool {
if (i < totalGroups - 1) {
await Future.delayed(const Duration(seconds: 3));
}
// 更新广播次数
for (final v in currentGroup) {
v.broadcastCount++;
await broadcastDao.edit(v);
}
// 发送mq消息
}
} catch (e, stack) {
logger.e("|$_tag|检查广播,广播错误,error:|$e|stack:|$stack|");
@@ -79,4 +90,62 @@ abstract class SyncTakeFoodBroadcastTool {
_isBroadcast = false;
}
}
/// 手动查询今天所有的广播并且更新本地数据库
static Future<void> queryTodayBroadcast() async {
// 检查有没有网络
if (!AppNetworkTool.isAutoNetwork()) return;
int currentPage = 1;
final pa = {"current": currentPage, "size": 100};
while (true) {
final isMore = await _queryTodayBroadcastGroup(pa);
if (!isMore) break;
currentPage++;
}
}
/// 手动查询今天所有的广播并且更新本地数据库
static Future<bool> _queryTodayBroadcastGroup(dynamic pa) async {
final serviceList = await HardApi.broadcastToday(pa);
if (serviceList == null) return false;
final result = serviceList.size == 100;
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;
}
// 根据服务码查询本地数据库
await broadcastDao.delByServiceCodes(serviceCodes!);
final saveList = serviceList.records!
.map((e) => _convertServiceBroadcastTodayToBroadcastEntity(e))
.toList();
await broadcastDao.batchSave(saveList);
return result;
}
/// 把 ServiceBroadcastToday 转化为 BroadcastEntity
static BroadcastEntity _convertServiceBroadcastTodayToBroadcastEntity(
ServiceBroadcastToday obj,
) {
return BroadcastEntity(
content: obj.content,
broadcastCount: 0,
broadcastMaxCount: obj.broadcastMaxCount ?? 20,
isBroadcast: true,
isDone: false,
productDesc: obj.productDesc,
serviceCode: obj.id,
userId: obj.userId,
username: obj.username,
userMobile: obj.userMobile,
payPrice: obj.payPrice,
hourType:
ProductHourType.values.fromCode(obj.hourType) ?? ProductHourType.NOON,
enable: true,
createTime: DateTime.now(),
);
}
}