interactionLogic.cc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. Json::Value eventList; // 按键事件的缓存
  38. Json::Value interactionList; // 交互记录
  39. std::string _interactionTransmitCustomerId = "";
  40. std::string _interactionTransmitDeviceId = "";
  41. #define EVENT_TIME_HANDLE 8 // 事件定时器
  42. void getEvent() {
  43. std::string url = getHttpGateway() + "/deviceBed/get_event_list_by_part_id/" + StoragePreferences::getString(STORE_PARTID, "");
  44. LOGD("请求事件列表. url = %s", url.c_str());
  45. //发起HTTP POST请求
  46. RestClient::Response r = RestClient::get(url);
  47. if (r.code != 200) {
  48. LOGD("请求事件列表-> 错误代码: %d", r.code);
  49. return;
  50. }
  51. LOGD("获得事件列表. result = %s", r.body.c_str());
  52. //解析json
  53. Json::Reader reader;
  54. Json::Value root;
  55. if(reader.parse(r.body, root, false)) {
  56. eventList = root;
  57. int size = eventList.size();
  58. LOGD("eventList.size() = %d", size);
  59. // 按键事件
  60. for (int i = 0; i < size; i++) {
  61. eventList[i]["invalid"] = false;
  62. }
  63. // }
  64. mEventListViewPtr->refreshListView();
  65. }
  66. }
  67. void getInteraction() {
  68. std::string url = getHttpGateway() + "/deviceBed/getInteractionVOByCustomerId?page_no=" + to_string(1) + "&page_size=" + to_string(30) + "&customer_id=" + _interactionTransmitCustomerId;
  69. std::string content_type = std::string("application/json");
  70. LOGD("请求交互记录列表. url = %s", url.c_str());
  71. //发起HTTP POST请求
  72. RestClient::Response r = RestClient::post(url, content_type, "");
  73. if (r.code != 200) {
  74. LOGD("请求交互记录列表-> 错误代码: %d", r.code);
  75. return;
  76. }
  77. LOGD("获得交互记录列表. result = %s", r.body.c_str());
  78. //解析json
  79. Json::Reader reader;
  80. Json::Value root;
  81. if(reader.parse(r.body, root, false)) {
  82. interactionList = root["data"];
  83. mInteractionListViewPtr->refreshListView();
  84. }
  85. }
  86. /**
  87. * 注册定时器
  88. * 填充数组用于注册定时器
  89. * 注意:id不能重复
  90. */
  91. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  92. //{0, 6000}, //定时器id=0, 时间间隔6秒
  93. //{1, 1000},
  94. };
  95. /**
  96. * 当界面构造时触发
  97. */
  98. static void onUI_init(){
  99. //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123");
  100. mInteractionBackButtonPtr->setAlpha(200);
  101. getEvent();
  102. }
  103. /**
  104. * 当切换到该界面时触发
  105. */
  106. static void onUI_intent(const Intent *intentPtr) {
  107. if (intentPtr != NULL) {
  108. //TODO
  109. // 键值解析
  110. _interactionTransmitCustomerId = intentPtr->getExtra(transmitCustomerId);
  111. _interactionTransmitDeviceId = intentPtr->getExtra(transmitDeviceId);
  112. interactionList = Json::nullValue;
  113. getInteraction();
  114. }
  115. }
  116. /*
  117. * 当界面显示时触发
  118. */
  119. static void onUI_show() {
  120. EASYUICONTEXT->hideStatusBar();
  121. EASYUICONTEXT->hideNaviBar();
  122. }
  123. /*
  124. * 当界面隐藏时触发
  125. */
  126. static void onUI_hide() {
  127. }
  128. /*
  129. * 当界面完全退出时触发
  130. */
  131. static void onUI_quit() {
  132. }
  133. /**
  134. * 串口数据回调接口
  135. */
  136. static void onProtocolDataUpdate(const SProtocolData &data) {
  137. }
  138. /**
  139. * 定时器触发函数
  140. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  141. * 参数: id
  142. * 当前所触发定时器的id,与注册时的id相同
  143. * 返回值: true
  144. * 继续运行当前定时器
  145. * false
  146. * 停止运行当前定时器
  147. */
  148. static bool onUI_Timer(int id){
  149. switch (id) {
  150. case EVENT_TIME_HANDLE:
  151. for (int i = 0; i < eventList.size(); i++) {
  152. eventList[i]["invalid"] = false;
  153. }
  154. mEventListViewPtr->refreshListView();
  155. return false;
  156. break;
  157. default:
  158. break;
  159. }
  160. return true;
  161. }
  162. /**
  163. * 有新的触摸事件时触发
  164. * 参数:ev
  165. * 新的触摸事件
  166. * 返回值:true
  167. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  168. * false
  169. * 触摸事件将继续传递到控件上
  170. */
  171. static bool oninteractionActivityTouchEvent(const MotionEvent &ev) {
  172. switch (ev.mActionStatus) {
  173. case MotionEvent::E_ACTION_DOWN://触摸按下
  174. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  175. break;
  176. case MotionEvent::E_ACTION_MOVE://触摸滑动
  177. break;
  178. case MotionEvent::E_ACTION_UP: //触摸抬起
  179. break;
  180. default:
  181. break;
  182. }
  183. return false;
  184. }
  185. static bool onButtonClick_InteractionBackButton(ZKButton *pButton) {
  186. LOGD(" ButtonClick InteractionBackButton !!!\n");
  187. EASYUICONTEXT->closeActivity("interactionActivity");
  188. return false;
  189. }
  190. static bool onButtonClick_RecoverButton(ZKButton *pButton) {
  191. LOGD(" ButtonClick RecoverButton !!!\n");
  192. EASYUICONTEXT->closeActivity("interactionActivity");
  193. return false;
  194. }
  195. static int getListItemCount_EventListView(const ZKListView *pListView) {
  196. //LOGD("getListItemCount_EventListView !\n");
  197. return eventList.size();
  198. }
  199. static void obtainListItemData_EventListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  200. //LOGD(" obtainListItemData_ EventListView !!!\n");
  201. pListItem->setText(eventList[index]["name"].asString());
  202. pListItem->setInvalid(eventList[index]["invalid"].asBool());
  203. }
  204. static void onListItemClick_EventListView(ZKListView *pListView, int index, int id) {
  205. //LOGD(" onListItemClick_ EventListView !!!\n");
  206. LOGD("选中的按键事件, name = %s", eventList[index]["name"].asString().c_str());
  207. int size = eventList.size();
  208. for (int i = 0; i < size; i++) {
  209. eventList[i]["invalid"] = true;
  210. }
  211. pListView->refreshListView();
  212. mActivityPtr->registerUserTimer(EVENT_TIME_HANDLE, 3000);
  213. // 发送tcp, tcp_type = EVENT, tcp_action = CALL, data = {"id" : eventList[index]["id"]}
  214. TcpModel tcpModel;
  215. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  216. tcpModel.type = TcpType::EVENT;
  217. tcpModel.action = EventAction::KEY_CLICK;
  218. tcpModel.from_id = std::stoi(_interactionTransmitDeviceId);
  219. Json::Value json;
  220. json["id"] = eventList[index]["id"];
  221. tcpModel.json = json;
  222. sendTcpModel(tcpModel);
  223. Intent* intent = new Intent();
  224. intent->putExtra(functionWindows, "eventCall");
  225. intent->putExtra(functionText, eventList[index]["name"].asString());
  226. EASYUICONTEXT->openActivity("functionActivity", intent);
  227. EASYUICONTEXT->closeActivity("interactionActivity");
  228. }
  229. static void onCheckedChanged_InteractionTypeRadioGroup(ZKRadioGroup* pRadioGroup, int checkedID) {
  230. LOGD(" RadioGroup InteractionTypeRadioGroup checked %d", checkedID);
  231. }
  232. static int getListItemCount_InteractionListView(const ZKListView *pListView) {
  233. //LOGD("getListItemCount_InteractionListView !\n");
  234. return interactionList.size();
  235. }
  236. static void obtainListItemData_InteractionListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  237. //LOGD(" obtainListItemData_ InteractionListView !!!\n");
  238. ZKListView::ZKListSubItem* interactionTime = pListItem->findSubItemByID(ID_INTERACTION_TimeSubItem);
  239. ZKListView::ZKListSubItem* interactionStatus = pListItem->findSubItemByID(ID_INTERACTION_StatusSubItem);
  240. string time = interactionList[index]["create_date"].asString();
  241. std::string pDate = TimeHelper::getTimeStrOnTimeDifference(time, getTimeDifference(), "%d-%02d-%02d %02d:%02d:%02d");
  242. interactionTime->setText(pDate);
  243. string actionType = interactionList[index]["action_type"].asString();
  244. if (actionType == "SOS") {
  245. pListItem->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "interaction/sos.png");
  246. pListItem->setText(LANGUAGEMANAGER->getValue("SOSCall"));
  247. }
  248. else if (actionType == "EVENT") {
  249. pListItem->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "interaction/shijian.png");
  250. pListItem->setText(interactionList[index]["data"].asString());
  251. }
  252. else if (actionType == "REINFORCE") {
  253. pListItem->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "interaction/zengyuan2.png");
  254. pListItem->setText(LANGUAGEMANAGER->getValue("ReinforceCall"));
  255. }
  256. else if (actionType == "VOICE") {
  257. if (interactionList[index]["from_device_id"].asInt() == StoragePreferences::getInt(STORE_DEVICE_ID, 0)) {
  258. pListItem->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "interaction/huru.png");
  259. pListItem->setText(LANGUAGEMANAGER->getValue("CallIn") + interactionList[index]["from_device_name"].asString());
  260. }
  261. else {
  262. pListItem->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "interaction/huchu.png");
  263. pListItem->setText(LANGUAGEMANAGER->getValue("CallOut") + interactionList[index]["to_device_name"].asString());
  264. }
  265. }
  266. else if (actionType == "SIDE") {
  267. pListItem->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "interaction/huli3.png");
  268. pListItem->setText(LANGUAGEMANAGER->getValue("InNursing"));
  269. }
  270. else {
  271. pListItem->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "interaction/zengyuan2.png");
  272. pListItem->setText(LANGUAGEMANAGER->getValue("Other"));
  273. }
  274. if (actionType == "EVENT") {
  275. string actionStatus = interactionList[index]["action_status"].asString();
  276. if (actionStatus == "已发送") {
  277. interactionStatus->setText(LANGUAGEMANAGER->getValue("Sented"));
  278. interactionStatus->setTextColor((int) defaultRed);
  279. }
  280. else if (actionStatus == "已响应") {
  281. interactionStatus->setText(LANGUAGEMANAGER->getValue("Responded"));
  282. interactionStatus->setTextColor((int) defaultGreen);
  283. }
  284. else if (actionStatus == "已取消") {
  285. interactionStatus->setText(LANGUAGEMANAGER->getValue("Canceled"));
  286. interactionStatus->setTextColor((int) defaultBlue);
  287. }
  288. else if (actionStatus == "已完成") {
  289. interactionStatus->setText(LANGUAGEMANAGER->getValue("Completed"));
  290. interactionStatus->setTextColor((int) defaultGreen);
  291. }
  292. else {
  293. if (interactionList[index]["action_end"].asString() != "") {
  294. interactionStatus->setText(LANGUAGEMANAGER->getValue("Responded"));
  295. interactionStatus->setTextColor((int) defaultGreen);
  296. }
  297. else {
  298. interactionStatus->setText(LANGUAGEMANAGER->getValue("Sented"));
  299. interactionStatus->setTextColor((int) defaultRed);
  300. }
  301. }
  302. }
  303. else if (actionType == "VOICE") {
  304. if (interactionList[index]["action_end"].asString() != "") {
  305. interactionStatus->setText(LANGUAGEMANAGER->getValue("Answered"));
  306. interactionStatus->setTextColor((int) defaultGreen);
  307. }
  308. else {
  309. interactionStatus->setText(LANGUAGEMANAGER->getValue("UnAnswered"));
  310. interactionStatus->setTextColor((int) defaultRed);
  311. }
  312. }
  313. else {
  314. if (interactionList[index]["action_end"].asString() != "") {
  315. interactionStatus->setText(LANGUAGEMANAGER->getValue("Responded"));
  316. interactionStatus->setTextColor((int) defaultGreen);
  317. }
  318. else {
  319. interactionStatus->setText(LANGUAGEMANAGER->getValue("NotRespond"));
  320. interactionStatus->setTextColor((int) defaultRed);
  321. }
  322. }
  323. }
  324. static void onListItemClick_InteractionListView(ZKListView *pListView, int index, int id) {
  325. //LOGD(" onListItemClick_ InteractionListView !!!\n");
  326. string actionType = interactionList[index]["action_type"].asString();
  327. if (actionType == "EVENT") {
  328. string actionStatus = interactionList[index]["action_status"].asString();
  329. Json::Value interaction = interactionList[index];
  330. Json::FastWriter writer;
  331. string interactionStr = writer.write(interaction);
  332. if (actionStatus == "已发送") {
  333. Intent* intent = new Intent();
  334. intent->putExtra(functionWindows, "eventHandle");
  335. intent->putExtra(functionText, interactionStr);
  336. intent->putExtra(transmitDeviceId, _interactionTransmitDeviceId);
  337. EASYUICONTEXT->openActivity("functionActivity", intent);
  338. EASYUICONTEXT->closeActivity("interactionActivity");
  339. }
  340. else if (actionStatus == "已响应") {
  341. Intent* intent = new Intent();
  342. intent->putExtra(functionWindows, "eventHandle");
  343. intent->putExtra(functionText, interactionStr);
  344. intent->putExtra(transmitDeviceId, _interactionTransmitDeviceId);
  345. EASYUICONTEXT->openActivity("functionActivity", intent);
  346. EASYUICONTEXT->closeActivity("interactionActivity");
  347. }
  348. }
  349. }