Browse Source

Merge branch 'dev-zyj' of usky-cloud-paas/data-writer into master

James 1 year ago
parent
commit
6f75ae7c26

+ 6 - 3
ytDataWriteProcess/databaseeventthread.cpp

@@ -2,10 +2,13 @@
 
 //#define HostName "172.17.35.51"
 //#define HostName "124.71.140.20"
-#define HostName "172.16.120.165"
+//#define HostName "172.16.120.165"
+#define HostName "uskycloud000.mysql.rds.aliyuncs.com"
 #define HostPort 3306
-#define UserName "usky"
-#define PassWord "Yt#75Usky"
+#define UserName "usky_admin"
+//"usky"
+#define PassWord "Usky@2023!@#$_"
+//"Yt#75Usky"
 #define DatabaseName "usky-data"
 
 DatabaseEventThread::DatabaseEventThread(QObject *parent) : QThread(parent)

+ 6 - 3
ytDataWriteProcess/databasethread.cpp

@@ -2,10 +2,13 @@
 
 //#define HostName "172.17.35.51"
 //#define HostName "124.71.140.20"
-#define HostName "172.16.120.165"
+//#define HostName "172.16.120.165"
+#define HostName "uskycloud000.mysql.rds.aliyuncs.com"
 #define HostPort 3306
-#define UserName "usky"
-#define PassWord "Yt#75Usky"
+#define UserName "usky_admin"
+//"usky"
+#define PassWord "Usky@2023!@#$_"
+//"Yt#75Usky"
 #define DatabaseName "usky-data"
 
 DatabaseThread::DatabaseThread(QObject *parent) : QThread(parent)

+ 3 - 3
ytDataWriteProcess/dealmqttalarmthread.cpp

@@ -36,7 +36,7 @@ void DealMqttAlarmThread::run()
                     QJsonObject obj = doc.object();
                     QString deviceId = obj.value("device_id").toString();
                     QString deviceCode = obj.value("device_code").toString();
-                    QString companyCode = obj.value("product_id").toString();
+                    QString productCode = obj.value("product_id").toString();
                     int timeStamp = obj.value("timestamp").toInt();
                     QString dataTime = QDateTime::fromTime_t(timeStamp).toString("yyyy-MM-dd HH:mm:ss");
                     QString deviceType = obj.value("device_type").toString();
@@ -48,7 +48,7 @@ void DealMqttAlarmThread::run()
                         devBrief = spit.at(1);
                     }
 
-                    if((devType.length()==3)&&(devType.startsWith("5"))){
+//                    if((devType.length()==3)&&(devType.startsWith("5"))){
                         QString attribute_name = "";
                         QString attribute_value = "";
 
@@ -73,7 +73,7 @@ void DealMqttAlarmThread::run()
                         attribute_value = attribute_value.left(attribute_value.length()-1);
                         QString sql = QString("insert into alarm_%1 (%2) values(%3);").arg(devBrief).arg(attribute_name).arg(attribute_value);
                         emit dmqSql(sql);
-                    }
+//                    }
 
                 }
 

+ 3 - 3
ytDataWriteProcess/dealmqtteventthread.cpp

@@ -36,7 +36,7 @@ void DealMqttEventThread::run()
                     QJsonObject obj = doc.object();
                     QString deviceId = obj.value("device_id").toString();
                     QString deviceCode = obj.value("device_code").toString();
-                    QString companyCode = obj.value("product_id").toString();
+                    QString productCode = obj.value("product_id").toString();
                     int timeStamp = obj.value("timestamp").toInt();
                     QString dataTime = QDateTime::fromTime_t(timeStamp).toString("yyyy-MM-dd HH:mm:ss");
                     QString deviceType = obj.value("device_type").toString();
@@ -48,7 +48,7 @@ void DealMqttEventThread::run()
                         devBrief = spit.at(1);
                     }
 
-                    if((devType.length()==3)&&(devType.startsWith("5"))){
+//                    if((devType.length()==3)&&(devType.startsWith("5"))){
                         QString attribute_name = "";
                         QString attribute_value = "";
 
@@ -73,7 +73,7 @@ void DealMqttEventThread::run()
                         attribute_value = attribute_value.left(attribute_value.length()-1);
                         QString sql = QString("insert into event_%1 (%2) values(%3);").arg(devBrief).arg(attribute_name).arg(attribute_value);
                         emit dmqSql(sql);
-                    }
+//                    }
 
                 }
 

