3500/HistoryAlarm.cpp

672 lines
29 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "HistoryAlarm.h"
#include "ui_HistoryAlarm.h"
#include <QListView>
#include "sqlitedb.h"
#include "QMyTableViewBtnDelegate.h"
#include "AlarmDetails.h"
#include "ftpclient.h"
#include "global.h"
#include "NetMgr.h"
CHistoryAlarm::CHistoryAlarm(QWidget *parent) :
QWidget(parent),
ui(new Ui::CHistoryAlarm)
{
ui->setupUi(this);
headerStr = QObject::tr(" ,序号,级别,报警内容,报警时间,复归时间,报警详情");
myHeader = new TableHeaderView(Qt::Horizontal, ui->tableView);
model = new QStandardItemModel(ui->tableView);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中行
connect(myHeader, &TableHeaderView::stateChanged, this, &CHistoryAlarm::headerStateChangedSlot);
QStringList headerList = headerStr.split(",");
model->setHorizontalHeaderLabels(headerList);
model->setColumnCount(headerList.size());
ui->tableView->setModel(model);
ui->tableView->horizontalHeader()->setSectionResizeMode(0,QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setSectionResizeMode(6,QHeaderView::ResizeToContents);
ui->dateTimeEdit_start->setCalendarPopup(true);
ui->dateTimeEdit_end->setCalendarPopup(true);
QDateTime curDateTime=QDateTime::currentDateTime();//通过QDateTime的currentDateTime获得当前的日期时间并赋值给curDateTime
ui->dateTimeEdit_start->setDateTime(curDateTime.addDays(-7));
ui->dateTimeEdit_end->setDateTime(curDateTime.addSecs(300));
ui->comboBox_channel->setView(new QListView());
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->setHorizontalHeader(myHeader);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中行
CheckBoxDelegate *pCheckDelegate = new CheckBoxDelegate(this);
ui->tableView->setItemDelegateForColumn(0, pCheckDelegate);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
ui->tableView->setColumnWidth(0, 50);
ui->tableView->setColumnWidth(1, 50);
ui->tableView->setColumnWidth(2, 50);
ui->tableView->setColumnWidth(3, 370);
ui->tableView->setColumnWidth(4, 170);
ui->tableView->setColumnWidth(5, 170);
ui->tableView->setAlternatingRowColors(true);
connect(ui->comboBox_channel,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(on_comboBox_channel_currentTextChanged(const QString&)));
ui->comboBox_channel->addItem("请选择通道...");
for (int i = 0; i < g_ChannelBaseInfo.size(); i++) {
ui->comboBox_channel->insertItem(i,g_ChannelBaseInfo[i].channelName);
}
ui->comboBox_channel->setCurrentText("请选择通道...");
}
CHistoryAlarm::~CHistoryAlarm()
{
delete ui;
}
void CHistoryAlarm::on_comboBox_channel_currentTextChanged(const QString& strChannelName)
{
int i = 0;
for (i = 0; i < g_ChannelBaseInfo.size(); i++) {
if(strChannelName == g_ChannelBaseInfo[i].channelName){
m_strChannelID = g_ChannelBaseInfo[i].channelID;
break;
}
}
}
void CHistoryAlarm::headerStateChangedSlot(int state)
{
int rowCount = model->rowCount();
if (state == 2)//全选
{
for (int j = 0; j<rowCount; j++)
{
QModelIndex index = model->index(j, 0, QModelIndex());
model->setData(index, true, Qt::UserRole);
}
}
else if (state == 0) //全不选
{
for (int j = 0; j<rowCount; j++)
{
QModelIndex index = model->index(j, 0, QModelIndex());
model->setData(index, false, Qt::UserRole);
}
}
}
void CHistoryAlarm::createRowItem(int Row,QVariantList RowItem)
{
model->setRowCount(Row+1);
for (int j = 1; j < RowItem.size()+1; ++j)
{
model->setData(model->index(Row,j,QModelIndex()),RowItem.at(j-1));
}
}
void CHistoryAlarm::on_pushButton_search_clicked()
{
model->removeRows(0, model->rowCount());
QDateTime dateTimeStart =ui->dateTimeEdit_start->dateTime();
QDateTime dateTimeEnd =ui->dateTimeEdit_end->dateTime();
int timestampStart = dateTimeStart.toTime_t();
int timestampEnd = dateTimeEnd.toTime_t();
QString strTableName = "t_AlarmStatusInfo",strSql;
if(ui->comboBox_channel->currentText() == "请选择通道..."){
strSql = QString(" timestamp > %1 and timestamp < %2 order by timestamp desc").arg(timestampStart).arg(timestampEnd);
}
else{
strSql = QString(" channelId = '%1' and timestamp > %2 and timestamp < %3 order by timestamp desc").arg(m_strChannelID).arg(timestampStart).arg(timestampEnd);
}
QVector<TriggerAlarmStatusInfo_t>().swap(m_vecTriggerAlarmStatusInfo);
m_vecTriggerAlarmStatusInfo = g_SqliteDB->GetTriggerAlarmStatusInfo(strTableName,strSql);
QString strSize = QString(" 事件个数 : %1").arg(m_vecTriggerAlarmStatusInfo.size());
customLogMessageHandler(QtInfoMsg,strSize);
if(m_vecTriggerAlarmStatusInfo.size() > 0){
for (int i = 0; i < m_vecTriggerAlarmStatusInfo.size(); i++) {
QVariantList strRowItem ;
QString TStr = QDateTime::fromSecsSinceEpoch(m_vecTriggerAlarmStatusInfo[i].timestamp).toString("yyyy-MM-dd hh:mm:ss");
QString resetTime = "";
if(m_vecTriggerAlarmStatusInfo[i].resetTimestamp != 0)
resetTime = QDateTime::fromSecsSinceEpoch(m_vecTriggerAlarmStatusInfo[i].resetTimestamp).toString("yyyy-MM-dd hh:mm:ss");
QString triggerLevel = "",triggerEventName = "";
if(m_vecTriggerAlarmStatusInfo[i].triggerLevel == "1"){
triggerLevel = "警报";
}else if(m_vecTriggerAlarmStatusInfo[i].triggerLevel == "2"){
triggerLevel = "危险";
}
QString strFeatureName = "";
if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("MinValues"))
strFeatureName = "最小值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("MaxValues"))
strFeatureName = "最大值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("DCValues"))
strFeatureName = "偏置电压/Gap";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("RMSValues"))
strFeatureName = "有效值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("DiagnosisPk2Pk"))
strFeatureName = "诊断峰峰值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("IntegratRMS"))
strFeatureName = "有效值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("IntegratPk2Pk"))
strFeatureName = "积分峰峰值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("SpeedProfileSpeed"))
strFeatureName = "转速";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("IntegratPk2Pk/2"))
strFeatureName = "峰值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("DiagnosisPeak"))
strFeatureName = "峰值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("MonitorPk2Pk"))
strFeatureName = "监测保护峰峰值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("InvertDanger") )
strFeatureName = "反时限危险值";
else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("InvertAlarm"))
strFeatureName = "反时限警报值";
if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("Over")){
triggerEventName = m_vecTriggerAlarmStatusInfo[i].channelName + "-" + strFeatureName+ "-" + "高于" + triggerLevel + "";
}else if(m_vecTriggerAlarmStatusInfo[i].triggerEventName.contains("Under")){
triggerEventName = m_vecTriggerAlarmStatusInfo[i].channelName + "-" + strFeatureName+ "-" + "低于" + triggerLevel + "";
}
strRowItem << i + 1 << triggerLevel << triggerEventName << TStr << resetTime;
createRowItem(i,strRowItem);
}
QMyTableViewBtnDelegate *m_btnDelegate = new QMyTableViewBtnDelegate(QStringList()<<"详情", this);
ui->tableView->setItemDelegateForColumn(6, m_btnDelegate);
connect(m_btnDelegate, SIGNAL(editData(const QModelIndex &)), this,SLOT(Details(const QModelIndex &)));
}else{
QMessageBox::information(this, "提示", QString("未查询到数据!"));
}
}
void CHistoryAlarm::OpenDatFile(QString& strFileName)
{
QProgressDialog *progressDialog = new QProgressDialog(this);
progressDialog->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
progressDialog->setWindowModality(Qt::WindowModal);
progressDialog->setWindowTitle(tr("Please Wait"));
progressDialog->setLabelText(tr("读取中..."));
progressDialog->setCancelButton(0);
progressDialog->show();
QTime startTime = QTime::currentTime();
m_vecGroupdata.clear();
m_vecWaveInfo.clear();
QVector<GroupData>().swap(m_vecGroupdata);
QVector<WAVE_INFO>().swap(m_vecWaveInfo);
QVector<WAVE_ALLDATA>().swap(m_vecAllData);
QMap<QString,QVector<WAVE_DATA>>::Iterator iter1 = mapWaveData.begin();
for(iter1 = mapWaveData.begin();iter1 != mapWaveData.end();iter1++){
QVector<WAVE_DATA>().swap(iter1.value());
mapWaveData.erase(iter1);
}
int channelwork[64];
int channelEnabled[64];
int theSize = 0; //通道数
//读12字节头文件
int iJsonSize, iChannelsize;
char equipNo[12]; //设备No 12字节
char time[10]; //数据起始时间 10字节
QFile file(strFileName);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << "::MainWidget::ReadDatData() cannot open file for read";
return;
}
file.read((char*)&iChannelsize, sizeof(iChannelsize));
//qDebug() << "::MainWidget::ReadDatData() Channelsize:" << iChannelsize;
int iCount; //存储dat文件原始数据秒数
file.read((char*)&iCount, sizeof(iCount));
//qDebug() << "::MainWidget::ReadDatData() iCount:" << iCount;
file.read(equipNo, sizeof(equipNo));
QString sEquipNo(equipNo);
file.read(time, sizeof(time));
QString CollectTime(time);
file.read((char *)&iJsonSize, sizeof(iJsonSize));
//qDebug() << "::MainWidget::ReadDatData() iJsonSize:" << iJsonSize;
//读json串
char *buf0 = (char *)malloc(sizeof(char) *iJsonSize);
file.read(buf0,iJsonSize);
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(buf0,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
qDebug()<<tr("解析json文件错误");
delete progressDialog;
file.close();
return;
}
int channels = 0;
QJsonObject jsonObject = document.object();
QString strType = jsonObject["DeviceType"].toString();
if(jsonObject.contains(QStringLiteral("ChannelSettings"))){
QJsonValue arrayValue = jsonObject.value(QStringLiteral("ChannelSettings"));
if(arrayValue.isArray()){
QJsonArray array = arrayValue.toArray();
theSize = array.size();
for(int i = 0; i<array.size();i++){
WAVE_INFO waveInfo;
channelEnabled[i] = array.at(i)["isEnable"].toInt();
channelwork[i] = array.at(i)["isWork"].toInt();
QString strchannelType = array.at(i)["sensorType"].toString();
if(channelEnabled[i] && channelwork[i] && strchannelType != "DO" && strchannelType != "DI"){
waveInfo.channelId = array.at(i)["channelId"].toString();
waveInfo.channelType = array.at(i)["sensorType"].toString();
waveInfo.channelName = array.at(i)["channelName"].toString();
waveInfo.sensorType = array.at(i)["sensorType"].toString();
waveInfo.channelSamleRate = array.at(i)["samplingRate"].toInt();
waveInfo.pairChannelID = array.at(i)["pairChannelId"].toString();
waveInfo.equipmentName = array.at(i)["equipmentName"].toString();
waveInfo.sensorEngineeringUnit = array.at(i)["sensorEngineeringUnit"].toString();
waveInfo.speedRefChannelId = array.at(i)["speedRefChannelId"].toString();
waveInfo.tachAutoTach = array.at(i)["tachAutoTach"].toBool();
waveInfo.sensorGapVoltage = array.at(i)["sensorGapVoltage"].toDouble();
waveInfo.sensorSensitivity = array.at(i)["sensorSensitivity"].toDouble();
QString strtachTriggerEdge = array.at(i)["tachTriggerEdge"].toString();
if(strtachTriggerEdge == "rising"){
waveInfo.iTrigger = 0;
}else if(strtachTriggerEdge == "falling"){
waveInfo.iTrigger = 1;
}
waveInfo.iTrigger = 0;
waveInfo.iKeyCount = array.at(i)["tachTriggerPerRev"].toInt();
waveInfo.iTriggerValue = array.at(i)["tachTriggerVoltageLevel"].toDouble();
waveInfo.iHysteresis = array.at(i)["tachTriggerHysteresis"].toDouble();
//qDebug() <<waveInfo.channelId<< "iKeyCount" << waveInfo.iKeyCount << "iTriggerValue" << waveInfo.iTriggerValue << "iHysteresis" << waveInfo.iHysteresis << endl;
m_vecWaveInfo.push_back(waveInfo);
channels ++ ;
//qDebug() << waveInfo.sensorGapVoltage << waveInfo.sensorSensitivity << endl;
//qDebug() << waveInfo.channelId << waveInfo.channelType <<waveInfo.channelName << waveInfo.pairChannelID << waveInfo.sensorEngineeringUnit << waveInfo.speedRefChannelId << waveInfo.iTriggerValue<<endl;
}
}
}
}if(jsonObject.contains(QStringLiteral("groups"))){
QJsonValue arrayValue = jsonObject.value(QStringLiteral("groups"));
if(arrayValue.isArray()){
QJsonArray array1 = arrayValue.toArray();
theSize = array1.size();
for(int i = 0; i<array1.size();i++){
QString strChannelType = array1.at(i)["ChannelType"].toString();
QString strChannelID = array1.at(i)["name"].toString();
//if(strChannelType == "TACHOMETER")
{
for(int ii = 0; ii < m_vecWaveInfo.size();ii++){
if(strChannelID == m_vecWaveInfo[ii].channelId){
QJsonValue arrayValue = array1.at(i)["channels"];
QJsonArray array2 = arrayValue.toArray();
for(int j = 0; j<array2.size();j++){
if("SpeedProfileSpeed" == array2.at(j)["name"].toString()){
QJsonArray arrayValue = array2.at(j)["data"].toArray();
for(int jj = 0; jj < arrayValue.size();jj++){
m_vecWaveInfo[ii].SpeedProfileSpeed.push_back(arrayValue[jj].toDouble());
}
}
if("RMSValues" == array2.at(j)["name"].toString()){
QJsonArray arrayValue = array2.at(j)["data"].toArray();
for(int jj = 0; jj < arrayValue.size();jj++){
m_vecWaveInfo[ii].RMSValue.push_back(arrayValue[jj].toDouble());
}
}
}
}
}
}
}
}
}
//qDebug()<<"channels" <<channels<<endl;
//循环读出原始数据内容
WAVE_CHNDATA m_WaveChnData[15000];
int Count, waveSize,bufferSiz;
if(strType == "3500")
bufferSiz = 16;
else
bufferSiz = 15;
char buf[bufferSiz];
m_vecAllData.clear();
//QVector<WAVE_DATA> pData;
int j = 0;
int temCount = 0;
int flag = -1;
progressDialog->setRange(0, iCount * channels-1);
while (!file.atEnd()) {
file.read((char *)&Count, sizeof(Count));
//qDebug()<<"Count" << Count << "temCount" <<temCount<< endl;
if(Count > temCount && flag == 0)//过滤超出的秒数的数据
break;
if(Count == temCount && flag == 0)
flag = 1;
if(Count < temCount || flag == 1){//过滤原始数据中转速多余数据
file.read(buf, sizeof(buf));
file.read((char *)&waveSize, sizeof(waveSize));
float f = 0.0;
QVector<double> vecSpeed;
//qDebug()<<"waveSize1" <<waveSize<<endl;
for (int i = 0; i < waveSize; i++) {
file.read((char *)&f, sizeof(f));
vecSpeed.push_back(f);
}
for(int ii = 0; ii < 2000;ii++){
if(m_WaveChnData[ii].Second == Count){
m_WaveChnData[ii].TimeStamp = vecSpeed;
}
}
flag = 0;
//qDebug()<<"::MainWidget::ReadDatData()11 wave.channelId" << buf <<" wave.count"<<Count<<" wave.wavedata"<<m_WaveChnData[j].waveData.size()<<"waveSize"<<waveSize << "j"<<j<<endl;;
}else {
file.read(buf, sizeof(buf));
file.read((char *)&waveSize, sizeof(waveSize));
float f = 0.0;
WAVE_ALLDATA waveAll;
if(waveSize < 0 || waveSize > 131072){
//qDebug() << "waveSize2" << waveSize << endl;
delete progressDialog;
file.close();
return;
}
for (int i = 0; i < waveSize; i++) {
file.read((char *)&f, sizeof(f));
m_WaveChnData[j].channelId = buf;
m_WaveChnData[j].waveData.push_back((double)f);
m_WaveChnData[j].Second = Count;
}
temCount = Count;
//qDebug()<<"::MainWidget::ReadDatData() wave.channelId" << m_WaveChnData[j].channelId<<" wave.count"<<Count<<" wave.wavedata"<<m_WaveChnData[j].waveData.size()<<"waveSize"<<waveSize << "j"<<j<<endl;;
}
progressDialog->setValue(j);
if (progressDialog->wasCanceled())
{
delete progressDialog;
file.close();
return ;
}
j++;
}
/*if(temCount != iCount){
MyMsgBox(QMessageBox::Warning,"警告","Dat文件采集秒数与实际读取秒数不一致");
iCount = temCount;
}*/
//qDebug()<<m_vecAllData.size()<<m_vecAllData.capacity() << "iCount" <<iCount << "m_vecWaveInfo" << m_vecWaveInfo.size() <<endl;
QVector<WAVE_INFO>::iterator iter = m_vecWaveInfo.begin();
int linecolor = 0;
for (;iter != m_vecWaveInfo.end() ; iter++ ) {
WAVE_DATA wave;
int ii = 0;
QVector<WAVE_DATA> m_vecPushData1;
for(int i = 0; i < j; i++){
//qDebug() << "i" << iter->channelId.left(bufferSiz) << "j " << m_WaveChnData[i].channelId.left(bufferSiz) <<endl;
if(iter->channelId.left(bufferSiz) == m_WaveChnData[i].channelId.left(bufferSiz)){
wave.waveData = m_WaveChnData[i].waveData;
double sum = 0.0;
if(iter->sensorType == "ACCELEROMETER" || iter->sensorType == "MICROPHONE" ||
iter->sensorType == "PROXIMETER" || iter->sensorType == "VELOCITY" ||
iter->sensorType == "TACHOMETER" || iter->sensorType == "THRUST" ||
iter->sensorType == "FAST_VOLTAGE"){
sum = std::accumulate(std::begin(wave.waveData), std::end(wave.waveData), 0.0);
double size = m_WaveChnData[i].waveData.size();
wave.mean = sum/size;
}else{
sum = 0.0;
}
if(iter->sensorType == "TACHOMETER"){
wave.TimeStamp = m_WaveChnData[i].TimeStamp;
//qDebug()<< "iCount" <<iCount<<endl;
ii ++;
}
wave.SpeedProfileSpeed = iter->SpeedProfileSpeed;
wave.wavesize = wave.waveData.size();
wave.SamleRate = iter->channelSamleRate;
wave.sensorType = iter->sensorType;
wave.channelId = iter->channelId;
wave.channelNo = theSize;
wave.Time = iCount;
wave.channelName = iter->channelName;
wave.pairChannelID = iter->pairChannelID;
wave.sensorEngineeringUnit = iter->sensorEngineeringUnit;
wave.speedRefChannelId = iter->speedRefChannelId;
wave.RMSValue = iter->RMSValue;
wave.iTrigger = iter->iTrigger;
wave.iKeyCount = iter->iKeyCount;
wave.iTriggerValue = iter->iTriggerValue;
wave.iHysteresis = iter->iHysteresis;
wave.tachAutoTach = iter->tachAutoTach;
wave.sensorGapVoltage = iter->sensorGapVoltage;
wave.sensorSensitivity = iter->sensorSensitivity;
switch(linecolor){
case 0:
wave.linColor = Qt::green ;
break;
case 1:
wave.linColor = QColor(30,144,255) ;
break;
case 2:
wave.linColor = QColor(255,182,193) ;
break;
case 3:
wave.linColor = Qt::cyan ;
break;
case 4:
wave.linColor = Qt::magenta ;
break;
case 5:
wave.linColor = Qt::yellow ;
break;
case 6:
wave.linColor = QColor(255,69,0) ;
break;
case 7:
wave.linColor = QColor(0, 255, 127) ;
break;
case 8:
wave.linColor = QColor(255,140,0) ;
break;
case 9:
wave.linColor = QColor(0, 191, 255) ;
break;
case 10:
wave.linColor = Qt::darkMagenta ;
break;
case 11:
wave.linColor = Qt::lightGray ;
break;
case 12:
wave.linColor = Qt::darkYellow ;
break;
case 13:
wave.linColor = QColor(153, 51, 250);
break;
case 14:
wave.linColor = QColor(255, 218, 185) ;
break;
case 15:
wave.linColor = QColor(0,199,140) ;
break;
default:
break;
}
m_vecPushData1.push_back(wave);
}
}
linecolor++;
if(linecolor > 15){
linecolor = 0;
}
mapWaveData.insert(iter->channelId,m_vecPushData1);
}
file.close();
free(buf0);
QTime stopTime = QTime::currentTime();
// qDebug() << "Time: " << startTime.msecsTo(stopTime) << "ms" <<endl;
delete progressDialog;
DateViewdialog = new CDataGraphView();
connect(DateViewdialog, SIGNAL(ItemCheckStateSignal(QString, bool)), this, SLOT(ItemCheckStateSlot(QString, bool)));
DateViewdialog->setWindowModality(Qt::ApplicationModal);
DateViewdialog->setAttribute(Qt::WA_DeleteOnClose);
DateViewdialog->show();
QStringList strIDList,strChannleType,strChannleNameList;
QMap<QString,QVector<WAVE_DATA>>::Iterator iter2 = mapWaveData.begin();
for (; iter2 != mapWaveData.end(); iter2 ++)
{
if(!strIDList.contains(iter2.key()))
strIDList.push_back(iter2.key());
strChannleType.push_back(iter2.value()[0].sensorType);
strChannleNameList.push_back(iter2.value()[0].channelName);
}
DateViewdialog->SetDataIDs(strIDList, tr("Data Watch "),strChannleType,strChannleNameList);
}
void CHistoryAlarm::downloadProcess_Slot(qint64 byteSend, qint64 byteTotal)
{
qDebug() << byteSend << byteTotal << endl;
downloadProgressDialog->setRange(0, byteTotal);
downloadProgressDialog->setValue(byteSend);
if(byteSend == byteTotal){
disconnect(g_FtpClient,SIGNAL(sigDownloadProcess(qint64 , qint64 )),this,SLOT(downloadProcess_Slot(qint64 , qint64)));
customLogMessageHandler(QtDebugMsg,"HistoryAlarm Open:" + g_LocalFile);
OpenDatFile(g_LocalFile);
}
}
void CHistoryAlarm::Details(const QModelIndex &index)
{
int row = index.row();
QString strCol = "triggeredFileName";
QString strTimeStamp = QString("%1").arg(m_vecTriggerAlarmStatusInfo[row].timestamp);
qDebug() << "TriggerAlarm timestamp" << strTimeStamp << endl;
QString strTableName = QString("t_TriggerEvent ORDER BY ABS(triggeredTime - %1) LIMIT 1").arg(m_vecTriggerAlarmStatusInfo[row].timestamp);
QString strFileName = g_SqliteDB->GetSingelLine(strTableName,strCol);
strFileName = strFileName.left(strFileName.size()-1);
QStringList strList = strFileName.split("/");
#ifdef Q_OS_WIN32
QString strPath = QCoreApplication::applicationDirPath() + "\\dat\\" + strList[5];
#endif
#ifdef Q_OS_LINUX
QString strPath = QCoreApplication::applicationDirPath() + "/dat/" + strList[5];
#endif
customLogMessageHandler(QtDebugMsg,"HistoryAlarm:" + strPath);
QFile file(strPath);
g_LocalFile = strPath;
if(file.exists()){
OpenDatFile(strPath);
}else{
downloadProgressDialog = new QProgressDialog(this);
downloadProgressDialog->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
downloadProgressDialog->setWindowModality(Qt::WindowModal);
downloadProgressDialog->setWindowTitle(tr("Please Wait"));
downloadProgressDialog->setLabelText(tr("下载中..."));
//downloadProgressDialog->setCancelButton(0);
downloadProgressDialog->show();
qDebug() << "file2" << endl;
connect(g_FtpClient,SIGNAL(sigDownloadProcess(qint64 , qint64 )),this,SLOT(downloadProcess_Slot(qint64 , qint64)));
//connect(g_FtpClient,SIGNAL(sigDownloadStatus()),this,SLOT(DownloadStatus_Slot()));
QString str = QString("ftp://%1/").arg(IP);
g_FtpClient->SetServerInfo(str);
g_FtpClient->SetUserInfo("root","@#cidw!@123456");
g_FtpClient->DownLoad(strFileName,strPath);
}
}
void CHistoryAlarm::ItemCheckStateSlot(QString strID, bool bChecked)
{
DateViewdialog->ViewData(strID,mapWaveData[strID]);
}
void CHistoryAlarm::on_pushButton_delete_clicked()
{
QMessageBox:: StandardButton iResult = QMessageBox::question(this, QStringLiteral("提示"),
QStringLiteral("确认后将删除选中的记录!"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
switch (iResult) {
case QMessageBox::Yes:
break;
case QMessageBox::No:
return;
break;
default:
break;
}
QStringList strListFileName;
QString strChannelName;
QVector<TriggerEvent_t> vecTriggerEvent;
for (int i = 0; i < model->rowCount(); i++) {
QModelIndex indexCheck = model->index(i,0);
bool check = model->data(indexCheck, Qt::UserRole).toBool();
if(check){
QString strDate = model->data(model->index(i,4)).toString();
strChannelName = model->data(model->index(i,3)).toString();
QStringList channellist = strChannelName.split("-");
QDateTime dateTime = QDateTime::fromString(strDate, "yyyy-MM-dd hh:mm:ss");
QString strTableNameAlarm = "t_AlarmStatusInfo",strTableNameTriger = "t_TriggerEvent";
// 将QDateTime转换为时间戳
qint64 timestamp = dateTime.toSecsSinceEpoch();
QString strWhere1 = QString("timestamp = '%1' and channelName = '%2'").arg(timestamp).arg(channellist[0]);
QString strWhere2 = QString("triggeredTime = %1 and triggeredChannelName = '%2'").arg(timestamp).arg(channellist[0]);
QString strCol = "triggeredFileName";
QString strTableName = QString("t_TriggerEvent ORDER BY ABS(triggeredTime - %1) LIMIT 1").arg(timestamp);
QString strFileName = g_SqliteDB->GetSingelLine(strTableName,strCol);
strFileName = strFileName.left(strFileName.size()-1);
strListFileName = strFileName.split("/");
g_SqliteDB->DeleteDataW(strTableNameAlarm,strWhere1);
g_SqliteDB->DeleteDataW(strTableNameTriger,strWhere2);
}
}
QJsonObject allObj,cmdBody;
QJsonArray arrayFileName;
allObj.insert("cmd", "40");
cmdBody.insert("type","ARRAY");
arrayFileName.append(strChannelName);
cmdBody.insert("fileName",strListFileName[5]);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
g_NetMgr->PostJson(req,allObj);
QString dat_path = QCoreApplication::applicationDirPath() + "\\dat\\" + strListFileName[5];
QDir datDir(dat_path);
if (datDir.exists()) {
datDir.removeRecursively();
}
on_pushButton_search_clicked();
}