HttpHelper.cs 56 KB

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