|
|
|
@ -1,12 +1,10 @@
@@ -1,12 +1,10 @@
|
|
|
|
|
// memory_table_service.dart |
|
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
|
|
import 'package:win_text_editor/modules/memory_table/models/memory_table.dart'; |
|
|
|
|
import 'package:win_text_editor/shared/data/std_fields_cache.dart'; |
|
|
|
|
import 'package:win_text_editor/shared/models/std_filed.dart'; |
|
|
|
|
import 'package:win_text_editor/shared/uft_std_fields/field_data_service.dart'; |
|
|
|
|
import 'package:xml/xml.dart' as xml; |
|
|
|
|
import 'package:path/path.dart' as path; |
|
|
|
|
import 'package:win_text_editor/framework/controllers/logger.dart'; |
|
|
|
|
|
|
|
|
|
class CallFunctionService { |
|
|
|
@ -14,11 +12,22 @@ class CallFunctionService {
@@ -14,11 +12,22 @@ class CallFunctionService {
|
|
|
|
|
|
|
|
|
|
CallFunctionService(this._logger); |
|
|
|
|
|
|
|
|
|
Future<TableData> parseStructureFile(String filePath) async { |
|
|
|
|
static const Map<String, String> _functionRootTypeMap = { |
|
|
|
|
'uftfunction': 'business:Function', |
|
|
|
|
'uftservice': 'business:Service', |
|
|
|
|
'uftatomfunction': 'business:Function', |
|
|
|
|
'uftatomservice': 'business:Service', |
|
|
|
|
'uftfactorfunction': 'business:FactorFunction', |
|
|
|
|
'uftfactorservice': 'business:FactorService', |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Future<FunctionData> parseXmlFile(String filePath) async { |
|
|
|
|
try { |
|
|
|
|
// 1. Check file extension |
|
|
|
|
if (!filePath.toLowerCase().endsWith('.uftstructure')) { |
|
|
|
|
throw const FormatException("文件扩展名必须是.uftstructure"); |
|
|
|
|
final extendFileName = filePath.toLowerCase().split('.').last; |
|
|
|
|
final String? rootNodeType = _functionRootTypeMap[extendFileName]; |
|
|
|
|
if (rootNodeType == null) { |
|
|
|
|
throw const FormatException("文件扩展名不正确!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2. 查找 metadata 目录和 stdfield.stfield 文件 |
|
|
|
@ -35,27 +44,26 @@ class CallFunctionService {
@@ -35,27 +44,26 @@ class CallFunctionService {
|
|
|
|
|
final content = await file.readAsString(); |
|
|
|
|
|
|
|
|
|
final document = xml.XmlDocument.parse(content); |
|
|
|
|
final structureNode = document.findAllElements('structure:Structure').firstOrNull; |
|
|
|
|
final rootNode = document.findAllElements(rootNodeType).firstOrNull; |
|
|
|
|
|
|
|
|
|
if (structureNode == null) { |
|
|
|
|
throw const FormatException("文件格式错误:缺少structure:Structure节点"); |
|
|
|
|
if (rootNode == null) { |
|
|
|
|
throw const FormatException("文件格式错误:缺少支持的根节点"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 4. Get basic info |
|
|
|
|
final fileNameWithoutExt = path.basenameWithoutExtension(filePath); |
|
|
|
|
final chineseName = structureNode.getAttribute('chineseName') ?? ''; |
|
|
|
|
final objectId = structureNode.getAttribute('objectId') ?? ''; |
|
|
|
|
final chineseName = rootNode.getAttribute('chineseName') ?? ''; |
|
|
|
|
final objectId = rootNode.getAttribute('objectId') ?? ''; |
|
|
|
|
|
|
|
|
|
// 5. Process properties (fields) |
|
|
|
|
final properties = document.findAllElements('properties'); |
|
|
|
|
final fields = <Field>[]; |
|
|
|
|
// 5. Process inputParameters (fields) |
|
|
|
|
final inputParameters = document.findAllElements('inputParameters'); |
|
|
|
|
final inputFields = <Field>[]; |
|
|
|
|
int index = 1; |
|
|
|
|
|
|
|
|
|
for (final property in properties) { |
|
|
|
|
final id = property.getAttribute('id') ?? ''; |
|
|
|
|
for (final parameter in inputParameters) { |
|
|
|
|
final id = parameter.getAttribute('id') ?? ''; |
|
|
|
|
// 尝试从缓存获取标准字段信息 |
|
|
|
|
final stdField = StdFieldsCache.getData(id); |
|
|
|
|
fields.add( |
|
|
|
|
inputFields.add( |
|
|
|
|
Field( |
|
|
|
|
(index++).toString(), // 序号 |
|
|
|
|
id, // 名称 |
|
|
|
@ -65,41 +73,30 @@ class CallFunctionService {
@@ -65,41 +73,30 @@ class CallFunctionService {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 6. Process indexes |
|
|
|
|
final indexes = document.findAllElements('indexs'); |
|
|
|
|
final indexList = <Index>[]; |
|
|
|
|
|
|
|
|
|
for (final indexNode in indexes) { |
|
|
|
|
final name = indexNode.getAttribute('name') ?? ''; |
|
|
|
|
final containerType = indexNode.getAttribute('containerType'); |
|
|
|
|
final isPrimary = containerType == null; |
|
|
|
|
final rule = containerType ?? ''; |
|
|
|
|
|
|
|
|
|
// Get all index fields |
|
|
|
|
final items = indexNode.findAllElements('items'); |
|
|
|
|
final fieldsList = |
|
|
|
|
items |
|
|
|
|
.map((item) => item.getAttribute('attrname') ?? '') |
|
|
|
|
.where((f) => f.isNotEmpty) |
|
|
|
|
.toList(); |
|
|
|
|
final indexFields = fieldsList.join(','); |
|
|
|
|
|
|
|
|
|
indexList.add( |
|
|
|
|
Index( |
|
|
|
|
name, // 索引名称 |
|
|
|
|
isPrimary, // 是否主键 |
|
|
|
|
indexFields, // 索引字段 |
|
|
|
|
rule, // 规则 |
|
|
|
|
// 6. Process outputParameters |
|
|
|
|
final outputParameters = document.findAllElements('outputParameters'); |
|
|
|
|
final outputFields = <Field>[]; |
|
|
|
|
index = 1; |
|
|
|
|
|
|
|
|
|
for (final parameter in outputParameters) { |
|
|
|
|
final id = parameter.getAttribute('id') ?? ''; |
|
|
|
|
// 尝试从缓存获取标准字段信息 |
|
|
|
|
final stdField = StdFieldsCache.getData(id); |
|
|
|
|
outputFields.add( |
|
|
|
|
Field( |
|
|
|
|
(index++).toString(), // 序号 |
|
|
|
|
id, // 名称 |
|
|
|
|
stdField?.chineseName ?? '', // 中文名 |
|
|
|
|
stdField?.dateType ?? '', // 类型 |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return TableData( |
|
|
|
|
tableName: fileNameWithoutExt, |
|
|
|
|
return FunctionData( |
|
|
|
|
chineseName: chineseName, |
|
|
|
|
objectId: objectId, |
|
|
|
|
fields: fields.isNotEmpty ? fields : FieldDataService.getDefaultFields(), |
|
|
|
|
indexes: indexList.isNotEmpty ? indexList : FieldDataService.getDefaultIndexes(), |
|
|
|
|
inputFields: inputFields.isNotEmpty ? inputFields : FieldDataService.getDefaultFields(), |
|
|
|
|
outputFields: outputFields.isNotEmpty ? outputFields : FieldDataService.getDefaultFields(), |
|
|
|
|
); |
|
|
|
|
} on xml.XmlParserException catch (e) { |
|
|
|
|
_logger.error("XML解析错误: ${e.message}"); |
|
|
|
@ -111,18 +108,16 @@ class CallFunctionService {
@@ -111,18 +108,16 @@ class CallFunctionService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class TableData { |
|
|
|
|
final String tableName; |
|
|
|
|
class FunctionData { |
|
|
|
|
final String chineseName; |
|
|
|
|
final String objectId; |
|
|
|
|
final List<Field> fields; |
|
|
|
|
final List<Index> indexes; |
|
|
|
|
final List<Field> inputFields; |
|
|
|
|
final List<Field> outputFields; |
|
|
|
|
|
|
|
|
|
TableData({ |
|
|
|
|
required this.tableName, |
|
|
|
|
FunctionData({ |
|
|
|
|
required this.chineseName, |
|
|
|
|
required this.objectId, |
|
|
|
|
required this.fields, |
|
|
|
|
required this.indexes, |
|
|
|
|
required this.inputFields, |
|
|
|
|
required this.outputFields, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|