mainLogic.cc 33 KB

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