From 917e7b4e83af7fb986f74683c2a91a3fc9ddfef1 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Tue, 1 Sep 2026 17:36:37 +0800 Subject: [PATCH] 111 --- README.md | 2 +- lib/common/utils/app/app_mq_tool.dart | 8 +- lib/common/utils/sync/sync_product_tool.dart | 91 +++++++++++++------ .../setting/widgets/setting_baseInfo.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 73 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 92d0908..618dafa 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ flutter pub run build_runner build --delete-conflicting-outputs~ ## flutter打包 ``` -flutter build apk --build-name 1.4.4 --build-number 144 +flutter build apk --build-name 1.4.5 --build-number 145 --build-name为版本号(展示) --build-number为版本号(内部比较) ``` diff --git a/lib/common/utils/app/app_mq_tool.dart b/lib/common/utils/app/app_mq_tool.dart index 86f55b0..bc83875 100644 --- a/lib/common/utils/app/app_mq_tool.dart +++ b/lib/common/utils/app/app_mq_tool.dart @@ -91,8 +91,14 @@ class AppMqTool { mqUpdateEventBus.fire(MqtActionEnum.CONFIG); break; case MqtActionEnum.CANTEEN_PRODUCT: + // 食堂变更需要让当前收银页及时刷新,但只查询收到消息时的当天,避免 MQTT 拉取未来一周菜谱。 + final success = await SyncProductTool.syncTodayCanteenProduct(); + if (success) { + mqUpdateEventBus.fire(MqtActionEnum.CANTEEN_PRODUCT); + } + break; case MqtActionEnum.SUPERMARKET_PRODUCT: - // 商品变更通知统一进入现有 productSync 队列,避免 MQTT 回调另起一次同步并打断收银操作。 + // 超市商品变更仍进入现有 productSync 队列,避免 MQTT 回调打断收银操作。 unawaited(SyncCheckTool.instance.trigger( ScheduledTaskType.productSync, // MQTT 只负责排队;catchUp 让 idleOnly 任务等待完整 60 秒空闲窗口。 diff --git a/lib/common/utils/sync/sync_product_tool.dart b/lib/common/utils/sync/sync_product_tool.dart index 15e27c1..272fb6b 100644 --- a/lib/common/utils/sync/sync_product_tool.dart +++ b/lib/common/utils/sync/sync_product_tool.dart @@ -207,7 +207,9 @@ abstract class SyncProductTool { } } - /// 同步商品 + /// 按终端业态执行常规商品同步。 + /// + /// 食堂常规同步保留今天起连续七天的缓存范围;MQTT 食堂变更必须改用 [syncTodayCanteenProduct]。 static Future syncProduct() async { final sysSetting = await AppSettingTool.getSysSetting(); final sysType = sysSetting.sysType; @@ -217,34 +219,11 @@ abstract class SyncProductTool { final DateTime now = DateTime.now(); for (int i = 0; i < 7; i++) { final DateTime date = now.add(Duration(days: i)); - final String day = DateUtil.formatDate( - date, - format: DateFormats.y_mo_d, + final success = await _syncCanteenProductForDay( + date: date, + merchantId: sysSetting.serviceMerchantId, ); - final dayDatetime = DateUtil.getDateTime(day); - final pa = { - "day": day, - "hourType": null, - "categoryId": null, - "merchantId": sysSetting.serviceMerchantId, - }; - final canteenList = await ProductApi.canteenProduct(pa); - if (canteenList == null) return; - if (ObjectUtil.isEmptyList(canteenList)) { - // 空数组只代表当天没有可售菜品,不能清空其他日期已经同步的商品。 - final app = Get.find(); - await app.dataBase.getCanteenSpuDao.replaceByDay( - day, - const [], - const [], - ); - continue; - } - for (var v in canteenList) { - v.saleDate = dayDatetime; - } - // 更新数据 - await _batchUpdateCaneenProduct(list: canteenList, dayStr: day); + if (!success) return; } } else if (sysType == SysType.SUPERMARKET) { // 超市 @@ -294,6 +273,62 @@ abstract class SyncProductTool { } } + /// 仅同步终端本地时区的当天食堂菜品,并在成功后记录食堂商品同步时间。 + /// + /// MQTT 菜品变更使用此入口,确保请求和本地替换都不会扩展到未来一周。 + static Future syncTodayCanteenProduct() async { + final today = DateTime.now(); + final sysSetting = await AppSettingTool.getSysSetting(); + if (sysSetting.sysType != SysType.CANTEEN) return false; + try { + final success = await _syncCanteenProductForDay( + date: today, + merchantId: sysSetting.serviceMerchantId, + ); + if (!success) return false; + sysSetting.canteenProductSyncTime = DateTime.now(); + await AppSettingTool.setSysSetting(sysSetting); + return true; + } catch (e, stack) { + logger.e("|$_tag|同步当天食堂商品信息意外的错误error:|$e|,stack:|$stack|"); + return false; + } + } + + /// 请求并原子替换指定自然日的食堂菜品快照。 + /// + /// 返回 `false` 表示接口没有有效响应,本地当天旧快照会保留;空数组属于有效响应,会清空当天快照。 + static Future _syncCanteenProductForDay({ + required DateTime date, + required String? merchantId, + }) async { + final day = DateUtil.formatDate(date, format: DateFormats.y_mo_d); + final dayDatetime = DateUtil.getDateTime(day); + final canteenList = await ProductApi.canteenProduct({ + "day": day, + "hourType": null, + "categoryId": null, + "merchantId": merchantId, + }); + if (canteenList == null) return false; + if (ObjectUtil.isEmptyList(canteenList)) { + // 空数组只代表指定日期没有可售菜品,不能清空其他日期已经同步的商品。 + final app = Get.find(); + await app.dataBase.getCanteenSpuDao.replaceByDay( + day, + const [], + const [], + ); + return true; + } + for (final product in canteenList) { + // 接口按 day 查询,统一覆盖供应日期可防止异常响应把其他日期写进当天同步结果。 + product.saleDate = dayDatetime; + } + await _batchUpdateCaneenProduct(list: canteenList, dayStr: day); + return true; + } + // ************************************************************************** // 同步食堂商品 spu start // ************************************************************************** diff --git a/lib/pages/terminal/setting/widgets/setting_baseInfo.dart b/lib/pages/terminal/setting/widgets/setting_baseInfo.dart index 6de98ac..f3e171f 100644 --- a/lib/pages/terminal/setting/widgets/setting_baseInfo.dart +++ b/lib/pages/terminal/setting/widgets/setting_baseInfo.dart @@ -29,7 +29,7 @@ Future _bindServiceDialog(BuildContext context, SysSetting sys) async { final theme = FTheme.of(context); var text = sys.serviceId ?? ""; if (AppSysTool.isDev()) { - text = "2081591297864437761"; + text = "2094277933165223938"; } final uniqueCodeController = TextEditingController(text: text); await showAppDialog( diff --git a/pubspec.yaml b/pubspec.yaml index f7ebb25..713e268 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: pj_supermarket_cloud description: "资安信智慧后勤-测试" publish_to: "none" -version: 1.4.4+144 +version: 1.4.5+145 environment: sdk: ^3.6.0