|
|
@ -27,7 +27,7 @@ typedef DisinfectionRecordCSVHeader CSVHeader; |
|
|
|
|
|
|
|
#define LOG_STORGE_PATH "./disinfection_logs/"
|
|
|
|
#define EXPORT_PATH "/mnt/exportdata/Transmit/"
|
|
|
|
#define MAX_LOG_NUM 5
|
|
|
|
#define MAX_LOG_NUM 300
|
|
|
|
#define IF_ERROR_RETURN(x) \
|
|
|
|
if (!x) { \ |
|
|
|
return err::kappe_udisk_wr_fail; \ |
|
|
@ -135,9 +135,10 @@ static void split(const string& s, vector<string>& sv, const char delim = ' ') { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
static string createDisinfectionID() { |
|
|
|
struct tm tm = {0}; |
|
|
|
time_t t = time(nullptr); |
|
|
|
static string createFakeDisinfectionID() { |
|
|
|
static int cnt; |
|
|
|
struct tm tm = {0}; |
|
|
|
time_t t = time(nullptr); |
|
|
|
if (t == -1) { |
|
|
|
printf("time error\n"); |
|
|
|
exit(-1); |
|
|
@ -147,11 +148,11 @@ static string createDisinfectionID() { |
|
|
|
printf("localtime_r error\n"); |
|
|
|
exit(-1); |
|
|
|
} |
|
|
|
return fmt::format("{:0>4}-{:0>2}{:0>2}-{:0>2}{:0>2}", tm.tm_year + 1900, //
|
|
|
|
tm.tm_mon + 1, //
|
|
|
|
tm.tm_mday, //
|
|
|
|
tm.tm_hour, //
|
|
|
|
tm.tm_min); |
|
|
|
return fmt::format("{:0>4}-{:0>2}{:0>2}-{:0>2}{:0>2}.{:0>2}", tm.tm_year + 1900, //
|
|
|
|
tm.tm_mon + 1, //
|
|
|
|
tm.tm_mday, //
|
|
|
|
tm.tm_hour, //
|
|
|
|
tm.tm_min, cnt++); |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
@ -166,13 +167,14 @@ void DisinfectionLogsService::initialize() { |
|
|
|
GET_TO_SERVICE(m_udiskMgrService); |
|
|
|
|
|
|
|
REG_EXTFN_VOID(getRecordList, void()); |
|
|
|
REG_EXTFN_VOID(getRecordsStorageState, void()); |
|
|
|
REG_EXTFN(getRecord, void(string), logName); |
|
|
|
REG_EXTFN(deleteReport, void(string), logName); |
|
|
|
REG_EXTFN(deleteReports, void(vector<string>), logNames); |
|
|
|
REG_EXTFN(exportRecord, void(vector<string>), logNames); |
|
|
|
REG_EXTFN_VOID(exportAllRecord, void()); |
|
|
|
REG_EXTFN(printRecord, void(string), logName); |
|
|
|
REG_EXTFN(createFakeData, void(bool), printInPrinter); |
|
|
|
REG_EXTFN(createFakeData, void(int), cnt); |
|
|
|
|
|
|
|
m_csvHeaderDict.insert(CSVHeader::time, "时间"); |
|
|
|
m_csvHeaderDict.insert(CSVHeader::state, "设备状态"); |
|
|
@ -252,20 +254,19 @@ 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); |
|
|
|
m_recordFiles.push_front(m_sessionId); |
|
|
|
clearRecordFiles(); |
|
|
|
/**
|
|
|
|
* @brief |
|
|
|
* 1.创建打印文件缓存 |
|
|
|
* 2.创建PDF文件缓存 |
|
|
|
*/ |
|
|
|
if (printfLogWhenDisinfectionFinished) printRecordFile(m_sessionId); |
|
|
|
// if (printfLogWhenDisinfectionFinished) printRecordFile(m_sessionId);
|
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
@ -474,7 +475,7 @@ void DisinfectionLogsService::dumpDisinfectionToPrinterPdf(string sessionId, lis |
|
|
|
* @brief 删除记录,多余记录文件 |
|
|
|
*/ |
|
|
|
void DisinfectionLogsService::clearRecordFiles() { |
|
|
|
//
|
|
|
|
// //
|
|
|
|
vector<string> recordlist; |
|
|
|
for (auto& record : m_recordFiles) { |
|
|
|
recordlist.push_back(record); |
|
|
@ -497,13 +498,13 @@ void DisinfectionLogsService::clearRecordFiles() { |
|
|
|
deleteRecordFile(file); |
|
|
|
} |
|
|
|
|
|
|
|
int fileNum = getDirFileNum(LOG_STORGE_PATH); |
|
|
|
if ((uint32_t)fileNum != m_recordFiles.size() * 3) { |
|
|
|
logger->error("record file num error, delete all record files"); |
|
|
|
logger->info("delete all record files"); |
|
|
|
dosystem(fmt::format("rm -rf {}/*", LOG_STORGE_PATH)); |
|
|
|
m_recordFiles.clear(); |
|
|
|
} |
|
|
|
// int fileNum = getDirFileNum(LOG_STORGE_PATH);
|
|
|
|
// if ((uint32_t)fileNum != m_recordFiles.size() * 3) {
|
|
|
|
// logger->error("record file num error, delete all record files");
|
|
|
|
// logger->info("delete all record files");
|
|
|
|
// dosystem(fmt::format("rm -rf {}/*", LOG_STORGE_PATH));
|
|
|
|
// m_recordFiles.clear();
|
|
|
|
// }
|
|
|
|
} |
|
|
|
void DisinfectionLogsService::deleteRecordFile(string file) { |
|
|
|
string filepath = fmt::format("{}{}.*", LOG_STORGE_PATH, file); |
|
|
@ -552,15 +553,15 @@ int32_t DisinfectionLogsService::exportDisinfectionData(vector<string> files) { |
|
|
|
logger->info("copy file: {}", file); |
|
|
|
/**********************************拷贝CSV**********************************/ |
|
|
|
// 拷贝文件到TMP目录
|
|
|
|
IF_ERROR_RETURN(dosystem(fmt::format("cp -rf /app/disinfection_logs/{}.csv /tmp/{}.csv", file, file))); |
|
|
|
dosystem(fmt::format("cp -rf /app/disinfection_logs/{}.csv /tmp/{}.csv", file, file)); |
|
|
|
// 编码转换
|
|
|
|
IF_ERROR_RETURN(dosystem(fmt::format("iconv -f UTF-8 -tgb18030 /tmp/{}.csv -o /tmp/{}.csv.1", file, file))); |
|
|
|
dosystem(fmt::format("iconv -f UTF-8 -tgb18030 /tmp/{}.csv -o /tmp/{}.csv.1", file, file)); |
|
|
|
// 移动文件
|
|
|
|
IF_ERROR_RETURN(dosystem(fmt::format("mv /tmp/{}.csv.1 /tmp/{}.csv", file, file))); |
|
|
|
dosystem(fmt::format("mv /tmp/{}.csv.1 /tmp/{}.csv", file, file)); |
|
|
|
// 拷贝文件到U盘
|
|
|
|
IF_ERROR_RETURN(dosystem(fmt::format("cp -rf /tmp/{}.csv {}", file, EXPORT_PATH))); |
|
|
|
dosystem(fmt::format("cp -rf /tmp/{}.csv {}", file, EXPORT_PATH)); |
|
|
|
// 删除文件
|
|
|
|
IF_ERROR_RETURN(dosystem(fmt::format("rm -rf /tmp/{}.csv", file))); |
|
|
|
dosystem(fmt::format("rm -rf /tmp/{}.csv", file)); |
|
|
|
|
|
|
|
/**********************************拷贝PDF**********************************/ |
|
|
|
// 拷贝pdf文件
|
|
|
@ -568,9 +569,9 @@ int32_t DisinfectionLogsService::exportDisinfectionData(vector<string> files) { |
|
|
|
} |
|
|
|
|
|
|
|
// 卸载目录
|
|
|
|
IF_ERROR_RETURN(dosystem(fmt::format("umount /mnt/exportdata"))); |
|
|
|
dosystem(fmt::format("umount /mnt/exportdata")); |
|
|
|
// 删除目录
|
|
|
|
IF_ERROR_RETURN(dosystem(fmt::format("rm -rf /mnt/exportdata"))); |
|
|
|
dosystem(fmt::format("rm -rf /mnt/exportdata")); |
|
|
|
|
|
|
|
return err::ksucc; |
|
|
|
} |
|
|
@ -589,6 +590,21 @@ bool DisinfectionLogsService::dosystem(string cmd) { |
|
|
|
/*******************************************************************************
|
|
|
|
* EXT_API * |
|
|
|
*******************************************************************************/ |
|
|
|
void DisinfectionLogsService::getRecordsStorageState(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
vector<string> record; |
|
|
|
for (auto& file : m_recordFiles) record.push_back(file); |
|
|
|
cxt->rely["records"] = record; |
|
|
|
cxt->rely["nums"] = record.size(); |
|
|
|
cxt->rely["maxNums"] = MAX_LOG_NUM; |
|
|
|
cxt->rely["full"] = record.size() >= MAX_LOG_NUM; |
|
|
|
if ((MAX_LOG_NUM - MAX_LOG_NUM * 0.8) > 20) { |
|
|
|
cxt->rely["beFullSoon"] = record.size() >= (MAX_LOG_NUM - 20); |
|
|
|
} else { |
|
|
|
cxt->rely["beFullSoon"] = record.size() >= (MAX_LOG_NUM * 0.8); |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionLogsService::getRecordList(shared_ptr<MsgProcessContext> cxt) { |
|
|
|
/**
|
|
|
@ -644,43 +660,43 @@ chrono::system_clock::time_point time_point_increment(chrono::system_clock::time |
|
|
|
return tp; |
|
|
|
} |
|
|
|
|
|
|
|
void DisinfectionLogsService::createFakeData(shared_ptr<MsgProcessContext> cxt, bool printInPrinter) { |
|
|
|
string ssid = createDisinfectionID(); |
|
|
|
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++) { |
|
|
|
void DisinfectionLogsService::createFakeData(shared_ptr<MsgProcessContext> cxt, int cnt) { |
|
|
|
for (int i = 0; i < cnt; i++) { |
|
|
|
string ssid = createFakeDisinfectionID(); |
|
|
|
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::disinfection, 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); |
|
|
|
} |
|
|
|
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::disinfection, 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; |
|
|
|
|
|
|
|
printfLogWhenDisinfectionFinished = false; |
|
|
|
onAppDisinfectionFinishedEvent(statistics); |
|
|
|
printfLogWhenDisinfectionFinished = true; |
|
|
|
} |
|
|
|
|
|
|
|
shared_ptr<DisinfectionStateSnapshot> DisinfectionLogsService::selftest_createFakeSnapshot(zsystem_tp time, DisinfectionState state, int sensorNum, bool forceLog) { |
|
|
|