mainLogic.cc 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include "net/NetManager.h"
  4. #include "storage/StoragePreferences.h"
  5. #include "net/net.h"
  6. #include <system/Thread.h>
  7. #include "restclient-cpp/restclient.h"
  8. #include "curl/curl.h"
  9. #include <algorithm>
  10. #include "service/BusinessConfig.h"
  11. #include "core/sip_config.h"
  12. #include "manager/LanguageManager.h"
  13. #include "core/utilities.h"
  14. #include <string>
  15. #include "zkaudio.h"
  16. #include "base/strings.hpp"
  17. #include "base/http_client.h"
  18. #include "os/UpgradeMonitor.h"
  19. #include "core/update_assistant.h"
  20. #include "utils/TimeHelper.h"
  21. #define ETHERNETMANAGER NETMANAGER->getEthernetManager()
  22. #define WIFIMANAGER NETMANAGER->getWifiManager()
  23. /*
  24. *此文件由GUI工具生成
  25. *文件功能:用于处理用户的逻辑相应代码
  26. *功能说明:
  27. *========================onButtonClick_XXXX
  28. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  29. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  30. *========================onSlideWindowItemClick_XXXX(int index)
  31. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  32. 如slideWindow1;index 代表按下图标的偏移值
  33. *========================onSeekBarChange_XXXX(int progress)
  34. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  35. 如SeekBar1;progress 代表当前的进度值
  36. *========================ogetListItemCount_XXXX()
  37. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  38. 如List1;返回值为当前列表的总条数
  39. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  40. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  41. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  42. *========================常用接口===============
  43. *LOGD(...) 打印调试信息的接口
  44. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  45. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  46. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  47. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  48. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  49. *
  50. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  51. */
  52. static bool dataInit = false; // false表示需要从数据库里获取数据,true表示从缓存里获取数据
  53. PartSetting partSetting;
  54. Json::Value frameRoom;
  55. Json::Value frameBedList;
  56. Json::Value frameInfo; // 缓存房间名字等
  57. Json::Value rightTitleInfo; // 缓存分机右边医生和护士标题
  58. Json::Value painterInfo;
  59. Json::Value painterInfoList;
  60. static bool serverInfo = true; // 判断是否需要从服务器获取服务器信息,第一次要,后续不要
  61. static int inBedCount = 0;
  62. static int emptyBedCount = 0;
  63. static int themeInt = 1;
  64. static int modeInt = 1;
  65. #define HELP_TIMER_HANDLE 3 // 增援的定时器id
  66. #define EVENT_TIME_HANDLE 8 // 事件定时器
  67. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  68. void setMainTheme() {
  69. themeInt = StoragePreferences::getInt(STORE_THEME, defaultThemeInt);
  70. LOGD("themeInt =====> %d", themeInt);
  71. if (themeInt == 1) {
  72. mRoomPainterPtr->setBackgroundPic("/main/roomBg.png");
  73. mRoomPrcPainterPtr->setBackgroundPic("/main/fang.png");
  74. mInBedNumTextViewPtr->setTextColor(buleDeepColour);
  75. mInBedPicPainterPtr->setBackgroundPic("/main/chuang-l.png");
  76. }
  77. else if (themeInt == 2) {
  78. mRoomPainterPtr->setBackgroundPic("/main/roomBg-pink.png");
  79. mRoomPrcPainterPtr->setBackgroundPic("/main/fang-pink.png");
  80. mInBedNumTextViewPtr->setTextColor(redDeepColour);
  81. mInBedPicPainterPtr->setBackgroundPic("/main/chuang-l-pink.png");
  82. }
  83. else if (themeInt == 3) {
  84. mRoomPainterPtr->setBackgroundPic("/main/roomBg-green.png");
  85. mRoomPrcPainterPtr->setBackgroundPic("/main/fang-green.png");
  86. mInBedNumTextViewPtr->setTextColor(yellowDeepColour);
  87. mInBedPicPainterPtr->setBackgroundPic("/main/chuang-l-yellow.png");
  88. }
  89. }
  90. void setMainMode() {
  91. modeInt = StoragePreferences::getInt(STORE_MODE, defaultModeInt);
  92. if (modeInt == 1) {
  93. mBedListViewPtr->setVisible(true);
  94. mBedListView2Ptr->setVisible(false);
  95. }
  96. else if (modeInt == 2) {
  97. mBedListViewPtr->setVisible(false);
  98. mBedListView2Ptr->setVisible(true);
  99. }
  100. }
  101. static net::Conn* udpConn;
  102. class UdpThread: public Thread {
  103. public:
  104. static void getServerInfo(){
  105. string url = getHttpGateway() + "/ncs_url/server_info";
  106. LOGD("请求服务器信息. url = %s", url.c_str());
  107. //发起HTTP GET请求
  108. RestClient::Response r = RestClient::get(url);
  109. //解析json
  110. Json::Reader reader;
  111. Json::Value root;
  112. if (reader.parse(r.body, root, false)){
  113. // http
  114. StoragePreferences::putString(STORE_GATEWAY, root["http_local_ip"].asString());
  115. StoragePreferences::putInt(STORE_HTTP_PORT, root["http_port"].asInt());
  116. // tcp
  117. StoragePreferences::putString(STORE_TCP_LOCAL_IP, root["tcp_local_ip"].asString());
  118. StoragePreferences::putInt(STORE_TCP_PORT, root["tcp_port"].asInt());
  119. // sip
  120. StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString());
  121. StoragePreferences::putInt(SIP_REG_PORT, root["sip_port"].asInt());
  122. serverInfo = false; // 只有请求成功了,才不需要重复请求
  123. }
  124. }
  125. static void getDeviceInfo(){
  126. if (dataInit){
  127. getFrameInfo();
  128. getBedCount();
  129. return;
  130. }
  131. if (!isConnectServer()) {
  132. return;
  133. }
  134. string url = getHttpGateway() + "/deviceRoom/get_device_by_eth_mac/" + StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0");
  135. LOGD("请求设备信息. url = %s", url.c_str());
  136. //发起HTTP GET请求
  137. RestClient::Response r = RestClient::get(url);
  138. LOGD("获得设备信息. result = %s", r.body.c_str());
  139. //解析json
  140. Json::Reader reader;
  141. Json::Value root;
  142. if (reader.parse(r.body, root, false)){
  143. string partName = root["part_display"].asString();
  144. StoragePreferences::putString(STORE_PARTNAME,partName);
  145. NavibarSetPartName(partName);
  146. //设备
  147. StoragePreferences::putInt(STORE_DEVICE_ID, root["id"].asInt());
  148. StoragePreferences::putInt(STORE_DEVICE_TYPE, root["device_type"].asInt());
  149. //SIP存储
  150. // StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); // 应该去找配置文件里的sip-ip
  151. StoragePreferences::putString(SIP_REG_ACCOUNT,root["sip_id"].asString());
  152. StoragePreferences::putString(SIP_REG_PASSWORD, root["sip_password"].asString());
  153. frameInfo["frame_id"] = root["frame_id"].asInt();
  154. frameInfo["full_name"] = root["full_name"].asString();
  155. frameInfo["part_id"] = root["part_id"].asInt();
  156. getFrameInfo();
  157. //获取科室设置
  158. string partId = root["part_id"].asString();
  159. StoragePreferences::putString(STORE_PARTID, partId);
  160. getPartSetting(partId);
  161. getVersion();
  162. getNfcInteraction();
  163. }
  164. }
  165. static void getFrameRoom(int frame_id) {
  166. string url = getHttpGateway() + "/deviceRoom/get_frame_room/" + to_string(frame_id);
  167. LOGD("请求房间信息. url = %s", url.c_str());
  168. //发起HTTP GET请求
  169. RestClient::Response r = RestClient::get(url);
  170. LOGD("获得房间信息. result = %s", r.body.c_str());
  171. //解析json
  172. Json::Reader reader;
  173. Json::Value root;
  174. if (reader.parse(r.body, root, false)){
  175. frameRoom = root;
  176. frameBedList = root["frame_bed_list"];
  177. inBedCount = 0;
  178. emptyBedCount = 0;
  179. if (frameBedList.size() > 0) {
  180. for (int i = 0; i < frameBedList.size(); i++) {
  181. string customerId = frameBedList[i]["customer_id"].asString();
  182. if (customerId != "") {
  183. inBedCount += 1;
  184. }
  185. }
  186. emptyBedCount = frameBedList.size() - inBedCount;
  187. getBedCount();
  188. }
  189. if (mBedListViewPtr != NULL) {
  190. mBedListViewPtr->refreshListView();
  191. }
  192. }
  193. }
  194. // 读取空间缓存的数据
  195. static void getFrameInfo() {
  196. mRoomNameTextViewPtr->setText(frameInfo["full_name"].asString());
  197. }
  198. static void getBedCount() {
  199. if (mActivityPtr == NULL) {
  200. return;
  201. }
  202. mInBedNumTextViewPtr->setText(inBedCount);
  203. mEmptyBedNumTextViewPtr->setText(emptyBedCount);
  204. }
  205. // 将医生和护士别称缓存起来
  206. static void setRightTitle(Json::Value partSetting) {
  207. rightTitleInfo["doctor_title"] = partSetting["doctor_title"].asString();
  208. rightTitleInfo["doctor_valid"] = partSetting["doctor_valid"].asInt();
  209. rightTitleInfo["nurse_title"] = partSetting["nurse_title"].asString();
  210. rightTitleInfo["nurse_valid"] = partSetting["nurse_valid"].asInt();
  211. }
  212. static void getPartSetting(string partId){
  213. string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId;
  214. LOGD("请求科室信息. url = %s", url.c_str());
  215. //发起HTTP GET请求
  216. RestClient::Response r = RestClient::get(url);
  217. LOGD("获得科室信息. result = %s", r.body.c_str());
  218. //解析json
  219. Json::Reader reader;
  220. Json::Value root;
  221. if (reader.parse(r.body, root, false)){
  222. partSetting.partId = root["part_id"].asInt();
  223. partSetting.dayStart = root["day_start"].asString();
  224. partSetting.dayLight = root["day_light"].asInt();
  225. partSetting.dayVol = root["day_vol"].asInt();
  226. partSetting.dayRingVol = root["day_ring_vol"].asInt();
  227. partSetting.dayRingTimes = root["day_ring_times"].asInt();
  228. partSetting.dayNurseLed = root["day_nurse_led"].asInt();
  229. partSetting.dayDoorVol = root["day_door_vol"].asInt();
  230. partSetting.dayBedVol = root["day_bed_vol"].asInt();
  231. partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt();
  232. partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt();
  233. partSetting.nightStart = root["night_start"].asString();
  234. partSetting.nightLight = root["night_light"].asInt();
  235. partSetting.nightVol = root["night_vol"].asInt();
  236. partSetting.nightRingVol = root["night_ring_vol"].asInt();
  237. partSetting.nightRingTimes = root["night_ring_times"].asInt();
  238. partSetting.nightNurseLed = root["night_nurse_led"].asInt();
  239. partSetting.nightDoorVol = root["night_door_vol"].asInt();
  240. partSetting.nightBedVol = root["night_bed_vol"].asInt();
  241. partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt();
  242. partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt();
  243. partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt();
  244. partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt();
  245. partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt();
  246. partSetting.sipOvertime = root["sip_overtime"].asInt();
  247. partSetting.transferDuration = root["transfer_duration"].asInt();
  248. partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt();
  249. partSetting.communicationModeBed = root["communication_mode_bed"].asInt();
  250. partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt();
  251. partSetting.communicationModeMobile = root["communication_model_mobile"].asInt();
  252. partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt();
  253. partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt();
  254. partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt();
  255. partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt();
  256. partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt();
  257. partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt();
  258. partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString();
  259. partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt();
  260. partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString();
  261. partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt();
  262. partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString();
  263. partSetting.doctorTitle = root["doctor_title"].asString();
  264. partSetting.doctorValid = root["doctor_valid"].asInt();
  265. partSetting.nurseTitle = root["nurse_title"].asString();
  266. partSetting.nurseValid = root["nurse_valid"].asInt();
  267. partSetting.doorNurseTitle = root["door_nurse_title"].asString();
  268. partSetting.doorNurseValid = root["door_nurse_valid"].asInt();
  269. partSetting.doorNursingTitle = root["door_nursing_title"].asString();
  270. partSetting.doorNursingValid = root["door_nursing_valid"].asInt();
  271. partSetting.upSeconds = root["up_seconds"].asInt();
  272. partSetting.autoAccept = root["auto_accept"].asInt();
  273. partSetting.eventForward = root["event_forward"].asInt();
  274. partSetting.nursingColorRgb = root["nursing_color_rgb"].asString();
  275. partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt();
  276. partSetting.qrUrl = root["qr_url"].asString();
  277. partSetting.screenLight = root["screen_light"].asInt();
  278. partSetting.roomCallBed = root["room_call_bed"].asInt();
  279. partSetting.autoPosition = root["auto_position"].asInt();
  280. partSetting.customerAgeHiddenOnDoor = root["customer_age_hidden_on_door"].asInt();
  281. if (root.isMember("linux_bed_volume_native")) {
  282. partSetting.linuxDoorVolumeNative = root["linux_door_volume_native"].asInt();
  283. partSetting.linuxDoorGainSize = root["linux_door_gain_size"].asInt();
  284. zk_audio_input_set_volume_native(0, 0);
  285. zk_audio_input_set_volume_native(1, partSetting.linuxDoorVolumeNative);
  286. GetTelephone()->SetInputPcmGainSize(partSetting.linuxDoorGainSize);
  287. StoragePreferences::putInt(STORE_VOLUME_NATIVE, partSetting.linuxDoorVolumeNative);
  288. StoragePreferences::putInt(STORE_GAIN_SIZE, partSetting.linuxDoorGainSize);
  289. }
  290. StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart);
  291. StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight);
  292. StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol);
  293. StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes);
  294. StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart);
  295. StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight);
  296. StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol);
  297. StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes);
  298. StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsDoor);
  299. StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle);
  300. StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1);
  301. StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle);
  302. StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1);
  303. StoragePreferences::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb);
  304. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  305. StoragePreferences::putInt(STORE_SCREEN_LIGHT, partSetting.screenLight);
  306. StoragePreferences::putInt(STORE_ROOM_CALL_BED, partSetting.roomCallBed);
  307. StoragePreferences::putInt(STORE_AUTO_POSITION, partSetting.autoPosition);
  308. setRightTitle(root);
  309. callBedButtonSetVisible();
  310. getFrameRoom(frameInfo["frame_id"].asInt());
  311. dataInit = true;
  312. }
  313. }
  314. static void getVersion() {
  315. std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=403&part_id=" + StoragePreferences::getString(STORE_PARTID, "");
  316. std::string content_type = std::string("application/json");
  317. LOGD("请求版本信息. url = %s", url.c_str());
  318. //发起HTTP POST请求
  319. RestClient::Response r = RestClient::post(url, content_type, "");
  320. if (r.code != 200) {
  321. LOGD("请求版本信息-> 错误代码: %d", r.code);
  322. return;
  323. }
  324. LOGD("获得版本信息. result = %s", r.body.c_str());
  325. //解析json
  326. Json::Reader reader;
  327. Json::Value root;
  328. if(reader.parse(r.body, root, false)) {
  329. int currentVersionNo = getVersionNo();
  330. int responseVersionNo = root["version_no"].asInt();
  331. std::string responseVersion = root["version_code"].asString();
  332. LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo);
  333. if (currentVersionNo < responseVersionNo) {
  334. Intent* intent = new Intent();
  335. intent->putExtra(appUpdate, "true");
  336. EASYUICONTEXT->openActivity("updateActivity", intent);
  337. }
  338. }
  339. }
  340. static void getNfcInteraction() {
  341. std::string url = getHttpGateway() + "/deviceRoom/get_nfc_interaction_end_time_is_null/" + to_string(StoragePreferences::getInt(STORE_DEVICE_ID,0));
  342. LOGD("请求未完成的nfc记录. url = %s", url.c_str());
  343. //发起HTTP POST请求
  344. RestClient::Response r = RestClient::get(url);
  345. if (r.code != 200) {
  346. LOGD("请求未完成的nfc记录-> 错误代码: %d", r.code);
  347. return;
  348. }
  349. LOGD("获得未完成的nfc记录. result = %s", r.body.c_str());
  350. //解析json
  351. Json::Reader reader;
  352. Json::Value root;
  353. if(reader.parse(r.body, root, false)) {
  354. int clerkId = 0;
  355. for (int i = 0; i < root.size(); i++) {
  356. if (root[i]["components_type"].asCString() == TcpType::AUTH) {
  357. clerkId = root[i]["clerk_id"].asInt();
  358. setClerk(root[i]["clerk_name"].asCString(), root[i]["pass_no"].asCString(), root[i]["id"].asInt());
  359. }
  360. else if (root[i]["components_type"].asString() == "POSITION_COMPONENT") {
  361. setPosistionItId(root[i]["id"].asInt());
  362. setPositionButton(true);
  363. }
  364. else if (root[i]["components_type"].asString() == "ROOMCHECK_COMPONENT") {
  365. setRoomCheckItId(root[i]["id"].asInt());
  366. setRoomPatrolButton(true);
  367. }
  368. else if (root[i]["components_type"].asString() == "SCREEN_TIP_SET_COMPONENT") {
  369. time_t now = TimeHelper::getDateline();
  370. if (now <= 0) {
  371. continue;
  372. }
  373. Json::Reader Reader;
  374. Json::Value operationData;
  375. Reader.parse(root[i]["operation_data"].asString(), operationData);
  376. int seconds = operationData["seconds"].asInt();
  377. if (now - root[i]["start_time"].asInt() < seconds) {
  378. setPromptTimeItId(root[i]["id"].asInt());
  379. Intent* intent = new Intent();
  380. intent->putExtra(promptText2, operationData["tips"].asString());
  381. intent->putExtra(promptTime2, to_string(seconds - (now - root[i]["start_time"].asInt())));
  382. EASYUICONTEXT->openActivity("promptActivity", intent);
  383. }
  384. else {
  385. sendPromptQuit(root[i]["id"].asInt());
  386. }
  387. }
  388. }
  389. if (clerkId != 0) {
  390. goCare();
  391. }
  392. }
  393. }
  394. /**
  395. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  396. * return true 继续线程
  397. * false 退出线程
  398. */
  399. virtual bool readyToRun() {
  400. LOGD("Thread 已经创建完成");
  401. return true;
  402. }
  403. /**
  404. * 线程循环函数
  405. *
  406. * return true 继续线程循环
  407. * false 推出线程
  408. */
  409. virtual bool threadLoop() {
  410. LOGD("线程循环函数");
  411. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  412. if (exitPending()) {
  413. return false;
  414. }
  415. udpConn = net::Dial("udp", "192.168.1.255:10010");
  416. if (udpConn) {
  417. byte buf[1024] = {0};
  418. const char* req = "search_server";
  419. //发送
  420. udpConn->Write((byte*)req, strlen(req));
  421. while (true && !exitPending()) {
  422. //读取,超时10*1000毫秒
  423. int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000);
  424. if (n > 0) {
  425. buf[n] = 0;
  426. char serverStr[1024];
  427. sprintf(serverStr,"%s",buf);
  428. LOGD("读取 %d字节: %s", n, serverStr);
  429. //解析json
  430. Json::Reader reader;
  431. Json::Value root;
  432. if (reader.parse(serverStr, root, false)){
  433. if (root.isMember("success") && root["success"].asBool()){
  434. serverIP = root["data"]["third_server"].asString();
  435. serverHttpPort = root["data"]["third_server_port"].asInt();
  436. StoragePreferences::putString(STORE_GATEWAY, serverIP);
  437. StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort);
  438. //先获取服务器信息
  439. //getServerInfo();
  440. //就当在获取服务器信息完成后获取用户信息,这里测试用
  441. //getCustomerInfo();
  442. //退出UDP线程
  443. pthread_exit(NULL);
  444. break;
  445. }
  446. }
  447. } else if (n == 0) {
  448. LOGD("连接正常断开");
  449. break;
  450. } else if (n == net::E_TIMEOUT) {
  451. udpConn->Write((byte*)req, strlen(req));
  452. LOGD("读取超时");
  453. } else {
  454. LOGD("出错");
  455. break;
  456. }
  457. }
  458. //关闭连接
  459. udpConn->Close();
  460. //释放内存
  461. delete udpConn;
  462. udpConn = NULL;
  463. }
  464. //返回真,继续下次线程循环
  465. return true;
  466. }
  467. };
  468. static UdpThread udp_thread;
  469. Json::Value getFrame() {
  470. return frameRoom;
  471. }
  472. // 收到tcp的时候,刷新数据
  473. void dataRefresh() {
  474. LOGD("DATA-REFRESH, 数据刷新");
  475. if (mActivityPtr == NULL) {
  476. return;
  477. }
  478. if (serverInfo) {
  479. udp_thread.getServerInfo();
  480. }
  481. dataInit = false;
  482. udp_thread.getDeviceInfo();
  483. mBedListViewPtr->refreshListView();
  484. }
  485. void getPartSetting() {
  486. udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  487. }
  488. /**
  489. * 注册定时器
  490. * 填充数组用于注册定时器
  491. * 注意:id不能重复
  492. */
  493. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  494. //{0, 6000}, //定时器id=0, 时间间隔6秒
  495. //{1, 1000},
  496. };
  497. /**
  498. * 当界面构造时触发
  499. */
  500. static void onUI_init(){
  501. //run("this is thread name");
  502. //测试用
  503. LOGD("进入mainLogic页面, 触发 onUI_init");
  504. if(serverInfo && isConnectServer()) { // 如果是false,就是不需要
  505. udp_thread.getServerInfo();
  506. }
  507. udp_thread.getDeviceInfo();
  508. }
  509. /**
  510. * 当切换到该界面时触发
  511. */
  512. static void onUI_intent(const Intent *intentPtr) {
  513. if (intentPtr != NULL) {
  514. }
  515. }
  516. /*
  517. * 当界面显示时触发
  518. */
  519. static void onUI_show() {
  520. EASYUICONTEXT->showStatusBar();
  521. EASYUICONTEXT->showNaviBar();
  522. setMainTheme();
  523. setMainMode();
  524. }
  525. /*
  526. * 当界面隐藏时触发
  527. */
  528. static void onUI_hide() {
  529. }
  530. /*
  531. * 当界面完全退出时触发
  532. */
  533. static void onUI_quit() {
  534. //pthread_exit(NULL);
  535. }
  536. /**
  537. * 串口数据回调接口
  538. */
  539. static void onProtocolDataUpdate(const SProtocolData &data) {
  540. }
  541. /**
  542. * 定时器触发函数
  543. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  544. * 参数: id
  545. * 当前所触发定时器的id,与注册时的id相同
  546. * 返回值: true
  547. * 继续运行当前定时器
  548. * false
  549. * 停止运行当前定时器
  550. */
  551. static bool onUI_Timer(int id){
  552. switch (id) {
  553. default:
  554. break;
  555. }
  556. return true;
  557. }
  558. /**
  559. * 有新的触摸事件时触发
  560. * 参数:ev
  561. * 新的触摸事件
  562. * 返回值:true
  563. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  564. * false
  565. * 触摸事件将继续传递到控件上
  566. */
  567. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  568. switch (ev.mActionStatus) {
  569. case MotionEvent::E_ACTION_DOWN://触摸按下
  570. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  571. break;
  572. case MotionEvent::E_ACTION_MOVE://触摸滑动
  573. break;
  574. case MotionEvent::E_ACTION_UP: //触摸抬起
  575. break;
  576. default:
  577. break;
  578. }
  579. return false;
  580. }
  581. static int getListItemCount_BedListView(const ZKListView *pListView) {
  582. //LOGD("getListItemCount_BedListView !\n");
  583. return frameBedList.size();
  584. }
  585. static void obtainListItemData_BedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  586. //LOGD(" obtainListItemData_ BedListView !!!\n");
  587. if (modeInt != 1) {
  588. return;
  589. }
  590. if (frameBedList.size() > 0) {
  591. ZKListView::ZKListSubItem* bedNum = pListItem->findSubItemByID(ID_MAIN_BedNumSubItem);
  592. ZKListView::ZKListSubItem* name = pListItem->findSubItemByID(ID_MAIN_CustomerNameSubItem);
  593. ZKListView::ZKListSubItem* age = pListItem->findSubItemByID(ID_MAIN_AgeSubItem);
  594. ZKListView::ZKListSubItem* sex = pListItem->findSubItemByID(ID_MAIN_SexSubItem);
  595. ZKListView::ZKListSubItem* doctorTitle = pListItem->findSubItemByID(ID_MAIN_DoctorTitleSubItem);
  596. ZKListView::ZKListSubItem* nurseTitle = pListItem->findSubItemByID(ID_MAIN_NurseTitleSubItem);
  597. ZKListView::ZKListSubItem* doctor = pListItem->findSubItemByID(ID_MAIN_DoctorSubItem);
  598. ZKListView::ZKListSubItem* nurse = pListItem->findSubItemByID(ID_MAIN_NurseSubItem);
  599. if (themeInt == 1) {
  600. bedNum->setBackgroundPic("/main/bedNameBg.png");
  601. }
  602. else if (themeInt == 2) {
  603. bedNum->setBackgroundPic("/main/bedNameBg-pink.png");
  604. }
  605. else if (themeInt == 3) {
  606. bedNum->setBackgroundPic("/main/bedNameBg-green.png");
  607. }
  608. string frameBedName = frameBedList[index]["frame_bed"]["full_name"].asString();
  609. if (frameBedName == "") {
  610. bedNum->setText(LANGUAGEMANAGER->getValue("EmptyBed"));
  611. } else {
  612. int nPos = frameBedName.find("-");
  613. if (nPos != -1) {
  614. frameBedName = frameBedName.substr(nPos + 1, frameBedName.length());
  615. }
  616. bedNum->setText(frameBedName);
  617. }
  618. // 用户相关
  619. string customerName = frameBedList[index]["customer_name"].asString();
  620. if (customerName == "") {
  621. name->setText(LANGUAGEMANAGER->getValue("EmptyCustomer"));
  622. } else {
  623. name->setText(customerName);
  624. }
  625. if (partSetting.customerAgeHiddenOnDoor != 0) {
  626. if (frameBedList[index]["customer_age"].asString() == "") {
  627. age->setText("");
  628. } else {
  629. age->setText("*" + frameBedList[index]["customer_age_unit"].asString());
  630. }
  631. }
  632. else {
  633. age->setText(frameBedList[index]["customer_age"].asString() + frameBedList[index]["customer_age_unit"].asString());
  634. }
  635. string customerSex = frameBedList[index]["customer_sex"].asString();
  636. if (customerSex == "0") { // 如果性别为女性,替换成女性,底色为粉色
  637. sex->setText(LANGUAGEMANAGER->getValue("Woman"));
  638. sex->setTextColor(0xFF9F9F);
  639. sex->setBackgroundPic("main/woman.png");
  640. }
  641. else if (customerSex == "1") {
  642. sex->setText(LANGUAGEMANAGER->getValue("Man"));
  643. sex->setTextColor(0x3A78EF);
  644. sex->setBackgroundPic("main/man.png");
  645. }
  646. else {
  647. sex->setText(LANGUAGEMANAGER->getValue("Unknown"));
  648. sex->setTextColor(0x37B643);
  649. sex->setBackgroundPic("main/age.png");
  650. }
  651. // 医生护士相关
  652. if (rightTitleInfo["doctor_valid"] != 1){
  653. doctorTitle->setVisible(false);
  654. } else {
  655. doctorTitle->setText(rightTitleInfo["doctor_title"].asString());
  656. }
  657. if (rightTitleInfo["nurse_valid"] != 1){
  658. nurseTitle->setVisible(false);
  659. } else {
  660. nurseTitle->setText(rightTitleInfo["nurse_title"].asString());
  661. }
  662. doctor->setText(frameBedList[index]["doctor_name"].asString());
  663. nurse->setText(frameBedList[index]["nurse_name"].asString());
  664. // // 护理项相关
  665. // Json::Value nurseConfigList = frameBedList[index]["nurse_config_dtos"];
  666. // if (nurseConfigList.size() > 0) {
  667. // for (int i = 0; i < 5; i++) {
  668. // int nurseConfigColorNumber = ID_MAIN_NurseConfigColor1 + i;
  669. // int nurseConfigNumber = ID_MAIN_NurseConfig1 + i * 2;
  670. // int nurseOptionNumber = ID_MAIN_NurseOption1 + i * 2;
  671. // if (nurseConfigList.size() >= i) {
  672. // //颜色
  673. // string nurseConfigColot = nurseConfigList[i]["nurse_color_rbg"].asString();
  674. // uint32_t bgColor = 0xFFC0C0C0;
  675. // if (nurseConfigColot != "") {
  676. // string rgbStr = "FF" + nurseConfigColot;
  677. // transform(rgbStr.begin(), rgbStr.end(), rgbStr.begin(), ::toupper);
  678. // bgColor = strtoul(("0x" + rgbStr).c_str(), NULL,16);
  679. // }
  680. // pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(bgColor);
  681. // pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  682. // string nurseOptionName = nurseConfigList[i]["nurse_option_name"].asString();
  683. // if (nurseOptionName == "") {
  684. // nurseOptionName = LANGUAGEMANAGER->getValue("None");
  685. // }
  686. // pListItem->findSubItemByID(nurseOptionNumber)->setText(nurseOptionName);
  687. //
  688. // } else {
  689. // //颜色
  690. // pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(0xFFC0C0C0);
  691. // pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  692. // pListItem->findSubItemByID(nurseOptionNumber)->setText(LANGUAGEMANAGER->getValue("None"));
  693. // }
  694. // }
  695. // }
  696. // else {
  697. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor1)->setBackgroundColor(0xFFC0C0C0);
  698. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor2)->setBackgroundColor(0xFFC0C0C0);
  699. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor3)->setBackgroundColor(0xFFC0C0C0);
  700. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor4)->setBackgroundColor(0xFFC0C0C0);
  701. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor5)->setBackgroundColor(0xFFC0C0C0);
  702. // pListItem->findSubItemByID(ID_MAIN_NurseConfig1)->setText("");
  703. // pListItem->findSubItemByID(ID_MAIN_NurseConfig2)->setText("");
  704. // pListItem->findSubItemByID(ID_MAIN_NurseConfig3)->setText("");
  705. // pListItem->findSubItemByID(ID_MAIN_NurseConfig4)->setText("");
  706. // pListItem->findSubItemByID(ID_MAIN_NurseConfig5)->setText("");
  707. // pListItem->findSubItemByID(ID_MAIN_NurseOption1)->setText(LANGUAGEMANAGER->getValue("None"));
  708. // pListItem->findSubItemByID(ID_MAIN_NurseOption2)->setText(LANGUAGEMANAGER->getValue("None"));
  709. // pListItem->findSubItemByID(ID_MAIN_NurseOption3)->setText(LANGUAGEMANAGER->getValue("None"));
  710. // pListItem->findSubItemByID(ID_MAIN_NurseOption4)->setText(LANGUAGEMANAGER->getValue("None"));
  711. // pListItem->findSubItemByID(ID_MAIN_NurseOption5)->setText(LANGUAGEMANAGER->getValue("None"));
  712. // }
  713. }
  714. }
  715. static void onListItemClick_BedListView(ZKListView *pListView, int index, int id) {
  716. //LOGD(" onListItemClick_ BedListView !!!\n");
  717. }
  718. static int getListItemCount_BedListView2(const ZKListView *pListView) {
  719. //LOGD("getListItemCount_BedListView2 !\n");
  720. return frameBedList.size();
  721. }
  722. static void obtainListItemData_BedListView2(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  723. //LOGD(" obtainListItemData_ BedListView2 !!!\n");
  724. if (modeInt != 2) {
  725. return;
  726. }
  727. if (frameBedList.size() > 0) {
  728. ZKListView::ZKListSubItem* bedNum = pListItem->findSubItemByID(ID_MAIN_BedNumSubItem2);
  729. ZKListView::ZKListSubItem* name = pListItem->findSubItemByID(ID_MAIN_CustomerNameSubItem2);
  730. ZKListView::ZKListSubItem* age = pListItem->findSubItemByID(ID_MAIN_AgeSubItem2);
  731. ZKListView::ZKListSubItem* sex = pListItem->findSubItemByID(ID_MAIN_SexSubItem2);
  732. ZKListView::ZKListSubItem* doctorTitle = pListItem->findSubItemByID(ID_MAIN_DoctorTitleSubItem2);
  733. ZKListView::ZKListSubItem* nurseTitle = pListItem->findSubItemByID(ID_MAIN_NurseTitleSubItem2);
  734. ZKListView::ZKListSubItem* doctor = pListItem->findSubItemByID(ID_MAIN_DoctorSubItem2);
  735. ZKListView::ZKListSubItem* nurse = pListItem->findSubItemByID(ID_MAIN_NurseSubItem2);
  736. if (themeInt == 1) {
  737. bedNum->setBackgroundPic("/main/bedNameBg2.png");
  738. }
  739. else if (themeInt == 2) {
  740. bedNum->setBackgroundPic("/main/bedNameBg2-pink.png");
  741. }
  742. else if (themeInt == 3) {
  743. bedNum->setBackgroundPic("/main/bedNameBg2-green.png");
  744. }
  745. string frameBedName = frameBedList[index]["frame_bed"]["full_name"].asString();
  746. if (frameBedName == "") {
  747. bedNum->setText(LANGUAGEMANAGER->getValue("EmptyBed"));
  748. } else {
  749. int nPos = frameBedName.find("-");
  750. if (nPos != -1) {
  751. frameBedName = frameBedName.substr(nPos + 1, frameBedName.length());
  752. }
  753. bedNum->setText(frameBedName);
  754. }
  755. // 用户相关
  756. string customerName = frameBedList[index]["customer_name"].asString();
  757. if (customerName == "") {
  758. name->setText(LANGUAGEMANAGER->getValue("EmptyCustomer"));
  759. } else {
  760. name->setText(customerName);
  761. }
  762. if (partSetting.customerAgeHiddenOnDoor != 0) {
  763. if (frameBedList[index]["customer_age"].asString() == "") {
  764. age->setText("");
  765. } else {
  766. age->setText("*" + frameBedList[index]["customer_age_unit"].asString());
  767. }
  768. }
  769. else {
  770. age->setText(frameBedList[index]["customer_age"].asString() + frameBedList[index]["customer_age_unit"].asString());
  771. }
  772. string customerSex = frameBedList[index]["customer_sex"].asString();
  773. if (customerSex == "0") { // 如果性别为女性,替换成女性,底色为粉色
  774. sex->setText(LANGUAGEMANAGER->getValue("Woman"));
  775. sex->setTextColor(0xFF9F9F);
  776. sex->setBackgroundPic("main/woman.png");
  777. }
  778. else if (customerSex == "1") {
  779. sex->setText(LANGUAGEMANAGER->getValue("Man"));
  780. sex->setTextColor(0x3A78EF);
  781. sex->setBackgroundPic("main/man.png");
  782. }
  783. else {
  784. sex->setText(LANGUAGEMANAGER->getValue("Unknown"));
  785. sex->setTextColor(0x37B643);
  786. sex->setBackgroundPic("main/age.png");
  787. }
  788. // 医生护士相关
  789. if (rightTitleInfo["doctor_valid"] != 1){
  790. doctorTitle->setVisible(false);
  791. } else {
  792. doctorTitle->setText(rightTitleInfo["doctor_title"].asString());
  793. }
  794. if (rightTitleInfo["nurse_valid"] != 1){
  795. nurseTitle->setVisible(false);
  796. } else {
  797. nurseTitle->setText(rightTitleInfo["nurse_title"].asString());
  798. }
  799. doctor->setText(frameBedList[index]["doctor_name"].asString());
  800. nurse->setText(frameBedList[index]["nurse_name"].asString());
  801. }
  802. }
  803. static void onListItemClick_BedListView2(ZKListView *pListView, int index, int id) {
  804. //LOGD(" onListItemClick_ BedListView2 !!!\n");
  805. }