完成元数据更新功能
This commit is contained in:
parent
8ecf44db1a
commit
273da28390
|
|
@ -20,10 +20,17 @@ SOURCES += main.cpp \
|
||||||
src/metadataupdate/uf2interface.cpp \
|
src/metadataupdate/uf2interface.cpp \
|
||||||
src/metadataupdate/uft3interface.cpp \
|
src/metadataupdate/uft3interface.cpp \
|
||||||
src/metadataupdate/metadataprocessor.cpp \
|
src/metadataupdate/metadataprocessor.cpp \
|
||||||
|
src/metadataupdate/uf2datatype.cpp \
|
||||||
|
src/metadataupdate/uf2stdfields.cpp \
|
||||||
|
src/metadataupdate/uf2errnumber.cpp \
|
||||||
|
src/metadataupdate/uft3datatype.cpp \
|
||||||
|
src/metadataupdate/uft3stdfields.cpp \
|
||||||
|
src/metadataupdate/uft3table.cpp \
|
||||||
src/utils/datacache.cpp \
|
src/utils/datacache.cpp \
|
||||||
src/utils/uf2configreader.cpp \
|
src/utils/uf2configreader.cpp \
|
||||||
src/utils/uft3configreader.cpp \
|
src/utils/uft3configreader.cpp \
|
||||||
src/utils/logmanager.cpp
|
src/utils/logmanager.cpp \
|
||||||
|
src/utils/configmanager.cpp
|
||||||
|
|
||||||
HEADERS += src/mainwindow/mainwindow.h \
|
HEADERS += src/mainwindow/mainwindow.h \
|
||||||
src/pythonrunner/PythonRunner.h \
|
src/pythonrunner/PythonRunner.h \
|
||||||
|
|
@ -39,10 +46,17 @@ HEADERS += src/mainwindow/mainwindow.h \
|
||||||
src/metadataupdate/uf2interface.h \
|
src/metadataupdate/uf2interface.h \
|
||||||
src/metadataupdate/uft3interface.h \
|
src/metadataupdate/uft3interface.h \
|
||||||
src/metadataupdate/metadataprocessor.h \
|
src/metadataupdate/metadataprocessor.h \
|
||||||
|
src/metadataupdate/uf2datatype.h \
|
||||||
|
src/metadataupdate/uf2stdfields.h \
|
||||||
|
src/metadataupdate/uf2errnumber.h \
|
||||||
|
src/metadataupdate/uft3datatype.h \
|
||||||
|
src/metadataupdate/uft3stdfields.h \
|
||||||
|
src/metadataupdate/uft3table.h \
|
||||||
src/utils/datacache.h \
|
src/utils/datacache.h \
|
||||||
src/utils/uf2configreader.h \
|
src/utils/uf2configreader.h \
|
||||||
src/utils/uft3configreader.h \
|
src/utils/uft3configreader.h \
|
||||||
src/utils/logmanager.h
|
src/utils/logmanager.h \
|
||||||
|
src/utils/configmanager.h
|
||||||
|
|
||||||
RESOURCES += resources.qrc
|
RESOURCES += resources.qrc
|
||||||
|
|
||||||
|
|
|
||||||
6
main.cpp
6
main.cpp
|
|
@ -1,13 +1,19 @@
|
||||||
#include "src/mainwindow/mainwindow.h"
|
#include "src/mainwindow/mainwindow.h"
|
||||||
#include "ElaApplication.h"
|
#include "ElaApplication.h"
|
||||||
|
#include "src/utils/configmanager.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
a.setWindowIcon(QIcon(":resources/images/ChangeCode.png"));
|
a.setWindowIcon(QIcon(":resources/images/ChangeCode.png"));
|
||||||
eApp->init();
|
eApp->init();
|
||||||
|
|
||||||
|
QString basePath = QCoreApplication::applicationDirPath();
|
||||||
|
ConfigManager::instance()->loadConfig(basePath);
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.showMaximized();
|
w.showMaximized();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
#include "uf2interface.h"
|
|
||||||
#include "uft3interface.h"
|
|
||||||
#include "filedb.h"
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QCommandLineParser>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
QJsonObject interfaceInfoToJson(const InterfaceInfo& info)
|
|
||||||
{
|
|
||||||
QJsonObject obj;
|
|
||||||
obj["cname"] = info.cname;
|
|
||||||
obj["eName"] = info.eName;
|
|
||||||
obj["functionNo"] = info.functionNo;
|
|
||||||
obj["flag"] = info.flag;
|
|
||||||
obj["path"] = info.path;
|
|
||||||
obj["code"] = info.code;
|
|
||||||
obj["id"] = info.id;
|
|
||||||
obj["sysStatus"] = info.sysStatus;
|
|
||||||
obj["description"] = info.description;
|
|
||||||
obj["moudle"] = info.moudle;
|
|
||||||
obj["moudleEName"] = info.moudleEName;
|
|
||||||
obj["serverType"] = info.serverType;
|
|
||||||
obj["returnResultSet"] = info.returnResultSet;
|
|
||||||
obj["needTransMonitor"] = info.needTransMonitor;
|
|
||||||
obj["checkLicence"] = info.checkLicence;
|
|
||||||
|
|
||||||
QJsonObject inputFields;
|
|
||||||
for (const QString& key : info.inputFields.keys()) {
|
|
||||||
QJsonObject field;
|
|
||||||
field["name"] = info.inputFields[key].name;
|
|
||||||
field["flag"] = info.inputFields[key].flag;
|
|
||||||
field["desc"] = info.inputFields[key].desc;
|
|
||||||
field["uuid"] = info.inputFields[key].uuid;
|
|
||||||
inputFields[key] = field;
|
|
||||||
}
|
|
||||||
obj["inputFields"] = inputFields;
|
|
||||||
|
|
||||||
QJsonObject outputFields;
|
|
||||||
for (const QString& key : info.outputFields.keys()) {
|
|
||||||
QJsonObject field;
|
|
||||||
field["name"] = info.outputFields[key].name;
|
|
||||||
field["flag"] = info.outputFields[key].flag;
|
|
||||||
field["desc"] = info
|
|
||||||
|
|
@ -2,7 +2,14 @@
|
||||||
#include "uf2interface.h"
|
#include "uf2interface.h"
|
||||||
#include "uft3interface.h"
|
#include "uft3interface.h"
|
||||||
#include "filedb.h"
|
#include "filedb.h"
|
||||||
|
#include "uf2stdfields.h"
|
||||||
|
#include "uf2datatype.h"
|
||||||
|
#include "uf2errnumber.h"
|
||||||
|
#include "uft3stdfields.h"
|
||||||
|
#include "uft3datatype.h"
|
||||||
|
#include "uft3table.h"
|
||||||
#include "utils/logmanager.h"
|
#include "utils/logmanager.h"
|
||||||
|
#include "utils/configmanager.h"
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
@ -12,61 +19,43 @@ MetadataProcessor::MetadataProcessor(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MetadataProcessor::initConfig(const QString& basePath)
|
||||||
|
{
|
||||||
|
m_basePath = basePath;
|
||||||
|
m_uf2touft3Path = QDir(basePath).filePath("uf2touft3");
|
||||||
|
|
||||||
|
LogManager::instance()->log("========== 初始化配置 ==========");
|
||||||
|
|
||||||
|
ConfigManager* configManager = ConfigManager::instance();
|
||||||
|
|
||||||
|
m_uf20Path = configManager->getValue("projectPath", "uf20");
|
||||||
|
m_ufAcct20Path = configManager->getValue("projectPath", "ufAcct20");
|
||||||
|
m_uftDbSettPath = configManager->getValue("projectPath", "UftdbSett");
|
||||||
|
m_uft30PubPath = configManager->getValue("projectPath", "uft30pub");
|
||||||
|
m_uft30CbptransPath = configManager->getValue("projectPath", "uft30cbptrans");
|
||||||
|
m_uft30Path = configManager->getValue("projectPath", "uft30");
|
||||||
|
|
||||||
|
m_supportUftdbSett = configManager->getValue("testConfig", "supportUftdbSett");
|
||||||
|
m_moduleGenerationCheck = configManager->getValue("testConfig", "moduleGenerationCheck");
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("UF2TOUFT3路径: %1").arg(m_uf2touft3Path));
|
||||||
|
LogManager::instance()->log(QString("UF20路径: %1").arg(m_uf20Path));
|
||||||
|
LogManager::instance()->log(QString("UF20会计路径: %1").arg(m_ufAcct20Path));
|
||||||
|
LogManager::instance()->log(QString("UFT数据库设置路径: %1").arg(m_uftDbSettPath));
|
||||||
|
LogManager::instance()->log(QString("UFT30公共路径: %1").arg(m_uft30PubPath));
|
||||||
|
LogManager::instance()->log(QString("UFT30交易路径: %1").arg(m_uft30CbptransPath));
|
||||||
|
LogManager::instance()->log(QString("UFT30路径: %1").arg(m_uft30Path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool MetadataProcessor::isValidUtf8(const QByteArray& data)
|
bool MetadataProcessor::isValidUtf8(const QByteArray& data)
|
||||||
{
|
{
|
||||||
QString test = QString::fromUtf8(data);
|
QString test = QString::fromUtf8(data);
|
||||||
return test.toUtf8() == data;
|
return test.toUtf8() == data;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MetadataProcessor::readConfig(const QString& section, const QString& key, const QString& basePath)
|
|
||||||
{
|
|
||||||
QString uf2touft3Path = QDir(basePath).filePath("uf2touft3");
|
|
||||||
QString configPath = QDir(uf2touft3Path).filePath("config.ini");
|
|
||||||
|
|
||||||
QFile file(configPath);
|
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
|
||||||
LogManager::instance()->logError(QString("无法打开配置文件: %1").arg(configPath));
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray data = file.readAll();
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
QString content;
|
|
||||||
if (isValidUtf8(data)) {
|
|
||||||
content = QString::fromUtf8(data);
|
|
||||||
} else {
|
|
||||||
content = QString::fromLocal8Bit(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString sectionPattern = QString("\\[%1\\]").arg(section);
|
|
||||||
QString keyPattern = QString("^%1\\s*=\\s*(.+)$").arg(key);
|
|
||||||
|
|
||||||
QRegularExpression sectionRegex(sectionPattern);
|
|
||||||
QRegularExpression keyRegex(keyPattern, QRegularExpression::MultilineOption);
|
|
||||||
|
|
||||||
int sectionPos = content.indexOf(sectionRegex);
|
|
||||||
if (sectionPos == -1) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
int nextSectionPos = content.indexOf(QRegularExpression("\\["), sectionPos + 1);
|
|
||||||
QString sectionContent;
|
|
||||||
if (nextSectionPos == -1) {
|
|
||||||
sectionContent = content.mid(sectionPos);
|
|
||||||
} else {
|
|
||||||
sectionContent = content.mid(sectionPos, nextSectionPos - sectionPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRegularExpressionMatch match = keyRegex.match(sectionContent);
|
|
||||||
if (match.hasMatch()) {
|
|
||||||
QString value = match.captured(1).trimmed();
|
|
||||||
value.replace("\\", "/");
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MetadataProcessor::writeJson(const QString& filePath, const QJsonObject& jsonObject)
|
bool MetadataProcessor::writeJson(const QString& filePath, const QJsonObject& jsonObject)
|
||||||
{
|
{
|
||||||
|
|
@ -176,8 +165,7 @@ bool MetadataProcessor::processUf2Interfaces(const QString& basePath)
|
||||||
LogManager::instance()->log("========== 开始处理 UF2.0 接口 ==========");
|
LogManager::instance()->log("========== 开始处理 UF2.0 接口 ==========");
|
||||||
LogManager::instance()->log(QString("基础路径(basePath): %1").arg(basePath));
|
LogManager::instance()->log(QString("基础路径(basePath): %1").arg(basePath));
|
||||||
|
|
||||||
QString uf2touft3Path = QDir(basePath).filePath("uf2touft3");
|
QString configPath = QDir(m_uf2touft3Path).filePath("config.ini");
|
||||||
QString configPath = QDir(uf2touft3Path).filePath("config.ini");
|
|
||||||
LogManager::instance()->log(QString("配置文件路径: %1").arg(configPath));
|
LogManager::instance()->log(QString("配置文件路径: %1").arg(configPath));
|
||||||
|
|
||||||
QStringList completeNameList = {"module.xml", ".project", "冲突检测.wlua"};
|
QStringList completeNameList = {"module.xml", ".project", "冲突检测.wlua"};
|
||||||
|
|
@ -187,11 +175,11 @@ bool MetadataProcessor::processUf2Interfaces(const QString& basePath)
|
||||||
filterDict["completeNameList"] = completeNameList;
|
filterDict["completeNameList"] = completeNameList;
|
||||||
filterDict["containNameList"] = containNameList;
|
filterDict["containNameList"] = containNameList;
|
||||||
|
|
||||||
QString dirPath = readConfig("projectPath", "uf20", basePath);
|
QString dirPath = m_uf20Path;
|
||||||
QString ufAcct20ProjectDir = readConfig("projectPath", "ufAcct20", basePath);
|
QString ufAcct20ProjectDir = m_ufAcct20Path;
|
||||||
QString uftDbSett = readConfig("projectPath", "UftdbSett", basePath);
|
QString uftDbSett = m_uftDbSettPath;
|
||||||
|
|
||||||
QString supportUftdbSett = readConfig("testConfig", "supportUftdbSett", basePath);
|
QString supportUftdbSett = m_supportUftdbSett;
|
||||||
if (supportUftdbSett == "0") {
|
if (supportUftdbSett == "0") {
|
||||||
uftDbSett.clear();
|
uftDbSett.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -200,7 +188,7 @@ bool MetadataProcessor::processUf2Interfaces(const QString& basePath)
|
||||||
LogManager::instance()->log(QString("UF20 会计项目路径: %1").arg(ufAcct20ProjectDir));
|
LogManager::instance()->log(QString("UF20 会计项目路径: %1").arg(ufAcct20ProjectDir));
|
||||||
LogManager::instance()->log(QString("UFT 数据库设置路径: %1").arg(uftDbSett));
|
LogManager::instance()->log(QString("UFT 数据库设置路径: %1").arg(uftDbSett));
|
||||||
|
|
||||||
QString custJsonPath = QDir(uf2touft3Path).filePath("cust.json");
|
QString custJsonPath = QDir(m_uf2touft3Path).filePath("cust.json");
|
||||||
LogManager::instance()->log(QString("客户配置文件路径: %1").arg(custJsonPath));
|
LogManager::instance()->log(QString("客户配置文件路径: %1").arg(custJsonPath));
|
||||||
QJsonObject custJson = readJson(custJsonPath);
|
QJsonObject custJson = readJson(custJsonPath);
|
||||||
|
|
||||||
|
|
@ -262,7 +250,7 @@ bool MetadataProcessor::processUf2Interfaces(const QString& basePath)
|
||||||
resultJson[key] = interfaceJson;
|
resultJson[key] = interfaceJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString outputPath = QDir(uf2touft3Path).filePath("uf2.json");
|
QString outputPath = QDir(m_uf2touft3Path).filePath("uf2.json");
|
||||||
|
|
||||||
if (!writeJson(outputPath, resultJson)) {
|
if (!writeJson(outputPath, resultJson)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -281,11 +269,10 @@ bool MetadataProcessor::processUft3Interfaces(const QString& basePath)
|
||||||
LogManager::instance()->log("========== 开始处理 UFT3.0 接口 ==========");
|
LogManager::instance()->log("========== 开始处理 UFT3.0 接口 ==========");
|
||||||
LogManager::instance()->log(QString("基础路径(basePath): %1").arg(basePath));
|
LogManager::instance()->log(QString("基础路径(basePath): %1").arg(basePath));
|
||||||
|
|
||||||
QString uf2touft3Path = QDir(basePath).filePath("uf2touft3");
|
QString configPath = QDir(m_uf2touft3Path).filePath("config.ini");
|
||||||
QString configPath = QDir(uf2touft3Path).filePath("config.ini");
|
|
||||||
LogManager::instance()->log(QString("配置文件路径: %1").arg(configPath));
|
LogManager::instance()->log(QString("配置文件路径: %1").arg(configPath));
|
||||||
|
|
||||||
QString moduleGenerationCheck = readConfig("testConfig", "moduleGenerationCheck", basePath);
|
QString moduleGenerationCheck = m_moduleGenerationCheck;
|
||||||
LogManager::instance()->log(QString("模块生成检查: %1").arg(moduleGenerationCheck));
|
LogManager::instance()->log(QString("模块生成检查: %1").arg(moduleGenerationCheck));
|
||||||
|
|
||||||
QStringList completeNameList = {"module.xml", "project.xml", "冲突检测.wlua"};
|
QStringList completeNameList = {"module.xml", "project.xml", "冲突检测.wlua"};
|
||||||
|
|
@ -295,7 +282,7 @@ bool MetadataProcessor::processUft3Interfaces(const QString& basePath)
|
||||||
filterDict["completeNameList"] = completeNameList;
|
filterDict["completeNameList"] = completeNameList;
|
||||||
filterDict["containNameList"] = containNameList;
|
filterDict["containNameList"] = containNameList;
|
||||||
|
|
||||||
QString dirPath = readConfig("projectPath", "uft30", basePath);
|
QString dirPath = m_uft30Path;
|
||||||
LogManager::instance()->log(QString("UFT30 项目路径: %1").arg(dirPath));
|
LogManager::instance()->log(QString("UFT30 项目路径: %1").arg(dirPath));
|
||||||
|
|
||||||
Uft3Interface uft3;
|
Uft3Interface uft3;
|
||||||
|
|
@ -311,7 +298,7 @@ bool MetadataProcessor::processUft3Interfaces(const QString& basePath)
|
||||||
resultJson[key] = interfaceInfoToUFT3Json(info);
|
resultJson[key] = interfaceInfoToUFT3Json(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString outputPath = QDir(uf2touft3Path).filePath("uft3.json");
|
QString outputPath = QDir(m_uf2touft3Path).filePath("uft3.json");
|
||||||
|
|
||||||
if (!writeJson(outputPath, resultJson)) {
|
if (!writeJson(outputPath, resultJson)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -323,7 +310,7 @@ bool MetadataProcessor::processUft3Interfaces(const QString& basePath)
|
||||||
transCodeJson[key] = interfaceInfoToUFT3Json(info);
|
transCodeJson[key] = interfaceInfoToUFT3Json(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString transOutputPath = QDir(uf2touft3Path).filePath("uft3Trans.json");
|
QString transOutputPath = QDir(m_uf2touft3Path).filePath("uft3Trans.json");
|
||||||
|
|
||||||
if (!writeJson(transOutputPath, transCodeJson)) {
|
if (!writeJson(transOutputPath, transCodeJson)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -333,3 +320,210 @@ bool MetadataProcessor::processUft3Interfaces(const QString& basePath)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MetadataProcessor::processUf2DataType(const QString& basePath)
|
||||||
|
{
|
||||||
|
LogManager::instance()->log("========== 开始处理 UF2.0 数据类型 ==========");
|
||||||
|
|
||||||
|
QString dirPath = m_uf20Path;
|
||||||
|
|
||||||
|
Uf2DataType uf2DataType;
|
||||||
|
auto resultMap = uf2DataType.loadData(dirPath);
|
||||||
|
|
||||||
|
QJsonObject resultJson;
|
||||||
|
for (const QString& key : resultMap.keys()) {
|
||||||
|
const QMap<QString, QString>& typeInfo = resultMap[key];
|
||||||
|
QJsonObject typeJson;
|
||||||
|
for (const QString& attrKey : typeInfo.keys()) {
|
||||||
|
typeJson[attrKey] = typeInfo[attrKey];
|
||||||
|
}
|
||||||
|
resultJson[key] = typeJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString outputPath = QDir(m_uf2touft3Path).filePath("uf2dataType.json");
|
||||||
|
|
||||||
|
if (!writeJson(outputPath, resultJson)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("UF2.0 数据类型处理完成,结果已保存到: %1").arg(outputPath));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MetadataProcessor::processUf2StdFields(const QString& basePath)
|
||||||
|
{
|
||||||
|
LogManager::instance()->log("========== 开始处理 UF2.0 标准字段 ==========");
|
||||||
|
|
||||||
|
QString dirPath = m_uf20Path;
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> uf2datatypeMap;
|
||||||
|
QString datatypeJsonPath = QDir(m_uf2touft3Path).filePath("uf2dataType.json");
|
||||||
|
QJsonObject datatypeJson = readJson(datatypeJsonPath);
|
||||||
|
for (const QString& key : datatypeJson.keys()) {
|
||||||
|
QJsonObject typeObj = datatypeJson[key].toObject();
|
||||||
|
QMap<QString, QString> typeInfo;
|
||||||
|
for (const QString& attrKey : typeObj.keys()) {
|
||||||
|
typeInfo[attrKey] = typeObj[attrKey].toString();
|
||||||
|
}
|
||||||
|
uf2datatypeMap[key] = typeInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uf2StdFields uf2StdFields;
|
||||||
|
auto resultMap = uf2StdFields.loadData(dirPath, uf2datatypeMap);
|
||||||
|
|
||||||
|
QJsonObject resultJson;
|
||||||
|
for (const QString& key : resultMap.keys()) {
|
||||||
|
const QMap<QString, QString>& fieldInfo = resultMap[key];
|
||||||
|
QJsonObject fieldJson;
|
||||||
|
for (const QString& attrKey : fieldInfo.keys()) {
|
||||||
|
fieldJson[attrKey] = fieldInfo[attrKey];
|
||||||
|
}
|
||||||
|
resultJson[key] = fieldJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString outputPath = QDir(m_uf2touft3Path).filePath("uf2stdfield.json");
|
||||||
|
|
||||||
|
if (!writeJson(outputPath, resultJson)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("UF2.0 标准字段处理完成,结果已保存到: %1").arg(outputPath));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MetadataProcessor::processUf2ErrNumber(const QString& basePath)
|
||||||
|
{
|
||||||
|
LogManager::instance()->log("========== 开始处理 UF2.0 标准错误号 ==========");
|
||||||
|
|
||||||
|
QString dirPath = m_uf20Path;
|
||||||
|
|
||||||
|
Uf2ErrNumber uf2ErrNumber;
|
||||||
|
auto resultMap = uf2ErrNumber.loadData(dirPath);
|
||||||
|
|
||||||
|
QJsonObject resultJson;
|
||||||
|
for (const QString& key : resultMap.keys()) {
|
||||||
|
const QMap<QString, QString>& errorInfo = resultMap[key];
|
||||||
|
QJsonObject errorJson;
|
||||||
|
for (const QString& attrKey : errorInfo.keys()) {
|
||||||
|
errorJson[attrKey] = errorInfo[attrKey];
|
||||||
|
}
|
||||||
|
resultJson[key] = errorJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString outputPath = QDir(m_uf2touft3Path).filePath("uf2Error.json");
|
||||||
|
|
||||||
|
if (!writeJson(outputPath, resultJson)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("UF2.0 标准错误号处理完成,结果已保存到: %1").arg(outputPath));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MetadataProcessor::processUft3DataType(const QString& basePath)
|
||||||
|
{
|
||||||
|
LogManager::instance()->log("========== 开始处理 UFT3.0 数据类型 ==========");
|
||||||
|
|
||||||
|
QString dirPath = m_uft30PubPath;
|
||||||
|
|
||||||
|
Uft3DataType uft3DataType;
|
||||||
|
auto resultMap = uft3DataType.loadData(dirPath);
|
||||||
|
|
||||||
|
QJsonObject resultJson;
|
||||||
|
for (const QString& key : resultMap.keys()) {
|
||||||
|
const QMap<QString, QString>& typeInfo = resultMap[key];
|
||||||
|
QJsonObject typeJson;
|
||||||
|
for (const QString& attrKey : typeInfo.keys()) {
|
||||||
|
typeJson[attrKey] = typeInfo[attrKey];
|
||||||
|
}
|
||||||
|
resultJson[key] = typeJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString outputPath = QDir(m_uf2touft3Path).filePath("uft3datatype.json");
|
||||||
|
|
||||||
|
if (!writeJson(outputPath, resultJson)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("UFT3.0 数据类型处理完成,结果已保存到: %1").arg(outputPath));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MetadataProcessor::processUft3StdFields(const QString& basePath)
|
||||||
|
{
|
||||||
|
LogManager::instance()->log("========== 开始处理 UFT3.0 标准字段 ==========");
|
||||||
|
|
||||||
|
QString dirPath = m_uft30PubPath;
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> uf3datatypeMap;
|
||||||
|
QString datatypeJsonPath = QDir(m_uf2touft3Path).filePath("uft3datatype.json");
|
||||||
|
QJsonObject datatypeJson = readJson(datatypeJsonPath);
|
||||||
|
for (const QString& key : datatypeJson.keys()) {
|
||||||
|
QJsonObject typeObj = datatypeJson[key].toObject();
|
||||||
|
QMap<QString, QString> typeInfo;
|
||||||
|
for (const QString& attrKey : typeObj.keys()) {
|
||||||
|
typeInfo[attrKey] = typeObj[attrKey].toString();
|
||||||
|
}
|
||||||
|
uf3datatypeMap[key] = typeInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uft3StdFields uft3StdFields;
|
||||||
|
auto resultMap = uft3StdFields.loadData(dirPath, uf3datatypeMap);
|
||||||
|
|
||||||
|
QJsonObject resultJson;
|
||||||
|
for (const QString& key : resultMap.keys()) {
|
||||||
|
const QMap<QString, QString>& fieldInfo = resultMap[key];
|
||||||
|
QJsonObject fieldJson;
|
||||||
|
for (const QString& attrKey : fieldInfo.keys()) {
|
||||||
|
fieldJson[attrKey] = fieldInfo[attrKey];
|
||||||
|
}
|
||||||
|
resultJson[key] = fieldJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString outputPath = QDir(m_uf2touft3Path).filePath("uft3stdfields.json");
|
||||||
|
|
||||||
|
if (!writeJson(outputPath, resultJson)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("UFT3.0 标准字段处理完成,结果已保存到: %1").arg(outputPath));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MetadataProcessor::processUft3Table(const QString& basePath)
|
||||||
|
{
|
||||||
|
LogManager::instance()->log("========== 开始处理 UFT3.0 表结构 ==========");
|
||||||
|
|
||||||
|
QString dirPath = m_uft30PubPath;
|
||||||
|
|
||||||
|
Uft3Table uft3Table;
|
||||||
|
auto resultMap = uft3Table.loadData(dirPath);
|
||||||
|
|
||||||
|
QJsonObject resultJson;
|
||||||
|
for (const QString& key : resultMap.keys()) {
|
||||||
|
const QMap<QString, QVariant>& tableInfo = resultMap[key];
|
||||||
|
QJsonObject tableJson;
|
||||||
|
for (const QString& attrKey : tableInfo.keys()) {
|
||||||
|
QVariant value = tableInfo[attrKey];
|
||||||
|
if (value.canConvert<QJsonValue>()) {
|
||||||
|
tableJson[attrKey] = value.toJsonValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultJson[key] = tableJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString outputPath = QDir(m_uf2touft3Path).filePath("uft3Table.json");
|
||||||
|
|
||||||
|
if (!writeJson(outputPath, resultJson)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("UFT3.0 表结构处理完成,结果已保存到: %1").arg(outputPath));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
@ -18,17 +18,38 @@ public:
|
||||||
bool processUf2Interfaces(const QString& basePath);
|
bool processUf2Interfaces(const QString& basePath);
|
||||||
bool processUft3Interfaces(const QString& basePath);
|
bool processUft3Interfaces(const QString& basePath);
|
||||||
|
|
||||||
|
bool processUf2StdFields(const QString& basePath);
|
||||||
|
bool processUf2DataType(const QString& basePath);
|
||||||
|
bool processUf2ErrNumber(const QString& basePath);
|
||||||
|
|
||||||
|
bool processUft3StdFields(const QString& basePath);
|
||||||
|
bool processUft3DataType(const QString& basePath);
|
||||||
|
bool processUft3Table(const QString& basePath);
|
||||||
|
|
||||||
QString getBasePath() const;
|
QString getBasePath() const;
|
||||||
void setBasePath(const QString& path);
|
void setBasePath(const QString& path);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initConfig(const QString& basePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isValidUtf8(const QByteArray& data);
|
bool isValidUtf8(const QByteArray& data);
|
||||||
QString readConfig(const QString& section, const QString& key, const QString& basePath);
|
|
||||||
bool writeJson(const QString& filePath, const QJsonObject& jsonObject);
|
bool writeJson(const QString& filePath, const QJsonObject& jsonObject);
|
||||||
QJsonObject readJson(const QString& filePath);
|
QJsonObject readJson(const QString& filePath);
|
||||||
QJsonObject interfaceInfoToUFT3Json(const InterfaceInfo& info);
|
QJsonObject interfaceInfoToUFT3Json(const InterfaceInfo& info);
|
||||||
|
|
||||||
QString m_basePath;
|
QString m_basePath;
|
||||||
|
QString m_uf2touft3Path;
|
||||||
|
|
||||||
|
QString m_uf20Path;
|
||||||
|
QString m_ufAcct20Path;
|
||||||
|
QString m_uftDbSettPath;
|
||||||
|
QString m_uft30PubPath;
|
||||||
|
QString m_uft30CbptransPath;
|
||||||
|
QString m_uft30Path;
|
||||||
|
|
||||||
|
QString m_supportUftdbSett;
|
||||||
|
QString m_moduleGenerationCheck;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // METADATAPROCESSOR_H
|
#endif // METADATAPROCESSOR_H
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
#include "uf2datatype.h"
|
||||||
|
#include "utils/logmanager.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
|
Uf2DataType::Uf2DataType(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> Uf2DataType::loadData(const QString& dirPath)
|
||||||
|
{
|
||||||
|
QMap<QString, QMap<QString, QString>> resultMap;
|
||||||
|
|
||||||
|
QString filePath = dirPath;
|
||||||
|
filePath.replace('\\', '/');
|
||||||
|
filePath += "/公共资源/datatypes.xml";
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("加载UF2数据类型文件: %1").arg(filePath));
|
||||||
|
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
LogManager::instance()->logError(QString("无法打开文件: %1").arg(filePath));
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
QXmlStreamReader xml(&file);
|
||||||
|
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
QXmlStreamReader::TokenType token = xml.readNext();
|
||||||
|
|
||||||
|
if (token == QXmlStreamReader::StartElement) {
|
||||||
|
QString elementName = xml.name().toString();
|
||||||
|
|
||||||
|
if (elementName == "userType") {
|
||||||
|
QXmlStreamAttributes attrs = xml.attributes();
|
||||||
|
QString hsType = attrs.value("name").toString();
|
||||||
|
|
||||||
|
QString cValue = "";
|
||||||
|
QString oValue = "";
|
||||||
|
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
token = xml.readNext();
|
||||||
|
|
||||||
|
if (token == QXmlStreamReader::StartElement) {
|
||||||
|
QString childElementName = xml.name().toString();
|
||||||
|
|
||||||
|
if (childElementName == "language") {
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
token = xml.readNext();
|
||||||
|
if (token == QXmlStreamReader::StartElement && xml.name().toString() == "map") {
|
||||||
|
cValue = xml.attributes().value("value").toString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (childElementName == "database") {
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
token = xml.readNext();
|
||||||
|
if (token == QXmlStreamReader::StartElement && xml.name().toString() == "map") {
|
||||||
|
oValue = xml.attributes().value("value").toString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (token == QXmlStreamReader::EndElement && xml.name().toString() == "userType") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> typeInfo;
|
||||||
|
typeInfo["HsType"] = hsType;
|
||||||
|
typeInfo["CType"] = cValue;
|
||||||
|
typeInfo["OType"] = oValue;
|
||||||
|
|
||||||
|
resultMap[hsType] = typeInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
LogManager::instance()->log(QString("UF2数据类型加载完成,共 %1 条").arg(resultMap.size()));
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef UF2DATATYPE_H
|
||||||
|
#define UF2DATATYPE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
class Uf2DataType : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Uf2DataType(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> loadData(const QString& dirPath);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
#include "uf2errnumber.h"
|
||||||
|
#include "utils/logmanager.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
|
Uf2ErrNumber::Uf2ErrNumber(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> Uf2ErrNumber::loadData(const QString& dirPath)
|
||||||
|
{
|
||||||
|
QMap<QString, QMap<QString, QString>> resultMap;
|
||||||
|
|
||||||
|
QString filePath = dirPath;
|
||||||
|
filePath.replace('\\', '/');
|
||||||
|
filePath += "/公共资源/errNumbers.xml";
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("加载UF2错误号文件: %1").arg(filePath));
|
||||||
|
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
LogManager::instance()->logError(QString("无法打开文件: %1").arg(filePath));
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
QXmlStreamReader xml(&file);
|
||||||
|
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
QXmlStreamReader::TokenType token = xml.readNext();
|
||||||
|
|
||||||
|
if (token == QXmlStreamReader::StartElement) {
|
||||||
|
QString elementName = xml.name().toString();
|
||||||
|
|
||||||
|
if (elementName == "error_no") {
|
||||||
|
QXmlStreamAttributes attrs = xml.attributes();
|
||||||
|
|
||||||
|
QString sErrorNo = attrs.value("code").toString();
|
||||||
|
QString sConstant = attrs.value("constant").toString();
|
||||||
|
QString sErrorInfo = attrs.value("info").toString();
|
||||||
|
|
||||||
|
QMap<QString, QString> errorInfo;
|
||||||
|
errorInfo["code"] = sErrorNo;
|
||||||
|
errorInfo["constant"] = sConstant;
|
||||||
|
errorInfo["info"] = sErrorInfo;
|
||||||
|
|
||||||
|
resultMap[sConstant] = errorInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
LogManager::instance()->log(QString("UF2错误号加载完成,共 %1 条").arg(resultMap.size()));
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef UF2ERRNUMBER_H
|
||||||
|
#define UF2ERRNUMBER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
class Uf2ErrNumber : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Uf2ErrNumber(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> loadData(const QString& dirPath);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
#include "uf2stdfields.h"
|
||||||
|
#include "utils/logmanager.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
|
Uf2StdFields::Uf2StdFields(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> Uf2StdFields::loadData(
|
||||||
|
const QString& dirPath,
|
||||||
|
const QMap<QString, QMap<QString, QString>>& uf2datatypeMap)
|
||||||
|
{
|
||||||
|
QMap<QString, QMap<QString, QString>> resultMap;
|
||||||
|
|
||||||
|
QString filePath = dirPath;
|
||||||
|
filePath.replace('\\', '/');
|
||||||
|
filePath += "/公共资源/stdfields.xml";
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("加载UF2标准字段文件: %1").arg(filePath));
|
||||||
|
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
LogManager::instance()->logError(QString("无法打开文件: %1").arg(filePath));
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
QXmlStreamReader xml(&file);
|
||||||
|
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
QXmlStreamReader::TokenType token = xml.readNext();
|
||||||
|
|
||||||
|
if (token == QXmlStreamReader::StartElement) {
|
||||||
|
QString elementName = xml.name().toString();
|
||||||
|
|
||||||
|
if (elementName == "stdfield") {
|
||||||
|
QXmlStreamAttributes attrs = xml.attributes();
|
||||||
|
|
||||||
|
QString sFieldName = attrs.value("name").toString();
|
||||||
|
QString sCname = attrs.value("cname").toString();
|
||||||
|
QString sType = attrs.value("type").toString();
|
||||||
|
QString sDesc = attrs.value("desc").toString();
|
||||||
|
sDesc.replace("'", "\"");
|
||||||
|
QString sDictId = attrs.value("dict").toString();
|
||||||
|
|
||||||
|
QString sCtype = "";
|
||||||
|
QString sOType = "";
|
||||||
|
|
||||||
|
if (uf2datatypeMap.contains(sType)) {
|
||||||
|
sCtype = uf2datatypeMap[sType].value("CType");
|
||||||
|
sOType = uf2datatypeMap[sType].value("OType");
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> fieldInfo;
|
||||||
|
fieldInfo["name"] = sFieldName;
|
||||||
|
fieldInfo["cname"] = sCname;
|
||||||
|
fieldInfo["type"] = sType;
|
||||||
|
fieldInfo["desc"] = sDesc;
|
||||||
|
fieldInfo["dict"] = sDictId;
|
||||||
|
fieldInfo["cType"] = sCtype;
|
||||||
|
fieldInfo["oType"] = sOType;
|
||||||
|
|
||||||
|
resultMap[sFieldName] = fieldInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
LogManager::instance()->log(QString("UF2标准字段加载完成,共 %1 条").arg(resultMap.size()));
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef UF2STDFIELDS_H
|
||||||
|
#define UF2STDFIELDS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
class Uf2StdFields : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Uf2StdFields(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> loadData(const QString& dirPath,
|
||||||
|
const QMap<QString, QMap<QString, QString>>& uf2datatypeMap);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
#include "uft3datatype.h"
|
||||||
|
#include "utils/logmanager.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
|
Uft3DataType::Uft3DataType(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> Uft3DataType::loadData(const QString& dirPath)
|
||||||
|
{
|
||||||
|
QMap<QString, QMap<QString, QString>> resultMap;
|
||||||
|
|
||||||
|
QString filePath = dirPath;
|
||||||
|
filePath.replace('\\', '/');
|
||||||
|
filePath += "/metadata/datatype.datatype";
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("加载UFT3数据类型文件: %1").arg(filePath));
|
||||||
|
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
LogManager::instance()->logError(QString("无法打开文件: %1").arg(filePath));
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
QXmlStreamReader xml(&file);
|
||||||
|
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
QXmlStreamReader::TokenType token = xml.readNext();
|
||||||
|
|
||||||
|
if (token == QXmlStreamReader::StartElement) {
|
||||||
|
QString elementName = xml.name().toString();
|
||||||
|
|
||||||
|
if (elementName == "items") {
|
||||||
|
QXmlStreamAttributes attrs = xml.attributes();
|
||||||
|
|
||||||
|
QString hsType = attrs.value("name").toString();
|
||||||
|
QString uftValue = attrs.value("stdType").toString();
|
||||||
|
QString uftLen = "0";
|
||||||
|
|
||||||
|
if (uftValue.toLower() == "string") {
|
||||||
|
uftLen = attrs.value("length").toString();
|
||||||
|
uftValue = "char[" + uftLen + "]";
|
||||||
|
}
|
||||||
|
else if (uftValue.toLower() == "int32") {
|
||||||
|
uftValue = "int";
|
||||||
|
}
|
||||||
|
else if (uftValue.toLower() == "int64") {
|
||||||
|
uftValue = "double";
|
||||||
|
}
|
||||||
|
else if (uftValue.toLower() == "double") {
|
||||||
|
uftValue = "double";
|
||||||
|
}
|
||||||
|
else if (uftValue.toLower() == "char") {
|
||||||
|
uftValue = "char";
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> typeInfo;
|
||||||
|
typeInfo["HsType"] = hsType;
|
||||||
|
typeInfo["uftType"] = uftValue;
|
||||||
|
|
||||||
|
resultMap[hsType] = typeInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
LogManager::instance()->log(QString("UFT3数据类型加载完成,共 %1 条").arg(resultMap.size()));
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef TFT3DATATYPE_H
|
||||||
|
#define TFT3DATATYPE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
class Uft3DataType : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Uft3DataType(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> loadData(const QString& dirPath);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include "uft3stdfields.h"
|
||||||
|
#include "utils/logmanager.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
|
Uft3StdFields::Uft3StdFields(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> Uft3StdFields::loadData(
|
||||||
|
const QString& dirPath,
|
||||||
|
const QMap<QString, QMap<QString, QString>>& uf3datatypeMap)
|
||||||
|
{
|
||||||
|
QMap<QString, QMap<QString, QString>> resultMap;
|
||||||
|
|
||||||
|
QString filePath = dirPath;
|
||||||
|
filePath.replace('\\', '/');
|
||||||
|
filePath += "/metadata/stdfield.stdfield";
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("加载UFT3标准字段文件: %1").arg(filePath));
|
||||||
|
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
LogManager::instance()->logError(QString("无法打开文件: %1").arg(filePath));
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
QXmlStreamReader xml(&file);
|
||||||
|
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
QXmlStreamReader::TokenType token = xml.readNext();
|
||||||
|
|
||||||
|
if (token == QXmlStreamReader::StartElement) {
|
||||||
|
QString elementName = xml.name().toString();
|
||||||
|
|
||||||
|
if (elementName == "items") {
|
||||||
|
QXmlStreamAttributes attrs = xml.attributes();
|
||||||
|
|
||||||
|
QString sFieldName = attrs.value("name").toString();
|
||||||
|
QString sCname = attrs.value("chineseName").toString();
|
||||||
|
QString sType = attrs.value("dataType").toString();
|
||||||
|
QString sDesc = attrs.value("description").toString();
|
||||||
|
sDesc.replace("'", "\"");
|
||||||
|
QString sDictId = attrs.value("dictionaryType").toString();
|
||||||
|
|
||||||
|
QString sUftType = "";
|
||||||
|
|
||||||
|
if (uf3datatypeMap.contains(sType)) {
|
||||||
|
sUftType = uf3datatypeMap[sType].value("uftType");
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> fieldInfo;
|
||||||
|
fieldInfo["name"] = sFieldName;
|
||||||
|
fieldInfo["cname"] = sCname;
|
||||||
|
fieldInfo["type"] = sType;
|
||||||
|
fieldInfo["desc"] = sDesc;
|
||||||
|
fieldInfo["dict"] = sDictId;
|
||||||
|
fieldInfo["uftType"] = sUftType;
|
||||||
|
|
||||||
|
resultMap[sFieldName] = fieldInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
LogManager::instance()->log(QString("UFT3标准字段加载完成,共 %1 条").arg(resultMap.size()));
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef TFT3STDFIELDS_H
|
||||||
|
#define TFT3STDFIELDS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
class Uft3StdFields : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Uft3StdFields(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QString>> loadData(const QString& dirPath,
|
||||||
|
const QMap<QString, QMap<QString, QString>>& uf3datatypeMap);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,191 @@
|
||||||
|
#include "uft3table.h"
|
||||||
|
#include "utils/logmanager.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
Uft3Table::Uft3Table(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QVariant>> Uft3Table::loadData(const QString& dirPath)
|
||||||
|
{
|
||||||
|
QMap<QString, QMap<QString, QVariant>> resultMap;
|
||||||
|
|
||||||
|
QString scanPath = dirPath;
|
||||||
|
scanPath.replace('\\', '/');
|
||||||
|
scanPath += "/uftstructure";
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("加载UFT3表结构目录: %1").arg(scanPath));
|
||||||
|
|
||||||
|
QDir dir(scanPath);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
LogManager::instance()->logError(QString("表结构目录不存在: %1").arg(scanPath));
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
scanDirectory(scanPath, resultMap);
|
||||||
|
|
||||||
|
for (const QString& filePath : _fileList) {
|
||||||
|
if (filePath.contains(".uftstructure")) {
|
||||||
|
parseTableFile(filePath, resultMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("UFT3表结构加载完成,共 %1 条").arg(resultMap.size()));
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Uft3Table::scanDirectory(const QString& dirPath, QMap<QString, QMap<QString, QVariant>>& resultMap)
|
||||||
|
{
|
||||||
|
QDir dir(dirPath);
|
||||||
|
|
||||||
|
QFileInfoList fileList = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
|
|
||||||
|
for (const QFileInfo& fileInfo : fileList) {
|
||||||
|
if (fileInfo.isDir()) {
|
||||||
|
scanDirectory(fileInfo.absoluteFilePath(), resultMap);
|
||||||
|
}
|
||||||
|
else if (fileInfo.isFile()) {
|
||||||
|
_fileList.append(fileInfo.absoluteFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Uft3Table::parseTableFile(const QString& filePath, QMap<QString, QMap<QString, QVariant>>& resultMap)
|
||||||
|
{
|
||||||
|
QString sFilePath = filePath;
|
||||||
|
sFilePath.replace('\\', '/');
|
||||||
|
|
||||||
|
QFile file(sFilePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
LogManager::instance()->logError(QString("无法打开表结构文件: %1").arg(sFilePath));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QXmlStreamReader xml(&file);
|
||||||
|
|
||||||
|
QString tableEngName = "";
|
||||||
|
QString tablePath = "";
|
||||||
|
QString chineseName = "";
|
||||||
|
QString objectId = "";
|
||||||
|
QString spaceName = "";
|
||||||
|
QStringList fieldList;
|
||||||
|
QMap<QString, QStringList> indexMap;
|
||||||
|
QMap<QString, QStringList> uniqueIndexMap;
|
||||||
|
QMap<QString, QStringList> globalIndexMap;
|
||||||
|
|
||||||
|
int lastSlash = sFilePath.lastIndexOf('/');
|
||||||
|
if (lastSlash != -1) {
|
||||||
|
tableEngName = sFilePath.mid(lastSlash + 1);
|
||||||
|
tableEngName = tableEngName.left(tableEngName.indexOf(".uftstructure"));
|
||||||
|
}
|
||||||
|
|
||||||
|
int uftstructurePos = sFilePath.indexOf("uftstructure");
|
||||||
|
if (uftstructurePos != -1) {
|
||||||
|
tablePath = sFilePath.mid(uftstructurePos);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
QXmlStreamReader::TokenType token = xml.readNext();
|
||||||
|
|
||||||
|
if (token == QXmlStreamReader::StartElement) {
|
||||||
|
QString elementName = xml.name().toString();
|
||||||
|
QXmlStreamAttributes attrs = xml.attributes();
|
||||||
|
|
||||||
|
if (elementName == "uftstructure") {
|
||||||
|
chineseName = attrs.value("chineseName").toString();
|
||||||
|
objectId = attrs.value("objectId").toString();
|
||||||
|
if (attrs.hasAttribute("space")) {
|
||||||
|
spaceName = attrs.value("space").toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (elementName == "properties") {
|
||||||
|
QString fieldId = attrs.value("id").toString();
|
||||||
|
if (!fieldId.isEmpty()) {
|
||||||
|
fieldList.append(fieldId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (elementName == "indexs") {
|
||||||
|
QString indexName = attrs.value("name").toString();
|
||||||
|
QStringList indexFieldList;
|
||||||
|
bool isUnique = !attrs.hasAttribute("containerType");
|
||||||
|
bool isGlobal = false;
|
||||||
|
|
||||||
|
if (attrs.hasAttribute("global") && attrs.value("global").toString() == "true") {
|
||||||
|
isGlobal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!xml.atEnd() && !xml.hasError()) {
|
||||||
|
token = xml.readNext();
|
||||||
|
|
||||||
|
if (token == QXmlStreamReader::StartElement && xml.name().toString() == "items") {
|
||||||
|
QString fieldAttr = xml.attributes().value("attrname").toString();
|
||||||
|
if (!fieldAttr.isEmpty()) {
|
||||||
|
indexFieldList.append(fieldAttr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (token == QXmlStreamReader::EndElement && xml.name().toString() == "indexs") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!indexName.isEmpty() && !indexFieldList.isEmpty()) {
|
||||||
|
indexMap[indexName] = indexFieldList;
|
||||||
|
if (isUnique) {
|
||||||
|
uniqueIndexMap[indexName] = indexFieldList;
|
||||||
|
}
|
||||||
|
if (isGlobal) {
|
||||||
|
globalIndexMap[indexName] = indexFieldList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
QString sUser = "";
|
||||||
|
if (spaceName == "HS_UFT_DATA") {
|
||||||
|
sUser = "hs_uft";
|
||||||
|
}
|
||||||
|
else if (spaceName == "HS_UARG_DATA") {
|
||||||
|
sUser = "hs_uarg";
|
||||||
|
}
|
||||||
|
else if (spaceName == "HS_USMS_DATA") {
|
||||||
|
sUser = "hs_usms";
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QVariant> tableInfoDetail;
|
||||||
|
tableInfoDetail["tableEngName"] = tableEngName;
|
||||||
|
tableInfoDetail["tablePath"] = tablePath;
|
||||||
|
tableInfoDetail["chineseName"] = chineseName;
|
||||||
|
tableInfoDetail["objectId"] = objectId;
|
||||||
|
tableInfoDetail["fieldList"] = fieldList;
|
||||||
|
tableInfoDetail["user"] = sUser;
|
||||||
|
|
||||||
|
QJsonObject indexMapJson;
|
||||||
|
for (const QString& key : indexMap.keys()) {
|
||||||
|
indexMapJson[key] = QJsonArray::fromStringList(indexMap[key]);
|
||||||
|
}
|
||||||
|
tableInfoDetail["indexMap"] = indexMapJson;
|
||||||
|
|
||||||
|
QJsonObject uniqueIndexMapJson;
|
||||||
|
for (const QString& key : uniqueIndexMap.keys()) {
|
||||||
|
uniqueIndexMapJson[key] = QJsonArray::fromStringList(uniqueIndexMap[key]);
|
||||||
|
}
|
||||||
|
tableInfoDetail["uniqueIndexMap"] = uniqueIndexMapJson;
|
||||||
|
|
||||||
|
QJsonObject globalIndexMapJson;
|
||||||
|
for (const QString& key : globalIndexMap.keys()) {
|
||||||
|
globalIndexMapJson[key] = QJsonArray::fromStringList(globalIndexMap[key]);
|
||||||
|
}
|
||||||
|
tableInfoDetail["globalIndexMap"] = globalIndexMapJson;
|
||||||
|
|
||||||
|
if (!tableEngName.isEmpty()) {
|
||||||
|
resultMap[tableEngName] = tableInfoDetail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef TFT3TABLE_H
|
||||||
|
#define TFT3TABLE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class Uft3Table : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Uft3Table(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QMap<QString, QMap<QString, QVariant>> loadData(const QString& dirPath);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void scanDirectory(const QString& dirPath, QMap<QString, QMap<QString, QVariant>>& resultMap);
|
||||||
|
void parseTableFile(const QString& filePath, QMap<QString, QMap<QString, QVariant>>& resultMap);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStringList _fileList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -15,6 +15,8 @@ MetadataUpdatePage::MetadataUpdatePage(QWidget *parent)
|
||||||
{
|
{
|
||||||
initUI();
|
initUI();
|
||||||
_processor = new MetadataProcessor(this);
|
_processor = new MetadataProcessor(this);
|
||||||
|
QString basePath = QCoreApplication::applicationDirPath();
|
||||||
|
_processor->initConfig(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
MetadataUpdatePage::~MetadataUpdatePage()
|
MetadataUpdatePage::~MetadataUpdatePage()
|
||||||
|
|
@ -136,7 +138,7 @@ void MetadataUpdatePage::showEvent(QShowEvent* event)
|
||||||
|
|
||||||
void MetadataUpdatePage::showUpdateItems()
|
void MetadataUpdatePage::showUpdateItems()
|
||||||
{
|
{
|
||||||
QStringList uft3Items = {"标准字段", "数据类型", "标准错误号",
|
QStringList uft3Items = {"标准字段", "数据类型", "表结构",
|
||||||
"接口数据"};
|
"接口数据"};
|
||||||
|
|
||||||
QStringList uf20Items = {"标准字段", "数据类型", "标准错误号",
|
QStringList uf20Items = {"标准字段", "数据类型", "标准错误号",
|
||||||
|
|
@ -243,10 +245,13 @@ void MetadataUpdatePage::onUpdateUFT3()
|
||||||
void MetadataUpdatePage::updateUf2Interfaces(const QStringList& items)
|
void MetadataUpdatePage::updateUf2Interfaces(const QStringList& items)
|
||||||
{
|
{
|
||||||
QString basePath = QCoreApplication::applicationDirPath();
|
QString basePath = QCoreApplication::applicationDirPath();
|
||||||
|
int itemCount = items.size();
|
||||||
|
|
||||||
foreach (const QString& item, items) {
|
foreach (const QString& item, items) {
|
||||||
_processLabel->setText(QString("正在更新UF20 - %1").arg(item));
|
_processLabel->setText(QString("正在更新UF20 - %1").arg(item));
|
||||||
_progressBar->setValue((items.indexOf(item) + 1) * 100 / items.size());
|
int currentIndex = items.indexOf(item);
|
||||||
|
int progress = (itemCount == 1) ? 0 : (currentIndex * 100 / itemCount);
|
||||||
|
_progressBar->setValue(progress);
|
||||||
|
|
||||||
if (item == "标准字段") {
|
if (item == "标准字段") {
|
||||||
processUf2StdFields(basePath);
|
processUf2StdFields(basePath);
|
||||||
|
|
@ -257,72 +262,83 @@ void MetadataUpdatePage::updateUf2Interfaces(const QStringList& items)
|
||||||
} else if (item == "接口数据") {
|
} else if (item == "接口数据") {
|
||||||
processUf2Interface(basePath);
|
processUf2Interface(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_progressBar->setValue(100);
|
||||||
|
_processLabel->setText("UF20更新完成");
|
||||||
|
|
||||||
onUpdateFinished(true, "UF20更新完成");
|
onUpdateFinished(true, "UF20更新完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::updateUft3Interfaces(const QStringList& items)
|
void MetadataUpdatePage::updateUft3Interfaces(const QStringList& items)
|
||||||
{
|
{
|
||||||
QString basePath = QCoreApplication::applicationDirPath();
|
QString basePath = QCoreApplication::applicationDirPath();
|
||||||
|
int itemCount = items.size();
|
||||||
|
|
||||||
foreach (const QString& item, items) {
|
foreach (const QString& item, items) {
|
||||||
_processLabel->setText(QString("正在更新UFT30 - %1").arg(item));
|
_processLabel->setText(QString("正在更新UFT30 - %1").arg(item));
|
||||||
_progressBar->setValue((items.indexOf(item) + 1) * 100 / items.size());
|
int currentIndex = items.indexOf(item);
|
||||||
|
int progress = (itemCount == 1) ? 0 : (currentIndex * 100 / itemCount);
|
||||||
|
_progressBar->setValue(progress);
|
||||||
|
|
||||||
if (item == "标准字段") {
|
if (item == "标准字段") {
|
||||||
processUft3StdFields(basePath);
|
processUft3StdFields(basePath);
|
||||||
} else if (item == "数据类型") {
|
} else if (item == "数据类型") {
|
||||||
processUft3DataType(basePath);
|
processUft3DataType(basePath);
|
||||||
} else if (item == "标准错误号") {
|
} else if (item == "表结构") {
|
||||||
processUft3ErrNumber(basePath);
|
processUft3Table(basePath);
|
||||||
} else if (item == "接口数据") {
|
} else if (item == "接口数据") {
|
||||||
processUft3Interface(basePath);
|
processUft3Interface(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_progressBar->setValue(100);
|
||||||
|
_processLabel->setText("UFT30更新完成");
|
||||||
|
|
||||||
onUpdateFinished(true, "UFT30更新完成");
|
onUpdateFinished(true, "UFT30更新完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::processUf2StdFields(const QString& basePath)
|
void MetadataUpdatePage::processUf2StdFields(const QString& basePath)
|
||||||
{
|
{
|
||||||
qInfo() << "处理UF20标准字段";
|
_processor->processUf2StdFields(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::processUf2DataType(const QString& basePath)
|
void MetadataUpdatePage::processUf2DataType(const QString& basePath)
|
||||||
{
|
{
|
||||||
qInfo() << "处理UF20数据类型";
|
_processor->processUf2DataType(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::processUf2ErrNumber(const QString& basePath)
|
void MetadataUpdatePage::processUf2ErrNumber(const QString& basePath)
|
||||||
{
|
{
|
||||||
qInfo() << "处理UF20标准错误号";
|
_processor->processUf2ErrNumber(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::processUf2Interface(const QString& basePath)
|
void MetadataUpdatePage::processUf2Interface(const QString& basePath)
|
||||||
{
|
{
|
||||||
qInfo() << "处理UF20接口数据";
|
|
||||||
_processor->processUf2Interfaces(basePath);
|
_processor->processUf2Interfaces(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::processUft3StdFields(const QString& basePath)
|
void MetadataUpdatePage::processUft3StdFields(const QString& basePath)
|
||||||
{
|
{
|
||||||
qInfo() << "处理UFT30标准字段";
|
_processor->processUft3StdFields(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::processUft3DataType(const QString& basePath)
|
void MetadataUpdatePage::processUft3DataType(const QString& basePath)
|
||||||
{
|
{
|
||||||
qInfo() << "处理UFT30数据类型";
|
_processor->processUft3DataType(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::processUft3ErrNumber(const QString& basePath)
|
void MetadataUpdatePage::processUft3Table(const QString& basePath)
|
||||||
{
|
{
|
||||||
qInfo() << "处理UFT30标准错误号";
|
_processor->processUft3Table(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetadataUpdatePage::processUft3Interface(const QString& basePath)
|
void MetadataUpdatePage::processUft3Interface(const QString& basePath)
|
||||||
{
|
{
|
||||||
qInfo() << "处理UFT30接口数据";
|
|
||||||
_processor->processUft3Interfaces(basePath);
|
_processor->processUft3Interfaces(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ private:
|
||||||
|
|
||||||
void processUft3StdFields(const QString& basePath);
|
void processUft3StdFields(const QString& basePath);
|
||||||
void processUft3DataType(const QString& basePath);
|
void processUft3DataType(const QString& basePath);
|
||||||
void processUft3ErrNumber(const QString& basePath);
|
void processUft3Table(const QString& basePath);
|
||||||
void processUft3Interface(const QString& basePath);
|
void processUft3Interface(const QString& basePath);
|
||||||
|
|
||||||
QGridLayout* _updateGridLayout{nullptr};
|
QGridLayout* _updateGridLayout{nullptr};
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include "ElaLineEdit.h"
|
#include "ElaLineEdit.h"
|
||||||
#include "ElaComboBox.h"
|
#include "ElaComboBox.h"
|
||||||
#include "ElaPushButton.h"
|
#include "ElaPushButton.h"
|
||||||
|
#include "src/utils/configmanager.h"
|
||||||
|
|
||||||
SettingsPage::SettingsPage(QWidget *parent)
|
SettingsPage::SettingsPage(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
|
@ -311,7 +312,22 @@ void SettingsPage::onSaveSettings()
|
||||||
QSettings settings("UFT30", "ChangeCode");
|
QSettings settings("UFT30", "ChangeCode");
|
||||||
settings.setValue("Theme", m_themeCombo->currentText());
|
settings.setValue("Theme", m_themeCombo->currentText());
|
||||||
|
|
||||||
saveToConfigIni();
|
ConfigManager* configManager = ConfigManager::instance();
|
||||||
|
|
||||||
|
QString uft30Val = m_uft30PathEdit->text().trimmed().replace("/", "\\");
|
||||||
|
QString uf20Val = m_uf20PathEdit->text().trimmed().replace("/", "\\");
|
||||||
|
QString ufAcct20Val = m_uf20AccountPathEdit->text().trimmed().replace("/", "\\");
|
||||||
|
QString createPathVal = m_outputPathEdit->text().trimmed().replace("/", "\\");
|
||||||
|
|
||||||
|
configManager->setValue("projectPath", "uft30", uft30Val);
|
||||||
|
configManager->setValue("projectPath", "uf20", uf20Val);
|
||||||
|
configManager->setValue("projectPath", "ufAcct20", ufAcct20Val);
|
||||||
|
configManager->setValue("projectPath", "createPath", createPathVal);
|
||||||
|
|
||||||
|
QString uft30PubVal = uft30Val + "\\upub\\dev_codes";
|
||||||
|
configManager->setValue("projectPath", "uft30pub", uft30PubVal);
|
||||||
|
|
||||||
|
configManager->saveConfig();
|
||||||
|
|
||||||
QMessageBox::information(this, "保存成功", "配置已保存!");
|
QMessageBox::information(this, "保存成功", "配置已保存!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
#include "configmanager.h"
|
||||||
|
#include "logmanager.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
ConfigManager* ConfigManager::m_instance = nullptr;
|
||||||
|
|
||||||
|
ConfigManager::ConfigManager(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigManager::~ConfigManager()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigManager* ConfigManager::instance()
|
||||||
|
{
|
||||||
|
if (!m_instance) {
|
||||||
|
m_instance = new ConfigManager();
|
||||||
|
}
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConfigManager::isValidUtf8(const QByteArray& data)
|
||||||
|
{
|
||||||
|
QString test = QString::fromUtf8(data);
|
||||||
|
return test.toUtf8() == data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConfigManager::loadConfig(const QString& basePath)
|
||||||
|
{
|
||||||
|
m_basePath = basePath;
|
||||||
|
QString uf2touft3Path = QDir(basePath).filePath("uf2touft3");
|
||||||
|
m_configFilePath = QDir(uf2touft3Path).filePath("config.ini");
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("========== 加载配置文件 =========="));
|
||||||
|
LogManager::instance()->log(QString("配置文件路径: %1").arg(m_configFilePath));
|
||||||
|
|
||||||
|
QFile file(m_configFilePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
|
LogManager::instance()->logError(QString("无法打开配置文件: %1").arg(m_configFilePath));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray data = file.readAll();
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
QString content;
|
||||||
|
if (isValidUtf8(data)) {
|
||||||
|
content = QString::fromUtf8(data);
|
||||||
|
} else {
|
||||||
|
content = QString::fromLocal8Bit(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_configCache.clear();
|
||||||
|
|
||||||
|
QRegularExpression sectionRegex("\\[(.+?)\\]");
|
||||||
|
QRegularExpression keyValueRegex("^\\s*([^=\\s]+)\\s*=\\s*(.+)$", QRegularExpression::MultilineOption);
|
||||||
|
|
||||||
|
QString currentSection;
|
||||||
|
QStringList lines = content.split('\n');
|
||||||
|
|
||||||
|
for (const QString& line : lines) {
|
||||||
|
QRegularExpressionMatch sectionMatch = sectionRegex.match(line);
|
||||||
|
if (sectionMatch.hasMatch()) {
|
||||||
|
currentSection = sectionMatch.captured(1).trimmed();
|
||||||
|
m_configCache[currentSection] = QMap<QString, QString>();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentSection.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRegularExpressionMatch keyValueMatch = keyValueRegex.match(line);
|
||||||
|
if (keyValueMatch.hasMatch()) {
|
||||||
|
QString key = keyValueMatch.captured(1).trimmed();
|
||||||
|
QString value = keyValueMatch.captured(2).trimmed();
|
||||||
|
value.replace("\\", "/");
|
||||||
|
m_configCache[currentSection][key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager::instance()->log(QString("配置文件加载完成,共 %1 个section").arg(m_configCache.size()));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ConfigManager::getValue(const QString& section, const QString& key, const QString& defaultValue)
|
||||||
|
{
|
||||||
|
if (m_configCache.contains(section) && m_configCache[section].contains(key)) {
|
||||||
|
return m_configCache[section][key];
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigManager::setValue(const QString& section, const QString& key, const QString& value)
|
||||||
|
{
|
||||||
|
m_configCache[section][key] = value;
|
||||||
|
LogManager::instance()->log(QString("配置更新: [%1] %2 = %3").arg(section).arg(key).arg(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConfigManager::saveConfig()
|
||||||
|
{
|
||||||
|
LogManager::instance()->log(QString("========== 保存配置文件 =========="));
|
||||||
|
LogManager::instance()->log(QString("配置文件路径: %1").arg(m_configFilePath));
|
||||||
|
|
||||||
|
QFile file(m_configFilePath);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
LogManager::instance()->logError(QString("无法打开配置文件进行写入: %1").arg(m_configFilePath));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString content;
|
||||||
|
for (const QString& section : m_configCache.keys()) {
|
||||||
|
content += QString("[%1]\n").arg(section);
|
||||||
|
for (const QString& key : m_configCache[section].keys()) {
|
||||||
|
QString value = m_configCache[section][key];
|
||||||
|
value.replace("/", "\\");
|
||||||
|
content += QString("%1=%2\n").arg(key).arg(value);
|
||||||
|
}
|
||||||
|
content += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write(content.toUtf8());
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
LogManager::instance()->log("配置文件保存完成");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ConfigManager::getBasePath() const
|
||||||
|
{
|
||||||
|
return m_basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ConfigManager::getConfigFilePath() const
|
||||||
|
{
|
||||||
|
return m_configFilePath;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef CONFIGMANAGER_H
|
||||||
|
#define CONFIGMANAGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
class ConfigManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
static ConfigManager* instance();
|
||||||
|
|
||||||
|
bool loadConfig(const QString& basePath);
|
||||||
|
|
||||||
|
QString getValue(const QString& section, const QString& key, const QString& defaultValue = QString());
|
||||||
|
void setValue(const QString& section, const QString& key, const QString& value);
|
||||||
|
|
||||||
|
bool saveConfig();
|
||||||
|
|
||||||
|
QString getBasePath() const;
|
||||||
|
QString getConfigFilePath() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit ConfigManager(QObject *parent = nullptr);
|
||||||
|
~ConfigManager();
|
||||||
|
|
||||||
|
bool isValidUtf8(const QByteArray& data);
|
||||||
|
|
||||||
|
QString m_basePath;
|
||||||
|
QString m_configFilePath;
|
||||||
|
QMap<QString, QMap<QString, QString>> m_configCache;
|
||||||
|
|
||||||
|
static ConfigManager* m_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONFIGMANAGER_H
|
||||||
Loading…
Reference in New Issue