#include "core.h" #include "ytservicecore.h" #include #include #include #include //extern YT_SERVICE_SHM *ytShm; void chkmd5(const char *data, char *md5){ MD5_CTX ctx; unsigned char tmp,md[16]; int i; MD5_Init(&ctx); MD5_Update(&ctx,data,strlen(data)); MD5_Final(md,&ctx); for(i=0;i<16;i++){ tmp = (md[i]>>4)&0x0f; if(tmp<10) md5[i*2+0] = (char)(tmp+0x30); else md5[i*2+0] = (char)(tmp+0x37); tmp = md[i]&0x0f; if(tmp<10) md5[i*2+1] = (char)(tmp+0x30); else md5[i*2+1] = (char)(tmp+0x37); } md5[32] = 0x00; } Core::Core(QObject *parent) : QObject(parent) { isRunning = false; ypCount = 0; lhworktime = 0; work_time = 0; xfzdworktime = 0; lhworktime1 = 0; ypSyncDisdataList.clear(); XfzdSyncdataLiet.clear(); sqlList.clear(); sqlList2.clear(); sqlList3.clear(); hour = 25; hour1 = 25; minute = 255; logThread = new LogThread(this); logThread->start(); ytShm->updatetime[CORE_MAIN] = time(static_cast(nullptr)); ytShm->updatetime[DB_THREAD] = ytShm->updatetime[CORE_MAIN] ; db = QSqlDatabase::addDatabase("QSQLITE","dog_conf"); db.setDatabaseName("/root/db/watchdog2.db"); mdb = QSqlDatabase::addDatabase("QMYSQL","jdxf2_db"); mdb.setDatabaseName("jdxf"); mdb.setHostName("47.98.201.187"); mdb.setPort(3306); mdb.setUserName("root"); mdb.setPassword("Yt2018IoT"); mdbOpened = mdb.open(); if(db.open()){ db_init(); } dbThread = new DataBaseThread(this); dbThread->start(); timer = new QTimer(this); netAccessManager = new QNetworkAccessManager(this); connect(timer,SIGNAL(timeout()),this,SLOT(time_out())); connect(netAccessManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedSlot(QNetworkReply*))); XfzdnetAccessManager = new QNetworkAccessManager(this); connect(XfzdnetAccessManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedSlot9(QNetworkReply*))); time_out(); } Core::~Core(){ logThread->stop(); dbThread->stop(); } void Core::appendLog(QString log){ logThread->appendData(log); } void Core::start() { printf("core start\n"); timer->start(1000); } void Core::needSync(QString deviceCode) { logThread->appendData(QString("[ %1 dataupdate ] %2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz")).arg(deviceCode)); } void Core::companyAlarmChanged(QString companyCode) { wsCenter->checkLastNote(companyCode); } void Core::SyncData(QString uuid, QString jsonstr) { ypSyncdataList.append(SyncRep(uuid,jsonstr)); } void Core::XfzdSyncData(int xh,QString uuid, QString jsonstr, int devCategory, QString deviceCode) { XfzdSyncdataLiet.append(XfzdSyncRep(xh,uuid,jsonstr,devCategory,deviceCode)); } void Core::finishedSlot(QNetworkReply *reply) { if(ypSyncdataList.length()>0){ SyncRep rep = ypSyncdataList.first(); if(reply->error()==QNetworkReply::NoError){ ypCount=0; QString bak_info = QString::fromUtf8(reply->readAll()); dbThread->appendSql(QString::fromUtf8("update `ypsync_t_rec` set `send`=1, `reply_str`='%1', `reply_time`='%2' where `uuid`='%3'") .arg(bak_info).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(rep.Id)); }else dbThread->appendSql(QString::fromUtf8("update `ypsync_t_rec` set `reply_time`='%1' where `uuid`='%2'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(rep.Id)); ypSyncdataList.removeFirst(); } reply->deleteLater(); isSending = false; } void Core::finishedSlot9(QNetworkReply *reply) { if(XfzdSyncdataLiet.length()>0){ XfzdSyncRep rep = XfzdSyncdataLiet.first(); if(reply->error()==QNetworkReply::NoError){ QString bak_info = QString::fromUtf8(reply->readAll()); dbThread->appendSql(QString::fromUtf8("update `xfzdsync_t_rec` set `send`=1, `reply_str`='%1', `reply_time`='%2' where `uuid`='%3'") .arg(bak_info).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(rep.Id)); // printf("%s\n",bak_info.toUtf8().data()); }else dbThread->appendSql(QString::fromUtf8("update `xfzdsync_t_rec` set `reply_time`='%1' where `uuid`='%2'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(rep.Id)); XfzdSyncdataLiet.removeFirst(); } reply->deleteLater(); isSending9 = false; } void Core::reply_timeout() { if(ypSyncdataList.length()>0){ SyncRep rep = ypSyncdataList.first(); dbThread->appendSql(QString::fromUtf8("update `ypsync_t_rec` set `reply_time`='%1' where `uuid`='%2'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(rep.Id)); ypSyncdataList.removeFirst(); } isSending = false; } void Core::reply_timeout9() { if(XfzdSyncdataLiet.length()>0){ XfzdSyncRep rep = XfzdSyncdataLiet.first(); dbThread->appendSql(QString::fromUtf8("update `xfzdsync_t_rec` set `reply_time`='%1' where `uuid`='%2'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(rep.Id)); XfzdSyncdataLiet.removeFirst(); } isSending9 = false; } void Core::time_out() { QSqlQuery qry; QSqlQuery qry1; int ret = 0; // printf("core time_out start\n"); time_t tmp_time = time(static_cast(nullptr)); ytShm->updatetime[CORE_MAIN] = tmp_time; if(!mdbOpened) { mdbOpened = mdb.open(); } if(isRunning) return; isRunning = true; if((tmp_time-lhworktime)>=1750){ QSqlQuery qry12; lhworktime=tmp_time; qry.clear(); syncDevList.clear(); qry = mdb.exec("select id,owner_name,owner_code,unitinfo,company,dwtype from sp_owner where company in ('10232','10318') and dwtype in (2,5)"); while(qry.next()){ syncDevList.append(YPSyncDev(qry.value(0).toInt(), qry.value(1).toString(), qry.value(2).toString(), qry.value(3).toString(), qry.value(4).toString(), qry.value(5).toInt())); } qry.clear(); qry = mdb.exec("select id,owner_name,owner_code,unitinfo,company,dwtype from sp_owner where owner_code in ('4023383030343730','4023383030343639')"); while(qry.next()){ syncDevList.append(YPSyncDev(qry.value(0).toInt(), qry.value(1).toString(), qry.value(2).toString(), qry.value(3).toString(), qry.value(4).toString(), qry.value(5).toInt())); } qry.clear(); XfzdDevList.clear(); qry = mdb.exec("select device_code,device_name,descript,device_type,device_type_name,open_project_id, dwtype, data, port,device_floor from sp_corps_share"); while(qry.next()){ XfzdDevList.append(XfzdSyncDev(qry.value(0).toString(), qry.value(1).toString(), qry.value(2).toString(), qry.value(3).toInt(), qry.value(4).toString(), qry.value(5).toString(), qry.value(6).toInt(), qry.value(7).toString().trimmed(), qry.value(8).toString(), qry.value(9).toString())); } qry.clear(); } if((tmp_time-lhworktime1)>=700){ lhworktime1=tmp_time; for(int i=0;i(nullptr)); ytShm->updatetime[CORE_MAIN] = tmp_time; YPSyncDev syncdev = syncDevList.at(i); QString jdata = ""; QJsonArray jajsonArray; QJsonObject jaobj; QJsonObject jaobj2; if(syncdev.DeviceType==6){ QString sql = QString("select point_code, point_data, content, data_time from sp_owner_status where device_id=%1").arg("4023383030343730"); qry = mdb.exec(sql); printf("core time_out6 start\n"); while(qry.next()){ if(syncdev.OwnerCode.compare("4023383030343730")==0){ if(qry.value(0).toInt()==65){ printf("core time_out7 start\n"); jaobj2.insert("pointValue", qry.value(1).toDouble()); jaobj2.insert("desc", syncdev.Unitinfo+"-"+"消防泵主管水压-压力正常"); jaobj2.insert("sensorId", 1211017); } }else if (syncdev.OwnerCode.compare("4023383030343639")==0) { if(qry.value(0).toInt()==66){ jaobj2.insert("pointValue", qry.value(1).toDouble()); jaobj2.insert("desc", syncdev.Unitinfo+"-"+"喷淋泵主管水压-压力正常"); jaobj2.insert("sensorId", 1211018); } } } }else { printf("core time_out2 start\n"); QString sql = QString("select point_code, point_data, content, data_time from sp_owner_status where device_id=%1 and point_code=4").arg(syncdev.OwnerCode); qry = mdb.exec(sql); while(qry.next()){ jaobj2.insert("pointValue", qry.value(1).toDouble()); } jaobj2.insert("desc", syncdev.Unitinfo+"-"+syncdev.OwnerName+"-压力正常"); jaobj2.insert("sensorId", syncdev.Id); } if(syncdev.Company.compare("10232")==0){ jdata.append(QString("\"mqttId\":\"%1\"").arg("a71c40bb-5b02-4741-881b-24449f699db5")); }else if (syncdev.Company.compare("10318")==0) { jdata.append(QString("\"mqttId\":\"%1\"").arg("a71c40bb-5b02-4741-881b-24449f699db6")); } jdata.append(QString(",\"action\":\"%1\"").arg("transpush")); if(syncdev.DeviceType==2){ jaobj.insert("deviceType", "XiaoFangShuiYa"); jaobj2.insert("unit", "MPa"); }else if (syncdev.DeviceType==5) { jaobj.insert("deviceType", "YeWei"); jaobj2.insert("unit", "m-米"); }else { jaobj.insert("deviceType", "XiaoFangShuiYa"); jaobj2.insert("unit", "MPa"); } jaobj.insert("dataType", "deviceInfo"); jaobj.insert("provider", "Usky"); jaobj.insert("softVersion", "1.00.00"); jaobj.insert("hardVersion", "0.1"); jaobj2.insert("status", 0); jaobj2.insert("lowThreshold", 0.07); jaobj2.insert("highThreshold", 1.2); jaobj2.insert("sendTime", 1800); jajsonArray.append(jaobj2); jaobj["sensorList"]=jajsonArray; jdata.append(QString(",\"data\":%1").arg(QString(QJsonDocument(jaobj).toJson()))); QString jasign3=jdata.replace("\r","").replace("\n","").replace(" ",""); SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""),"{"+jasign3+"}"); } } // if((tmp_time-xfzdworktime)>44000){ // xfzdworktime=tmp_time; hour = QDateTime::currentDateTime().time().hour(); minute = QDateTime::currentDateTime().time().minute(); if(hour1 != hour){ hour1 = hour; if(hour%6 == 0){ for(int i=0;i(nullptr)); ytShm->updatetime[CORE_MAIN] = tmp_time; qry.clear(); XfzdSyncDev xfzddev = XfzdDevList.at(i); time_t myt=time(NULL); QString jdata = ""; QString sql = QString("select point_code, point_data, content, data_time from sp_owner_status where device_id=%1").arg(xfzddev.DeviceCode); jdata.append(QString("\"descript\":\"%1\"").arg(xfzddev.Descript)); jdata.append(QString(",\"deviceName\":\"%1\"").arg(xfzddev.DeviceName)); if(xfzddev.devCategory==6){ jdata.append(QString(",\"deviceNo\":\"%1\"").arg(xfzddev.DeviceCode+xfzddev.Port)); }else{ jdata.append(QString(",\"deviceNo\":\"%1\"").arg(xfzddev.DeviceCode)); } jdata.append(QString(",\"deviceType\":\"%1\"").arg(xfzddev.DeviceType)); jdata.append(QString(",\"deviceTypeName\":\"%1\"").arg(xfzddev.DeviceTypeName)); jdata.append(QString(",\"openProjectId\":\"%1\"").arg(xfzddev.OpenProjectId)); jdata.append(QString(",\"floor\":\"%1\"").arg(xfzddev.DeviceFloor)); qry = mdb.exec(sql); if(xfzddev.devCategory==2){ while(qry.next()){ if(qry.value(0).toInt()==4){ jdata.append(QString(",\"logTime\":\"%1\"").arg(QDateTime::fromTime_t(myt).toString("yyyy-MM-dd HH:mm:ss"))); jdata.append(QString(",\"pressure\":\"%1\"").arg(qry.value(1).toString())); }else if(qry.value(0).toInt()==1){ if(qry.value(2).toString().indexOf(QString::fromUtf8("正常"))==0){ jdata.append(QString(",\"alarmStatus\":\"%1\"").arg(0)); }else if(qry.value(2).toString().indexOf(QString::fromUtf8("低压"))==0){ jdata.append(QString(",\"alarmStatus\":\"%1\"").arg(1)); }else if(qry.value(2).toString().indexOf(QString::fromUtf8("高压"))==0){ jdata.append(QString(",\"alarmStatus\":\"%1\"").arg(2)); } } } if(xfzddev.DeviceType==302){ XfzdSyncData(0,QUuid::createUuid().toString().replace("{","").replace("}",""), "{"+jdata+"}",xfzddev.devCategory,xfzddev.DeviceCode); }else if(xfzddev.DeviceType==301){ XfzdSyncData(1,QUuid::createUuid().toString().replace("{","").replace("}",""), "{"+jdata+"}",xfzddev.devCategory,xfzddev.DeviceCode); }else if(xfzddev.DeviceType==305){ XfzdSyncData(13,QUuid::createUuid().toString().replace("{","").replace("}",""), "{"+jdata+"}",xfzddev.devCategory,xfzddev.DeviceCode); }else if(xfzddev.DeviceType==304){ XfzdSyncData(14,QUuid::createUuid().toString().replace("{","").replace("}",""), "{"+jdata+"}",xfzddev.devCategory,xfzddev.DeviceCode); } }else if(xfzddev.devCategory==5){ while(qry.next()){ if(qry.value(0).toInt()==4){ jdata.append(QString(",\"logTime\":\"%1\"").arg(QDateTime::fromTime_t(myt).toString("yyyy-MM-dd HH:mm:ss"))); jdata.append(QString(",\"level\":\"%1\"").arg(qry.value(1).toString())); }else if(qry.value(0).toInt()==1){ if(qry.value(2).toString().indexOf(QString::fromUtf8("正常"))==0){ jdata.append(QString(",\"alarmStatus\":\"%1\"").arg(0)); }else if(qry.value(2).toString().indexOf(QString::fromUtf8("低液位"))==0){ jdata.append(QString(",\"alarmStatus\":\"%1\"").arg(1)); }else if(qry.value(2).toString().indexOf(QString::fromUtf8("高液位"))==0){ jdata.append(QString(",\"alarmStatus\":\"%1\"").arg(2)); } } } if(xfzddev.DeviceType==402){ XfzdSyncData(2,QUuid::createUuid().toString().replace("{","").replace("}",""), "{"+jdata+"}",xfzddev.devCategory,xfzddev.DeviceCode); }else{ XfzdSyncData(3,QUuid::createUuid().toString().replace("{","").replace("}",""), "{"+jdata+"}",xfzddev.devCategory,xfzddev.DeviceCode); } }else if(xfzddev.devCategory==6){ if(xfzddev.DeviceType==258||xfzddev.DeviceType==256||xfzddev.DeviceType==452){ QList pnoList = getPnoValue(xfzddev.Data); QJsonArray jajsonArray; for(int i=0;i pnoList = getPnoValue(xfzddev.Data); jdata.append(QString(",\"logTime\":\"%1\"").arg(QDateTime::fromTime_t(myt).toString("yyyy-MM-dd HH:mm:ss"))); while(qry.next()){ for(int i=0;i0)){ isSending = true; ypCount=ypCount+1; SyncRep rep = ypSyncdataList.first(); dbThread->appendSql(QString("insert into `ypsync_t_rec` (`id`,`uuid`,`data_str`, `send`, `store_time`) values (NULL,'%1','%2',0,'%3')") .arg(rep.Id).arg(rep.JsonStr).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))); QByteArray Report = rep.JsonStr.toUtf8(); QNetworkRequest *req = new QNetworkRequest(); req->setUrl(QUrl("https://iot.usky.cn/ytapi/admin/Manage/ceShiUrl")); req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json; charset=UTF-8"); req->setHeader(QNetworkRequest::ContentLengthHeader,QString("%1").arg(Report.length()).toUtf8()); QNetworkReply *reply = netAccessManager->post(*req,Report); QReplayTimeout *pTimeout = new QReplayTimeout(reply,10000); connect(pTimeout, SIGNAL(net_timeout()),this,SLOT(reply_timeout())); } if((!isSending9)&&(XfzdSyncdataLiet.length()>0)){ isSending9 = true; XfzdSyncRep rep = XfzdSyncdataLiet.first(); QByteArray Report = rep.JsonStr.toUtf8(); QNetworkRequest *req = new QNetworkRequest(); if(rep.Xh==1){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/sprinkler/pipepressunusual")); }else if(rep.Xh==0){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/hydrant/pipepress")); }else if(rep.Xh==2){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/hydrant/tanklevel")); }else if(rep.Xh==3){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/hydrant/tanklevel")); }else if(rep.Xh==4){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/hydrant/pumpstatus")); }else if(rep.Xh==5){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/sprinkler/spraypump")); }else if(rep.Xh==6){ req->setUrl(QUrl("http://iot.shxf-119.com/access/event/fire/alarm/fireinfo")); }else if(rep.Xh==7){ req->setUrl(QUrl("http://iot.shxf-119.com/access/event/fault/alarm/freport")); }else if(rep.Xh==8){ req->setUrl(QUrl("http://iot.shxf-119.com/access/event/action/alarm/supervise")); }else if(rep.Xh==9){ req->setUrl(QUrl("http://iot.shxf-119.com/access/event/fire/alarm/manual")); }else if(rep.Xh==10){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/alarm/reset")); }else if(rep.Xh==11){ req->setUrl(QUrl("http://iot.shxf-119.com/access/event/action/alarm/linkagefeedback")); }else if(rep.Xh==12){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/smoke/smokefan")); }else if(rep.Xh==13){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/hydrant/endpressure")); }else if(rep.Xh==14){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/sprinkler/endpressure")); }else if(rep.Xh==15){ req->setUrl(QUrl("http://iot.shxf-119.com/access/devlog/transmission/devicestatus")); } req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json; charset=UTF-8"); req->setRawHeader("appKey","850404889644236801"); req->setHeader(QNetworkRequest::ContentLengthHeader,QString("%1").arg(Report.length()).toUtf8()); dbThread->appendSql(QString("insert into `xfzdsync_t_rec` (`id`,`uuid`,`data_str`, `send`, `store_time`, `device_code`) values (NULL,'%1','%2',0,'%3','%4')") .arg(rep.Id).arg( req->url().toString()+"\r\n"+ rep.JsonStr).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(rep.deviceCode)); QNetworkReply *reply = XfzdnetAccessManager->post(*req,Report); QReplayTimeout *pTimeout = new QReplayTimeout(reply,10000); connect(pTimeout, SIGNAL(net_timeout()),this,SLOT(reply_timeout9())); } if(sqlList.length()>0){ if(db.transaction()){ while(sqlList.length()>0){ db.exec(sqlList.first()); sqlList.removeFirst(); } db.commit(); } } // if(sqlList2.length()>0){ // QSqlDatabase recdb; // if(QSqlDatabase::contains("rec_db")) // recdb = QSqlDatabase::database("rec_db"); // else // recdb = QSqlDatabase::addDatabase("QSQLITE","rec_db"); // recdb.setDatabaseName(QString("/root/db/watchdoglog%1.db").arg(QDate::currentDate().toString("yyyyMMdd"))); // if(recdb.open()){ // if(!chk_table("ypsync_t_rec",recdb.tables())) // { // recdb.exec("create table `ypsync_t_rec` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20))"); // } // if(!chk_table("ypsync_t_rec_dis",recdb.tables())) // { // recdb.exec("create table `ypsync_t_rec_dis` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20))"); // } // if(!chk_table("ypsync_t_rec_xy",recdb.tables())) // { // recdb.exec("create table `ypsync_t_rec_xy` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20))"); // } // if(!chk_table("cnsync_t_rec",recdb.tables())){ // recdb.exec("create table `cnsync_t_rec` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20))"); // } // if(!chk_table("jasync_t_rec",recdb.tables())){ // recdb.exec("create table `jasync_t_rec` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20))"); // } // if(!chk_table("hpsync_t_rec",recdb.tables())){ // recdb.exec("create table `hpsync_t_rec` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20))"); // } // if(!chk_table("newcnsync_t_rec",recdb.tables())){ // recdb.exec("create table `newcnsync_t_rec` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20))"); // } // if(!chk_table("ypywsync_t_rec",recdb.tables())){ // recdb.exec("create table `ypywsync_t_rec` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20))"); // } // if(!chk_table("xfzdsync_t_rec",recdb.tables())){ // recdb.exec("create table `xfzdsync_t_rec` (`id` integer primary key autoincrement, `uuid` text(40), `data_str` text(1024), `send` integer , `store_time` text(20), `reply_str` text(1024), `reply_time` text(20), `device_code` text(40))"); // } // if(recdb.transaction()){ // while(sqlList2.length()>0){ // recdb.exec(sqlList2.first()); // sqlList2.removeFirst(); // } // recdb.commit(); // } // recdb.close(); // } // QSqlDatabase::removeDatabase("rec_db"); // } if((tmp_time-work_time)>59){ work_time = tmp_time; qry = db.exec("select `app_name`, `app_path`, `keep_working`, `wait_time` , `log_limit`, `keep_size` from `app_t_conf`"); while(qry.next()){ QString app_name = qry.value(0).toString(); QString app_path = qry.value(1).toString(); bool keep_working = (qry.value(2).toUInt()==1); uint wait_time = qry.value(3).toUInt(); bool log_limit = (qry.value(4).toUInt()==1); qint64 keep_size = qry.value(5).toLongLong(); if(app_name.compare("workerman")==0){ QFileInfoList loglist= QDir(QString("%1").arg(app_path)).entryInfoList(); qint64 current_size = 0; uint current_time = 0; // bool nofile = true; for(int i=0;i=0)) { // nofile = false; current_size += info.size(); if(info.lastModified().toTime_t()>current_time) current_time = info.lastModified().toTime_t(); } } if(log_limit){ if(current_size>keep_size){ ret = system(QString("rm -f %1/*.log").arg(app_path).toUtf8().data()); db.exec(QString("insert into operation_t_rec (`id`, `app_name`, `operation_type`, `operation_comment`,`store_time`) values (NULL,'%1',2,'delete file %2/*.log', '%3')").arg(app_name).arg(app_path).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))); } } }else{ QDir dir(QString("%1/log").arg(app_path)); dir.setSorting(QDir::Time|QDir::Reversed); QFileInfoList loglist = dir.entryInfoList(); qint64 current_size = 0; uint current_time = 0; // bool nofile = true; for(int i=0;icurrent_time) current_time = info.lastModified().toTime_t(); } } if(log_limit){ if(current_size>keep_size) { for(int i=0;i0)) { if(QFile(info.absoluteFilePath()).remove()) { db.exec(QString("insert into operation_t_rec (`id`, `app_name`, `operation_type`, `operation_comment`,`store_time`) values (NULL,'%1',2,'delete file %2', '%3')").arg(app_name).arg(info.fileName()).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))); current_size -= f_size; } } if(current_size<=keep_size) break; } ret = system(QString("rm -f %1/vendor/workerman/*.log").arg(app_path).toUtf8().data()); } } uint c_time = QDateTime::currentDateTime().toTime_t(); if(keep_working) { if(((c_time-wait_time)>(current_time+(times*60))) &&(current_time>0)) { ret = system(QString("cd %1 && php start.php restart -d && cd").arg(app_path).toUtf8().data()); db.exec(QString("insert into operation_t_rec (`id`, `app_name`, `operation_type`, `operation_comment`,`store_time`) values (NULL,'%1',1,'restart(%2)', '%3')").arg(app_name).arg(QDateTime::fromTime_t(current_time).toString("yyyy-MM-dd HH:mm:ss")).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))); } } } } qry.clear(); } times++; isRunning = false; mdb.close(); mdbOpened = false; } QList Core::getPnoValue(QString pnoset) { QList list; QJsonParseError json_error; QJsonDocument jsonDoc(QJsonDocument::fromJson(pnoset.toUtf8(),&json_error)); if(json_error.error == QJsonParseError::NoError){ QJsonArray json_root = jsonDoc.array(); for(int i=0;i-2)&&(name.length()>0)) list.append(CnPno(name,port,defvalue)); } } return list; } bool Core::chk_table(QString tablename, QStringList tables) { for(int i=0;i