mainLogic.cc 47 KB

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