HttpHelper.cs 64 KB

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