mainLogic.cc 38 KB

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