智慧水务管理系统 - 精河县供水工程综合管理平台

patrol_task_model.dart 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /// 巡检任务模型
  2. class PatrolTaskModel {
  3. final String id;
  4. final String taskName;
  5. final String taskCode;
  6. final String routeName;
  7. final String assignee;
  8. final String status; // pending, in_progress, completed, overdue
  9. final DateTime planDate;
  10. final int checkpointTotal;
  11. final int checkpointCompleted;
  12. final String? remark;
  13. PatrolTaskModel({
  14. required this.id,
  15. required this.taskName,
  16. required this.taskCode,
  17. required this.routeName,
  18. required this.assignee,
  19. required this.status,
  20. required this.planDate,
  21. required this.checkpointTotal,
  22. required this.checkpointCompleted,
  23. this.remark,
  24. });
  25. double get progress =>
  26. checkpointTotal > 0 ? checkpointCompleted / checkpointTotal : 0;
  27. factory PatrolTaskModel.fromJson(Map<String, dynamic> json) {
  28. return PatrolTaskModel(
  29. id: json['id']?.toString() ?? '',
  30. taskName: json['taskName'] ?? '',
  31. taskCode: json['taskCode'] ?? '',
  32. routeName: json['routeName'] ?? '',
  33. assignee: json['assignee'] ?? '',
  34. status: json['status'] ?? 'pending',
  35. planDate: DateTime.tryParse(json['planDate'] ?? '') ?? DateTime.now(),
  36. checkpointTotal: json['checkpointTotal'] ?? 0,
  37. checkpointCompleted: json['checkpointCompleted'] ?? 0,
  38. remark: json['remark'],
  39. );
  40. }
  41. Map<String, dynamic> toJson() {
  42. return {
  43. 'id': id,
  44. 'taskName': taskName,
  45. 'taskCode': taskCode,
  46. 'routeName': routeName,
  47. 'assignee': assignee,
  48. 'status': status,
  49. 'planDate': planDate.toIso8601String(),
  50. 'checkpointTotal': checkpointTotal,
  51. 'checkpointCompleted': checkpointCompleted,
  52. 'remark': remark,
  53. };
  54. }
  55. }