HttpHelper.cs 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  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. public async Task SendTaoKou_GetSensorData()
  926. {
  927. UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_TaoKou_GetSensorData);
  928. await www.SendWebRequest();
  929. try
  930. {
  931. if (www.result != UnityWebRequest.Result.Success)
  932. {
  933. Debug.LogWarning("获取套口闸门设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  934. }
  935. else
  936. {
  937. GlobalData.taoKouSensorData = JsonUtility.FromJson<SensorDataResult>(www.downloadHandler.text);
  938. }
  939. }
  940. catch (Exception e)
  941. {
  942. Debug.LogWarning("获取套口闸门设备数据不成功,原因:" + e.ToString());
  943. }
  944. www.Dispose();
  945. }
  946. /// <summary>
  947. /// 获取补元硬件组数据
  948. /// </summary>
  949. /// <param name="sendData"></param>
  950. /// <returns></returns>
  951. public async Task<string> Devices(GetDevicesData sendData)
  952. {
  953. string cmdUrl = ServerAddress.API_BuYuan_GetDevicesGroupInfo;
  954. string tempStr = JsonConvert.SerializeObject(sendData);
  955. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  956. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  957. www.uploadHandler = new UploadHandlerRaw(sendByte);
  958. www.downloadHandler = new DownloadHandlerBuffer();
  959. www.SetRequestHeader("Content-Type", "application/json");
  960. await www.SendWebRequest();
  961. if (www.result != UnityWebRequest.Result.Success)
  962. {
  963. Debug.LogWarning($"获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  964. }
  965. string result = www.downloadHandler.text;
  966. www.Dispose();
  967. return result;
  968. }
  969. /// <summary>
  970. /// 获取设备的最近N条记录
  971. /// </summary>
  972. /// <param name="channelId"></param>
  973. /// <param name="deviceId"></param>
  974. /// <param name="count"></param>
  975. /// <returns></returns>
  976. public async Task<string> GetSingleDevicesInfo(int channelId, int deviceId, int count)
  977. {
  978. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo;
  979. GetSingleDeviceData sendData = new GetSingleDeviceData();
  980. sendData.ChannelID = channelId;
  981. sendData.DeviceID = deviceId;
  982. sendData.N = count;
  983. string tempStr = JsonConvert.SerializeObject(sendData);
  984. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  985. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  986. www.uploadHandler = new UploadHandlerRaw(sendByte);
  987. www.downloadHandler = new DownloadHandlerBuffer();
  988. www.SetRequestHeader("Content-Type", "application/json");
  989. await www.SendWebRequest();
  990. if (www.result != UnityWebRequest.Result.Success)
  991. {
  992. Debug.LogWarning("获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  993. }
  994. string result = www.downloadHandler.text;
  995. www.Dispose();
  996. return result;
  997. }
  998. /// <summary>
  999. /// 获取设备最近几天的平均数据
  1000. /// </summary>
  1001. /// <param name="channelId"></param>
  1002. /// <param name="deviceId"></param>
  1003. /// <param name="count"></param>
  1004. /// <returns></returns>
  1005. public async Task<string> GetSingleDevicesInfo_day(int channelId, int deviceId, int count)
  1006. {
  1007. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  1008. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  1009. sendData.ChannelID = channelId;
  1010. sendData.DeviceID = deviceId;
  1011. sendData.AvgType = "day";
  1012. sendData.N = count;
  1013. string tempStr = JsonConvert.SerializeObject(sendData);
  1014. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1015. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1016. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1017. www.downloadHandler = new DownloadHandlerBuffer();
  1018. www.SetRequestHeader("Content-Type", "application/json");
  1019. await www.SendWebRequest();
  1020. if (www.result != UnityWebRequest.Result.Success)
  1021. {
  1022. Debug.LogWarning("获取设备天平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1023. }
  1024. string result = www.downloadHandler.text;
  1025. www.Dispose();
  1026. return result;
  1027. }
  1028. /// <summary>
  1029. /// 获取设备最近几小时的平均数据
  1030. /// </summary>
  1031. /// <param name="channelId"></param>
  1032. /// <param name="deviceId"></param>
  1033. /// <param name="count"></param>
  1034. /// <returns></returns>
  1035. public async Task<string> GetSingleDevicesInfo_hour(int channelId, int deviceId, int count)
  1036. {
  1037. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  1038. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  1039. sendData.ChannelID = channelId;
  1040. sendData.DeviceID = deviceId;
  1041. sendData.AvgType = "hour";
  1042. sendData.N = count;
  1043. string tempStr = JsonConvert.SerializeObject(sendData);
  1044. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1045. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1046. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1047. www.downloadHandler = new DownloadHandlerBuffer();
  1048. www.SetRequestHeader("Content-Type", "application/json");
  1049. await www.SendWebRequest();
  1050. if (www.result != UnityWebRequest.Result.Success)
  1051. {
  1052. Debug.LogWarning("获取设备小时平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1053. }
  1054. string result = www.downloadHandler.text;
  1055. www.Dispose();
  1056. return result;
  1057. }
  1058. /// <summary>
  1059. /// 获取设备最近几个月的平均数据
  1060. /// </summary>
  1061. /// <param name="channelId"></param>
  1062. /// <param name="deviceId"></param>
  1063. /// <param name="count"></param>
  1064. /// <returns></returns>
  1065. public async Task<string> GetSingleDevicesInfo_month(int channelId, int deviceId, int count)
  1066. {
  1067. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  1068. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  1069. sendData.ChannelID = channelId;
  1070. sendData.DeviceID = deviceId;
  1071. sendData.AvgType = "month";
  1072. sendData.N = count;
  1073. string tempStr = JsonConvert.SerializeObject(sendData);
  1074. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1075. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1076. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1077. www.downloadHandler = new DownloadHandlerBuffer();
  1078. www.SetRequestHeader("Content-Type", "application/json");
  1079. await www.SendWebRequest();
  1080. if (www.result != UnityWebRequest.Result.Success)
  1081. {
  1082. Debug.LogWarning("获取设备月平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1083. }
  1084. string result = www.downloadHandler.text;
  1085. www.Dispose();
  1086. return result;
  1087. }
  1088. /// <summary>
  1089. /// 0 补元 1套口
  1090. /// </summary>
  1091. /// <param name="type"></param>
  1092. public async Task InitGCYWData1(int type)
  1093. {
  1094. GlobalData.B08_Type = type;
  1095. string jsonStr;
  1096. try
  1097. {
  1098. jsonStr = await B08_API_data(ServerAddress.API_B08_dataStatis,type);
  1099. Debug.Log("API_B08_dataStatis" + jsonStr);
  1100. GlobalData.B08DataStatis = JsonConvert.DeserializeObject<B08_dataStatis>(jsonStr);
  1101. }
  1102. catch (Exception e)
  1103. {
  1104. Debug.LogWarning("获取API_B08_dataStatis数据不成功,原因:" + e.ToString());
  1105. }
  1106. try
  1107. {
  1108. jsonStr = await B08_API_data(ServerAddress.API_B08_inspectResult,type);
  1109. Debug.Log("API_B08_inspectResult" + jsonStr);
  1110. GlobalData.B08InspectResult = JsonConvert.DeserializeObject<B08_inspectResult>(jsonStr);
  1111. }
  1112. catch (Exception e)
  1113. {
  1114. Debug.LogWarning("获取API_B08_inspectResult数据不成功,原因:" + e.ToString());
  1115. }
  1116. try
  1117. {
  1118. jsonStr = await B08_API_data(ServerAddress.API_B08_projectExamine,type);
  1119. Debug.Log("API_B08_projectExamine" + jsonStr);
  1120. GlobalData.B08ProjectExamine = JsonConvert.DeserializeObject<B08_projectExamine>(jsonStr);
  1121. }
  1122. catch (Exception e)
  1123. {
  1124. Debug.LogWarning("获取API_B08_projectExamine数据不成功,原因:" + e.ToString());
  1125. }
  1126. try
  1127. {
  1128. jsonStr = await B08_API_data(ServerAddress.API_B08_event,type);
  1129. Debug.Log("API_B08_event" + jsonStr);
  1130. GlobalData.B08Event = JsonConvert.DeserializeObject<B08_event>(jsonStr);
  1131. }
  1132. catch (Exception e)
  1133. {
  1134. Debug.LogWarning("获取API_B08_event数据不成功,原因:" + e.ToString());
  1135. }
  1136. try
  1137. {
  1138. jsonStr = await B08_API_data(ServerAddress.API_B08_questionStatis,type);
  1139. Debug.Log("API_B08_questionStatis" + jsonStr);
  1140. GlobalData.B08QuestionStatis = JsonConvert.DeserializeObject<B08_questionStatis>(jsonStr);
  1141. }
  1142. catch (Exception e)
  1143. {
  1144. Debug.LogWarning("获取API_B08_questionStatis数据不成功,原因:" + e.ToString());
  1145. }
  1146. try
  1147. {
  1148. jsonStr = await B08_API_data(ServerAddress.API_B08_inspectType,type);
  1149. Debug.Log("API_B08_inspectType" + jsonStr);
  1150. GlobalData.B08InspectType = JsonConvert.DeserializeObject<B08_inspectType>(jsonStr);
  1151. }
  1152. catch (Exception e)
  1153. {
  1154. Debug.LogWarning("获取API_B08_inspectType数据不成功,原因:" + e.ToString());
  1155. }
  1156. }
  1157. public async Task<string> B08_API_data(string cmdUrl,int type)
  1158. {
  1159. if (type == 0)
  1160. {
  1161. cmdUrl += "1794245918999351298";
  1162. }
  1163. else
  1164. {
  1165. cmdUrl += "1798366756789653505";
  1166. }
  1167. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  1168. www.downloadHandler = new DownloadHandlerBuffer();
  1169. www.SetRequestHeader("Content-Type", "application/json");
  1170. await www.SendWebRequest();
  1171. if (www.result != UnityWebRequest.Result.Success)
  1172. {
  1173. Debug.LogWarning($"获取{cmdUrl}数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1174. }
  1175. string result = www.downloadHandler.text;
  1176. www.Dispose();
  1177. return result;
  1178. }
  1179. /// <summary>
  1180. /// 获取站点水位信息
  1181. /// </summary>
  1182. /// <param name="stcd"></param>
  1183. /// <returns></returns>
  1184. public async Task<string> GetWaterTrend_Chart(string stcd)
  1185. {
  1186. UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetWaterTrend_chart+stcd, "Get");
  1187. www.downloadHandler = new DownloadHandlerBuffer();
  1188. www.SetRequestHeader("Content-Type", "application/json");
  1189. await www.SendWebRequest();
  1190. if (www.result != UnityWebRequest.Result.Success)
  1191. {
  1192. Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1193. }
  1194. string result = www.downloadHandler.text;
  1195. www.Dispose();
  1196. return result;
  1197. }
  1198. public async Task<string> GetWaterTrend_List(string stcd)
  1199. {
  1200. UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetWaterTrend_list+stcd, "Get");
  1201. www.downloadHandler = new DownloadHandlerBuffer();
  1202. www.SetRequestHeader("Content-Type", "application/json");
  1203. await www.SendWebRequest();
  1204. if (www.result != UnityWebRequest.Result.Success)
  1205. {
  1206. Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1207. }
  1208. string result = www.downloadHandler.text;
  1209. www.Dispose();
  1210. return result;
  1211. }
  1212. public void SaveFirstFrame(byte[] uploadData, string fileName, string _targetName)
  1213. {
  1214. StartCoroutine(SendSaveFirstFrame(uploadData, fileName, _targetName));
  1215. }
  1216. IEnumerator SendSaveFirstFrame(byte[] uploadData, string fileName, string _targetName)
  1217. {
  1218. Debug.Log(fileName);
  1219. WWWForm form = new WWWForm();
  1220. form.AddBinaryData("file", uploadData, fileName);
  1221. UnityWebRequest www = UnityWebRequest.Post(ServerAddress.API_TextureUploadPath, form);
  1222. yield return www.SendWebRequest();
  1223. if (www.result == UnityWebRequest.Result.Success)
  1224. {
  1225. ActionInstance._Instance.obsFmUpdata?.Invoke(_targetName);
  1226. }
  1227. Debug.Log(www.downloadHandler.text);
  1228. www.Dispose();
  1229. }
  1230. #region 摄像头远程控制
  1231. public void GetDeviceChannelId(string deviceId, Action<string> callBack)
  1232. {
  1233. StartCoroutine(SendGetDevicesChannel(deviceId, 1, 1, callBack));
  1234. }
  1235. IEnumerator SendGetDevicesChannel(string deviceId, int page, int count, Action<string> call)
  1236. {
  1237. string sendUrl = ServerAddress.API_GetDevicesInfo;
  1238. sendUrl += $"/{deviceId}/channels?page={page}&count={count}&query&online&channelType&catalogUnderDevice";
  1239. UnityWebRequest www = UnityWebRequest.Get(sendUrl);
  1240. yield return www.SendWebRequest();
  1241. ObsHttpRequestData tempData = JsonConvert.DeserializeObject<ObsHttpRequestData>(www.downloadHandler.text);
  1242. GetObsChannelRequestData channelData = tempData.data.ToObject<GetObsChannelRequestData>();
  1243. call?.Invoke(channelData.list[0].channelId);
  1244. www.Dispose();
  1245. }
  1246. IEnumerator SendStartRTSP(string deviceId, string channelId)
  1247. {
  1248. string sendUrl = ServerAddress.API_PlayStart;
  1249. sendUrl += $"/{deviceId}/{channelId}";
  1250. UnityWebRequest www = UnityWebRequest.Get(sendUrl);
  1251. yield return www.SendWebRequest();
  1252. Debug.Log(www.downloadHandler.text);
  1253. www.Dispose();
  1254. }
  1255. public void SendObsCameraCtrlCmd(string deviceId, string channelId, ObsCtrlType type)
  1256. {
  1257. StartCoroutine(SendCameraCtrl(deviceId, channelId, type.ToString()));
  1258. }
  1259. IEnumerator SendCameraCtrl(string deviceId, string channelId, string command)
  1260. {
  1261. string sendUrl = ServerAddress.API_CameraCtrl;
  1262. sendUrl += $"/{deviceId}/{channelId}?command={command}&horizonSpeed=10&verticalSpeed=10&zoomSpeed=10";
  1263. UnityWebRequest www = UnityWebRequest.Post(sendUrl, "");
  1264. Debug.Log("send:" + sendUrl);
  1265. yield return www.SendWebRequest();
  1266. Debug.Log(www.downloadHandler.text);
  1267. www.Dispose();
  1268. }
  1269. #endregion
  1270. /// <summary>
  1271. /// 初始化所有补元硬件设备的获取信息
  1272. /// </summary>
  1273. public void InItBuYuanDevicesList()
  1274. {
  1275. _devicesIdDatas_BuYuan = new Dictionary<string, DevicesId_Data>();
  1276. _devicesIdDatas_BuYuan.Add("上游水位计", new DevicesId_Data()
  1277. {
  1278. ChannelID = 7,
  1279. DeviceID = 4,
  1280. name = "上游水位计",
  1281. showName = "",
  1282. value = -1
  1283. });
  1284. _devicesIdDatas_BuYuan.Add("下游水位计", new DevicesId_Data()
  1285. {
  1286. ChannelID = 8,
  1287. DeviceID = 4,
  1288. name = "上游水位计",
  1289. showName = "",
  1290. value = -1
  1291. });
  1292. #region P
  1293. _devicesIdDatas_BuYuan.Add("P1", new DevicesId_Data()
  1294. {
  1295. ChannelID = 1,
  1296. DeviceID = 2,
  1297. name = "P1/UP1",
  1298. showName = "",
  1299. value = -1
  1300. });
  1301. _devicesIdDatas_BuYuan.Add("P2", new DevicesId_Data()
  1302. {
  1303. ChannelID = 2,
  1304. DeviceID = 2,
  1305. name = "P2/UP2",
  1306. showName = "",
  1307. value = -1
  1308. });
  1309. _devicesIdDatas_BuYuan.Add("P3", new DevicesId_Data()
  1310. {
  1311. ChannelID = 3,
  1312. DeviceID = 2,
  1313. name = "P3",
  1314. showName = "",
  1315. value = -1
  1316. });
  1317. _devicesIdDatas_BuYuan.Add("P4", new DevicesId_Data()
  1318. {
  1319. ChannelID = 4,
  1320. DeviceID = 2,
  1321. name = "P4/UP3",
  1322. showName = "",
  1323. value = -1
  1324. });
  1325. _devicesIdDatas_BuYuan.Add("P5", new DevicesId_Data()
  1326. {
  1327. ChannelID = 1,
  1328. DeviceID = 3,
  1329. name = "P5/UP5",
  1330. showName = "",
  1331. value = -1
  1332. });
  1333. _devicesIdDatas_BuYuan.Add("P6", new DevicesId_Data()
  1334. {
  1335. ChannelID = 2,
  1336. DeviceID = 3,
  1337. name = "P6/",
  1338. showName = "",
  1339. value = -1
  1340. });
  1341. _devicesIdDatas_BuYuan.Add("P7", new DevicesId_Data()
  1342. {
  1343. ChannelID = 3,
  1344. DeviceID = 3,
  1345. name = "P7/UP5",
  1346. showName = "",
  1347. value = -1
  1348. });
  1349. _devicesIdDatas_BuYuan.Add("P8", new DevicesId_Data()
  1350. {
  1351. ChannelID = 4,
  1352. DeviceID = 3,
  1353. name = "P8/UP6",
  1354. showName = "",
  1355. value = -1
  1356. });
  1357. _devicesIdDatas_BuYuan.Add("P5温度", new DevicesId_Data()
  1358. {
  1359. ChannelID = 9,
  1360. DeviceID = 3,
  1361. name = "P5温度",
  1362. showName = "",
  1363. value = -1
  1364. });
  1365. _devicesIdDatas_BuYuan.Add("P6温度", new DevicesId_Data()
  1366. {
  1367. ChannelID = 10,
  1368. DeviceID = 3,
  1369. name = "P6温度",
  1370. showName = "",
  1371. value = -1
  1372. });
  1373. _devicesIdDatas_BuYuan.Add("P7温度", new DevicesId_Data()
  1374. {
  1375. ChannelID = 11,
  1376. DeviceID = 3,
  1377. name = "P7温度",
  1378. showName = "",
  1379. value = -1
  1380. });
  1381. _devicesIdDatas_BuYuan.Add("P8温度", new DevicesId_Data()
  1382. {
  1383. ChannelID = 12,
  1384. DeviceID = 3,
  1385. name = "P8温度",
  1386. showName = "",
  1387. value = -1
  1388. });
  1389. _devicesIdDatas_BuYuan.Add("P9温度", new DevicesId_Data()
  1390. {
  1391. ChannelID = 9,
  1392. DeviceID = 4,
  1393. name = "P9温度",
  1394. showName = "",
  1395. value = -1
  1396. });
  1397. _devicesIdDatas_BuYuan.Add("P10温度", new DevicesId_Data()
  1398. {
  1399. ChannelID = 10,
  1400. DeviceID = 4,
  1401. name = "P10温度",
  1402. showName = "",
  1403. value = -1
  1404. });
  1405. _devicesIdDatas_BuYuan.Add("P12温度", new DevicesId_Data()
  1406. {
  1407. ChannelID = 11,
  1408. DeviceID = 4,
  1409. name = "P12温度",
  1410. showName = "",
  1411. value = -1
  1412. });
  1413. _devicesIdDatas_BuYuan.Add("P9", new DevicesId_Data()
  1414. {
  1415. ChannelID = 3,
  1416. DeviceID = 4,
  1417. name = "P9",
  1418. showName = "",
  1419. value = -1
  1420. });
  1421. _devicesIdDatas_BuYuan.Add("P10", new DevicesId_Data()
  1422. {
  1423. ChannelID = 4,
  1424. DeviceID = 4,
  1425. name = "P10/UP7",
  1426. showName = "",
  1427. value = -1
  1428. });
  1429. _devicesIdDatas_BuYuan.Add("P11", new DevicesId_Data()
  1430. {
  1431. ChannelID = 5,
  1432. DeviceID = 4,
  1433. name = "P11/UP8",
  1434. showName = "",
  1435. value = -1
  1436. });
  1437. _devicesIdDatas_BuYuan.Add("P12", new DevicesId_Data()
  1438. {
  1439. ChannelID = 1,
  1440. DeviceID = 4,
  1441. name = "P12/UP9",
  1442. showName = "",
  1443. value = -1
  1444. });
  1445. _devicesIdDatas_BuYuan.Add("P13", new DevicesId_Data()
  1446. {
  1447. ChannelID = 2,
  1448. DeviceID = 4,
  1449. name = "P13/UP10",
  1450. showName = "",
  1451. value = -1
  1452. });
  1453. #endregion
  1454. #region M
  1455. //M1-8
  1456. int m_cid = 1;
  1457. int m_did = 5;
  1458. for (int i = 0; i < 8; i++)
  1459. {
  1460. _devicesIdDatas_BuYuan.Add($"M{i + 1}", new DevicesId_Data()
  1461. {
  1462. ChannelID = m_cid + i,
  1463. DeviceID = m_did,
  1464. name = $"M{i + 1}",
  1465. showName = "",
  1466. value = -1
  1467. });
  1468. }
  1469. //M温度
  1470. _devicesIdDatas_BuYuan.Add($"M2温度", new DevicesId_Data()
  1471. {
  1472. ChannelID = 10,
  1473. DeviceID = 5,
  1474. name = $"M2温度",
  1475. showName = "",
  1476. value = -1
  1477. });
  1478. _devicesIdDatas_BuYuan.Add($"M5温度", new DevicesId_Data()
  1479. {
  1480. ChannelID = 13,
  1481. DeviceID = 5,
  1482. name = $"M5温度",
  1483. showName = "",
  1484. value = -1
  1485. });
  1486. _devicesIdDatas_BuYuan.Add($"M6温度", new DevicesId_Data()
  1487. {
  1488. ChannelID = 14,
  1489. DeviceID = 5,
  1490. name = $"M6温度",
  1491. showName = "",
  1492. value = -1
  1493. });
  1494. _devicesIdDatas_BuYuan.Add($"M7温度", new DevicesId_Data()
  1495. {
  1496. ChannelID = 15,
  1497. DeviceID = 5,
  1498. name = $"M7温度",
  1499. showName = "",
  1500. value = -1
  1501. });
  1502. _devicesIdDatas_BuYuan.Add($"M8温度", new DevicesId_Data()
  1503. {
  1504. ChannelID = 16,
  1505. DeviceID = 5,
  1506. name = $"M8温度",
  1507. showName = "",
  1508. value = -1
  1509. });
  1510. #endregion
  1511. }
  1512. }