From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/CPageGlassList.cpp | 480 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 475 insertions(+), 5 deletions(-)
diff --git a/SourceCode/Bond/Servo/CPageGlassList.cpp b/SourceCode/Bond/Servo/CPageGlassList.cpp
index eabdf81..29b3b23 100644
--- a/SourceCode/Bond/Servo/CPageGlassList.cpp
+++ b/SourceCode/Bond/Servo/CPageGlassList.cpp
@@ -13,6 +13,7 @@
#include <unordered_map>
#include <vector>
#include <string>
+#include <algorithm>
#include "CProcessDataListDlg.h"
#define PAGE_SIZE 50
@@ -99,6 +100,9 @@
// ====== 寮�鍏筹細1=鍚敤鍋囨暟鎹紙鍙浛鎹� DB 鏌ヨ锛夛紱0=鐢ㄧ湡瀹� DB ======
#define USE_FAKE_DB_DEMO 0
+
+// ====== 寮�鍏筹細1=鍚敤妯℃嫙浼犳劅鍣ㄦ暟鎹敓鎴愶紱0=浣跨敤鐪熷疄鏁版嵁 ======
+#define USE_MOCK_SENSOR_DATA 0
#if USE_FAKE_DB_DEMO
#include <ctime>
@@ -372,6 +376,55 @@
return true;
}
+// 杈呭姪鍑芥暟锛氬皢 ANSI CString 鍐欏叆鏂囦欢涓� UTF-8 缂栫爜
+bool CPageGlassList::WriteAnsiStringAsUtf8ToFile(const CString& ansiContent, const CString& filePath)
+{
+ CFile file;
+ if (!file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) {
+ return false;
+ }
+
+ // 鍐欏叆 UTF-8 BOM
+ const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
+ file.Write(bom, 3);
+
+ // 灏� ANSI 杞崲涓� Unicode
+ int unicodeLength = MultiByteToWideChar(CP_ACP, 0,
+ ansiContent, ansiContent.GetLength(),
+ NULL, 0);
+
+ if (unicodeLength <= 0) {
+ file.Close();
+ return false;
+ }
+
+ wchar_t* unicodeBuffer = new wchar_t[unicodeLength + 1];
+ MultiByteToWideChar(CP_ACP, 0,
+ ansiContent, ansiContent.GetLength(),
+ unicodeBuffer, unicodeLength);
+ unicodeBuffer[unicodeLength] = 0;
+
+ // 灏� Unicode 杞崲涓� UTF-8
+ int utf8Length = WideCharToMultiByte(CP_UTF8, 0,
+ unicodeBuffer, unicodeLength,
+ NULL, 0, NULL, NULL);
+
+ bool success = false;
+ if (utf8Length > 0) {
+ char* utf8Buffer = new char[utf8Length];
+ WideCharToMultiByte(CP_UTF8, 0,
+ unicodeBuffer, unicodeLength,
+ utf8Buffer, utf8Length, NULL, NULL);
+
+ file.Write(utf8Buffer, utf8Length);
+ delete[] utf8Buffer;
+ success = true;
+ }
+
+ delete[] unicodeBuffer;
+ file.Close();
+ return success;
+}
// CPageGlassList 瀵硅瘽妗�
@@ -426,6 +479,7 @@
ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CPageGlassList::OnBnClickedButtonPrevPage)
ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CPageGlassList::OnBnClickedButtonNextPage)
ON_NOTIFY(ELCN_SHOWFULLTEXT, IDC_LIST_ALARM, &CPageGlassList::OnShowFullText)
+ ON_BN_CLICKED(IDC_BUTTON_EXPORT_ROW, &CPageGlassList::OnBnClickedButtonExportRow)
END_MESSAGE_MAP()
// ===== 绉佹湁灏忓伐鍏� =====
@@ -1034,9 +1088,10 @@
{
CDialogEx::OnInitDialog();
- // 瀹氭椂鍣細1=鍒濆鍖栬闃咃紝2=鍛ㄦ湡鍒锋柊锛堝彧澧為噺锛�
+ // 瀹氭椂鍣細1=鍒濆鍖栬闃咃紝2=鍛ㄦ湡鍒锋柊锛堝彧澧為噺锛夛紝3=寤惰繜鍔犺浇棣栧睆鏁版嵁
SetTimer(1, 3000, nullptr);
SetTimer(2, 2000, nullptr);
+ SetTimer(3, 10, nullptr);
// 涓嬫媺妗嗘帶浠�
InitStatusCombo();
@@ -1086,7 +1141,6 @@
m_listCtrl.SetPopupFullTextColumns({ 11, 12 });
Resize();
- OnBnClickedButtonSearch(); // 瑙﹀彂涓�娆℃煡璇笌棣栧睆濉厖
return TRUE; // return TRUE unless you set the focus to a control
}
@@ -1146,6 +1200,10 @@
else if (nIDEvent == 2) {
UpdateWipData(); // 鍙仛澧為噺锛屼笉閲嶅缓
}
+ else if (nIDEvent == 3) {
+ KillTimer(3);
+ OnBnClickedButtonSearch(); // 寤惰繜棣栧睆鏌ヨ锛岄伩鍏嶅崱浣� OnInitDialog
+ }
CDialogEx::OnTimer(nIDEvent);
}
@@ -1175,6 +1233,8 @@
void CPageGlassList::OnBnClickedButtonSearch()
{
+ CWaitCursor wait; // 鏄剧ず绛夊緟鍏夋爣锛屾彁绀烘鍦ㄥ姞杞�
+
// 鑾峰彇鍏抽敭瀛楄緭鍏ユ鍐呭
CString strKeyword;
GetDlgItemText(IDC_EDIT_KEYWORD, strKeyword);
@@ -1240,6 +1300,264 @@
}
}
+void CPageGlassList::OnBnClickedButtonExportRow()
+{
+ int nSelected = m_listCtrl.GetSelectionMark();
+ if (nSelected == -1) {
+ AfxMessageBox(_T("璇峰厛閫夋嫨涓�琛岃褰曪紒"));
+ return;
+ }
+
+ // 鐩存帴浠庣涓�鍒楄幏鍙� ID
+ CString strId = m_listCtrl.GetItemText(nSelected, 1);
+
+ if (strId.IsEmpty()) {
+ AfxMessageBox(_T("WIP璁板綍鏆備笉鏀寔淇濆瓨"));
+ return;
+ }
+
+ // 鏁版嵁搴撹褰�
+ long long recordId = _ttoi64(strId);
+
+ // 浠庢暟鎹簱鏌ヨ瀹屾暣璁板綍
+ auto& db = GlassLogDb::Instance();
+ auto row = db.queryById(recordId);
+
+ if (!row) {
+ AfxMessageBox(_T("鏌ヨ璁板綍澶辫触"));
+ return;
+ }
+
+ // 浣跨敤 Glass ID 鏋勫缓榛樿鏂囦欢鍚�
+ CString strDefaultFileName;
+ CString strGlassId = row->classId.c_str();
+
+ // 绉婚櫎鏂囦欢鍚嶄腑鐨勯潪娉曞瓧绗�
+ CString strSanitizedGlassId = strGlassId;
+ strSanitizedGlassId.Remove('\\');
+ strSanitizedGlassId.Remove('/');
+ strSanitizedGlassId.Remove(':');
+ strSanitizedGlassId.Remove('*');
+ strSanitizedGlassId.Remove('?');
+ strSanitizedGlassId.Remove('"');
+ strSanitizedGlassId.Remove('<');
+ strSanitizedGlassId.Remove('>');
+ strSanitizedGlassId.Remove('|');
+
+ strDefaultFileName.Format(_T("Glass_%s.csv"), strSanitizedGlassId);
+
+ // 鏂囦欢淇濆瓨瀵硅瘽妗嗭紝璁剧疆榛樿鏂囦欢鍚�
+ CFileDialog fileDialog(FALSE, _T("csv"), strDefaultFileName,
+ OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ _T("CSV Files (*.csv)|*.csv|JSON Files (*.json)|*.json||"));
+
+ if (fileDialog.DoModal() != IDOK) return;
+
+ CString filePath = fileDialog.GetPathName();
+ CString fileExt = fileDialog.GetFileExt();
+
+ if (fileExt.CompareNoCase(_T("json")) == 0) {
+ ExportToJson(*row, filePath);
+ }
+ else {
+ ExportToCsv(*row, filePath);
+ }
+}
+
+void CPageGlassList::ExportToJson(const GlassLogDb::Row& row, const CString& filePath)
+{
+ // 淇濆瓨涓� JSON
+ if (!row.pretty.empty()) {
+ CFile file;
+ if (file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) {
+ file.Write(row.pretty.c_str(), (UINT)row.pretty.length());
+ file.Close();
+
+ CString strSuccess;
+ strSuccess.Format(_T("璁板綍宸蹭繚瀛樹负JSON鏂囦欢锛歕n%s"), filePath);
+ AfxMessageBox(strSuccess);
+ }
+ else {
+ AfxMessageBox(_T("淇濆瓨鏂囦欢澶辫触"));
+ }
+ }
+ else {
+ AfxMessageBox(_T("璇ヨ褰曟病鏈塉SON鏁版嵁"));
+ }
+}
+
+void CPageGlassList::ExportToCsv(const GlassLogDb::Row& row, const CString& filePath)
+{
+ CString csvContent;
+
+ // === 绗竴閮ㄥ垎锛氬熀纭�淇℃伅 ===
+ ExportBasicInfo(csvContent, row);
+
+ // === 绗簩閮ㄥ垎锛氬伐鑹哄弬鏁� ===
+ ExportProcessParams(csvContent, row);
+
+ // === 绗笁閮ㄥ垎锛氫紶鎰熷櫒鏁版嵁璇︽儏 ===
+ ExportSensorData(csvContent, row);
+
+ // 浣跨敤杈呭姪鍑芥暟淇濆瓨涓� UTF-8 缂栫爜
+ if (WriteAnsiStringAsUtf8ToFile(csvContent, filePath)) {
+ CString strSuccess;
+ strSuccess.Format(_T("璁板綍宸蹭繚瀛樹负CSV鏂囦欢锛歕n%s"), filePath);
+ AfxMessageBox(strSuccess);
+ }
+ else {
+ AfxMessageBox(_T("淇濆瓨鏂囦欢澶辫触"));
+ }
+}
+
+void CPageGlassList::ExportBasicInfo(CString& csvContent, const GlassLogDb::Row& row)
+{
+ csvContent += _T("=== 鍩虹淇℃伅 ===\n");
+ csvContent += _T("ID,Cassette搴忓垪鍙�,Job搴忓垪鍙�,Glass ID,鐗╂枡绫诲瀷,鐘舵��,寮�濮嬫椂闂�,缁撴潫鏃堕棿,缁戝畾Glass ID,AOI缁撴灉,璺緞\n");
+
+ CString baseInfoRow;
+ baseInfoRow.Format(_T("%lld,%d,%d,%s,%d,%d,%s,%s,%s,%d,%s\n"),
+ row.id, row.cassetteSeqNo, row.jobSeqNo,
+ CString(row.classId.c_str()), row.materialType, row.state,
+ CString(row.tStart.c_str()), CString(row.tEnd.c_str()),
+ CString(row.buddyId.c_str()), row.aoiResult,
+ CString(row.path.c_str()));
+ csvContent += baseInfoRow;
+}
+
+void CPageGlassList::ExportProcessParams(CString& csvContent, const GlassLogDb::Row& row)
+{
+ csvContent += _T("\n=== 宸ヨ壓鍙傛暟 ===\n");
+
+ // 濡傛灉鏈� pretty 瀛楁锛岃В鏋愬伐鑹哄弬鏁�
+ if (!row.pretty.empty()) {
+ SERVO::CGlass tempGlass;
+ if (GlassJson::FromString(row.pretty, tempGlass)) {
+ auto& params = tempGlass.getParams();
+ if (!params.empty()) {
+ // 宸ヨ壓鍙傛暟琛ㄥご
+ csvContent += _T("鍙傛暟鍚嶇О,鍙傛暟ID,鏁板��,鏈哄櫒鍗曞厓\n");
+
+ // 宸ヨ壓鍙傛暟鏁版嵁
+ for (auto& param : params) {
+ CString paramRow;
+ CString valueStr;
+
+ // 鏍规嵁鍙傛暟绫诲瀷鏍煎紡鍖栨暟鍊�
+ if (param.getValueType() == PVT_INT) {
+ valueStr.Format(_T("%d"), param.getIntValue());
+ }
+ else {
+ valueStr.Format(_T("%.3f"), param.getDoubleValue());
+ }
+
+ paramRow.Format(_T("%s,%s,%s,%s\n"),
+ CString(param.getName().c_str()),
+ CString(param.getId().c_str()),
+ valueStr,
+ CString(param.getUnit().c_str()));
+
+ csvContent += paramRow;
+ }
+ }
+ else {
+ csvContent += _T("鏃犲伐鑹哄弬鏁版暟鎹甛n");
+ }
+ }
+ else {
+ csvContent += _T("鏃犳硶瑙f瀽宸ヨ壓鍙傛暟\n");
+ }
+ }
+ else {
+ csvContent += _T("鏃犲伐鑹哄弬鏁版暟鎹甛n");
+ }
+}
+
+void CPageGlassList::ExportSensorData(CString& csvContent, const GlassLogDb::Row& row)
+{
+ csvContent += _T("\n=== 浼犳劅鍣ㄦ暟鎹鎯� ===\n");
+
+ // 濡傛灉鏈� pretty 瀛楁锛岃В鏋愪紶鎰熷櫒鏁版嵁
+ if (!row.pretty.empty()) {
+ SERVO::CGlass tempGlass;
+ if (GlassJson::FromString(row.pretty, tempGlass)) {
+#if USE_MOCK_SENSOR_DATA
+ // 鐢熸垚妯℃嫙鐨凷VData鐢ㄤ簬娴嬭瘯
+ GenerateMockSVData(tempGlass);
+#endif
+ // 瀵规瘡涓満鍣ㄧ敓鎴愯〃鏍�
+ for (const auto& machinePair : tempGlass.getAllSVData()) {
+ int machineId = machinePair.first;
+ const auto& dataByType = machinePair.second;
+ CString machineName = CString(SERVO::CServoUtilsTool::getEqName(machineId).c_str());
+
+ csvContent += _T("\n[") + machineName + _T("]\n");
+
+ if (dataByType.empty()) {
+ csvContent += _T("No sensor data\n");
+ continue;
+ }
+
+ auto columnOrder = getMachineColumnOrder(machineId, &dataByType);
+ if (columnOrder.empty()) {
+ csvContent += _T("No exportable columns\n");
+ continue;
+ }
+
+ CString header = _T("Timestamp(ms),LocalTime");
+ for (const auto& dataType : columnOrder) {
+ header += _T(",");
+ header += CString(dataType.c_str());
+ }
+ header += _T("\n");
+ csvContent += header;
+
+ auto baselineIt = std::find_if(columnOrder.begin(), columnOrder.end(),
+ [&](const std::string& type) {
+ auto dataIt = dataByType.find(type);
+ return dataIt != dataByType.end() && !dataIt->second.empty();
+ });
+ if (baselineIt == columnOrder.end()) {
+ csvContent += _T("No usable time series\n");
+ continue;
+ }
+
+ const auto& timeSeries = dataByType.at(*baselineIt);
+ for (size_t i = 0; i < timeSeries.size(); ++i) {
+ auto timestamp = timeSeries[i].timestamp;
+ auto ms = timePointToMs(timestamp);
+ CString row;
+ row.Format(_T("%lld,"), ms);
+
+ CString localTime = CString(timePointToString(timestamp).c_str());
+ row += localTime;
+
+ for (const auto& dataType : columnOrder) {
+ row += _T(",");
+ auto dataTypeIt = dataByType.find(dataType);
+ if (dataTypeIt != dataByType.end() && i < dataTypeIt->second.size()) {
+ CString valueStr;
+ valueStr.Format(_T("%.3f"), dataTypeIt->second[i].value);
+ row += valueStr;
+ }
+ else {
+ row += _T("N/A");
+ }
+ }
+ row += _T("\n");
+ csvContent += row;
+ }
+ }
+ }
+ else {
+ csvContent += _T("鏃犳硶瑙f瀽浼犳劅鍣ㄦ暟鎹甛n");
+ }
+ }
+ else {
+ csvContent += _T("鏃犱紶鎰熷櫒鏁版嵁\n");
+ }
+}
+
void CPageGlassList::OnBnClickedButtonPrevPage()
{
if (m_nCurPage > 1) {
@@ -1261,9 +1579,14 @@
auto* p = reinterpret_cast<NMC_ELC_SHOWFULLTEXT*>(pNMHDR);
// 瀵硅瘽妗嗘樉绀哄伐鑹哄弬鏁�
- CProcessDataListDlg dlg;
- dlg.setRawText(p->text);
- dlg.DoModal();
+ if (p->iSubItem == 12) {
+ CProcessDataListDlg dlg;
+ dlg.setRawText(p->text);
+ dlg.DoModal();
+ }
+ else {
+ AfxMessageBox(p->text);
+ }
*pResult = 0;
}
@@ -1596,3 +1919,150 @@
return CDialogEx::PreTranslateMessage(pMsg);
}
+
+// 鑾峰彇鏈哄櫒棰勫畾涔夌殑鍒楅『搴�
+std::vector<std::string> CPageGlassList::getMachineColumnOrder(int machineId,
+ const std::unordered_map<std::string, std::vector<SERVO::SVDataItem>>* actualData)
+{
+ std::vector<std::string> columnOrder;
+ auto dataTypes = SERVO::CServoUtilsTool::getEqDataTypes();
+ auto it = dataTypes.find(machineId);
+
+ if (actualData != nullptr) {
+ if (it != dataTypes.end()) {
+ for (const auto& name : it->second) {
+ if (actualData->find(name) != actualData->end()) {
+ columnOrder.push_back(name);
+ }
+ }
+ }
+ for (const auto& kv : *actualData) {
+ if (std::find(columnOrder.begin(), columnOrder.end(), kv.first) == columnOrder.end()) {
+ columnOrder.push_back(kv.first);
+ }
+ }
+ return columnOrder;
+ }
+
+ if (it != dataTypes.end()) {
+ columnOrder = it->second;
+ }
+ return columnOrder;
+}
+
+// 鏃堕棿鎴宠浆鎹负瀛楃涓�
+std::string CPageGlassList::timePointToString(const std::chrono::system_clock::time_point& tp)
+{
+ auto time_t = std::chrono::system_clock::to_time_t(tp);
+ std::tm tm;
+ localtime_s(&tm, &time_t);
+ char buffer[20];
+ std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm);
+ return buffer;
+}
+
+// 鏃堕棿鎴宠浆鎹负姣
+int64_t CPageGlassList::timePointToMs(const std::chrono::system_clock::time_point& tp)
+{
+ return std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch()).count();
+}
+
+// 鐢熸垚妯℃嫙鐨凷VData鐢ㄤ簬娴嬭瘯
+void CPageGlassList::GenerateMockSVData(SERVO::CGlass& glass)
+{
+ // 鑾峰彇璁惧鏁版嵁绫诲瀷閰嶇疆
+ auto& dataTypes = SERVO::CServoUtilsTool::getEqDataTypes();
+
+ // 涓烘瘡涓澶囩敓鎴愭ā鎷熸暟鎹�
+ for (const auto& machinePair : dataTypes) {
+ int machineId = machinePair.first;
+ const auto& dataTypeList = machinePair.second;
+ std::vector<std::string> filteredTypes;
+
+ if (machineId == EQ_ID_VACUUMBAKE || machineId == EQ_ID_BAKE_COOLING) {
+ const char activePrefix = 'A';
+ for (const auto& dataType : dataTypeList) {
+ if (!dataType.empty() && dataType[0] == activePrefix) {
+ filteredTypes.push_back(dataType);
+ }
+ }
+ }
+
+ const auto& typeList = filteredTypes.empty() ? dataTypeList : filteredTypes;
+
+ // 鐢熸垚鏃堕棿搴忓垪锛氫粠褰撳墠鏃堕棿寰�鍓嶆帹10鍒嗛挓锛屾瘡1绉掍竴涓暟鎹偣
+ auto now = std::chrono::system_clock::now();
+ auto startTime = now - std::chrono::minutes(10);
+
+ // 涓烘瘡涓暟鎹被鍨嬬敓鎴愭ā鎷熸暟鎹�
+ for (const auto& dataType : typeList) {
+ std::vector<SERVO::SVDataItem> mockData;
+
+ // 鐢熸垚600涓暟鎹偣锛�10鍒嗛挓 * 60涓偣/鍒嗛挓锛�
+ for (int i = 0; i < 600; ++i) {
+ auto timestamp = startTime + std::chrono::seconds(i * 1);
+
+ // 鏍规嵁璁惧绫诲瀷鍜屾暟鎹被鍨嬬敓鎴愪笉鍚岀殑妯℃嫙鍊�
+ double value = GenerateMockValue(machineId, dataType, i);
+
+ mockData.emplace_back(timestamp, value);
+ }
+
+ // 灏嗘ā鎷熸暟鎹坊鍔犲埌glass瀵硅薄涓�
+ glass.addSVData(machineId, dataType, mockData);
+ }
+ }
+}
+
+// 鏍规嵁璁惧绫诲瀷鍜屾暟鎹被鍨嬬敓鎴愭ā鎷熸暟鍊�
+double CPageGlassList::GenerateMockValue(int machineId, const std::string& dataType, int index)
+{
+ // 鍩虹鍊艰寖鍥�
+ double baseValue = 0.0;
+ double variation = 0.0;
+
+ // 鏍规嵁璁惧绫诲瀷璁剧疆鍩虹鍊�
+ switch (machineId) {
+ case EQ_ID_Bonder1:
+ case EQ_ID_Bonder2:
+ if (dataType.find("鍘嬪姏") != std::string::npos) {
+ baseValue = 50.0; // 鍘嬪姏鍩虹鍊�
+ variation = 10.0; // 鍘嬪姏鍙樺寲鑼冨洿
+ } else if (dataType.find("娓╁害") != std::string::npos) {
+ baseValue = 180.0; // 娓╁害鍩虹鍊�
+ variation = 5.0; // 娓╁害鍙樺寲鑼冨洿
+ } else if (dataType.find("鎵╁睍鍊�") != std::string::npos) {
+ baseValue = 100.0; // 鎵╁睍鍊煎熀纭�鍊�
+ variation = 15.0; // 鎵╁睍鍊煎彉鍖栬寖鍥�
+ }
+ break;
+
+ case EQ_ID_VACUUMBAKE:
+ if (dataType.find("鎵╁睍鍊�") != std::string::npos) {
+ baseValue = 80.0;
+ variation = 12.0;
+ } else if (dataType.find("娓╁害") != std::string::npos) {
+ baseValue = 200.0;
+ variation = 8.0;
+ }
+ break;
+
+ case EQ_ID_BAKE_COOLING:
+ if (dataType.find("娓╁害") != std::string::npos) {
+ baseValue = 25.0; // 鍐峰嵈娓╁害
+ variation = 3.0;
+ }
+ break;
+
+ default:
+ baseValue = 50.0;
+ variation = 5.0;
+ break;
+ }
+
+ // 娣诲姞鏃堕棿鐩稿叧鐨勮秼鍔垮拰闅忔満鍙樺寲
+ double timeTrend = sin(index * 0.1) * 2.0; // 姝e鸡娉㈣秼鍔�
+ double randomNoise = (rand() % 100 - 50) / 100.0 * variation * 0.3; // 闅忔満鍣0
+
+ return baseValue + timeTrend + randomNoise;
+}
--
Gitblit v1.9.3