mainLogic.cc 33 KB

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