HttpHelper.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using UnityAsync;
  7. using Best.HTTP;
  8. using Best.HTTP.JSON;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Linq;
  11. using UnityEngine;
  12. using UnityEngine.Networking;
  13. using Unity.VisualScripting;
  14. using static System.Net.WebRequestMethods;
  15. public class HttpHelper : MonoBehaviour
  16. {
  17. public Action OnSWYJRefresh;
  18. public static HttpHelper _Instance;
  19. public static Dictionary<string, DevicesId_Data> _devicesIdDatas_BuYuan = new Dictionary<string, DevicesId_Data>();
  20. public const int timeOut = 3;
  21. private async void Awake()
  22. {
  23. _Instance = this;
  24. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2 || GlobalData.pageIndex == PageIndex.Page3)
  25. {
  26. Debug.Log("HttpInitYZTData");
  27. //可以并行,无需等待
  28. InitYZTData();
  29. }
  30. if (GlobalData.pageIndex == PageIndex.Page1)
  31. {
  32. InItBuYuanDevicesList();
  33. SendBuYuan_GetSensorData();
  34. GetBuYuanDevicesGroupInfo();
  35. }
  36. if (GlobalData.pageIndex == PageIndex.Page1)
  37. {
  38. Debug.Log("InitXHGKData");
  39. //可以并行,无需等待
  40. InitXHGKData();//已完成迁移
  41. }
  42. if (GlobalData.pageIndex == PageIndex.Page1)
  43. {
  44. Debug.Log("HttpInitGCJKData");
  45. //可以并行,无需等待
  46. InitGCJKData();
  47. }
  48. if (GlobalData.pageIndex == PageIndex.Page1)
  49. {
  50. Debug.Log("HttpInitXHDDData");
  51. //可以并行,无需等待
  52. InitXHDDData();
  53. }
  54. if (GlobalData.pageIndex == PageIndex.Page1)
  55. {
  56. Debug.Log("HttpInitRKZYData");
  57. //可以并行,无需等待
  58. InitRKZYData();
  59. }
  60. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2)
  61. {
  62. Debug.Log("HttpInitSWYJData");
  63. //可以并行,无需等待
  64. InitSWYJData();
  65. }
  66. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2)
  67. {
  68. Debug.Log("HttpInitGCYWData1");
  69. //可以并行,无需等待
  70. InitGCYWData1(0);
  71. }
  72. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2 || GlobalData.pageIndex == PageIndex.Page3)
  73. {
  74. Debug.Log("HttpInitFloorGateData");
  75. InitFloorGateData();
  76. }
  77. if (GlobalData.pageIndex == PageIndex.Page2)
  78. {
  79. Debug.Log("HttpInitDPSWData");
  80. InitDPSWData();
  81. }
  82. if (GlobalData.pageIndex == PageIndex.Page2)
  83. {
  84. Debug.Log("HttpInitGCYWData2");
  85. InitGCYWData2();
  86. }
  87. if (GlobalData.pageIndex == PageIndex.Page2)
  88. {
  89. Debug.Log("HttpInitYJSJData2");
  90. InitYJSJData2();
  91. }
  92. }
  93. private async Task InitGCYWData2()
  94. {
  95. bool successInternet = true;
  96. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetInspectionStatistics);
  97. requestData.timeout = timeOut;
  98. await requestData.SendWebRequest();
  99. try
  100. {
  101. if (requestData.result != UnityWebRequest.Result.Success)
  102. {
  103. Debug.LogWarning("大屏运维数据联网不成功,读本地缓存数据,原因:返request不成功");
  104. successInternet = false;
  105. }
  106. else
  107. {
  108. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  109. // 提取data字段的值
  110. JToken dataToken = jsonObject["data"];
  111. JToken codeToken = jsonObject["code"];
  112. if (codeToken.ToString() == "200")
  113. {
  114. GlobalData.InspectionStat = JsonConvert.DeserializeObject<List<StationInspection>>(dataToken.ToString());
  115. }
  116. else
  117. {
  118. Debug.LogWarning("大屏运维数据联网不成功,读本地缓存数据,原因:返序列化失败");
  119. successInternet = false;
  120. }
  121. }
  122. }
  123. catch (Exception e)
  124. {
  125. successInternet = false;
  126. Debug.LogWarning("大屏运维数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  127. }
  128. requestData.Dispose();
  129. if (!successInternet)
  130. {
  131. WWW www = new WWW(Application.streamingAssetsPath + "/inspectionStatistics.json");
  132. await new UnityAsync.WaitUntil(() =>
  133. {
  134. return www.isDone;
  135. });
  136. GlobalData.InspectionStat = JsonConvert.DeserializeObject<List<StationInspection>>(www.text);
  137. www.Dispose();
  138. }
  139. }
  140. private async Task InitYJSJData2()
  141. {
  142. bool successInternet = true;
  143. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetAlertData);
  144. requestData.timeout = timeOut;
  145. await requestData.SendWebRequest();
  146. try
  147. {
  148. if (requestData.result != UnityWebRequest.Result.Success)
  149. {
  150. Debug.LogWarning("大屏预警数据联网不成功,读本地缓存数据,原因:返request不成功");
  151. successInternet = false;
  152. }
  153. else
  154. {
  155. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  156. // 提取data字段的值
  157. JToken dataToken = jsonObject["data"];
  158. JToken codeToken = jsonObject["code"];
  159. if (codeToken.ToString() == "200")
  160. {
  161. GlobalData.alertData = JsonConvert.DeserializeObject<AlertData>(dataToken.ToString());
  162. GlobalData.alertData.success = true;
  163. }
  164. else
  165. {
  166. Debug.LogWarning("大屏预警数据联网不成功,读本地缓存数据,原因:返序列化失败");
  167. successInternet = false;
  168. }
  169. }
  170. }
  171. catch (Exception e)
  172. {
  173. successInternet = false;
  174. Debug.LogWarning("大屏预警数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  175. }
  176. requestData.Dispose();
  177. if (!successInternet)
  178. {
  179. WWW www = new WWW(Application.streamingAssetsPath + "/alertData.json");
  180. await new UnityAsync.WaitUntil(() =>
  181. {
  182. return www.isDone;
  183. });
  184. Debug.Log(www.text);
  185. GlobalData.alertData = JsonConvert.DeserializeObject<AlertData>(www.text.ToString());
  186. GlobalData.alertData.success = true;
  187. Debug.Log(GlobalData.alertData.alerts.threeLineWarnings[0].title);
  188. www.Dispose();
  189. }
  190. }
  191. private async Task InitFloorGateData()
  192. {
  193. bool successInternet = true;
  194. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetFloodGateData);
  195. requestData.timeout = timeOut;
  196. await requestData.SendWebRequest();
  197. try
  198. {
  199. if (requestData.result != UnityWebRequest.Result.Success)
  200. {
  201. Debug.LogWarning("大屏闸口数据联网不成功,读本地缓存数据,原因:返request不成功");
  202. successInternet = false;
  203. }
  204. else
  205. {
  206. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  207. // 提取data字段的值
  208. JToken dataToken = jsonObject["data"];
  209. JToken codeToken = jsonObject["code"];
  210. if (codeToken.ToString() == "200")
  211. {
  212. GlobalData.floorGateData = JsonConvert.DeserializeObject<FloodGateStatusData>(dataToken.ToString());
  213. GlobalData.floorGateData.success = true;
  214. }
  215. else
  216. {
  217. Debug.LogWarning("大屏闸口数据联网不成功,读本地缓存数据,原因:返序列化失败");
  218. successInternet = false;
  219. }
  220. }
  221. }
  222. catch (Exception e)
  223. {
  224. successInternet = false;
  225. Debug.LogWarning("大屏闸口数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  226. }
  227. requestData.Dispose();
  228. if (!successInternet)
  229. {
  230. WWW www = new WWW(Application.streamingAssetsPath + "/floodGateStatusData.json");
  231. await new UnityAsync.WaitUntil(() =>
  232. {
  233. return www.isDone;
  234. });
  235. Debug.Log(www.text);
  236. GlobalData.floorGateData = JsonConvert.DeserializeObject<FloodGateStatusData>(www.text.ToString());
  237. GlobalData.floorGateData.success = true;
  238. www.Dispose();
  239. }
  240. }
  241. private async Task InitDPSWData()
  242. {
  243. bool successInternet = true;
  244. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetHydrologicalData);
  245. requestData.timeout = timeOut;
  246. await requestData.SendWebRequest();
  247. try
  248. {
  249. if (requestData.result != UnityWebRequest.Result.Success)
  250. {
  251. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:返request不成功");
  252. successInternet = false;
  253. }
  254. else
  255. {
  256. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  257. // 提取data字段的值
  258. JToken dataToken = jsonObject["data"];
  259. JToken codeToken = jsonObject["code"];
  260. if (codeToken.ToString() == "200")
  261. {
  262. GlobalData.locationWeatherData = JsonConvert.DeserializeObject<List<LocationWeatherData>>(dataToken.ToString());
  263. }
  264. else
  265. {
  266. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:返序列化失败");
  267. successInternet = false;
  268. }
  269. }
  270. }
  271. catch (Exception e)
  272. {
  273. successInternet = false;
  274. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  275. }
  276. requestData.Dispose();
  277. if (!successInternet)
  278. {
  279. WWW www = new WWW(Application.streamingAssetsPath + "/hydrologicalData.json");
  280. await new UnityAsync.WaitUntil(() =>
  281. {
  282. return www.isDone;
  283. });
  284. Debug.Log(www.text);
  285. GlobalData.locationWeatherData = JsonConvert.DeserializeObject<List<LocationWeatherData>>(www.text.ToString());
  286. www.Dispose();
  287. }
  288. }
  289. public async Task InitYZTData()
  290. {
  291. InitYZTData1();//已完成迁移
  292. InitYZTData2();//未完成迁移
  293. InitYZTData3();//已完成迁移
  294. }
  295. public async Task InitYZTData1()
  296. {
  297. bool successInternet = true;
  298. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetWaterManagerProject);
  299. requestData.timeout = timeOut;
  300. await requestData.SendWebRequest();
  301. try
  302. {
  303. if (requestData.result != UnityWebRequest.Result.Success)
  304. {
  305. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返request不成功");
  306. successInternet = false;
  307. }
  308. else
  309. {
  310. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  311. // 提取data字段的值
  312. JToken dataToken = jsonObject["data"];
  313. JToken codeToken = jsonObject["code"];
  314. if (codeToken.ToString() == "200")
  315. {
  316. GlobalData.layerUnitDatas = JsonConvert.DeserializeObject<List<LayerUnitData>>(dataToken.ToString());
  317. }
  318. else
  319. {
  320. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返序列化失败");
  321. successInternet = false;
  322. }
  323. }
  324. }
  325. catch (Exception e)
  326. {
  327. successInternet = false;
  328. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
  329. }
  330. requestData.Dispose();
  331. if (!successInternet)
  332. {
  333. WWW www = new WWW(Application.streamingAssetsPath + "/layerUnitDatas.json");
  334. await new UnityAsync.WaitUntil(() =>
  335. {
  336. return www.isDone;
  337. });
  338. GlobalData.layerUnitDatas = JsonConvert.DeserializeObject<List<LayerUnitData>>(www.text);
  339. www.Dispose();
  340. }
  341. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  342. {
  343. if (GlobalData.layerUnitDatas[i].type == LayerUnitType.JK)
  344. {
  345. GlobalData.obsCameraLib.Add(GlobalData.layerUnitDatas[i].name, GlobalData.layerUnitDatas[i].namePri);
  346. }
  347. }
  348. }
  349. public async Task InitYZTData2()
  350. {
  351. Debug.Log("!!!!!");
  352. bool successInternet = true;
  353. string sendUrl = ServerAddress.API_GetDevicesInfo;
  354. sendUrl += "/34020000001180000001/channels?page=1&count=40";
  355. Debug.Log(sendUrl);
  356. UnityWebRequest requestData = UnityWebRequest.Get(sendUrl);
  357. requestData.timeout = timeOut;
  358. await requestData.SendWebRequest();
  359. try
  360. {
  361. if (requestData.result != UnityWebRequest.Result.Success)
  362. {
  363. Debug.LogWarning("监控数据联网不成功,原因:返request不成功:" + requestData.error);
  364. successInternet = false;
  365. }
  366. else
  367. {
  368. Debug.Log(requestData.downloadHandler.text);
  369. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  370. // 提取data字段的值
  371. JToken dataToken = jsonObject["data"];
  372. JToken codeToken = jsonObject["code"];
  373. if (codeToken.ToString() == "0")
  374. {
  375. GlobalData.obsDatas = new List<ObsData>();
  376. ServerObsDatas serverObsDatas = JsonConvert.DeserializeObject<ServerObsDatas>(dataToken.ToString());
  377. for (int i = 0; i < serverObsDatas.list.Count; i++)
  378. {
  379. ObsData obsData = new ObsData();
  380. obsData.name = serverObsDatas.list[i].name;
  381. obsData.targetName = GlobalData.obsCameraLib[obsData.name];
  382. // if (i > 0)
  383. // {
  384. // obsData.url =
  385. // "http://www.chatgpt918.top:9080/rtp/34020000001180000001_34020000001310000001/hls.m3u8";
  386. // }
  387. // else
  388. // {
  389. obsData.url = ServerAddress.ObsSeverM3U8Address + string.Format("/rtp/{0}_{1}/hls.m3u8", serverObsDatas.list[i].deviceId, serverObsDatas.list[i].channelId);
  390. //}
  391. obsData.type = obsType.BuYuanObs;
  392. obsData.deviceId = serverObsDatas.list[i].deviceId;
  393. obsData.channelId = serverObsDatas.list[i].channelId;
  394. obsData.status = serverObsDatas.list[i].status;
  395. GlobalData.obsDatas.Add(obsData);
  396. }
  397. }
  398. else
  399. {
  400. Debug.LogWarning("监控数据联网不成功,原因:返序列化失败");
  401. successInternet = false;
  402. }
  403. }
  404. }
  405. catch (Exception e)
  406. {
  407. successInternet = false;
  408. Debug.LogWarning("监控数据联网不成功,原因:" + e.ToString());
  409. }
  410. requestData.Dispose();
  411. if (!successInternet)
  412. {
  413. WWW www = new WWW(Application.streamingAssetsPath + "/ObsDatas.json");
  414. await new UnityAsync.WaitUntil(() =>
  415. {
  416. return www.isDone;
  417. });
  418. Debug.Log($"缓存数据:{www.text}");
  419. GlobalData.obsDatas = JsonConvert.DeserializeObject<List<ObsData>>(www.text);
  420. www.Dispose();
  421. }
  422. }
  423. public async Task InitYZTData3()
  424. {
  425. bool successInternet = true;
  426. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetWaterHotPoint);
  427. requestData.timeout = timeOut;
  428. await requestData.SendWebRequest();
  429. try
  430. {
  431. if (requestData.result != UnityWebRequest.Result.Success)
  432. {
  433. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返request不成功");
  434. successInternet = false;
  435. }
  436. else
  437. {
  438. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  439. // 提取data字段的值
  440. JToken dataToken = jsonObject["data"];
  441. JToken codeToken = jsonObject["code"];
  442. if (codeToken.ToString() == "200")
  443. {
  444. GlobalData.hotPointDatas = JsonConvert.DeserializeObject<List<HotPointData>>(dataToken.ToString());
  445. }
  446. else
  447. {
  448. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返序列化失败");
  449. successInternet = false;
  450. }
  451. }
  452. }
  453. catch (Exception e)
  454. {
  455. successInternet = false;
  456. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
  457. }
  458. requestData.Dispose();
  459. if (!successInternet)
  460. {
  461. WWW www = new WWW(Application.streamingAssetsPath + "/hotPoints.json");
  462. await new UnityAsync.WaitUntil(() =>
  463. {
  464. return www.isDone;
  465. });
  466. GlobalData.hotPointDatas = JsonConvert.DeserializeObject<List<HotPointData>>(www.text);
  467. Debug.Log(GlobalData.hotPointDatas.Count);
  468. www.Dispose();
  469. }
  470. }
  471. public async Task InitXHGKData()
  472. {
  473. bool successInternet = true;
  474. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGetProjectMilestones);
  475. requestData.timeout = timeOut;
  476. await requestData.SendWebRequest();
  477. try
  478. {
  479. if (requestData.result != UnityWebRequest.Result.Success)
  480. {
  481. Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返request不成功");
  482. successInternet = false;
  483. }
  484. else
  485. {
  486. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  487. // ȡdata ֶε ֵ
  488. JToken dataToken = jsonObject["data"];
  489. //Debug.Log(dataToken.ToString());
  490. JToken codeToken = jsonObject["code"];
  491. if (codeToken.ToString() == "200")
  492. {
  493. GlobalData.dsjContents = JsonConvert.DeserializeObject<List<DSJData>>(dataToken.ToString());
  494. }
  495. else
  496. {
  497. Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返序列化失败");
  498. successInternet = false;
  499. }
  500. }
  501. }
  502. catch (Exception e)
  503. {
  504. successInternet = false;
  505. Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
  506. }
  507. requestData.Dispose();
  508. if (!successInternet)
  509. {
  510. WWW www = new WWW(Application.streamingAssetsPath + "/dsj.json");
  511. await new UnityAsync.WaitUntil(() =>
  512. {
  513. return www.isDone;
  514. });
  515. GlobalData.dsjContents = JsonConvert.DeserializeObject<List<DSJData>>(www.text);
  516. www.Dispose();
  517. }
  518. }
  519. public async Task InitGCJKData()
  520. {
  521. bool successInternet = true;
  522. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeQXZData);
  523. requestData.timeout = timeOut;
  524. await requestData.SendWebRequest();
  525. try
  526. {
  527. if (requestData.result != UnityWebRequest.Result.Success)
  528. {
  529. Debug.LogWarning("水文站联网不成功,原因:返request不成功");
  530. successInternet = false;
  531. }
  532. else
  533. {
  534. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  535. // 提取data字段的值
  536. JToken dataToken = jsonObject["data"];
  537. JToken codeToken = jsonObject["code"];
  538. if (codeToken.ToString() == "200")
  539. {
  540. GlobalData.qXZDatas = JsonConvert.DeserializeObject<List<QXZData>>(dataToken.ToString());
  541. }
  542. else
  543. {
  544. Debug.LogWarning("水文站联网不成功,原因:返序列化失败");
  545. successInternet = false;
  546. }
  547. }
  548. }
  549. catch (Exception e)
  550. {
  551. successInternet = false;
  552. Debug.LogWarning("水文站联网不成功,原因:" + e.ToString());
  553. }
  554. requestData.Dispose();
  555. successInternet = true;
  556. UnityWebRequest requestData1 = UnityWebRequest.Get(ServerAddress.APIGetGeSWZData);
  557. await requestData1.SendWebRequest();
  558. try
  559. {
  560. if (requestData1.result != UnityWebRequest.Result.Success)
  561. {
  562. Debug.LogWarning("水文站联网不成功,原因:返request不成功");
  563. successInternet = false;
  564. }
  565. else
  566. {
  567. JObject jsonObject = JObject.Parse(requestData1.downloadHandler.text);
  568. // 提取data字段的值
  569. JToken dataToken = jsonObject["data"];
  570. JToken codeToken = jsonObject["code"];
  571. if (codeToken.ToString() == "200")
  572. {
  573. GlobalData.sWZDatas = JsonConvert.DeserializeObject<List<SWZData>>(dataToken.ToString());
  574. }
  575. else
  576. {
  577. Debug.LogWarning("水文站联网不成功,原因:返序列化失败");
  578. successInternet = false;
  579. }
  580. }
  581. }
  582. catch (Exception e)
  583. {
  584. successInternet = false;
  585. Debug.LogWarning("水文站联网不成功,原因:" + e.ToString());
  586. }
  587. requestData1.Dispose();
  588. }
  589. public async Task InitXHDDData()
  590. {
  591. WWW www = new WWW(Application.streamingAssetsPath + "/scheduling.json");
  592. await new UnityAsync.WaitUntil(() =>
  593. {
  594. return www.isDone;
  595. });
  596. GlobalData.schedulingData = JsonConvert.DeserializeObject<SchedulingData>(www.text);
  597. www.Dispose();
  598. }
  599. public async Task InitRKZYData()
  600. {
  601. bool successInternet = true;
  602. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGetMovePlans);
  603. requestData.timeout = timeOut;
  604. await requestData.SendWebRequest();
  605. try
  606. {
  607. if (true)
  608. {
  609. Debug.LogWarning("RKZYLayer联网不成功,读本地缓存数据,原因:返request不成功");
  610. successInternet = false;
  611. }
  612. else
  613. {
  614. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  615. // 提取data字段的值
  616. JToken dataToken = jsonObject["data"];
  617. JToken codeToken = jsonObject["code"];
  618. if (codeToken.ToString() == "200")
  619. {
  620. GlobalData.allServerMovePlans = JsonConvert.DeserializeObject<List<ServerMovePlan>>(dataToken.ToString());
  621. }
  622. else
  623. {
  624. successInternet = false;
  625. Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返序列化失败");
  626. }
  627. }
  628. }
  629. catch (Exception e)
  630. {
  631. successInternet = false;
  632. Debug.LogWarning("RKZYLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
  633. }
  634. if (!successInternet)
  635. {
  636. WWW www = new WWW(Application.streamingAssetsPath + "/moveplan.json");
  637. await new UnityAsync.WaitUntil(() =>
  638. {
  639. return www.isDone;
  640. });
  641. GlobalData.allServerMovePlans = JsonConvert.DeserializeObject<List<ServerMovePlan>>(www.text);
  642. www.Dispose();
  643. }
  644. }
  645. public async Task InitSWYJData()
  646. {
  647. InitSWYJData0();
  648. await InitSWYJData1();
  649. await InitSWYJData2();
  650. OnSWYJRefresh?.Invoke();
  651. }
  652. public async Task InitSWYJData1()
  653. {
  654. GlobalData.BuYuanShuiWeiDataList = new List<ShuiWeiData>();
  655. var devicesInfo = _devicesIdDatas_BuYuan["上游水位计"];
  656. string sw1Result = await GetSingleDevicesInfo(devicesInfo.ChannelID, devicesInfo.DeviceID, 24);
  657. try
  658. {
  659. GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(sw1Result);
  660. if (tempData != null)
  661. {
  662. GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
  663. {
  664. name = "补元上游水位",
  665. targetName = "BY_ShuiWei_Up",
  666. value = tempData.datas[0].NodeValue / 100,
  667. type = shuiWeiType.BuYuanShuiWei,
  668. datas = tempData.datas.ToArray()
  669. });
  670. }
  671. }
  672. catch (Exception e)
  673. {
  674. Debug.LogWarning("补元上游水位不成功,原因:" + e.ToString());
  675. }
  676. var devicesInfo1 = _devicesIdDatas_BuYuan["下游水位计"];
  677. string sw2Result = await GetSingleDevicesInfo(devicesInfo1.ChannelID, devicesInfo1.DeviceID, 24);
  678. try
  679. {
  680. GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(sw2Result);
  681. if (tempData != null)
  682. {
  683. GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
  684. {
  685. name = "补元下游水位",
  686. targetName = "BY_ShuiWei_Down",
  687. value = tempData.datas[0].NodeValue / 100,
  688. type = shuiWeiType.BuYuanShuiWei,
  689. datas = tempData.datas.ToArray()
  690. });
  691. }
  692. }
  693. catch (Exception e)
  694. {
  695. Debug.LogWarning("补元下游水位不成功,原因:" + e.ToString());
  696. }
  697. string dayResult = await GetSingleDevicesInfo_day(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
  698. try
  699. {
  700. GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(dayResult);
  701. GlobalData.buYuanShuiWei_day = new ShuiWeiBianHuaData();
  702. GlobalData.buYuanShuiWei_day.name = new string[6];
  703. GlobalData.buYuanShuiWei_day.value = new double[6];
  704. for (int i = 0; i < tempData.datas.Count; i++)
  705. {
  706. GlobalData.buYuanShuiWei_day.name[i] = tempData.datas[i].RecvTime;
  707. GlobalData.buYuanShuiWei_day.value[i] = tempData.datas[i].NodeValue;
  708. }
  709. }
  710. catch (Exception e)
  711. {
  712. Debug.LogWarning("获取6天平均数据不成功,原因:" + e.ToString());
  713. }
  714. string monthResult = await GetSingleDevicesInfo_month(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
  715. try
  716. {
  717. GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(monthResult);
  718. GlobalData.buYuanShuiWei_month = new ShuiWeiBianHuaData();
  719. GlobalData.buYuanShuiWei_month.name = new string[6];
  720. GlobalData.buYuanShuiWei_month.value = new double[6];
  721. for (int i = 0; i < tempData.datas.Count; i++)
  722. {
  723. GlobalData.buYuanShuiWei_month.name[i] = tempData.datas[i].RecvTime;
  724. GlobalData.buYuanShuiWei_month.value[i] = tempData.datas[i].NodeValue;
  725. }
  726. }
  727. catch (Exception e)
  728. {
  729. Debug.LogWarning("获取6月平均数据不成功,原因:" + e.ToString());
  730. }
  731. string hourResult = await GetSingleDevicesInfo_hour(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
  732. try
  733. {
  734. GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(hourResult);
  735. GlobalData.buYuanShuiWei_hour = new ShuiWeiBianHuaData();
  736. GlobalData.buYuanShuiWei_hour.name = new string[6];
  737. GlobalData.buYuanShuiWei_hour.value = new double[6];
  738. for (int i = 0; i < tempData.datas.Count; i++)
  739. {
  740. GlobalData.buYuanShuiWei_hour.name[i] = tempData.datas[i].RecvTime;
  741. GlobalData.buYuanShuiWei_hour.value[i] = tempData.datas[i].NodeValue;
  742. }
  743. }
  744. catch (Exception e)
  745. {
  746. Debug.LogWarning("获取6小时平均数据不成功,原因:" + e.ToString());
  747. }
  748. }
  749. public async Task InitSWYJData2()
  750. {
  751. bool successInternet = true;
  752. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeSWData);
  753. requestData.timeout = timeOut;
  754. await requestData.SendWebRequest();
  755. try
  756. {
  757. if (requestData.result != UnityWebRequest.Result.Success)
  758. {
  759. Debug.LogWarning("水位高度联网不成功,原因:返request不成功");
  760. successInternet = false;
  761. }
  762. else
  763. {
  764. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  765. // 提取data字段的值
  766. JToken dataToken = jsonObject["data"];
  767. JToken codeToken = jsonObject["code"];
  768. if (codeToken.ToString() == "200")
  769. {
  770. GlobalData.swDatas = JsonConvert.DeserializeObject<List<StationData>>(dataToken.ToString());
  771. }
  772. else
  773. {
  774. Debug.LogWarning("水位高度联网不成功,原因:返序列化失败");
  775. successInternet = false;
  776. }
  777. for (int i = 0; i < GlobalData.BuYuanShuiWeiDataList.Count; i++)
  778. {
  779. StationData stationData = new StationData();
  780. stationData.LGTD = 113.910187f;
  781. stationData.LTTD = 30.1765823f;
  782. stationData.STNM = GlobalData.BuYuanShuiWeiDataList[i].name;
  783. stationData.upz = GlobalData.BuYuanShuiWeiDataList[i].name.Contains("上") ? GlobalData.BuYuanShuiWeiDataList[i].value : -1;
  784. stationData.dwz = GlobalData.BuYuanShuiWeiDataList[i].name.Contains("下") ? GlobalData.BuYuanShuiWeiDataList[i].value : -1;
  785. GlobalData.swDatas.Add(stationData);
  786. }
  787. }
  788. }
  789. catch (Exception e)
  790. {
  791. successInternet = false;
  792. Debug.LogWarning("水位高度联网不成功,原因:" + e.ToString());
  793. }
  794. }
  795. public async Task InitSWYJData0()
  796. {
  797. bool successInternet = true;
  798. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetThreeLevel);
  799. requestData.timeout = timeOut;
  800. await requestData.SendWebRequest();
  801. try
  802. {
  803. if (requestData.result != UnityWebRequest.Result.Success)
  804. {
  805. Debug.LogWarning("三线水位联网不成功,原因:返request不成功");
  806. successInternet = false;
  807. }
  808. else
  809. {
  810. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  811. // 提取data字段的值
  812. JToken dataToken = jsonObject["data"];
  813. JToken codeToken = jsonObject["code"];
  814. if (codeToken.ToString() == "200")
  815. {
  816. GlobalData.threeLevelShuiWeiDatas = JsonConvert.DeserializeObject<List<ThreeLevelShuiWeiData>>(dataToken.ToString());
  817. }
  818. else
  819. {
  820. Debug.LogWarning("三线水位联网不成功,原因:返序列化失败");
  821. successInternet = false;
  822. }
  823. }
  824. }
  825. catch (Exception e)
  826. {
  827. successInternet = false;
  828. Debug.LogWarning("三线水位联网不成功,原因:" + e.ToString());
  829. }
  830. }
  831. public async Task SendBuYuan_GetSensorData()
  832. {
  833. UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_BuYuan_GetSensorData);
  834. await www.SendWebRequest();
  835. try
  836. {
  837. if (www.result != UnityWebRequest.Result.Success)
  838. {
  839. Debug.LogWarning("获取补元闸门设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  840. }
  841. else
  842. {
  843. GlobalData.buYuanSensorData = JsonUtility.FromJson<SensorDataResult>(www.downloadHandler.text);
  844. }
  845. }
  846. catch (Exception e)
  847. {
  848. Debug.LogWarning("获取补元闸门设备数据不成功,原因:" + e.ToString());
  849. }
  850. www.Dispose();
  851. }
  852. public async Task GetBuYuanDevicesGroupInfo()
  853. {
  854. //获取所有渗压记
  855. GetDevicesData tempData = new GetDevicesData();
  856. tempData.idsList = new List<DevicesMessage>();
  857. for (int i = 0; i < 13; i++)
  858. {
  859. var devicesInfo = _devicesIdDatas_BuYuan[$"P{i + 1}"];
  860. tempData.idsList.Add(new DevicesMessage()
  861. {
  862. DeviceID = devicesInfo.DeviceID,
  863. ChannelID = devicesInfo.ChannelID
  864. });
  865. }
  866. string jsonStr;
  867. try
  868. {
  869. jsonStr = await Devices(tempData);
  870. jsonStr = "{\"datas\":" + jsonStr + "}";
  871. Debug.Log(jsonStr);
  872. GetDevicesRequestData resultData = JsonUtility.FromJson<GetDevicesRequestData>(jsonStr);
  873. GlobalData.BuYuanShuiYaDataList = new List<ShuiYaData>();
  874. for (int i = 0; i < resultData.datas.Count; i++)
  875. {
  876. GlobalData.BuYuanShuiYaDataList.Add(new ShuiYaData()
  877. {
  878. name = resultData.datas[i].NodeName,
  879. value = resultData.datas[i].NodeValue,
  880. type = shuiYaType.BuYuanShuiYa,
  881. targetName = $"BY_{resultData.datas[i].NodeName}"
  882. });
  883. }
  884. }
  885. catch (Exception e)
  886. {
  887. Debug.LogWarning("获取补元水压计设备数据不成功,原因:" + e.ToString());
  888. throw;
  889. }
  890. //获取所有位移记
  891. tempData = new GetDevicesData();
  892. tempData.idsList = new List<DevicesMessage>();
  893. for (int i = 0; i < 8; i++)
  894. {
  895. var devicesInfo = _devicesIdDatas_BuYuan[$"M{i + 1}"];
  896. tempData.idsList.Add(new DevicesMessage()
  897. {
  898. DeviceID = devicesInfo.DeviceID,
  899. ChannelID = devicesInfo.ChannelID
  900. });
  901. }
  902. try
  903. {
  904. jsonStr = await Devices(tempData);
  905. jsonStr = "{\"datas\":" + jsonStr + "}";
  906. GetDevicesRequestData resultData = JsonUtility.FromJson<GetDevicesRequestData>(jsonStr);
  907. GlobalData.BuYuanWeiYiDataList = new List<WeiYiData>();
  908. for (int i = 0; i < resultData.datas.Count; i++)
  909. {
  910. GlobalData.BuYuanWeiYiDataList.Add(new WeiYiData()
  911. {
  912. name = resultData.datas[i].NodeName,
  913. value = resultData.datas[i].NodeValue,
  914. type = weiYiType.BuYuanWeiYi,
  915. targetName = $"BY_{resultData.datas[i].NodeName}"
  916. });
  917. }
  918. }
  919. catch (Exception e)
  920. {
  921. Debug.LogWarning("获取补元位移计设备数据不成功,原因:" + e.ToString());
  922. throw;
  923. }
  924. }
  925. /// <summary>
  926. /// 获取补元硬件组数据
  927. /// </summary>
  928. /// <param name="sendData"></param>
  929. /// <returns></returns>
  930. public async Task<string> Devices(GetDevicesData sendData)
  931. {
  932. string cmdUrl = ServerAddress.API_BuYuan_GetDevicesGroupInfo;
  933. string tempStr = JsonConvert.SerializeObject(sendData);
  934. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  935. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  936. www.uploadHandler = new UploadHandlerRaw(sendByte);
  937. www.downloadHandler = new DownloadHandlerBuffer();
  938. www.SetRequestHeader("Content-Type", "application/json");
  939. await www.SendWebRequest();
  940. if (www.result != UnityWebRequest.Result.Success)
  941. {
  942. Debug.LogWarning($"获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  943. }
  944. string result = www.downloadHandler.text;
  945. www.Dispose();
  946. return result;
  947. }
  948. /// <summary>
  949. /// 获取设备的最近N条记录
  950. /// </summary>
  951. /// <param name="channelId"></param>
  952. /// <param name="deviceId"></param>
  953. /// <param name="count"></param>
  954. /// <returns></returns>
  955. public async Task<string> GetSingleDevicesInfo(int channelId, int deviceId, int count)
  956. {
  957. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo;
  958. GetSingleDeviceData sendData = new GetSingleDeviceData();
  959. sendData.ChannelID = channelId;
  960. sendData.DeviceID = deviceId;
  961. sendData.N = count;
  962. string tempStr = JsonConvert.SerializeObject(sendData);
  963. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  964. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  965. www.uploadHandler = new UploadHandlerRaw(sendByte);
  966. www.downloadHandler = new DownloadHandlerBuffer();
  967. www.SetRequestHeader("Content-Type", "application/json");
  968. await www.SendWebRequest();
  969. if (www.result != UnityWebRequest.Result.Success)
  970. {
  971. Debug.LogWarning("获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  972. }
  973. string result = www.downloadHandler.text;
  974. www.Dispose();
  975. return result;
  976. }
  977. /// <summary>
  978. /// 获取设备最近几天的平均数据
  979. /// </summary>
  980. /// <param name="channelId"></param>
  981. /// <param name="deviceId"></param>
  982. /// <param name="count"></param>
  983. /// <returns></returns>
  984. public async Task<string> GetSingleDevicesInfo_day(int channelId, int deviceId, int count)
  985. {
  986. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  987. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  988. sendData.ChannelID = channelId;
  989. sendData.DeviceID = deviceId;
  990. sendData.AvgType = "day";
  991. sendData.N = count;
  992. string tempStr = JsonConvert.SerializeObject(sendData);
  993. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  994. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  995. www.uploadHandler = new UploadHandlerRaw(sendByte);
  996. www.downloadHandler = new DownloadHandlerBuffer();
  997. www.SetRequestHeader("Content-Type", "application/json");
  998. await www.SendWebRequest();
  999. if (www.result != UnityWebRequest.Result.Success)
  1000. {
  1001. Debug.LogWarning("获取设备天平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1002. }
  1003. string result = www.downloadHandler.text;
  1004. www.Dispose();
  1005. return result;
  1006. }
  1007. /// <summary>
  1008. /// 获取设备最近几小时的平均数据
  1009. /// </summary>
  1010. /// <param name="channelId"></param>
  1011. /// <param name="deviceId"></param>
  1012. /// <param name="count"></param>
  1013. /// <returns></returns>
  1014. public async Task<string> GetSingleDevicesInfo_hour(int channelId, int deviceId, int count)
  1015. {
  1016. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  1017. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  1018. sendData.ChannelID = channelId;
  1019. sendData.DeviceID = deviceId;
  1020. sendData.AvgType = "hour";
  1021. sendData.N = count;
  1022. string tempStr = JsonConvert.SerializeObject(sendData);
  1023. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1024. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1025. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1026. www.downloadHandler = new DownloadHandlerBuffer();
  1027. www.SetRequestHeader("Content-Type", "application/json");
  1028. await www.SendWebRequest();
  1029. if (www.result != UnityWebRequest.Result.Success)
  1030. {
  1031. Debug.LogWarning("获取设备小时平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1032. }
  1033. string result = www.downloadHandler.text;
  1034. www.Dispose();
  1035. return result;
  1036. }
  1037. /// <summary>
  1038. /// 获取设备最近几个月的平均数据
  1039. /// </summary>
  1040. /// <param name="channelId"></param>
  1041. /// <param name="deviceId"></param>
  1042. /// <param name="count"></param>
  1043. /// <returns></returns>
  1044. public async Task<string> GetSingleDevicesInfo_month(int channelId, int deviceId, int count)
  1045. {
  1046. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  1047. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  1048. sendData.ChannelID = channelId;
  1049. sendData.DeviceID = deviceId;
  1050. sendData.AvgType = "month";
  1051. sendData.N = count;
  1052. string tempStr = JsonConvert.SerializeObject(sendData);
  1053. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1054. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1055. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1056. www.downloadHandler = new DownloadHandlerBuffer();
  1057. www.SetRequestHeader("Content-Type", "application/json");
  1058. await www.SendWebRequest();
  1059. if (www.result != UnityWebRequest.Result.Success)
  1060. {
  1061. Debug.LogWarning("获取设备月平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1062. }
  1063. string result = www.downloadHandler.text;
  1064. www.Dispose();
  1065. return result;
  1066. }
  1067. /// <summary>
  1068. /// 0 补元 1套口
  1069. /// </summary>
  1070. /// <param name="type"></param>
  1071. public async Task InitGCYWData1(int type)
  1072. {
  1073. GlobalData.B08_Type = type;
  1074. string jsonStr;
  1075. try
  1076. {
  1077. jsonStr = await B08_API_data(ServerAddress.API_B08_dataStatis,type);
  1078. Debug.Log("API_B08_dataStatis" + jsonStr);
  1079. GlobalData.B08DataStatis = JsonConvert.DeserializeObject<B08_dataStatis>(jsonStr);
  1080. }
  1081. catch (Exception e)
  1082. {
  1083. Debug.LogWarning("获取API_B08_dataStatis数据不成功,原因:" + e.ToString());
  1084. }
  1085. try
  1086. {
  1087. jsonStr = await B08_API_data(ServerAddress.API_B08_inspectResult,type);
  1088. Debug.Log("API_B08_inspectResult" + jsonStr);
  1089. GlobalData.B08InspectResult = JsonConvert.DeserializeObject<B08_inspectResult>(jsonStr);
  1090. }
  1091. catch (Exception e)
  1092. {
  1093. Debug.LogWarning("获取API_B08_inspectResult数据不成功,原因:" + e.ToString());
  1094. }
  1095. try
  1096. {
  1097. jsonStr = await B08_API_data(ServerAddress.API_B08_projectExamine,type);
  1098. Debug.Log("API_B08_projectExamine" + jsonStr);
  1099. GlobalData.B08ProjectExamine = JsonConvert.DeserializeObject<B08_projectExamine>(jsonStr);
  1100. }
  1101. catch (Exception e)
  1102. {
  1103. Debug.LogWarning("获取API_B08_projectExamine数据不成功,原因:" + e.ToString());
  1104. }
  1105. try
  1106. {
  1107. jsonStr = await B08_API_data(ServerAddress.API_B08_event,type);
  1108. Debug.Log("API_B08_event" + jsonStr);
  1109. GlobalData.B08Event = JsonConvert.DeserializeObject<B08_event>(jsonStr);
  1110. }
  1111. catch (Exception e)
  1112. {
  1113. Debug.LogWarning("获取API_B08_event数据不成功,原因:" + e.ToString());
  1114. }
  1115. try
  1116. {
  1117. jsonStr = await B08_API_data(ServerAddress.API_B08_questionStatis,type);
  1118. Debug.Log("API_B08_questionStatis" + jsonStr);
  1119. GlobalData.B08QuestionStatis = JsonConvert.DeserializeObject<B08_questionStatis>(jsonStr);
  1120. }
  1121. catch (Exception e)
  1122. {
  1123. Debug.LogWarning("获取API_B08_questionStatis数据不成功,原因:" + e.ToString());
  1124. }
  1125. try
  1126. {
  1127. jsonStr = await B08_API_data(ServerAddress.API_B08_inspectType,type);
  1128. Debug.Log("API_B08_inspectType" + jsonStr);
  1129. GlobalData.B08InspectType = JsonConvert.DeserializeObject<B08_inspectType>(jsonStr);
  1130. }
  1131. catch (Exception e)
  1132. {
  1133. Debug.LogWarning("获取API_B08_inspectType数据不成功,原因:" + e.ToString());
  1134. }
  1135. }
  1136. public async Task<string> B08_API_data(string cmdUrl,int type)
  1137. {
  1138. if (type == 0)
  1139. {
  1140. cmdUrl += "1794245918999351298";
  1141. }
  1142. else
  1143. {
  1144. cmdUrl += "1798366756789653505";
  1145. }
  1146. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  1147. www.downloadHandler = new DownloadHandlerBuffer();
  1148. www.SetRequestHeader("Content-Type", "application/json");
  1149. await www.SendWebRequest();
  1150. if (www.result != UnityWebRequest.Result.Success)
  1151. {
  1152. Debug.LogWarning($"获取{cmdUrl}数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1153. }
  1154. string result = www.downloadHandler.text;
  1155. www.Dispose();
  1156. return result;
  1157. }
  1158. /// <summary>
  1159. /// 获取站点水位信息
  1160. /// </summary>
  1161. /// <param name="stcd"></param>
  1162. /// <returns></returns>
  1163. public async Task<string> GetWaterTrend_Chart(string stcd)
  1164. {
  1165. UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetWaterTrend_chart+stcd, "Get");
  1166. www.downloadHandler = new DownloadHandlerBuffer();
  1167. www.SetRequestHeader("Content-Type", "application/json");
  1168. await www.SendWebRequest();
  1169. if (www.result != UnityWebRequest.Result.Success)
  1170. {
  1171. Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1172. }
  1173. string result = www.downloadHandler.text;
  1174. www.Dispose();
  1175. return result;
  1176. }
  1177. public async Task<string> GetWaterTrend_List(string stcd)
  1178. {
  1179. UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetWaterTrend_list+stcd, "Get");
  1180. www.downloadHandler = new DownloadHandlerBuffer();
  1181. www.SetRequestHeader("Content-Type", "application/json");
  1182. await www.SendWebRequest();
  1183. if (www.result != UnityWebRequest.Result.Success)
  1184. {
  1185. Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1186. }
  1187. string result = www.downloadHandler.text;
  1188. www.Dispose();
  1189. return result;
  1190. }
  1191. public void SaveFirstFrame(byte[] uploadData, string fileName, string _targetName)
  1192. {
  1193. StartCoroutine(SendSaveFirstFrame(uploadData, fileName, _targetName));
  1194. }
  1195. IEnumerator SendSaveFirstFrame(byte[] uploadData, string fileName, string _targetName)
  1196. {
  1197. Debug.Log(fileName);
  1198. WWWForm form = new WWWForm();
  1199. form.AddBinaryData("file", uploadData, fileName);
  1200. UnityWebRequest www = UnityWebRequest.Post(ServerAddress.API_TextureUploadPath, form);
  1201. yield return www.SendWebRequest();
  1202. if (www.result == UnityWebRequest.Result.Success)
  1203. {
  1204. ActionInstance._Instance.obsFmUpdata?.Invoke(_targetName);
  1205. }
  1206. Debug.Log(www.downloadHandler.text);
  1207. www.Dispose();
  1208. }
  1209. #region 摄像头远程控制
  1210. public void GetDeviceChannelId(string deviceId, Action<string> callBack)
  1211. {
  1212. StartCoroutine(SendGetDevicesChannel(deviceId, 1, 1, callBack));
  1213. }
  1214. IEnumerator SendGetDevicesChannel(string deviceId, int page, int count, Action<string> call)
  1215. {
  1216. string sendUrl = ServerAddress.API_GetDevicesInfo;
  1217. sendUrl += $"/{deviceId}/channels?page={page}&count={count}&query&online&channelType&catalogUnderDevice";
  1218. UnityWebRequest www = UnityWebRequest.Get(sendUrl);
  1219. yield return www.SendWebRequest();
  1220. ObsHttpRequestData tempData = JsonConvert.DeserializeObject<ObsHttpRequestData>(www.downloadHandler.text);
  1221. GetObsChannelRequestData channelData = tempData.data.ToObject<GetObsChannelRequestData>();
  1222. call?.Invoke(channelData.list[0].channelId);
  1223. www.Dispose();
  1224. }
  1225. IEnumerator SendStartRTSP(string deviceId, string channelId)
  1226. {
  1227. string sendUrl = ServerAddress.API_PlayStart;
  1228. sendUrl += $"/{deviceId}/{channelId}";
  1229. UnityWebRequest www = UnityWebRequest.Get(sendUrl);
  1230. yield return www.SendWebRequest();
  1231. Debug.Log(www.downloadHandler.text);
  1232. www.Dispose();
  1233. }
  1234. public void SendObsCameraCtrlCmd(string deviceId, string channelId, ObsCtrlType type)
  1235. {
  1236. StartCoroutine(SendCameraCtrl(deviceId, channelId, type.ToString()));
  1237. }
  1238. IEnumerator SendCameraCtrl(string deviceId, string channelId, string command)
  1239. {
  1240. string sendUrl = ServerAddress.API_CameraCtrl;
  1241. sendUrl += $"/{deviceId}/{channelId}?command={command}&horizonSpeed=10&verticalSpeed=10&zoomSpeed=10";
  1242. UnityWebRequest www = UnityWebRequest.Post(sendUrl, "");
  1243. Debug.Log("send:" + sendUrl);
  1244. yield return www.SendWebRequest();
  1245. Debug.Log(www.downloadHandler.text);
  1246. www.Dispose();
  1247. }
  1248. #endregion
  1249. /// <summary>
  1250. /// 初始化所有补元硬件设备的获取信息
  1251. /// </summary>
  1252. public void InItBuYuanDevicesList()
  1253. {
  1254. _devicesIdDatas_BuYuan = new Dictionary<string, DevicesId_Data>();
  1255. _devicesIdDatas_BuYuan.Add("上游水位计", new DevicesId_Data()
  1256. {
  1257. ChannelID = 7,
  1258. DeviceID = 4,
  1259. name = "上游水位计",
  1260. showName = "",
  1261. value = -1
  1262. });
  1263. _devicesIdDatas_BuYuan.Add("下游水位计", new DevicesId_Data()
  1264. {
  1265. ChannelID = 8,
  1266. DeviceID = 4,
  1267. name = "上游水位计",
  1268. showName = "",
  1269. value = -1
  1270. });
  1271. #region P
  1272. _devicesIdDatas_BuYuan.Add("P1", new DevicesId_Data()
  1273. {
  1274. ChannelID = 1,
  1275. DeviceID = 2,
  1276. name = "P1/UP1",
  1277. showName = "",
  1278. value = -1
  1279. });
  1280. _devicesIdDatas_BuYuan.Add("P2", new DevicesId_Data()
  1281. {
  1282. ChannelID = 2,
  1283. DeviceID = 2,
  1284. name = "P2/UP2",
  1285. showName = "",
  1286. value = -1
  1287. });
  1288. _devicesIdDatas_BuYuan.Add("P3", new DevicesId_Data()
  1289. {
  1290. ChannelID = 3,
  1291. DeviceID = 2,
  1292. name = "P3",
  1293. showName = "",
  1294. value = -1
  1295. });
  1296. _devicesIdDatas_BuYuan.Add("P4", new DevicesId_Data()
  1297. {
  1298. ChannelID = 4,
  1299. DeviceID = 2,
  1300. name = "P4/UP3",
  1301. showName = "",
  1302. value = -1
  1303. });
  1304. _devicesIdDatas_BuYuan.Add("P5", new DevicesId_Data()
  1305. {
  1306. ChannelID = 1,
  1307. DeviceID = 3,
  1308. name = "P5/UP5",
  1309. showName = "",
  1310. value = -1
  1311. });
  1312. _devicesIdDatas_BuYuan.Add("P6", new DevicesId_Data()
  1313. {
  1314. ChannelID = 2,
  1315. DeviceID = 3,
  1316. name = "P6/",
  1317. showName = "",
  1318. value = -1
  1319. });
  1320. _devicesIdDatas_BuYuan.Add("P7", new DevicesId_Data()
  1321. {
  1322. ChannelID = 3,
  1323. DeviceID = 3,
  1324. name = "P7/UP5",
  1325. showName = "",
  1326. value = -1
  1327. });
  1328. _devicesIdDatas_BuYuan.Add("P8", new DevicesId_Data()
  1329. {
  1330. ChannelID = 4,
  1331. DeviceID = 3,
  1332. name = "P8/UP6",
  1333. showName = "",
  1334. value = -1
  1335. });
  1336. _devicesIdDatas_BuYuan.Add("P5温度", new DevicesId_Data()
  1337. {
  1338. ChannelID = 9,
  1339. DeviceID = 3,
  1340. name = "P5温度",
  1341. showName = "",
  1342. value = -1
  1343. });
  1344. _devicesIdDatas_BuYuan.Add("P6温度", new DevicesId_Data()
  1345. {
  1346. ChannelID = 10,
  1347. DeviceID = 3,
  1348. name = "P6温度",
  1349. showName = "",
  1350. value = -1
  1351. });
  1352. _devicesIdDatas_BuYuan.Add("P7温度", new DevicesId_Data()
  1353. {
  1354. ChannelID = 11,
  1355. DeviceID = 3,
  1356. name = "P7温度",
  1357. showName = "",
  1358. value = -1
  1359. });
  1360. _devicesIdDatas_BuYuan.Add("P8温度", new DevicesId_Data()
  1361. {
  1362. ChannelID = 12,
  1363. DeviceID = 3,
  1364. name = "P8温度",
  1365. showName = "",
  1366. value = -1
  1367. });
  1368. _devicesIdDatas_BuYuan.Add("P9温度", new DevicesId_Data()
  1369. {
  1370. ChannelID = 9,
  1371. DeviceID = 4,
  1372. name = "P9温度",
  1373. showName = "",
  1374. value = -1
  1375. });
  1376. _devicesIdDatas_BuYuan.Add("P10温度", new DevicesId_Data()
  1377. {
  1378. ChannelID = 10,
  1379. DeviceID = 4,
  1380. name = "P10温度",
  1381. showName = "",
  1382. value = -1
  1383. });
  1384. _devicesIdDatas_BuYuan.Add("P12温度", new DevicesId_Data()
  1385. {
  1386. ChannelID = 11,
  1387. DeviceID = 4,
  1388. name = "P12温度",
  1389. showName = "",
  1390. value = -1
  1391. });
  1392. _devicesIdDatas_BuYuan.Add("P9", new DevicesId_Data()
  1393. {
  1394. ChannelID = 3,
  1395. DeviceID = 4,
  1396. name = "P9",
  1397. showName = "",
  1398. value = -1
  1399. });
  1400. _devicesIdDatas_BuYuan.Add("P10", new DevicesId_Data()
  1401. {
  1402. ChannelID = 4,
  1403. DeviceID = 4,
  1404. name = "P10/UP7",
  1405. showName = "",
  1406. value = -1
  1407. });
  1408. _devicesIdDatas_BuYuan.Add("P11", new DevicesId_Data()
  1409. {
  1410. ChannelID = 5,
  1411. DeviceID = 4,
  1412. name = "P11/UP8",
  1413. showName = "",
  1414. value = -1
  1415. });
  1416. _devicesIdDatas_BuYuan.Add("P12", new DevicesId_Data()
  1417. {
  1418. ChannelID = 1,
  1419. DeviceID = 4,
  1420. name = "P12/UP9",
  1421. showName = "",
  1422. value = -1
  1423. });
  1424. _devicesIdDatas_BuYuan.Add("P13", new DevicesId_Data()
  1425. {
  1426. ChannelID = 2,
  1427. DeviceID = 4,
  1428. name = "P13/UP10",
  1429. showName = "",
  1430. value = -1
  1431. });
  1432. #endregion
  1433. #region M
  1434. //M1-8
  1435. int m_cid = 1;
  1436. int m_did = 5;
  1437. for (int i = 0; i < 8; i++)
  1438. {
  1439. _devicesIdDatas_BuYuan.Add($"M{i + 1}", new DevicesId_Data()
  1440. {
  1441. ChannelID = m_cid + i,
  1442. DeviceID = m_did,
  1443. name = $"M{i + 1}",
  1444. showName = "",
  1445. value = -1
  1446. });
  1447. }
  1448. //M温度
  1449. _devicesIdDatas_BuYuan.Add($"M2温度", new DevicesId_Data()
  1450. {
  1451. ChannelID = 10,
  1452. DeviceID = 5,
  1453. name = $"M2温度",
  1454. showName = "",
  1455. value = -1
  1456. });
  1457. _devicesIdDatas_BuYuan.Add($"M5温度", new DevicesId_Data()
  1458. {
  1459. ChannelID = 13,
  1460. DeviceID = 5,
  1461. name = $"M5温度",
  1462. showName = "",
  1463. value = -1
  1464. });
  1465. _devicesIdDatas_BuYuan.Add($"M6温度", new DevicesId_Data()
  1466. {
  1467. ChannelID = 14,
  1468. DeviceID = 5,
  1469. name = $"M6温度",
  1470. showName = "",
  1471. value = -1
  1472. });
  1473. _devicesIdDatas_BuYuan.Add($"M7温度", new DevicesId_Data()
  1474. {
  1475. ChannelID = 15,
  1476. DeviceID = 5,
  1477. name = $"M7温度",
  1478. showName = "",
  1479. value = -1
  1480. });
  1481. _devicesIdDatas_BuYuan.Add($"M8温度", new DevicesId_Data()
  1482. {
  1483. ChannelID = 16,
  1484. DeviceID = 5,
  1485. name = $"M8温度",
  1486. showName = "",
  1487. value = -1
  1488. });
  1489. #endregion
  1490. }
  1491. }