90 lines
2.9 KiB
Dart
90 lines
2.9 KiB
Dart
import 'package:ef/ef.dart';
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
|
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
|
|
|
part 'common_message_setting_controller.g.dart'; // 由json_serializable自动生成的部分
|
|
|
|
@JsonSerializable()
|
|
class CommonMessageSettingModel {
|
|
int? setting = 0; //总设置 0 关闭 1 开启
|
|
int? appSetting = 0; //app消息设置
|
|
int? serviceSetting = 0; //服务号消息
|
|
int? tipSetting = 0; //设备放置说明
|
|
int? deviceUpgradeSetting = 0; //设备升级提示
|
|
int? deviceIssueSetting = 0; //设备故障提示
|
|
int? sleepReportSetting = 0; //睡眠报告通知
|
|
|
|
CommonMessageSettingModel();
|
|
|
|
// 从JSON反序列化时的异常处理
|
|
|
|
factory CommonMessageSettingModel.fromJson(Map<String, dynamic> json) {
|
|
try {
|
|
return _$CommonMessageSettingModelFromJson(json);
|
|
} catch (e) {
|
|
// 在实际应用中,应该有更细致的异常处理策略和错误日志
|
|
return CommonMessageSettingModel(); // 或者返回一个带有错误信息的特定DeviceInfoModel实例
|
|
}
|
|
}
|
|
|
|
// 序列化为JSON时的异常处理
|
|
Map<String, dynamic> toJson() => _$CommonMessageSettingModelToJson(this);
|
|
}
|
|
|
|
class CommonMessageSettingController
|
|
extends GetControllerEx<CommonMessageSettingModel> {
|
|
CommonMessageSettingController() {
|
|
attr = GetModel(CommonMessageSettingModel()).obs;
|
|
}
|
|
|
|
Future<void> getAppSleepNotify() async {
|
|
String serviceAddress = ServiceConstant.service_address;
|
|
String serviceName = ServiceConstant.server_service;
|
|
String serviceApi = ServiceConstant.user_setting;
|
|
String type = "sleep_report_notify";
|
|
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type";
|
|
await requestWithLog(
|
|
logTitle: "查询用户睡眠通知消息配置",
|
|
method: MyHttpMethod.get,
|
|
queryUrl: queryUrl,
|
|
onSuccess: (res) {
|
|
if (res.data == null) {
|
|
model.sleepReportSetting = 1;
|
|
} else {
|
|
model.sleepReportSetting = res.data["setting"];
|
|
}
|
|
updateAll();
|
|
},
|
|
onFailure: (res) {
|
|
print(res);
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> updateSleepNotify(bool val) async {
|
|
String serviceAddress = ServiceConstant.service_address;
|
|
String serviceName = ServiceConstant.server_service;
|
|
String serviceApi = ServiceConstant.user_setting;
|
|
String type = "sleep_report_notify";
|
|
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type";
|
|
var data = {
|
|
"type": type,
|
|
"setting": val == true ? 1 : 0,
|
|
"time": DateTime.now().millisecondsSinceEpoch,
|
|
};
|
|
await requestWithLog(
|
|
logTitle: "查询用户睡眠通知消息配置",
|
|
method: MyHttpMethod.put,
|
|
queryUrl: queryUrl,
|
|
data: data,
|
|
onSuccess: (res) {
|
|
updateAll();
|
|
},
|
|
onFailure: (res) {
|
|
print(res);
|
|
},
|
|
);
|
|
}
|
|
}
|