task_center.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'package:flyinsono/lab/mock_data/mock_rpc.dart';
  2. import 'package:flyinsono/managers/interfaces/entities/process_arg.dart';
  3. import 'package:flyinsono/managers/interfaces/entities/task_info.dart';
  4. import 'package:flyinsono/managers/interfaces/export_data.dart';
  5. import 'package:flyinsono/managers/interfaces/import_data.dart';
  6. import 'package:get/get.dart';
  7. import 'package:fis_common/event/event_type.dart';
  8. import 'package:fis_jsonrpc/rpc.dart';
  9. ///本地化任务中心
  10. TaskCenter get localTaskCenter => _taskCenterInstance;
  11. final _taskCenterInstance = _buildTaskCenterInstance();
  12. TaskCenter _buildTaskCenterInstance() {
  13. return TaskCenter();
  14. }
  15. class TaskCenter {
  16. final importDataManager = Get.find<IImportDataManager>();
  17. final exportDataManager = Get.find<IExportDataManager>();
  18. final processChange = FEventHandler<ExportProcessArg>();
  19. TaskCenter() {
  20. processChange.addListener((sender, e) {
  21. importDataManager.processChange.emit(sender, e);
  22. exportDataManager.processChange.emit(sender, e);
  23. });
  24. }
  25. ///获取本地的任务标题列表
  26. List<TaskBaseDTO> getTaskList() {
  27. List<TaskBaseDTO> result = [];
  28. TaskBaseDTO? importTaskModel = importDataManager.getCurrentTask();
  29. if (importTaskModel != null) {
  30. result.add(importTaskModel);
  31. }
  32. TaskBaseDTO? exportTaskModel = exportDataManager.getCurrentTask();
  33. if (exportTaskModel != null) {
  34. result.add(exportTaskModel);
  35. }
  36. var resultList = result
  37. .map(
  38. (e) => TaskBaseDTO(
  39. code: e.code,
  40. taskName: e.taskName,
  41. status: VTaskStatus.Processing,
  42. taskType: e.taskType,
  43. ),
  44. )
  45. .toList();
  46. resultList.sort((a, b) {
  47. // 比较两个TaskBaseDTO对象的createTime属性
  48. if (a.createTime == null && b.createTime == null) {
  49. return 0; // 都是null,视为相等
  50. } else if (a.createTime == null) {
  51. return 1; // null的排在后面
  52. } else if (b.createTime == null) {
  53. return -1; // null的排在后面
  54. } else {
  55. return b.createTime!.compareTo(a.createTime!); // 按照时间降序排列,最近的时间排在最前面
  56. }
  57. });
  58. for (var i in resultList) {
  59. print(i.taskName);
  60. }
  61. return resultList;
  62. }
  63. ///获取本地的任务详情列表
  64. List<TaskDetail> getLocalTasks(String currentSelectedTaskId) {
  65. if (currentSelectedTaskId == importDataManager.taskId) {
  66. return importDataManager.getLocalTasks(currentSelectedTaskId);
  67. } else if (currentSelectedTaskId == exportDataManager.taskId) {
  68. return exportDataManager.getLocalTasks(currentSelectedTaskId);
  69. } else {
  70. print(
  71. "target id:$currentSelectedTaskId,exportDataManager.taskId:${exportDataManager.taskId}");
  72. }
  73. return [];
  74. }
  75. void canCelTask(String currentSelectedTaskId) {
  76. if (currentSelectedTaskId == importDataManager.taskId) {
  77. importDataManager.cancelImport();
  78. } else if (currentSelectedTaskId == exportDataManager.taskId) {
  79. exportDataManager.cancelExport();
  80. }
  81. }
  82. TaskInfo? getTaskInfo(String currentSelectedTaskId) {
  83. if (currentSelectedTaskId == importDataManager.taskId) {
  84. return importDataManager.getTaskInfo(currentSelectedTaskId);
  85. } else if (currentSelectedTaskId == exportDataManager.taskId) {
  86. return exportDataManager.getTaskInfo(currentSelectedTaskId);
  87. }
  88. return null;
  89. }
  90. }