diff --git a/lib/common/api/hard_api.dart b/lib/common/api/hard_api.dart index d7c9e79..6bd93d1 100644 --- a/lib/common/api/hard_api.dart +++ b/lib/common/api/hard_api.dart @@ -135,9 +135,11 @@ abstract class HardApi { static Future broadcastToday( dynamic formData, ) async { - final res = await HttpManage() - .dio - .get("/hard/hard-broadcast/ad/today", queryParameters: formData); + final res = await HttpManage().dio.get( + "/hard/hard-broadcast/ad/today", + queryParameters: formData, + data: {"hardId": formData["hardId"]}, + ); if (res.data == null) return null; return ServiceBroadcastTodayPage.fromJson(res.data); } diff --git a/lib/common/models/mq/mq_models.dart b/lib/common/models/mq/mq_models.dart index 03e8c4e..ed79f9c 100644 --- a/lib/common/models/mq/mq_models.dart +++ b/lib/common/models/mq/mq_models.dart @@ -79,6 +79,9 @@ class MqttTakeFoodBroadcastMsg { /// 广播id String id; + /// 订单id + String orderId; + /// 预定标题 String title; @@ -107,6 +110,7 @@ class MqttTakeFoodBroadcastMsg { required this.username, required this.userMobile, required this.id, + required this.orderId, required this.title, required this.content, required this.broadcastMaxCount, diff --git a/lib/common/models/mq/mq_models.g.dart b/lib/common/models/mq/mq_models.g.dart index f5c5174..276c35e 100644 --- a/lib/common/models/mq/mq_models.g.dart +++ b/lib/common/models/mq/mq_models.g.dart @@ -55,6 +55,7 @@ MqttTakeFoodBroadcastMsg _$MqttTakeFoodBroadcastMsgFromJson( username: json['username'] as String, userMobile: json['userMobile'] as String, id: json['id'] as String, + orderId: json['orderId'] as String, title: json['title'] as String, content: json['content'] as String, broadcastMaxCount: (json['broadcastMaxCount'] as num).toInt(), @@ -72,6 +73,7 @@ Map _$MqttTakeFoodBroadcastMsgToJson( 'username': instance.username, 'userMobile': instance.userMobile, 'id': instance.id, + 'orderId': instance.orderId, 'title': instance.title, 'content': instance.content, 'broadcastMaxCount': instance.broadcastMaxCount, diff --git a/lib/common/services/database/dao/broadcast_dao.dart b/lib/common/services/database/dao/broadcast_dao.dart index abd5c6d..35d58a4 100644 --- a/lib/common/services/database/dao/broadcast_dao.dart +++ b/lib/common/services/database/dao/broadcast_dao.dart @@ -56,10 +56,10 @@ abstract class BroadcastDao { @Query(""" DELETE FROM broadcast WHERE - isDone = 1 - AND (:serviceCode = '-1' OR serviceCode = :serviceCode) + isDone = 0 + AND (:serviceOrderCode = '-1' OR serviceOrderCode = :serviceOrderCode) """) - Future del(String serviceCode); + Future del(String serviceOrderCode); @update Future edit(BroadcastEntity entity); diff --git a/lib/common/services/database/database.g.dart b/lib/common/services/database/database.g.dart index 9d14e56..b02bbd2 100644 --- a/lib/common/services/database/database.g.dart +++ b/lib/common/services/database/database.g.dart @@ -118,7 +118,7 @@ class _$AppDatabase extends AppDatabase { }, onCreate: (database, version) async { await database.execute( - 'CREATE TABLE IF NOT EXISTS `broadcast` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `content` TEXT NOT NULL, `broadcastCount` INTEGER NOT NULL, `broadcastMaxCount` INTEGER NOT NULL, `isBroadcast` INTEGER NOT NULL, `isDone` INTEGER NOT NULL, `isDoneTime` TEXT, `serviceCode` TEXT NOT NULL, `userId` TEXT NOT NULL, `username` TEXT NOT NULL, `userMobile` TEXT NOT NULL, `productDesc` TEXT NOT NULL, `payPrice` INTEGER NOT NULL, `hourType` INTEGER, `enable` INTEGER NOT NULL, `createTime` TEXT NOT NULL)'); + 'CREATE TABLE IF NOT EXISTS `broadcast` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `content` TEXT NOT NULL, `broadcastCount` INTEGER NOT NULL, `broadcastMaxCount` INTEGER NOT NULL, `isBroadcast` INTEGER NOT NULL, `isDone` INTEGER NOT NULL, `isDoneTime` TEXT, `serviceCode` TEXT NOT NULL, `serviceOrderCode` TEXT NOT NULL, `userId` TEXT NOT NULL, `username` TEXT NOT NULL, `userMobile` TEXT NOT NULL, `productDesc` TEXT NOT NULL, `payPrice` INTEGER NOT NULL, `hourType` INTEGER, `enable` INTEGER NOT NULL, `createTime` TEXT NOT NULL)'); await database.execute( 'CREATE TABLE IF NOT EXISTS `order_record` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `uniqueCode` TEXT NOT NULL, `serviceUniqueCode` TEXT NOT NULL, `sysType` TEXT NOT NULL, `userCode` TEXT NOT NULL, `username` TEXT, `hourType` TEXT, `price` INTEGER NOT NULL, `extraPrice` INTEGER NOT NULL, `payPrice` INTEGER NOT NULL, `walletId` TEXT, `orderSourceTypeId` TEXT, `type` TEXT NOT NULL, `status` TEXT NOT NULL, `payType` TEXT NOT NULL, `productDesc` TEXT, `count` INTEGER NOT NULL, `weight` REAL NOT NULL, `payTime` TEXT, `createTime` TEXT NOT NULL)'); await database.execute( @@ -232,6 +232,7 @@ class _$BroadcastDao extends BroadcastDao { 'isDone': _boolConverter.encode(item.isDone), 'isDoneTime': _dateTimeEmptyConverter.encode(item.isDoneTime), 'serviceCode': item.serviceCode, + 'serviceOrderCode': item.serviceOrderCode, 'userId': item.userId, 'username': item.username, 'userMobile': item.userMobile, @@ -254,6 +255,7 @@ class _$BroadcastDao extends BroadcastDao { 'isDone': _boolConverter.encode(item.isDone), 'isDoneTime': _dateTimeEmptyConverter.encode(item.isDoneTime), 'serviceCode': item.serviceCode, + 'serviceOrderCode': item.serviceOrderCode, 'userId': item.userId, 'username': item.username, 'userMobile': item.userMobile, @@ -277,7 +279,7 @@ class _$BroadcastDao extends BroadcastDao { @override Future del(String serviceCode) async { await _queryAdapter.queryNoReturn( - 'DELETE FROM broadcast WHERE isDone = 1 AND (?1 = \'-1\' OR serviceCode = ?1)', + 'DELETE FROM broadcast WHERE isDone = 0 AND (?1 = \'-1\' OR serviceCode = ?1)', arguments: [serviceCode]); } @@ -285,7 +287,7 @@ class _$BroadcastDao extends BroadcastDao { Future> getAll(String hourType) async { return _queryAdapter.queryList( '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 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)), + mapper: (Map 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, serviceOrderCode: row['serviceOrderCode'] 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]); } @@ -297,7 +299,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 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)), + mapper: (Map 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, serviceOrderCode: row['serviceOrderCode'] 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]); } diff --git a/lib/common/services/database/entity/broadcast_entity.dart b/lib/common/services/database/entity/broadcast_entity.dart index 1c041c2..a3939a1 100644 --- a/lib/common/services/database/entity/broadcast_entity.dart +++ b/lib/common/services/database/entity/broadcast_entity.dart @@ -32,6 +32,9 @@ class BroadcastEntity { /// 服务单号 String serviceCode; + /// 服务订单号 + String serviceOrderCode; + /// 用户id String userId; @@ -65,6 +68,7 @@ class BroadcastEntity { required this.isDone, required this.createTime, required this.serviceCode, + required this.serviceOrderCode, required this.userId, required this.username, required this.userMobile, diff --git a/lib/common/services/database/entity/broadcast_entity.g.dart b/lib/common/services/database/entity/broadcast_entity.g.dart index c18ccbd..c8dc359 100644 --- a/lib/common/services/database/entity/broadcast_entity.g.dart +++ b/lib/common/services/database/entity/broadcast_entity.g.dart @@ -16,6 +16,7 @@ BroadcastEntity _$BroadcastEntityFromJson(Map json) => isDone: json['isDone'] as bool, createTime: DateTime.parse(json['createTime'] as String), serviceCode: json['serviceCode'] as String, + serviceOrderCode: json['serviceOrderCode'] as String, userId: json['userId'] as String, username: json['username'] as String, userMobile: json['userMobile'] as String, @@ -37,6 +38,7 @@ Map _$BroadcastEntityToJson(BroadcastEntity instance) => 'isDone': instance.isDone, 'isDoneTime': instance.isDoneTime?.toIso8601String(), 'serviceCode': instance.serviceCode, + 'serviceOrderCode': instance.serviceOrderCode, 'userId': instance.userId, 'username': instance.username, 'userMobile': instance.userMobile, diff --git a/lib/common/utils/sync/sync_take_food_broadcast_tool.dart b/lib/common/utils/sync/sync_take_food_broadcast_tool.dart index 27b6e93..027dea9 100644 --- a/lib/common/utils/sync/sync_take_food_broadcast_tool.dart +++ b/lib/common/utils/sync/sync_take_food_broadcast_tool.dart @@ -13,7 +13,7 @@ abstract class SyncTakeFoodBroadcastTool { final broadcastDao = appC.dataBase.getBroadcastDao; // 完成就删除掉 if (msg.isDone) { - await broadcastDao.del(msg.id); + await broadcastDao.del(msg.orderId); return; } final saveObj = BroadcastEntity( @@ -21,9 +21,10 @@ abstract class SyncTakeFoodBroadcastTool { broadcastCount: 0, broadcastMaxCount: msg.broadcastMaxCount, isBroadcast: true, - isDone: false, + isDone: msg.isDone, productDesc: msg.productDesc, serviceCode: msg.id, + serviceOrderCode: msg.orderId, userId: msg.userId, username: msg.username, userMobile: msg.userMobile, @@ -113,8 +114,13 @@ abstract class SyncTakeFoodBroadcastTool { static Future queryTodayBroadcast() async { // 检查有没有网络 if (!AppNetworkTool.isAutoNetwork()) return; + final sysSetting = await AppSettingTool.getSysSetting(); int currentPage = 1; - final pa = {"current": currentPage, "size": 100}; + final pa = { + "current": currentPage, + "size": 100, + "hardId": sysSetting.serviceId + }; while (true) { final isMore = await _queryTodayBroadcastGroup(pa); if (!isMore) break; @@ -163,6 +169,7 @@ abstract class SyncTakeFoodBroadcastTool { isDone: false, productDesc: obj.productDesc, serviceCode: obj.id, + serviceOrderCode: obj.bizId!, userId: obj.userId, username: obj.username, userMobile: obj.userMobile, diff --git a/lib/common/values/constants.dart b/lib/common/values/constants.dart index 3f0f278..bbbd4d5 100644 --- a/lib/common/values/constants.dart +++ b/lib/common/values/constants.dart @@ -12,7 +12,7 @@ class Constants { /// 服务 url // static const apiUrl = 'https://stgl.pj.gov.cn/api'; - static const apiUrl = 'http://192.168.101.123:9999'; + static const apiUrl = 'http://192.168.101.125:9999'; /// 静态资源 url static const ossUrl = apiUrl; diff --git a/lib/pages/canteen_reserve/controller.dart b/lib/pages/canteen_reserve/controller.dart index 4fd2f89..020f0dc 100644 --- a/lib/pages/canteen_reserve/controller.dart +++ b/lib/pages/canteen_reserve/controller.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:forui/forui.dart'; import 'package:get/get.dart'; @@ -9,6 +11,8 @@ class CanteenReserveController extends GetxController { final appC = Get.find(); + StreamSubscription? mqUpdateListen; + RxList reserveList = [].obs; Rx hourType = Rx(ProductHourType.MORNING); @@ -29,8 +33,10 @@ class CanteenReserveController extends GetxController { } @override - void onInit() { + void onInit() async { super.onInit(); + await syncAllBroadcast(isMessageDialog: false); + _listrenMq(); hourTypeC.addValueListener((v) async { final currentHourType = ProductHourType.values.fromCode( v.first, @@ -57,6 +63,8 @@ class CanteenReserveController extends GetxController { void onClose() { super.onClose(); hourTypeC.dispose(); + // mq + mqUpdateListen?.cancel(); } Future doPage({int? page}) async { @@ -70,7 +78,6 @@ class CanteenReserveController extends GetxController { Future _getReservePage() async { final appSetting = await AppSettingTool.getSysSetting(); final sysType = appSetting.sysType.name; - final broadcastDao = appC.dataBase.getBroadcastDao; /// 处理查询参数 @@ -78,7 +85,6 @@ class CanteenReserveController extends GetxController { if (sysType == SysType.SUPERMARKET.name) { hourTypeCode = "-1"; } - final list = await broadcastDao.findAllPage( hourTypeCode, pageSize.value, @@ -167,10 +173,12 @@ class CanteenReserveController extends GetxController { } /// 同步所有广播 - Future syncAllBroadcast() async { + Future syncAllBroadcast({bool isMessageDialog = true}) async { // 是否同步所有广播 - final isSure = await appMessageDialog(Get.context!, "是否同步所有广播"); - if (!isSure) return; + if (isMessageDialog) { + final isSure = await appMessageDialog(Get.context!, "是否同步所有广播"); + if (!isSure) return; + } EasyLoading.show( status: '同步中...', maskType: EasyLoadingMaskType.black, @@ -185,4 +193,12 @@ class CanteenReserveController extends GetxController { EasyLoading.dismiss(); } } + + _listrenMq() { + mqUpdateListen = + appC.mqUpdateEventBus.on().listen((event) async { + if (event != MqtActionEnum.TAKE_FOOD_BROADCAST) return; + await syncAllBroadcast(isMessageDialog: false); + }); + } }