item_metas.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:vid/us/vid_us_unit.dart';
  3. /// 测量项配置元信息
  4. class ItemMeta {
  5. /// 名称
  6. String name;
  7. /// 描述
  8. String description;
  9. /// 简介注释
  10. String briefAnnotation;
  11. /// 测量类型
  12. String measureType;
  13. /// 计算输出元信息
  14. List<ItemOutputMeta> outputs;
  15. /// 子项元信息集合
  16. List<ItemMeta> childItems;
  17. /// 当前测量项的购买状态
  18. /// 0: Free 免费
  19. /// 1: Probation 试用中
  20. /// 2: Unpaid 未购买
  21. /// 3: Purchased 已购买
  22. WorkingItemStatusEnum? buyStatus;
  23. ItemMeta(
  24. this.name, {
  25. required this.measureType,
  26. required this.description,
  27. required this.outputs,
  28. this.buyStatus,
  29. this.briefAnnotation = '',
  30. this.childItems = const [],
  31. });
  32. /// 根据名称获取子项
  33. ItemMeta? getChildByName(String name) {
  34. final matchList = childItems.where((e) => e.name == name);
  35. if (matchList.isNotEmpty) {
  36. return matchList.first;
  37. }
  38. return null;
  39. }
  40. /// 根据类型获取子项
  41. ItemMeta? getChildByType(String type) {
  42. final matchList = childItems.where((e) => e.measureType == type);
  43. if (matchList.isNotEmpty) {
  44. return matchList.first;
  45. }
  46. return null;
  47. }
  48. }
  49. class ItemOutputMeta {
  50. /// 名称
  51. String name;
  52. /// 描述
  53. String description;
  54. /// 单位
  55. VidUsUnit unit;
  56. /// 简介注释
  57. String? briefAnnotation;
  58. /// 额外注释
  59. String? additionalAnnotation;
  60. /// 小数精度
  61. int fractionalDigits;
  62. ItemOutputMeta(
  63. this.name,
  64. this.description,
  65. this.unit, {
  66. this.briefAnnotation,
  67. this.additionalAnnotation,
  68. this.fractionalDigits = 2,
  69. });
  70. ItemOutputMeta copyWith({
  71. String? name,
  72. String? description,
  73. VidUsUnit? unit,
  74. String? briefAnnotation,
  75. String? additionalAnnotation,
  76. int? fractionalDigits,
  77. }) {
  78. final meta = ItemOutputMeta(
  79. name ?? this.name,
  80. description ?? this.description,
  81. unit ?? this.unit,
  82. additionalAnnotation: additionalAnnotation ?? this.additionalAnnotation,
  83. fractionalDigits: fractionalDigits ?? this.fractionalDigits,
  84. );
  85. return meta;
  86. }
  87. }