feat:广播

This commit is contained in:
dzc committed 2025-05-12 14:18:15 +08:00
1 parent 5ce8e595b0
commit 903299cd6c
10 files changed
+59 -20

No files matched your search

+5 -3
View File
@@ -135,9 +135,11 @@ abstract class HardApi {
static Future<ServiceBroadcastTodayPage?> 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);
}
+4
View File
@@ -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,
+2
View File
@@ -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<String, dynamic> _$MqttTakeFoodBroadcastMsgToJson(
'username': instance.username,
'userMobile': instance.userMobile,
'id': instance.id,
'orderId': instance.orderId,
'title': instance.title,
'content': instance.content,
'broadcastMaxCount': instance.broadcastMaxCount,
@@ -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<void> del(String serviceCode);
Future<void> del(String serviceOrderCode);
@update
Future<void> edit(BroadcastEntity entity);
+6 -4
View File
@@ -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<void> 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<List<BroadcastEntity>> 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<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)),
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, 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<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)),
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, 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]);
}
@@ -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,
@@ -16,6 +16,7 @@ BroadcastEntity _$BroadcastEntityFromJson(Map<String, dynamic> 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<String, dynamic> _$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,
@@ -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<void> 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,
+1 -1
View File
@@ -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;
+22 -6
View File
@@ -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<AppControl>();
StreamSubscription? mqUpdateListen;
RxList<BroadcastEntity> reserveList = <BroadcastEntity>[].obs;
Rx<ProductHourType> 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<void> doPage({int? page}) async {
@@ -70,7 +78,6 @@ class CanteenReserveController extends GetxController {
Future<void> _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<void> syncAllBroadcast() async {
Future<void> 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<MqtActionEnum>().listen((event) async {
if (event != MqtActionEnum.TAKE_FOOD_BROADCAST) return;
await syncAllBroadcast(isMessageDialog: false);
});
}
}