subreportthread.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "subreportthread.h"
  2. SubReportThread::SubReportThread(qintptr socketDescriptor, QObject *parent)
  3. : QThread(parent)
  4. {
  5. this->SocketDescriptor = socketDescriptor;
  6. // logThread = new LogThread(this);
  7. // logThread->start();
  8. }
  9. void SubReportThread::run()
  10. {
  11. QTcpSocket *so = new QTcpSocket;
  12. if(!so->setSocketDescriptor(this->SocketDescriptor))
  13. {
  14. so->abort();
  15. return;
  16. }
  17. if(so->waitForReadyRead()){
  18. QByteArray Cmd = so->readAll();
  19. QStringList Dat = QString(Cmd).split("\r\n");
  20. QByteArray cmd;
  21. bool found = false;
  22. for(int i=0;i<Dat.length();i++){
  23. if(Dat.at(i).indexOf("{")>=0)
  24. found = true;
  25. if(found)
  26. cmd.append(Dat.at(i).trimmed().toUtf8());
  27. }
  28. QJsonParseError json_error;
  29. QJsonDocument jsonDoc(QJsonDocument::fromJson(cmd,&json_error));
  30. if(json_error.error==QJsonParseError::NoError){
  31. QJsonObject root = jsonDoc.object();
  32. quint16 type = 0;
  33. QString deviceId = "", companyCode="", evt_name="", evt="",alarm_time="",artificial_id="",reason="",handler="",mobile="";
  34. quint64 insertId = 0;
  35. quint16 area_status = 0;
  36. bool flag = false;
  37. if((!root.value("SubType").isUndefined())&&(!root.value("SubType").isNull())){
  38. if(root.value("SubType").isString())
  39. type = root.value("SubType").toString().toInt()&0xffff;
  40. else
  41. type = root.value("SubType").toInt()&0xffff;
  42. }
  43. if((!root.value("DeviceId").isUndefined())&&(!root.value("DeviceId").isNull())){
  44. if(root.value("DeviceId").isString())
  45. deviceId = root.value("DeviceId").toString();
  46. else
  47. deviceId = QString("%1").arg(root.value("DeviceId").toInt());
  48. }
  49. if((!root.value("InsertId").isUndefined())&&(!root.value("InsertId").isNull())){
  50. if(root.value("InsertId").isString())
  51. insertId = root.value("InsertId").toString().toULongLong()&0xffffffffffffffff;
  52. else
  53. insertId = root.value("InsertId").toVariant().toULongLong()&0xffffffffffffffff;
  54. }
  55. if((!root.value("Confirmed").isUndefined())&&(!root.value("Confirm").isNull())){
  56. if(root.value("Confirmed").isString())
  57. flag = QString::compare(root.value("Confirmed").toString(),"1")==0?true:false;
  58. else
  59. flag = root.value("Confirmed").toBool();
  60. }if((!root.value("CompanyCode").isUndefined())&&(!root.value("CompanyCode").isNull())){
  61. if(root.value("DeviceId").isString())
  62. companyCode = root.value("CompanyCode").toString();
  63. else
  64. companyCode = QString("%1").arg(root.value("CompanyCode").toInt());
  65. }
  66. if((!root.value("evt_name").isUndefined())&&(!root.value("etv_name").isNull())){
  67. if(root.value("evt_name").isString())
  68. evt_name = root.value("evt_name").toString();
  69. }
  70. if((!root.value("evt").isUndefined())&&(!root.value("evt").isNull())){
  71. if(root.value("evt").isString())
  72. evt = root.value("evt").toString();
  73. }
  74. if((!root.value("alarm_time").isUndefined())&&(!root.value("alarm_time").isNull())){
  75. if(root.value("alarm_time").isString())
  76. alarm_time = root.value("alarm_time").toString();
  77. }
  78. if((!root.value("artificial_id").isUndefined())&&(!root.value("artificial_id").isNull())){
  79. if(root.value("artificial_id").isString())
  80. artificial_id = root.value("artificial_id").toString();
  81. }
  82. if((!root.value("reason").isUndefined())&&(!root.value("reason").isNull())){
  83. if(root.value("reason").isString())
  84. reason = root.value("reason").toString();
  85. }
  86. if((!root.value("handler").isUndefined())&&(!root.value("handler").isNull())){
  87. if(root.value("handler").isString())
  88. handler = root.value("handler").toString();
  89. }
  90. if((!root.value("mobile").isUndefined())&&(!root.value("mobile").isNull())){
  91. if(root.value("mobile").isString())
  92. mobile = root.value("mobile").toString();
  93. }
  94. if((!root.value("area_status").isUndefined())&&(!root.value("area_status").isNull())){
  95. if(root.value("area_status").isString())
  96. area_status = root.value("area_status").toString().toInt()&0xffff;
  97. else
  98. area_status = root.value("area_status").toInt()&0xffff;
  99. }
  100. // if(flag==0)
  101. // flag = 2;
  102. // emit appendLog(QString("ceshihuojing456[%1, %2, %3, %4, %5, %6, %7, %8]").arg(type).arg(deviceId).arg(insertId).arg(flag).arg(companyCode).arg(evt_name).arg(evt).arg(alarm_time));
  103. if((type>0)&&(area_status>0)&&(artificial_id.length()>0)){
  104. // ret = true;
  105. emit getSubReport2(type, artificial_id, area_status, reason, handler, mobile);
  106. }
  107. if((type>0)&&(insertId>0)&&(companyCode.length()>0)){
  108. // ret = true;
  109. emit getSubReport1(type,deviceId,insertId,flag,companyCode,evt_name,evt,alarm_time);
  110. }
  111. if((type>0)&&(insertId>0))
  112. emit getSubReport(type,deviceId,insertId,flag);
  113. so->write("HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-type: text/plain\r\n\r\n");
  114. so->waitForBytesWritten();
  115. // so->close();
  116. }
  117. }
  118. so->close();
  119. }