已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
This commit is contained in:
78
apps/user_app/lib/domain/models/usage_statistics.dart
Normal file
78
apps/user_app/lib/domain/models/usage_statistics.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
// 功能描述:定义用气统计的服务端事实模型;版本:1.0.0。
|
||||
|
||||
class UsagePoint {
|
||||
const UsagePoint({required this.date, required this.usage});
|
||||
final DateTime date;
|
||||
final double usage;
|
||||
|
||||
factory UsagePoint.fromJson(Map<String, Object?> json) => UsagePoint(
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
usage: (json['usage'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
class UsageComposition {
|
||||
const UsageComposition({required this.breakfast, required this.lunch, required this.dinner});
|
||||
final double breakfast, lunch, dinner;
|
||||
|
||||
factory UsageComposition.fromJson(Map<String, Object?> json) => UsageComposition(
|
||||
breakfast: (json['breakfast'] as num? ?? 0).toDouble(),
|
||||
lunch: (json['lunch'] as num? ?? 0).toDouble(),
|
||||
dinner: (json['dinner'] as num? ?? 0).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
class UsageStatistics {
|
||||
const UsageStatistics({
|
||||
required this.available,
|
||||
required this.deviceIdentity,
|
||||
required this.deviceName,
|
||||
required this.deviceCode,
|
||||
required this.period,
|
||||
required this.periodStart,
|
||||
required this.periodEnd,
|
||||
required this.unit,
|
||||
required this.points,
|
||||
required this.totalUsage,
|
||||
required this.averageUsage,
|
||||
required this.composition,
|
||||
required this.source,
|
||||
required this.calcVersion,
|
||||
required this.updatedAt,
|
||||
required this.unavailableReason,
|
||||
});
|
||||
|
||||
final bool available;
|
||||
final String deviceIdentity, deviceName, deviceCode, period, unit;
|
||||
final DateTime periodStart, periodEnd;
|
||||
final List<UsagePoint> points;
|
||||
final double totalUsage, averageUsage;
|
||||
final UsageComposition composition;
|
||||
final String source, calcVersion, unavailableReason;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
factory UsageStatistics.fromJson(Map<String, Object?> json) {
|
||||
final device = json['device'] as Map<String, Object?>? ?? const {};
|
||||
final composition = json['composition'] as Map<String, Object?>? ?? const {};
|
||||
return UsageStatistics(
|
||||
available: json['available'] == true,
|
||||
deviceIdentity: device['identity'] as String? ?? '',
|
||||
deviceName: device['name'] as String? ?? '',
|
||||
deviceCode: device['code'] as String? ?? '',
|
||||
period: json['period'] as String? ?? 'month',
|
||||
periodStart: DateTime.parse(json['period_start'] as String),
|
||||
periodEnd: DateTime.parse(json['period_end'] as String),
|
||||
unit: json['unit'] as String? ?? 'kg',
|
||||
points: (json['points'] as List<Object?>? ?? const [])
|
||||
.map((item) => UsagePoint.fromJson(item as Map<String, Object?>))
|
||||
.toList(),
|
||||
totalUsage: (json['total_usage'] as num? ?? 0).toDouble(),
|
||||
averageUsage: (json['average_usage'] as num? ?? 0).toDouble(),
|
||||
composition: UsageComposition.fromJson(composition),
|
||||
source: json['source'] as String? ?? '',
|
||||
calcVersion: json['calc_version'] as String? ?? '',
|
||||
updatedAt: DateTime.tryParse(json['updated_at']?.toString() ?? '')?.toLocal(),
|
||||
unavailableReason: json['unavailable_reason'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user