123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- 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 = [];
- late final List<ItemMeta> _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<ItemMeta> _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<ItemOutputMeta> _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),
- );
- }
- }
|