RunHttpGet_getCabinetHomePage.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "RunHttpGet_getCabinetHomePage.h"
  2. #include "../user/config.h"
  3. extern config *pconfig;
  4. RunHttpGet_getCabinetHomePage::RunHttpGet_getCabinetHomePage(InteractiveTask *task, QMutex *mutex)
  5. : RunAbstract(task, mutex)
  6. {
  7. }
  8. void RunHttpGet_getCabinetHomePage::run()
  9. {
  10. QByteArray outData = InteractiveHttp::http_get_getCabinetHomePage();
  11. InteractiveData *pSingletonData = SINGLETON_CREATE(InteractiveData)();
  12. // 进行数据写操作
  13. QWriteLocker locker(&pSingletonData->m_dataCacheLock);
  14. // 如果数据发生改变,缓存信息
  15. if (!outData.isEmpty())
  16. {
  17. pconfig->changeNumber = 0;
  18. pconfig->checkNumber = 0;
  19. pconfig->rarNumber = 0;
  20. pconfig->bottomTypeName.clear();
  21. pconfig->bottomTypeIcon.clear();
  22. pconfig->bottomTypeAll.clear();
  23. pconfig->bottomTypeBorrowable.clear();
  24. QJsonParseError error;
  25. QJsonDocument jsonDoc = QJsonDocument::fromJson(outData, &error);
  26. if (error.error == QJsonParseError::NoError)
  27. {
  28. if(!(jsonDoc.isNull() || jsonDoc.isEmpty()))
  29. {
  30. QJsonObject jsonObjRoot = jsonDoc.object();
  31. if(jsonObjRoot.contains("code"))
  32. {
  33. if (jsonObjRoot.value("code").toInt() == 200)
  34. {
  35. QJsonObject jsonObjData = jsonObjRoot.value("data").toObject();
  36. QString changeNumber = QString::number(jsonObjData.value("changeNumber").toInt());
  37. QString checkNumber = QString::number(jsonObjData.value("checkNumber").toInt());
  38. QString rarNumber = QString::number(jsonObjData.value("rarNumber").toInt());
  39. pconfig->changeNumber = changeNumber;
  40. pconfig->checkNumber = checkNumber;
  41. pconfig->rarNumber = rarNumber;
  42. QJsonArray jsonArrList = jsonObjData.value("list").toArray();
  43. for (int i = 0; i < jsonArrList.size(); ++i)
  44. {
  45. QJsonObject jsonObjList = jsonArrList.at(i).toObject();
  46. QString materialsTypeId = jsonObjList.value("materialsTypeId").toString();
  47. QString materialsTypeName = jsonObjList.value("materialsTypeName").toString();
  48. QString materialsTypeIcon = jsonObjList.value("materialsTypeIcon").toString();
  49. QString allNumber = QString::number(jsonObjList.value("allNumber").toInt());
  50. QString borrowableNumber = QString::number(jsonObjList.value("borrowableNumber").toInt());
  51. pconfig->bottomTypeName.insert(materialsTypeId, materialsTypeName);
  52. pconfig->bottomTypeIcon.insert(materialsTypeId, materialsTypeIcon);
  53. pconfig->bottomTypeAll.insert(materialsTypeId, allNumber);
  54. pconfig->bottomTypeBorrowable.insert(materialsTypeId, borrowableNumber);
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }