HttpHelper.cs 59 KB

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