mainLogic.cc 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  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.png");
  258. mPainterInfoPtr->setBackgroundColor(redDeepColour);
  259. // 用户
  260. mCustomerNameTextViewPtr->setTextColor(redDeepColour);
  261. mDescTextViewPtr->setBackgroundColor(redDeepColour);
  262. mInDateTextViewPtr->setTextColor(redDeepColour);
  263. mOutDateTextViewPtr->setTextColor(redDeepColour);
  264. mMsgPainterPtr->setBackgroundPic("/main/msg_red.png");
  265. // 更多
  266. mMoreButtonPtr->setTextColor(redDeepColour);
  267. // 设置科室名称和时间
  268. setPartNameAndDateColor(redDeepColour);
  269. // 设置ui3界面的颜色
  270. setUi3BgColor(redDeepColour);
  271. if (babyList.size() == 0) {
  272. return;
  273. }
  274. if (babySex == BabySex.girl) { // 只有一个女孩的时候
  275. // 主图
  276. mCustomerInfoPainterPtr->setBackgroundPic("/main/girl.png");
  277. // 婴儿姓名
  278. mBayNameTextViewPtr->setVisible(true);
  279. mBayNameTextViewPtr->setText(babyList[0]["relative_member_name"].asCString());
  280. mBayNameTextViewPtr->setTextColor(redDeepColour);
  281. // 婴儿出生日期
  282. mBabyBirTextViewPtr->setVisible(true);
  283. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  284. string babyBir = babyList[0]["relative_birthday"].asString();
  285. babyBir = babyBir.substr(0, 10);
  286. if (babyBir != "") {
  287. time_t timet = stoi(babyBir);
  288. struct tm *t = gmtime(&timet);
  289. char pDate[25];
  290. sprintf(pDate,"%d-%02d-%02d",
  291. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  292. babyBir = pDate;
  293. }
  294. babyBirStr += babyBir;
  295. mBabyBirTextViewPtr->setText(babyBirStr);
  296. mBabySexTextViewPtr->setVisible(true);
  297. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Woman"));
  298. mBabySexTextViewPtr->setBackgroundColor(redDeepColour);
  299. mBabyNameTextView2Ptr->setVisible(false);
  300. mBabyBirTextView2Ptr->setText("");
  301. mBabySexTextView2Ptr->setVisible(false);
  302. }
  303. else { // 双胞胎女孩
  304. // 主图
  305. mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_girl.png");
  306. // 婴儿姓名
  307. mBayNameTextViewPtr->setVisible(true);
  308. mBayNameTextViewPtr->setText(babyList[0]["relative_member_name"].asCString());
  309. mBayNameTextViewPtr->setTextColor(redDeepColour);
  310. // 婴儿出生日期
  311. mBabyBirTextViewPtr->setVisible(true);
  312. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  313. string babyBir = babyList[0]["relative_birthday"].asString();
  314. if (babyBir != "") {
  315. babyBir = babyBir.substr(0, 10);
  316. time_t timet = stoi(babyBir);
  317. struct tm *t = gmtime(&timet);
  318. char pDate[25];
  319. sprintf(pDate,"%d-%02d-%02d",
  320. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  321. babyBir = pDate;
  322. }
  323. babyBirStr += babyBir;
  324. mBabyBirTextViewPtr->setText(babyBirStr);
  325. mBabySexTextViewPtr->setVisible(true);
  326. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Woman"));
  327. mBabySexTextViewPtr->setBackgroundColor(redDeepColour);
  328. // 婴儿姓名
  329. mBabyNameTextView2Ptr->setVisible(true);
  330. mBabyNameTextView2Ptr->setText(babyList[1]["relative_member_name"].asCString());
  331. mBabyNameTextView2Ptr->setTextColor(redDeepColour);
  332. // 婴儿出生日期
  333. mBabyBirTextView2Ptr->setVisible(true);
  334. string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime");
  335. string babyBir2 = babyList[1]["relative_birthday"].asString();
  336. babyBir2 = babyBir2.substr(0, 10);
  337. if (babyBir != "") {
  338. time_t timet = stoi(babyBir2);
  339. struct tm *t = gmtime(&timet);
  340. char pDate[25];
  341. sprintf(pDate,"%d-%02d-%02d",
  342. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  343. babyBir2 = pDate;
  344. }
  345. babyBir2Str += babyBir2;
  346. mBabyBirTextView2Ptr->setText(babyBir2Str);
  347. mBabySexTextView2Ptr->setVisible(true);
  348. mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Woman"));
  349. mBabySexTextView2Ptr->setBackgroundColor(redDeepColour);
  350. }
  351. }
  352. else {
  353. // 背景
  354. mMainPainterPtr->setBackgroundColor(buleLightColour);
  355. // 房间
  356. // mPainterInfoPtr->setBackgroundPic("/main/title_blue.png");
  357. mPainterInfoPtr->setBackgroundColor(buleDeepColour);
  358. // 用户
  359. mCustomerNameTextViewPtr->setTextColor(buleDeepColour);
  360. mDescTextViewPtr->setBackgroundColor(buleDeepColour);
  361. mInDateTextViewPtr->setTextColor(buleDeepColour);
  362. mOutDateTextViewPtr->setTextColor(buleDeepColour);
  363. mMsgPainterPtr->setBackgroundPic("/main/msg_blue.png");
  364. // 更多
  365. mMoreButtonPtr->setTextColor(buleDeepColour);
  366. // 设置科室名称和时间
  367. setPartNameAndDateColor(buleDeepColour);
  368. // 设置ui3界面的颜色
  369. setUi3BgColor(buleDeepColour);
  370. if (babyList.size() == 0) {
  371. return;
  372. }
  373. if (babySex == BabySex.boy) { // 只有一个男孩
  374. // 主图
  375. mCustomerInfoPainterPtr->setBackgroundPic("/main/boy.png");
  376. // 婴儿姓名
  377. mBayNameTextViewPtr->setVisible(true);
  378. mBayNameTextViewPtr->setText(babyList[0]["relative_member_name"].asCString());
  379. mBayNameTextViewPtr->setTextColor(buleDeepColour);
  380. // 婴儿出生日期
  381. mBabyBirTextViewPtr->setVisible(true);
  382. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  383. string babyBir = babyList[0]["relative_birthday"].asString();
  384. babyBir = babyBir.substr(0, 10);
  385. if (babyBir != "") {
  386. time_t timet = stoi(babyBir);
  387. struct tm *t = gmtime(&timet);
  388. char pDate[25];
  389. sprintf(pDate,"%d-%02d-%02d",
  390. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  391. babyBir = pDate;
  392. }
  393. babyBirStr += babyBir;
  394. mBabyBirTextViewPtr->setText(babyBirStr);
  395. mBabySexTextViewPtr->setVisible(true);
  396. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man"));
  397. mBabySexTextViewPtr->setBackgroundColor(buleDeepColour);
  398. mBabyNameTextView2Ptr->setVisible(false);
  399. mBabyBirTextView2Ptr->setText("");
  400. mBabySexTextView2Ptr->setVisible(false);
  401. }
  402. else if (babySex == BabySex.twins_boy) { // 双胞胎男孩
  403. // 主图
  404. mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_boy.png");
  405. // 婴儿姓名
  406. mBayNameTextViewPtr->setVisible(true);
  407. mBayNameTextViewPtr->setText(babyList[0]["relative_member_name"].asCString());
  408. mBayNameTextViewPtr->setTextColor(buleDeepColour);
  409. // 婴儿出生日期
  410. mBabyBirTextViewPtr->setVisible(true);
  411. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  412. string babyBir = babyList[0]["relative_birthday"].asString();
  413. if (babyBir != "") {
  414. babyBir = babyBir.substr(0, 10);
  415. time_t timet = stoi(babyBir);
  416. struct tm *t = gmtime(&timet);
  417. char pDate[25];
  418. sprintf(pDate,"%d-%02d-%02d",
  419. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  420. babyBir = pDate;
  421. }
  422. babyBirStr += babyBir;
  423. mBabyBirTextViewPtr->setText(babyBirStr);
  424. mBabySexTextViewPtr->setVisible(true);
  425. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man"));
  426. mBabySexTextViewPtr->setBackgroundColor(buleDeepColour);
  427. // 婴儿姓名
  428. mBabyNameTextView2Ptr->setVisible(true);
  429. mBabyNameTextView2Ptr->setText(babyList[1]["relative_member_name"].asCString());
  430. mBabyNameTextView2Ptr->setTextColor(buleDeepColour);
  431. // 婴儿出生日期
  432. mBabyBirTextView2Ptr->setVisible(true);
  433. string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime");
  434. string babyBir2 = babyList[1]["relative_birthday"].asString();
  435. babyBir2 = babyBir2.substr(0, 10);
  436. if (babyBir != "") {
  437. time_t timet = stoi(babyBir2);
  438. struct tm *t = gmtime(&timet);
  439. char pDate[25];
  440. sprintf(pDate,"%d-%02d-%02d",
  441. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  442. babyBir2 = pDate;
  443. }
  444. babyBir2Str += babyBir2;
  445. mBabyBirTextView2Ptr->setText(babyBir2Str);
  446. mBabySexTextView2Ptr->setVisible(true);
  447. mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Man"));
  448. mBabySexTextView2Ptr->setBackgroundColor(buleDeepColour);
  449. }
  450. else if (babySex == BabySex.twins_boy_and_girl) { // 龙凤胎
  451. // 主图
  452. mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_boy_girl.png");
  453. for (int i = 0; i < babyList.size(); i++) {
  454. if (babyList[i]["relative_sex"].asInt() == 1) {
  455. // 婴儿姓名
  456. mBayNameTextViewPtr->setVisible(true);
  457. mBayNameTextViewPtr->setText(babyList[i]["relative_member_name"].asCString());
  458. mBayNameTextViewPtr->setTextColor(buleDeepColour);
  459. // 婴儿出生日期
  460. mBabyBirTextViewPtr->setVisible(true);
  461. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  462. string babyBir = babyList[i]["relative_birthday"].asString();
  463. if (babyBir != "") {
  464. babyBir = babyBir.substr(0, 10);
  465. time_t timet = stoi(babyBir);
  466. struct tm *t = gmtime(&timet);
  467. char pDate[25];
  468. sprintf(pDate,"%d-%02d-%02d",
  469. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  470. babyBir = pDate;
  471. }
  472. babyBirStr += babyBir;
  473. mBabyBirTextViewPtr->setText(babyBirStr);
  474. mBabySexTextViewPtr->setVisible(true);
  475. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man"));
  476. mBabySexTextViewPtr->setBackgroundColor(buleDeepColour);
  477. }
  478. else {
  479. // 婴儿姓名
  480. mBabyNameTextView2Ptr->setVisible(true);
  481. mBabyNameTextView2Ptr->setText(babyList[i]["relative_member_name"].asCString());
  482. mBabyNameTextView2Ptr->setTextColor(redDeepColour);
  483. // 婴儿出生日期
  484. mBabyBirTextView2Ptr->setVisible(true);
  485. string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime");
  486. string babyBir2 = babyList[i]["relative_birthday"].asString();
  487. babyBir2 = babyBir2.substr(0, 10);
  488. if (babyBir2 != "") {
  489. time_t timet = stoi(babyBir2);
  490. struct tm *t = gmtime(&timet);
  491. char pDate[25];
  492. sprintf(pDate,"%d-%02d-%02d",
  493. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  494. babyBir2 = pDate;
  495. }
  496. babyBir2Str += babyBir2;
  497. mBabyBirTextView2Ptr->setText(babyBir2Str);
  498. mBabySexTextView2Ptr->setVisible(true);
  499. mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Woman"));
  500. mBabySexTextView2Ptr->setBackgroundColor(redDeepColour);
  501. }
  502. }
  503. }
  504. }
  505. }
  506. static void getPartSetting(string partId){
  507. string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId;
  508. LOGD("请求科室信息. url = %s", url.c_str());
  509. //发起HTTP GET请求
  510. RestClient::Response r = RestClient::get(url);
  511. LOGD("获得科室信息. result = %s", r.body.c_str());
  512. //解析json
  513. Json::Reader reader;
  514. Json::Value root;
  515. if (reader.parse(r.body, root, false)){
  516. partSetting.partId = root["part_id"].asInt();
  517. partSetting.dayStart = root["day_start"].asString();
  518. partSetting.dayLight = root["day_light"].asInt();
  519. partSetting.dayVol = root["day_vol"].asInt();
  520. partSetting.dayRingVol = root["day_ring_vol"].asInt();
  521. partSetting.dayRingTimes = root["day_ring_times"].asInt();
  522. partSetting.dayNurseLed = root["day_nurse_led"].asInt();
  523. partSetting.dayDoorVol = root["day_door_vol"].asInt();
  524. partSetting.dayBedVol = root["day_bed_vol"].asInt();
  525. partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt();
  526. partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt();
  527. partSetting.nightStart = root["night_start"].asString();
  528. partSetting.nightLight = root["night_light"].asInt();
  529. partSetting.nightVol = root["night_vol"].asInt();
  530. partSetting.nightRingVol = root["night_ring_vol"].asInt();
  531. partSetting.nightRingTimes = root["night_ring_times"].asInt();
  532. partSetting.nightNurseLed = root["night_nurse_led"].asInt();
  533. partSetting.nightDoorVol = root["night_door_vol"].asInt();
  534. partSetting.nightBedVol = root["night_bed_vol"].asInt();
  535. partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt();
  536. partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt();
  537. partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt();
  538. partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt();
  539. partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt();
  540. partSetting.sipOvertime = root["sip_overtime"].asInt();
  541. partSetting.transferDuration = root["transfer_duration"].asInt();
  542. partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt();
  543. partSetting.communicationModeBed = root["communication_mode_bed"].asInt();
  544. partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt();
  545. partSetting.communicationModeMobile = root["communication_model_mobile"].asInt();
  546. partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt();
  547. partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt();
  548. partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt();
  549. partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt();
  550. partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt();
  551. partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt();
  552. partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString();
  553. partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt();
  554. partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString();
  555. partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt();
  556. partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString();
  557. partSetting.doctorTitle = root["doctor_title"].asString();
  558. partSetting.doctorValid = root["doctor_valid"].asInt();
  559. partSetting.nurseTitle = root["nurse_title"].asString();
  560. partSetting.nurseValid = root["nurse_valid"].asInt();
  561. partSetting.doorNurseTitle = root["door_nurse_title"].asString();
  562. partSetting.doorNurseValid = root["door_nurse_valid"].asInt();
  563. partSetting.doorNursingTitle = root["door_nursing_title"].asString();
  564. partSetting.doorNursingValid = root["door_nursing_valid"].asInt();
  565. partSetting.upSeconds = root["up_seconds"].asInt();
  566. partSetting.autoAccept = root["auto_accept"].asInt();
  567. partSetting.eventForward = root["event_forward"].asInt();
  568. partSetting.nursingColorRgb = root["nursing_color_rgb"].asString();
  569. partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt();
  570. partSetting.qrUrl = root["qr_url"].asString();
  571. partSetting.screenLight = root["screen_light"].asInt();
  572. StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart);
  573. StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight);
  574. StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol);
  575. StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes);
  576. StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart);
  577. StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight);
  578. StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol);
  579. StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes);
  580. StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsDoor);
  581. StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle);
  582. StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1);
  583. StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle);
  584. StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1);
  585. StoragePreferences::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb);
  586. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  587. StoragePreferences::putInt(STORE_SCREEN_LIGHT, partSetting.screenLight);
  588. dataInit = true;
  589. }
  590. }
  591. static void getVersion() {
  592. std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=303&part_id=" + StoragePreferences::getString(STORE_PARTID, "");
  593. std::string content_type = std::string("application/json");
  594. LOGD("请求版本信息. url = %s", url.c_str());
  595. //发起HTTP POST请求
  596. RestClient::Response r = RestClient::post(url, content_type, "");
  597. if (r.code != 200) {
  598. LOGD("请求版本信息-> 错误代码: %d", r.code);
  599. return;
  600. }
  601. LOGD("获得版本信息. result = %s", r.body.c_str());
  602. //解析json
  603. Json::Reader reader;
  604. Json::Value root;
  605. if(reader.parse(r.body, root, false)) {
  606. int currentVersionNo = getVersionNo();
  607. int responseVersionNo = root["version_no"].asInt();
  608. std::string responseVersion = root["version_code"].asString();
  609. LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo);
  610. if (currentVersionNo < responseVersionNo) {
  611. Intent* intent = new Intent();
  612. intent->putExtra(appUpdate, "true");
  613. EASYUICONTEXT->openActivity("DeviceUpdateActivity", intent);
  614. }
  615. }
  616. }
  617. /**
  618. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  619. * return true 继续线程
  620. * false 退出线程
  621. */
  622. virtual bool readyToRun() {
  623. LOGD("Thread 已经创建完成");
  624. return true;
  625. }
  626. /**
  627. * 线程循环函数
  628. *
  629. * return true 继续线程循环
  630. * false 推出线程
  631. */
  632. virtual bool threadLoop() {
  633. LOGD("线程循环函数");
  634. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  635. if (exitPending()) {
  636. return false;
  637. }
  638. udpConn = net::Dial("udp", "192.168.1.255:10010");
  639. if (udpConn) {
  640. byte buf[1024] = {0};
  641. const char* req = "search_server";
  642. //发送
  643. udpConn->Write((byte*)req, strlen(req));
  644. while (true && !exitPending()) {
  645. //读取,超时10*1000毫秒
  646. int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000);
  647. if (n > 0) {
  648. buf[n] = 0;
  649. char serverStr[1024];
  650. sprintf(serverStr,"%s",buf);
  651. LOGD("读取 %d字节: %s", n, serverStr);
  652. //解析json
  653. Json::Reader reader;
  654. Json::Value root;
  655. if (reader.parse(serverStr, root, false)){
  656. if (root.isMember("success") && root["success"].asBool()){
  657. serverIP = root["data"]["third_server"].asString();
  658. serverHttpPort = root["data"]["third_server_port"].asInt();
  659. StoragePreferences::putString(STORE_GATEWAY, serverIP);
  660. StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort);
  661. //先获取服务器信息
  662. //getServerInfo();
  663. //就当在获取服务器信息完成后获取用户信息,这里测试用
  664. //getCustomerInfo();
  665. //退出UDP线程
  666. pthread_exit(NULL);
  667. break;
  668. }
  669. }
  670. } else if (n == 0) {
  671. LOGD("连接正常断开");
  672. break;
  673. } else if (n == net::E_TIMEOUT) {
  674. udpConn->Write((byte*)req, strlen(req));
  675. LOGD("读取超时");
  676. } else {
  677. LOGD("出错");
  678. break;
  679. }
  680. }
  681. //关闭连接
  682. udpConn->Close();
  683. //释放内存
  684. delete udpConn;
  685. udpConn = NULL;
  686. }
  687. //返回真,继续下次线程循环
  688. return true;
  689. }
  690. };
  691. static UdpThread udp_thread;
  692. int getNowTime() {
  693. struct tm *t = TimeHelper::getDateTime();
  694. char timeStr[50];
  695. string formatStr = "%02d:%02d:%02d";
  696. sprintf(timeStr, formatStr.c_str(), t->tm_hour,t->tm_min,t->tm_sec);
  697. int hour, minute, second;// 定义时间的各个int临时变量。
  698. sscanf(timeStr, "%d:%d:%d", &hour, &minute, &second);
  699. int time = hour * 60 * 60 + minute * 60 + second;
  700. return time;
  701. }
  702. Json::Value getPainterInfoList() {
  703. return painterInfoList;
  704. }
  705. void addPainterInfo(int deviceId, uint32_t bgColor, const std::string& msg, const std::string type, int endTime) {
  706. // 将设备id,颜色,展示的信息,时间存放起来
  707. painterInfo["deviceId"] = deviceId;
  708. // painterInfo["bgColor"] = bgColor + "";
  709. painterInfo["bgColor"] = bgColor;
  710. painterInfo["msg"] = msg;
  711. painterInfo["type"] = type;
  712. painterInfo["endTime"] = getNowTime() + endTime;
  713. painterInfoList.append(painterInfo);
  714. }
  715. bool removePainterInfo(int deviceId, const std::string type) {
  716. // 获取painterInfoList的长度
  717. int size = painterInfoList.size();
  718. if (size == 0) { // 如果为空了,那就代表painterInfoList没有值,直接返回
  719. return false;
  720. }
  721. // 如果painterInfoList里有对应的deviceId,那就需要先删除原本的,然后再从头添加新的
  722. int removeIndex = -1;
  723. for (int i = 0; i < painterInfoList.size(); i++) {
  724. LOGD("deviceId == %d", deviceId);
  725. LOGD("painterInfoList.deviceId == %d", painterInfoList[i]["deviceId"].asInt());
  726. LOGD("type == %s", type.c_str());
  727. LOGD("painterInfoList.type == %s", painterInfoList[i]["type"].asCString());
  728. if (painterInfoList[i]["deviceId"].asInt() == deviceId && painterInfoList[i]["type"].asString() == type) {
  729. removeIndex = i;
  730. }
  731. }
  732. if (removeIndex != -1) {
  733. painterInfoList.removeIndex(removeIndex, &painterInfo);
  734. }
  735. return true;
  736. }
  737. // 收到tcp的时候,刷新数据
  738. void dataRefresh() {
  739. LOGD("DATA-REFRESH, 数据刷新");
  740. if (serverInfo) {
  741. udp_thread.getServerInfo();
  742. }
  743. dataInit = false;
  744. udp_thread.getDeviceInfo();
  745. }
  746. void getPartSetting() {
  747. udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  748. }
  749. /**
  750. * 注册定时器
  751. * 填充数组用于注册定时器
  752. * 注意:id不能重复
  753. */
  754. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  755. //{0, 6000}, //定时器id=0, 时间间隔6秒
  756. //{1, 1000},
  757. };
  758. /**
  759. * 当界面构造时触发
  760. */
  761. static void onUI_init(){
  762. //udp_thread.run("this is thread name");
  763. //测试用
  764. LOGD("进入mainLogic页面, 触发 onUI_init");
  765. if(serverInfo) { // 如果是false,就是不需要
  766. udp_thread.getServerInfo();
  767. }
  768. udp_thread.getDeviceInfo();
  769. }
  770. /**
  771. * 当切换到该界面时触发
  772. */
  773. static void onUI_intent(const Intent *intentPtr) {
  774. if (intentPtr != NULL) {
  775. }
  776. }
  777. /*
  778. * 当界面显示时触发
  779. */
  780. static void onUI_show() {
  781. }
  782. /*
  783. * 当界面隐藏时触发
  784. */
  785. static void onUI_hide() {
  786. }
  787. /*
  788. * 当界面完全退出时触发
  789. */
  790. static void onUI_quit() {
  791. //pthread_exit(NULL);
  792. }
  793. /**
  794. * 串口数据回调接口
  795. */
  796. static void onProtocolDataUpdate(const SProtocolData &data) {
  797. }
  798. /**
  799. * 定时器触发函数
  800. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  801. * 参数: id
  802. * 当前所触发定时器的id,与注册时的id相同
  803. * 返回值: true
  804. * 继续运行当前定时器
  805. * false
  806. * 停止运行当前定时器
  807. */
  808. static bool onUI_Timer(int id){
  809. switch (id) {
  810. default:
  811. break;
  812. }
  813. return true;
  814. }
  815. /**
  816. * 有新的触摸事件时触发
  817. * 参数:ev
  818. * 新的触摸事件
  819. * 返回值:true
  820. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  821. * false
  822. * 触摸事件将继续传递到控件上
  823. */
  824. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  825. switch (ev.mActionStatus) {
  826. case MotionEvent::E_ACTION_DOWN://触摸按下
  827. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  828. break;
  829. case MotionEvent::E_ACTION_MOVE://触摸滑动
  830. break;
  831. case MotionEvent::E_ACTION_UP: //触摸抬起
  832. break;
  833. default:
  834. break;
  835. }
  836. return false;
  837. }
  838. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  839. LOGD(" ButtonClick MoreButton !!!\n");
  840. EASYUICONTEXT->openActivity("ui3Activity");
  841. return false;
  842. }