|
@@ -0,0 +1,88 @@
|
|
|
+import 'package:fis_jsonrpc/services/remedical.m.dart';
|
|
|
+import 'package:fis_measure/interfaces/process/items/item_metas.dart';
|
|
|
+import 'package:vid/us/vid_us_unit.dart';
|
|
|
+
|
|
|
+class ItemMetaConverter {
|
|
|
+ ItemMetaConverter(this.dto);
|
|
|
+
|
|
|
+ final ItemMetaDTO dto;
|
|
|
+
|
|
|
+ late String _measureType = dto.measureTypeName!;
|
|
|
+
|
|
|
+ late final List<ItemOutputMeta> _outputs;
|
|
|
+ late final List<ItemMeta> _childItems = [];
|
|
|
+
|
|
|
+ /// 输出测量项元
|
|
|
+ ItemMeta output() {
|
|
|
+ if (dto.multiMethodItems != null && dto.multiMethodItems!.isNotEmpty) {
|
|
|
+ _loadMulti();
|
|
|
+ } else if (dto.methodChildItems != null &&
|
|
|
+ dto.methodChildItems!.isNotEmpty) {
|
|
|
+ _loadCombo();
|
|
|
+ } else {
|
|
|
+ _loadSimple();
|
|
|
+ }
|
|
|
+ _outputs = _convetOutputsFromCalc(dto.calculator!);
|
|
|
+
|
|
|
+ final meta = ItemMeta(
|
|
|
+ dto.name!,
|
|
|
+ measureType: _measureType,
|
|
|
+ description: dto.description!,
|
|
|
+ briefAnnotation: dto.briefAnnotation ?? '',
|
|
|
+ outputs: _outputs,
|
|
|
+ childItems: _childItems,
|
|
|
+ );
|
|
|
+
|
|
|
+ return meta;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 简单测量
|
|
|
+ void _loadSimple() {
|
|
|
+ //
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 组合测量
|
|
|
+ void _loadCombo() {
|
|
|
+ for (var child in dto.methodChildItems!) {
|
|
|
+ _childItems.add(_convertChildItem(child));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 多测量方法
|
|
|
+ void _loadMulti() {
|
|
|
+ final workingItem = dto.multiMethodItems!.firstWhere((e) => e.isWorking);
|
|
|
+ _measureType = workingItem.measureTypeName!;
|
|
|
+
|
|
|
+ if (workingItem.childItems != null && workingItem.childItems!.isNotEmpty) {
|
|
|
+ for (var child in workingItem.childItems!) {
|
|
|
+ _childItems.add(_convertChildItem(child));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static ItemMeta _convertChildItem(ChildItemMetaDTO c) {
|
|
|
+ return ItemMeta(
|
|
|
+ c.name!,
|
|
|
+ measureType: c.measureTypeName!,
|
|
|
+ description: c.description!,
|
|
|
+ outputs: _convetOutputsFromCalc(c.calculator!),
|
|
|
+ childItems: [],
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ static List<ItemOutputMeta> _convetOutputsFromCalc(
|
|
|
+ CalculatorMetaDTO calcDto) {
|
|
|
+ return calcDto.availableOutputs!
|
|
|
+ .where((e) => e.isWorking == true)
|
|
|
+ .map((e) => _convetOutputFromDto(e))
|
|
|
+ .toList();
|
|
|
+ }
|
|
|
+
|
|
|
+ static ItemOutputMeta _convetOutputFromDto(OutputItemMetaDTO o) {
|
|
|
+ return ItemOutputMeta(
|
|
|
+ o.name!,
|
|
|
+ o.description!,
|
|
|
+ VidUsUnitMap.getUnit(o.unit),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|