Files
datatrace/source/pq_app.h

301 lines
13 KiB
C
Raw Permalink Normal View History

2026-07-10 14:13:02 +08:00
#pragma once
/*
* pq_app.h
*
*
* - interface.cpp Win32 GUI/
* - mq.cpp HTTP /ICD RocketMQ
* - main.cpp JSON/XML Excel 2003 XML .xls
* - icd_mapper.cpp ICD DOI 簿
*
* Win32/RocketMQ
*/
2026-07-10 14:13:02 +08:00
#include <functional>
#include <string>
#include <utility>
#include <vector>
/*
*
*
*
* 1. pqDefaultConfig()
* 2. GUI readConfig()
* 3. 使 main.cpp XML/JSON/origin
*
*
* frontInst/frontIp IP
* terminalStatus JSON "[0]"
* monitorStatus
* icdFlag "1" devType ICD /
* dataStatTopic Topic frontType=cfg_stat_data
* dataRealtimeTopic Topic frontType=cfg_3s_data
* topicAsk/tagAsk/keyAsk cfg_3s_data set_log
* dataTopic/dataTag/dataKey GUI frontType Topic/Tag/Key
* traceRootDir // JSONorigin
*
*
* xmlSaveDirjsonDataPathoriginPathsoutputPathtraceRootDir
*/
2026-07-10 14:13:02 +08:00
struct PqToolConfig {
std::string frontInst = "6c2adb324940e19e208d717f4970f2ee";
std::string frontIp = "192.168.1.68";
std::string terminalStatus = "[0]";
std::string monitorStatus = "[1,2]";
std::string icdFlag = "0";
std::string webDevice = "http://192.168.1.68:10202/nodeDevice/nodeDeviceList";
std::string webIcd = "http://192.168.1.68:10202/icd/icdPathList";
std::string webFiledownload = "http://192.168.1.68:10207/file/download";
std::string xmlSaveDir = "runtime\\downloaded_xml";
std::string producer = "TRACE_PRODUCER";
std::string ipport = "192.168.1.68:9876";
std::string producerAccessKey = "rmqroot";
std::string producerSecretKey = "001@#njcnmq";
std::string topicLOG = "ask_log_Topic";
std::string tagLOG = "6c2adb324940e19e208d717f4970f2ee";
std::string keyLOG = "Test_Keys";
std::string topicAsk = "ask_data_Topic";
std::string tagAsk = "6c2adb324940e19e208d717f4970f2ee";
std::string keyAsk = "Test_Keys";
2026-07-10 14:13:02 +08:00
std::string consumer = "TRACE_CONSUMER";
std::string consumerIpport = "192.168.1.68:9876";
std::string consumerAccessKey = "rmqroot";
std::string consumerSecretKey = "001@#njcnmq";
std::string dataStatTopic = "MQ_INST_1697676490574298_Bm3DLamM%LN_Topic";
std::string dataRealtimeTopic = "MQ_INST_1697676490574298_Bm3DLamM%Real_Time_Data_Topic";
std::string dataTopic = "MQ_INST_1697676490574298_Bm3DLamM%LN_Topic";
std::string dataStatTag = "6c2adb324940e19e208d717f4970f2ee";
std::string dataStatKey = "Test_Keys";
std::string dataRealtimeTag = "6c2adb324940e19e208d717f4970f2ee";
std::string dataRealtimeKey = "Test_Keys";
std::string dataTag = "6c2adb324940e19e208d717f4970f2ee";
std::string dataKey = "Test_Keys";
std::string traceTopic = "Trace_Topic";
std::string traceTag = "6c2adb324940e19e208d717f4970f2ee";
std::string traceKey = "Test_Key";
std::string xmlPath;
std::string jsonDataPath = "runtime\\json\\jsondata.txt";
std::vector<std::string> jsonDataPaths;
std::vector<std::string> originPaths;
std::string outputPath = "runtime\\final_sorted.xls";
std::string traceRootDir = "runtime\\trace_data";
};
/*
*
*
* pqFetchLedgerAndIcd() WebDevice monitorData
* GUI monitor.id MQ
*/
2026-07-10 14:13:02 +08:00
struct PqLedgerMonitor {
std::string id;
std::string name;
std::string lineNo;
std::string voltageLevel;
std::string connectType;
std::string status;
std::vector<std::pair<std::string, std::string>> fields;
};
/*
*
*
* pqFetchLedgerAndIcd() WebDevice data
*
* - GUI processNo -> device -> monitor
* - devType ICD/XML
* - xmlPath 使 XML
*/
2026-07-10 14:13:02 +08:00
struct PqLedgerDevice {
std::string id;
std::string name;
std::string ip;
std::string status;
std::string devType;
std::string devKey;
std::string orgName;
std::string stationName;
std::string subName;
std::string manufacturer;
std::string port;
std::string series;
std::string updateTime;
std::string processNo;
std::string maxProcessNum;
std::string xmlPath;
std::vector<std::pair<std::string, std::string>> fields;
std::vector<PqLedgerMonitor> monitors;
};
// 日志回调业务函数只发字符串GUI/命令行决定显示到日志框还是控制台。
2026-07-10 14:13:02 +08:00
using PqLogFn = std::function<void(const std::string&)>;
/*
* MQ/ GUI
*
* kind:
* sent /
* data DATATopic jsondata
* trace TraceTopic origin/ MMS
*
* path/traceDir GUI
*/
2026-07-10 14:13:02 +08:00
struct PqMqEvent {
std::string kind;
std::string title;
std::string body;
std::string path;
2026-07-13 15:12:55 +08:00
std::string monitorId;
std::string traceDir;
2026-07-10 14:13:02 +08:00
};
using PqMqEventFn = std::function<void(const PqMqEvent&)>;
2026-07-14 17:02:23 +08:00
/**
* @brief
* @details mq.cpp exe runtime GUI
*
* @return HTTPRocketMQTopic/Tag/Key PqToolConfig
*/
2026-07-10 14:13:02 +08:00
PqToolConfig pqDefaultConfig();
/*
* ICD/XML
*
* cfg WebDevice/WebIcd/WebFiledownload
*
* devices
* firstXmlPath XML GUI XML
* return true
*/
2026-07-10 14:13:02 +08:00
bool pqFetchLedgerAndIcd(const PqToolConfig& cfg,
std::vector<PqLedgerDevice>& devices,
std::string& firstXmlPath,
PqLogFn log);
/*
* RocketMQ
*
* TopicTagKeyNameServer
* runtime\json\mq_runtime_config.json
* DLL true mq_outbox_*.jsonl
*/
2026-07-10 14:13:02 +08:00
bool pqInitializeMq(const PqToolConfig& cfg, PqLogFn log, PqMqEventFn event = {});
/*
*
*
*
* device.processNo processNo processNo=0
* monitor.id messageBody.id
* frontType cfg_stat_data cfg_3s_data
* RocketMQ JSON key guidmessageBody JSON
*/
2026-07-10 14:13:02 +08:00
std::string pqBuildTracePayload(const PqToolConfig& cfg,
const PqLedgerDevice& device,
const PqLedgerMonitor& monitor,
const std::string& frontType);
/*
*
*
*
* 1. payload trace_context.json
* 2. sent_trace_request.json last_trace_request.json便
* 3. RocketMQ topicLOG/tagLOG/keyLOG
* 4. cfg_3s_data topicAsk/tagAsk/keyAsk
* 5. RocketMQ Topic mq_outbox_*.jsonl
*/
2026-07-10 14:13:02 +08:00
bool pqSendTraceRequest(const PqToolConfig& cfg,
const PqLedgerDevice& device,
const PqLedgerMonitor& monitor,
const std::string& frontType,
PqLogFn log,
PqMqEventFn event = {});
2026-07-14 17:02:23 +08:00
/**
* @brief /
* @details pqTraceDirectoryFor() txtjsonjsonllog
*
* @param cfg traceRootDir
* @param device
* @param monitor
*/
2026-07-10 14:13:02 +08:00
void pqClearTraceRecords(const PqToolConfig& cfg,
const PqLedgerDevice& device,
const PqLedgerMonitor& monitor);
2026-07-14 17:02:23 +08:00
/**
* @brief
* @details traceRootDir/process_x/device_x/monitor_x
* Windows
*
* @return UTF-8
*/
2026-07-10 14:13:02 +08:00
std::string pqTraceDirectoryFor(const PqToolConfig& cfg,
const PqLedgerDevice& device,
const PqLedgerMonitor& monitor);
2026-07-14 17:02:23 +08:00
/**
* @brief ICD/XML
* @details device.xmlPathicd_response.json cfg.xmlPath
*
* @param cfg XML
* @param device xmlPathdevType
* @return UTF-8
*/
2026-07-10 14:13:02 +08:00
std::string pqFindDeviceXmlPath(const PqToolConfig& cfg, const PqLedgerDevice& device);
/*
* XML + jsondata + origin Excel XML 簿
* vector
*/
2026-07-10 14:13:02 +08:00
bool pqRunParser(const std::string& xmlPath,
const std::string& jsonPath,
const std::vector<std::string>& originPaths,
const std::string& outPath,
std::string* err,
const std::string& frontType = "");
/*
* XML + jsondata + origin Excel XML 簿
*
*
* xmlPath ICD/XML
* jsonPaths DATATopic / DATA_TYPE
* originPaths TraceTopic MMS
* frontType cfg_stat_data/cfg_3s_data
*
* outPath Excel 2003 XML .xls
* err
* return true false
*/
2026-07-10 14:13:02 +08:00
bool pqRunParser(const std::string& xmlPath,
const std::vector<std::string>& jsonPaths,
const std::vector<std::string>& originPaths,
const std::string& outPath,
std::string* err,
const std::string& frontType = "");
/*
* ICD LN/DOI desc 簿
* DO origin
*/
2026-07-13 15:12:55 +08:00
bool pqApplyIcdDescriptionsToWorkbook(const std::string& icdPath,
const std::string& workbookPath,
std::string* message = nullptr);
2026-07-10 14:13:02 +08:00
2026-07-14 17:02:23 +08:00
/**
* @brief Win32
* @details main.cpp AppState
* GetMessage/DispatchMessage interface.cpp::wndProc
* @return 退退
*/
2026-07-10 14:13:02 +08:00
int runPqGuiApp();