Files
water-management-system/mobile-app/lib/features/patrol/models/patrol_task_model.dart
T

60 lines
1.7 KiB
Dart
Raw Normal View History

/// 巡检任务模型
class PatrolTaskModel {
final String id;
final String taskName;
final String taskCode;
final String routeName;
final String assignee;
final String status; // pending, in_progress, completed, overdue
final DateTime planDate;
final int checkpointTotal;
final int checkpointCompleted;
final String? remark;
PatrolTaskModel({
required this.id,
required this.taskName,
required this.taskCode,
required this.routeName,
required this.assignee,
required this.status,
required this.planDate,
required this.checkpointTotal,
required this.checkpointCompleted,
this.remark,
});
double get progress =>
checkpointTotal > 0 ? checkpointCompleted / checkpointTotal : 0;
factory PatrolTaskModel.fromJson(Map<String, dynamic> json) {
return PatrolTaskModel(
id: json['id']?.toString() ?? '',
taskName: json['taskName'] ?? '',
taskCode: json['taskCode'] ?? '',
routeName: json['routeName'] ?? '',
assignee: json['assignee'] ?? '',
status: json['status'] ?? 'pending',
planDate: DateTime.tryParse(json['planDate'] ?? '') ?? DateTime.now(),
checkpointTotal: json['checkpointTotal'] ?? 0,
checkpointCompleted: json['checkpointCompleted'] ?? 0,
remark: json['remark'],
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'taskName': taskName,
'taskCode': taskCode,
'routeName': routeName,
'assignee': assignee,
'status': status,
'planDate': planDate.toIso8601String(),
'checkpointTotal': checkpointTotal,
'checkpointCompleted': checkpointCompleted,
'remark': remark,
};
}
}