customerAffairLogic.cc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include "restclient-cpp/restclient.h"
  4. #include "service/BusinessConfig.h"
  5. #include "base/http_client.h"
  6. #include "base/strings.hpp"
  7. #include <manager/LanguageManager.h>
  8. /*
  9. *此文件由GUI工具生成
  10. *文件功能:用于处理用户的逻辑相应代码
  11. *功能说明:
  12. *========================onButtonClick_XXXX
  13. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  14. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  15. *========================onSlideWindowItemClick_XXXX(int index)
  16. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  17. 如slideWindow1;index 代表按下图标的偏移值
  18. *========================onSeekBarChange_XXXX(int progress)
  19. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  20. 如SeekBar1;progress 代表当前的进度值
  21. *========================ogetListItemCount_XXXX()
  22. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  23. 如List1;返回值为当前列表的总条数
  24. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  25. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  26. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  27. *========================常用接口===============
  28. *LOGD(...) 打印调试信息的接口
  29. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  30. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  31. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  32. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  33. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  34. *
  35. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  36. */
  37. static int executeInt = 0;
  38. std::string _affairTransmitCustomerId = "";
  39. std::string _affairTransmitDeviceId = "";
  40. Json::Value customerAffairs;
  41. void getCustomerAffair() {
  42. std::string url = getHttpGateway() + "/deviceRoom/get_affairs_of_late/" + _affairTransmitCustomerId;
  43. LOGD("请求用户事务列表. url = %s", url.c_str());
  44. //发起HTTP GET请求
  45. RestClient::Response r = RestClient::get(url);
  46. if (r.code != 200) {
  47. LOGD("请求用户事务列表-> 错误代码: %d", r.code);
  48. return;
  49. }
  50. LOGD("获得用户事务列表. result = %s", r.body.c_str());
  51. //解析json
  52. Json::Reader reader;
  53. Json::Value root;
  54. if(reader.parse(r.body, root, false)) {
  55. customerAffairs = root;
  56. mAffairListViewPtr->refreshListView();
  57. }
  58. }
  59. void doCutsomerAffair(int execute) {
  60. Json::Value affair = customerAffairs[executeInt];
  61. std::string url = getHttpGateway() + "/deviceBed/execute_affair/" + affair["id"].asString() + "/" + _affairTransmitDeviceId + "/" + to_string(execute);
  62. LOGD("处理用户事务. url = %s", url.c_str());
  63. //发起HTTP GET请求
  64. RestClient::Response r = RestClient::get(url);
  65. if (r.code != 200) {
  66. LOGD("处理用户事务-> 错误代码: %d", r.code);
  67. return;
  68. }
  69. getCustomerAffair();
  70. }
  71. /**
  72. * 注册定时器
  73. * 填充数组用于注册定时器
  74. * 注意:id不能重复
  75. */
  76. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  77. //{0, 6000}, //定时器id=0, 时间间隔6秒
  78. //{1, 1000},
  79. };
  80. /**
  81. * 当界面构造时触发
  82. */
  83. static void onUI_init(){
  84. //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123");
  85. }
  86. /**
  87. * 当切换到该界面时触发
  88. */
  89. static void onUI_intent(const Intent *intentPtr) {
  90. if (intentPtr != NULL) {
  91. //TODO
  92. // 键值解析
  93. _affairTransmitCustomerId = intentPtr->getExtra(transmitCustomerId);
  94. _affairTransmitDeviceId = intentPtr->getExtra(transmitDeviceId);
  95. customerAffairs = Json::nullValue;
  96. getCustomerAffair();
  97. }
  98. }
  99. /*
  100. * 当界面显示时触发
  101. */
  102. static void onUI_show() {
  103. EASYUICONTEXT->hideStatusBar();
  104. EASYUICONTEXT->hideNaviBar();
  105. }
  106. /*
  107. * 当界面隐藏时触发
  108. */
  109. static void onUI_hide() {
  110. }
  111. /*
  112. * 当界面完全退出时触发
  113. */
  114. static void onUI_quit() {
  115. }
  116. /**
  117. * 串口数据回调接口
  118. */
  119. static void onProtocolDataUpdate(const SProtocolData &data) {
  120. }
  121. /**
  122. * 定时器触发函数
  123. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  124. * 参数: id
  125. * 当前所触发定时器的id,与注册时的id相同
  126. * 返回值: true
  127. * 继续运行当前定时器
  128. * false
  129. * 停止运行当前定时器
  130. */
  131. static bool onUI_Timer(int id){
  132. switch (id) {
  133. default:
  134. break;
  135. }
  136. return true;
  137. }
  138. /**
  139. * 有新的触摸事件时触发
  140. * 参数:ev
  141. * 新的触摸事件
  142. * 返回值:true
  143. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  144. * false
  145. * 触摸事件将继续传递到控件上
  146. */
  147. static bool oncustomerAffairActivityTouchEvent(const MotionEvent &ev) {
  148. switch (ev.mActionStatus) {
  149. case MotionEvent::E_ACTION_DOWN://触摸按下
  150. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  151. break;
  152. case MotionEvent::E_ACTION_MOVE://触摸滑动
  153. break;
  154. case MotionEvent::E_ACTION_UP: //触摸抬起
  155. break;
  156. default:
  157. break;
  158. }
  159. return false;
  160. }
  161. static bool onButtonClick_sys_back(ZKButton *pButton) {
  162. LOGD(" ButtonClick sys_back !!!\n");
  163. return false;
  164. }
  165. static int getListItemCount_AffairListView(const ZKListView *pListView) {
  166. //LOGD("getListItemCount_AffairListView !\n");
  167. return customerAffairs.size();
  168. }
  169. static void obtainListItemData_AffairListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  170. //LOGD(" obtainListItemData_ AffairListView !!!\n");
  171. ZKListView::ZKListSubItem* affairContent = pListItem->findSubItemByID(ID_CUSTOMERAFFAIR_CustomerContentSubItem);
  172. ZKListView::ZKListSubItem* planTime = pListItem->findSubItemByID(ID_CUSTOMERAFFAIR_PlanTimeSubItem);
  173. ZKListView::ZKListSubItem* affairStatus = pListItem->findSubItemByID(ID_CUSTOMERAFFAIR_CustomerStatusSubItem);
  174. ZKListView::ZKListSubItem* handle = pListItem->findSubItemByID(ID_CUSTOMERAFFAIR_CustomerAffairHandleSubItem);
  175. affairContent->setText(customerAffairs[index]["content"].asString());
  176. string time = customerAffairs[index]["affair_plan_time"].asString();
  177. std::string _planTime = TimeHelper::getTimeStrOnTimeDifference(time, 8, "%d-%02d-%02d %02d:%02d:%02d");
  178. planTime->setText(_planTime);
  179. string _status = customerAffairs[index]["affair_state"].asString();
  180. if (_status == "") {
  181. affairStatus->setText(LANGUAGEMANAGER->getValue("Unexecuted"));
  182. affairStatus->setTextColor(defaultYellow);
  183. }
  184. else if (_status == "1") {
  185. affairStatus->setText(LANGUAGEMANAGER->getValue("Executed"));
  186. affairStatus->setTextColor(defaultGreen);
  187. }
  188. else if (_status == "0") {
  189. affairStatus->setText(LANGUAGEMANAGER->getValue("Canceled"));
  190. affairStatus->setTextColor(defaultRed);
  191. }
  192. string doTime = customerAffairs[index]["affair_do_time"].asString();
  193. if (doTime != "") {
  194. std::string _doTime = TimeHelper::getTimeStrOnTimeDifference(doTime, 8, "%d-%02d-%02d %02d:%02d:%02d");
  195. handle->setText(_doTime);
  196. handle->setTextColor(BlackColor);
  197. handle->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "");
  198. handle->setButtonStatusPic(ZK_CONTROL_STATUS_PRESSED, "");
  199. }
  200. else {
  201. handle->setText(LANGUAGEMANAGER->getValue("Execute"));
  202. handle->setTextColor(whiteColour);
  203. handle->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "button/elliptic_bule_125x33.png");
  204. handle->setButtonStatusPic(ZK_CONTROL_STATUS_PRESSED, "button/elliptic_grey_125x33.png");
  205. }
  206. }
  207. static void onListItemClick_AffairListView(ZKListView *pListView, int index, int id) {
  208. //LOGD(" onListItemClick_ AffairListView !!!\n");
  209. executeInt = index;
  210. Intent* intent = new Intent();
  211. intent->putExtra(functionWindows, "customerAffair");
  212. intent->putExtra(functionText, customerAffairs[executeInt]["content"].asString());
  213. EASYUICONTEXT->openActivity("functionActivity", intent);
  214. }