修复bug-可回退
This commit is contained in:
@@ -84,8 +84,20 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
if (responseData['total'] == 0) {
|
||||
return [];
|
||||
} else {
|
||||
final rows = responseData['rows'];
|
||||
debugPrint('🔧 [DeviceAPI] 原始 rows 数量: ${rows.length}');
|
||||
if (rows.isNotEmpty) {
|
||||
debugPrint('🔧 [DeviceAPI] 第一个元素类型: ${rows.first.runtimeType}');
|
||||
debugPrint('🔧 [DeviceAPI] 第一个元素内容: ${rows.first}');
|
||||
if (rows.first is Map) {
|
||||
debugPrint('🔧 [DeviceAPI] 第一个元素的 keys: ${rows.first.keys}');
|
||||
rows.first.forEach((k, v) {
|
||||
debugPrint('🔧 [DeviceAPI] $k: ${v.runtimeType} = $v');
|
||||
});
|
||||
}
|
||||
}
|
||||
List<DeviceEntity> devices = [];
|
||||
for (var item in responseData['rows']) {
|
||||
for (var item in rows) {
|
||||
devices.add(DeviceEntity.fromJson(item));
|
||||
}
|
||||
return devices;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:maibu_satabot_v2/core/data/base_model.dart';
|
||||
import 'package:maibu_satabot_v2/core/utils/json_safe.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
|
||||
class DeviceModel extends DeviceEntity implements BaseModel {
|
||||
@@ -17,16 +18,16 @@ class DeviceModel extends DeviceEntity implements BaseModel {
|
||||
|
||||
factory DeviceModel.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceModel(
|
||||
deviceName: json['deviceName'],
|
||||
productId: json['productId'],
|
||||
productName: json['productName'],
|
||||
tenantId: json['tenantId'],
|
||||
tenantName: json['tenantName'],
|
||||
status: json['status'],
|
||||
activeTime: json['activeTime'],
|
||||
deviceAlias: json['deviceAlias'],
|
||||
isBind: json['isBind'],
|
||||
onlineStatus: json['onlineStatus'],
|
||||
deviceName: JsonSafe.asString(json['deviceName']),
|
||||
productId: JsonSafe.asInt(json['productId'], -1),
|
||||
productName: JsonSafe.asString(json['productName'], "割草机产品MC700"),
|
||||
tenantId: JsonSafe.asInt(json['tenantId']),
|
||||
tenantName: JsonSafe.asString(json['tenantName']),
|
||||
status: JsonSafe.asInt(json['status']),
|
||||
activeTime: JsonSafe.asStringOrNull(json['activeTime']),
|
||||
deviceAlias: JsonSafe.asStringOrNull(json['deviceAlias']),
|
||||
isBind: JsonSafe.asInt(json['isBind']),
|
||||
onlineStatus: JsonSafe.asInt(json['onlineStatus']),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../../core/utils/json_safe.dart';
|
||||
|
||||
class DeviceEntity extends Equatable {
|
||||
final String deviceName;
|
||||
@@ -25,26 +26,24 @@ class DeviceEntity extends Equatable {
|
||||
this.onlineStatus = 0,
|
||||
});
|
||||
|
||||
// 方便从后端 JSON 转换
|
||||
factory DeviceEntity.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceEntity(
|
||||
deviceName: json['deviceName'],
|
||||
productId: json['productId'] ?? -1,
|
||||
productName: json['productName'] ?? "割草机产品MC700",
|
||||
tenantId: json['tenantId'],
|
||||
tenantName: json['tenantName'],
|
||||
status: json['status'] ?? 0,
|
||||
activeTime: json['activeTime'],
|
||||
deviceAlias: json['deviceAlias'],
|
||||
isBind: json['isBind'] ?? 0,
|
||||
onlineStatus: json['onlineStatus'] ?? 0,
|
||||
deviceName: JsonSafe.asString(json['deviceName']),
|
||||
productId: JsonSafe.asInt(json['productId'], -1),
|
||||
productName: JsonSafe.asString(json['productName'], "割草机产品MC700"),
|
||||
tenantId: JsonSafe.asInt(json['tenantId']),
|
||||
tenantName: JsonSafe.asString(json['tenantName']),
|
||||
status: JsonSafe.asInt(json['status']),
|
||||
activeTime: JsonSafe.asStringOrNull(json['activeTime']),
|
||||
deviceAlias: JsonSafe.asStringOrNull(json['deviceAlias']),
|
||||
isBind: JsonSafe.asInt(json['isBind']),
|
||||
onlineStatus: JsonSafe.asInt(json['onlineStatus']),
|
||||
);
|
||||
}
|
||||
|
||||
// 获取显示的名称(优先别名,没有则用设备名)
|
||||
String get displayName => (deviceAlias != null && deviceAlias!.isNotEmpty)
|
||||
? deviceAlias!
|
||||
: (deviceName ?? "未知设备");
|
||||
: (deviceName.isNotEmpty ? deviceName : "未知设备");
|
||||
|
||||
// 辅助方法:判断是否在线
|
||||
bool get isOnline => onlineStatus == 1;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../../core/utils/json_safe.dart';
|
||||
|
||||
class DeviceRunStatisticsEntity extends Equatable {
|
||||
final String startTime; // 开始时间
|
||||
final String endTime; // 结束时间
|
||||
final double workArea; // 工作面积
|
||||
final double? distance; // 工作距离(可为空)
|
||||
final int time; // 花费时间
|
||||
final String startTime;
|
||||
final String endTime;
|
||||
final double workArea;
|
||||
final double? distance;
|
||||
final int time;
|
||||
|
||||
const DeviceRunStatisticsEntity({
|
||||
required this.startTime,
|
||||
@@ -17,11 +18,11 @@ class DeviceRunStatisticsEntity extends Equatable {
|
||||
|
||||
factory DeviceRunStatisticsEntity.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceRunStatisticsEntity(
|
||||
startTime: json['startTime'] as String,
|
||||
endTime: json['endTime'] as String,
|
||||
workArea: (json['workArea'] as num).toDouble(),
|
||||
distance: json['distance'] != null ? (json['distance'] as num).toDouble() : null,
|
||||
time: json['time'] as int,
|
||||
startTime: JsonSafe.asString(json['startTime']),
|
||||
endTime: JsonSafe.asString(json['endTime']),
|
||||
workArea: JsonSafe.asDouble(json['workArea']),
|
||||
distance: json['distance'] != null ? JsonSafe.asDouble(json['distance']) : null,
|
||||
time: JsonSafe.asInt(json['time']),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user