#include "../DB/LDBTool.h"
|
#include <basic/debug/Debug.h>
|
#include "loadManage.h"
|
#include <QDateTime>
|
#include <QString>
|
#include <QVector>
|
|
|
loadFileManage::loadFileManage(LDBTool *dbTool) : TaskManage(dbTool) {
|
init();
|
}
|
|
loadFileManage::~loadFileManage() {
|
|
}
|
|
void loadFileManage::init(void) {
|
//search all loadfile_info where finish_flag = 0
|
m_list = db_c->searchLoadFileTableAll();
|
}
|
|
|
#define Record_Cam_Chn2pChannelLoadFileManage(RCC, RESULT) \
|
{\
|
RESULT.strDevID = RCC.str_storage_dev_id.toStdString();\
|
RESULT.nChannelID = RCC.n_chn;\
|
RESULT.startTime.Year = RCC.tim_do_time.date().year();\
|
RESULT.startTime.Month = RCC.tim_do_time.date().month();\
|
RESULT.startTime.Day = RCC.tim_do_time.date().day();\
|
RESULT.startTime.Hour = RCC.tim_do_time.time().hour();\
|
RESULT.startTime.Minute = RCC.tim_do_time.time().minute();\
|
RESULT.startTime.Second = RCC.tim_do_time.time().second();\
|
nDuration = db_c->searchDurationByDeviceId(RCC.str_storage_dev_id);\
|
/*endTime = RCC.tim_do_time.addSecs(nDuration * 3600);//nDuration 1格为0.5小时*/\
|
endTime = RCC.tim_do_time.addSecs(nDuration * 1800);\
|
RESULT.endTime.Year = endTime.date().year();\
|
RESULT.endTime.Month = endTime.date().month();\
|
RESULT.endTime.Day = endTime.date().day();\
|
RESULT.endTime.Hour = endTime.time().hour();\
|
RESULT.endTime.Minute = endTime.time().minute();\
|
RESULT.endTime.Second = endTime.time().second();\
|
}
|
|
ChannelLoadFileManage loadFileManage::getTask(void) {
|
ChannelLoadFileManage result;
|
|
QDateTime endTime;
|
int nDuration;
|
|
if (m_list.size() > 0) {
|
Record_Load_File_info rec = *m_list.begin();
|
m_list.pop_front();
|
Record_Cam_Chn2pChannelLoadFileManage(rec, result);
|
} else {
|
//get task from cam_chn_table
|
Record_Cam_Chn rec = db_c->searchOldestRecordfromChnTableByUpdateTime();
|
if (rec.n_id == 0 || rec.tim_do_time.secsTo(QDateTime::currentDateTime()) <= nDuration * 1800) {
|
DBG("searchOldestRecordfromChnTableByUpdateTime NULL"
|
<< rec.tim_do_time.secsTo(QDateTime::currentDateTime())
|
<< rec.tim_do_time.toString("yyyy-MM-dd hh:mm:ss").toStdString());
|
return result;
|
}
|
//#todo search nDuration from deviceTable where rec.str_storage_dev_id
|
|
Record_Cam_Chn2pChannelLoadFileManage(rec, result);
|
|
Record_Load_File_info loadFileRec{0, rec.str_storage_dev_id, rec.n_chn, rec.tim_do_time, false, "",
|
QDateTime::currentDateTime(), ""};
|
|
//修改更新时间和处理时间
|
rec.tim_update_time = QDateTime::currentDateTime();
|
rec.tim_do_time = endTime;
|
|
if (rec.str_storage_dev_id.size() <= 0) {
|
ERR(" " << rec.str_storage_dev_id.toStdString());
|
}
|
|
//insert rec to loadfile_info && update cam_chn
|
bool ret = db_c->insertLoadFileTableAndUpdateChannelTable(loadFileRec, rec);
|
if (!ret) return ChannelLoadFileManage();
|
|
}
|
return result;
|
}
|
|
|
bool loadFileManage::finishTask(const pChannelLoadFileManage finishInfo) {
|
//TODO
|
//根据设备id/通道号/开始时间找到该条记录,然后更新,将该条记录的标志置1,添加path
|
//update db
|
char charStr[256] = {0};
|
sprintf(charStr, "%4d-%02d-%02d %02d:%02d:%02d", finishInfo->startTime.Year, finishInfo->startTime.Month,
|
finishInfo->startTime.Day, finishInfo->startTime.Hour, finishInfo->startTime.Minute,
|
finishInfo->startTime.Second);
|
QString strBuffer = QString(charStr);
|
|
QDateTime time = QDateTime::fromString(strBuffer, "yyyy-MM-dd hh:mm:ss");
|
|
Record_Load_File_info loadFileRec{0, QString::fromStdString(finishInfo->strDevID), finishInfo->nChannelID,
|
time, true, QString::fromStdString(finishInfo->srcPath),
|
QDateTime::currentDateTime(), ""};
|
db_c->updateLoadFileTable(loadFileRec);
|
return true;
|
}
|