Browse Source

add storage in realtime

storage-in-realtime
zhaohe 11 months ago
parent
commit
e1a0783aa7
  1. 3
      .vscode/settings.json
  2. 20
      appdep/iflytop/core/components/zcsv/zstream_csv_writer.cpp
  3. 34
      appdep/iflytop/core/components/zcsv/zstream_csv_writer.hpp
  4. 35
      appsrc/service/disinfection_logs_service.cpp
  5. 14
      appsrc/service/disinfection_logs_service.hpp

3
.vscode/settings.json

@ -70,6 +70,7 @@
"any": "cpp",
"unordered_set": "cpp",
"csignal": "cpp",
"zh2o2_computer.h": "c"
"zh2o2_computer.h": "c",
"zstream_csvhcpp": "cpp"
}
}

20
appdep/iflytop/core/components/zcsv/zstream_csv_writer.cpp

@ -0,0 +1,20 @@
#include "zstream_csv_writer.hpp"
using namespace std;
using namespace iflytop;
void ZStreamCSVWriter::addColumn(string key) { columns.push_back(key); }
void ZStreamCSVWriter::setValue(string key, string value) { //
onelineDataCache[key] = value;
}
void ZStreamCSVWriter::addNewLine() {
outfile << endl;
for (auto& col : columns) {
if (onelineDataCache.find(col) == onelineDataCache.end()) {
outfile << ",";
} else {
outfile << onelineDataCache[col] << ",";
}
}
onelineDataCache.clear();
}

34
appdep/iflytop/core/components/zcsv/zstream_csv_writer.hpp

@ -0,0 +1,34 @@
#pragma once
#include <fstream>
#include <fstream> // 引入文件流库
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
namespace iflytop {
using namespace std;
class ZStreamCSVWriter {
private:
list<string> columns;
map<string, string> onelineDataCache;
ofstream outfile;
public:
ZStreamCSVWriter(string filename) : outfile(filename) {};
void addColumn(string key);
void storageColumns();
void setValue(string key, string value);
void addNewLine();
};
} // namespace iflytop

35
appsrc/service/disinfection_logs_service.cpp

@ -207,6 +207,9 @@ void DisinfectionLogsService::initialize() {
// TODO: 检查指令iconv是否可用
/**
* @brief
*/
AppEventBus::ins()->onEvent.connect([this](shared_ptr<IAppEvent> event) {
if (auto e = dynamic_pointer_cast<AppDisinfectionStartEvent>(event); e) {
// logger->info("DisinfectionLogsService: start new disinfection session");
@ -227,8 +230,6 @@ void DisinfectionLogsService::initialize() {
}
});
// m_recordFiles
/**
* @brief
*/
@ -252,22 +253,23 @@ void DisinfectionLogsService::onAppDisinfectionStartEvent(string sessionId) { /
}
void DisinfectionLogsService::onAppDisinfectionSnapshotEvent(shared_ptr<DisinfectionStateSnapshot> snapshot) { m_snapshots.push_back(snapshot); }
void DisinfectionLogsService::onAppDisinfectionFinishedEvent(shared_ptr<DisinfectionStatistics> statistics) {
clearRecordFiles();
m_statistics = statistics;
dumpDisinfectionRecord(m_sessionId, m_snapshots);
dumpDisinfectionToPrinterLog(m_sessionId, m_snapshots);
m_recordFiles.remove_if([this](const string& s) { return s == m_sessionId; }); // 删除已经存在的记录
m_recordFiles.push_back(m_sessionId);
// clearRecordFiles();
// dumpDisinfectionRecord(m_sessionId, m_snapshots);
// dumpDisinfectionToPrinterLog(m_sessionId, m_snapshots);
// m_recordFiles.remove_if([this](const string& s) { return s == m_sessionId; }); // 删除已经存在的记录
// m_recordFiles.push_back(m_sessionId);
/**
* @brief
* 1.
* 2.PDF文件缓存
*/
if (printfLogWhenDisinfectionFinished) printRecordFile(m_sessionId);
// if (printfLogWhenDisinfectionFinished) printRecordFile(m_sessionId);
}
#if 0
/**
* @brief csv文件
*
@ -470,6 +472,9 @@ void DisinfectionLogsService::dumpDisinfectionToPrinterLog(string sessionId, lis
pdfwriter.dump();
}
void DisinfectionLogsService::dumpDisinfectionToPrinterPdf(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots) {}
#endif
#if 0
/**
* @brief ,
*/
@ -505,6 +510,7 @@ void DisinfectionLogsService::clearRecordFiles() {
m_recordFiles.clear();
}
}
#endif
void DisinfectionLogsService::deleteRecordFile(string file) {
string filepath = fmt::format("{}{}.*", LOG_STORGE_PATH, file);
dosystem(fmt::format("rm -rf {}", filepath));
@ -564,7 +570,8 @@ int32_t DisinfectionLogsService::exportDisinfectionData(vector<string> files) {
/**********************************拷贝PDF**********************************/
// 拷贝pdf文件
dosystem(fmt::format("cp -rf /app/disinfection_logs/{}.pdf {}", file, EXPORT_PATH));
// TODO: 生成pdf,并导出pdf
// dosystem(fmt::format("cp -rf /app/disinfection_logs/{}.pdf {}", file, EXPORT_PATH));
}
// 卸载目录
@ -639,7 +646,11 @@ void DisinfectionLogsService::printRecord(shared_ptr<MsgProcessContext> cxt, str
printRecordFile(logName);
}
chrono::system_clock::time_point time_point_increment(chrono::system_clock::time_point& tp, int seconds) {
/*******************************************************************************
* 使 *
*******************************************************************************/
static chrono::system_clock::time_point time_point_increment(chrono::system_clock::time_point& tp, int seconds) {
tp += chrono::seconds(seconds);
return tp;
}

14
appsrc/service/disinfection_logs_service.hpp

@ -35,6 +35,7 @@ class DisinfectionLogsService : public enable_shared_from_this<DisinfectionLogsS
bool printfLogWhenDisinfectionFinished = true;
//
public:
DisinfectionLogsService();
void initialize();
@ -45,10 +46,11 @@ class DisinfectionLogsService : public enable_shared_from_this<DisinfectionLogsS
void onAppDisinfectionFinishedEvent(shared_ptr<DisinfectionStatistics> statistics);
private:
void dumpDisinfectionRecord(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots);
void dumpDisinfectionToPrinterLog(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots);
void dumpDisinfectionToPrinterPdf(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots);
// void dumpDisinfectionRecord(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots);
// void dumpDisinfectionToPrinterLog(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots);
// void dumpDisinfectionToPrinterPdf(string sessionId, list<shared_ptr<DisinfectionStateSnapshot>> snapshots);
private:
/*******************************************************************************
* *
@ -66,9 +68,9 @@ class DisinfectionLogsService : public enable_shared_from_this<DisinfectionLogsS
private:
int32_t exportDisinfectionData(vector<string> files);
void clearRecordFiles();
void deleteRecordFile(string file);
void printRecordFile(string file);
// void clearRecordFiles();
void deleteRecordFile(string file);
void printRecordFile(string file);
bool dosystem(string cmd);

Loading…
Cancel
Save