设备 预约接口

This commit is contained in:
czz
2025-06-16 21:43:07 +08:00
parent f7b50ae609
commit 89d0bbcc00
29 changed files with 2134 additions and 1085 deletions

View File

@@ -1,13 +1,15 @@
import 'package:ef/ef.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:vbvs_app/common/color/ServiceConstant.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/common/util/requestWithLog.dart';
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
part 'people_info_controller.g.dart'; // 由json_serializable自动生成的部分
@JsonSerializable()
class PeopleInfoPojo {
class PeopleInfoModel {
String? name;
String sex = "";
String? height;
@@ -15,95 +17,71 @@ class PeopleInfoPojo {
DateTime? birthday;
String? phone;
String? contact;
List peopleList = [];
PeopleInfoModel();
PeopleInfoPojo();
// // 从JSON反序列化时的异常处理
factory PeopleInfoPojo.fromJson(Map<String, dynamic> json) {
factory PeopleInfoModel.fromJson(Map<String, dynamic> json) {
try {
return _$PeopleInfoPojoFromJson(json);
return _$PeopleInfoModelFromJson(json);
} catch (e) {
// 在实际应用中,应该有更细致的异常处理策略和错误日志
return PeopleInfoPojo(); // 或者返回一个带有错误信息的特定PeopleInfoModel实例
return PeopleInfoModel(); // 或者返回一个带有错误信息的特定PeopleInfoModel实例
}
}
// 序列化为JSON时的异常处理
Map<String, dynamic> toJson() => _$PeopleInfoPojoToJson(this);
Map<String, dynamic> toJson() => _$PeopleInfoModelToJson(this);
}
class PeopleInfoController extends GetControllerEx<PeopleInfoPojo> {
class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
PeopleInfoController() {
attr = GetModel(PeopleInfoPojo()).obs;
attr = GetModel(PeopleInfoModel()).obs;
}
GlobalController get glcontroller => Get.find<GlobalController>();
@override
Future<void> initData(String mac) async {
await getPeoples(mac); // 控制器创建时立即执行
}
// getPeoples() async {
// var arr = [];
// String bindMacA =
// glcontroller.getUpperCaseMac(glcontroller.model.deviceMain["bindMacA"]);
// String bindMacB =
// glcontroller.getUpperCaseMac(glcontroller.model.deviceMain["bindMacB"]);
// arr.add(bindMacA);
// if (bindMacB.length > 6) {
// arr.add(bindMacB);
// } else {
// model.peopleList[1] = PeopleInfoPojo();
// }
// model.peopleList[0] = PeopleInfoPojo();
// print("getuser $arr");
// var data = await ef.from("app_personnel").select().inFilter("mac", arr);
// print("getuser $data");
// data?.forEach((d) {
// PeopleInfoPojo peopleInfoPojo = PeopleInfoPojo();
// peopleInfoPojo.name = d["name"];
// peopleInfoPojo.sex = d["gender"] == 1 ? "男" : "女";
// peopleInfoPojo.height = d["height"] == null ? null : "${d["height"]}";
// peopleInfoPojo.weight = d["weight"] == null ? null : "${d["weight"]}";
// if (d["birthday"] != null) {
// peopleInfoPojo.birthday = DateTime.parse(d["birthday"]).toLocal();
// }
// peopleInfoPojo.tel = d["tel"];
// peopleInfoPojo.emergencyContact = d["contact"];
// if (glcontroller.getUpperCaseMac(d['mac']) == bindMacA) {
// model.peopleList[0] = peopleInfoPojo;
// }
// if (glcontroller.getUpperCaseMac(d['mac']) == bindMacB) {
// model.peopleList[1] = peopleInfoPojo;
// }
// });
// updateAll();
// attr.value.updateAll();
// }
getPeoples(String mac) async {
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.server_service;
String serviceApi = ServiceConstant.person_info;
String queryUrl = "$serviceAddress$serviceName$serviceApi?mac=$mac";
// savePeoples() async {
// String bindMacA =
// glcontroller.getUpperCaseMac(glcontroller.model.deviceMain["bindMacA"]);
// String bindMacB =
// glcontroller.getUpperCaseMac(glcontroller.model.deviceMain["bindMacB"]);
// List<Future> arr = [];
// for (var i = 0; i < 2; i++) {
// if (i == 1 && bindMacB.length < 6) {
// break;
// }
// arr.add(ef.from("app_personnel").update({
// "name": model.peopleList[i].name,
// "gender": model.peopleList[i].sex == "男" ? 1 : 0,
// "height": int.tryParse("${model.peopleList[i].height}"),
// "weight": int.tryParse("${model.peopleList[i].weight}"),
// "birthday": model.peopleList[i].birthday == null
// ? null
// : model.peopleList[i].birthday.toString(),
// "tel": model.peopleList[i].tel,
// "contact": model.peopleList[i].emergencyContact
// }).eq("mac", i == 0 ? bindMacA : bindMacB));
// }
// return Future.wait(arr);
// }
requestWithLog(
logTitle: "获取设备的人员信息列表",
method: MyHttpMethod.get,
queryUrl: queryUrl,
onSuccess: (res) {
if (res.data != null && res.data is List) {
model.peopleList = res.data;
updateAll();
print("peopleList: ${model.peopleList}");
}
},
onFailure: (err) {
print("获取人员信息失败: $err");
},
);
}
// Future saveOnePeople(mac, data) async {
// return ef.from("app_personnel").update(data).eq("mac", mac);
// }
savePeoples(Map<String, dynamic> data) async {
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.server_service;
String serviceApi = ServiceConstant.person_info;
String queryUrl = "$serviceAddress$serviceName$serviceApi";
requestWithLog(
logTitle: "更新人员信息",
method: MyHttpMethod.put,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
print("更新人员信息成功: $res");
},
onFailure: (err) {
print("更新人员信息失败: $err");
},
);
}
}