71 lines
2.0 KiB
Dart
71 lines
2.0 KiB
Dart
class AppUsage {
|
|
final int? id;
|
|
final String packageName;
|
|
final String appName;
|
|
final DateTime startTime;
|
|
final DateTime endTime;
|
|
final int duration; // 秒
|
|
final String category;
|
|
final int? projectId;
|
|
final int deviceUnlockCount;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
|
|
AppUsage({
|
|
this.id,
|
|
required this.packageName,
|
|
required this.appName,
|
|
required this.startTime,
|
|
required this.endTime,
|
|
required this.duration,
|
|
required this.category,
|
|
this.projectId,
|
|
this.deviceUnlockCount = 0,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'package_name': packageName,
|
|
'app_name': appName,
|
|
'start_time': startTime.millisecondsSinceEpoch ~/ 1000,
|
|
'end_time': endTime.millisecondsSinceEpoch ~/ 1000,
|
|
'duration': duration,
|
|
'category': category,
|
|
'project_id': projectId,
|
|
'device_unlock_count': deviceUnlockCount,
|
|
'created_at': createdAt.millisecondsSinceEpoch ~/ 1000,
|
|
'updated_at': updatedAt.millisecondsSinceEpoch ~/ 1000,
|
|
};
|
|
}
|
|
|
|
factory AppUsage.fromMap(Map<String, dynamic> map) {
|
|
return AppUsage(
|
|
id: map['id'],
|
|
packageName: map['package_name'],
|
|
appName: map['app_name'],
|
|
startTime: DateTime.fromMillisecondsSinceEpoch(map['start_time'] * 1000),
|
|
endTime: DateTime.fromMillisecondsSinceEpoch(map['end_time'] * 1000),
|
|
duration: map['duration'],
|
|
category: map['category'],
|
|
projectId: map['project_id'],
|
|
deviceUnlockCount: map['device_unlock_count'] ?? 0,
|
|
createdAt: DateTime.fromMillisecondsSinceEpoch(map['created_at'] * 1000),
|
|
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updated_at'] * 1000),
|
|
);
|
|
}
|
|
|
|
// 格式化时长
|
|
String get formattedDuration {
|
|
final hours = duration ~/ 3600;
|
|
final minutes = (duration % 3600) ~/ 60;
|
|
if (hours > 0) {
|
|
return '${hours}h ${minutes}m';
|
|
}
|
|
return '${minutes}m';
|
|
}
|
|
}
|
|
|