This commit is contained in:
dzc committed 2026-09-01 17:36:37 +08:00
1 parent d3b818a660
commit 917e7b4e83
5 files changed
+73 -32

No files matched your search

+1 -1
View File
@@ -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为版本号(内部比较)
```
+7 -1
View File
@@ -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 秒空闲窗口。
+63 -28
View File
@@ -207,7 +207,9 @@ abstract class SyncProductTool {
}
}
/// 同步商品
/// 按终端业态执行常规商品同步。
///
/// 食堂常规同步保留今天起连续七天的缓存范围;MQTT 食堂变更必须改用 [syncTodayCanteenProduct]。
static Future<void> 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<AppControl>();
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<bool> 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<bool> _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<AppControl>();
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
// **************************************************************************
@@ -29,7 +29,7 @@ Future<void> _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<void>(
+1 -1
View File
@@ -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