import 'package:ef/ef.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:vbvs_app/controller/main_bottom/global_controller.dart'; part 'people_info_controller.g.dart'; // 由json_serializable自动生成的部分 class PeopleInfoModel { List peopleList = [PeopleInfoPojo(), PeopleInfoPojo()]; } @JsonSerializable() class PeopleInfoPojo { String? name; String sex = "男"; String? height; String? weight; DateTime? birthday; String? tel; String? emergencyContact; PeopleInfoPojo(); // // 从JSON反序列化时的异常处理 factory PeopleInfoPojo.fromJson(Map json) { try { return _$PeopleInfoPojoFromJson(json); } catch (e) { // 在实际应用中,应该有更细致的异常处理策略和错误日志 return PeopleInfoPojo(); // 或者返回一个带有错误信息的特定PeopleInfoModel实例 } } // 序列化为JSON时的异常处理 Map toJson() => _$PeopleInfoPojoToJson(this); } class PeopleInfoController extends GetControllerEx { PeopleInfoController() { attr = GetModel(PeopleInfoModel()).obs; } GlobalController get glcontroller => Get.find(); // 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(); // } // savePeoples() async { // String bindMacA = // glcontroller.getUpperCaseMac(glcontroller.model.deviceMain["bindMacA"]); // String bindMacB = // glcontroller.getUpperCaseMac(glcontroller.model.deviceMain["bindMacB"]); // List 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); // } // Future saveOnePeople(mac, data) async { // return ef.from("app_personnel").update(data).eq("mac", mac); // } }