派生自 development/c++

zhangjixing
2019-01-18 9f08028f23d9e5cbfa159bec1e07d63b141a6809
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#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;
}