mainLogic.cc 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  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, 1);
  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, 1);
  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, 1) == 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.type = TcpType::REINFORCE;
  928. tcpModel.action = ReinforceAction::CALL;
  929. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  930. tcpModel.to_id = 0;
  931. std::string req = getTcpModelString(tcpModel);
  932. LOGD("REINFORCE CALL : %s",req.c_str());
  933. // TcpClient::instance()->sendMsg(req.c_str());
  934. //回调注册
  935. TcpCallback callback;
  936. callback.tid = tcpModel.tid;
  937. callback.jsonStr = req;
  938. callback.onSuccess = [](Json::Value json){
  939. LOGD("callback success");
  940. return 0;
  941. };
  942. callback.onFalied = [](Json::Value json){
  943. LOGD("callback failed");
  944. return 0;
  945. };
  946. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  947. // setHelpButton("/button/button_help3.png" ,false);
  948. // SetPainterInfo(0xFF2F9DF1, "增援已发出");
  949. // setReinforce(true); // 设置增援状态为true
  950. // //1分钟后无响应还原颜色
  951. // if (!isHelpTimerRegistered){
  952. // mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 60000);
  953. // }
  954. setPainterInfo(StoragePreferences::getInt(STORE_DEVICE_ID,0), 0xFF2F9DF1, LANGUAGEMANAGER->getValue("HelpInfo"), "REINFORCE", "ADD", 60);
  955. return false;
  956. }
  957. static bool onButtonClick_CallCencelButton(ZKButton *pButton) {
  958. LOGD(" ButtonClick CallCencelButton !!!\n");
  959. // 发送tcp, tcp_type = VOICE, tcp_action = CANCEL_BY_DOOR
  960. TcpModel tcpModel;
  961. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  962. tcpModel.type = TcpType::VOICE;
  963. tcpModel.action = VoiceAction::CANCEL_BY_DOOR;
  964. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  965. tcpModel.to_id = NULL;
  966. std::string req = getTcpModelString(tcpModel);
  967. LOGD("TCP VOICE : %s",req.c_str());
  968. cencalByDoorTid = tcpModel.tid;
  969. //回调注册
  970. TcpCallback callback;
  971. callback.tid = tcpModel.tid;
  972. callback.jsonStr = req;
  973. callback.onSuccess = [](Json::Value json){
  974. LOGD("side callback success");
  975. return 0;
  976. };
  977. callback.onFalied = [](Json::Value json){
  978. LOGD("side callback failed");
  979. return 0;
  980. };
  981. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  982. return false;
  983. }
  984. static bool onButtonClick_NursingButton(ZKButton *pButton) {
  985. LOGD(" ButtonClick NursingButton !!!\n");
  986. // std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  987. // std::string heartStr;
  988. // if (color != "" && color.size() == 3) {
  989. // heartStr = "DOORLED," + color + "F";
  990. // } else {
  991. // heartStr = "DOORLED,010F";
  992. // }
  993. // const char* sendMsg = heartStr.c_str();
  994. // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  995. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  996. if (color != "" && color.size() == 3) {
  997. color = color + "F";
  998. } else {
  999. color = "010F";
  1000. }
  1001. lightControl("DOORLED", color);
  1002. mFunctionWinPtr->showWnd();
  1003. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  1004. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  1005. mFunctionBackPtr->setVisible(false);
  1006. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING
  1007. TcpModel tcpModel;
  1008. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  1009. tcpModel.type = TcpType::SIDE;
  1010. tcpModel.action = SideAction::NURSING;
  1011. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  1012. tcpModel.to_id = NULL;
  1013. std::string req = getTcpModelString(tcpModel);
  1014. LOGD("TCP SIDE : %s",req.c_str());
  1015. //回调注册
  1016. TcpCallback callback;
  1017. callback.tid = tcpModel.tid;
  1018. callback.jsonStr = req;
  1019. callback.onSuccess = [](Json::Value json){
  1020. LOGD("side callback success");
  1021. return 0;
  1022. };
  1023. callback.onFalied = [](Json::Value json){
  1024. LOGD("side callback failed");
  1025. return 0;
  1026. };
  1027. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  1028. // 把护理状态缓存起来
  1029. StoragePreferences::putBool(STORE_NURSING_TYPE, true);
  1030. return false;
  1031. }
  1032. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  1033. LOGD(" ButtonClick MoreButton !!!\n");
  1034. EASYUICONTEXT->openActivity("ui3Activity");
  1035. return false;
  1036. }
  1037. static bool onButtonClick_FunctionButton(ZKButton *pButton) {
  1038. LOGD(" ButtonClick FunctionButton !!!\n");
  1039. mFunctionWinPtr->hideWnd();
  1040. sendNursingEnd();
  1041. return false;
  1042. }
  1043. static bool onButtonClick_FunctionBack(ZKButton *pButton) {
  1044. LOGD(" ButtonClick FunctionBack !!!\n");
  1045. return false;
  1046. }
  1047. static int getListItemCount_CallBedListView(const ZKListView *pListView) {
  1048. //LOGD("getListItemCount_CallBedListView !\n");
  1049. return frameBedList.size();
  1050. }
  1051. static void obtainListItemData_CallBedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  1052. //LOGD(" obtainListItemData_ CallBedListView !!!\n");
  1053. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  1054. pListItem->findSubItemByID(ID_MAIN_CallBedName)->setText(frameBedList[index]["customer_name"].asString());
  1055. }
  1056. static void onListItemClick_CallBedListView(ZKListView *pListView, int index, int id) {
  1057. // LOGD(" onListItemClick_ CallBedListView !!!\n");
  1058. string customerName = frameBedList[index]["customer_name"].asString();
  1059. string toId = frameBedList[index]["bed_device_id"].asString();
  1060. if (customerName == "") {
  1061. Intent* intent = new Intent();
  1062. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoCustomer"));
  1063. EASYUICONTEXT->openActivity("warnActivity", intent);
  1064. }
  1065. else if (toId == "") {
  1066. Intent* intent = new Intent();
  1067. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedDevice"));
  1068. EASYUICONTEXT->openActivity("warnActivity", intent);
  1069. }
  1070. else {
  1071. mCallBebWinPtr->hideWnd();
  1072. Intent* intent = new Intent();
  1073. intent->putExtra(isOutgoing, "true");
  1074. intent->putExtra(audioOnly, "true");
  1075. intent->putExtra(toIdStr, toId);
  1076. intent->putExtra(callName, frameBedList[index]["frame_bed"]["full_name"].asString() + " " + customerName);
  1077. EASYUICONTEXT->openActivity("callActivity", intent);
  1078. }
  1079. }
  1080. static bool onButtonClick_CallBedCancel(ZKButton *pButton) {
  1081. LOGD(" ButtonClick CallBedCancel !!!\n");
  1082. mCallBebWinPtr->hideWnd();
  1083. return false;
  1084. }