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 _outputs; late final List _childItems = []; late final List _multiMethodItems = []; int? _rimWidth; /// 输出测量项元 ItemMeta output() { if (dto.multiMethodItems != null && dto.multiMethodItems!.isNotEmpty) { _loadMulti(); } else if (dto.methodChildItems != null && dto.methodChildItems!.isNotEmpty) { _loadCombo(); _outputs = _convetOutputsFromCalc(dto.calculator!); } else { _loadSimple(); _outputs = _convetOutputsFromCalc(dto.calculator!); } final meta = ItemMeta( dto.name!, measureType: _measureType, description: dto.description!, briefAnnotation: dto.briefAnnotation ?? '', outputs: _outputs, childItems: _childItems, multiMethodItems: _multiMethodItems, /// 【TODO】 暂时屏蔽 buyStatus // buyStatus: dto.status, rimWidth: _rimWidth, ); return meta; } /// 简单测量 void _loadSimple() { // } /// 组合测量 void _loadCombo() { for (var child in dto.methodChildItems!) { _childItems.add(_convertChildItem(child)); } } /// 多测量方法 void _loadMultiMethodItems() { for (var child in dto.multiMethodItems!) { _multiMethodItems.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)); } } if (workingItem.rimWidth != null) { _rimWidth = workingItem.rimWidth; } _loadMultiMethodItems(); _outputs = _convetOutputsFromCalc(workingItem.calculator!); } static ItemMeta _convertChildItem(ChildItemMetaDTO c) { List _kids = []; if (c.childItems != null && c.childItems!.isNotEmpty) { for (var child in c.childItems!) { // if (child.isWorking) { _kids.add(_convertChildItem(child)); // } } } return ItemMeta( c.name!, measureType: c.measureTypeName!, description: c.description ?? c.name!, outputs: _convetOutputsFromCalc(c.calculator!), childItems: _kids, ); } static List _convetOutputsFromCalc( CalculatorMetaDTO calcDto) { final outputs = calcDto.availableOutputs! .where((e) => e.isWorking == true) .map((e) => _convetOutputFromDto(e)) .toList(); if (outputs.isEmpty) { //TODO: wait remove // return [_convetOutputFromDto(calcDto.availableOutputs!.first)]; return []; } return outputs; } static ItemOutputMeta _convetOutputFromDto(OutputItemMetaDTO o) { return ItemOutputMeta( o.name!, o.description!, VidUsUnitMap.getUnit(o.unit), ); } }