import 'package:fis_lib_report/report/element_tag.dart'; import 'package:fis_lib_report/report/element_type.dart'; import 'package:fis_lib_report/report/inputImageList.dart'; import 'package:fis_lib_report/report/interfaces/block_element.dart'; import 'package:fis_lib_report/report/interfaces/report_template_document.dart'; import 'package:fis_lib_report/report/paragraph.dart'; import 'package:fis_lib_report/report/rt_page_size.dart'; import 'package:fis_lib_report/report/rt_table.dart'; import 'package:fis_lib_report/report/rt_thickness.dart'; import 'package:uuid/uuid.dart'; class ReportTemplateDocument implements IReportTemplateDocument { Map> _customizeTranslation = {}; Set _customizeComments = {}; Set _customizeReportComments = {}; Set _customizeCalculations = {}; List _blocks = []; List _headers = []; List _footers = []; String? _fontName; Map> get customizeTranslation => _customizeTranslation; @override set customizeTranslation(Map>? v) { _customizeTranslation = v ?? {}; } Set get customizeComments => _customizeComments; @override set customizeReportComments(Set? v) { _customizeReportComments = v ?? {}; } Set get customizeReportComments => _customizeReportComments; @override set customizeComments(Set? v) { _customizeComments = v ?? {}; } Set get customizeCalculations => _customizeCalculations; @override set customizeCalculations(Set? v) { _customizeCalculations = v ?? {}; } /// Gets the author of the report template. @override String? author; @override double? baseFontSize; /// Gets all the report template blocks. @override List? blocks = []; /// get or set the distance between the footer and the bottom of the page @override double? footerDistance; /// Gets or sets the height of footer. @override double? footerHeight; /// get or set the distance between the header and the top of the page @override double? headerDistance; /// Gets or sets the height of header. @override double? headerHeight; @override bool? invertColor; /// Gets or sets the value to indicate whether the report template is created by user. @override bool? isCustom; /// Gets the report template name. @override String? name; /// Gets or sets the page padding. Default is 20mm. @override RTThickness? pagePadding; /// Gets or sets the page size. @override RTPageSize? pageSize; /// Gets the custom input element tags of the report template. @override Map? tags; /// Gets or sets the update time. @override DateTime? updateTime; ///version @override String? version; /// Gets the id. @override late String id; /// Gets the report template footer. @override List? footer = []; /// Gets the report template header. @override List? header = []; @override ReportTemplateDocument() { id = Uuid().v1(); pageSize = RTPageSize.a4; pagePadding = new RTThickness.uniform(56.83); headerHeight = null; footerHeight = null; baseFontSize = 9; headerDistance = 34; footerDistance = 34; } //TODO(Loki):目前仅能支持常规模板解析,其他模板需添加缺少的类 ReportTemplateDocument.fromJson(Map json) { try { isCustom = json['IsCustom']; id = json['Id']; final jsonData = json['UpdateTime']; updateTime = DateTime.parse(jsonData!).toLocal(); author = json['Author']; name = json['Name']; headerHeight = json['HeaderHeight']; footerHeight = json['FooterHeight']; headerDistance = json['HeaderDistance']; footerDistance = json['FooterDistance']; baseFontSize = json['BaseFontSize']; invertColor = json['InvertColor']; version = json['Version']; pagePadding = RTThickness.fromJson(json['PagePadding'] ?? {}); pageSize = RTPageSize.fromJson(json['PageSize'] ?? {}); Map jsonTags = json['Tags']; if (jsonTags.length > 0) { //TODO(Loki):tags convert } else { tags = {}; } Map jsonLanguages = json['CustomizeTranslation'] ?? {}; jsonLanguages.forEach((key, value) { if (value is Map) { if (value.isNotEmpty) { customizeTranslation[key] = value as Map; } else { customizeTranslation[key] = {}; } } else { customizeTranslation[key] = {}; } }); _initComments(json); _initBlocks(json); } catch (e) { print(e); } } void _initBlocks(Map json) { List jsonBlocks = json['Blocks']; if (jsonBlocks.isNotEmpty) { for (var block in jsonBlocks) { final type = block['ElementType']; final jsonType = ElementType.fromJson(type); final name = jsonType.name; if (name == ElementType.rtTable!.name) { final jsonBlock = RTTable.fromJson(block); blocks!.add(jsonBlock); } else if (name == ElementType.paragraph!.name) { final jsonBlock = Paragraph.fromJson(block); blocks!.add(jsonBlock); } else if (name == ElementType.imageList!.name) { final inputImageList = InputImageList.fromJson(block); blocks!.add(inputImageList); } } } List jsonHeads = json['Header']; if (jsonHeads.isNotEmpty) { //TODO(Loki): init headers } List jsonFooter = json['Footer']; if (jsonFooter.isNotEmpty) { for (var block in jsonFooter) { final type = block['ElementType']; final jsonType = ElementType.fromJson(type); final name = jsonType.name; if (name == ElementType.rtTable!.name) { final jsonBlock = RTTable.fromJson(block); footer!.add(jsonBlock); } else if (name == ElementType.paragraph!.name) { final paragraph = Paragraph.fromJson(block); footer!.add(paragraph); } } } } void _initComments(Map json) { List tempComments = []; List jsonCustomizeComments = json['CustomizeComments'] ?? []; for (var element in jsonCustomizeComments) { tempComments.add(element.toString()); } customizeComments = tempComments.toSet(); tempComments.clear(); List jsonReportComments = json['CustomizeReportComments'] ?? []; for (var element in jsonReportComments) { tempComments.add(element.toString()); } customizeReportComments = tempComments.toSet(); tempComments.clear(); List jsonCustomizeCalculations = json['CustomizeCalculations'] ?? []; for (var element in jsonCustomizeCalculations) { tempComments.add(element.toString()); } customizeCalculations = tempComments.toSet(); } }