item_meta_convert.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import 'package:fis_jsonrpc/services/remedical.m.dart';
  2. import 'package:fis_measure/interfaces/process/items/item_metas.dart';
  3. import 'package:vid/us/vid_us_unit.dart';
  4. class ItemMetaConverter {
  5. ItemMetaConverter(this.dto);
  6. final ItemMetaDTO dto;
  7. late String _measureType = dto.measureTypeName!;
  8. late final List<ItemOutputMeta> _outputs;
  9. late final List<ItemMeta> _childItems = [];
  10. late final List<ItemMeta> _multiMethodItems = [];
  11. int? _rimWidth;
  12. /// 输出测量项元
  13. ItemMeta output() {
  14. if (dto.multiMethodItems != null && dto.multiMethodItems!.isNotEmpty) {
  15. _loadMulti();
  16. } else if (dto.methodChildItems != null &&
  17. dto.methodChildItems!.isNotEmpty) {
  18. _loadCombo();
  19. _outputs = _convetOutputsFromCalc(dto.calculator!);
  20. } else {
  21. _loadSimple();
  22. _outputs = _convetOutputsFromCalc(dto.calculator!);
  23. }
  24. final meta = ItemMeta(
  25. dto.name!,
  26. measureType: _measureType,
  27. description: dto.description!,
  28. briefAnnotation: dto.briefAnnotation ?? '',
  29. outputs: _outputs,
  30. childItems: _childItems,
  31. multiMethodItems: _multiMethodItems,
  32. /// 【TODO】 暂时屏蔽 buyStatus
  33. // buyStatus: dto.status,
  34. rimWidth: _rimWidth,
  35. );
  36. return meta;
  37. }
  38. /// 简单测量
  39. void _loadSimple() {
  40. //
  41. }
  42. /// 组合测量
  43. void _loadCombo() {
  44. for (var child in dto.methodChildItems!) {
  45. _childItems.add(_convertChildItem(child));
  46. }
  47. }
  48. /// 多测量方法
  49. void _loadMultiMethodItems() {
  50. for (var child in dto.multiMethodItems!) {
  51. _multiMethodItems.add(_convertChildItem(child));
  52. }
  53. }
  54. /// 多测量方法
  55. void _loadMulti() {
  56. final workingItem = dto.multiMethodItems!.firstWhere((e) => e.isWorking);
  57. _measureType = workingItem.measureTypeName!;
  58. if (workingItem.childItems != null && workingItem.childItems!.isNotEmpty) {
  59. for (var child in workingItem.childItems!) {
  60. _childItems.add(_convertChildItem(child));
  61. }
  62. }
  63. if (workingItem.rimWidth != null) {
  64. _rimWidth = workingItem.rimWidth;
  65. }
  66. _loadMultiMethodItems();
  67. _outputs = _convetOutputsFromCalc(workingItem.calculator!);
  68. }
  69. static ItemMeta _convertChildItem(ChildItemMetaDTO c) {
  70. List<ItemMeta> _kids = [];
  71. if (c.childItems != null && c.childItems!.isNotEmpty) {
  72. for (var child in c.childItems!) {
  73. // if (child.isWorking) {
  74. _kids.add(_convertChildItem(child));
  75. // }
  76. }
  77. }
  78. return ItemMeta(
  79. c.name!,
  80. measureType: c.measureTypeName!,
  81. description: c.description ?? c.name!,
  82. outputs: _convetOutputsFromCalc(c.calculator!),
  83. childItems: _kids,
  84. );
  85. }
  86. static List<ItemOutputMeta> _convetOutputsFromCalc(
  87. CalculatorMetaDTO calcDto) {
  88. final outputs = calcDto.availableOutputs!
  89. .where((e) => e.isWorking == true)
  90. .map((e) => _convetOutputFromDto(e))
  91. .toList();
  92. if (outputs.isEmpty) {
  93. //TODO: wait remove
  94. // return [_convetOutputFromDto(calcDto.availableOutputs!.first)];
  95. return [];
  96. }
  97. return outputs;
  98. }
  99. static ItemOutputMeta _convetOutputFromDto(OutputItemMetaDTO o) {
  100. return ItemOutputMeta(
  101. o.name!,
  102. o.description!,
  103. VidUsUnitMap.getUnit(o.unit),
  104. );
  105. }
  106. }