db_syncthread.bak.cpp 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. #include "db_syncthread.h"
  2. #include "ytServiceShm.h"
  3. extern YT_SERVICE_SHM *ytShm;
  4. DB_SyncThread::DB_SyncThread(QObject *parent) :
  5. QThread(parent)
  6. {
  7. isWorking = false;
  8. mdb = QSqlDatabase::addDatabase("QMYSQL","jdxf_db");
  9. mdb.setDatabaseName("jdxf");
  10. mdb.setHostName("localhost");
  11. mdb.setUserName("root");
  12. mdb.setPassword("Yt2018IoT");
  13. mdbOpened = mdb.open();
  14. }
  15. bool DB_SyncThread::userInfoSync(QString devid,QString deviceCode, uint sync_id,QString tbname,QDate chkday,uint ID)
  16. {
  17. QString qrysql,sql;
  18. QString upsql_0="select 1;",upsql_1="select 1;";
  19. bool found = false;
  20. bool updated = false;
  21. int count=0;
  22. QSqlQuery qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_hj2017 where device_code='%1' and data1<>'U44'").arg(devid));
  23. if(qry2.next()){
  24. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  25. .arg(qry2.value(0).toInt())
  26. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  27. .arg(devid));
  28. }
  29. qry2.clear();
  30. qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_hj2017 where device_code='%1' and data1='U44'").arg(devid));
  31. if(qry2.next()){
  32. mdb.exec(QString("update sp_device_sync set com_count=%1, com_confirm=%2 where device_id='%3'")
  33. .arg(qry2.value(0).toInt())
  34. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  35. .arg(devid));
  36. }
  37. qry2.clear();
  38. for(int i=0;i<dList.length();i++){
  39. if(dList.at(i).compare(deviceCode)==0)
  40. {
  41. found = true;
  42. break;
  43. }
  44. }
  45. if(!found){
  46. 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));
  47. 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));
  48. dList.append(deviceCode);
  49. pcList.append(0);
  50. dList.append(deviceCode);
  51. pcList.append(1);
  52. }
  53. 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'));
  54. qry2 = mdb.exec(qrysql);
  55. while(qry2.next()){
  56. updated = true;
  57. if(count==0)
  58. 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')")
  59. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(1).isNull()?"0":"1")
  60. .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"))
  61. .arg(qry2.value(4).isNull()?"":qry2.value(4).toString()).arg(qry2.value(5).isNull()?"":qry2.value(5).toString());
  62. else
  63. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  64. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(1).isNull()?"0":"1")
  65. .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"))
  66. .arg(qry2.value(4).isNull()?"":qry2.value(4).toString()).arg(qry2.value(5).isNull()?"":qry2.value(5).toString());
  67. if(qry2.value(1).isNull())
  68. 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';")
  69. .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"))
  70. .arg(qry2.value(4).isNull()?"":qry2.value(4).toString()).arg(qry2.value(5).isNull()?"":qry2.value(5).toString())
  71. .arg(1).arg(devid).arg("0");
  72. else
  73. 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';")
  74. .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"))
  75. .arg(qry2.value(4).isNull()?"":qry2.value(4).toString()).arg(qry2.value(5).isNull()?"":qry2.value(5).toString())
  76. .arg(1).arg(devid);
  77. sync_id = qry2.value(0).toUInt();
  78. count++;
  79. if(count>=100){
  80. time_t tmp_time = time((time_t *)NULL);
  81. ytShm->updatetime[DB_THREAD] = tmp_time;
  82. sql.append(";");
  83. mdb.exec(sql);
  84. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  85. mdb.exec(upsql_0);
  86. mdb.exec(upsql_1);
  87. sql = "";
  88. count=0;
  89. }
  90. }
  91. if(count>0){
  92. time_t tmp_time = time((time_t *)NULL);
  93. ytShm->updatetime[DB_THREAD] = tmp_time;
  94. sql.append(";");
  95. mdb.exec(sql);
  96. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  97. mdb.exec(upsql_0);
  98. mdb.exec(upsql_1);
  99. sql = "";
  100. count=0;
  101. }
  102. return updated;
  103. }
  104. bool DB_SyncThread::waterInfoSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID,int dwtype)
  105. {
  106. QString qrysql,sql,upsql;
  107. int count=0;
  108. bool updated = false;
  109. bool found = false;
  110. 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' ").arg(devid));
  111. if(qry2.next()){
  112. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  113. .arg(qry2.value(0).toInt())
  114. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  115. .arg(devid));
  116. }
  117. qry2.clear();
  118. 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' )").arg(devid));
  119. if(qry2.next()){
  120. mdb.exec(QString("update sp_device_sync set com_count=%1, com_confirm=%2 where device_id='%3'")
  121. .arg(qry2.value(0).toInt())
  122. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  123. .arg(devid));
  124. }
  125. qry2.clear();
  126. for(int i=0;i<dList.length();i++){
  127. if(dList.at(i).compare(deviceCode)==0)
  128. {
  129. found = true;
  130. break;
  131. }
  132. }
  133. if(!found){
  134. 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));
  135. 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));
  136. 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));
  137. 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));
  138. dList.append(deviceCode);
  139. pcList.append(1);
  140. dList.append(deviceCode);
  141. pcList.append(2);
  142. dList.append(deviceCode);
  143. pcList.append(3);
  144. dList.append(deviceCode);
  145. pcList.append(4);
  146. }
  147. qrysql = QString("select id, time, data1, data2, data3, data4 from `%1` where id>%2 and time>'%3-%4-01 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'));
  148. qry2 = mdb.exec(qrysql);
  149. while(qry2.next()){
  150. updated = true;
  151. if(count==0){
  152. 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')")
  153. .arg(qry2.value(0).toUInt()).arg(devid).arg(1).arg(qry2.value(2).isNull()?"0":qry2.value(2).toString())
  154. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  155. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  156. .arg(qry2.value(0).toUInt()).arg(devid).arg(2).arg(qry2.value(3).isNull()?"0":qry2.value(3).toString())
  157. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  158. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  159. .arg(qry2.value(0).toUInt()).arg(devid).arg(3).arg(qry2.value(4).isNull()?"0":qry2.value(4).toString())
  160. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  161. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  162. .arg(qry2.value(0).toUInt()).arg(devid).arg(4).arg(qry2.value(5).isNull()?"0":qry2.value(5).toString())
  163. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  164. }else{
  165. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  166. .arg(qry2.value(0).toUInt()).arg(devid).arg(1).arg(qry2.value(2).isNull()?"0":qry2.value(2).toString())
  167. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  168. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  169. .arg(qry2.value(0).toUInt()).arg(devid).arg(2).arg(qry2.value(3).isNull()?"0":qry2.value(3).toString())
  170. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  171. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  172. .arg(qry2.value(0).toUInt()).arg(devid).arg(3).arg(qry2.value(4).isNull()?"0":qry2.value(4).toString())
  173. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  174. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  175. .arg(qry2.value(0).toUInt()).arg(devid).arg(4).arg(qry2.value(5).isNull()?"0":qry2.value(5).toString())
  176. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss")).arg("");
  177. }
  178. QString wp = qry2.value(2).toString();
  179. if(wp.compare("WP0")==0)
  180. 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';")
  181. .arg(0)
  182. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  183. .arg(QString::fromUtf8("正常")).arg(dwtype).arg(devid).arg(1);
  184. else if(wp.compare("WP1")==0)
  185. 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';")
  186. .arg(1)
  187. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  188. .arg(QString::fromUtf8("低压")).arg(dwtype).arg(devid).arg(1);
  189. else if(wp.compare("WP2")==0)
  190. 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';")
  191. .arg(2)
  192. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  193. .arg(QString::fromUtf8("高压")).arg(dwtype).arg(devid).arg(1);
  194. else if(wp.compare("WP3")==0)
  195. 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';")
  196. .arg(3)
  197. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  198. .arg(QString::fromUtf8("故障")).arg(dwtype).arg(devid).arg(1);
  199. else if(wp.compare("WP4")==0)
  200. 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';")
  201. .arg(4)
  202. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  203. .arg(QString::fromUtf8("离线")).arg(dwtype).arg(devid).arg(1);
  204. 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';")
  205. .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"))
  207. .arg("").arg(dwtype).arg(devid).arg(2));
  208. 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';")
  209. .arg(qry2.value(4).isNull()?"0":qry2.value(4).toString())
  210. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  211. .arg("").arg(dwtype).arg(devid).arg(3));
  212. 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';")
  213. .arg(qry2.value(5).isNull()?"0":qry2.value(5).toString())
  214. .arg(qry2.value(1).isNull()?"1970-01-01 08:00:00":qry2.value(1).toDateTime().toString("yyyy-MM_dd HH:mm:ss"))
  215. .arg("").arg(dwtype).arg(devid).arg(4));
  216. count += 4;
  217. sync_id = qry2.value(0).toUInt();
  218. if(count>=100){
  219. time_t tmp_time = time((time_t *)NULL);
  220. ytShm->updatetime[DB_THREAD] = tmp_time;
  221. sql.append(";");
  222. mdb.exec(sql);
  223. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  224. mdb.exec(upsql);
  225. count=0;
  226. sql="";
  227. }
  228. }
  229. if(count>0){
  230. time_t tmp_time = time((time_t *)NULL);
  231. ytShm->updatetime[DB_THREAD] = tmp_time;
  232. sql.append(";");
  233. mdb.exec(sql);
  234. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  235. mdb.exec(upsql);
  236. count=0;
  237. sql="";
  238. }
  239. return updated;
  240. }
  241. bool DB_SyncThread::water2InfoSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID)
  242. {
  243. QString qrysql,sql,upsql;
  244. int count=0;
  245. bool found = false;
  246. bool updated = false;
  247. for(int i=0;i<dList.length();i++){
  248. if(dList.at(i).compare(deviceCode)==0)
  249. {
  250. found = true;
  251. break;
  252. }
  253. }
  254. if(!found){
  255. 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));
  256. 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));
  257. 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));
  258. dList.append(deviceCode);
  259. pcList.append(1);
  260. dList.append(deviceCode);
  261. pcList.append(2);
  262. dList.append(deviceCode);
  263. pcList.append(3);
  264. }
  265. qrysql = QString("select id, DeviceStatus, BatteryLevel, SensorLevel, storeTime from %1 where id>%2 and storeTime>'%3-%4-01 00:00:00' and DeviceType=1")
  266. .arg(tbname).arg(sync_id).arg(chkday.year(),4,10,QChar('0')).arg(chkday.month(),2,10,QChar('0'));
  267. QSqlQuery qry2 = mdb.exec(qrysql);
  268. while(qry2.next()){
  269. updated = true;
  270. int sta = qry2.value(1).toInt();
  271. if(count==0){
  272. 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')")
  273. .arg(qry2.value(0).toUInt()).arg(devid).arg(1).arg(qry2.value(1).toString())
  274. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  275. .arg(sta==1?QString::fromUtf8("报警")
  276. :(sta==2?QString::fromUtf8("报警静音")
  277. :(sta==4?QString::fromUtf8("低压")
  278. :(sta==5?QString::fromUtf8("故障")
  279. :(sta==7?QString::fromUtf8("正常")
  280. :"")))));
  281. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  282. .arg(qry2.value(0).toUInt()).arg(devid).arg(2).arg(qry2.value(2).toString())
  283. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  284. .arg("");
  285. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  286. .arg(qry2.value(0).toUInt()).arg(devid).arg(3).arg(qry2.value(3).toString())
  287. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  288. .arg("");
  289. }else{
  290. sql += QString::fromUtf8(", (NULL,%1,'%2','%3','%4','%5','%6')")
  291. .arg(qry2.value(0).toUInt()).arg(devid).arg(1).arg(qry2.value(1).toString())
  292. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  293. .arg(sta==1?QString::fromUtf8("报警")
  294. :(sta==2?QString::fromUtf8("报警静音")
  295. :(sta==4?QString::fromUtf8("低压")
  296. :(sta==5?QString::fromUtf8("故障")
  297. :(sta==7?QString::fromUtf8("正常")
  298. :"")))));
  299. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  300. .arg(qry2.value(0).toUInt()).arg(devid).arg(2).arg(qry2.value(2).toString())
  301. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  302. .arg("");
  303. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6')")
  304. .arg(qry2.value(0).toUInt()).arg(devid).arg(3).arg(qry2.value(3).toString())
  305. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  306. .arg("");
  307. }
  308. 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';")
  309. .arg(sta==7?0:sta)
  310. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  311. .arg(sta==1?QString::fromUtf8("报警")
  312. :(sta==2?QString::fromUtf8("报警静音")
  313. :(sta==4?QString::fromUtf8("低压")
  314. :(sta==5?QString::fromUtf8("故障")
  315. :(sta==7?QString::fromUtf8("正常")
  316. :"")))))
  317. .arg(3).arg(devid).arg(1);
  318. 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';")
  319. .arg(qry2.value(2).toString())
  320. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  321. .arg("").arg(3).arg(devid).arg(2));
  322. 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';")
  323. .arg(qry2.value(3).toString())
  324. .arg(qry2.value(4).isNull()?"1970-01-01 08:00:00":qry2.value(4).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  325. .arg("").arg(3).arg(devid).arg(3));
  326. count += 3;
  327. sync_id = qry2.value(0).toUInt();
  328. if(count>=100){
  329. time_t tmp_time = time((time_t *)NULL);
  330. ytShm->updatetime[DB_THREAD] = tmp_time;
  331. sql.append(";");
  332. mdb.exec(sql);
  333. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  334. mdb.exec(upsql);
  335. count=0;
  336. sql="";
  337. }
  338. }
  339. if(count>0){
  340. time_t tmp_time = time((time_t *)NULL);
  341. ytShm->updatetime[DB_THREAD] = tmp_time;
  342. sql.append(";");
  343. mdb.exec(sql);
  344. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  345. mdb.exec(upsql);
  346. count=0;
  347. sql="";
  348. }
  349. return updated;
  350. }
  351. bool DB_SyncThread::rtuInfoSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID)
  352. {
  353. QString qrysql,sql,upsql="";
  354. int count=0;
  355. bool found = false;
  356. bool updated= false;
  357. QSqlQuery qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_rtu2017 where device_code='%1' and status<>'44'").arg(devid));
  358. if(qry2.next()){
  359. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  360. .arg(qry2.value(0).toInt())
  361. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  362. .arg(devid));
  363. }
  364. qry2.clear();
  365. qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_rtu2017 where device_code='%1' and status='44'").arg(devid));
  366. if(qry2.next()){
  367. mdb.exec(QString("update sp_device_sync set com_count=%1, com_confirm=%2 where device_id='%3'")
  368. .arg(qry2.value(0).toInt())
  369. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  370. .arg(devid));
  371. }
  372. qry2.clear();
  373. found = false;
  374. for(int i=0;i<dList.length();i++){
  375. if(dList.at(i).compare(deviceCode)==0){
  376. found = true;
  377. break;
  378. }
  379. }
  380. if(!found){
  381. 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));
  382. dList.append(deviceCode);
  383. pcList.append(0);
  384. }
  385. 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'")
  386. .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'));
  387. qry2 = mdb.exec(qrysql);
  388. QSqlQuery qry3 = mdb.exec(QString("select iotype,ports,ioname from sp_owner_port where owner_code='%1'").arg(devid));
  389. QStringList nameList;
  390. QList<int> typeList,portList;
  391. while(qry3.next()){
  392. typeList.append(qry3.value(0).toInt());
  393. portList.append(qry3.value(1).toInt());
  394. nameList.append(qry3.value(2).toString());
  395. found = false;
  396. if(qry3.value(0).toInt()==1){
  397. for(int i=0;i<dList.length();i++){
  398. if(dList.at(i).compare(deviceCode)==0){
  399. if(pcList.at(i)==qry3.value(1).toInt()){
  400. found = true;
  401. break;
  402. }
  403. }
  404. }
  405. if(found)
  406. mdb.exec(QString("update sp_owner_status set point_name='%1',dwtype=6 where device_id='%2' and point_code='%3'")
  407. .arg(qry3.value(2).toString()).arg(devid).arg(qry3.value(1).toInt()));
  408. else{
  409. 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()));
  410. dList.append(deviceCode);
  411. pcList.append(qry3.value(1).toInt());
  412. }
  413. }else{
  414. for(int i=0;i<dList.length();i++){
  415. if(dList.at(i).compare(deviceCode)==0){
  416. if(pcList.at(i)==(qry3.value(1).toInt()+64)){
  417. found = true;
  418. break;
  419. }
  420. }
  421. }
  422. if(found)
  423. mdb.exec(QString("update sp_owner_status set point_name='%1',dwtype=6 where device_id='%2' and point_code='%3'")
  424. .arg(qry3.value(2).toString()).arg(devid).arg(qry3.value(1).toInt()+64));
  425. else{
  426. 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));
  427. dList.append(deviceCode);
  428. pcList.append(qry3.value(1).toInt()+64);
  429. }
  430. }
  431. }
  432. qry3.clear();
  433. while(qry2.next()){
  434. updated = true;
  435. if(qry2.value(1).toString().compare("44")==0)
  436. {
  437. if(count==0)
  438. 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')")
  439. .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"))
  440. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  441. else
  442. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  443. .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"))
  444. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  445. 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';")
  446. .arg(0).arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  447. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString()).arg(6).arg(devid).arg(0);
  448. mdb.exec(upsql);
  449. }else{
  450. upsql = QString::fromUtf8("update sp_owner_status set point_data='',content='' where device_id='%1' and point_code='0'").arg(devid);
  451. mdb.exec(upsql);
  452. if(!qry2.value(2).isNull()){
  453. if(qry2.value(2).toString().compare("E3")==0){
  454. if(count==0)
  455. 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')")
  456. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(3).toInt()).arg(qry2.value(1).toString())
  457. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  458. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  459. else
  460. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  461. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(3).toInt()).arg(qry2.value(1).toString())
  462. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  463. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  464. int tmpIdx = qry2.value(3).toInt();
  465. if(tmpIdx>0){
  466. QString pname = "";
  467. for(int Idx=0;Idx<nameList.length();Idx++){
  468. if((typeList.at(Idx)==1)&&(portList.at(Idx)==tmpIdx)){
  469. pname = nameList.at(Idx);
  470. break;
  471. }
  472. }
  473. 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';")
  474. .arg(qry2.value(1).toString())
  475. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  476. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString()).arg(pname)
  477. .arg(6).arg(devid).arg(tmpIdx);
  478. mdb.exec(upsql);
  479. }
  480. }else if(qry2.value(2).toString().compare("E6")==0){
  481. if(count==0)
  482. 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')")
  483. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(3).toInt()+64).arg(qry2.value(8).toString())
  484. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  485. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  486. else
  487. sql += QString(", (NULL,%1,'%2','%3','%4','%5','%6 %7')")
  488. .arg(qry2.value(0).toUInt()).arg(devid).arg(qry2.value(3).toInt()+64).arg(qry2.value(8).toString())
  489. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  490. .arg(qry2.value(5).toString()).arg(qry2.value(6).toString());
  491. int tmpIdx = qry2.value(3).toInt();
  492. if(tmpIdx>0){
  493. QString pname = "";
  494. for(int Idx=0;Idx<nameList.length();Idx++){
  495. if((typeList.at(Idx)==2)&&(portList.at(Idx)==tmpIdx)){
  496. pname = nameList.at(Idx);
  497. break;
  498. }
  499. }
  500. 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';")
  501. .arg(qry2.value(8).toString())
  502. .arg(qry2.value(7).isNull()?"1970-01-01 00:00:00":qry2.value(7).toDateTime().toString("yyyy-MM-dd HH:mm:ss"))
  503. .arg(pname).arg(qry2.value(5).toString())
  504. .arg(qry2.value(6).toString())
  505. .arg(6)
  506. .arg(devid)
  507. .arg(tmpIdx+64);
  508. mdb.exec(upsql);
  509. }
  510. }
  511. }
  512. }
  513. count++;
  514. sync_id = qry2.value(0).toUInt();
  515. if(count>=100){
  516. time_t tmp_time = time((time_t *)NULL);
  517. ytShm->updatetime[DB_THREAD] = tmp_time;
  518. sql.append(";");
  519. mdb.exec(sql);
  520. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  521. // mdb.exec(upsql);
  522. count=0;
  523. sql="";
  524. upsql="";
  525. }
  526. }
  527. if(count>0){
  528. time_t tmp_time = time((time_t *)NULL);
  529. ytShm->updatetime[DB_THREAD] = tmp_time;
  530. sql.append(";");
  531. mdb.exec(sql);
  532. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  533. // mdb.exec(upsql);
  534. count=0;
  535. sql="";
  536. upsql="";
  537. }
  538. return updated;
  539. }
  540. bool DB_SyncThread::efireInfoSync(QString devid, QString deviceCode, uint sync_id, QString tbname, QDate chkday, uint ID)
  541. {
  542. QString upsql1, upsql2, upsql3, upsql4,upsql5,upsql6,sql;
  543. int count=0;
  544. bool updated = false;
  545. QSqlQuery qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_ef2017 where device_code='%1' and data1='EF9'").arg(devid));
  546. if(qry2.next()){
  547. mdb.exec(QString("update sp_device_sync set com_count=%1, com_confirm=%2 where device_id='%3'")
  548. .arg(qry2.value(0).toInt())
  549. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  550. .arg(devid));
  551. }
  552. qry2.clear();
  553. qry2 = mdb.exec(QString("select count(*) as count, sum(clzt) as sum from sp_ef2017 where device_code='%1' and data1<>'EF9'").arg(devid));
  554. if(qry2.next()){
  555. mdb.exec(QString("update sp_device_sync set alm_count=%1, alm_confirm=%2 where device_id='%3'")
  556. .arg(qry2.value(0).toInt())
  557. .arg(qry2.value(0).toInt()>0?qry2.value(1).toInt():0)
  558. .arg(devid));
  559. }
  560. qry2.clear();
  561. qry2 =mdb.exec(QString("select count(*) from sp_owner_status where device_id='%1'").arg(devid));
  562. if(qry2.next()){
  563. if(qry2.value(0).toInt()==0){
  564. 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));
  565. 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));
  566. 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));
  567. 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));
  568. 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));
  569. 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));
  570. 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));
  571. 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));
  572. 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));
  573. 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));
  574. 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));
  575. 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));
  576. 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));
  577. 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));
  578. 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));
  579. 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));
  580. }else if(qry2.value(0).toInt()==6){
  581. mdb.exec(QString::fromUtf8("delete from sp_owner_status where device_id='%1'").arg(devid));
  582. 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));
  583. 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));
  584. 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));
  585. 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));
  586. 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));
  587. 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));
  588. 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));
  589. 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));
  590. 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));
  591. 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));
  592. 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));
  593. 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));
  594. 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));
  595. 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));
  596. 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));
  597. 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));
  598. }
  599. }
  600. qry2.clear();
  601. 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'")
  602. .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')));
  603. while(qry2.next()){
  604. updated = true;
  605. switch(qry2.value(0).toInt()){
  606. case 1:
  607. if(count==0){
  608. 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','')")
  609. .arg(qry2.value(11).toInt()).arg(devid).arg(4).arg(qry2.value(2).toInt())
  610. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  611. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  612. .arg(qry2.value(11).toInt()).arg(devid).arg(1).arg(qry2.value(12).toInt())
  613. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  614. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  615. .arg(qry2.value(11).toInt()).arg(devid).arg(2).arg(qry2.value(13).toInt())
  616. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  617. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  618. .arg(qry2.value(11).toInt()).arg(devid).arg(3).arg(qry2.value(14).toInt())
  619. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  620. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  621. .arg(qry2.value(11).toInt()).arg(devid).arg(65).arg(qry2.value(4).toFloat())
  622. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  623. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  624. .arg(qry2.value(11).toInt()).arg(devid).arg(66).arg(qry2.value(5).toFloat())
  625. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  626. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  627. .arg(qry2.value(11).toInt()).arg(devid).arg(67).arg(qry2.value(6).toFloat())
  628. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  629. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  630. .arg(qry2.value(11).toInt()).arg(devid).arg(68).arg(qry2.value(7).toFloat())
  631. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  632. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  633. .arg(qry2.value(11).toInt()).arg(devid).arg(69).arg(qry2.value(8).toFloat())
  634. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  635. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  636. .arg(qry2.value(11).toInt()).arg(devid).arg(70).arg(qry2.value(9).toFloat())
  637. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  638. }else{
  639. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  640. .arg(qry2.value(11).toInt()).arg(devid).arg(4).arg(qry2.value(2).toInt())
  641. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  642. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  643. .arg(qry2.value(11).toInt()).arg(devid).arg(1).arg(qry2.value(12).toInt())
  644. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  645. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  646. .arg(qry2.value(11).toInt()).arg(devid).arg(2).arg(qry2.value(13).toInt())
  647. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  648. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  649. .arg(qry2.value(11).toInt()).arg(devid).arg(3).arg(qry2.value(14).toInt())
  650. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  651. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  652. .arg(qry2.value(11).toInt()).arg(devid).arg(65).arg(qry2.value(4).toFloat())
  653. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  654. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  655. .arg(qry2.value(11).toInt()).arg(devid).arg(66).arg(qry2.value(5).toFloat())
  656. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  657. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  658. .arg(qry2.value(11).toInt()).arg(devid).arg(67).arg(qry2.value(6).toFloat())
  659. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  660. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  661. .arg(qry2.value(11).toInt()).arg(devid).arg(68).arg(qry2.value(7).toFloat())
  662. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  663. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  664. .arg(qry2.value(11).toInt()).arg(devid).arg(69).arg(qry2.value(8).toFloat())
  665. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  666. sql += QString(", (NULL,%1,'%2','%3','%4','%5','')")
  667. .arg(qry2.value(11).toInt()).arg(devid).arg(70).arg(qry2.value(9).toFloat())
  668. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  669. }
  670. count += 10;
  671. upsql1 = QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2',point_name='供电过压' where device_id='%3' and point_code=1;")
  672. .arg(qry2.value(12).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  673. upsql1 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2', point_name='供电低压' where device_id='%3' and point_code=2; ")
  674. .arg(qry2.value(13).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  675. upsql1 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2', point_name='供电过流' where device_id='%3' and point_code=3; ")
  676. .arg(qry2.value(14).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  677. upsql1 += QString::fromUtf8("update sp_owner_status set point_data=%1, data_time='%2', point_name='漏电报警' where device_id='%3' and point_code=4; ")
  678. .arg(qry2.value(2).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  679. 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;")
  680. .arg(qry2.value(4).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  681. 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;")
  682. .arg(qry2.value(5).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  683. 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;")
  684. .arg(qry2.value(6).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  685. 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; ")
  686. .arg(qry2.value(7).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  687. 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; ")
  688. .arg(qry2.value(8).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  689. 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; ")
  690. .arg(qry2.value(9).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  691. break;
  692. case 2:
  693. if(count==0){
  694. 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','')")
  695. .arg(qry2.value(11).toInt()).arg(devid).arg(5).arg(qry2.value(2).toInt())
  696. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  697. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  698. .arg(qry2.value(11).toInt()).arg(devid).arg(71).arg(qry2.value(3).toFloat())
  699. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  700. }else{
  701. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  702. .arg(qry2.value(11).toInt()).arg(devid).arg(5).arg(qry2.value(2).toInt())
  703. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  704. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  705. .arg(qry2.value(11).toInt()).arg(devid).arg(71).arg(qry2.value(3).toFloat())
  706. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  707. }
  708. count += 2;
  709. 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;")
  710. .arg(qry2.value(2).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  711. 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;")
  712. .arg(qry2.value(3).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  713. break;
  714. case 3:
  715. if(count==0){
  716. 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','')")
  717. .arg(qry2.value(11).toInt()).arg(devid).arg(6).arg(qry2.value(2).toInt())
  718. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  719. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  720. .arg(qry2.value(11).toInt()).arg(devid).arg(72).arg(qry2.value(3).toFloat())
  721. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  722. }else{
  723. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  724. .arg(qry2.value(11).toInt()).arg(devid).arg(6).arg(qry2.value(2).toInt())
  725. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  726. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  727. .arg(qry2.value(11).toInt()).arg(devid).arg(72).arg(qry2.value(3).toFloat())
  728. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  729. }
  730. count += 2;
  731. 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;")
  732. .arg(qry2.value(2).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  733. 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;")
  734. .arg(qry2.value(3).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  735. break;
  736. case 4:
  737. if(count==0){
  738. 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','')")
  739. .arg(qry2.value(11).toInt()).arg(devid).arg(7).arg(qry2.value(2).toInt())
  740. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  741. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  742. .arg(qry2.value(11).toInt()).arg(devid).arg(73).arg(qry2.value(3).toFloat())
  743. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  744. }else{
  745. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  746. .arg(qry2.value(11).toInt()).arg(devid).arg(7).arg(qry2.value(2).toInt())
  747. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  748. sql += QString(",(NULL,%1,'%2','%3','%4','%5','')")
  749. .arg(qry2.value(11).toInt()).arg(devid).arg(73).arg(qry2.value(3).toFloat())
  750. .arg(qry2.value(10).isNull()?"1970-01-01 08:00:00":qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss"));
  751. }
  752. count += 2;
  753. 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;")
  754. .arg(qry2.value(2).toInt()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  755. 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;")
  756. .arg(qry2.value(3).toFloat()).arg(qry2.value(10).toDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(devid);
  757. break;
  758. }
  759. sync_id = qry2.value(6).toUInt();
  760. if(count>=100){
  761. time_t tmp_time = time((time_t *)NULL);
  762. ytShm->updatetime[DB_THREAD] = tmp_time;
  763. sql.append(";");
  764. mdb.exec(sql);
  765. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  766. mdb.exec(upsql1);
  767. mdb.exec(upsql2);
  768. mdb.exec(upsql3);
  769. mdb.exec(upsql4);
  770. mdb.exec(upsql5);
  771. mdb.exec(upsql6);
  772. count=0;
  773. sql="";
  774. upsql1="";
  775. upsql2="";
  776. upsql3="";
  777. upsql4="";
  778. upsql5="";
  779. upsql6="";
  780. }
  781. }
  782. if(count>0){
  783. time_t tmp_time = time((time_t *)NULL);
  784. ytShm->updatetime[DB_THREAD] = tmp_time;
  785. sql.append(";");
  786. mdb.exec(sql);
  787. mdb.exec(QString("update sp_owner_sync set sync_id=%1 where id=%2").arg(sync_id).arg(ID));
  788. mdb.exec(upsql1);
  789. mdb.exec(upsql2);
  790. mdb.exec(upsql3);
  791. mdb.exec(upsql4);
  792. mdb.exec(upsql5);
  793. mdb.exec(upsql6);
  794. count=0;
  795. sql="";
  796. upsql1="";
  797. upsql2="";
  798. upsql3="";
  799. upsql4="";
  800. upsql5="";
  801. upsql6="";
  802. }
  803. return updated;
  804. }
  805. void DB_SyncThread::chkInList(QString devid)
  806. {
  807. QSqlQuery qry;
  808. QString sql;
  809. for(int i=0;i<syncDevList.length();i++){
  810. if(devid.compare(syncDevList.at(i).OwnerCode)==0){
  811. if(syncDevList.at(i).ObjType.compare("YTFC")==0){
  812. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  813. // 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());
  814. QDateTime dataTime = QDateTime::fromTime_t(0);
  815. QString PowerAlarm="off";
  816. QString ManualAct = "off";
  817. QString DevWorking01 = "off";
  818. QString DevWorking02 = "off";
  819. QString DevAlarm01 = "off";
  820. QString DevAlarm02 = "off";
  821. QString FireAutoAct = "off";
  822. sql = QString("select dwtype,point_code,point_data,data_time from sp_owner_status where device_id='%1'").arg(devid);
  823. // system(QString("echo \"[YTFC] %1\" >> /root/test.log").arg(sql).toUtf8().data());
  824. // qDebug()<<sql.toUtf8().data();
  825. qry = mdb.exec(sql);
  826. while(qry.next()){
  827. int code = qry.value(1).toInt();
  828. if((code>0)&&(code<8)){
  829. int value = qry.value(2).toInt();
  830. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  831. dataTime = qry.value(3).toDateTime();
  832. if(code==1){
  833. if(value==0)
  834. PowerAlarm = "on";
  835. }else if(code==2){
  836. if(value==0)
  837. ManualAct = "on";
  838. }else if(code==3){
  839. if(value==0)
  840. DevWorking01 = "on";
  841. }else if(code==4){
  842. if(value==0)
  843. DevWorking02 = "on";
  844. }else if(code==5){
  845. if(value==0)
  846. DevAlarm01 = "on";
  847. }else if(code==6){
  848. if(value==0)
  849. DevAlarm02 = "on";
  850. }else if(code==7){
  851. if(value==0)
  852. FireAutoAct = "on";
  853. }
  854. }
  855. }
  856. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  857. {
  858. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  859. 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\"}}")
  860. .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);
  861. // system(QString("echo \"[YTFC] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  862. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  863. }
  864. }else if(syncDevList.at(i).ObjType.compare("YTCI")==0){
  865. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  866. // 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());
  867. QString Temperature = "0.0";
  868. QString Humidity = "0.0";
  869. QDateTime dataTime = QDateTime::fromTime_t(0);
  870. 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);
  871. // system(QString("echo \"[YTCI]%1\" >> /root/test.log").arg(sql).toUtf8().data());
  872. // qDebug()<<sql.toUtf8().data();
  873. qry = mdb.exec(sql);
  874. int nrow = 0;
  875. while(qry.next()){
  876. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  877. dataTime = qry.value(3).toDateTime();
  878. if(nrow==0)
  879. Temperature = qry.value(2).toString();
  880. else if(nrow==1)
  881. Humidity = qry.value(2).toString();
  882. nrow++;
  883. }
  884. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  885. {
  886. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  887. QString jsonstr = QString("{\"dataCode\":\"DATA_ENVIRONM\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"Temperature\":%3,\"Humidity\":%4}}")
  888. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(Temperature).arg(Humidity);
  889. // system(QString("echo \"[YTCI] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  890. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  891. }
  892. }else if(syncDevList.at(i).ObjType.compare("YTWP")==0){
  893. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  894. // 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());
  895. QString WaterPressure = "0.0";
  896. QDateTime dataTime = QDateTime::fromTime_t(0);
  897. 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);
  898. // system(QString("echo \"[YTWP]%1\" >> /root/test.log").arg(sql).toUtf8().data());
  899. // qDebug()<<sql.toUtf8().data();
  900. qry = mdb.exec(sql);
  901. if(qry.next()){
  902. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  903. dataTime = qry.value(3).toDateTime();
  904. WaterPressure = qry.value(2).toString();
  905. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  906. {
  907. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  908. QString jsonstr = QString("{\"dataCode\":\"DATA_WATERPRE\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"WaterPressure\":%3}}")
  909. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(WaterPressure);
  910. // system(QString("echo \"[YTWP] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  911. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  912. }
  913. }
  914. }else if(syncDevList.at(i).ObjType.compare("YTLL")==0){
  915. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  916. // 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());
  917. QString LiquidLevel = "0.0";
  918. QDateTime dataTime = QDateTime::fromTime_t(0);
  919. 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);
  920. // system(QString("echo \"[YTLL]%1\" >> /root/test.log").arg(sql).toUtf8().data());
  921. // qDebug()<<sql.toUtf8().data();
  922. qry = mdb.exec(sql);
  923. if(qry.next()){
  924. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  925. dataTime = qry.value(3).toDateTime();
  926. LiquidLevel = qry.value(2).toString();
  927. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  928. {
  929. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  930. QString jsonstr = QString("{\"dataCode\":\"DATA_LIQUIDLE\",\"deviceId\":\"%1\",\"postTime\":\"%2\",\"data\":{\"LiquidLevel\":%3}}")
  931. .arg(syncDevList.at(i).ObjCode).arg(dataTime.toString("yyyy-MM-dd HH:mm:ss")).arg(LiquidLevel);
  932. // system(QString("echo \"[YTLL] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  933. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  934. }
  935. }
  936. }else if(syncDevList.at(i).ObjType.compare("YTEF")==0){
  937. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  938. // 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());
  939. QString HighVoltageAlarm ="off";
  940. QString LowVoltageAlarm = "off";
  941. QString HighCurrentAlarm = "off";
  942. QString ElectricityLeakage = "off";
  943. QString HighTemperatureA = "off";
  944. QString HighTemperatureB = "off";
  945. QString HighTemperatureC = "off";
  946. QString VoltageA = "0.0";
  947. QString VoltageB = "0.0";
  948. QString VoltageC = "0.0";
  949. QString CurrentA = "0.0";
  950. QString CurrentB = "0.0";
  951. QString CurrentC = "0.0";
  952. QString TemperatureA = "0.0";
  953. QString TemperatureB = "0.0";
  954. QString TemperatureC = "0.0";
  955. QDateTime dataTime = QDateTime::fromTime_t(0);
  956. sql =QString("select dwtype,point_code,point_data,data_time from sp_owner_status where device_id='%1'").arg(devid);
  957. // system(QString("echo \"[YTEF]%1\" >> /root/test.log").arg(sql).toUtf8().data());
  958. // qDebug()<<sql.toUtf8().data();
  959. qry = mdb.exec(sql);
  960. while(qry.next()){
  961. if(dataTime.toTime_t()<qry.value(3).toDateTime().toTime_t())
  962. dataTime = qry.value(3).toDateTime();
  963. int code = qry.value(1).toInt();
  964. if(code==1){
  965. if(qry.value(2).toInt()==1)
  966. HighVoltageAlarm = "on";
  967. }else if(code==2){
  968. if(qry.value(2).toInt()==1)
  969. LowVoltageAlarm = "on";
  970. }else if(code==3){
  971. if(qry.value(2).toInt()==1)
  972. HighCurrentAlarm = "on";
  973. }else if(code==4){
  974. if(qry.value(2).toInt()==1)
  975. ElectricityLeakage = "on";
  976. }else if(code==5){
  977. if(qry.value(2).toInt()==1)
  978. HighTemperatureA = "on";
  979. }else if(code==6){
  980. if(qry.value(2).toInt()==1)
  981. HighTemperatureB = "on";
  982. }else if(code==7){
  983. if(qry.value(2).toInt()==1)
  984. HighTemperatureC = "on";
  985. }else if(code==65)
  986. VoltageA = qry.value(2).toString();
  987. else if(code==66)
  988. VoltageB = qry.value(2).toString();
  989. else if(code==67)
  990. VoltageC = qry.value(2).toString();
  991. else if(code==68)
  992. CurrentA = qry.value(2).toString();
  993. else if(code==69)
  994. CurrentB = qry.value(2).toString();
  995. else if(code==70)
  996. CurrentC = qry.value(2).toString();
  997. else if(code==71)
  998. TemperatureA = qry.value(2).toString();
  999. else if(code==72)
  1000. TemperatureB = qry.value(2).toString();
  1001. else if(code==73)
  1002. TemperatureC = qry.value(2).toString();
  1003. }
  1004. // if(dataTime.toTime_t()>syncDevList.at(i).RecCur)
  1005. {
  1006. mdb.exec(QString("update sp_yangpu_share set rec_cur=%1 where object_code='%2'").arg(dataTime.toTime_t()).arg(syncDevList.at(i).ObjCode));
  1007. 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}}")
  1008. .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);
  1009. // system(QString("echo \"[YTEF] %1\" >> /root/test.log").arg(jsonstr).toUtf8().data());
  1010. emit SyncData(QUuid::createUuid().toString().replace("{","").replace("}",""), jsonstr);
  1011. }
  1012. }else if(syncDevList.at(i).ObjType.compare("YTVA")==0){
  1013. // system(QString("echo \"%1\" >> /root/test.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).toUtf8().data());
  1014. }
  1015. }
  1016. }
  1017. }
  1018. void DB_SyncThread::time_out()
  1019. {
  1020. QSqlQuery qry,qry2;
  1021. QString qrysql;
  1022. if(!isWorking)
  1023. {
  1024. isWorking = true;
  1025. if(!mdbOpened)
  1026. {
  1027. mdbOpened = mdb.open();
  1028. }
  1029. else
  1030. {
  1031. // if(sqlList.length()>0){
  1032. // while(sqlList.length()>0){
  1033. // system(QString("echo \"%1\" >> /root/test.sql").arg(sqlList.first()).toUtf8().data());
  1034. // mdb.exec(sqlList.first());
  1035. // sqlList.removeFirst();
  1036. // usleep(10000);
  1037. // }
  1038. // }
  1039. syncDevList.clear();
  1040. qry = mdb.exec("select owner_code,dwtype,object_code,start_port,rec_cur from sp_yangpu_share");
  1041. while(qry.next()){
  1042. syncDevList.append(YPSyncDev(qry.value(0).toString(),
  1043. qry.value(1).toString(),
  1044. qry.value(2).toString(),
  1045. qry.value(3).toInt(),
  1046. qry.value(4).toUInt()));
  1047. }
  1048. qry.clear();
  1049. qry2 = mdb.exec("select device_id,point_code from sp_owner_status");
  1050. dList.clear();
  1051. pcList.clear();
  1052. while(qry2.next()){
  1053. dList.append(qry2.value(0).toString());
  1054. pcList.append(qry2.value(1).toInt());
  1055. }
  1056. qry2.clear();
  1057. qry = mdb.exec("select id, owner_code, owner_name, unitinfo, install_time, dwtype, company, rtmp from sp_owner");
  1058. while(qry.next())
  1059. {
  1060. time_t tmp_time = time((time_t *)NULL);
  1061. ytShm->updatetime[DB_THREAD] = tmp_time;
  1062. int dwtype = qry.value(5).toInt();
  1063. uint ID = qry.value(0).toUInt();
  1064. QDate chkday = QDate::currentDate().addDays(-7);
  1065. bool need_sync = false;
  1066. qry2 =mdb.exec(QString("select count(*) from sp_device_sync where device_id='%1'").arg(qry.value(1).toString()));
  1067. if(qry2.next()){
  1068. if(qry2.value(0).toInt()==0){
  1069. 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()));
  1070. }
  1071. }
  1072. qry2.clear();
  1073. qrysql = QString("select count(*),table_name,sync_id from sp_owner_sync where id=%1").arg(ID);
  1074. qry2 = mdb.exec(qrysql);
  1075. if(qry2.next()){
  1076. QString deviceCode = qry.value(1).toString();
  1077. QString tbname = QString("sp_%1%2").arg(qry.value(5).toInt()==3?"y":"d").arg(deviceCode);
  1078. uint sync_id = 0;
  1079. if(qry2.value(0).toInt()==0){
  1080. 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) ")
  1081. .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())
  1082. .arg(qry.value(5).toInt()).arg(qry.value(6).toString()).arg(qry.value(7).toString()).arg(tbname).arg(sync_id));
  1083. }else{
  1084. sync_id = qry2.value(2).toUInt();
  1085. }
  1086. qry2.clear();
  1087. switch(dwtype){
  1088. case 1://userinfo
  1089. need_sync = userInfoSync(qry.value(1).toString(),deviceCode,sync_id, tbname, chkday,ID);
  1090. break;
  1091. case 2://water
  1092. case 5:
  1093. need_sync = waterInfoSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID,dwtype);
  1094. break;
  1095. case 3:
  1096. need_sync = water2InfoSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID);
  1097. break;
  1098. case 6:
  1099. need_sync = rtuInfoSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID);
  1100. break;
  1101. case 7:
  1102. need_sync = efireInfoSync(qry.value(1).toString(),deviceCode,sync_id,tbname,chkday,ID);
  1103. break;
  1104. }
  1105. qry2.clear();
  1106. if(need_sync)
  1107. chkInList(qry.value(1).toString());
  1108. }
  1109. usleep(5000);
  1110. }
  1111. qry.clear();
  1112. 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, sp_owner.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) and a.company<>'' group by a.company, a.dwtype");
  1113. while(qry.next()){
  1114. QString sql2="";
  1115. qry2 = mdb.exec(QString("select count(*) from sp_company_sync where company_code='%1'").arg(qry.value(0).toString()));
  1116. if(qry2.next()){
  1117. if(qry2.value(0).toInt()==0){
  1118. 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) 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);")
  1119. .arg(qry.value(0).toString());
  1120. }
  1121. }
  1122. qry2.clear();
  1123. if(qry.value(1).toInt()==1)
  1124. 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'")
  1125. .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());
  1126. else if(qry.value(1).toInt()==2)
  1127. 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'")
  1128. .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());
  1129. else if(qry.value(1).toInt()==5)
  1130. 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'")
  1131. .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());
  1132. else if(qry.value(1).toInt()==6)
  1133. 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'")
  1134. .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());
  1135. else if(qry.value(1).toInt()==7)
  1136. 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'")
  1137. .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());
  1138. mdb.exec(sql2);
  1139. qry2.clear();
  1140. usleep(5000);
  1141. }
  1142. qry.clear();
  1143. QDate d_day = QDate::currentDate().addDays(-7);
  1144. 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'));
  1145. mdb.exec(delsql);
  1146. 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'");
  1147. while(qry.next()){
  1148. qry2 = mdb.exec(QString("select clzt from sp_hj2017 where device_code=%1 and time='%2'")
  1149. .arg(qry.value(1).toString()).arg(qry.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss")));
  1150. if((qry2.next())&&(qry2.value(0).toInt()==1))
  1151. mdb.exec(QString("update sp_owner_status set point_data='0' where id=%1").arg(qry.value(0).toInt()));
  1152. qry.clear();
  1153. usleep(5000);
  1154. }
  1155. qry.clear();
  1156. 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'");
  1157. while(qry.next()){
  1158. qry2 = mdb.exec(QString("select clzt from sp_sj2017 where device_code=%1 and time='%2'")
  1159. .arg(qry.value(1).toString()).arg(qry.value(2).toDateTime().toString("yyyy-MM-dd HH:mm:ss")));
  1160. if((qry2.next())&&(qry2.value(0).toInt()==1))
  1161. 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()));
  1162. else
  1163. 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()));
  1164. usleep(5000);
  1165. }
  1166. mdb.close();
  1167. mdbOpened = false;
  1168. }
  1169. isWorking = false;
  1170. }
  1171. }
  1172. void DB_SyncThread::run()
  1173. {
  1174. while(1)
  1175. {
  1176. time_t tmp_time = time((time_t *)NULL);
  1177. ytShm->updatetime[DB_THREAD] = tmp_time;
  1178. time_out();
  1179. sleep(5);
  1180. }
  1181. }