+ 7 - 7
ytDataWriteProcess/dealmqttthread.cpp

@@ -36,7 +36,7 @@ void DealMqttThread::run()
                     QJsonObject obj = doc.object();
                     QString deviceId = obj.value("device_id").toString();
                     QString deviceCode = obj.value("device_code").toString();
-                    QString companyCode = obj.value("product_id").toString();
+                    QString productCode = obj.value("product_id").toString();
                     int timeStamp = obj.value("timestamp").toInt();
                     QString dataTime = QDateTime::fromTime_t(timeStamp).toString("yyyy-MM-dd HH:mm:ss");
                     QString deviceType = obj.value("device_type").toString();
@@ -48,24 +48,24 @@ void DealMqttThread::run()
                         devBrief = spit.at(1);
                     }
 
-                    if((devType.length()==3)&&(devType.startsWith("5"))){
+//                    if((devType.length()==3)&&(devType.startsWith("5"))){
                         QJsonValue metric_value = obj.value("metrics");
 
                         QJsonObject metric_obj = metric_value.toObject();
                         QVariantMap fd = metric_obj.toVariantMap();
                         QVariantMap::Iterator iter;
                         QString sql = "";
-                        QString sql1 = QString("insert into data_%1_history(id,device_id,device_code,device_type,attribute_name,attribute_data,data_time,insert_time) values").arg(devBrief);
+                        QString sql1 = QString("insert into data_%1_history(id,device_id,product_code,device_type,attribute_name,attribute_data,data_time,insert_time) values").arg(devBrief);
                         for(iter=fd.begin();iter!=fd.end();iter++){
-                            sql.append(QString("insert into data_real_time (id, device_id, device_code, device_type, attribute_name, attribute_data, data_time, insert_time) values(null,'%1','%2',%3,'%4','%5','%6','%7') ON DUPLICATE KEY UPDATE  attribute_data = values(attribute_data),data_time = values(data_time),insert_time = values(insert_time);")
-                                    .arg(deviceId).arg(deviceCode).arg(devType).arg(iter.key()).arg(iter.value().toString()).arg(dataTime).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")));
+                            sql.append(QString("insert into data_real_time (id, device_id, product_code, device_type, attribute_name, attribute_data, data_time, insert_time) values(null,'%1','%2',%3,'%4','%5','%6','%7') ON DUPLICATE KEY UPDATE  attribute_data = values(attribute_data),data_time = values(data_time),insert_time = values(insert_time);")
+                                    .arg(deviceId).arg(productCode).arg(devType).arg(QString(iter.key()).toLower()).arg(iter.value().toString()).arg(dataTime).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")));
                             sql1.append(QString("(NULL,'%1','%2',%3,'%4','%5','%6','%7'),")
-                                       .arg(deviceId).arg(deviceCode).arg(devType).arg(iter.key()).arg(iter.value().toString()).arg(dataTime).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")));
+                                       .arg(deviceId).arg(productCode).arg(devType).arg(QString(iter.key()).toLower()).arg(iter.value().toString()).arg(dataTime).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")));
 
                         }
                         sql.append(sql1.left(sql1.length()-1).append(" ON DUPLICATE KEY UPDATE  attribute_data = values(attribute_data),insert_time = values(insert_time);"));
                         emit dmqSql(sql);
-                    }
+//                    }
 
                 }
 

+ 2 - 2
ytDataWriteProcess/writecore.cpp

@@ -14,7 +14,7 @@ WriteCore::WriteCore(QObject *parent) : QObject(parent)
 
     dbeventthread = new DatabaseEventThread(this);
     dbeventthread->start();
-    connect(dbthread,&DatabaseThread::dbdata_log,this,&WriteCore::dbdata_log);
+    connect(dbeventthread,&DatabaseEventThread::dbdata_log,this,&WriteCore::dbdata_log);
 
     logthread = new LogThread(this);
     logthread->start();
@@ -66,7 +66,7 @@ void WriteCore::start()
 
 void WriteCore::time_out()
 {
-    dataWriteShm->processStatus[1].t_time = QDateTime::currentDateTime().toTime_t();
+//    dataWriteShm->processStatus[1].t_time = QDateTime::currentDateTime().toTime_t();
 
 }