mainLogic.cc 32 KB

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