mainLogic.cc 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include "net/NetManager.h"
  4. #include "storage/StoragePreferences.h"
  5. #include "net/net.h"
  6. #include <system/Thread.h>
  7. #include "restclient-cpp/restclient.h"
  8. #include "curl/curl.h"
  9. #include <algorithm>
  10. #include "service/BusinessConfig.h"
  11. #include "core/sip_config.h"
  12. #include "manager/LanguageManager.h"
  13. #include "core/utilities.h"
  14. #include <string>
  15. #include "base/strings.hpp"
  16. #include "base/http_client.h"
  17. #include "os/UpgradeMonitor.h"
  18. #include "core/jhws.h"
  19. #include "core/update_assistant.h"
  20. #include "utils/TimeHelper.h"
  21. #define ETHERNETMANAGER NETMANAGER->getEthernetManager()
  22. /*
  23. *此文件由GUI工具生成
  24. *文件功能:用于处理用户的逻辑相应代码
  25. *功能说明:
  26. *========================onButtonClick_XXXX
  27. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  28. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  29. *========================onSlideWindowItemClick_XXXX(int index)
  30. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  31. 如slideWindow1;index 代表按下图标的偏移值
  32. *========================onSeekBarChange_XXXX(int progress)
  33. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  34. 如SeekBar1;progress 代表当前的进度值
  35. *========================ogetListItemCount_XXXX()
  36. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  37. 如List1;返回值为当前列表的总条数
  38. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  39. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  40. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  41. *========================常用接口===============
  42. *LOGD(...) 打印调试信息的接口
  43. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  44. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  45. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  46. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  47. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  48. *
  49. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  50. */
  51. TcpModel nursingTcpModel;
  52. static bool dataInit = false; // false表示需要从数据库里获取数据,true表示从缓存里获取数据
  53. PartSetting partSetting;
  54. Json::Value frameRoom;
  55. Json::Value frameBedList;
  56. Json::Value frameInfo; // 缓存房间名字等
  57. Json::Value rightTitleInfo; // 缓存分机右边医生和护士标题
  58. Json::Value painterInfo;
  59. Json::Value painterInfoList;
  60. static bool reinforce = false; // 判断设备是否处于增援状态
  61. static bool serverInfo = true; // 判断是否需要从服务器获取服务器信息,第一次要,后续不要
  62. static bool isHelpTimerRegistered = false;
  63. static std::string cencalByDoorTid = "";
  64. #define HELP_TIMER_HANDLE 3 // 增援的定时器id
  65. #define NURSING_TIME_HANDLE 6 // 护理的定时器id
  66. #define EVENT_TIME_HANDLE 8 // 事件定时器
  67. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  68. //======================================= udp 请示服务器信息
  69. static net::Conn* udpConn;
  70. class UdpThread: public Thread {
  71. public:
  72. static void getServerInfo(){
  73. string url = getHttpGateway() + "/ncs_url/server_info";
  74. LOGD("请求服务器信息. url = %s", url.c_str());
  75. //发起HTTP GET请求
  76. RestClient::Response r = RestClient::get(url);
  77. //解析json
  78. Json::Reader reader;
  79. Json::Value root;
  80. if (reader.parse(r.body, root, false)){
  81. // http
  82. StoragePreferences::putString(STORE_GATEWAY, root["http_local_ip"].asString());
  83. StoragePreferences::putInt(STORE_HTTP_PORT, root["http_port"].asInt());
  84. // tcp
  85. StoragePreferences::putString(STORE_TCP_LOCAL_IP, root["tcp_local_ip"].asString());
  86. StoragePreferences::putInt(STORE_TCP_PORT, root["tcp_port"].asInt());
  87. // sip
  88. StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString());
  89. StoragePreferences::putInt(SIP_REG_PORT, root["sip_port"].asInt());
  90. serverInfo = false; // 只有请求成功了,才不需要重复请求
  91. }
  92. }
  93. static void getDeviceInfo(){
  94. if (dataInit){
  95. getFrameInfo();
  96. //getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  97. reinforceDispaly();
  98. return;
  99. }
  100. string url = getHttpGateway() + "/deviceRoom/get_device_by_eth_mac/" + ETHERNETMANAGER->getMacAddr();
  101. LOGD("请求设备信息. url = %s", url.c_str());
  102. //发起HTTP GET请求
  103. RestClient::Response r = RestClient::get(url);
  104. LOGD("获得设备信息. result = %s", r.body.c_str());
  105. //解析json
  106. Json::Reader reader;
  107. Json::Value root;
  108. if (reader.parse(r.body, root, false)){
  109. string partName = root["part_display"].asString();
  110. StoragePreferences::putString(STORE_PARTNAME,partName);
  111. NavibarSetPartName(partName);
  112. //设备
  113. StoragePreferences::putInt(STORE_DEVICE_ID, root["id"].asInt());
  114. StoragePreferences::putInt(STORE_DEVICE_TYPE, root["device_type"].asInt());
  115. //SIP存储
  116. // StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); // 应该去找配置文件里的sip-ip
  117. StoragePreferences::putString(SIP_REG_ACCOUNT,root["sip_id"].asString());
  118. StoragePreferences::putString(SIP_REG_PASSWORD, root["sip_password"].asString());
  119. //获取科室设置
  120. string partId = root["part_id"].asString();
  121. StoragePreferences::putString(STORE_PARTID, partId);
  122. getPartSetting(partId);
  123. getVersion();
  124. setFrameInfo(root);
  125. }
  126. }
  127. // 将空间相关的数据缓存起来
  128. static void setFrameInfo(Json::Value deviceInfo) {
  129. frameInfo["frame_id"] = deviceInfo["frame_id"].asInt();
  130. frameInfo["full_name"] = deviceInfo["full_name"].asString();
  131. frameInfo["part_id"] = deviceInfo["part_id"].asInt();
  132. getFrameInfo();
  133. getFrameRoom(deviceInfo["frame_id"].asInt());
  134. }
  135. // 读取空间缓存的数据
  136. static void getFrameInfo() {
  137. mRoomNamePtr->setText(frameInfo["full_name"].asString());
  138. }
  139. static void getFrameRoom(int frame_id) {
  140. string url = getHttpGateway() + "/deviceRoom/get_frame_room/" + to_string(frame_id);
  141. LOGD("请求房间信息. url = %s", url.c_str());
  142. //发起HTTP GET请求
  143. RestClient::Response r = RestClient::get(url);
  144. LOGD("获得房间信息. result = %s", r.body.c_str());
  145. //解析json
  146. Json::Reader reader;
  147. Json::Value root;
  148. if (reader.parse(r.body, root, false)){
  149. frameRoom = root;
  150. frameBedList = root["frame_bed_list"];
  151. }
  152. }
  153. static void getPartSetting(string partId){
  154. string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId;
  155. LOGD("请求科室信息. url = %s", url.c_str());
  156. //发起HTTP GET请求
  157. RestClient::Response r = RestClient::get(url);
  158. LOGD("获得科室信息. result = %s", r.body.c_str());
  159. //解析json
  160. Json::Reader reader;
  161. Json::Value root;
  162. if (reader.parse(r.body, root, false)){
  163. partSetting.partId = root["part_id"].asInt();
  164. partSetting.dayStart = root["day_start"].asString();
  165. partSetting.dayLight = root["day_light"].asInt();
  166. partSetting.dayVol = root["day_vol"].asInt();
  167. partSetting.dayRingVol = root["day_ring_vol"].asInt();
  168. partSetting.dayRingTimes = root["day_ring_times"].asInt();
  169. partSetting.dayNurseLed = root["day_nurse_led"].asInt();
  170. partSetting.dayDoorVol = root["day_door_vol"].asInt();
  171. partSetting.dayBedVol = root["day_bed_vol"].asInt();
  172. partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt();
  173. partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt();
  174. partSetting.nightStart = root["night_start"].asString();
  175. partSetting.nightLight = root["night_light"].asInt();
  176. partSetting.nightVol = root["night_vol"].asInt();
  177. partSetting.nightRingVol = root["night_ring_vol"].asInt();
  178. partSetting.nightRingTimes = root["night_ring_times"].asInt();
  179. partSetting.nightNurseLed = root["night_nurse_led"].asInt();
  180. partSetting.nightDoorVol = root["night_door_vol"].asInt();
  181. partSetting.nightBedVol = root["night_bed_vol"].asInt();
  182. partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt();
  183. partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt();
  184. partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt();
  185. partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt();
  186. partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt();
  187. partSetting.sipOvertime = root["sip_overtime"].asInt();
  188. partSetting.transferDuration = root["transfer_duration"].asInt();
  189. partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt();
  190. partSetting.communicationModeBed = root["communication_mode_bed"].asInt();
  191. partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt();
  192. partSetting.communicationModeMobile = root["communication_model_mobile"].asInt();
  193. partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt();
  194. partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt();
  195. partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt();
  196. partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt();
  197. partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt();
  198. partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt();
  199. partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString();
  200. partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt();
  201. partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString();
  202. partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt();
  203. partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString();
  204. partSetting.doctorTitle = root["doctor_title"].asString();
  205. partSetting.doctorValid = root["doctor_valid"].asInt();
  206. partSetting.nurseTitle = root["nurse_title"].asString();
  207. partSetting.nurseValid = root["nurse_valid"].asInt();
  208. partSetting.doorNurseTitle = root["door_nurse_title"].asString();
  209. partSetting.doorNurseValid = root["door_nurse_valid"].asInt();
  210. partSetting.doorNursingTitle = root["door_nursing_title"].asString();
  211. partSetting.doorNursingValid = root["door_nursing_valid"].asInt();
  212. partSetting.upSeconds = root["up_seconds"].asInt();
  213. partSetting.autoAccept = root["auto_accept"].asInt();
  214. partSetting.eventForward = root["event_forward"].asInt();
  215. partSetting.nursingColorRgb = root["nursing_color_rgb"].asString();
  216. partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt();
  217. partSetting.qrUrl = root["qr_url"].asString();
  218. partSetting.screenLight = root["screen_light"].asInt();
  219. partSetting.roomCallBed = root["room_call_bed"].asInt();
  220. StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart);
  221. StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight);
  222. StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol);
  223. StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes);
  224. StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart);
  225. StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight);
  226. StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol);
  227. StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes);
  228. StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsDoor);
  229. StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle);
  230. StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1);
  231. StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle);
  232. StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1);
  233. StoragePreferences::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb);
  234. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  235. StoragePreferences::putInt(STORE_SCREEN_LIGHT, partSetting.screenLight);
  236. StoragePreferences::putInt(STORE_ROOM_CALL_BED, partSetting.roomCallBed);
  237. setRightTitle(root);
  238. callBedButtonSetVisible();
  239. dataInit = true;
  240. }
  241. }
  242. static void callBedButtonSetVisible() {
  243. int roomCallBed = StoragePreferences::getInt(STORE_ROOM_CALL_BED, 1);
  244. if (!roomCallBed) {
  245. // 如果roomCallBed是0的话,那就隐藏
  246. mCallBedButtonPtr->setVisible(roomCallBed);
  247. mCallNurseButtonPtr->setPosition(LayoutPosition(869, 125, 140, 55));
  248. mCallCencelButtonPtr->setPosition(LayoutPosition(869, 209, 140, 55));
  249. mHelpButtonPtr->setPosition(LayoutPosition(869, 293, 140, 55));
  250. mNursingButtonPtr->setPosition(LayoutPosition(869, 377, 140, 55));
  251. mMoreButtonPtr->setPosition(LayoutPosition(869, 461, 140, 55));
  252. }
  253. else {
  254. // 如果roomCallBed是1的话,那就显示
  255. mCallBedButtonPtr->setVisible(roomCallBed);
  256. mCallNurseButtonPtr->setPosition(LayoutPosition(869, 198, 140, 55));
  257. mCallCencelButtonPtr->setPosition(LayoutPosition(869, 271, 140, 55));
  258. mHelpButtonPtr->setPosition(LayoutPosition(869, 344, 140, 55));
  259. mNursingButtonPtr->setPosition(LayoutPosition(869, 417, 140, 55));
  260. mMoreButtonPtr->setPosition(LayoutPosition(869, 490, 140, 55));
  261. }
  262. }
  263. // 将医生和护士别称缓存起来
  264. static void setRightTitle(Json::Value partSetting) {
  265. rightTitleInfo["doctor_title"] = partSetting["doctor_title"].asString();
  266. rightTitleInfo["doctor_valid"] = partSetting["doctor_valid"].asInt();
  267. rightTitleInfo["nurse_title"] = partSetting["nurse_title"].asString();
  268. rightTitleInfo["nurse_valid"] = partSetting["nurse_valid"].asInt();
  269. }
  270. static void getVersion() {
  271. std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=303&part_id=" + StoragePreferences::getString(STORE_PARTID, "");
  272. std::string content_type = std::string("application/json");
  273. LOGD("请求版本信息. url = %s", url.c_str());
  274. //发起HTTP POST请求
  275. RestClient::Response r = RestClient::post(url, content_type, "");
  276. if (r.code != 200) {
  277. LOGD("请求版本信息-> 错误代码: %d", r.code);
  278. return;
  279. }
  280. LOGD("获得版本信息. result = %s", r.body.c_str());
  281. //解析json
  282. Json::Reader reader;
  283. Json::Value root;
  284. if(reader.parse(r.body, root, false)) {
  285. int currentVersionNo = getVersionNo();
  286. int responseVersionNo = root["version_no"].asInt();
  287. std::string responseVersion = root["version_code"].asString();
  288. LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo);
  289. if (currentVersionNo < responseVersionNo) {
  290. Intent* intent = new Intent();
  291. intent->putExtra(appUpdate, "true");
  292. EASYUICONTEXT->openActivity("DeviceUpdateActivity", intent);
  293. }
  294. }
  295. }
  296. // 判断是否处于增援状态,处于增援状态,就要显示蓝色
  297. static void reinforceDispaly() {
  298. if (reinforce) {
  299. // SetPainterInfo(0xFF2F9DF1, "增援已发出");
  300. // setHelpButton("/button/button_help3.png" ,false);
  301. setPainterInfo(StoragePreferences::getInt(STORE_DEVICE_ID,0), 0xFF2F9DF1, LANGUAGEMANAGER->getValue("HelpInfo"), "REINFORCE", "ADD", 60);
  302. }
  303. }
  304. /**
  305. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  306. * return true 继续线程
  307. * false 退出线程
  308. */
  309. virtual bool readyToRun() {
  310. LOGD("Thread 已经创建完成");
  311. return true;
  312. }
  313. /**
  314. * 线程循环函数
  315. *
  316. * return true 继续线程循环
  317. * false 推出线程
  318. */
  319. virtual bool threadLoop() {
  320. LOGD("线程循环函数");
  321. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  322. if (exitPending()) {
  323. return false;
  324. }
  325. udpConn = net::Dial("udp", "192.168.1.255:10010");
  326. if (udpConn) {
  327. byte buf[1024] = {0};
  328. const char* req = "search_server";
  329. //发送
  330. udpConn->Write((byte*)req, strlen(req));
  331. while (true && !exitPending()) {
  332. //读取,超时10*1000毫秒
  333. int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000);
  334. if (n > 0) {
  335. buf[n] = 0;
  336. char serverStr[1024];
  337. sprintf(serverStr,"%s",buf);
  338. LOGD("读取 %d字节: %s", n, serverStr);
  339. //解析json
  340. Json::Reader reader;
  341. Json::Value root;
  342. if (reader.parse(serverStr, root, false)){
  343. if (root.isMember("success") && root["success"].asBool()){
  344. serverIP = root["data"]["third_server"].asString();
  345. serverHttpPort = root["data"]["third_server_port"].asInt();
  346. StoragePreferences::putString(STORE_GATEWAY, serverIP);
  347. StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort);
  348. //先获取服务器信息
  349. //getServerInfo();
  350. //就当在获取服务器信息完成后获取用户信息,这里测试用
  351. //getCustomerInfo();
  352. //退出UDP线程
  353. pthread_exit(NULL);
  354. break;
  355. }
  356. }
  357. } else if (n == 0) {
  358. LOGD("连接正常断开");
  359. break;
  360. } else if (n == net::E_TIMEOUT) {
  361. udpConn->Write((byte*)req, strlen(req));
  362. LOGD("读取超时");
  363. } else {
  364. LOGD("出错");
  365. break;
  366. }
  367. }
  368. //关闭连接
  369. udpConn->Close();
  370. //释放内存
  371. delete udpConn;
  372. udpConn = NULL;
  373. }
  374. //返回真,继续下次线程循环
  375. return true;
  376. }
  377. };
  378. static UdpThread udp_thread;
  379. void setReinforce(bool result) {
  380. reinforce = result;
  381. }
  382. void setHelpButton(const char *pPicPath, bool isTouchable){
  383. mHelpButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, pPicPath);
  384. mHelpButtonPtr->setTouchable(isTouchable);
  385. }
  386. void cancelAutoBtnHelpTimer(){
  387. if (isHelpTimerRegistered) {
  388. mActivityPtr->unregisterUserTimer(HELP_TIMER_HANDLE);
  389. isHelpTimerRegistered = false;
  390. }
  391. }
  392. std::string getCencalByDoorTid() {
  393. return cencalByDoorTid;
  394. }
  395. int getNowTime() {
  396. struct tm *t = TimeHelper::getDateTime();
  397. char timeStr[50];
  398. string formatStr = "%02d:%02d:%02d";
  399. sprintf(timeStr, formatStr.c_str(), t->tm_hour,t->tm_min,t->tm_sec);
  400. int hour, minute, second;// 定义时间的各个int临时变量。
  401. sscanf(timeStr, "%d:%d:%d", &hour, &minute, &second);
  402. int time = hour * 60 * 60 + minute * 60 + second;
  403. return time;
  404. }
  405. Json::Value getPainterInfoList() {
  406. return painterInfoList;
  407. }
  408. void addPainterInfo(int deviceId, uint32_t bgColor, const std::string& msg, const std::string type, int endTime) {
  409. // 将设备id,颜色,展示的信息,时间存放起来
  410. painterInfo["deviceId"] = deviceId;
  411. // painterInfo["bgColor"] = bgColor + "";
  412. painterInfo["bgColor"] = bgColor;
  413. painterInfo["msg"] = msg;
  414. painterInfo["type"] = type;
  415. painterInfo["endTime"] = getNowTime() + endTime;
  416. painterInfoList.append(painterInfo);
  417. }
  418. bool removePainterInfo(int deviceId, const std::string type) {
  419. // 获取painterInfoList的长度
  420. int size = painterInfoList.size();
  421. if (size == 0) { // 如果为空了,那就代表painterInfoList没有值,直接返回
  422. return false;
  423. }
  424. // 如果painterInfoList里有对应的deviceId,那就需要先删除原本的,然后再从头添加新的
  425. int removeIndex = -1;
  426. for (int i = 0; i < painterInfoList.size(); i++) {
  427. LOGD("deviceId == %d", deviceId);
  428. LOGD("painterInfoList.deviceId == %d", painterInfoList[i]["deviceId"].asInt());
  429. LOGD("type == %s", type.c_str());
  430. LOGD("painterInfoList.type == %s", painterInfoList[i]["type"].asCString());
  431. if (painterInfoList[i]["deviceId"].asInt() == deviceId && painterInfoList[i]["type"].asString() == type) {
  432. removeIndex = i;
  433. }
  434. }
  435. if (removeIndex != -1) {
  436. painterInfoList.removeIndex(removeIndex, &painterInfo);
  437. }
  438. return true;
  439. }
  440. //标识方法
  441. void setPainterInfo(int deviceId, uint32_t bgColor, const std::string& msg, const std::string type, const std::string handle, int endTime) {
  442. if (handle == "ADD") { // 进行添加,如果painterInfoList为空时,添加需要启动定时器
  443. int size = painterInfoList.size();
  444. removePainterInfo(deviceId, type);
  445. addPainterInfo(deviceId, bgColor, msg, type, endTime);
  446. if (size == 0) {
  447. mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 1000); // 每秒检测一次
  448. }
  449. if (type == "REINFORCE") { // 增援添加的时候,需要禁用增援按钮
  450. setReinforce(true); // 设置增援状态为true
  451. setHelpButton("/button/button_help3.png", false);
  452. }
  453. }
  454. else if (handle == "UPDATE") { // 进行修改时,需要把原本的删除掉,再进行添加
  455. bool result = removePainterInfo(deviceId, type);
  456. addPainterInfo(deviceId, bgColor, msg, type, endTime);
  457. if (!result) {
  458. mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 1000); // 每秒检测一次
  459. }
  460. }
  461. else if (handle == "DELETE") { // 进行删除
  462. removePainterInfo(deviceId, type);
  463. if (type == "REINFORCE") { // 增援删除的时候,需要还原增援按钮的图片
  464. setReinforce(false);
  465. setHelpButton("/button/button_help2.png", true);
  466. }
  467. }
  468. LOGD("painterInfoList.size() == %d", painterInfoList.size());
  469. mPainterInfoPtr->setBackgroundColor(bgColor);
  470. mTextInfoPtr->setText(msg);
  471. if (bgColor == 0xFFFFFFFF){
  472. mRoomNamePtr->setTextColor(0x00AAF4);
  473. } else {
  474. mRoomNamePtr->setTextColor(0xFFFFFF);
  475. }
  476. }
  477. // 收到tcp的时候,刷新数据
  478. void dataRefresh() {
  479. LOGD("DATA-REFRESH, 数据刷新");
  480. if (serverInfo) {
  481. udp_thread.getServerInfo();
  482. }
  483. dataInit = false;
  484. udp_thread.getDeviceInfo();
  485. mBedListViewPtr->refreshListView();
  486. }
  487. void getPartSetting() {
  488. udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  489. }
  490. // 处理护理的tcpModel
  491. void setNursingTcpModel(TcpModel tcpModel) {
  492. LOGD("缓存Nursing的tcpModel !!!");
  493. nursingTcpModel = tcpModel;
  494. }
  495. /**
  496. * 注册定时器
  497. * 填充数组用于注册定时器
  498. * 注意:id不能重复
  499. */
  500. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  501. //{0, 6000}, //定时器id=0, 时间间隔6秒
  502. //{1, 1000},
  503. };
  504. /**
  505. * 当界面构造时触发
  506. */
  507. static void onUI_init(){
  508. //udp_thread.run("this is thread name");
  509. //测试用
  510. LOGD("进入mainLogic页面, 触发 onUI_init");
  511. if(serverInfo) { // 如果是false,就是不需要
  512. udp_thread.getServerInfo();
  513. }
  514. udp_thread.getDeviceInfo();
  515. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) { // 如果处于护理状态
  516. mFunctionWinPtr->showWnd();
  517. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  518. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  519. mFunctionBackPtr->setVisible(false);
  520. } else {
  521. mFunctionWinPtr->hideWnd();
  522. }
  523. }
  524. /**
  525. * 当切换到该界面时触发
  526. */
  527. static void onUI_intent(const Intent *intentPtr) {
  528. if (intentPtr != NULL) {
  529. }
  530. }
  531. /*
  532. * 当界面显示时触发
  533. */
  534. static void onUI_show() {
  535. }
  536. /*
  537. * 当界面隐藏时触发
  538. */
  539. static void onUI_hide() {
  540. }
  541. /*
  542. * 当界面完全退出时触发
  543. */
  544. static void onUI_quit() {
  545. //pthread_exit(NULL);
  546. }
  547. /**
  548. * 串口数据回调接口
  549. */
  550. static void onProtocolDataUpdate(const SProtocolData &data) {
  551. }
  552. /**
  553. * 定时器触发函数
  554. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  555. * 参数: id
  556. * 当前所触发定时器的id,与注册时的id相同
  557. * 返回值: true
  558. * 继续运行当前定时器
  559. * false
  560. * 停止运行当前定时器
  561. */
  562. static bool onUI_Timer(int id){
  563. switch (id) {
  564. case HELP_TIMER_HANDLE: // 不能在线程里面关掉线程
  565. {
  566. // SetPainterInfo(0xFFFFFFFF, "");
  567. // setReinforce(false);
  568. // setHelpButton("/button/button_help2.png", true);
  569. // return false;
  570. if (painterInfoList.size() > 0) { // painterInfoList代表里面存在内容
  571. // 取出排列最后的一项,判断列表是否超时,没有超时就将内容填充到里面
  572. Json::Value _painterInfo;
  573. _painterInfo = painterInfoList.get(painterInfoList.size() - 1, &painterInfo);
  574. int nowTime = getNowTime();
  575. if (nowTime >= _painterInfo["endTime"].asInt()) {
  576. if (_painterInfo["type"] == "REINFORCE") {
  577. setReinforce(false);
  578. setHelpButton("/button/button_help2.png", true);
  579. }
  580. painterInfoList.removeIndex(painterInfoList.size() - 1, &painterInfo);
  581. } else {
  582. mPainterInfoPtr->setBackgroundColor( _painterInfo["bgColor"].asUInt());
  583. mTextInfoPtr->setText(_painterInfo["msg"].asCString());
  584. if (_painterInfo["bgColor"] == 0xFFFFFFFF){
  585. mRoomNamePtr->setTextColor(0x00AAF4);
  586. } else {
  587. mRoomNamePtr->setTextColor(0xFFFFFF);
  588. }
  589. }
  590. } else {
  591. mPainterInfoPtr->setBackgroundColor(0xFFFFFFFF);
  592. mTextInfoPtr->setText("");
  593. mRoomNamePtr->setTextColor(0x00AAF4);
  594. setReinforce(false);
  595. setHelpButton("/button/button_help2.png", true);
  596. return false;
  597. }
  598. }
  599. break;
  600. default:
  601. break;
  602. }
  603. return true;
  604. }
  605. /**
  606. * 有新的触摸事件时触发
  607. * 参数:ev
  608. * 新的触摸事件
  609. * 返回值:true
  610. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  611. * false
  612. * 触摸事件将继续传递到控件上
  613. */
  614. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  615. switch (ev.mActionStatus) {
  616. case MotionEvent::E_ACTION_DOWN://触摸按下
  617. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  618. break;
  619. case MotionEvent::E_ACTION_MOVE://触摸滑动
  620. break;
  621. case MotionEvent::E_ACTION_UP: //触摸抬起
  622. break;
  623. default:
  624. break;
  625. }
  626. return false;
  627. }
  628. static int getListItemCount_BedListView(const ZKListView *pListView) {
  629. //LOGD("getListItemCount_BedListView !\n");
  630. if (frameBedList.size() > 3) {
  631. return frameBedList.size();
  632. }
  633. return 3;
  634. }
  635. static void obtainListItemData_BedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  636. //LOGD(" obtainListItemData_ BedListView !!!\n");
  637. if (frameBedList.size() > 0) {
  638. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  639. // 用户相关
  640. string customerName = frameBedList[index]["customer_name"].asString();
  641. pListItem->findSubItemByID(ID_MAIN_CustomerName)->setText(customerName);
  642. pListItem->findSubItemByID(ID_MAIN_CustomerAge)->setText(frameBedList[index]["customer_age"].asString() + frameBedList[index]["customer_age_unit"].asString());
  643. string customerSex = frameBedList[index]["customer_sex"].asString();
  644. if (customerSex == "0") { // 如果性别为女性,则替换成女性头像,和女性的图标
  645. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_female.png");
  646. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_female.png");
  647. }
  648. else if (customerSex == "1") {
  649. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_male.png");
  650. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_male.png");
  651. }
  652. else {
  653. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_empty.png");
  654. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("");
  655. }
  656. // 医生护士相关
  657. if (rightTitleInfo["doctor_valid"] != 1){
  658. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setVisible(false);
  659. } else {
  660. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setText(rightTitleInfo["doctor_title"].asString());
  661. }
  662. if (rightTitleInfo["nurse_valid"] != 1){
  663. pListItem->findSubItemByID(ID_MAIN_NurseText)->setVisible(false);
  664. } else {
  665. pListItem->findSubItemByID(ID_MAIN_NurseText)->setText(rightTitleInfo["nurse_title"].asString());
  666. }
  667. pListItem->findSubItemByID(ID_MAIN_DoctorName)->setText(frameBedList[index]["doctor_name"].asString());
  668. pListItem->findSubItemByID(ID_MAIN_NurseName)->setText(frameBedList[index]["nurse_name"].asString());
  669. // 护理项相关
  670. Json::Value nurseConfigList = frameBedList[index]["nurse_config_dtos"];
  671. if (nurseConfigList.size() > 0) {
  672. for (int i = 0; i < 5; i++) {
  673. int nurseConfigColorNumber = ID_MAIN_NurseConfigColor1 + i;
  674. int nurseConfigNumber = ID_MAIN_NurseConfig1 + i * 2;
  675. int nurseOptionNumber = ID_MAIN_NurseOption1 + i * 2;
  676. if (nurseConfigList.size() >= i) {
  677. //颜色
  678. string nurseConfigColot = nurseConfigList[i]["nurse_color_rbg"].asString();
  679. uint32_t bgColor = 0xFFC0C0C0;
  680. if (nurseConfigColot != "") {
  681. string rgbStr = "FF" + nurseConfigColot;
  682. transform(rgbStr.begin(), rgbStr.end(), rgbStr.begin(), ::toupper);
  683. bgColor = strtoul(("0x" + rgbStr).c_str(), NULL,16);
  684. }
  685. pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(bgColor);
  686. pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  687. string nurseOptionName = nurseConfigList[i]["nurse_option_name"].asString();
  688. if (nurseOptionName == "") {
  689. nurseOptionName = LANGUAGEMANAGER->getValue("None");
  690. }
  691. pListItem->findSubItemByID(nurseOptionNumber)->setText(nurseOptionName);
  692. } else {
  693. //颜色
  694. pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(0xFFC0C0C0);
  695. pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  696. pListItem->findSubItemByID(nurseOptionNumber)->setText(LANGUAGEMANAGER->getValue("None"));
  697. }
  698. }
  699. }
  700. else {
  701. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor1)->setBackgroundColor(0xFFC0C0C0);
  702. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor2)->setBackgroundColor(0xFFC0C0C0);
  703. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor3)->setBackgroundColor(0xFFC0C0C0);
  704. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor4)->setBackgroundColor(0xFFC0C0C0);
  705. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor5)->setBackgroundColor(0xFFC0C0C0);
  706. pListItem->findSubItemByID(ID_MAIN_NurseConfig1)->setText("");
  707. pListItem->findSubItemByID(ID_MAIN_NurseConfig2)->setText("");
  708. pListItem->findSubItemByID(ID_MAIN_NurseConfig3)->setText("");
  709. pListItem->findSubItemByID(ID_MAIN_NurseConfig4)->setText("");
  710. pListItem->findSubItemByID(ID_MAIN_NurseConfig5)->setText("");
  711. pListItem->findSubItemByID(ID_MAIN_NurseOption1)->setText(LANGUAGEMANAGER->getValue("None"));
  712. pListItem->findSubItemByID(ID_MAIN_NurseOption2)->setText(LANGUAGEMANAGER->getValue("None"));
  713. pListItem->findSubItemByID(ID_MAIN_NurseOption3)->setText(LANGUAGEMANAGER->getValue("None"));
  714. pListItem->findSubItemByID(ID_MAIN_NurseOption4)->setText(LANGUAGEMANAGER->getValue("None"));
  715. pListItem->findSubItemByID(ID_MAIN_NurseOption5)->setText(LANGUAGEMANAGER->getValue("None"));
  716. }
  717. }
  718. }
  719. static void onListItemClick_BedListView(ZKListView *pListView, int index, int id) {
  720. //LOGD(" onListItemClick_ BedListView !!!\n");
  721. }
  722. static bool onButtonClick_CallBedButton(ZKButton *pButton) {
  723. LOGD(" ButtonClick CallBedButton !!!\n");
  724. if (frameBedList.size() > 0) {
  725. mCallBebWinPtr->showWnd();
  726. } else {
  727. Intent* intent = new Intent();
  728. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedList"));
  729. EASYUICONTEXT->openActivity("warnActivity", intent);
  730. }
  731. return false;
  732. }
  733. static bool onButtonClick_CallNurseButton(ZKButton *pButton) {
  734. LOGD(" ButtonClick CallNurseButton !!!\n");
  735. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  736. int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT);
  737. std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT);
  738. std::string od_number = StoragePreferences::getString(SIP_REG_DOOR_ACCOUNT, SIP_REG_DOOR_ACCOUNT_DEFAULT);
  739. std::string od_number_uri = URI(od_number, domain, port);
  740. LOGD("od_number_uri: %s", od_number_uri.c_str());
  741. GetTelephone()->MakeCall(od_number_uri);
  742. } else {
  743. Intent* intent = new Intent();
  744. intent->putExtra(isOutgoing, "true");
  745. intent->putExtra(audioOnly, "true");
  746. EASYUICONTEXT->openActivity("callActivity", intent);
  747. }
  748. return false;
  749. }
  750. static bool onButtonClick_HelpButton(ZKButton *pButton) {
  751. LOGD(" ButtonClick HelpButton !!!\n");
  752. TcpModel tcpModel;
  753. tcpModel.type = TcpType::REINFORCE;
  754. tcpModel.action = ReinforceAction::CALL;
  755. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  756. tcpModel.to_id = 0;
  757. std::string req = getTcpModelString(tcpModel);
  758. LOGD("REINFORCE CALL : %s",req.c_str());
  759. // TcpClient::instance()->sendMsg(req.c_str());
  760. //回调注册
  761. TcpCallback callback;
  762. callback.tid = tcpModel.tid;
  763. callback.jsonStr = req;
  764. callback.onSuccess = [](Json::Value json){
  765. LOGD("callback success");
  766. return 0;
  767. };
  768. callback.onFalied = [](Json::Value json){
  769. LOGD("callback failed");
  770. return 0;
  771. };
  772. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  773. // setHelpButton("/button/button_help3.png" ,false);
  774. // SetPainterInfo(0xFF2F9DF1, "增援已发出");
  775. // setReinforce(true); // 设置增援状态为true
  776. // //1分钟后无响应还原颜色
  777. // if (!isHelpTimerRegistered){
  778. // mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 60000);
  779. // }
  780. setPainterInfo(StoragePreferences::getInt(STORE_DEVICE_ID,0), 0xFF2F9DF1, LANGUAGEMANAGER->getValue("HelpInfo"), "REINFORCE", "ADD", 60);
  781. return false;
  782. }
  783. static bool onButtonClick_CallCencelButton(ZKButton *pButton) {
  784. LOGD(" ButtonClick CallCencelButton !!!\n");
  785. // 发送tcp, tcp_type = VOICE, tcp_action = CANCEL_BY_DOOR
  786. TcpModel tcpModel;
  787. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  788. tcpModel.type = TcpType::VOICE;
  789. tcpModel.action = VoiceAction::CANCEL_BY_DOOR;
  790. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  791. tcpModel.to_id = NULL;
  792. std::string req = getTcpModelString(tcpModel);
  793. LOGD("TCP VOICE : %s",req.c_str());
  794. cencalByDoorTid = tcpModel.tid;
  795. //回调注册
  796. TcpCallback callback;
  797. callback.tid = tcpModel.tid;
  798. callback.jsonStr = req;
  799. callback.onSuccess = [](Json::Value json){
  800. LOGD("side callback success");
  801. return 0;
  802. };
  803. callback.onFalied = [](Json::Value json){
  804. LOGD("side callback failed");
  805. return 0;
  806. };
  807. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  808. return false;
  809. }
  810. static bool onButtonClick_NursingButton(ZKButton *pButton) {
  811. LOGD(" ButtonClick NursingButton !!!\n");
  812. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  813. std::string heartStr;
  814. if (color != "" && color.size() == 3) {
  815. heartStr = "DOORLED," + color + "F";
  816. } else {
  817. heartStr = "DOORLED,010F";
  818. }
  819. const char* sendMsg = heartStr.c_str();
  820. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  821. mFunctionWinPtr->showWnd();
  822. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  823. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  824. mFunctionBackPtr->setVisible(false);
  825. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING
  826. TcpModel tcpModel;
  827. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  828. tcpModel.type = TcpType::SIDE;
  829. tcpModel.action = SideAction::NURSING;
  830. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  831. tcpModel.to_id = NULL;
  832. std::string req = getTcpModelString(tcpModel);
  833. LOGD("TCP SIDE : %s",req.c_str());
  834. //回调注册
  835. TcpCallback callback;
  836. callback.tid = tcpModel.tid;
  837. callback.jsonStr = req;
  838. callback.onSuccess = [](Json::Value json){
  839. LOGD("side callback success");
  840. return 0;
  841. };
  842. callback.onFalied = [](Json::Value json){
  843. LOGD("side callback failed");
  844. return 0;
  845. };
  846. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  847. // 把护理状态缓存起来
  848. StoragePreferences::putBool(STORE_NURSING_TYPE, true);
  849. return false;
  850. }
  851. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  852. LOGD(" ButtonClick MoreButton !!!\n");
  853. EASYUICONTEXT->openActivity("ui3Activity");
  854. return false;
  855. }
  856. static bool onButtonClick_FunctionButton(ZKButton *pButton) {
  857. LOGD(" ButtonClick FunctionButton !!!\n");
  858. mFunctionWinPtr->hideWnd();
  859. StoragePreferences::putBool(STORE_NURSING_TYPE, false);
  860. std::string heartStr = "DOORLED,000F";
  861. const char* sendMsg = heartStr.c_str();
  862. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  863. if (nursingTcpModel.json.size() != 0) { // 对比一下,json里面不为空的时候
  864. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING_END
  865. TcpModel tcpModel;
  866. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  867. tcpModel.type = TcpType::SIDE;
  868. tcpModel.action = SideAction::NURSING_END;
  869. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  870. tcpModel.data = nursingTcpModel.json["id"].asString(); // 获取nursingTcpModel里,id字段的数据
  871. std::string req = getTcpModelString(tcpModel);
  872. LOGD("TCP NURSING_END : %s",req.c_str());
  873. //回调注册
  874. TcpCallback callback;
  875. callback.tid = tcpModel.tid;
  876. callback.jsonStr = req;
  877. callback.onSuccess = [](Json::Value json){
  878. LOGD("event callback success");
  879. return 0;
  880. };
  881. callback.onFalied = [](Json::Value json){
  882. LOGD("event callback failed");
  883. return 0;
  884. };
  885. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  886. TcpModel newTcpModel;
  887. nursingTcpModel = newTcpModel; // 清空nursingTcpModel
  888. }
  889. return false;
  890. }
  891. static bool onButtonClick_FunctionBack(ZKButton *pButton) {
  892. LOGD(" ButtonClick FunctionBack !!!\n");
  893. return false;
  894. }
  895. static int getListItemCount_CallBedListView(const ZKListView *pListView) {
  896. //LOGD("getListItemCount_CallBedListView !\n");
  897. return frameBedList.size();
  898. }
  899. static void obtainListItemData_CallBedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  900. //LOGD(" obtainListItemData_ CallBedListView !!!\n");
  901. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  902. pListItem->findSubItemByID(ID_MAIN_CallBedName)->setText(frameBedList[index]["customer_name"].asString());
  903. }
  904. static void onListItemClick_CallBedListView(ZKListView *pListView, int index, int id) {
  905. // LOGD(" onListItemClick_ CallBedListView !!!\n");
  906. string customerName = frameBedList[index]["customer_name"].asString();
  907. string toId = frameBedList[index]["bed_device_id"].asString();
  908. if (customerName == "") {
  909. Intent* intent = new Intent();
  910. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoCustomer"));
  911. EASYUICONTEXT->openActivity("warnActivity", intent);
  912. }
  913. else if (toId == "") {
  914. Intent* intent = new Intent();
  915. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedDevice"));
  916. EASYUICONTEXT->openActivity("warnActivity", intent);
  917. }
  918. else {
  919. mCallBebWinPtr->hideWnd();
  920. Intent* intent = new Intent();
  921. intent->putExtra(isOutgoing, "true");
  922. intent->putExtra(audioOnly, "true");
  923. intent->putExtra(toIdStr, toId);
  924. intent->putExtra(callName, frameBedList[index]["frame_bed"]["full_name"].asString() + " " + customerName);
  925. EASYUICONTEXT->openActivity("callActivity", intent);
  926. }
  927. }
  928. static bool onButtonClick_CallBedCancel(ZKButton *pButton) {
  929. LOGD(" ButtonClick CallBedCancel !!!\n");
  930. mCallBebWinPtr->hideWnd();
  931. return false;
  932. }