mainLogic.cc 33 KB

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