db_syncthread.cpp 148 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203
  1. #include "db_syncthread.h"
  2. #include "ytservicecore.h"
  3. #include <time.h>
  4. #include <openssl/md5.h>
  5. #include <string.h>
  6. //void chkmd5(const char *data, char *md5){
  7. // MD5_CTX ctx;
  8. // unsigned char tmp,md[16];
  9. // int i;
  10. // MD5_Init(&ctx);
  11. // MD5_Update(&ctx,data,strlen(data));
  12. // MD5_Final(md,&ctx);
  13. // for(i=0;i<16;i++){
  14. // tmp = (md[i]>>4)&0x0f;
  15. // if(tmp<10)
  16. // md5[i*2+0] = (char)(tmp+0x30);
  17. // else
  18. // md5[i*2+0] = (char)(tmp+0x37);
  19. // tmp = md[i]&0x0f;
  20. // if(tmp<10)
  21. // md5[i*2+1] = (char)(tmp+0x30);
  22. // else
  23. // md5[i*2+1] = (char)(tmp+0x37);
  24. // }
  25. // md5[32] = 0x00;
  26. //}
  27. bool compareAlarmSet(const AlarmSet &a1, const AlarmSet &a2)
  28. {
  29. if(a1.AlarmTime>a2.AlarmTime)
  30. return true;
  31. return false;
  32. }
  33. DB_SyncThread::DB_SyncThread(QObject *parent) :
  34. QThread(parent)
  35. {
  36. isWorking = false;
  37. deviceDataList.clear();
  38. day = 255;
  39. initTime = true;
  40. ProgramConf *conf = new ProgramConf(this);
  41. mdb = QSqlDatabase::addDatabase(conf->getDbDrive(),conf->getDbConnectName());
  42. mdb.setDatabaseName(conf->getDbName());
  43. mdb.setHostName(conf->getDbHost());
  44. mdb.setPort(conf->getDbPort());
  45. mdb.setUserName(conf->getDbUser());
  46. mdb.setPassword(conf->getDbPassword());
  47. mdbOpened = mdb.open();
  48. }
  49. bool DB_SyncThread::userInfoSync(QString devid,QString deviceCode, uint sync_id,QString tbname,QDate chkday,uint ID, QString companyCode)
  50. {
  51. QString qrysql,sql;
  52. QString upsql_0="select 1;",upsql_1="select 1;";
  53. bool found = false;
  54. bool updated = false;
  55. int count=0;
  56. QSqlQuery qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_hj2017 where device_code='%1' and data1<>'U44' and time<now()").arg(devid));
  57. if(qry2.next()){
  58. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  59. .arg(qry2.value(0).toInt())
  60. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  61. .arg(devid));
  62. }
  63. qry2.clear();
  64. qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_hj2017 where device_code='%1' and data1='U44' and time<now()").arg(devid));
  65. if(qry2.next()){
  66. mdb.exec(QString("update sp_device_sync set com_count=%1, com_confirm=%2 where device_id='%3'")
  67. .arg(qry2.value(0).toInt())
  68. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  69. .arg(devid));
  70. }
  71. qry2.clear();
  72. for(int i=0;i<dList.length();i++){
  73. if(dList.at(i).compare(deviceCode)==0)
  74. {
  75. found = true;
  76. break;
  77. }
  78. }
  79. if(!found){
  80. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','0','','1970-01-01 08:00:00','');").arg(deviceCode));
  81. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','1','','1970-01-01 08:00:00','');").arg(deviceCode));
  82. dList.append(deviceCode);
  83. pcList.append(0);
  84. dList.append(deviceCode);
  85. pcList.append(1);
  86. }
  87. qrysql = QString("select id, data3, data5, time, data2, data4 from `%1` where id> %2 and time>'%3-%4-%5 00:00:00' order by id").arg(tbname).arg(sync_id).arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0'));
  88. qry2 = mdb.exec(qrysql);
  89. while(qry2.next()){
  90. setCompanyAlarmSet(deviceCode, AlarmSet(0xffffffff,"",QString::fromUtf8("%1,%2").arg(qry2.value(4).toString()).arg(qry2.value(5).toString()),1,qry2.value(3).toDateTime().toTime_t(),1));
  91. updated = true;
  92. if(count==0)
  93. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  94. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(1).isNull()?"0":"1")
  95. .arg(qry2.value(2).isNull()?"":qry2.value(2).toString()).arg(qry2.value(3).isNull()?"1970-01-01 08:00:00":qry2.value(3).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  96. .arg(qry2.value(4).isNull()?"":qry2.value(4).toString()).arg(qry2.value(5).isNull()?"":qry2.value(5).toString());
  97. else
  98. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  99. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(1).isNull()?"0":"1")
  100. .arg(qry2.value(2).isNull()?"":qry2.value(2).toString()).arg(qry2.value(3).isNull()?"1970-01-01 08:00:00":qry2.value(3).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  101. .arg(qry2.value(4).isNull()?"":qry2.value(4).toString()).arg(qry2.value(5).isNull()?"":qry2.value(5).toString());
  102. if(qry2.value(1).isNull())
  103. upsql_0 = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3 %4', point_name='通信报警',dwtype=%5 where device_id='%6' and point_code='%7';")
  104. .arg(qry2.value(2).isNull()?"":qry2.value(2).toString()).arg(qry2.value(3).isNull()?"1970-01-01 08:00:00":qry2.value(3).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  105. .arg(qry2.value(4).isNull()?"":qry2.value(4).toString()).arg(qry2.value(5).isNull()?"":qry2.value(5).toString())
  106. .arg(1).arg(devid).arg("0");
  107. else
  108. upsql_1 = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3 %4', point_name='主机报警',dwtype=%5 where device_id='%6' and point_code!='0';")
  109. .arg(qry2.value(2).isNull()?"":qry2.value(2).toString()).arg(qry2.value(3).isNull()?"1970-01-01 08:00:00":qry2.value(3).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  110. .arg(qry2.value(4).isNull()?"":qry2.value(4).toString()).arg(qry2.value(5).isNull()?"":qry2.value(5).toString())
  111. .arg(1).arg(devid);
  112. sync_id = qry2.value(0).toUInt();
  113. count++;
  114. if(count>=100){
  115. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  116. ytShm->updatetime[DB_THREAD] = tmp_time;
  117. sql.append(";");
  118. mdb.exec(sql);
  119. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  120. mdb.exec(upsql_0);
  121. mdb.exec(upsql_1);
  122. sql = "";
  123. count=0;
  124. }
  125. }
  126. if(count>0){
  127. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  128. ytShm->updatetime[DB_THREAD] = tmp_time;
  129. sql.append(";");
  130. mdb.exec(sql);
  131. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  132. mdb.exec(upsql_0);
  133. mdb.exec(upsql_1);
  134. sql = "";
  135. count=0;
  136. }
  137. return updated;
  138. }
  139. bool DB_SyncThread::waterInfoSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID,int dwtype, QString companyCode)
  140. {
  141. QString qrysql,sql,upsql;
  142. int count=0;
  143. bool updated = false;
  144. bool found = false;
  145. QSqlQuery qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_sj2017 where device_code='%1' and data1<>'WP4' and data1<>'LL4' and time<now()").arg(devid));
  146. // .arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')));
  147. if(qry2.next()){
  148. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  149. .arg(qry2.value(0).toInt())
  150. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  151. .arg(devid));
  152. }
  153. qry2.clear();
  154. qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_sj2017 where device_code='%1' and ( data1='WP4' or data1='LL4' ) and time<now()").arg(devid));
  155. if(qry2.next()){
  156. mdb.exec(QString("update sp_device_sync set com_count=%1, com_confirm=%2 where device_id='%3'")
  157. .arg(qry2.value(0).toInt())
  158. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  159. .arg(devid));
  160. }
  161. qry2.clear();
  162. for(int i=0;i<dList.length();i++){
  163. if(dList.at(i).compare(deviceCode)==0)
  164. {
  165. found = true;
  166. break;
  167. }
  168. }
  169. if(!found){
  170. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','1','','1970-01-01 08:00:00','');").arg(deviceCode));
  171. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','2','','1970-01-01 08:00:00','');").arg(deviceCode));
  172. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','3','','1970-01-01 08:00:00','');").arg(deviceCode));
  173. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','4','','1970-01-01 08:00:00','');").arg(deviceCode));
  174. dList.append(deviceCode);
  175. pcList.append(1);
  176. dList.append(deviceCode);
  177. pcList.append(2);
  178. dList.append(deviceCode);
  179. pcList.append(3);
  180. dList.append(deviceCode);
  181. pcList.append(4);
  182. }
  183. qrysql = QString("select id, time, data1, data2, data3, data4 from `%1` where id>%2 and time>'%3-%4-01 00:00:00' and time<now() order by id ").arg(tbname).arg(sync_id).arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0'));
  184. qry2 = mdb.exec(qrysql);
  185. while(qry2.next()){
  186. QString dat1 = qry2.value(2).toString();
  187. setCompanyAlarmSet(deviceCode, AlarmSet(0xffffffff,"",
  188. QString::fromUtf8("%1,%2").arg(QString::compare(dat1,"WP1")==0?QString::fromUtf8("低压"):
  189. (QString::compare(dat1,"WP2")==0?QString::fromUtf8("高压"):
  190. (QString::compare(dat1,"WP3")==0?QString::fromUtf8("故障"):
  191. (QString::compare(dat1,"WP4")==0?QString::fromUtf8("离线"):
  192. (QString::compare(dat1,"WP0")==0?QString::fromUtf8("恢复"):
  193. (QString::compare(dat1,"LL1")==0?QString::fromUtf8("低液位"):
  194. (QString::compare(dat1,"LL2")==0?QString::fromUtf8("高液位"):
  195. (QString::compare(dat1,"LL3")==0?QString::fromUtf8("故障"):
  196. (QString::compare(dat1,"LL4")==0?QString::fromUtf8("离线"):
  197. (QString::compare(dat1,"LL0")==0?QString::fromUtf8("恢复"):"")))))))))).arg(qry2.value(5).toString()),
  198. 2,qry2.value(1).toDateTime().toTime_t(),1));
  199. updated = true;
  200. if(count==0){
  201. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','%6')")
  202. .arg(qry2.value(0).toUInt()).arg(devid).arg(1).arg(qry2.value(2).isNull()?"0":qry2.value(2).toString())
  203. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  204. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  205. .arg(qry2.value(0).toUInt()).arg(devid).arg(2).arg(qry2.value(3).isNull()?"0":qry2.value(3).toString())
  206. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  207. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  208. .arg(qry2.value(0).toUInt()).arg(devid).arg(3).arg(qry2.value(4).isNull()?"0":qry2.value(4).toString())
  209. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  210. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  211. .arg(qry2.value(0).toUInt()).arg(devid).arg(4).arg(qry2.value(5).isNull()?"0":qry2.value(5).toString())
  212. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  213. }else{
  214. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  215. .arg(qry2.value(0).toUInt()).arg(devid).arg(1).arg(qry2.value(2).isNull()?"0":qry2.value(2).toString())
  216. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  217. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  218. .arg(qry2.value(0).toUInt()).arg(devid).arg(2).arg(qry2.value(3).isNull()?"0":qry2.value(3).toString())
  219. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  220. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  221. .arg(qry2.value(0).toUInt()).arg(devid).arg(3).arg(qry2.value(4).isNull()?"0":qry2.value(4).toString())
  222. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  223. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  224. .arg(qry2.value(0).toUInt()).arg(devid).arg(4).arg(qry2.value(5).isNull()?"0":qry2.value(5).toString())
  225. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  226. }
  227. QString wp = qry2.value(2).toString();
  228. if(wp.compare("WP0")==0)
  229. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='状态',dwtype=%4 where device_id='%5' and point_code='%6';")
  230. .arg(0)
  231. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  232. .arg(QString::fromUtf8("正常")).arg(dwtype).arg(devid).arg(1);
  233. else if(wp.compare("WP1")==0)
  234. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='状态',dwtype=%4 where device_id='%5' and point_code='%6';")
  235. .arg(1)
  236. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  237. .arg(QString::fromUtf8("低压")).arg(dwtype).arg(devid).arg(1);
  238. else if(wp.compare("WP2")==0)
  239. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='状态',dwtype=%4 where device_id='%5' and point_code='%6';")
  240. .arg(2)
  241. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  242. .arg(QString::fromUtf8("高压")).arg(dwtype).arg(devid).arg(1);
  243. else if(wp.compare("WP3")==0)
  244. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='状态',dwtype=%4 where device_id='%5' and point_code='%6';")
  245. .arg(3)
  246. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  247. .arg(QString::fromUtf8("故障")).arg(dwtype).arg(devid).arg(1);
  248. else if(wp.compare("WP4")==0)
  249. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='状态',dwtype=%4 where device_id='%5' and point_code='%6';")
  250. .arg(4)
  251. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  252. .arg(QString::fromUtf8("离线")).arg(dwtype).arg(devid).arg(1);
  253. upsql.append(QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='剩余电量',dwtype=%4 where device_id='%5' and point_code='%6';")
  254. .arg(qry2.value(3).isNull()?"0":qry2.value(3).toString())
  255. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  256. .arg("").arg(dwtype).arg(devid).arg(2));
  257. upsql.append(QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='无线信号',dwtype=%4 where device_id='%5' and point_code='%6';")
  258. .arg(qry2.value(4).isNull()?"0":qry2.value(4).toString())
  259. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  260. .arg("").arg(dwtype).arg(devid).arg(3));
  261. upsql.append(QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='水压/水位',dwtype=%4 where device_id='%5' and point_code='%6';")
  262. .arg(qry2.value(5).isNull()?"0":qry2.value(5).toString())
  263. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  264. .arg("").arg(dwtype).arg(devid).arg(4));
  265. count += 4;
  266. sync_id = qry2.value(0).toUInt();
  267. if(count>=100){
  268. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  269. ytShm->updatetime[DB_THREAD] = tmp_time;
  270. sql.append(";");
  271. mdb.exec(sql);
  272. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  273. mdb.exec(upsql);
  274. count=0;
  275. sql="";
  276. }
  277. }
  278. if(count>0){
  279. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  280. ytShm->updatetime[DB_THREAD] = tmp_time;
  281. sql.append(";");
  282. mdb.exec(sql);
  283. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  284. mdb.exec(upsql);
  285. count=0;
  286. sql="";
  287. }
  288. return updated;
  289. }
  290. bool DB_SyncThread::smokerInfoSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID, QString companyCode)
  291. {
  292. QString qrysql,sql,upsql;
  293. int count=0;
  294. bool found = false;
  295. bool updated = false;
  296. for(int i=0;i<dList.length();i++){
  297. if(dList.at(i).compare(deviceCode)==0)
  298. {
  299. found = true;
  300. count++;
  301. // break;
  302. }
  303. }
  304. if(!found){
  305. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','1','','1970-01-01 08:00:00','');").arg(deviceCode));
  306. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','2','','1970-01-01 08:00:00','');").arg(deviceCode));
  307. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','3','','1970-01-01 08:00:00','');").arg(deviceCode));
  308. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','4','','1970-01-01 08:00:00','');").arg(deviceCode));
  309. dList.append(deviceCode);
  310. pcList.append(1);
  311. dList.append(deviceCode);
  312. pcList.append(2);
  313. dList.append(deviceCode);
  314. pcList.append(3);
  315. dList.append(deviceCode);
  316. pcList.append(4);
  317. }else if(count==3){
  318. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','4','','1970-01-01 08:00:00','');").arg(deviceCode));
  319. dList.append(deviceCode);
  320. pcList.append(4);
  321. }
  322. count=0;
  323. QSqlQuery qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_hj2017 where device_code='%1' and data1<>'U44' and time<now()").arg(devid));
  324. if(qry2.next()){
  325. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  326. .arg(qry2.value(0).toInt())
  327. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  328. .arg(devid));
  329. }
  330. qry2.clear();
  331. qrysql = QString("select id, DeviceStatus, BatteryLevel, SensorLevel, storeTime,TData from %1 where id>%2 and storeTime>'%3-%4-01 00:00:00' and storeTime<now() and DeviceType=1")
  332. .arg(tbname).arg(sync_id).arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0'));
  333. qry2 = mdb.exec(qrysql);
  334. while(qry2.next()){
  335. updated = true;
  336. int sta = qry2.value(1).toInt();
  337. if(count==0){
  338. sql = QString::fromUtf8("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','%6')")
  339. .arg(qry2.value(0).toUInt()).arg(devid).arg(1).arg(qry2.value(1).toString())
  340. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  341. .arg(sta==1?QString::fromUtf8("报警")
  342. :(sta==2?QString::fromUtf8("报警静音")
  343. :(sta==4?QString::fromUtf8("低压")
  344. :(sta==5?QString::fromUtf8("故障")
  345. :(sta==7?QString::fromUtf8("正常")
  346. :"")))));
  347. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  348. .arg(qry2.value(0).toUInt()).arg(devid).arg(2).arg(qry2.value(2).toString())
  349. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  350. .arg("");
  351. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  352. .arg(qry2.value(0).toUInt()).arg(devid).arg(3).arg(qry2.value(3).toString())
  353. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  354. .arg("");
  355. if(qry2.value(5).toString().compare("-")!=0){
  356. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  357. .arg(qry2.value(0).toUInt()).arg(devid).arg(4).arg(qry2.value(5).toString())
  358. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  359. .arg("");
  360. }
  361. }else{
  362. sql += QString::fromUtf8(", (NULL,%1,'%2','%3','%4','%5','%6')")
  363. .arg(qry2.value(0).toUInt()).arg(devid).arg(1).arg(qry2.value(1).toString())
  364. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  365. .arg(sta==1?QString::fromUtf8("报警")
  366. :(sta==2?QString::fromUtf8("报警静音")
  367. :(sta==4?QString::fromUtf8("低压")
  368. :(sta==5?QString::fromUtf8("故障")
  369. :(sta==7?QString::fromUtf8("正常")
  370. :"")))));
  371. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  372. .arg(qry2.value(0).toUInt()).arg(devid).arg(2).arg(qry2.value(2).toString())
  373. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  374. .arg("");
  375. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  376. .arg(qry2.value(0).toUInt()).arg(devid).arg(3).arg(qry2.value(3).toString())
  377. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  378. .arg("");
  379. if(qry2.value(5).toString().compare("-")!=0){
  380. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  381. .arg(qry2.value(0).toUInt()).arg(devid).arg(4).arg(qry2.value(5).toString())
  382. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  383. .arg("");
  384. }
  385. }
  386. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='状态',dwtype=%4 where device_id='%5' and point_code='%6';")
  387. .arg(sta==7?0:sta)
  388. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  389. .arg(sta==1?QString::fromUtf8("报警")
  390. :(sta==2?QString::fromUtf8("报警静音")
  391. :(sta==4?QString::fromUtf8("低压")
  392. :(sta==5?QString::fromUtf8("故障")
  393. :(sta==7?QString::fromUtf8("正常")
  394. :"")))))
  395. .arg(3).arg(devid).arg(1);
  396. upsql.append(QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='剩余电量',dwtype=%4 where device_id='%5' and point_code='%6';")
  397. .arg(qry2.value(2).toString())
  398. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  399. .arg("").arg(3).arg(devid).arg(2));
  400. upsql.append(QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='无线信号',dwtype=%4 where device_id='%5' and point_code='%6';")
  401. .arg(qry2.value(3).toString())
  402. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  403. .arg("").arg(3).arg(devid).arg(3));
  404. if(qry2.value(5).toString().compare("-")!=0){
  405. upsql.append(QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3', point_name='温度',dwtype=%4 where device_id='%5' and point_code='%6';")
  406. .arg(qry2.value(5).toString())
  407. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  408. .arg("").arg(6).arg(devid).arg(4));
  409. }
  410. count += 3;
  411. sync_id = qry2.value(0).toUInt();
  412. if(count>=100){
  413. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  414. ytShm->updatetime[DB_THREAD] = tmp_time;
  415. sql.append(";");
  416. mdb.exec(sql);
  417. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  418. mdb.exec(upsql);
  419. count=0;
  420. sql="";
  421. }
  422. }
  423. if(count>0){
  424. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  425. ytShm->updatetime[DB_THREAD] = tmp_time;
  426. sql.append(";");
  427. mdb.exec(sql);
  428. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  429. mdb.exec(upsql);
  430. count=0;
  431. sql="";
  432. }
  433. return updated;
  434. }
  435. bool DB_SyncThread::rtuInfoSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID, QString companyCode)
  436. {
  437. QString qrysql,sql,upsql="";
  438. int count=0;
  439. bool found = false;
  440. bool updated= false;
  441. QSqlQuery qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_rtu2017 where device_code='%1' and status<>'44' and time<now()").arg(devid));
  442. // .arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')));
  443. if(qry2.next()){
  444. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  445. .arg(qry2.value(0).toInt())
  446. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  447. .arg(devid));
  448. }
  449. qry2.clear();
  450. qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_rtu2017 where device_code='%1' and status='44' and time<now()").arg(devid));
  451. // .arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')));;
  452. if(qry2.next()){
  453. mdb.exec(QString("update sp_device_sync set com_count=%1, com_confirm=%2 where device_id='%3'")
  454. .arg(qry2.value(0).toInt())
  455. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  456. .arg(devid));
  457. }
  458. qry2.clear();
  459. found = false;
  460. for(int i=0;i<dList.length();i++){
  461. if(dList.at(i).compare(deviceCode)==0){
  462. found = true;
  463. break;
  464. }
  465. }
  466. if(!found){
  467. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','','%2','','1970-01-01 08:00:00','');").arg(deviceCode).arg(0));
  468. dList.append(deviceCode);
  469. pcList.append(0);
  470. }
  471. qrysql = QString("select id, status, port, ncmd, data3, data2, data4, time, data1 from %1 where id>%2 and time>'%3-%4-%5 00:00:00' and time<now()")
  472. .arg(tbname).arg(sync_id).arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0'));
  473. qry2 = mdb.exec(qrysql);
  474. QSqlQuery qry3 = mdb.exec(QString("select iotype,ports,ioname,systypeup from sp_owner_port where owner_code='%1'").arg(devid));
  475. QStringList nameList,vonameList;
  476. QList<int> typeList,portList;
  477. while(qry3.next()){
  478. typeList.append(qry3.value(0).toInt());
  479. portList.append(qry3.value(1).toInt());
  480. nameList.append(qry3.value(2).toString());
  481. vonameList.append(qry3.value(3).toString());
  482. found = false;
  483. if(qry3.value(0).toInt()==1){
  484. for(int i=0;i<dList.length();i++){
  485. if(dList.at(i).compare(deviceCode)==0){
  486. if(pcList.at(i)==qry3.value(1).toInt()){
  487. found = true;
  488. break;
  489. }
  490. }
  491. }
  492. if(found)
  493. mdb.exec(QString("update sp_owner_status set point_name='%1',dwtype=6 where device_id='%2' and point_code='%3'")
  494. .arg(qry3.value(2).toString()).arg(devid).arg(qry3.value(1).toInt()));
  495. else{
  496. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','%2','%3','','1970-01-01 08:00:00','');").arg(deviceCode).arg(qry3.value(2).toString()).arg(qry3.value(1).toInt()));
  497. dList.append(deviceCode);
  498. pcList.append(qry3.value(1).toInt());
  499. }
  500. }else{
  501. for(int i=0;i<dList.length();i++){
  502. if(dList.at(i).compare(deviceCode)==0){
  503. if(pcList.at(i)==(qry3.value(1).toInt()+64)){
  504. found = true;
  505. break;
  506. }
  507. }
  508. }
  509. if(found)
  510. mdb.exec(QString("update sp_owner_status set point_name='%1',dwtype=6 where device_id='%2' and point_code='%3'")
  511. .arg(qry3.value(2).toString()).arg(devid).arg(qry3.value(1).toInt()+64));
  512. else{
  513. mdb.exec(QString("insert into sp_owner_status (id,device_id,point_name,point_code,point_data,data_time,content) values (NULL,'%1','%2','%3','','1970-01-01 08:00:00','');").arg(deviceCode).arg(qry3.value(2).toString()).arg(qry3.value(1).toInt()+64));
  514. dList.append(deviceCode);
  515. pcList.append(qry3.value(1).toInt()+64);
  516. }
  517. }
  518. }
  519. qry3.clear();
  520. while(qry2.next()){
  521. updated = true;
  522. if(qry2.value(1).toString().compare("44")==0)
  523. {
  524. if(count==0)
  525. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  526. .arg(qry2.value(0).toUInt()).arg(devid).arg(0).arg(1).arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  527. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  528. else
  529. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  530. .arg(qry2.value(0).toUInt()).arg(devid).arg(0).arg(1).arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  531. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  532. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3 %4', point_name='通信报警',dwtype=%5 where device_id='%6' and point_code='%7';")
  533. .arg(0).arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  534. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString()).arg(6).arg(devid).arg(0);
  535. mdb.exec(upsql);
  536. }else{
  537. setCompanyAlarmSet(deviceCode, AlarmSet(0xffffffff,"",QString::fromUtf8("%1,%2").arg(qry2.value(5).toString()).arg(qry2.value(6).toString()),6,qry2.value(7).toDateTime().toTime_t(),1));
  538. upsql = QString::fromUtf8("update sp_owner_status set point_data='',content='' where device_id='%1' and point_code='0'").arg(devid);
  539. mdb.exec(upsql);
  540. if(!qry2.value(2).isNull()){
  541. if(qry2.value(2).toString().compare("E3")==0){
  542. int tmpIdx = qry2.value(3).toString().toInt(nullptr,16);
  543. if(tmpIdx>0){
  544. QString pv = "0";
  545. QString pname = "", vname="";
  546. for(int Idx=0;Idx<vonameList.length();Idx++){
  547. if((typeList.at(Idx)==1)&&(portList.at(Idx)==tmpIdx)){
  548. pname = nameList.at(Idx);
  549. vname = vonameList.at(Idx);
  550. break;
  551. }
  552. }
  553. if((vname.compare(QString::fromUtf8("故障"))==0)
  554. ||(vname.compare(QString::fromUtf8("手动"))==0)
  555. ||(vname.compare(QString::fromUtf8("运行"))==0)
  556. ||(vname.compare(QString::fromUtf8("接线"))==0)
  557. ||(vname.compare(QString::fromUtf8("正常"))==0)){
  558. if(qry2.value(1).toInt()==0)
  559. pv="0";
  560. else
  561. pv="1";
  562. }else{
  563. if(qry2.value(1).toInt()==0)
  564. pv="1";
  565. else
  566. pv="0";
  567. }
  568. if(count==0)
  569. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  570. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(3).toInt()).arg(pv)
  571. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  572. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  573. else
  574. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  575. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(3).toInt()).arg(pv)
  576. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  577. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  578. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3 %4', point_name='%5',dwtype=%6 where device_id='%7' and point_code='%8';")
  579. .arg(pv)
  580. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  581. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString()).arg(pname)
  582. .arg(6).arg(devid).arg(tmpIdx);
  583. mdb.exec(upsql);
  584. }
  585. }else if(qry2.value(2).toString().compare("E6")==0){
  586. if(count==0)
  587. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  588. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(3).toInt()+64).arg(qry2.value(8).toString())
  589. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  590. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  591. else
  592. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  593. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(3).toInt()+64).arg(qry2.value(8).toString())
  594. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  595. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  596. int tmpIdx = qry2.value(3).toInt();
  597. if(tmpIdx>0){
  598. QString pname = "";
  599. for(int Idx=0;Idx<nameList.length();Idx++){
  600. if((typeList.at(Idx)==2)&&(portList.at(Idx)==tmpIdx)){
  601. pname = nameList.at(Idx);
  602. break;
  603. }
  604. }
  605. upsql = QString::fromUtf8("update sp_owner_status set point_data='%1', data_time='%2', content='%3 %4 %5',dwtype=%6 where device_id='%7' and point_code='%8';")
  606. .arg(qry2.value(8).toString())
  607. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  608. .arg(pname).arg(qry2.value(5).toString())
  609. .arg(qry2.value(6).toString())
  610. .arg(6)
  611. .arg(devid)
  612. .arg(tmpIdx+64);
  613. mdb.exec(upsql);
  614. }
  615. }
  616. }
  617. }
  618. count++;
  619. sync_id = qry2.value(0).toUInt();
  620. if(count>=100){
  621. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  622. ytShm->updatetime[DB_THREAD] = tmp_time;
  623. sql.append(";");
  624. mdb.exec(sql);
  625. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  626. // mdb.exec(upsql);
  627. count=0;
  628. sql="";
  629. upsql="";
  630. }
  631. }
  632. if(count>0){
  633. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  634. ytShm->updatetime[DB_THREAD] = tmp_time;
  635. sql.append(";");
  636. mdb.exec(sql);
  637. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  638. // mdb.exec(upsql);
  639. count=0;
  640. sql="";
  641. upsql="";
  642. }
  643. return updated;
  644. }
  645. bool DB_SyncThread::videoalarmSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID, QString companyCode)
  646. {
  647. QString sql,upsql;
  648. int count=0;
  649. bool updated = false;
  650. QString csql = QString("select count(*) as count, sum(clzt) as sum from sp_video2017 where device_code='%1' and time<now()").arg(devid);
  651. // printf("%s\n",csql.toUtf8().data());
  652. QSqlQuery qry2 = mdb.exec(csql);
  653. // .arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')));
  654. if(qry2.next()){
  655. csql = QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  656. .arg(qry2.value(0).toInt())
  657. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  658. .arg(devid);
  659. // printf("%s\n",csql.toUtf8().data());
  660. mdb.exec(csql);
  661. }
  662. qry2.clear();
  663. qry2 =mdb.exec(QString("select count(*) from sp_owner_status where device_id='%1'").arg(devid));
  664. if(qry2.next()){
  665. if(qry2.value(0).toInt()==0){
  666. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',16,'占道侦测告警',1,0,'1970-01-01 08:00:00','')").arg(devid));
  667. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',16,'火点侦测告警',2,0,'1970-01-01 08:00:00','')").arg(devid));
  668. }
  669. }
  670. qry2.clear();
  671. // printf("%s\n",QString("select id,port,time from sp_video2017 where id>%1 and time>'%2-%3-%4 00:00:00' and device_code='%5'").arg(sync_id).arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')).arg(devid).toUtf8().data());
  672. qry2 = mdb.exec(QString("select id,port,time,data4 from sp_video2017 where id>%1 and time>'%2-%3-%4 00:00:00' and time<now() and device_code='%5'").arg(sync_id).arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')).arg(devid));
  673. while(qry2.next()){
  674. updated = true;
  675. // system(QString("echo '%1 %2'>> /root/data.txt").arg(deviceCode).arg(qry2.value(2).toString()).toUtf8().data());
  676. setCompanyAlarmSet(deviceCode,AlarmSet(0xffffffff,"",qry2.value(3).toString(),16,qry2.value(2).toDateTime().toTime_t(),1));
  677. if(count==0){
  678. if(qry2.value(1).toInt()==1){
  679. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5',''),(NULL,%6,'%7','%8','%9','%10','')")
  680. .arg(qry2.value(0).toInt()).arg(devid).arg(1).arg(1).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  681. .arg(qry2.value(0).toInt()).arg(devid).arg(2).arg(0).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  682. }else{
  683. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5',''),(NULL,%6,'%7','%8','%9','%10','')")
  684. .arg(qry2.value(0).toInt()).arg(devid).arg(1).arg(0).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  685. .arg(qry2.value(0).toInt()).arg(devid).arg(2).arg(1).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  686. }
  687. }else{
  688. if(qry2.value(1).toInt()==1)
  689. sql += QString(", (NULL,%1,'%2','%3','%4','%5',''),(NULL,%6,'%7','%8','%9','%10','')")
  690. .arg(qry2.value(0).toInt()).arg(devid).arg(1).arg(1).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  691. .arg(qry2.value(0).toInt()).arg(devid).arg(2).arg(0).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  692. else
  693. sql += QString(", (NULL,%1,'%2','%3','%4','%5',''),(NULL,%6,'%7','%8','%9','%10','')")
  694. .arg(qry2.value(0).toInt()).arg(devid).arg(1).arg(0).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  695. .arg(qry2.value(0).toInt()).arg(devid).arg(2).arg(1).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  696. }
  697. if(qry2.value(1).toInt()==1)
  698. upsql = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='占道侦测告警' where device_id='%3' and point_code=1;")
  699. .arg(1).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  700. else
  701. upsql = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='火点侦测告警' where device_id='%3' and point_code=2;")
  702. .arg(1).arg(qry2.value(2).isNull()?"1970-01-01 08:00:00":qry2.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  703. sync_id = qry2.value(0).toUInt();
  704. count++;
  705. if(count>=100){
  706. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  707. ytShm->updatetime[DB_THREAD] = tmp_time;
  708. sql.append(";");
  709. // printf("%s\n%s",sql.toUtf8().data(),upsql.toUtf8().data());
  710. mdb.exec(sql);
  711. mdb.exec(upsql);
  712. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  713. count = 0;
  714. sql="";
  715. upsql="";
  716. }
  717. }
  718. if(count>0){
  719. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  720. ytShm->updatetime[DB_THREAD] = tmp_time;
  721. sql.append(";");
  722. // printf("%s\n%s",sql.toUtf8().data(),upsql.toUtf8().data());
  723. mdb.exec(sql);
  724. mdb.exec(upsql);
  725. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  726. count = 0;
  727. sql="";
  728. upsql="";
  729. }
  730. return updated;
  731. }
  732. bool DB_SyncThread::efireInfoSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID, QString companyCode)
  733. {
  734. QString upsql1, upsql2, upsql3, upsql4,upsql5,upsql6,sql;
  735. int count=0;
  736. bool updated = false;
  737. QSqlQuery qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_ef2017 where device_code='%1' and data1='EF9' and time<now()").arg(devid));
  738. // .arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')));
  739. if(qry2.next()){
  740. mdb.exec(QString("update sp_device_sync set com_count=%1, com_confirm=%2 where device_id='%3'")
  741. .arg(qry2.value(0).toInt())
  742. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  743. .arg(devid));
  744. }
  745. qry2.clear();
  746. qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_ef2017 where device_code='%1' and data1<>'EF9' and time<now()").arg(devid));
  747. // .arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')));
  748. if(qry2.next()){
  749. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  750. .arg(qry2.value(0).toInt())
  751. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  752. .arg(devid));
  753. }
  754. qry2.clear();
  755. qry2 =mdb.exec(QString("select count(*) from sp_owner_status where device_id='%1'").arg(devid));
  756. if(qry2.next()){
  757. if(qry2.value(0).toInt()==0){
  758. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'供电过压',1,0,'1970-01-01 08:00:00','')").arg(devid));
  759. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'供电低压',2,0,'1970-01-01 08:00:00','')").arg(devid));
  760. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'供电过流',3,0,'1970-01-01 08:00:00','')").arg(devid));
  761. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'漏电报警',4,0,'1970-01-01 08:00:00','')").arg(devid));
  762. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'A相线缆温度超高',5,0,'1970-01-01 08:00:00','')").arg(devid));
  763. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'B相线缆温度超高',6,0,'1970-01-01 08:00:00','')").arg(devid));
  764. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'C相线缆温度超高',7,0,'1970-01-01 08:00:00','')").arg(devid));
  765. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'A相电压',65,0,'1970-01-01 08:00:00','')").arg(devid));
  766. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'B相电压',66,0,'1970-01-01 08:00:00','')").arg(devid));
  767. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'C相电压',67,0,'1970-01-01 08:00:00','')").arg(devid));
  768. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'A相电流',68,0,'1970-01-01 08:00:00','')").arg(devid));
  769. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'B相电流',69,0,'1970-01-01 08:00:00','')").arg(devid));
  770. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'C相电流',70,0,'1970-01-01 08:00:00','')").arg(devid));
  771. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'A相线缆温度',71,0,'1970-01-01 08:00:00','')").arg(devid));
  772. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'B相线缆温度',72,0,'1970-01-01 08:00:00','')").arg(devid));
  773. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'C相线缆温度',73,0,'1970-01-01 08:00:00','')").arg(devid));
  774. }else if(qry2.value(0).toInt()==6){
  775. mdb.exec(QString::fromUtf8("delete from sp_owner_status where device_id='%1'").arg(devid));
  776. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'供电过压',1,0,'1970-01-01 08:00:00','')").arg(devid));
  777. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'供电低压',2,0,'1970-01-01 08:00:00','')").arg(devid));
  778. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'供电过流',3,0,'1970-01-01 08:00:00','')").arg(devid));
  779. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'漏电报警',4,0,'1970-01-01 08:00:00','')").arg(devid));
  780. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'A相线缆温度超高',5,0,'1970-01-01 08:00:00','')").arg(devid));
  781. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'B相线缆温度超高',6,0,'1970-01-01 08:00:00','')").arg(devid));
  782. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'C相线缆温度超高',7,0,'1970-01-01 08:00:00','')").arg(devid));
  783. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'A相电压',65,0,'1970-01-01 08:00:00','')").arg(devid));
  784. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'B相电压',66,0,'1970-01-01 08:00:00','')").arg(devid));
  785. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'C相电压',67,0,'1970-01-01 08:00:00','')").arg(devid));
  786. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'A相电流',68,0,'1970-01-01 08:00:00','')").arg(devid));
  787. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'B相电流',69,0,'1970-01-01 08:00:00','')").arg(devid));
  788. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'C相电流',70,0,'1970-01-01 08:00:00','')").arg(devid));
  789. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'A相线缆温度',71,0,'1970-01-01 08:00:00','')").arg(devid));
  790. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'B相线缆温度',72,0,'1970-01-01 08:00:00','')").arg(devid));
  791. mdb.exec(QString::fromUtf8("insert into sp_owner_status (id, device_id, dwtype, point_name, point_code, point_data, data_time, content) values (NULL,'%1',7,'C相线缆温度',73,0,'1970-01-01 08:00:00','')").arg(devid));
  792. }
  793. }
  794. qry2.clear();
  795. qry2 = mdb.exec(QString("select loop_hl, category,alarm_state, measured_value,a_voltage,b_voltage,c_voltage, a_electric_current,b_electric_current,c_electric_current,acquisition_time,id,a_current_angle,b_current_angle,c_current_angle from %1 where id>%2 and acquisition_time>'%3-%4-%5 00:00:00' and acquisition_time<now()")
  796. .arg(tbname).arg(sync_id).arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0')).arg(chkday.day(),2,10,QChar('0')));
  797. while(qry2.next()){
  798. updated = true;
  799. switch(qry2.value(0).toInt()){
  800. case 1:
  801. if(count==0){
  802. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','')")
  803. .arg(qry2.value(11).toInt()).arg(devid).arg(4).arg(qry2.value(2).toInt())
  804. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  805. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  806. .arg(qry2.value(11).toInt()).arg(devid).arg(1).arg(qry2.value(12).toInt())
  807. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  808. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  809. .arg(qry2.value(11).toInt()).arg(devid).arg(2).arg(qry2.value(13).toInt())
  810. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  811. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  812. .arg(qry2.value(11).toInt()).arg(devid).arg(3).arg(qry2.value(14).toInt())
  813. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  814. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  815. .arg(qry2.value(11).toInt()).arg(devid).arg(65).arg(qry2.value(4).toDouble())
  816. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  817. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  818. .arg(qry2.value(11).toInt()).arg(devid).arg(66).arg(qry2.value(5).toDouble())
  819. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  820. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  821. .arg(qry2.value(11).toInt()).arg(devid).arg(67).arg(qry2.value(6).toDouble())
  822. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  823. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  824. .arg(qry2.value(11).toInt()).arg(devid).arg(68).arg(qry2.value(7).toDouble())
  825. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  826. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  827. .arg(qry2.value(11).toInt()).arg(devid).arg(69).arg(qry2.value(8).toDouble())
  828. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  829. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  830. .arg(qry2.value(11).toInt()).arg(devid).arg(70).arg(qry2.value(9).toDouble())
  831. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  832. }else{
  833. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  834. .arg(qry2.value(11).toInt()).arg(devid).arg(4).arg(qry2.value(2).toInt())
  835. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  836. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  837. .arg(qry2.value(11).toInt()).arg(devid).arg(1).arg(qry2.value(12).toInt())
  838. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  839. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  840. .arg(qry2.value(11).toInt()).arg(devid).arg(2).arg(qry2.value(13).toInt())
  841. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  842. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  843. .arg(qry2.value(11).toInt()).arg(devid).arg(3).arg(qry2.value(14).toInt())
  844. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  845. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  846. .arg(qry2.value(11).toInt()).arg(devid).arg(65).arg(qry2.value(4).toDouble())
  847. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  848. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  849. .arg(qry2.value(11).toInt()).arg(devid).arg(66).arg(qry2.value(5).toDouble())
  850. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  851. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  852. .arg(qry2.value(11).toInt()).arg(devid).arg(67).arg(qry2.value(6).toDouble())
  853. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  854. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  855. .arg(qry2.value(11).toInt()).arg(devid).arg(68).arg(qry2.value(7).toDouble())
  856. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  857. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  858. .arg(qry2.value(11).toInt()).arg(devid).arg(69).arg(qry2.value(8).toDouble())
  859. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  860. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  861. .arg(qry2.value(11).toInt()).arg(devid).arg(70).arg(qry2.value(9).toDouble())
  862. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  863. }
  864. count += 10;
  865. upsql1 = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='供电过压' where device_id='%3' and point_code=1;")
  866. .arg(qry2.value(12).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  867. upsql1 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2', point_name='供电低压' where device_id='%3' and point_code=2; ")
  868. .arg(qry2.value(13).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  869. upsql1 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2', point_name='供电过流' where device_id='%3' and point_code=3; ")
  870. .arg(qry2.value(14).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  871. upsql1 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2', point_name='漏电报警' where device_id='%3' and point_code=4; ")
  872. .arg(qry2.value(2).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  873. upsql2 = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='A相电压' where device_id='%3' and point_code=65;")
  874. .arg(qry2.value(4).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  875. upsql2 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='B相电压' where device_id='%3' and point_code=66;")
  876. .arg(qry2.value(5).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  877. upsql2 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='C相电压' where device_id='%3' and point_code=67;")
  878. .arg(qry2.value(6).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  879. upsql3 = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='A相电流' where device_id='%3' and point_code=68; ")
  880. .arg(qry2.value(7).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  881. upsql3 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='B相电流' where device_id='%3' and point_code=69; ")
  882. .arg(qry2.value(8).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  883. upsql3 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='C相电流' where device_id='%3' and point_code=70; ")
  884. .arg(qry2.value(9).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  885. break;
  886. case 2:
  887. if(count==0){
  888. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','')")
  889. .arg(qry2.value(11).toInt()).arg(devid).arg(5).arg(qry2.value(2).toInt())
  890. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  891. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  892. .arg(qry2.value(11).toInt()).arg(devid).arg(71).arg(qry2.value(3).toDouble())
  893. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  894. }else{
  895. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  896. .arg(qry2.value(11).toInt()).arg(devid).arg(5).arg(qry2.value(2).toInt())
  897. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  898. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  899. .arg(qry2.value(11).toInt()).arg(devid).arg(71).arg(qry2.value(3).toDouble())
  900. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  901. }
  902. count += 2;
  903. upsql4 = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='A相线缆温度超高' where device_id='%3' and point_code=5;")
  904. .arg(qry2.value(2).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  905. upsql4 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='A相线缆温度' where device_id='%3' and point_code=71;")
  906. .arg(qry2.value(3).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  907. break;
  908. case 3:
  909. if(count==0){
  910. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','')")
  911. .arg(qry2.value(11).toInt()).arg(devid).arg(6).arg(qry2.value(2).toInt())
  912. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  913. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  914. .arg(qry2.value(11).toInt()).arg(devid).arg(72).arg(qry2.value(3).toDouble())
  915. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  916. }else{
  917. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  918. .arg(qry2.value(11).toInt()).arg(devid).arg(6).arg(qry2.value(2).toInt())
  919. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  920. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  921. .arg(qry2.value(11).toInt()).arg(devid).arg(72).arg(qry2.value(3).toDouble())
  922. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  923. }
  924. count += 2;
  925. upsql5 = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='B相线缆温度超高' where device_id='%3' and point_code=6;")
  926. .arg(qry2.value(2).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  927. upsql5 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='B相线缆温度' where device_id='%3' and point_code=72;")
  928. .arg(qry2.value(3).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  929. break;
  930. case 4:
  931. if(count==0){
  932. sql = QString("insert into sp_owner_sync_data (id, native_id, device_id, point_code, point_data, data_time, content) values (NULL,%1,'%2','%3','%4','%5','')")
  933. .arg(qry2.value(11).toInt()).arg(devid).arg(7).arg(qry2.value(2).toInt())
  934. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  935. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  936. .arg(qry2.value(11).toInt()).arg(devid).arg(73).arg(qry2.value(3).toDouble())
  937. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  938. }else{
  939. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  940. .arg(qry2.value(11).toInt()).arg(devid).arg(7).arg(qry2.value(2).toInt())
  941. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  942. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  943. .arg(qry2.value(11).toInt()).arg(devid).arg(73).arg(qry2.value(3).toDouble())
  944. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  945. }
  946. count += 2;
  947. upsql6 = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='C相线缆温度超高' where device_id='%3' and point_code=7;")
  948. .arg(qry2.value(2).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  949. upsql6 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='C相线缆温度' where device_id='%3' and point_code=73;")
  950. .arg(qry2.value(3).toDouble()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  951. break;
  952. }
  953. sync_id = qry2.value(11).toUInt();
  954. if(count>=100){
  955. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  956. ytShm->updatetime[DB_THREAD] = tmp_time;
  957. sql.append(";");
  958. mdb.exec(sql);
  959. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  960. mdb.exec(upsql1);
  961. mdb.exec(upsql2);
  962. mdb.exec(upsql3);
  963. mdb.exec(upsql4);
  964. mdb.exec(upsql5);
  965. mdb.exec(upsql6);
  966. count=0;
  967. sql="";
  968. upsql1="";
  969. upsql2="";
  970. upsql3="";
  971. upsql4="";
  972. upsql5="";
  973. upsql6="";
  974. }
  975. }
  976. if(count>0){
  977. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  978. ytShm->updatetime[DB_THREAD] = tmp_time;
  979. sql.append(";");
  980. mdb.exec(sql);
  981. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  982. mdb.exec(upsql1);
  983. mdb.exec(upsql2);
  984. mdb.exec(upsql3);
  985. mdb.exec(upsql4);
  986. mdb.exec(upsql5);
  987. mdb.exec(upsql6);
  988. count=0;
  989. sql="";
  990. upsql1="";
  991. upsql2="";
  992. upsql3="";
  993. upsql4="";
  994. upsql5="";
  995. upsql6="";
  996. }
  997. return updated;
  998. }
  999. void DB_SyncThread::appendDevDataList(QString deviceid)
  1000. {
  1001. deviceDataList.append(deviceid);
  1002. }
  1003. void DB_SyncThread::chkInList(QString devid)
  1004. {
  1005. QSqlQuery qry;
  1006. QString sql;
  1007. bool found = false;
  1008. for(int i=0;i<syncDevList.length();i++){
  1009. if(devid.compare(syncDevList.at(i).OwnerCode)==0){
  1010. if(syncDevList.at(i).ObjType.compare("YTFC")==0){
  1011. found = true;
  1012. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  1013. // system(QString("echo \"[YTFC] dev:%1 obj:%2 start:%3 rec:%4\">> /root/test.log").arg(syncDevList.at(i).OwnerCode).arg(syncDevList.at(i).ObjCode).arg(syncDevList.at(i).StartPort).arg(syncDevList.at(i).RecCur).toUtf8().data());
  1014. QDateTime dataTime = QDateTime::fromTime_t(0);
  1015. QString PowerAlarm="off";
  1016. QString ManualAct = "off";
  1017. QString DevWorking01 = "off";
  1018. QString DevWorking02 = "off";
  1019. QString DevAlarm01 = "off";
  1020. QString DevAlarm02 = "off";
  1021. QString FireAutoAct = "off";
  1022. sql = QString("select dwtype,point_code,point_data,data_time from sp_owner_status where device_id='%1'").arg(devid);
  1023. // system(QString("echo \"[YTFC] %1\" >> /root/test.log").arg(sql).toUtf8().data());
  1024. // qDebug()<<sql.toUtf8().data();
  1025. qry = mdb.exec(sql);
  1026. while(qry.next()){
  1027. int code = qry.value(1).toInt();
  1028. if((code>0)&&(code<8)){
  1029. int value = qry.value(2).toInt();
  1030. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  1031. dataTime = qry.value(3).toDateTime();
  1032. if(code==1){
  1033. if(value==0)
  1034. PowerAlarm = "on";
  1035. }else if(code==2){
  1036. if(value==0)
  1037. ManualAct = "on";
  1038. }else if(code==3){
  1039. if(value==0)
  1040. DevWorking01 = "on";
  1041. }else if(code==4){
  1042. if(value==0)
  1043. DevWorking02 = "on";
  1044. }else if(code==5){
  1045. if(value==0)
  1046. DevAlarm01 = "on";
  1047. }else if(code==6){
  1048. if(value==0)
  1049. DevAlarm02 = "on";
  1050. }else if(code==7){
  1051. if(value==0)
  1052. FireAutoAct = "on";
  1053. }
  1054. }
  1055. }
  1056. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  1057. {
  1058. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  1059. QString jsonstr = QString("{\"dataCode\":\"DATA_FIRECONT\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"PowerAlarm\":\"%3\",\"ManualAct\":\"%4\",\"DevWorking01\":\"%5\",\"DevWorking02\":\"%6\",\"DevAlarm01\":\"%7\",\"DevAlarm02\":\"%8\",\"FireAutoAct\":\"%9\"}}")
  1060. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(PowerAlarm).arg(ManualAct).arg(DevWorking01).arg(DevWorking02).arg(DevAlarm01).arg(DevAlarm02).arg(FireAutoAct);
  1061. // system(QString("echo \"[YTFC] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  1062. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  1063. }
  1064. }else if(syncDevList.at(i).ObjType.compare("YTCI")==0){
  1065. found = true;
  1066. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  1067. // system(QString("echo \"[YTCI] dev:%1 obj:%2 start:%3 rec:%4\">> /root/test.log").arg(syncDevList.at(i).OwnerCode).arg(syncDevList.at(i).ObjCode).arg(syncDevList.at(i).StartPort).arg(syncDevList.at(i).RecCur).toUtf8().data());
  1068. QString Temperature = "0.0";
  1069. QString Humidity = "0.0";
  1070. QDateTime dataTime = QDateTime::fromTime_t(0);
  1071. sql = QString("select dwtype,point_code,point_data,data_time from sp_owner_status where device_id='%1' and point_code>%2 order by point_code limit 0,2").arg(devid).arg((syncDevList.at(i).StartPort>0)?(syncDevList.at(i).StartPort+63):0);
  1072. // system(QString("echo \"[YTCI]%1\" >> /root/test.log").arg(sql).toUtf8().data());
  1073. // qDebug()<<sql.toUtf8().data();
  1074. qry = mdb.exec(sql);
  1075. int nrow = 0;
  1076. while(qry.next()){
  1077. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  1078. dataTime = qry.value(3).toDateTime();
  1079. if(nrow==0)
  1080. Temperature = qry.value(2).toString();
  1081. else if(nrow==1)
  1082. Humidity = qry.value(2).toString();
  1083. nrow++;
  1084. }
  1085. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  1086. {
  1087. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  1088. QString jsonstr = QString("{\"dataCode\":\"DATA_ENVIRONM\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"Temperature\":%3,\"Humidity\":%4}}")
  1089. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(Temperature).arg(Humidity);
  1090. // system(QString("echo \"[YTCI] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  1091. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  1092. }
  1093. }else if(syncDevList.at(i).ObjType.compare("YTWP")==0){
  1094. found = true;
  1095. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  1096. // system(QString("echo \"[YTWP] dev:%1 obj:%2 start:%3 rec:%4\">> /root/test.log").arg(syncDevList.at(i).OwnerCode).arg(syncDevList.at(i).ObjCode).arg(syncDevList.at(i).StartPort).arg(syncDevList.at(i).RecCur).toUtf8().data());
  1097. QString WaterPressure = "0.0";
  1098. QDateTime dataTime = QDateTime::fromTime_t(0);
  1099. sql = QString("select dwtype,point_code,point_data,data_time from sp_owner_status where device_id='%1' and point_code>%2 order by point_code limit 0,1").arg(devid).arg((syncDevList.at(i).StartPort>0)?(syncDevList.at(i).StartPort+63):3);
  1100. // system(QString("echo \"[YTWP]%1\" >> /root/test.log").arg(sql).toUtf8().data());
  1101. // qDebug()<<sql.toUtf8().data();
  1102. qry = mdb.exec(sql);
  1103. if(qry.next()){
  1104. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  1105. dataTime = qry.value(3).toDateTime();
  1106. WaterPressure = qry.value(2).toString();
  1107. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  1108. {
  1109. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  1110. QString jsonstr = QString("{\"dataCode\":\"DATA_WATERPRE\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"WaterPressure\":%3}}")
  1111. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(WaterPressure);
  1112. // system(QString("echo \"[YTWP] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  1113. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  1114. }
  1115. }
  1116. }else if(syncDevList.at(i).ObjType.compare("YTLL")==0){
  1117. found = true;
  1118. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  1119. // system(QString("echo \"[YTLL] dev:%1 obj:%2 start:%3 rec:%4\">> /root/test.log").arg(syncDevList.at(i).OwnerCode).arg(syncDevList.at(i).ObjCode).arg(syncDevList.at(i).StartPort).arg(syncDevList.at(i).RecCur).toUtf8().data());
  1120. QString LiquidLevel = "0.0";
  1121. QDateTime dataTime = QDateTime::fromTime_t(0);
  1122. sql = QString("select dwtype,point_code,point_data,data_time from sp_owner_status where device_id='%1' and point_code>%2 order by point_code limit 0,1").arg(devid).arg((syncDevList.at(i).StartPort>0)?(syncDevList.at(i).StartPort+63):3);
  1123. // system(QString("echo \"[YTLL]%1\" >> /root/test.log").arg(sql).toUtf8().data());
  1124. // qDebug()<<sql.toUtf8().data();
  1125. qry = mdb.exec(sql);
  1126. if(qry.next()){
  1127. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  1128. dataTime = qry.value(3).toDateTime();
  1129. LiquidLevel = qry.value(2).toString();
  1130. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  1131. {
  1132. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  1133. QString jsonstr = QString("{\"dataCode\":\"DATA_LIQUIDLE\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"LiquidLevel\":%3}}")
  1134. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(LiquidLevel);
  1135. // system(QString("echo \"[YTLL] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  1136. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  1137. }
  1138. }
  1139. }else if(syncDevList.at(i).ObjType.compare("YTEF")==0){
  1140. found = true;
  1141. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  1142. // system(QString("echo \"[YTEF] dev:%1 obj:%2 start:%3 rec:%4\">> /root/test.log").arg(syncDevList.at(i).OwnerCode).arg(syncDevList.at(i).ObjCode).arg(syncDevList.at(i).StartPort).arg(syncDevList.at(i).RecCur).toUtf8().data());
  1143. QString HighVoltageAlarm ="off";
  1144. QString LowVoltageAlarm = "off";
  1145. QString HighCurrentAlarm = "off";
  1146. QString ElectricityLeakage = "off";
  1147. QString HighTemperatureA = "off";
  1148. QString HighTemperatureB = "off";
  1149. QString HighTemperatureC = "off";
  1150. QString VoltageA = "0.0";
  1151. QString VoltageB = "0.0";
  1152. QString VoltageC = "0.0";
  1153. QString CurrentA = "0.0";
  1154. QString CurrentB = "0.0";
  1155. QString CurrentC = "0.0";
  1156. QString TemperatureA = "0.0";
  1157. QString TemperatureB = "0.0";
  1158. QString TemperatureC = "0.0";
  1159. QDateTime dataTime = QDateTime::fromTime_t(0);
  1160. sql =QString("select dwtype,point_code,point_data,data_time from sp_owner_status where device_id='%1'").arg(devid);
  1161. // system(QString("echo \"[YTEF]%1\" >> /root/test.log").arg(sql).toUtf8().data());
  1162. // qDebug()<<sql.toUtf8().data();
  1163. qry = mdb.exec(sql);
  1164. while(qry.next()){
  1165. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  1166. dataTime = qry.value(3).toDateTime();
  1167. int code = qry.value(1).toInt();
  1168. if(code==1){
  1169. if(qry.value(2).toInt()==1)
  1170. HighVoltageAlarm = "on";
  1171. }else if(code==2){
  1172. if(qry.value(2).toInt()==1)
  1173. LowVoltageAlarm = "on";
  1174. }else if(code==3){
  1175. if(qry.value(2).toInt()==1)
  1176. HighCurrentAlarm = "on";
  1177. }else if(code==4){
  1178. if(qry.value(2).toInt()==1)
  1179. ElectricityLeakage = "on";
  1180. }else if(code==5){
  1181. if(qry.value(2).toInt()==1)
  1182. HighTemperatureA = "on";
  1183. }else if(code==6){
  1184. if(qry.value(2).toInt()==1)
  1185. HighTemperatureB = "on";
  1186. }else if(code==7){
  1187. if(qry.value(2).toInt()==1)
  1188. HighTemperatureC = "on";
  1189. }else if(code==65)
  1190. VoltageA = qry.value(2).toString();
  1191. else if(code==66)
  1192. VoltageB = qry.value(2).toString();
  1193. else if(code==67)
  1194. VoltageC = qry.value(2).toString();
  1195. else if(code==68)
  1196. CurrentA = qry.value(2).toString();
  1197. else if(code==69)
  1198. CurrentB = qry.value(2).toString();
  1199. else if(code==70)
  1200. CurrentC = qry.value(2).toString();
  1201. else if(code==71)
  1202. TemperatureA = qry.value(2).toString();
  1203. else if(code==72)
  1204. TemperatureB = qry.value(2).toString();
  1205. else if(code==73)
  1206. TemperatureC = qry.value(2).toString();
  1207. }
  1208. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  1209. {
  1210. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  1211. QString jsonstr = QString("{\"dataCode\":\"DATA_ElECTRIC\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"HighVoltageAlarm\":\"%3\",\"LowVoltageAlarm\":\"%4\",\"HighCurrentAlarm\":\"%5\",\"ElectricityLeakage\":\"%6\",\"HighTemperatureA\":\"%7\",\"HighTemperatureB\":\"%8\",\"HighTemperatureC\":\"%9\",\"VoltageA\":%10,\"VoltageB\":%11,\"VoltageC\":%12,\"CurrentA\":%13,\"CurrentB\":%14,\"CurrentC\":%15,\"TemperatureA\":%16,\"TemperatureB\":%17,\"TemperatureC\":%18}}")
  1212. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(HighVoltageAlarm).arg(LowVoltageAlarm).arg(HighCurrentAlarm).arg(ElectricityLeakage).arg(HighTemperatureA).arg(HighTemperatureB).arg(HighTemperatureC).arg(VoltageA).arg(VoltageB).arg(VoltageC).arg(CurrentA).arg(CurrentB).arg(CurrentC).arg(TemperatureA).arg(TemperatureB).arg(TemperatureC);
  1213. // system(QString("echo \"[YTEF] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  1214. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  1215. }
  1216. }else if(syncDevList.at(i).ObjType.compare("YTVA")==0){
  1217. found = true;
  1218. QString VideoAlarm01 = "off";
  1219. QString VideoAlarm02 = "off";
  1220. QDateTime dataTime = QDateTime::fromTime_t(0);
  1221. sql =QString("select dwtype,point_code,point_data,data_time from sp_owner_status where device_id='%1'").arg(devid);
  1222. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  1223. qry = mdb.exec(sql);
  1224. while(qry.next()){
  1225. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t()){
  1226. dataTime = qry.value(3).toDateTime();
  1227. int code = qry.value(1).toInt();
  1228. if(code==1){
  1229. if(qry.value(2).toInt()==1){
  1230. VideoAlarm01 = "on";
  1231. VideoAlarm02 = "off";
  1232. }
  1233. }else if(code==2){
  1234. if(qry.value(2).toInt()==1){
  1235. VideoAlarm01 = "off";
  1236. VideoAlarm02 = "on";
  1237. }
  1238. }
  1239. }
  1240. }
  1241. // mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  1242. QString jsonstr = QString("{\"dataCode\":\"DATA_VIDEOALA\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"VideoAlarm01\":\"%3\",\"VideoAlarm02\":\"%4\"}}")
  1243. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(VideoAlarm01).arg(VideoAlarm02);
  1244. // system(QString("echo \"[YTVA] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  1245. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  1246. }
  1247. }
  1248. }
  1249. if(!found){
  1250. for(int i=0;i<cnDevList.length();i++){
  1251. // if(found&&(devid.compare(cnDevList.at(i).OwnerCode)!=0))
  1252. // break;
  1253. if(devid.compare(cnDevList.at(i).OwnerCode)==0){
  1254. found = true;
  1255. if(cnDevList.at(i).ObjType.compare("YTUI")!=0){
  1256. CNSyncDev cndev = cnDevList.at(i);
  1257. uint MaxT = 0;
  1258. QString sql = QString("select point_code, point_data, data_time from sp_owner_status where device_id=%1").arg(devid);
  1259. QString jdata = "";
  1260. jdata.append(QString("\"devCategory\":%1").arg(cndev.devCategory));
  1261. jdata.append(QString(",\"devDesc\":\"%1\"").arg(cndev.ObjName));
  1262. jdata.append(QString(",\"devId\":\"%1\"").arg(cndev.ObjCode));
  1263. jdata.append(QString(",\"devName\":\"%1\"").arg(cndev.ObjName));
  1264. jdata.append(QString(",\"ownBid\":\"%1\"").arg(cndev.ownBid));
  1265. jdata.append(QString(",\"type\":%1").arg(cndev.subType));
  1266. qry = mdb.exec(sql);
  1267. if(cnDevList.at(i).StartPort.length()>0){
  1268. QList<CnPno> pnoList = getPnoValue(cnDevList.at(i).StartPort);
  1269. for(int i=0;i<pnoList.length();i++){
  1270. if(pnoList.at(i).Pno<0){
  1271. if(pnoList.at(i).PName.compare("devStatus")==0)
  1272. jdata.append(QString(",\"devStatus\":%1").arg(pnoList.at(i).Default.length()>0?pnoList.at(i).Default:"0"));
  1273. else
  1274. jdata.append(QString(",\"%1\":\"%2\"").arg(pnoList.at(i).PName).arg(pnoList.at(i).Default));
  1275. }
  1276. }
  1277. while(qry.next()){
  1278. uint cTime = qry.value(2).toDateTime().toTime_t();
  1279. if(cTime>MaxT)
  1280. MaxT = cTime;
  1281. for(int i=0;i<pnoList.length();i++){
  1282. if(pnoList.at(i).Pno==qry.value(0).toInt()){
  1283. if(pnoList.at(i).PName.compare("startStatus")==0)
  1284. jdata.append(QString(",\"%1\":\"%2\"").arg(pnoList.at(i).PName).arg(qry.value(1).toInt()));
  1285. else if(pnoList.at(i).PName.indexOf("Status")>=0)
  1286. jdata.append(QString(",\"%1\":%2").arg(pnoList.at(i).PName).arg(qry.value(1).toInt()));
  1287. else
  1288. jdata.append(QString(",\"%1\":%2").arg(pnoList.at(i).PName).arg(qry.value(1).toString()));
  1289. break;
  1290. }
  1291. }
  1292. }
  1293. }else{
  1294. while(qry.next()){
  1295. uint cTime = qry.value(2).toDateTime().toTime_t();
  1296. if(cTime>MaxT)
  1297. MaxT = cTime;
  1298. if(cndev.ObjType.compare("YTWP")==0){
  1299. if(qry.value(0).toInt()==1)
  1300. jdata.append(QString(",\"devStatus\":%1").arg(qry.value(1).toInt()));
  1301. else if(qry.value(0).toInt()==2)
  1302. jdata.append(QString(",\"power\":%1").arg(qry.value(1).toInt()));
  1303. else if(qry.value(0).toInt()==3)
  1304. jdata.append(QString(",\"signal\":%1").arg((qry.value(1).toInt()==5)?100:(qry.value(1).toInt()*20)));
  1305. else if(qry.value(0).toInt()==4)
  1306. jdata.append(QString(",\"value\":%1").arg(qry.value(1).toDouble()));
  1307. }
  1308. }
  1309. if(cndev.ObjType.compare("YTWP")==0)
  1310. jdata.append(QString(",\"unit\":\"MPa\""));
  1311. }
  1312. jdata.append(QString(",\"logTime\":\"%1\"").arg(QDateTime::fromTime_t(MaxT).toString("yyyy-MM-dd HH:mm:ss")));
  1313. emit cnSyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), "{"+jdata+"}",cndev.devCategory);
  1314. }else{
  1315. }
  1316. }
  1317. }
  1318. }
  1319. }
  1320. //QList<JaPno> DB_SyncThread::getJaPnoValue(QString pnoset)
  1321. //{
  1322. // QList<JaPno> list;
  1323. // QJsonParseError json_error;
  1324. // QJsonDocument jsonDoc(QJsonDocument::fromJson(pnoset.toUtf8(),&json_error));
  1325. // if(json_error.error == QJsonParseError::NoError){
  1326. // QJsonArray json_root = jsonDoc.array();
  1327. // for(int i=0;i<json_root.size();i++){
  1328. // QJsonObject obj = json_root.at(i).toObject();
  1329. // QString name = obj.value("name").toString();
  1330. // QString attr = obj.value("attr").toString();
  1331. // int port = obj.value("port").toInt();
  1332. // QString defvalue1 = obj.value("default1").toString();
  1333. // QString defvalue2 = obj.value("default2").toString();
  1334. // if((port>-2)&&(name.length()>0))
  1335. // list.append(JaPno(name,attr,port,defvalue1,defvalue2));
  1336. // }
  1337. // }
  1338. // return list;
  1339. //}
  1340. QList<CnPno> DB_SyncThread::getPnoValue(QString pnoset)
  1341. {
  1342. QList<CnPno> list;
  1343. QJsonParseError json_error;
  1344. QJsonDocument jsonDoc(QJsonDocument::fromJson(pnoset.toUtf8(),&json_error));
  1345. if(json_error.error == QJsonParseError::NoError){
  1346. QJsonArray json_root = jsonDoc.array();
  1347. for(int i=0;i<json_root.size();i++){
  1348. QJsonObject obj = json_root.at(i).toObject();
  1349. QString name = obj.value("name").toString();
  1350. int port = obj.value("port").toInt();
  1351. QString defvalue = obj.value("default").toString();
  1352. if((port>-2)&&(name.length()>0))
  1353. list.append(CnPno(name,port,defvalue));
  1354. }
  1355. }
  1356. // int i,port;
  1357. // json_object *pno, *obj;
  1358. // char name[1024],value[1024];
  1359. // obj = json_tokener_parse(pnoset.toUtf8().data());
  1360. // if(json_object_get_type(obj)==json_type_array){
  1361. // for(i=0;i<json_object_array_length(obj);i++){
  1362. // pno = json_object_array_get_idx(obj,i);
  1363. // bzero(name,sizeof(name));
  1364. // bzero(value,sizeof(value));
  1365. // port=-2;
  1366. // json_object_object_foreach(pno,key,val){
  1367. // if(strcmp(key,"name")==0)
  1368. // sprintf(name,"%s",json_object_get_string(val));
  1369. // else if(strcmp(key,"port")==0)
  1370. // port = json_object_get_int(val);
  1371. // else if(strcmp(key,"default")==0)
  1372. // sprintf(value,"%s",json_object_get_string(val));
  1373. // }
  1374. // if((port>-2)&&(strlen(name)>0)){
  1375. // list.append(CnPno(QString::fromUtf8(name),port,QString::fromUtf8(value)));
  1376. // }
  1377. // }
  1378. // }
  1379. // json_object_put(obj);
  1380. return list;
  1381. }
  1382. void DB_SyncThread::updatePortName()
  1383. {
  1384. QSqlQuery qry = mdb.exec("select s.owner_code, o.owner_name, o.unitinfo from sp_owner_sync s, sp_owner o where s.owner_code=o.owner_code and (s.owner_name<>o.owner_name or s.unitinfo<>o.unitinfo) group by s.owner_code");
  1385. while(qry.next()){
  1386. QString sql = QString("update sp_owner_sync set owner_name='%1', unitinfo='%2' where owner_code='%3'")
  1387. .arg(qry.value(1).toString()).arg(qry.value(2).toString()).arg(qry.value(0).toString());
  1388. printf("echo '%s' >> /root/sql.txt\n",sql.toUtf8().data());
  1389. mdb.exec(sql);
  1390. }
  1391. }
  1392. void DB_SyncThread::va_heartbeat(){
  1393. int ret = 0;
  1394. for(int i=0;i<syncDevList.length();i++){
  1395. if(syncDevList.at(i).ObjType.compare("YTVA")==0){
  1396. QString jsonstr = QString("{\"dataCode\":\"DATA_VIDEOALA\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"VideoAlarm01\":\"%3\",\"VideoAlarm02\":\"%4\"}}")
  1397. .arg(syncDevList.at(i).ObjCode).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg("off").arg("off");
  1398. ret = system(QString("echo '%1' >> /root/heartbeat.log").arg(jsonstr).toUtf8().data());
  1399. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  1400. }
  1401. }
  1402. }
  1403. void DB_SyncThread::time_out()
  1404. {
  1405. QSqlQuery qry,qry2;
  1406. QString qrysql;
  1407. if(!isWorking)
  1408. {
  1409. printf("update memory at %s\n",QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toUtf8().data());
  1410. UpdateTime = QDateTime::currentDateTime().toTime_t();
  1411. isWorking = true;
  1412. if(!mdbOpened)
  1413. {
  1414. mdbOpened = mdb.open();
  1415. }
  1416. else
  1417. {
  1418. if(((times++)&0x0f)==0x0f){
  1419. UpdateTime = QDateTime::currentDateTime().toTime_t();
  1420. checkUsers();
  1421. checkCompany();
  1422. checkDevice();
  1423. updatePortName();
  1424. }
  1425. syncDevList.clear();
  1426. qry = mdb.exec("select owner_code,dwtype,object_code,start_port,rec_cur from sp_yangpu_share");
  1427. while(qry.next()){
  1428. syncDevList.append(YPSyncDev(qry.value(0).toString(),
  1429. qry.value(1).toString(),
  1430. qry.value(2).toString(),
  1431. qry.value(3).toInt(),
  1432. qry.value(4).toUInt()));
  1433. }
  1434. qry.clear();
  1435. if(day!=QDate::currentDate().day()){
  1436. day = QDate::currentDate().day();
  1437. va_heartbeat();
  1438. }
  1439. cnDevList.clear();
  1440. qry = mdb.exec("select owner_code,dwtype,object_code,start_port,rec_cur,object_name, ownBid, devCategory, type from sp_changning_share");
  1441. while(qry.next()){
  1442. cnDevList.append(CNSyncDev(qry.value(0).toString(),
  1443. qry.value(5).toString(),
  1444. qry.value(1).toString(),
  1445. qry.value(2).toString(),
  1446. qry.value(3).toString().trimmed(),
  1447. qry.value(4).toUInt(),
  1448. qry.value(6).toString(),
  1449. qry.value(7).toInt(),
  1450. qry.value(8).toInt()));
  1451. }
  1452. qry.clear();
  1453. qry2 = mdb.exec("select device_id,point_code from sp_owner_status");
  1454. dList.clear();
  1455. pcList.clear();
  1456. while(qry2.next()){
  1457. dList.append(qry2.value(0).toString());
  1458. pcList.append(qry2.value(1).toInt());
  1459. }
  1460. qry2.clear();
  1461. qry = mdb.exec("select id, owner_code, owner_name, unitinfo, install_time, dwtype, company, rtmp from sp_owner");
  1462. while(qry.next())
  1463. {
  1464. time_t tmp_time = time(static_cast<time_t *>(Q_NULLPTR));
  1465. ytShm->updatetime[DB_THREAD] = tmp_time;
  1466. int dwtype = qry.value(5).toInt();
  1467. uint ID = qry.value(0).toUInt();
  1468. QString companyCode = qry.value(6).toString();
  1469. QDate chkday = QDate::currentDate().addDays(-7);
  1470. bool need_sync = false;
  1471. qry2 =mdb.exec(QString("select count(*) from sp_device_sync where device_id='%1'").arg(qry.value(1).toString()));
  1472. if(qry2.next()){
  1473. if(qry2.value(0).toInt()==0){
  1474. mdb.exec(QString("insert into sp_device_sync (device_id,com_count,com_confirm,alm_count,alm_confirm) values ('%1',0,0,0,0)").arg(qry.value(1).toString()));
  1475. }
  1476. }
  1477. qry2.clear();
  1478. qrysql = QString("select count(*),table_name,sync_id from sp_owner_sync where id=%1").arg(ID);
  1479. qry2 = mdb.exec(qrysql);
  1480. if(qry2.next()){
  1481. QString deviceCode = qry.value(1).toString();
  1482. QString tbname = QString("sp_%1%2").arg(qry.value(5).toInt()==3?"y":"d").arg(deviceCode);
  1483. uint sync_id = 0;
  1484. if(qry2.value(0).toInt()==0){
  1485. mdb.exec(QString("insert into sp_owner_sync (id, owner_code, owner_name, unitinfo, install_time, dwtype, company, rtmp, table_name, sync_id) values (%1,'%2','%3', '%4', '%5', %6, '%7', '%8', '%9', %10) ")
  1486. .arg(qry.value(0).toInt()).arg(qry.value(1).toString()).arg(qry.value(2).toString()).arg(qry.value(3).toString()).arg(qry.value(4).toString())
  1487. .arg(qry.value(5).toInt()).arg(qry.value(6).toString()).arg(qry.value(7).toString()).arg(tbname).arg(sync_id));
  1488. }else{
  1489. sync_id = qry2.value(2).toUInt();
  1490. }
  1491. qry2.clear();
  1492. switch(dwtype){
  1493. case 1://userinfo
  1494. need_sync = userInfoSync(qry.value(1).toString(),deviceCode,sync_id, tbname, chkday,ID,companyCode);
  1495. break;
  1496. case 2://water
  1497. case 5:
  1498. need_sync = waterInfoSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID,dwtype,companyCode);
  1499. break;
  1500. case 3:
  1501. need_sync = smokerInfoSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID,companyCode);
  1502. break;
  1503. case 6:
  1504. need_sync = rtuInfoSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID,companyCode);
  1505. break;
  1506. case 7:
  1507. need_sync = efireInfoSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID,companyCode);
  1508. break;
  1509. case 16:
  1510. need_sync = videoalarmSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID,companyCode);
  1511. // need_sync = false;//debug
  1512. break;
  1513. }
  1514. qry2.clear();
  1515. if(need_sync)
  1516. chkInList(qry.value(1).toString());
  1517. }
  1518. usleep(5000);
  1519. }
  1520. if(deviceDataList.length()>0){
  1521. while (deviceDataList.length()>0) {
  1522. chkInList(deviceDataList.first());
  1523. deviceDataList.removeFirst();
  1524. usleep(5000);
  1525. }
  1526. }
  1527. qry.clear();
  1528. qry = mdb.exec("select a.company as company, a.dwtype as dwtype, sum(a.devCount) as devCount, sum(a.com_count) as comCount, sum(a.com_confirm) as comConfirm, sum(a.alm_count) as almCount, sum(a.alm_confirm) as almConfirm from (select sp_owner.company, sp_device_sync.device_id, if(sp_owner.dwtype=3,1,sp_owner.dwtype) as dwtype, 1 as devCount, sp_device_sync.com_count, sp_device_sync.com_confirm, sp_device_sync.alm_count, sp_device_sync.alm_confirm from sp_owner, sp_device_sync where sp_owner.owner_code = sp_device_sync.device_id) a where a.dwtype in (1,2,5,6,7,16) and a.company<>'' group by a.company, a.dwtype");
  1529. while(qry.next()){
  1530. QString sql2="";
  1531. qry2 = mdb.exec(QString("select count(*) from sp_company_sync where company_code='%1'").arg(qry.value(0).toString()));
  1532. if(qry2.next()){
  1533. if(qry2.value(0).toInt()==0){
  1534. sql2 = QString("insert into sp_company_sync (company_code, device_00_count, device_00_out, device_00_out_confirm, device_00_alarm, device_00_alarm_confirm,device_01_count, device_01_out, device_01_out_confirm, device_01_alarm, device_01_alarm_confirm, device_02_count, device_02_out, device_02_out_confirm, device_02_alarm, device_02_alarm_confirm,device_06_count, device_06_out, device_06_out_confirm, device_06_alarm, device_06_alarm_confirm,device_07_count, device_07_out, device_07_out_confirm, device_07_alarm, device_07_alarm_confirm,device_16_count, device_16_out, device_16_out_confirm, device_16_alarm, device_16_alarm_confirm) values ('%1',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);")
  1535. .arg(qry.value(0).toString());
  1536. }
  1537. }
  1538. qry2.clear();
  1539. if(qry.value(1).toInt()==1){
  1540. sql2 += QString("update sp_company_sync set device_01_count=%1, device_01_out=%2, device_01_out_confirm=%3, device_01_alarm=%4, device_01_alarm_confirm=%5 where company_code='%6'")
  1541. .arg(qry.value(2).toInt()).arg(qry.value(3).toInt()).arg(qry.value(4).toInt()).arg(qry.value(5).toInt()).arg(qry.value(6).toInt()).arg(qry.value(0).toString());
  1542. update_company_alarmstatus(qry.value(0).toString(),1,qry.value(2).toUInt(),qry.value(3).toUInt(),qry.value(4).toUInt(),qry.value(5).toUInt(),qry.value(6).toUInt());
  1543. }else if(qry.value(1).toInt()==2){
  1544. sql2 += QString("update sp_company_sync set device_02_count=%1, device_02_out=%2, device_02_out_confirm=%3, device_02_alarm=%4, device_02_alarm_confirm=%5 where company_code='%6'")
  1545. .arg(qry.value(2).toInt()).arg(qry.value(3).toInt()).arg(qry.value(4).toInt()).arg(qry.value(5).toInt()).arg(qry.value(6).toInt()).arg(qry.value(0).toString());
  1546. update_company_alarmstatus(qry.value(0).toString(),2,qry.value(2).toUInt(),qry.value(3).toUInt(),qry.value(4).toUInt(),qry.value(5).toUInt(),qry.value(6).toUInt());
  1547. }else if(qry.value(1).toInt()==3){
  1548. sql2 += QString("update sp_company_sync set device_03_count=%1, device_03_out=%2, device_03_out_confirm=%3, device_03_alarm=%4, device_03_alarm_confirm=%5 where company_code='%6'")
  1549. .arg(qry.value(2).toInt()).arg(qry.value(3).toInt()).arg(qry.value(4).toInt()).arg(qry.value(5).toInt()).arg(qry.value(6).toInt()).arg(qry.value(0).toString());
  1550. update_company_alarmstatus(qry.value(0).toString(),1,qry.value(2).toUInt(),qry.value(3).toUInt(),qry.value(4).toUInt(),qry.value(5).toUInt(),qry.value(6).toUInt());
  1551. }else if(qry.value(1).toInt()==5){
  1552. sql2 += QString("update sp_company_sync set device_00_count=%1, device_00_out=%2, device_00_out_confirm=%3, device_00_alarm=%4, device_00_alarm_confirm=%5 where company_code='%6'")
  1553. .arg(qry.value(2).toInt()).arg(qry.value(3).toInt()).arg(qry.value(4).toInt()).arg(qry.value(5).toInt()).arg(qry.value(6).toInt()).arg(qry.value(0).toString());
  1554. update_company_alarmstatus(qry.value(0).toString(),0,qry.value(2).toUInt(),qry.value(3).toUInt(),qry.value(4).toUInt(),qry.value(5).toUInt(),qry.value(6).toUInt());
  1555. }else if(qry.value(1).toInt()==6){
  1556. sql2 += QString("update sp_company_sync set device_06_count=%1, device_06_out=%2, device_06_out_confirm=%3, device_06_alarm=%4, device_06_alarm_confirm=%5 where company_code='%6'")
  1557. .arg(qry.value(2).toInt()).arg(qry.value(3).toInt()).arg(qry.value(4).toInt()).arg(qry.value(5).toInt()).arg(qry.value(6).toInt()).arg(qry.value(0).toString());
  1558. update_company_alarmstatus(qry.value(0).toString(),6,qry.value(2).toUInt(),qry.value(3).toUInt(),qry.value(4).toUInt(),qry.value(5).toUInt(),qry.value(6).toUInt());
  1559. }else if(qry.value(1).toInt()==7){
  1560. sql2 += QString("update sp_company_sync set device_07_count=%1, device_07_out=%2, device_07_out_confirm=%3, device_07_alarm=%4, device_07_alarm_confirm=%5 where company_code='%6'")
  1561. .arg(qry.value(2).toInt()).arg(qry.value(3).toInt()).arg(qry.value(4).toInt()).arg(qry.value(5).toInt()).arg(qry.value(6).toInt()).arg(qry.value(0).toString());
  1562. update_company_alarmstatus(qry.value(0).toString(),7,qry.value(2).toUInt(),qry.value(3).toUInt(),qry.value(4).toUInt(),qry.value(5).toUInt(),qry.value(6).toUInt());
  1563. }else if(qry.value(1).toInt()==16){
  1564. sql2 += QString("update sp_company_sync set device_16_count=%1, device_16_out=%2, device_16_out_confirm=%3, device_16_alarm=%4, device_16_alarm_confirm=%5 where company_code='%6'")
  1565. .arg(qry.value(2).toInt()).arg(qry.value(3).toInt()).arg(qry.value(4).toInt()).arg(qry.value(5).toInt()).arg(qry.value(6).toInt()).arg(qry.value(0).toString());
  1566. update_company_alarmstatus(qry.value(0).toString(),16,qry.value(2).toUInt(),qry.value(3).toUInt(),qry.value(4).toUInt(),qry.value(5).toUInt(),qry.value(6).toUInt());
  1567. }
  1568. mdb.exec(sql2);
  1569. qry2.clear();
  1570. usleep(5000);
  1571. }
  1572. qry.clear();
  1573. QDate d_day = QDate::currentDate().addDays(-7);
  1574. QString delsql = QString("delete from sp_owner_sync_data where data_time<'%1-%2-%3 00:00:00'").arg(d_day.year(),4,10,QChar('0')).arg(d_day.month(),2,10,QChar('0')).arg(d_day.day(),2,10,QChar('0'));
  1575. mdb.exec(delsql);
  1576. qry = mdb.exec("select sp_owner_status.id, sp_owner_status.device_id, sp_owner_status.data_time, sp_owner.dwtype from sp_owner_status, sp_owner where sp_owner_status.device_id=sp_owner.owner_code and sp_owner.dwtype=1 and sp_owner_status.point_data !='0'");
  1577. while(qry.next()){
  1578. qry2 = mdb.exec(QString("select clzt from sp_hj2017 where device_code=%1 and time='%2'")
  1579. .arg(qry.value(1).toString()).arg(qry.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss")));
  1580. if((qry2.next())&&(qry2.value(0).toInt()==1))
  1581. mdb.exec(QString("update sp_owner_status set point_data='0' where id=%1").arg(qry.value(0).toInt()));
  1582. qry.clear();
  1583. usleep(5000);
  1584. }
  1585. qry.clear();
  1586. qry = mdb.exec("select sp_owner_status.id, sp_owner_status.device_id, sp_owner_status.data_time, sp_owner_status.point_data from sp_owner_status, sp_owner where sp_owner_status.point_code=1 and sp_owner_status.device_id=sp_owner.owner_code and (sp_owner.dwtype=2 or sp_owner.dwtype=5) and sp_owner_status.point_data !='0' and sp_owner_status.point_data !='WP0'");
  1587. while(qry.next()){
  1588. qry2 = mdb.exec(QString("select clzt from sp_sj2017 where device_code=%1 and time='%2'")
  1589. .arg(qry.value(1).toString()).arg(qry.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss")));
  1590. if((qry2.next())&&(qry2.value(0).toInt()==1))
  1591. mdb.exec(QString("update sp_owner_status set point_data='0',data_time='%1' where device_id='%2' and point_code=0").arg(qry.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(qry.value(1).toString()));
  1592. else
  1593. mdb.exec(QString("update sp_owner_status set point_data='%1',data_time='%2' where device_id='%3' and point_code=0").arg(qry.value(3).toString()).arg(qry.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(qry.value(1).toString()));
  1594. usleep(5000);
  1595. }
  1596. mdb.close();
  1597. mdbOpened = false;
  1598. }
  1599. isWorking = false;
  1600. }
  1601. }
  1602. void DB_SyncThread::setCompanyAlarmSet(QString deviceCode, AlarmSet set)
  1603. {
  1604. QString companyCode;
  1605. quint16 companyIdx = 0xffff;
  1606. quint32 deviceIdx = 0xffffffff;
  1607. AlarmSet tmp = AlarmSet(0xffffffff,"","",0xff,0,0);
  1608. for(quint32 i=0;i<102400;i++){
  1609. if(i>=webData->DevicesCount)
  1610. break;
  1611. if(QString::compare(QString(webData->devices[i].DevCode),deviceCode)==0){
  1612. deviceIdx = i;
  1613. companyCode = QString(webData->devices[i].CompanyCode);
  1614. set.DeviceIdx = deviceIdx;
  1615. set.DevName = QString(webData->devices[i].DevName);
  1616. if(set.dwType==16){
  1617. system(QString("echo '%1, %2, %3' >> /root/data.txt").arg(webData->devices[i].CompanyCode)
  1618. .arg(deviceCode).arg(QDateTime::fromTime_t(set.AlarmTime).toString("yyyy-MM-dd HH:mm:ss"))
  1619. .toUtf8().data());
  1620. }
  1621. setLastAlarmSet(static_cast<quint16>(i),set.dwType,set);
  1622. break;
  1623. }
  1624. }
  1625. for(quint16 i=0;i<10240;i++){
  1626. if(i>=webData->CompanysCount)
  1627. break;
  1628. if(QString::compare(QString(webData->companys[i].CompanyCode),companyCode)==0){
  1629. companyIdx = i;
  1630. break;
  1631. }
  1632. }
  1633. if(companyIdx<webData->CompanysCount){
  1634. for(quint8 i=0;i<10;i++){
  1635. if(set.AlarmTime>webData->CompanyAlarm[companyIdx].alarmRec[i].Time_T){
  1636. for(quint8 j=9;j>i;j--){
  1637. get_AlarmSet(companyIdx,j-1,&tmp);
  1638. set_AlarmSet(companyIdx,j,tmp);
  1639. }
  1640. set_AlarmSet(companyIdx,i,set);
  1641. break;
  1642. }
  1643. }
  1644. for(quint8 i=0;i<10;i++){
  1645. if(set.AlarmTime>webData->CompanyAlarm[10239].alarmRec[i].Time_T){
  1646. for(quint8 j=9;j>i;j--){
  1647. get_AlarmSet(10239,j-1,&tmp);
  1648. set_AlarmSet(10239,j,tmp);
  1649. }
  1650. set_AlarmSet(10239,i,set);
  1651. break;
  1652. }
  1653. }
  1654. }
  1655. }
  1656. void DB_SyncThread::set_AlarmSet(quint16 companyIdx, quint8 alarmIdx, AlarmSet set)
  1657. {
  1658. if(((companyIdx<webData->CompanysCount)||(companyIdx==10239))&&(alarmIdx<10)){
  1659. if(set.Enabled==0x01){
  1660. webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].DeviceIdx = set.DeviceIdx;
  1661. sprintf(webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].DevName,"%s",set.DevName.toUtf8().data());
  1662. sprintf(webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].Data,"%s",set.AlarmData.toUtf8().data());
  1663. sprintf(webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].Time,"%s",QDateTime::fromTime_t(set.AlarmTime).toString("yyyy-MM-dd HH:mm:ss").toUtf8().data());
  1664. webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].dwType = set.dwType;
  1665. webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].Time_T = set.AlarmTime;
  1666. webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].ShowFlag = 0x01;
  1667. }else
  1668. webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].ShowFlag = 0x00;
  1669. webData->CompanyAlarm[companyIdx].UpdateTime = UpdateTime;
  1670. }
  1671. }
  1672. void DB_SyncThread::setLastAlarmSet(quint16 companyIdx, quint8 dwtype, AlarmSet set)
  1673. {
  1674. int page=0, dwIdx=0;
  1675. // if(dwtype==16){
  1676. // system(QString("echo '16 to mem: %1 %2 %3 %4' >> /root/data.txt")
  1677. // .arg(companyIdx).arg(webData->CompanysCount).arg(set.DeviceIdx).arg(webData->DevicesCount)
  1678. // .toUtf8().data());
  1679. // }
  1680. if(((companyIdx<webData->CompanysCount)||(companyIdx==10239))&&(dwtype<20)){
  1681. if(dwtype==1){
  1682. page = 0;
  1683. dwIdx = 1;
  1684. }else if(dwtype==2){
  1685. page = 0;
  1686. dwIdx = 2;
  1687. }else if(dwtype==6){
  1688. page = 0;
  1689. dwIdx = 3;
  1690. }else if(dwtype==7){
  1691. page = 0;
  1692. dwIdx = 4;
  1693. }else if(dwtype==16){
  1694. page = 0;
  1695. dwIdx = 5;
  1696. }
  1697. if(set.Enabled==0x01)
  1698. {
  1699. // if(dwtype==16){
  1700. // system(QString("echo 'lastAlarmRec %1 %2 %3 companyIdx:%4 page:%5 dwIdx:%6' >> /root/data.txt")
  1701. // .arg(set.DevName).arg(set.AlarmData).arg(QDateTime::fromTime_t(set.AlarmTime).toString("yyyy-MM-dd HH:mm:ss"))
  1702. // .arg(companyIdx).arg(page).arg(dwIdx).toUtf8().data());
  1703. // }
  1704. webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].DeviceIdx = set.DeviceIdx;
  1705. sprintf(webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].DevName,"%s",set.DevName.toUtf8().data());
  1706. sprintf(webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].Data,"%s",set.AlarmData.toUtf8().data());
  1707. sprintf(webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].Time,"%s",QDateTime::fromTime_t(set.AlarmTime).toString("yyyy-MM-dd HH:mm:ss").toUtf8().data());
  1708. webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].dwType = set.dwType;
  1709. webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].Time_T = set.AlarmTime;
  1710. webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].ShowFlag = 0x01;
  1711. if(!initTime)
  1712. emit companyAlarmChanged(QString(webData->companys[companyIdx].CompanyCode));
  1713. }else
  1714. webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].ShowFlag = 0x00;
  1715. webData->LastAlarmRec[companyIdx][page].UpdateTime = UpdateTime;
  1716. }
  1717. }
  1718. void DB_SyncThread::get_AlarmSet(quint16 companyIdx, quint8 alarmIdx, AlarmSet *set)
  1719. {
  1720. if(((companyIdx<webData->CompanysCount)||(companyIdx==10239))&&(alarmIdx<10)){
  1721. if(webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].ShowFlag==0x01){
  1722. set->Enabled = 0x01;
  1723. set->DeviceIdx = webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].DeviceIdx;
  1724. set->dwType = webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].dwType;
  1725. set->AlarmTime = webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].Time_T;
  1726. set->DevName = QString::fromUtf8(webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].DevName);
  1727. set->AlarmData = QString::fromUtf8(webData->CompanyAlarm[companyIdx].alarmRec[alarmIdx].Data);
  1728. }else{
  1729. set->Enabled = 0x00;
  1730. }
  1731. }
  1732. }
  1733. void DB_SyncThread::getLastAlarmSet(quint16 companyIdx, quint8 dwtype, AlarmSet *set)
  1734. {
  1735. int page=0, dwIdx=0;
  1736. if(((companyIdx<webData->CompanysCount)||(companyIdx==10239))&&(dwtype<20)){
  1737. if(dwtype==1){
  1738. page = 0;
  1739. dwIdx = 1;
  1740. }else if(dwtype==2){
  1741. page = 0;
  1742. dwIdx = 2;
  1743. }else if(dwtype==6){
  1744. page = 0;
  1745. dwIdx = 3;
  1746. }else if(dwtype==7){
  1747. page = 0;
  1748. dwIdx = 4;
  1749. }else if(dwtype==16){
  1750. page = 0;
  1751. dwIdx = 5;
  1752. }
  1753. if(webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].ShowFlag==0x01){
  1754. set->Enabled = 0x01;
  1755. set->DeviceIdx = webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].DeviceIdx;
  1756. set->dwType = webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].dwType;
  1757. set->AlarmTime = webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].Time_T;
  1758. set->DevName = QString::fromUtf8(webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].DevName);
  1759. set->AlarmData = QString::fromUtf8(webData->LastAlarmRec[companyIdx][page].alarmRec[dwIdx].Data);
  1760. }else{
  1761. set->Enabled = 0x00;
  1762. }
  1763. }
  1764. }
  1765. void DB_SyncThread::update_company_alarmstatus(QString companycode, quint8 alarmidx, uint devCount, uint devOut, uint devOutConfirm, uint devAlarmCount, uint devAlarmConfirm)
  1766. {
  1767. uint dC=0,dO=0,dOC=0,dA=0,dAC=0;
  1768. quint16 companyIdx = 0xffff;
  1769. for(quint16 i=0;i<10240;i++){
  1770. if(i>=webData->CompanysCount)
  1771. break;
  1772. if(QString::compare(QString(webData->companys[i].CompanyCode),companycode)==0){
  1773. companyIdx = i;
  1774. break;
  1775. }
  1776. }
  1777. if(companyIdx<webData->CompanysCount){
  1778. for(quint16 i=0;i<10239;i++){
  1779. if(i==companyIdx){
  1780. webData->companys[i].subType[alarmidx].DevCount = devCount;
  1781. webData->companys[i].subType[alarmidx].DevOutLineCount = devOut;
  1782. webData->companys[i].subType[alarmidx].DevOutConfirmCount = devOutConfirm;
  1783. webData->companys[i].subType[alarmidx].DevAlarmCount = devAlarmCount;
  1784. webData->companys[i].subType[alarmidx].DevAlarmConfirmCount = devAlarmConfirm;
  1785. }
  1786. dC += webData->companys[i].subType[alarmidx].DevCount;
  1787. dO += webData->companys[i].subType[alarmidx].DevOutLineCount;
  1788. dOC += webData->companys[i].subType[alarmidx].DevOutConfirmCount;
  1789. dA += webData->companys[i].subType[alarmidx].DevAlarmCount;
  1790. dAC += webData->companys[i].subType[alarmidx].DevAlarmConfirmCount;
  1791. }
  1792. webData->companys[10239].subType[alarmidx].DevCount = dC;
  1793. webData->companys[10239].subType[alarmidx].DevOutLineCount = dO;
  1794. webData->companys[10239].subType[alarmidx].DevOutConfirmCount = dOC;
  1795. webData->companys[10239].subType[alarmidx].DevAlarmCount = dA;
  1796. webData->companys[10239].subType[alarmidx].DevAlarmConfirmCount = dAC;
  1797. }
  1798. }
  1799. void DB_SyncThread::webShmInit()
  1800. {
  1801. // printf("init memory at %s\n",QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toUtf8().data());
  1802. UpdateTime = QDateTime::currentDateTime().toTime_t();
  1803. checkUsers();
  1804. checkCompany();
  1805. checkDevice();
  1806. checkAlarmStatus();
  1807. checkAlarmList();
  1808. initTime = false;
  1809. }
  1810. quint32 DB_SyncThread::getDeviceIdxByDeviceCode(QString deviceCode)
  1811. {
  1812. for(quint32 i=0;i<102400;i++){
  1813. if(webData->devices[i].Enabled==0x01){
  1814. if(QString::compare(deviceCode,QString(webData->devices[i].DevCode))==0){
  1815. return i;
  1816. }
  1817. }
  1818. }
  1819. return 0xffffffff;
  1820. }
  1821. void DB_SyncThread::checkAlarmList()
  1822. {
  1823. QSqlQuery qry;
  1824. QList<AlarmSet> companyAlarmList;
  1825. QList<AlarmSet> allAlarmList;
  1826. int nrow;
  1827. allAlarmList.clear();
  1828. for(quint16 i=0;i<webData->CompanysCount;i++){
  1829. if(strlen(webData->companys[i].CompanyCode)>0){
  1830. companyAlarmList.clear();
  1831. qry = mdb.exec(QString("select h.device_code, h.time, h.data2, h.data4, o.owner_name from sp_hj2017 h, sp_owner o where o.owner_code = h.device_code and o.company='%1' and h.time<now() order by h.time desc limit 0, 10").arg(webData->companys[i].CompanyCode));
  1832. nrow = 0;
  1833. while(qry.next()){
  1834. AlarmSet CompanyAlarm = AlarmSet(getDeviceIdxByDeviceCode(qry.value(0).toString()),qry.value(4).toString(),
  1835. QString::fromUtf8("%1,%2").arg(qry.value(2).toString()).arg(qry.value(3).toString()),
  1836. 1,qry.value(1).toDateTime().toTime_t(),1);
  1837. if(nrow==0)
  1838. setLastAlarmSet(i,1,CompanyAlarm);
  1839. companyAlarmList.append(CompanyAlarm);
  1840. allAlarmList.append(CompanyAlarm);
  1841. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  1842. ytShm->updatetime[DB_THREAD] = tmp_time;
  1843. nrow++;
  1844. }
  1845. qry.clear();
  1846. nrow = 0;
  1847. qry = mdb.exec(QString("select s.device_code, s.time, s.data1, s.data4, o.owner_name from sp_sj2017 s, sp_owner o where o.owner_code = s.device_code and o.company='%1' and s.time<now() order by s.time desc limit 0, 10").arg(webData->companys[i].CompanyCode));
  1848. while(qry.next()){
  1849. QString dat1 = qry.value(2).toString();
  1850. QString data1 = QString::compare(dat1,"WP1")==0?QString::fromUtf8("低压"):
  1851. (QString::compare(dat1,"WP2")==0?QString::fromUtf8("高压"):
  1852. (QString::compare(dat1,"WP3")==0?QString::fromUtf8("故障"):
  1853. (QString::compare(dat1,"WP4")==0?QString::fromUtf8("离线"):
  1854. (QString::compare(dat1,"WP0")==0?QString::fromUtf8("恢复"):
  1855. (QString::compare(dat1,"LL1")==0?QString::fromUtf8("低液位"):
  1856. (QString::compare(dat1,"LL2")==0?QString::fromUtf8("高液位"):
  1857. (QString::compare(dat1,"LL3")==0?QString::fromUtf8("故障"):
  1858. (QString::compare(dat1,"LL4")==0?QString::fromUtf8("离线"):
  1859. (QString::compare(dat1,"LL0")==0?QString::fromUtf8("恢复"):"")))))))));
  1860. AlarmSet CompanyAlarm = AlarmSet(getDeviceIdxByDeviceCode(qry.value(0).toString()),qry.value(4).toString(),
  1861. data1+QString::fromUtf8(",")+qry.value(3).toString(),
  1862. 2,qry.value(1).toDateTime().toTime_t(),1);
  1863. if(nrow==0)
  1864. setLastAlarmSet(i,2,CompanyAlarm);
  1865. companyAlarmList.append(CompanyAlarm);
  1866. allAlarmList.append(CompanyAlarm);
  1867. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  1868. ytShm->updatetime[DB_THREAD] = tmp_time;
  1869. nrow++;
  1870. }
  1871. qry.clear();
  1872. nrow=0;
  1873. qry = mdb.exec(QString("select r.device_code, r.time, r.data2, r.data4, o.owner_name from sp_rtu2017 r, sp_owner o where o.owner_code = r.device_code and o.company='%1' and r.time<now() order by r.time desc limit 0, 10").arg(webData->companys[i].CompanyCode));
  1874. while(qry.next()){
  1875. AlarmSet CompanyAlarm = AlarmSet(getDeviceIdxByDeviceCode(qry.value(0).toString()),qry.value(4).toString(),
  1876. qry.value(2).toString()+QString::fromUtf8(",")+qry.value(3).toString(),
  1877. 6,qry.value(1).toDateTime().toTime_t(),1);
  1878. if(nrow==0)
  1879. setLastAlarmSet(i,6,CompanyAlarm);
  1880. companyAlarmList.append(CompanyAlarm);
  1881. allAlarmList.append(CompanyAlarm);
  1882. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  1883. ytShm->updatetime[DB_THREAD] = tmp_time;
  1884. nrow++;
  1885. }
  1886. qry.clear();
  1887. nrow=0;
  1888. qry = mdb.exec(QString("select e.device_code, e.time, e.data1, o.owner_name from sp_ef2017 e, sp_owner o where o.owner_code = e.device_code and o.company='%1' and e.time<now() order by e.time desc limit 0, 10").arg(webData->companys[i].CompanyCode));
  1889. while(qry.next()){
  1890. QString dat1 = qry.value(2).toString();
  1891. AlarmSet CompanyAlarm = AlarmSet(getDeviceIdxByDeviceCode(qry.value(0).toString()),qry.value(3).toString(),
  1892. QString::compare(dat1,"EF1")==0?QString::fromUtf8("欠压报警"):
  1893. (QString::compare(dat1,"EF2")==0?QString::fromUtf8("过压报警"):
  1894. (QString::compare(dat1,"EF3")==0?QString::fromUtf8("过流告警"):
  1895. (QString::compare(dat1,"EF4")==0?QString::fromUtf8("漏电报警"):
  1896. (QString::compare(dat1,"EF5")==0?QString::fromUtf8("#1线缆温度超高报警"):
  1897. (QString::compare(dat1,"EF6")==0?QString::fromUtf8("#2线缆温度超高报警"):
  1898. (QString::compare(dat1,"EF7")==0?QString::fromUtf8("#3线缆温度超高报警"):
  1899. (QString::compare(dat1,"EF8")==0?QString::fromUtf8("#4线缆温度超高报警"):
  1900. (QString::compare(dat1,"EF9")==0?QString::fromUtf8("设备离线"):
  1901. (QString::compare(dat1,"EF0")==0?QString::fromUtf8("报警撤销"):""))))))))),
  1902. 7,qry.value(1).toDateTime().toTime_t(),1);
  1903. if(nrow==0)
  1904. setLastAlarmSet(i,7,CompanyAlarm);
  1905. companyAlarmList.append(CompanyAlarm);
  1906. allAlarmList.append(CompanyAlarm);
  1907. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  1908. ytShm->updatetime[DB_THREAD] = tmp_time;
  1909. nrow++;
  1910. }
  1911. qry.clear();
  1912. nrow=0;
  1913. QString sql = QString("select v.device_code, v.time, v.data4, o.owner_name from sp_video2017 v, sp_owner o where o.owner_code = v.device_code and o.company='%1' and v.time<now() order by v.time desc limit 0, 10").arg(webData->companys[i].CompanyCode);
  1914. // system(QString("echo '%1' >> /root/sql.txt").arg(sql).toUtf8().data());
  1915. qry = mdb.exec(sql);
  1916. while(qry.next()){
  1917. AlarmSet CompanyAlarm = AlarmSet(getDeviceIdxByDeviceCode(qry.value(0).toString()),qry.value(3).toString(),
  1918. qry.value(2).toString(),16,qry.value(1).toDateTime().toTime_t(),1);
  1919. if(nrow==0){
  1920. // system(QString("echo '%1 %2 %3' >> /root/data.txt ").arg(webData->companys[i].CompanyCode).arg(qry.value(1).toString()).arg(qry.value(2).toString()).toUtf8().data());
  1921. setLastAlarmSet(i,16,CompanyAlarm);
  1922. }
  1923. companyAlarmList.append(CompanyAlarm);
  1924. allAlarmList.append(CompanyAlarm);
  1925. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  1926. ytShm->updatetime[DB_THREAD] = tmp_time;
  1927. nrow++;
  1928. }
  1929. qry.clear();
  1930. qSort(companyAlarmList.begin(),companyAlarmList.end(),compareAlarmSet);
  1931. qSort(allAlarmList.begin(),allAlarmList.end(),compareAlarmSet);
  1932. while(companyAlarmList.length()>10)
  1933. companyAlarmList.removeLast();
  1934. while(allAlarmList.length()>10)
  1935. allAlarmList.removeLast();
  1936. for(int j=0;j<10;j++){
  1937. if(j<companyAlarmList.length()){
  1938. AlarmSet alarm = companyAlarmList.at(j);
  1939. webData->CompanyAlarm[i].alarmRec[j].DeviceIdx=alarm.DeviceIdx;
  1940. sprintf(webData->CompanyAlarm[i].alarmRec[j].DevName,"%s",alarm.DevName.toUtf8().data());
  1941. sprintf(webData->CompanyAlarm[i].alarmRec[j].Data,"%s",alarm.AlarmData.toUtf8().data());
  1942. sprintf(webData->CompanyAlarm[i].alarmRec[j].Time,"%s",QDateTime::fromTime_t(alarm.AlarmTime).toString("yyyy-MM-dd HH:mm:ss").toUtf8().data());
  1943. webData->CompanyAlarm[i].alarmRec[j].dwType = alarm.dwType;
  1944. webData->CompanyAlarm[i].alarmRec[j].Time_T = alarm.AlarmTime;
  1945. webData->CompanyAlarm[i].alarmRec[j].ShowFlag = 0x01;
  1946. }else
  1947. webData->CompanyAlarm[i].alarmRec[j].ShowFlag = 0x00;
  1948. webData->CompanyAlarm[i].UpdateTime = UpdateTime;
  1949. }
  1950. }
  1951. usleep(5000);
  1952. }
  1953. for(int j=0;j<10;j++){
  1954. if(j<allAlarmList.length()){
  1955. AlarmSet alarm = allAlarmList.at(j);
  1956. webData->CompanyAlarm[10239].alarmRec[j].DeviceIdx = alarm.DeviceIdx;
  1957. sprintf(webData->CompanyAlarm[10239].alarmRec[j].DevName,"%s",alarm.DevName.toUtf8().data());
  1958. sprintf(webData->CompanyAlarm[10239].alarmRec[j].Data,"%s",alarm.AlarmData.toUtf8().data());
  1959. sprintf(webData->CompanyAlarm[10239].alarmRec[j].Time,"%s",QDateTime::fromTime_t(alarm.AlarmTime).toString("yyyy-MM-dd HH:mm:ss").toUtf8().data());
  1960. webData->CompanyAlarm[10239].alarmRec[j].dwType = alarm.dwType;
  1961. webData->CompanyAlarm[10239].alarmRec[j].Time_T = alarm.AlarmTime;
  1962. webData->CompanyAlarm[10239].alarmRec[j].ShowFlag = 0x01;
  1963. }else
  1964. webData->CompanyAlarm[10239].alarmRec[j].ShowFlag = 0x00;
  1965. webData->CompanyAlarm[10239].UpdateTime = UpdateTime;
  1966. }
  1967. }
  1968. void DB_SyncThread::checkAlarmStatus()
  1969. {
  1970. char company_code[50];
  1971. QSqlQuery qry = mdb.exec("select company_code, device_01_count+device_03_count as dev1count, device_01_out+device_03_out as dev1out, device_01_out_confirm+device_03_out_confirm as dev1outconfirm, device_01_alarm+device_03_alarm as dev1ala, device_01_alarm_confirm+device_03_alarm_confirm as dev1alaconfirm, device_02_count, device_02_out, device_02_out_confirm, device_02_alarm, device_02_alarm_confirm, device_06_count, device_06_out, device_06_out_confirm, device_06_alarm, device_06_alarm_confirm, device_07_count, device_07_out, device_07_out_confirm, device_07_alarm, device_07_alarm_confirm, device_16_count, device_16_out, device_16_out_confirm, device_16_alarm, device_16_alarm_confirm from sp_company_sync");
  1972. while(qry.next()){
  1973. sprintf(company_code,"%s",qry.value(0).toString().toUtf8().data());
  1974. if(strlen(company_code)>0){
  1975. for(unsigned int i=0;i<10240;i++){
  1976. if(i>=webData->CompanysCount)
  1977. break;
  1978. if(strcmp(company_code,webData->companys[i].CompanyCode)==0){
  1979. webData->companys[i].subType[1].DevCount = qry.value(1).toUInt();
  1980. webData->companys[i].subType[1].DevOutLineCount = qry.value(2).toUInt();
  1981. webData->companys[i].subType[1].DevOutConfirmCount = qry.value(3).toUInt();
  1982. webData->companys[i].subType[1].DevAlarmCount = qry.value(4).toUInt();
  1983. webData->companys[i].subType[1].DevAlarmConfirmCount = qry.value(5).toUInt();
  1984. webData->companys[i].subType[2].DevCount = qry.value(6).toUInt();
  1985. webData->companys[i].subType[2].DevOutLineCount = qry.value(7).toUInt();
  1986. webData->companys[i].subType[2].DevOutConfirmCount = qry.value(8).toUInt();
  1987. webData->companys[i].subType[2].DevAlarmCount = qry.value(9).toUInt();
  1988. webData->companys[i].subType[2].DevAlarmConfirmCount = qry.value(10).toUInt();
  1989. webData->companys[i].subType[6].DevCount = qry.value(11).toUInt();
  1990. webData->companys[i].subType[6].DevOutLineCount = qry.value(12).toUInt();
  1991. webData->companys[i].subType[6].DevOutConfirmCount = qry.value(13).toUInt();
  1992. webData->companys[i].subType[6].DevAlarmCount = qry.value(14).toUInt();
  1993. webData->companys[i].subType[6].DevAlarmConfirmCount = qry.value(15).toUInt();
  1994. webData->companys[i].subType[7].DevCount = qry.value(16).toUInt();
  1995. webData->companys[i].subType[7].DevOutLineCount = qry.value(17).toUInt();
  1996. webData->companys[i].subType[7].DevOutConfirmCount = qry.value(18).toUInt();
  1997. webData->companys[i].subType[7].DevAlarmCount = qry.value(19).toUInt();
  1998. webData->companys[i].subType[7].DevAlarmConfirmCount = qry.value(20).toUInt();
  1999. webData->companys[i].subType[16].DevCount = qry.value(21).toUInt();
  2000. webData->companys[i].subType[16].DevOutLineCount = qry.value(22).toUInt();
  2001. webData->companys[i].subType[16].DevOutConfirmCount = qry.value(23).toUInt();
  2002. webData->companys[i].subType[16].DevAlarmCount = qry.value(24).toUInt();
  2003. webData->companys[i].subType[16].DevAlarmConfirmCount = qry.value(25).toUInt();
  2004. break;
  2005. }
  2006. }
  2007. }
  2008. {
  2009. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  2010. ytShm->updatetime[DB_THREAD] = tmp_time;
  2011. }
  2012. usleep(5000);
  2013. }
  2014. qry.clear();
  2015. }
  2016. void DB_SyncThread::checkDevice()
  2017. {
  2018. unsigned int count = 0;
  2019. QSqlQuery qry = mdb.exec("SELECT id, owner_code, company, dwtype, owner_name, unitinfo from sp_owner");
  2020. while(qry.next()){
  2021. if((webData->devices[count].dwType!=(qry.value(3).toUInt()&0xff))
  2022. ||(QString::compare(QString::fromUtf8(webData->devices[count].DevCode),qry.value(1).toString())!=0)
  2023. ||(QString::compare(QString::fromUtf8(webData->devices[count].CompanyCode),qry.value(2).toString())!=0)
  2024. ||(QString::compare(QString::fromUtf8(webData->devices[count].DevName),qry.value(4).toString())!=0)
  2025. ||(QString::compare(QString::fromUtf8(webData->devices[count].DevInfo),qry.value(5).toString())!=0)){
  2026. webData->devices[count].DevIdx = count&0xffffffff;
  2027. sprintf(webData->devices[count].DevCode,"%s",qry.value(1).toString().toUtf8().data());
  2028. sprintf(webData->devices[count].CompanyCode,"%s",qry.value(2).toString().toUtf8().data());
  2029. webData->devices[count].dwType = qry.value(3).toUInt()&0xff;
  2030. sprintf(webData->devices[count].DevName,"%s",qry.value(4).toString().toUtf8().data());
  2031. sprintf(webData->devices[count].DevInfo,"%s",qry.value(5).toString().toUtf8().data());
  2032. webData->devices[count].Enabled = 0x01;
  2033. webData->devices[count].UpdateTime = UpdateTime;
  2034. }
  2035. count++;
  2036. if(count>webData->DevicesCount)
  2037. webData->DevicesCount = count;
  2038. if(count>102399)
  2039. break;
  2040. usleep(5000);
  2041. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  2042. ytShm->updatetime[DB_THREAD] = tmp_time;
  2043. }
  2044. qry.clear();
  2045. }
  2046. void DB_SyncThread::checkCompany()
  2047. {
  2048. unsigned int count = 0;
  2049. QSqlQuery qry = mdb.exec("select c.owner_id, c.owner_name, c.xmlx, p.username, p.phone, c.building_id, b.build_name, ifnull(concat(b.addr1,'.',b.addr2,'.',b.addr3,'.',b.address),''),ifnull(b.posistion,''),b.address from jdxf.sp_owner_company c, jdxf.sp_building b, ytIoT.ytiot_t_company_phone p where c.building_id=b.id and c.owner_id = p.owner_code");
  2050. while(qry.next()){
  2051. float Lng=0.0,Lat=0.0;
  2052. QString position = qry.value(8).toString();
  2053. if(position.length()>0){
  2054. QStringList pos = position.split(",");
  2055. if(pos.length()>1){
  2056. Lng = pos.at(0).toFloat();
  2057. Lat = pos.at(1).toFloat();
  2058. }
  2059. }
  2060. if(
  2061. // (webData->buildings[count].Lng!=Lng)
  2062. // ||(webData->buildings[count].Lat!=Lat)
  2063. // ||
  2064. (QString::compare(QString::fromUtf8(webData->companys[count].CompanyCode),qry.value(0).toString())!=0)
  2065. ||(QString::compare(QString::fromUtf8(webData->companys[count].CompanyName),qry.value(1).toString())!=0)
  2066. ||(QString::compare(QString::fromUtf8(webData->companys[count].ProjectType),qry.value(2).toString())!=0)
  2067. ||(QString::compare(QString::fromUtf8(webData->companys[count].UserName),qry.value(3).toString())!=0)
  2068. ||(QString::compare(QString::fromUtf8(webData->companys[count].Phone),qry.value(4).toString())!=0)
  2069. ||(QString::compare(QString::fromUtf8(webData->buildings[count].CompanyCode),qry.value(0).toString())!=0)
  2070. ||(QString::compare(QString::fromUtf8(webData->buildings[count].BuildingCode),qry.value(5).toString())!=0)
  2071. ||(QString::compare(QString::fromUtf8(webData->buildings[count].BuildingName),qry.value(6).toString())!=0)
  2072. ||(QString::compare(QString::fromUtf8(webData->buildings[count].FullAddress),qry.value(7).toString())!=0)
  2073. ||(QString::compare(QString::fromUtf8(webData->buildings[count].Address),qry.value(9).toString())!=0)){
  2074. sprintf(webData->companys[count].CompanyCode,"%s",qry.value(0).toString().toUtf8().data());
  2075. sprintf(webData->companys[count].CompanyName,"%s",qry.value(1).toString().toUtf8().data());
  2076. sprintf(webData->companys[count].ProjectType,"%s",qry.value(2).toString().toUtf8().data());
  2077. sprintf(webData->companys[count].UserName,"%s",qry.value(3).toString().toUtf8().data());
  2078. sprintf(webData->companys[count].Phone,"%s",qry.value(4).toString().toUtf8().data());
  2079. sprintf(webData->buildings[count].CompanyCode,"%s",qry.value(0).toString().toUtf8().data());
  2080. sprintf(webData->buildings[count].BuildingCode,"%s",qry.value(5).toString().toUtf8().data());
  2081. sprintf(webData->buildings[count].BuildingName,"%s",qry.value(6).toString().toUtf8().data());
  2082. sprintf(webData->buildings[count].FullAddress,"%s",qry.value(7).toString().toUtf8().data());
  2083. sprintf(webData->buildings[count].Address,"%s",qry.value(9).toString().toUtf8().data());
  2084. webData->buildings[count].Lng = Lng;
  2085. webData->buildings[count].Lat = Lat;
  2086. webData->companys[count].UpdateTime = UpdateTime;
  2087. webData->buildings[count].UpdateTime = UpdateTime;
  2088. }
  2089. count++;
  2090. if(count>webData->BuildingsCount)
  2091. webData->BuildingsCount = count;
  2092. if(count>webData->CompanysCount)
  2093. webData->CompanysCount = count;
  2094. if(count>webData->CompanysAlarmCount)
  2095. webData->CompanysAlarmCount = count;
  2096. if(count>10239)
  2097. break;
  2098. usleep(5000);
  2099. {
  2100. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  2101. ytShm->updatetime[DB_THREAD] = tmp_time;
  2102. }
  2103. }
  2104. webData->CompanysCount = count;
  2105. webData->BuildingsCount = count;
  2106. webData->CompanysAlarmCount = count;
  2107. qry.clear();
  2108. }
  2109. void DB_SyncThread::checkUsers()
  2110. {
  2111. unsigned int count = 0;
  2112. QSqlQuery qry = mdb.exec("select username, password, truename, status from sp_user order by id");
  2113. while(qry.next()){
  2114. if((webData->users[count].Status!=(qry.value(3).toUInt()&0xff))
  2115. ||(QString::compare(QString::fromUtf8(webData->users[count].LoginName),qry.value(0).toString())!=0)
  2116. ||(QString::compare(QString::fromUtf8(webData->users[count].Password),qry.value(1).toString())!=0)
  2117. ||(QString::compare(QString::fromUtf8(webData->users[count].UserName),qry.value(2).toString())!=0)){
  2118. sprintf(webData->users[count].LoginName,"%s",qry.value(0).toString().toUtf8().data());
  2119. sprintf(webData->users[count].Password,"%s",qry.value(1).toString().toUtf8().data());
  2120. sprintf(webData->users[count].UserName,"%s",qry.value(2).toString().toUtf8().data());
  2121. webData->users[count].Status = qry.value(3).toUInt()&0xff;
  2122. webData->users[count].UpdateTime = UpdateTime;
  2123. }
  2124. count++;
  2125. if(count>webData->UsersCount)
  2126. webData->UsersCount = count;
  2127. if(count>10239)
  2128. break;
  2129. usleep(5000);
  2130. {
  2131. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  2132. ytShm->updatetime[DB_THREAD] = tmp_time;
  2133. }
  2134. }
  2135. qry.clear();
  2136. count = 0;
  2137. qry = mdb.exec("select agentid, owner_code from sp_owner_weibao order by id");
  2138. while(qry.next()){
  2139. if((QString::compare(QString::fromUtf8(webData->userCompanys[count].Loginname),qry.value(0).toString())!=0)
  2140. ||(QString::compare(QString::fromUtf8(webData->userCompanys[count].CompanyCode),qry.value(1).toString())!=0)){
  2141. sprintf(webData->userCompanys[count].Loginname,"%s",qry.value(0).toString().toUtf8().data());
  2142. sprintf(webData->userCompanys[count].CompanyCode,"%s",qry.value(1).toString().toUtf8().data());
  2143. webData->userCompanys[count].UpdateTime = UpdateTime;
  2144. }
  2145. count++;
  2146. if(count>webData->UserCompanyCount)
  2147. webData->UserCompanyCount = count;
  2148. if(count>20479)
  2149. break;
  2150. usleep(5000);
  2151. {
  2152. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  2153. ytShm->updatetime[DB_THREAD] = tmp_time;
  2154. }
  2155. }
  2156. qry.clear();
  2157. }
  2158. void DB_SyncThread::run()
  2159. {
  2160. webShmInit();
  2161. times = 0;
  2162. while(1)
  2163. {
  2164. time_t tmp_time = time(static_cast<time_t *>(nullptr));
  2165. ytShm->updatetime[DB_THREAD] = tmp_time;
  2166. time_out();
  2167. sleep(5);
  2168. }
  2169. }