更新快检功能
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/controller/setting/language/language_controller.dart';
|
||||
import 'package:vbvs_app/enum/APPPackageType.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
@@ -42,7 +43,13 @@ class DeviceTypeController extends GetControllerEx<DeviceTypeModel> {
|
||||
attr = GetModel(DeviceTypeModel()).obs;
|
||||
}
|
||||
RxList deviceTypeList = [].obs;
|
||||
RxList cqHistoryList = [].obs;
|
||||
RxMap currentCq = {}.obs;
|
||||
LanguageController languageController = Get.find();
|
||||
// 404:未找到快检信息 200:快检进行中 201:快检完成 202:快检超时 203:已取消 500:计算错误
|
||||
RxInt experience_status = 404.obs;
|
||||
RxInt experience_percent = 0.obs; //体验进度
|
||||
RxString experience_id = "".obs; //体验id
|
||||
|
||||
Future<ApiResponse> getDeviceType() async {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "请求失败".tr);
|
||||
@@ -51,7 +58,7 @@ class DeviceTypeController extends GetControllerEx<DeviceTypeModel> {
|
||||
String serviceApi = ServiceConstant.device_type;
|
||||
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
String? language = "";
|
||||
String? language = "";
|
||||
if (AppConstants().ent_type == APPPackageType.MHT.code) {
|
||||
if (mhLanguageController.selectLanguage != null) {
|
||||
language = mhLanguageController.selectLanguage.value!.language_code;
|
||||
@@ -90,4 +97,177 @@ class DeviceTypeController extends GetControllerEx<DeviceTypeModel> {
|
||||
return apiResponse;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> checkReportStatus(String mac) async {
|
||||
String serviceAddress = ServiceConstant.qc_service_address;
|
||||
String serviceApi = ServiceConstant.checkQuickStatus;
|
||||
String queryUrl = "$serviceAddress$serviceApi?mac=${mac}";
|
||||
bool flag = false;
|
||||
await requestWithLog(
|
||||
logTitle: "查询快检状态",
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) {
|
||||
flag = res.data['status'] != 200;
|
||||
experience_status.value = res.data['status'];
|
||||
experience_percent.value = res.data['per'] ?? 0;
|
||||
experience_id.value = res.data['id'] ?? "";
|
||||
updateAll();
|
||||
},
|
||||
onFailure: (res) {
|
||||
flag = false;
|
||||
},
|
||||
);
|
||||
return flag;
|
||||
}
|
||||
|
||||
Future<bool> getCheckHistory({String? id}) async {
|
||||
String serviceAddress = ServiceConstant.qc_service_address;
|
||||
String serviceApi = ServiceConstant.getCheckHistory;
|
||||
String queryUrl = "$serviceAddress$serviceApi";
|
||||
|
||||
// 如果id不为空,拼接到url上
|
||||
if (id != null && id.isNotEmpty) {
|
||||
queryUrl = "$queryUrl?id=$id";
|
||||
}
|
||||
|
||||
bool flag = false;
|
||||
await requestWithLog(
|
||||
logTitle: "查询快检历史",
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) {
|
||||
flag = true;
|
||||
// 判断返回数据类型
|
||||
if (res.data is List) {
|
||||
// 如果是列表,赋值给cqHistoryList
|
||||
cqHistoryList.value = (res.data as List).cast<Map<String, dynamic>>();
|
||||
} else if (res.data is Map) {
|
||||
// 如果是Map,赋值给currentCq
|
||||
currentCq.value = res.data as Map<String, dynamic>;
|
||||
}
|
||||
updateAll();
|
||||
},
|
||||
onFailure: (res) {
|
||||
flag = false;
|
||||
currentCq.value = {};
|
||||
},
|
||||
);
|
||||
return flag;
|
||||
}
|
||||
|
||||
//快检状态控制 type 1:开始快检2:停止快检
|
||||
qcCheckControl(Map device, int type) async {
|
||||
String serviceAddress = ServiceConstant.qc_service_address;
|
||||
String serviceApi = ServiceConstant.qcControl;
|
||||
String queryUrl = "$serviceAddress$serviceApi";
|
||||
|
||||
// 从device中获取person信息,如果person存在则使用,否则使用默认值
|
||||
Map<String, dynamic> personData = {};
|
||||
if (device['person'] != null && device['person'] is Map) {
|
||||
// 处理name:null或空字符串时使用默认值
|
||||
String name = device['person']['name'];
|
||||
if (name == null || name.trim().isEmpty) {
|
||||
name = "体征检测设备".tr;
|
||||
}
|
||||
|
||||
// 处理gender:null或空字符串时使用默认值"男"
|
||||
String gender = "男"; // 默认值
|
||||
if (device['person']['gender'] != null) {
|
||||
var genderValue = device['person']['gender'];
|
||||
if (genderValue is int) {
|
||||
gender = genderValue == 1 ? "男" : "女";
|
||||
} else if (genderValue is String && genderValue.isNotEmpty) {
|
||||
gender = genderValue == "1" ? "男" : "女";
|
||||
}
|
||||
}
|
||||
|
||||
// 处理birthday:null或空字符串时使用默认年龄52
|
||||
int age = 52; // 默认年龄
|
||||
String? birthday = device['person']['birthday'];
|
||||
if (birthday != null && birthday.trim().isNotEmpty) {
|
||||
age = _calculateAge(birthday);
|
||||
}
|
||||
|
||||
// 处理weight:null或空字符串时使用默认值
|
||||
dynamic weightValue = device['person']['weight'];
|
||||
double weight = 37.5; // 默认值
|
||||
if (weightValue != null) {
|
||||
if (weightValue is num) {
|
||||
weight = weightValue.toDouble();
|
||||
} else if (weightValue is String && weightValue.trim().isNotEmpty) {
|
||||
weight = double.tryParse(weightValue) ?? 37.5;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理height:null或空字符串时使用默认值
|
||||
dynamic heightValue = device['person']['height'];
|
||||
double height = 165.0; // 默认值
|
||||
if (heightValue != null) {
|
||||
if (heightValue is num) {
|
||||
height = heightValue.toDouble();
|
||||
} else if (heightValue is String && heightValue.trim().isNotEmpty) {
|
||||
height = double.tryParse(heightValue) ?? 165.0;
|
||||
}
|
||||
}
|
||||
|
||||
personData = {
|
||||
"name": name,
|
||||
"gender": gender,
|
||||
"age": age,
|
||||
"weight": weight,
|
||||
"height": height
|
||||
};
|
||||
} else {
|
||||
// person为空时的默认值
|
||||
personData = {
|
||||
"name": "姓名",
|
||||
"gender": "男",
|
||||
"age": 52,
|
||||
"weight": 37.5,
|
||||
"height": 165
|
||||
};
|
||||
}
|
||||
|
||||
// 构建请求参数
|
||||
Map<String, dynamic> data = {
|
||||
"person": personData,
|
||||
"mac": device['mac'], // 使用device中的mac
|
||||
"type": type
|
||||
};
|
||||
|
||||
bool flag = false;
|
||||
await requestWithLog(
|
||||
logTitle: "更新快检状态",
|
||||
method: MyHttpMethod.post,
|
||||
queryUrl: queryUrl,
|
||||
data: data,
|
||||
onSuccess: (res) {
|
||||
flag = true;
|
||||
},
|
||||
onFailure: (res) {
|
||||
flag = false;
|
||||
},
|
||||
);
|
||||
return flag;
|
||||
}
|
||||
|
||||
// 添加一个辅助方法来根据生日计算年龄
|
||||
int _calculateAge(String birthday) {
|
||||
if (birthday.isEmpty) return 52;
|
||||
|
||||
try {
|
||||
// 假设生日格式为 "2017/03/06"
|
||||
List<String> parts = birthday.split('/');
|
||||
if (parts.length == 3) {
|
||||
int birthYear = int.parse(parts[0]);
|
||||
int currentYear = DateTime.now().year;
|
||||
return currentYear - birthYear;
|
||||
}
|
||||
} catch (e) {
|
||||
print("计算年龄出错: $e");
|
||||
}
|
||||
|
||||
return 52; // 出错时返回默认年龄
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user