Browse Source

添加消毒日志打印服务

storage-in-realtime
zhaohe 12 months ago
parent
commit
960cdeac3d
  1. 4
      appdep/iflytop/core/components/zcsv/zcsv.cpp
  2. 176
      appsrc/service/disinfection_logs_service.cpp
  3. 2
      appsrc/service/disinfection_logs_service.hpp

4
appdep/iflytop/core/components/zcsv/zcsv.cpp

@ -139,7 +139,7 @@ void ZCSV::dumpCSV(string filename) {
} }
void ZCSV::addValue(string key, string value) { void ZCSV::addValue(string key, string value) {
printf("addValue key=%s value=%s\n", key.c_str(), value.c_str());
// printf("addValue key=%s value=%s\n", key.c_str(), value.c_str());
// 查找0行的key是否存在 // 查找0行的key是否存在
int keyColNum = -1; int keyColNum = -1;
for (int i = 0; i <= m_maxColNum; i++) { for (int i = 0; i <= m_maxColNum; i++) {
@ -171,7 +171,7 @@ void ZCSV::addValue(string key, string value) {
lastRowNum = m_maxRowNum; lastRowNum = m_maxRowNum;
} }
printf("lastRowNum=%d m_maxRowNum:%d keyColNum:%d\n", lastRowNum, m_maxRowNum, keyColNum);
// printf("lastRowNum=%d m_maxRowNum:%d keyColNum:%d\n", lastRowNum, m_maxRowNum, keyColNum);
setdata(keyColNum, lastRowNum + 1, value); setdata(keyColNum, lastRowNum + 1, value);
} }

176
appsrc/service/disinfection_logs_service.cpp

@ -53,13 +53,7 @@ static string formattimeS(int sec) {
return fmt::format("N/A"); return fmt::format("N/A");
} }
} }
static string formatSensorVal(int val) {
if (val < 0) {
return fmt::format("N/A");
} else {
return fmt::format("{}", val);
}
}
static string formatSensorVal(int val) { return fmt::format("{}", val); }
static string format_zsystem_tp(zsystem_tp tp) { static string format_zsystem_tp(zsystem_tp tp) {
time_t time = system_clock().to_time_t(tp); time_t time = system_clock().to_time_t(tp);
struct tm tm = {0}; struct tm tm = {0};
@ -246,6 +240,8 @@ void DisinfectionLogsService::onAppDisinfectionStartEvent(string sessionId) { /
} }
void DisinfectionLogsService::onAppDisinfectionSnapshotEvent(shared_ptr<DisinfectionStateSnapshot> snapshot) { m_snapshots.push_back(snapshot); } void DisinfectionLogsService::onAppDisinfectionSnapshotEvent(shared_ptr<DisinfectionStateSnapshot> snapshot) { m_snapshots.push_back(snapshot); }
void DisinfectionLogsService::onAppDisinfectionFinishedEvent(shared_ptr<DisinfectionStatistics> statistics) { void DisinfectionLogsService::onAppDisinfectionFinishedEvent(shared_ptr<DisinfectionStatistics> statistics) {
clearRecordFiles();
m_statistics = statistics; m_statistics = statistics;
dumpDisinfectionRecord(m_sessionId, m_snapshots); dumpDisinfectionRecord(m_sessionId, m_snapshots);
dumpDisinfectionToPrinterLog(m_sessionId, m_snapshots); dumpDisinfectionToPrinterLog(m_sessionId, m_snapshots);
@ -255,7 +251,6 @@ void DisinfectionLogsService::onAppDisinfectionFinishedEvent(shared_ptr<Disinfec
* 1. * 1.
* 2.PDF文件缓存 * 2.PDF文件缓存
*/ */
clearRecordFiles();
} }
/** /**
@ -292,7 +287,11 @@ void DisinfectionLogsService::dumpDisinfectionRecord(string sessionId, list<shar
lastlogtime = s->time; lastlogtime = s->time;
csv.addValue(m_csvHeaderDict.getChName(CSVHeader::time), /******************/ tu_sys::fmt(s->time, "%Y-%m-%d %H:%M:%S")); csv.addValue(m_csvHeaderDict.getChName(CSVHeader::time), /******************/ tu_sys::fmt(s->time, "%Y-%m-%d %H:%M:%S"));
csv.addValue(m_csvHeaderDict.getChName(CSVHeader::state), /*****************/ m_dmStateDict.getChName(s->state));
if (s->state == DisinfectionState::error) {
csv.addValue(m_csvHeaderDict.getChName(CSVHeader::state), /*****************/ m_dmStateDict.getChName(s->state) + ":" + ecode2str(s->ecode));
} else {
csv.addValue(m_csvHeaderDict.getChName(CSVHeader::state), /*****************/ m_dmStateDict.getChName(s->state));
}
auto h2o2data = s->h2o2Snapshot; auto h2o2data = s->h2o2Snapshot;
for (int i = 0; i < h2o2data->getSensorDataNum(); i++) { for (int i = 0; i < h2o2data->getSensorDataNum(); i++) {
@ -346,14 +345,14 @@ void DisinfectionLogsService::dumpDisinfectionToPrinterLog(string sessionId, lis
content += fmt::format("= = = = = = = = = = = = = = = \n"); content += fmt::format("= = = = = = = = = = = = = = = \n");
content += fmt::format(" 全思美特 \n"); content += fmt::format(" 全思美特 \n");
content += fmt::format("操作人 {}\n", GET_SERVICE(DeviceStateService)->getLoginUid());
content += fmt::format("开始时间 {}\n", format_zsystem_tp(m_statistics->start_tp));
content += fmt::format("结束时间 {}\n", format_zsystem_tp(m_statistics->complete_tp));
content += fmt::format("总耗时(hh:mm::ss) {}:{}:{}\n", total_hours, total_mins, total_secs);
content += fmt::format("消毒液使用 {}g\n", m_statistics->disinfectantVolume_g);
content += fmt::format("目标LOG {}\n", m_statistics->tLog);
content += fmt::format("实际LOG {}\n", m_statistics->finalLog);
content += fmt::format("日志打印间隔: {}min\n", logdtime / 60);
content += fmt::format("操作人员: {}\n", GET_SERVICE(DeviceStateService)->getLoginUid());
content += fmt::format("开始时间: {}\n", format_zsystem_tp(m_statistics->start_tp));
content += fmt::format("结束时间: {}\n", format_zsystem_tp(m_statistics->complete_tp));
content += fmt::format("总耗时: {}:{}:{}\n", total_hours, total_mins, total_secs);
content += fmt::format("目标LOG: {}\n", m_statistics->tLog);
content += fmt::format("实际LOG: {}\n", m_statistics->finalLog);
content += fmt::format("消毒液使用: {}g\n", m_statistics->disinfectantVolume_g);
content += fmt::format("日志打印间隔: {}min\n", logdtime / 60);
content += fmt::format("= = = = = = = = = = = = = = = \n"); content += fmt::format("= = = = = = = = = = = = = = = \n");
DisinfectionState state = DisinfectionState::idle; DisinfectionState state = DisinfectionState::idle;
@ -373,36 +372,44 @@ void DisinfectionLogsService::dumpDisinfectionToPrinterLog(string sessionId, lis
if (tu_sys().dToS(snapshot->time - lastlogtime) > logdtime) logthis = true; if (tu_sys().dToS(snapshot->time - lastlogtime) > logdtime) logthis = true;
if (!logthis) continue; if (!logthis) continue;
state = snapshot->state;
content += fmt::format("{}\n", format_zsystem_tp(snapshot->time));
if (stateChanged) {
content += fmt::format("{}\n", m_dmStateDict.getChName(snapshot->state));
}
state = snapshot->state;
first = false;
lastlogtime = snapshot->time;
if (state == DisinfectionState::disinfection) { if (state == DisinfectionState::disinfection) {
content += fmt::format("{}\n", format_zsystem_tp(snapshot->time));
if (stateChanged) content += fmt::format("{}\n", m_dmStateDict.getChName(snapshot->state));
content += fmt::format("LOG: {}\n", snapshot->nlog); content += fmt::format("LOG: {}\n", snapshot->nlog);
}
if (state == DisinfectionState::disinfection) {
auto h2o2data = snapshot->h2o2Snapshot; auto h2o2data = snapshot->h2o2Snapshot;
for (int i = 0; i < h2o2data->getSensorDataNum(); i++) { for (int i = 0; i < h2o2data->getSensorDataNum(); i++) {
if (i == 0) { if (i == 0) {
content += fmt::format(" [S0] {}ppm {}%RS {}%RH \n", h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->h2o2[0]), //
h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->saturation[0]), //
content += fmt::format(" [S0] {}(ppm) {}(%RS) {}(%RH) \n", h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->h2o2[0]), //
h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->saturation[0]), //
h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->humid[0])); h2o2data->isExpired[0] ? "N/A" : formatSensorVal(h2o2data->humid[0]));
} }
if (i == 1 && !h2o2data->isExpired[1]) { if (i == 1 && !h2o2data->isExpired[1]) {
content += fmt::format(" [S1] {}ppm {}%RS {}%RH \n", formatSensorVal(h2o2data->h2o2[1]), //
formatSensorVal(h2o2data->saturation[1]), //
content += fmt::format(" [S1] {}(ppm) {}(%RS) {}(%RH) \n", formatSensorVal(h2o2data->h2o2[1]), //
formatSensorVal(h2o2data->saturation[1]), //
formatSensorVal(h2o2data->humid[1])); formatSensorVal(h2o2data->humid[1]));
} }
if (i == 2 && !h2o2data->isExpired[2]) { if (i == 2 && !h2o2data->isExpired[2]) {
content += fmt::format(" [S2] {}ppm {}%RS {}%RH \n", formatSensorVal(h2o2data->h2o2[2]), //
formatSensorVal(h2o2data->saturation[2]), //
content += fmt::format(" [S2] {}(ppm) {}(%RS) {}(%RH) \n", formatSensorVal(h2o2data->h2o2[2]), //
formatSensorVal(h2o2data->saturation[2]), //
formatSensorVal(h2o2data->humid[2])); formatSensorVal(h2o2data->humid[2]));
} }
} }
} else if (state == DisinfectionState::error) {
content += fmt::format("{}\n", format_zsystem_tp(snapshot->time));
content += fmt::format("{}\n", m_dmStateDict.getChName(snapshot->state));
content += fmt::format(" 错误:{}\n", ecode2str(snapshot->ecode));
} else {
if (stateChanged) {
content += fmt::format("{}\n", format_zsystem_tp(snapshot->time));
content += fmt::format("{}\n", m_dmStateDict.getChName(snapshot->state));
}
} }
} }
content += ("\n"); content += ("\n");
@ -562,54 +569,81 @@ void DisinfectionLogsService::fn_printRecord(shared_ptr<MsgProcessContext> cxt)
// //
} }
chrono::system_clock::time_point time_point_increment(chrono::system_clock::time_point& tp, int seconds) {
tp += chrono::seconds(seconds);
return tp;
}
void DisinfectionLogsService::fn_selftest(shared_ptr<MsgProcessContext> cxt) { void DisinfectionLogsService::fn_selftest(shared_ptr<MsgProcessContext> cxt) {
string ssid = createDisinfectionID(); string ssid = createDisinfectionID();
onAppDisinfectionStartEvent(ssid); onAppDisinfectionStartEvent(ssid);
auto now = zsystem_clock().now();
auto start_tp = now;
int sensorNum = 3;
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(now, DisinfectionState::idle, sensorNum, true));
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::idle, sensorNum, false));
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::init, sensorNum, false));
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::preheat, sensorNum, false));
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::disinfection, sensorNum, false));
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::disinfection, sensorNum, true));
for (int i = 0; i < 600; i++) {
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::disinfection, sensorNum, false));
}
for (int i = 0; i < 600; i++) {
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::degradation, sensorNum, false));
}
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::dehumidificationBeforeDisinfection, sensorNum, false));
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::dehumidificationAfterDisinfection, sensorNum, false));
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::emptyLiquidFromTheLine, sensorNum, false));
auto esnap = selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::error, sensorNum, false);
esnap->ecode = err::kappe_the_bottom_of_the_device_has_water;
onAppDisinfectionSnapshotEvent(esnap);
onAppDisinfectionSnapshotEvent(selftest_createFakeSnapshot(time_point_increment(now, 10), DisinfectionState::finished, sensorNum, false));
shared_ptr<DisinfectionStatistics> statistics = make_shared<DisinfectionStatistics>();
statistics->start_tp = start_tp;
statistics->complete_tp = now;
statistics->disinfectantVolume_g = 100;
statistics->tLog = 10;
statistics->finalLog = 9;
onAppDisinfectionFinishedEvent(statistics);
}
shared_ptr<DisinfectionStateSnapshot> DisinfectionLogsService::selftest_createFakeSnapshot(zsystem_tp time, DisinfectionState state, int sensorNum, bool forceLog) {
shared_ptr<H2O2SensorDataSnapshot> h2o2Snapshot = make_shared<H2O2SensorDataSnapshot>(); shared_ptr<H2O2SensorDataSnapshot> h2o2Snapshot = make_shared<H2O2SensorDataSnapshot>();
h2o2Snapshot->h2o2.push_back(0.1);
h2o2Snapshot->h2o2.push_back(0.2);
h2o2Snapshot->h2o2.push_back(0.3);
h2o2Snapshot->humid.push_back(0.4);
h2o2Snapshot->humid.push_back(0.5);
h2o2Snapshot->humid.push_back(0.6);
h2o2Snapshot->temp.push_back(0.7);
h2o2Snapshot->temp.push_back(0.8);
h2o2Snapshot->temp.push_back(0.9);
h2o2Snapshot->saturation.push_back(1.0);
h2o2Snapshot->saturation.push_back(1.1);
h2o2Snapshot->saturation.push_back(1.2);
h2o2Snapshot->isExpired.push_back(false);
h2o2Snapshot->isExpired.push_back(false);
h2o2Snapshot->isExpired.push_back(false);
h2o2Snapshot->minH2O2 = 10;
h2o2Snapshot->maxH2O2 = 20;
h2o2Snapshot->maxHumid = 30;
h2o2Snapshot->maxSaturation = 40;
h2o2Snapshot->h2o2.push_back(rand() % 100 / 2.0);
h2o2Snapshot->h2o2.push_back(rand() % 100 / 2.0);
h2o2Snapshot->h2o2.push_back(rand() % 100 / 2.0);
h2o2Snapshot->humid.push_back(rand() % 100 / 2.0);
h2o2Snapshot->humid.push_back(rand() % 100 / 2.0);
h2o2Snapshot->humid.push_back(rand() % 100 / 2.0);
h2o2Snapshot->temp.push_back(rand() % 100 / 2.0);
h2o2Snapshot->temp.push_back(rand() % 100 / 2.0);
h2o2Snapshot->temp.push_back(rand() % 100 / 2.0);
h2o2Snapshot->saturation.push_back(rand() % 100 / 2.0);
h2o2Snapshot->saturation.push_back(rand() % 100 / 2.0);
h2o2Snapshot->saturation.push_back(rand() % 100 / 2.0);
h2o2Snapshot->isExpired.push_back(!(sensorNum >= 1));
h2o2Snapshot->isExpired.push_back(!(sensorNum >= 2));
h2o2Snapshot->isExpired.push_back(!(sensorNum >= 3));
h2o2Snapshot->minH2O2 = rand() % 100 / 2.0;
h2o2Snapshot->maxH2O2 = rand() % 100 / 2.0;
h2o2Snapshot->maxHumid = rand() % 100 / 2.0;
h2o2Snapshot->maxSaturation = rand() % 100 / 2.0;
shared_ptr<DisinfectionStateSnapshot> snapshot = make_shared<DisinfectionStateSnapshot>(); shared_ptr<DisinfectionStateSnapshot> snapshot = make_shared<DisinfectionStateSnapshot>();
snapshot->state = DisinfectionState::disinfection;
snapshot->time = zsystem_clock().now();
snapshot->state = state;
snapshot->time = time;
snapshot->h2o2Snapshot = h2o2Snapshot; snapshot->h2o2Snapshot = h2o2Snapshot;
snapshot->forcelog = false;
snapshot->dval = 0;
snapshot->nlog = 0;
snapshot->tlog = 0;
snapshot->remainDisinfectant = 0;
snapshot->remainTime = 0;
snapshot->forcelog = forceLog;
snapshot->dval = rand() % 100 / 2.0;
snapshot->nlog = rand() % 100 / 2.0;
snapshot->tlog = rand() % 100 / 2.0;
snapshot->remainDisinfectant = rand() % 100 / 2.0;
snapshot->remainTime = rand() % 100 / 2.0;
snapshot->ecode = 0; snapshot->ecode = 0;
onAppDisinfectionSnapshotEvent(snapshot);
onAppDisinfectionSnapshotEvent(snapshot);
onAppDisinfectionSnapshotEvent(snapshot);
shared_ptr<DisinfectionStatistics> statistics = make_shared<DisinfectionStatistics>();
statistics->start_tp = zsystem_clock().now();
statistics->complete_tp = zsystem_clock().now();
statistics->disinfectantVolume_g = 0;
statistics->tLog = 0;
statistics->finalLog = 0;
onAppDisinfectionFinishedEvent(statistics);
return snapshot;
} }

2
appsrc/service/disinfection_logs_service.hpp

@ -64,5 +64,7 @@ class DisinfectionLogsService : public enable_shared_from_this<DisinfectionLogsS
void clearRecordFiles(); void clearRecordFiles();
void deleteRecordFile(string file); void deleteRecordFile(string file);
bool dosystem(string cmd); bool dosystem(string cmd);
shared_ptr<DisinfectionStateSnapshot> selftest_createFakeSnapshot(zsystem_tp time, DisinfectionState state, int sensorNum, bool forceLog);
}; };
} // namespace iflytop } // namespace iflytop
Loading…
Cancel
Save