InteractiveCore.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "InteractiveCore.h"
  2. #include "InteractiveWork.h"
  3. InteractiveCore::InteractiveCore(QObject *parent)
  4. : QObject(parent)
  5. {
  6. m_timerDataChcheRefresh = startTimer(TIMER_DATA_CHCHE_REFRESH);
  7. connect(SINGLETON_CREATE(InteractiveWork)(), &InteractiveWork::signal_completed,
  8. this, &InteractiveCore::slot_completed);
  9. connect(SINGLETON_CREATE(InteractiveWork)(), &InteractiveWork::signal_failstart,
  10. this, &InteractiveCore::slot_failstart);
  11. SINGLETON_CREATE(InteractiveWork)()->start();
  12. }
  13. void InteractiveCore::appendTask(InteractiveTask::TaskType type, QVariant request, QJSValue callback)
  14. {
  15. InteractiveTask* task = new InteractiveTask();
  16. task->type = type;
  17. task->request = request;
  18. task->callback = callback;
  19. SINGLETON_CREATE(InteractiveWork)()->appendTask(task);
  20. }
  21. void InteractiveCore::slot_completed(InteractiveTask *task)
  22. {
  23. if (qobject_cast<InteractiveTask*>(task))
  24. {
  25. if (task->callback.isCallable())
  26. {
  27. QJSValueList args;
  28. // 如果是string类型
  29. if (task->respond.typeId() == QMetaType::QString)
  30. {
  31. args << task->respond.toString();
  32. }
  33. // 如果是bytearray类型
  34. else if(task->respond.typeId() == QMetaType::QByteArray)
  35. {
  36. args << QString(task->respond.toByteArray());
  37. }
  38. // 如果是int类型
  39. else if (task->respond.typeId() == QMetaType::Int)
  40. {
  41. args << task->respond.toInt();
  42. }
  43. // 如果是其他类型
  44. else
  45. {
  46. // ...
  47. }
  48. task->callback.call(args);
  49. }
  50. }
  51. delete task;
  52. }
  53. void InteractiveCore::slot_failstart(InteractiveTask *task)
  54. {
  55. delete task;
  56. }
  57. void InteractiveCore::timerEvent(QTimerEvent *event)
  58. {
  59. // 定时刷新服务缓存
  60. if (event->timerId() == m_timerDataChcheRefresh)
  61. {
  62. // 获取异常类型字典值
  63. appendTask(InteractiveTask::TypeHttpGet_exception_type, QVariant(), QJSValue());
  64. // 获取严重等级字典值
  65. appendTask(InteractiveTask::TypeHttpGet_severity_level, QVariant(), QJSValue());
  66. // 获取物资柜id
  67. appendTask(InteractiveTask::TypeHttpGet_selectIsMaterialsCabinetByCode, QVariant(), QJSValue());
  68. // 查询物资信息All
  69. appendTask(InteractiveTask::TypeHttpGet_getIsMaterialsPage, QVariant(), QJSValue());
  70. }
  71. }
  72. // void InteractiveCore::slot_tid_update_Ex(quint16 count, QList<QString> tidList, const QVariant &user)
  73. // {
  74. // QString strType = user.toString();
  75. // if (strType == "物资取还" || strType == "物资检查" || strType == "手动更换" || strType == "异常处理")
  76. // {
  77. // }
  78. // else if (strType == "自动更换")
  79. // {
  80. // }
  81. // }