deviceAddLogic.cc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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 <string>
  7. /*
  8. *此文件由GUI工具生成
  9. *文件功能:用于处理用户的逻辑相应代码
  10. *功能说明:
  11. *========================onButtonClick_XXXX
  12. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  13. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  14. *========================onSlideWindowItemClick_XXXX(int index)
  15. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  16. 如slideWindow1;index 代表按下图标的偏移值
  17. *========================onSeekBarChange_XXXX(int progress)
  18. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  19. 如SeekBar1;progress 代表当前的进度值
  20. *========================ogetListItemCount_XXXX()
  21. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  22. 如List1;返回值为当前列表的总条数
  23. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  24. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  25. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  26. *========================常用接口===============
  27. *LOGD(...) 打印调试信息的接口
  28. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  29. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  30. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  31. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  32. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  33. *
  34. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  35. */
  36. static int choiceDeviceInt = 0;
  37. static int choiceHospitalInt = 0;
  38. static int choicePartInt = 0;
  39. static int choiceRoomInt = 0;
  40. static int choiceBedInt = 0;
  41. Json::Value hospitalList;
  42. Json::Value hospitalFrameTree;
  43. Json::Value partFrameTree;
  44. Json::Value roomFrameTree;
  45. Json::Value bedFrameTree;
  46. Json::Value choicePart;
  47. Json::Value choiceRoom;
  48. Json::Value choiceBed;
  49. Json::Value addDevice;
  50. static string mac = StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0");
  51. static void getHospital() {
  52. std::string url = getHttpGateway() + "/arrange/hospitals";
  53. LOGD("请求医院列表. url = %s", url.c_str());
  54. RestClient::Response r = RestClient::get(url);
  55. if (r.code != 200) {
  56. LOGD("请求医院列表-> 错误代码: %d", r.code);
  57. return;
  58. }
  59. LOGD("获得医院列表. result = %s", r.body.c_str());
  60. //解析json
  61. Json::Reader reader;
  62. Json::Value root;
  63. if(reader.parse(r.body, root, false)) {
  64. hospitalList = root;
  65. mHospitalListViewPtr->refreshListView();
  66. }
  67. }
  68. static void initFrame() {
  69. if (hospitalFrameTree.size() == 0) {
  70. return;
  71. }
  72. partFrameTree = hospitalFrameTree["frame_part_vos"];
  73. if (partFrameTree.size() == 0) {
  74. choicePart.clear();
  75. mChoicePartButtonPtr->setText("");
  76. return;
  77. }
  78. choicePart = partFrameTree[choicePartInt]["frame_part"];
  79. mChoicePartButtonPtr->setText(choicePart["full_name"].asString());
  80. addDevice["part_id"] = choicePart["part_id"];
  81. roomFrameTree = partFrameTree[choicePartInt]["frame_room_vos"];
  82. if (roomFrameTree.size() == 0) {
  83. choiceRoom.clear();
  84. mChoiceRoomButtonPtr->setText("");
  85. return;
  86. }
  87. choiceRoom = roomFrameTree[choiceRoomInt]["frame_room"];
  88. mChoiceRoomButtonPtr->setText(choiceRoom["full_name"].asString());
  89. if (choiceDeviceInt == 0) {
  90. addDevice["frame_id"] = choiceRoom["id"];
  91. LOGD("门口机注册空间id ===> %d", choiceRoom["id"].asInt());
  92. }
  93. else {
  94. bedFrameTree = roomFrameTree[choiceRoomInt]["frame_bed_list"];
  95. if (bedFrameTree.size() == 0) {
  96. choiceBed.clear();
  97. mChoiceBedButtonPtr->setText("");
  98. return;
  99. }
  100. choiceBed = bedFrameTree[choiceBedInt]["frame_bed"];
  101. addDevice["frame_id"] = choiceBed["id"];
  102. LOGD("手柄注册空间id ===> %d", choiceBed["id"].asInt());
  103. mChoiceBedButtonPtr->setText(choiceBed["full_name"].asString());
  104. }
  105. }
  106. static void getHospitalFrameTree(string hospitalId) {
  107. std::string url = getHttpGateway() + "/arrange/frame_hospital/" + hospitalId;
  108. LOGD("请求医院空间节点树状图. url = %s", url.c_str());
  109. RestClient::Response r = RestClient::get(url);
  110. if (r.code != 200) {
  111. LOGD("请求医院空间节点树状图-> 错误代码: %d", r.code);
  112. return;
  113. }
  114. LOGD("获得医院空间节点树状图. result = %s", r.body.c_str());
  115. //解析json
  116. Json::Reader reader;
  117. Json::Value root;
  118. if(reader.parse(r.body, root, false)) {
  119. hospitalFrameTree = root;
  120. initFrame();
  121. }
  122. }
  123. static void initHospital() {
  124. choicePartInt = 0;
  125. choiceRoomInt = 0;
  126. choiceBedInt = 0;
  127. if (choiceHospitalInt != 0 || hospitalFrameTree.size() == 0) {
  128. choiceHospitalInt = 0;
  129. mHospitalListViewPtr->refreshListView();
  130. getHospitalFrameTree(hospitalList[choiceHospitalInt]["shop_id"].asString());
  131. }
  132. else {
  133. initFrame();
  134. }
  135. }
  136. Json::Value getFrameTree(std::string frame) {
  137. if (frame == "getPartFrame") {
  138. return partFrameTree;
  139. }
  140. else if (frame == "getRoomFrame") {
  141. return roomFrameTree;
  142. }
  143. else if (frame == "getBedFrame") {
  144. return bedFrameTree;
  145. }
  146. Json::Value nullValue;
  147. return nullValue;
  148. }
  149. void setPartFrameTree(int index) {
  150. choicePartInt = index;
  151. choicePart = partFrameTree[choicePartInt]["frame_part"];
  152. mChoicePartButtonPtr->setText(choicePart["full_name"].asString());
  153. addDevice["part_id"] = choicePart["part_id"];
  154. roomFrameTree = partFrameTree[choicePartInt]["frame_room_vos"];
  155. setRoomFrameTree(0);
  156. }
  157. void setRoomFrameTree(int index) {
  158. choiceRoomInt = index;
  159. if (roomFrameTree.size() == 0) {
  160. choiceRoom.clear();
  161. mChoiceRoomButtonPtr->setText("");
  162. return;
  163. }
  164. choiceRoom = roomFrameTree[choiceRoomInt]["frame_room"];
  165. mChoiceRoomButtonPtr->setText(choiceRoom["full_name"].asString());
  166. if (choiceDeviceInt == 0) {
  167. addDevice["frame_id"] = choiceRoom["id"];
  168. LOGD("门口机注册空间id ===> %d", choiceRoom["id"].asInt());
  169. }
  170. else {
  171. bedFrameTree = roomFrameTree[choiceRoomInt]["frame_bed_list"];
  172. setBedFrameTree(0);
  173. }
  174. }
  175. void setBedFrameTree(int index) {
  176. choiceBedInt = index;
  177. if (bedFrameTree.size() == 0) {
  178. choiceBed.clear();
  179. mChoiceBedButtonPtr->setText("");
  180. return;
  181. }
  182. choiceBed = bedFrameTree[choiceBedInt]["frame_bed"];
  183. addDevice["frame_id"] = choiceBed["id"];
  184. LOGD("手柄注册空间id ===> %d", choiceBed["id"].asInt());
  185. mChoiceBedButtonPtr->setText(choiceBed["full_name"].asString());
  186. }
  187. void _addDevice() {
  188. string url = getHttpGateway() + "/arrange/linux_add_device";
  189. string content_type = std::string("application/json");
  190. Json::FastWriter writer;
  191. string data = writer.write(addDevice);
  192. LOGD("data =============> %s", data.c_str());
  193. LOGD("注册医院设备. url = %s", url.c_str());
  194. RestClient::Response r = RestClient::post(url, content_type, data);
  195. if (r.code != 200) {
  196. LOGD("注册医院设备-> 错误代码: %d", r.code);
  197. string errorMsg = LANGUAGEMANAGER->getValue("AddDeviceErrorMsg") + to_string(r.code);
  198. LOGD("r.body ===> %s", r.body.c_str());
  199. string error = "DEVICE_MAC_REPEAT";
  200. size_t pos = r.body.find(error);
  201. if (pos != std::string::npos) {
  202. errorMsg = LANGUAGEMANAGER->getValue("DEVICE_MAC_REPEAT");
  203. }
  204. error = "DEVICE_FRAME_FAILED";
  205. pos = r.body.find(error);
  206. if (pos != std::string::npos) {
  207. errorMsg = LANGUAGEMANAGER->getValue("DEVICE_FRAME_FAILED");
  208. }
  209. Intent* intent = new Intent();
  210. intent->putExtra(functionWindows, "warn");
  211. intent->putExtra(warnText, errorMsg);
  212. EASYUICONTEXT->openActivity("functionActivity", intent);
  213. return;
  214. }
  215. LOGD("注册医院设备. result = %s", r.body.c_str());
  216. //解析json
  217. Json::Reader reader;
  218. Json::Value root;
  219. if(reader.parse(r.body, root, false)) {
  220. Intent* intent = new Intent();
  221. intent->putExtra(functionWindows, "success");
  222. intent->putExtra(functionText, LANGUAGEMANAGER->getValue("AddDeviceSuccess"));
  223. EASYUICONTEXT->openActivity("functionActivity", intent);
  224. }
  225. }
  226. /**
  227. * 注册定时器
  228. * 填充数组用于注册定时器
  229. * 注意:id不能重复
  230. */
  231. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  232. //{0, 6000}, //定时器id=0, 时间间隔6秒
  233. //{1, 1000},
  234. };
  235. /**
  236. * 当界面构造时触发
  237. */
  238. static void onUI_init(){
  239. //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123");
  240. getHospital();
  241. mDeviceRadioGroupPtr->setCheckedID(ID_DEVICEADD_DeviceRadioButton1);
  242. choiceDeviceInt = 0;
  243. choiceHospitalInt = 0;
  244. choiceHospitalInt = 0;
  245. choicePartInt = 0;
  246. choiceRoomInt = 0;
  247. choiceBedInt = 0;
  248. }
  249. /**
  250. * 当切换到该界面时触发
  251. */
  252. static void onUI_intent(const Intent *intentPtr) {
  253. if (intentPtr != NULL) {
  254. //TODO
  255. }
  256. }
  257. /*
  258. * 当界面显示时触发
  259. */
  260. static void onUI_show() {
  261. EASYUICONTEXT->hideStatusBar();
  262. EASYUICONTEXT->hideNaviBar();
  263. }
  264. /*
  265. * 当界面隐藏时触发
  266. */
  267. static void onUI_hide() {
  268. }
  269. /*
  270. * 当界面完全退出时触发
  271. */
  272. static void onUI_quit() {
  273. }
  274. /**
  275. * 串口数据回调接口
  276. */
  277. static void onProtocolDataUpdate(const SProtocolData &data) {
  278. }
  279. /**
  280. * 定时器触发函数
  281. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  282. * 参数: id
  283. * 当前所触发定时器的id,与注册时的id相同
  284. * 返回值: true
  285. * 继续运行当前定时器
  286. * false
  287. * 停止运行当前定时器
  288. */
  289. static bool onUI_Timer(int id){
  290. switch (id) {
  291. default:
  292. break;
  293. }
  294. return true;
  295. }
  296. /**
  297. * 有新的触摸事件时触发
  298. * 参数:ev
  299. * 新的触摸事件
  300. * 返回值:true
  301. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  302. * false
  303. * 触摸事件将继续传递到控件上
  304. */
  305. static bool ondeviceAddActivityTouchEvent(const MotionEvent &ev) {
  306. switch (ev.mActionStatus) {
  307. case MotionEvent::E_ACTION_DOWN://触摸按下
  308. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  309. break;
  310. case MotionEvent::E_ACTION_MOVE://触摸滑动
  311. break;
  312. case MotionEvent::E_ACTION_UP: //触摸抬起
  313. break;
  314. default:
  315. break;
  316. }
  317. return false;
  318. }
  319. static bool onButtonClick_sys_back(ZKButton *pButton) {
  320. LOGD(" ButtonClick sys_back !!!\n");
  321. return false;
  322. }
  323. static void onCheckedChanged_DeviceRadioGroup(ZKRadioGroup* pRadioGroup, int checkedID) {
  324. LOGD(" RadioGroup DeviceRadioGroup checked %d", checkedID);
  325. switch(checkedID) {
  326. case ID_DEVICEADD_DeviceRadioButton1:
  327. choiceDeviceInt = 0;
  328. mDeviceMacTextViewPtr->setText(LANGUAGEMANAGER->getValue("DeviceAddMsg") + mac);
  329. mBedTextViewPtr->setVisible(false);
  330. mChoiceBedButtonPtr->setVisible(false);
  331. addDevice["device_type"] = 3;
  332. addDevice["name"] = LANGUAGEMANAGER->getValue("RoomDevice");
  333. addDevice["eth_mac"] = mac;
  334. addDevice["code"] = "SW10600101C-CM";
  335. addDevice["model"] = "linux_door";
  336. addDevice["soft_ver"] = "SV1.0";
  337. addDevice["hard_ver"] = "HV1.0";
  338. addDevice["status"] = 1;
  339. initHospital();
  340. break;
  341. case ID_DEVICEADD_DeviceRadioButton2:
  342. choiceDeviceInt = 1;
  343. mDeviceMacTextViewPtr->setText(LANGUAGEMANAGER->getValue("DeviceAddMsg2") + mac + ":h1");
  344. mBedTextViewPtr->setVisible(true);
  345. mChoiceBedButtonPtr->setVisible(true);
  346. addDevice["device_type"] = 4;
  347. addDevice["name"] = LANGUAGEMANAGER->getValue("BedDevice");
  348. addDevice["eth_mac"] = mac + ":h1";
  349. addDevice["code"] = "SW10600101C-CM";
  350. addDevice["model"] = "linux_handle";
  351. addDevice["soft_ver"] = "SV1.0";
  352. addDevice["hard_ver"] = "HV1.0";
  353. addDevice["status"] = 1;
  354. initHospital();
  355. break;
  356. case ID_DEVICEADD_DeviceRadioButton3:
  357. choiceDeviceInt = 2;
  358. mDeviceMacTextViewPtr->setText(LANGUAGEMANAGER->getValue("DeviceAddMsg3") + mac + ":h2");
  359. mBedTextViewPtr->setVisible(true);
  360. mChoiceBedButtonPtr->setVisible(true);
  361. addDevice["device_type"] = 4;
  362. addDevice["name"] = LANGUAGEMANAGER->getValue("BedDevice");
  363. addDevice["eth_mac"] = mac + ":h2";
  364. addDevice["code"] = "SW10600101C-CM";
  365. addDevice["model"] = "linux_handle";
  366. addDevice["soft_ver"] = "SV1.0";
  367. addDevice["hard_ver"] = "HV1.0";
  368. addDevice["status"] = 1;
  369. initHospital();
  370. break;
  371. }
  372. }
  373. static int getListItemCount_HospitalListView(const ZKListView *pListView) {
  374. //LOGD("getListItemCount_HospitalListView !\n");
  375. return hospitalList.size();
  376. }
  377. static void obtainListItemData_HospitalListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  378. //LOGD(" obtainListItemData_ HospitalListView !!!\n");
  379. if (hospitalList.size() == 0) {
  380. return;
  381. }
  382. pListItem->setText(hospitalList[index]["full_name"].asString());
  383. if (choiceHospitalInt == index) {
  384. pListItem->setSelected(true);
  385. }
  386. else {
  387. pListItem->setSelected(false);
  388. }
  389. }
  390. static void onListItemClick_HospitalListView(ZKListView *pListView, int index, int id) {
  391. //LOGD(" onListItemClick_ HospitalListView !!!\n");
  392. if (choiceHospitalInt != index) {
  393. choiceHospitalInt = index;
  394. getHospitalFrameTree(hospitalList[choiceHospitalInt]["shop_id"].asString());
  395. }
  396. }
  397. static bool onButtonClick_ChoicePartButton(ZKButton *pButton) {
  398. LOGD(" ButtonClick ChoicePartButton !!!\n");
  399. Intent* intent = new Intent();
  400. intent->putExtra(functionWindows, "getPartFrame");
  401. EASYUICONTEXT->openActivity("functionActivity", intent);
  402. return false;
  403. }
  404. static bool onButtonClick_ChoiceRoomButton(ZKButton *pButton) {
  405. LOGD(" ButtonClick ChoiceRoomButton !!!\n");
  406. Intent* intent = new Intent();
  407. intent->putExtra(functionWindows, "getRoomFrame");
  408. EASYUICONTEXT->openActivity("functionActivity", intent);
  409. return false;
  410. }
  411. static bool onButtonClick_ChoiceBedButton(ZKButton *pButton) {
  412. LOGD(" ButtonClick ChoiceBedButton !!!\n");
  413. Intent* intent = new Intent();
  414. intent->putExtra(functionWindows, "getBedFrame");
  415. EASYUICONTEXT->openActivity("functionActivity", intent);
  416. return false;
  417. }
  418. static bool onButtonClick_ConfirmButton(ZKButton *pButton) {
  419. LOGD(" ButtonClick ConfirmButton !!!\n");
  420. if (addDevice.isMember("frame_id")) {
  421. _addDevice();
  422. }
  423. else {
  424. Intent* intent = new Intent();
  425. intent->putExtra(functionWindows, "warn");
  426. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("AddDeviceFrameFailed"));
  427. EASYUICONTEXT->openActivity("functionActivity", intent);
  428. }
  429. return false;
  430. }
  431. static bool onButtonClick_RebootButton(ZKButton *pButton) {
  432. LOGD(" ButtonClick RebootButton !!!\n");
  433. Intent* intent = new Intent();
  434. intent->putExtra(functionWindows, "reboot");
  435. EASYUICONTEXT->openActivity("functionActivity", intent);
  436. return false;
  437. }