mainLogic.cc 47 KB

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