HttpHelper.cs 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641
  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.Serialization;
  11. using Newtonsoft.Json.Linq;
  12. using UnityEngine;
  13. using UnityEngine.Networking;
  14. using Unity.VisualScripting;
  15. using static System.Net.WebRequestMethods;
  16. using System.Linq;
  17. using UniTask = Cysharp.Threading.Tasks.UniTask;
  18. using UniTaskVoid = Cysharp.Threading.Tasks.UniTaskVoid;
  19. public class HttpHelper : MonoBehaviour
  20. {
  21. public Action OnSWYJRefresh;
  22. public static bool useAes = false;
  23. public static HttpHelper _Instance;
  24. public const int timeOut = 3;
  25. class DYServerAddress
  26. {
  27. public string YZTServerAddress;
  28. public string YZTServerPYAddress;
  29. public string Server_UploadPath;
  30. public string ModbusSeverAddress;
  31. public string ObsSeverAddress;
  32. public string ObsSeverM3U8Address;
  33. }
  34. void ChangeServerAddress()
  35. {
  36. //if (System.IO.File.Exists(Application.streamingAssetsPath + "/serverPath.json"))
  37. //{
  38. // string serverAddressContent = System.IO.File.ReadAllText(Application.streamingAssetsPath + "/serverPath.json");
  39. // Debug.Log(serverAddressContent);
  40. // DYServerAddress address = JsonConvert.DeserializeObject<DYServerAddress>(serverAddressContent);
  41. // ServerAddress.YZTServerAddress = address.YZTServerAddress;
  42. // ServerAddress.YZTServerPYAddress = address.YZTServerPYAddress;
  43. // ServerAddress.Server_UploadPath = address.Server_UploadPath;
  44. // ServerAddress.ModbusSeverAddress = address.ModbusSeverAddress;
  45. // ServerAddress.ObsSeverAddress = address.ObsSeverAddress;
  46. // Debug.Log(ServerAddress.ObsSeverAddress);
  47. // ServerAddress.ObsSeverM3U8Address = address.ObsSeverM3U8Address;
  48. //}
  49. }
  50. private async UniTaskVoid Awake()
  51. {
  52. _Instance = this;
  53. ChangeServerAddress();
  54. try
  55. {
  56. var tokenJson = await B08_API_GetToken();
  57. GetToken tokenResult= JsonConvert.DeserializeObject<GetToken>(tokenJson);
  58. //Debug.Log("GetToken:" + tokenResult.data.token);
  59. token = tokenResult.data.token;
  60. }
  61. catch (Exception e)
  62. {
  63. Debug.LogWarning("GetToken不成功,原因:" + e.ToString());
  64. }
  65. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2 ||
  66. GlobalData.pageIndex == PageIndex.Page3)
  67. {
  68. Debug.Log("HttpInitYZTData");
  69. //可以并行,无需等待
  70. InitYZTData();
  71. }
  72. if (GlobalData._devicesIdDatas.Count < 1)
  73. {
  74. await GetSensorList();
  75. }
  76. if (GlobalData.pageIndex == PageIndex.Page1)
  77. {
  78. SendBuYuan_GetSensorData();
  79. SendTaoKou_GetSensorData();
  80. GetBuYuanDevicesGroupInfo();
  81. GetTaoKouDevicesGroupInfo();
  82. }
  83. if (GlobalData.pageIndex == PageIndex.Page2)
  84. {
  85. SendBuYuan_GetSensorData();
  86. SendTaoKou_GetSensorData();
  87. }
  88. if (GlobalData.pageIndex == PageIndex.Page1)
  89. {
  90. Debug.Log("InitXHGKData");
  91. //可以并行,无需等待
  92. InitXHGKData(); //已完成迁移
  93. }
  94. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2)
  95. {
  96. Debug.Log("HttpInitGCJKData");
  97. //可以并行,无需等待
  98. InitGCJKData();
  99. InitGCJKData2();
  100. InitGCJKData1h();
  101. }
  102. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page3)
  103. {
  104. Debug.Log("HttpInitXHDDData");
  105. //可以并行,无需等待
  106. InitXHDDData0();
  107. InitXHDDData1();
  108. InitXHDDData2();
  109. InitXHDDData3();
  110. }
  111. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page3)
  112. {
  113. Debug.Log("HttpInitRKZYData");
  114. //可以并行,无需等待
  115. InitRKZYData();
  116. }
  117. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2 || GlobalData.pageIndex == PageIndex.Page3)
  118. {
  119. Debug.Log("HttpInitSWYJData");
  120. //可以并行,无需等待
  121. InitSWYJData();
  122. }
  123. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2)
  124. {
  125. GetGCYW_Station().Forget();
  126. }
  127. if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2 ||
  128. GlobalData.pageIndex == PageIndex.Page3)
  129. {
  130. Debug.Log("HttpInitFloorGateData");
  131. InitFloorGateData();
  132. }
  133. if (GlobalData.pageIndex == PageIndex.Page2)
  134. {
  135. Debug.Log("HttpInitDPSWData");
  136. //InitDPSWData();
  137. InitDPXHQData();
  138. }
  139. if (GlobalData.pageIndex == PageIndex.Page2)
  140. {
  141. Debug.Log("HttpInitGCYWData2");
  142. InitGCYWData2();
  143. }
  144. if (GlobalData.pageIndex == PageIndex.Page2)
  145. {
  146. Debug.Log("HttpInitYJSJData2");
  147. InitYJSJData2();
  148. }
  149. }
  150. private async Task InitGCYWData2()
  151. {
  152. bool successInternet = true;
  153. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetInspectionStatistics);
  154. requestData.timeout = timeOut;
  155. await requestData.SendWebRequest();
  156. try
  157. {
  158. if (requestData.result != UnityWebRequest.Result.Success)
  159. {
  160. Debug.LogWarning("大屏运维数据联网不成功,读本地缓存数据,原因:返request不成功");
  161. successInternet = false;
  162. }
  163. else
  164. {
  165. string postResult = requestData.downloadHandler.text;
  166. if (useAes)
  167. {
  168. postResult = AESCrypto.Decrypt(postResult);
  169. }
  170. JObject jsonObject = JObject.Parse(postResult);
  171. // 提取data字段的值
  172. JToken dataToken = jsonObject["data"];
  173. JToken codeToken = jsonObject["code"];
  174. if (codeToken.ToString() == "200")
  175. {
  176. GlobalData.InspectionStat =
  177. JsonConvert.DeserializeObject<List<StationInspection>>(dataToken.ToString());
  178. }
  179. else
  180. {
  181. Debug.LogWarning("大屏运维数据联网不成功,读本地缓存数据,原因:返序列化失败");
  182. successInternet = false;
  183. }
  184. }
  185. }
  186. catch (Exception e)
  187. {
  188. successInternet = false;
  189. Debug.LogWarning("大屏运维数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  190. }
  191. requestData.Dispose();
  192. if (!successInternet)
  193. {
  194. WWW www = new WWW(Application.streamingAssetsPath + "/inspectionStatistics.json");
  195. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  196. GlobalData.InspectionStat = JsonConvert.DeserializeObject<List<StationInspection>>(www.text);
  197. www.Dispose();
  198. }
  199. }
  200. private async Task InitYJSJData2()
  201. {
  202. bool successInternet = true;
  203. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetAlertData);
  204. requestData.timeout = timeOut;
  205. await requestData.SendWebRequest();
  206. try
  207. {
  208. if (requestData.result != UnityWebRequest.Result.Success)
  209. {
  210. Debug.LogWarning("大屏预警数据联网不成功,读本地缓存数据,原因:返request不成功");
  211. successInternet = false;
  212. }
  213. else
  214. {
  215. string postResult = requestData.downloadHandler.text;
  216. if (useAes)
  217. {
  218. postResult = AESCrypto.Decrypt(postResult);
  219. }
  220. JObject jsonObject = JObject.Parse(postResult);
  221. // 提取data字段的值
  222. JToken dataToken = jsonObject["data"];
  223. JToken codeToken = jsonObject["code"];
  224. if (codeToken.ToString() == "200")
  225. {
  226. GlobalData.alertData = JsonConvert.DeserializeObject<AlertData>(dataToken.ToString());
  227. GlobalData.alertData.success = true;
  228. }
  229. else
  230. {
  231. Debug.LogWarning("大屏预警数据联网不成功,读本地缓存数据,原因:返序列化失败");
  232. successInternet = false;
  233. }
  234. }
  235. }
  236. catch (Exception e)
  237. {
  238. successInternet = false;
  239. Debug.LogWarning("大屏预警数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  240. }
  241. requestData.Dispose();
  242. if (!successInternet)
  243. {
  244. WWW www = new WWW(Application.streamingAssetsPath + "/alertData.json");
  245. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  246. Debug.Log(www.text);
  247. GlobalData.alertData = JsonConvert.DeserializeObject<AlertData>(www.text.ToString());
  248. GlobalData.alertData.success = true;
  249. Debug.Log(GlobalData.alertData.alerts.threeLineWarnings[0].title);
  250. www.Dispose();
  251. }
  252. }
  253. private async Task InitFloorGateData()
  254. {
  255. bool successInternet = true;
  256. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetFloodGateData);
  257. requestData.timeout = timeOut;
  258. await requestData.SendWebRequest();
  259. try
  260. {
  261. if (requestData.result != UnityWebRequest.Result.Success)
  262. {
  263. Debug.LogWarning("大屏闸口数据联网不成功,读本地缓存数据,原因:返request不成功");
  264. successInternet = false;
  265. }
  266. else
  267. {
  268. string postResult = requestData.downloadHandler.text;
  269. Debug.Log("大屏闸口数据:" + postResult);
  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. Debug.Log(dataToken);
  281. GlobalData.floorGateData = JsonConvert.DeserializeObject<FloodGateStatusData>(dataToken.ToString());
  282. GlobalData.floorGateData.success = true;
  283. //Debug.Log("GlobalData.floorGateData.success:" + GlobalData.floorGateData.success);
  284. }
  285. else
  286. {
  287. Debug.LogWarning("大屏闸口数据联网不成功,读本地缓存数据,原因:返序列化失败");
  288. successInternet = false;
  289. }
  290. }
  291. }
  292. catch (Exception e)
  293. {
  294. successInternet = false;
  295. Debug.LogWarning("大屏闸口数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  296. }
  297. requestData.Dispose();
  298. if (!successInternet)
  299. {
  300. WWW www = new WWW(Application.streamingAssetsPath + "/floodGateStatusData.json");
  301. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  302. Debug.Log(www.text);
  303. GlobalData.floorGateData = JsonConvert.DeserializeObject<FloodGateStatusData>(www.text.ToString());
  304. GlobalData.floorGateData.success = true;
  305. www.Dispose();
  306. }
  307. }
  308. public async Task InitDPXHQData()
  309. {
  310. GlobalData.floodStorageArea = new FloodStorageArea();
  311. bool successInternet = true;
  312. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetDPXHQData);
  313. requestData.timeout = timeOut;
  314. await requestData.SendWebRequest();
  315. try
  316. {
  317. if (requestData.result != UnityWebRequest.Result.Success)
  318. {
  319. Debug.LogWarning("大屏蓄洪区数据联网不成功,读本地缓存数据,原因:返request不成功");
  320. successInternet = false;
  321. }
  322. else
  323. {
  324. string postResult = requestData.downloadHandler.text;
  325. if (useAes)
  326. {
  327. postResult = AESCrypto.Decrypt(postResult);
  328. }
  329. JObject jsonObject = JObject.Parse(postResult);
  330. // 提取data字段的值
  331. JToken dataToken = jsonObject["data"];
  332. JToken codeToken = jsonObject["code"];
  333. if (codeToken.ToString() == "200")
  334. {
  335. //LocationWeatherData data1 =
  336. // JsonConvert.DeserializeObject<LocationWeatherData>(dataToken.ToString());
  337. //GlobalData.locationWeatherData.Add(data1);
  338. }
  339. else
  340. {
  341. Debug.LogWarning("大屏蓄洪区数据联网不成功,读本地缓存数据,原因:返序列化失败");
  342. successInternet = false;
  343. }
  344. }
  345. }
  346. catch (Exception e)
  347. {
  348. successInternet = false;
  349. Debug.LogWarning("大屏蓄洪区数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  350. }
  351. if (!successInternet)
  352. {
  353. WWW www = new WWW(Application.streamingAssetsPath + "/xhq.json");
  354. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  355. // Debug.Log(www.text);
  356. GlobalData.floodStorageArea =
  357. JsonConvert.DeserializeObject<FloodStorageArea>(www.text.ToString());
  358. GlobalData.floodStorageArea.done = true;
  359. www.Dispose();
  360. //Debug.Log(GlobalData.floodStorageArea.pumpStations.value);
  361. }
  362. requestData.Dispose();
  363. }
  364. private async Task InitDPSWData()
  365. {
  366. GlobalData.locationWeatherData = new List<LocationWeatherData>();
  367. bool successInternet = true;
  368. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetHydrologicalData + "?projectType=1");
  369. requestData.timeout = timeOut;
  370. await requestData.SendWebRequest();
  371. try
  372. {
  373. if (requestData.result != UnityWebRequest.Result.Success)
  374. {
  375. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:返request不成功");
  376. successInternet = false;
  377. }
  378. else
  379. {
  380. string postResult = requestData.downloadHandler.text;
  381. if (useAes)
  382. {
  383. postResult = AESCrypto.Decrypt(postResult);
  384. }
  385. JObject jsonObject = JObject.Parse(postResult);
  386. // 提取data字段的值
  387. JToken dataToken = jsonObject["data"];
  388. JToken codeToken = jsonObject["code"];
  389. if (codeToken.ToString() == "200")
  390. {
  391. LocationWeatherData data1 =
  392. JsonConvert.DeserializeObject<LocationWeatherData>(dataToken.ToString());
  393. GlobalData.locationWeatherData.Add(data1);
  394. }
  395. else
  396. {
  397. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:返序列化失败");
  398. successInternet = false;
  399. }
  400. }
  401. }
  402. catch (Exception e)
  403. {
  404. successInternet = false;
  405. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  406. }
  407. UnityWebRequest requestData1 = UnityWebRequest.Get(ServerAddress.APIGetHydrologicalData + "?projectType=2");
  408. requestData1.timeout = timeOut;
  409. await requestData1.SendWebRequest();
  410. try
  411. {
  412. if (requestData1.result != UnityWebRequest.Result.Success)
  413. {
  414. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:返request不成功");
  415. successInternet = false;
  416. }
  417. else
  418. {
  419. JObject jsonObject = JObject.Parse(requestData1.downloadHandler.text);
  420. // 提取data字段的值
  421. JToken dataToken = jsonObject["data"];
  422. JToken codeToken = jsonObject["code"];
  423. if (codeToken.ToString() == "200")
  424. {
  425. LocationWeatherData data2 =
  426. JsonConvert.DeserializeObject<LocationWeatherData>(dataToken.ToString());
  427. GlobalData.locationWeatherData.Add(data2);
  428. }
  429. else
  430. {
  431. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:返序列化失败");
  432. successInternet = false;
  433. }
  434. }
  435. }
  436. catch (Exception e)
  437. {
  438. successInternet = false;
  439. Debug.LogWarning("大屏水文数据联网不成功,读本地缓存数据,原因:" + e.ToString());
  440. }
  441. requestData.Dispose();
  442. if (!successInternet)
  443. {
  444. WWW www = new WWW(Application.streamingAssetsPath + "/hydrologicalData.json");
  445. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  446. Debug.Log(www.text);
  447. GlobalData.locationWeatherData =
  448. JsonConvert.DeserializeObject<List<LocationWeatherData>>(www.text.ToString());
  449. www.Dispose();
  450. }
  451. }
  452. public async void InitYZTData()
  453. {
  454. await InitYZTData1(); //已完成迁移
  455. InitYZTData_BY_Obs(); //已完成迁移
  456. InitYZTData_TK_Obs(); //新增
  457. InitYZTData3(); //已完成迁移
  458. InitGCGKData();
  459. InitJKYJData();
  460. }
  461. public async Task InitYZTData1()
  462. {
  463. bool successInternet = true;
  464. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetWaterManagerProject);
  465. requestData.timeout = timeOut;
  466. await requestData.SendWebRequest();
  467. try
  468. {
  469. if (true)
  470. {
  471. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返request不成功");
  472. successInternet = false;
  473. }
  474. else
  475. {
  476. string postResult = requestData.downloadHandler.text;
  477. if (useAes)
  478. {
  479. postResult = AESCrypto.Decrypt(postResult);
  480. }
  481. JObject jsonObject = JObject.Parse(postResult);
  482. // 提取data字段的值
  483. JToken dataToken = jsonObject["data"];
  484. JToken codeToken = jsonObject["code"];
  485. if (codeToken.ToString() == "200")
  486. {
  487. GlobalData.layerUnitDatas =
  488. JsonConvert.DeserializeObject<List<LayerUnitData>>(dataToken.ToString());
  489. }
  490. else
  491. {
  492. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返序列化失败");
  493. successInternet = false;
  494. }
  495. }
  496. }
  497. catch (Exception e)
  498. {
  499. successInternet = false;
  500. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
  501. }
  502. requestData.Dispose();
  503. if (!successInternet)
  504. {
  505. WWW www = new WWW(Application.streamingAssetsPath + "/layerUnitDatas.json");
  506. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  507. GlobalData.layerUnitDatas = JsonConvert.DeserializeObject<List<LayerUnitData>>(www.text);
  508. www.Dispose();
  509. }
  510. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  511. {
  512. if (GlobalData.layerUnitDatas[i].type == LayerUnitType.JK)
  513. {
  514. if (!GlobalData.obsCameraLib.ContainsKey(GlobalData.layerUnitDatas[i].name))
  515. GlobalData.obsCameraLib.Add(GlobalData.layerUnitDatas[i].name, GlobalData.layerUnitDatas[i].namePri);
  516. }
  517. }
  518. }
  519. public async Task InitYZTData_BY_Obs()
  520. {
  521. bool successInternet = true;
  522. string sendUrl = ServerAddress.API_GetDevicesInfo;
  523. Debug.Log(ServerAddress.ObsSeverAddress);
  524. sendUrl += "/34020000001180000001/channels?page=1&count=100";
  525. Debug.Log(sendUrl);
  526. UnityWebRequest requestData = UnityWebRequest.Get(sendUrl);
  527. requestData.timeout = timeOut;
  528. await requestData.SendWebRequest();
  529. try
  530. {
  531. if (requestData.result != UnityWebRequest.Result.Success)
  532. {
  533. Debug.LogWarning("补元监控数据联网不成功,原因:返request不成功:" + requestData.error);
  534. successInternet = false;
  535. }
  536. else
  537. {
  538. Debug.Log("补元监控数据返回:" + requestData.downloadHandler.text);
  539. string postResult = requestData.downloadHandler.text;
  540. if (useAes)
  541. {
  542. postResult = AESCrypto.Decrypt(postResult);
  543. }
  544. JObject jsonObject = JObject.Parse(postResult);
  545. // 提取data字段的值
  546. JToken dataToken = jsonObject["data"];
  547. JToken codeToken = jsonObject["code"];
  548. if (codeToken.ToString() == "0")
  549. {
  550. GlobalData.obsDatas_by = new List<ObsData>();
  551. ServerObsDatas serverObsDatas = JsonConvert.DeserializeObject<ServerObsDatas>(dataToken.ToString());
  552. for (int i = 0; i < serverObsDatas.list.Count; i++)
  553. {
  554. ObsData obsData = new ObsData();
  555. string originName = serverObsDatas.list[i].name;
  556. obsData.name = "BY_" + serverObsDatas.list[i].name;
  557. //Debug.Log("111" + obsData.name);
  558. if (GlobalData.obsCameraLib.TryGetValue(obsData.name, out var value))
  559. {
  560. obsData.targetName = value;
  561. }
  562. obsData.type = obsType.BuYuanObs;
  563. obsData.deviceId = serverObsDatas.list[i].deviceId;
  564. obsData.channelId = serverObsDatas.list[i].channelId;
  565. GlobalData.obsDeviceIDLib.Add(obsData.name, obsData.channelId);
  566. obsData.status = serverObsDatas.list[i].status;
  567. GlobalData.obsDatas_by.Add(obsData);
  568. }
  569. }
  570. else
  571. {
  572. Debug.LogWarning("补元监控数据联网不成功,原因:返序列化失败");
  573. successInternet = false;
  574. }
  575. }
  576. }
  577. catch (Exception e)
  578. {
  579. successInternet = false;
  580. Debug.LogWarning("补元监控数据联网不成功,原因:" + e.ToString());
  581. }
  582. requestData.Dispose();
  583. if (!successInternet)
  584. {
  585. WWW www = new WWW(Application.streamingAssetsPath + "/ObsDatas_BY.json");
  586. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  587. Debug.Log($"缓存数据:{www.text}");
  588. GlobalData.obsDatas_by = JsonConvert.DeserializeObject<List<ObsData>>(www.text);
  589. www.Dispose();
  590. }
  591. }
  592. public async Task InitYZTData_TK_Obs()
  593. {
  594. bool successInternet = true;
  595. string sendUrl = ServerAddress.API_GetDevicesInfo;
  596. sendUrl += "/34020000001180000002/channels?page=1&count=100";
  597. Debug.Log(sendUrl);
  598. UnityWebRequest requestData = UnityWebRequest.Get(sendUrl);
  599. requestData.timeout = timeOut;
  600. await requestData.SendWebRequest();
  601. try
  602. {
  603. if (requestData.result != UnityWebRequest.Result.Success)
  604. {
  605. Debug.LogWarning("套口监控数据联网不成功,原因:返request不成功:" + requestData.error);
  606. successInternet = false;
  607. }
  608. else
  609. {
  610. Debug.Log("套口监控数据返回:" + requestData.downloadHandler.text);
  611. string postResult = requestData.downloadHandler.text;
  612. if (useAes)
  613. {
  614. postResult = AESCrypto.Decrypt(postResult);
  615. }
  616. JObject jsonObject = JObject.Parse(postResult);
  617. // 提取data字段的值
  618. JToken dataToken = jsonObject["data"];
  619. JToken codeToken = jsonObject["code"];
  620. if (codeToken.ToString() == "0")
  621. {
  622. GlobalData.obsDatas_tk = new List<ObsData>();
  623. ServerObsDatas serverObsDatas = JsonConvert.DeserializeObject<ServerObsDatas>(dataToken.ToString());
  624. for (int i = 0; i < serverObsDatas.list.Count; i++)
  625. {
  626. ObsData obsData = new ObsData();
  627. string originName = serverObsDatas.list[i].name;
  628. //Debug.Log("111111111111111:" + originName);
  629. obsData.name = "TK_" + serverObsDatas.list[i].name;
  630. if (GlobalData.obsCameraLib.TryGetValue(obsData.name, out var value))
  631. {
  632. obsData.targetName = value;
  633. }
  634. //obsData.url = await GetObsUrl(serverObsDatas.list[i].deviceId,serverObsDatas.list[i].channelId);
  635. //ServerAddress.ObsSeverM3U8Address + string.Format("/rtp/{0}_{1}/hls.m3u8", serverObsDatas.list[i].deviceId, serverObsDatas.list[i].channelId);
  636. //}
  637. obsData.type = obsType.TaoKouObs;
  638. obsData.deviceId = serverObsDatas.list[i].deviceId;
  639. obsData.channelId = serverObsDatas.list[i].channelId;
  640. GlobalData.obsDeviceIDLib.Add(obsData.name, obsData.channelId);
  641. obsData.status = serverObsDatas.list[i].status;
  642. GlobalData.obsDatas_tk.Add(obsData);
  643. }
  644. }
  645. else
  646. {
  647. Debug.LogWarning("套口监控数据联网不成功,原因:返序列化失败");
  648. successInternet = false;
  649. }
  650. }
  651. }
  652. catch (Exception e)
  653. {
  654. successInternet = false;
  655. Debug.LogWarning("套口监控数据联网不成功,原因:" + e.ToString());
  656. }
  657. requestData.Dispose();
  658. if (!successInternet)
  659. {
  660. WWW www = new WWW(Application.streamingAssetsPath + "/ObsDatas_TK.json");
  661. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  662. Debug.Log($"缓存数据:{www.text}");
  663. GlobalData.obsDatas_tk = JsonConvert.DeserializeObject<List<ObsData>>(www.text);
  664. www.Dispose();
  665. }
  666. }
  667. public async Task<string> GetObsUrl(string deviceId, string channelId)
  668. {
  669. string result = "";
  670. string cmdUrl = ServerAddress.API_PlayStart;
  671. cmdUrl += $"/{deviceId}/{channelId}?token=12345678";
  672. Debug.Log($"send:{cmdUrl}");
  673. UnityWebRequest requestData = UnityWebRequest.Get(cmdUrl);
  674. await requestData.SendWebRequest();
  675. if (requestData.result != UnityWebRequest.Result.Success)
  676. {
  677. Debug.LogWarning($"获取监控播放地址不成功,原因:返request不成功:" + requestData.downloadHandler.text);
  678. }
  679. else
  680. {
  681. Debug.Log(requestData.downloadHandler.text);
  682. string postResult = requestData.downloadHandler.text;
  683. if (useAes)
  684. {
  685. postResult = AESCrypto.Decrypt(postResult);
  686. }
  687. JObject jsonObject = JObject.Parse(postResult);
  688. // 提取data字段的值
  689. JToken dataToken = jsonObject["data"];
  690. ObsPlayUrlData urlData = JsonConvert.DeserializeObject<ObsPlayUrlData>(dataToken.ToString());
  691. if (urlData != null)
  692. {
  693. result = urlData.hls;
  694. Debug.Log("获取到监控播放路径:" + result);
  695. }
  696. }
  697. requestData.Dispose();
  698. return result;
  699. }
  700. public async Task InitYZTData3()
  701. {
  702. bool successInternet = true;
  703. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetWaterHotPoint);
  704. requestData.timeout = timeOut;
  705. await requestData.SendWebRequest();
  706. try
  707. {
  708. if (true)
  709. //if (requestData.result != UnityWebRequest.Result.Success)
  710. {
  711. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返request不成功");
  712. successInternet = false;
  713. }
  714. else
  715. {
  716. string postResult = requestData.downloadHandler.text;
  717. if (useAes)
  718. {
  719. postResult = AESCrypto.Decrypt(postResult);
  720. }
  721. JObject jsonObject = JObject.Parse(postResult);
  722. // 提取data字段的值
  723. JToken dataToken = jsonObject["data"];
  724. JToken codeToken = jsonObject["code"];
  725. if (codeToken.ToString() == "200")
  726. {
  727. GlobalData.hotPointDatas = JsonConvert.DeserializeObject<List<HotPointData>>(dataToken.ToString());
  728. }
  729. else
  730. {
  731. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返序列化失败");
  732. successInternet = false;
  733. }
  734. }
  735. }
  736. catch (Exception e)
  737. {
  738. successInternet = false;
  739. Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
  740. }
  741. requestData.Dispose();
  742. if (!successInternet)
  743. {
  744. WWW www = new WWW(Application.streamingAssetsPath + "/hotPoints.json");
  745. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  746. GlobalData.hotPointDatas = JsonConvert.DeserializeObject<List<HotPointData>>(www.text);
  747. Debug.Log(GlobalData.hotPointDatas.Count);
  748. www.Dispose();
  749. }
  750. }
  751. public async Task InitXHGKData()
  752. {
  753. bool successInternet = true;
  754. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGetProjectMilestones);
  755. requestData.timeout = timeOut;
  756. await requestData.SendWebRequest();
  757. try
  758. {
  759. if (true)
  760. {
  761. Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返request不成功");
  762. successInternet = false;
  763. }
  764. else
  765. {
  766. string postResult = requestData.downloadHandler.text;
  767. if (useAes)
  768. {
  769. postResult = AESCrypto.Decrypt(postResult);
  770. }
  771. JObject jsonObject = JObject.Parse(postResult);
  772. // ȡdata ֶε ֵ
  773. JToken dataToken = jsonObject["data"];
  774. //Debug.Log(dataToken.ToString());
  775. JToken codeToken = jsonObject["code"];
  776. if (codeToken.ToString() == "200")
  777. {
  778. GlobalData.dsjContents = JsonConvert.DeserializeObject<List<DSJData>>(dataToken.ToString());
  779. }
  780. else
  781. {
  782. Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返序列化失败");
  783. successInternet = false;
  784. }
  785. }
  786. }
  787. catch (Exception e)
  788. {
  789. successInternet = false;
  790. Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
  791. }
  792. requestData.Dispose();
  793. if (!successInternet)
  794. {
  795. WWW www = new WWW(Application.streamingAssetsPath + "/dsj.json");
  796. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  797. GlobalData.dsjContents = JsonConvert.DeserializeObject<List<DSJData>>(www.text);
  798. www.Dispose();
  799. }
  800. }
  801. /// <summary>
  802. /// 一张图首页工程概况
  803. /// </summary>
  804. /// <returns></returns>
  805. public async Task InitGCGKData()
  806. {
  807. bool successInternet = true;
  808. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetWaterGaiKuang);
  809. requestData.timeout = timeOut;
  810. await requestData.SendWebRequest();
  811. try
  812. {
  813. if (requestData.result != UnityWebRequest.Result.Success)
  814. {
  815. Debug.LogWarning("GCGK联网不成功,读本地缓存数据,原因:返request不成功");
  816. successInternet = false;
  817. }
  818. else
  819. {
  820. string postResult = requestData.downloadHandler.text;
  821. if (useAes)
  822. {
  823. postResult = AESCrypto.Decrypt(postResult);
  824. }
  825. JObject jsonObject = JObject.Parse(postResult);
  826. JToken dataToken = jsonObject["data"];
  827. //Debug.Log(dataToken.ToString());
  828. JToken codeToken = jsonObject["code"];
  829. if (codeToken.ToString() == "200")
  830. {
  831. //Debug.Log("1111111111:" + dataToken.ToString());
  832. GlobalData.gcgkContents = JsonConvert.DeserializeObject<List<GCGKData>>(dataToken.ToString());
  833. }
  834. else
  835. {
  836. Debug.LogWarning("GCGK联网不成功,读本地缓存数据,原因:返序列化失败");
  837. successInternet = false;
  838. }
  839. }
  840. }
  841. catch (Exception e)
  842. {
  843. successInternet = false;
  844. Debug.LogWarning("GCGK联网不成功,读本地缓存数据,原因:" + e.ToString());
  845. }
  846. requestData.Dispose();
  847. }
  848. /// <summary>
  849. /// 一张图首页监控预警
  850. /// </summary>
  851. /// <returns></returns>
  852. public async Task InitJKYJData()
  853. {
  854. bool successInternet = true;
  855. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetJKYJ + "buyuan");
  856. requestData.timeout = timeOut;
  857. await requestData.SendWebRequest();
  858. try
  859. {
  860. if (requestData.result != UnityWebRequest.Result.Success)
  861. {
  862. Debug.LogWarning("JKYJ-buyuan联网不成功,读本地缓存数据,原因:返request不成功");
  863. successInternet = false;
  864. }
  865. else
  866. {
  867. string postResult = requestData.downloadHandler.text;
  868. if (useAes)
  869. {
  870. postResult = AESCrypto.Decrypt(postResult);
  871. }
  872. JObject jsonObject = JObject.Parse(postResult);
  873. JToken dataToken = jsonObject["data"];
  874. //Debug.Log(dataToken.ToString());
  875. JToken codeToken = jsonObject["code"];
  876. if (codeToken.ToString() == "200")
  877. {
  878. //Debug.Log("1111111111:" + dataToken.ToString());
  879. GlobalData.byJKYJContents = JsonConvert.DeserializeObject<JKYJData>(dataToken.ToString());
  880. }
  881. else
  882. {
  883. Debug.LogWarning("JKYJ-buyuan联网不成功,读本地缓存数据,原因:返序列化失败");
  884. successInternet = false;
  885. }
  886. }
  887. }
  888. catch (Exception e)
  889. {
  890. successInternet = false;
  891. Debug.LogWarning("JKYJ-buyuan联网不成功,读本地缓存数据,原因:" + e.ToString());
  892. }
  893. requestData.Dispose();
  894. successInternet = true;
  895. UnityWebRequest requestData1 = UnityWebRequest.Get(ServerAddress.APIGetJKYJ + "taokou");
  896. requestData1.timeout = timeOut;
  897. await requestData1.SendWebRequest();
  898. try
  899. {
  900. if (requestData1.result != UnityWebRequest.Result.Success)
  901. {
  902. Debug.LogWarning("JKYJ-TAOKOU联网不成功,读本地缓存数据,原因:返request不成功");
  903. successInternet = false;
  904. }
  905. else
  906. {
  907. string postResult = requestData1.downloadHandler.text;
  908. Debug.Log(postResult);
  909. if (useAes)
  910. {
  911. postResult = AESCrypto.Decrypt(postResult);
  912. }
  913. JObject jsonObject = JObject.Parse(postResult);
  914. JToken dataToken = jsonObject["data"];
  915. //Debug.Log(dataToken.ToString());
  916. JToken codeToken = jsonObject["code"];
  917. if (codeToken.ToString() == "200")
  918. {
  919. //Debug.Log("1111111111:" + dataToken.ToString());
  920. GlobalData.tkJKYJContents = JsonConvert.DeserializeObject<JKYJData>(dataToken.ToString());
  921. }
  922. else
  923. {
  924. Debug.LogWarning("JKYJ-TAOKOU联网不成功,读本地缓存数据,原因:返序列化失败");
  925. successInternet = false;
  926. }
  927. }
  928. }
  929. catch (Exception e)
  930. {
  931. successInternet = false;
  932. Debug.LogWarning("JKYJ-TAOKOU联网不成功,读本地缓存数据,原因:" + e.ToString());
  933. }
  934. requestData1.Dispose();
  935. }
  936. public async Task InitGCJKData()
  937. {
  938. bool successInternet = true;
  939. //UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeQXZData);
  940. //requestData.timeout = timeOut;
  941. //await requestData.SendWebRequest();
  942. //try
  943. //{
  944. // if (requestData.result != UnityWebRequest.Result.Success)
  945. // {
  946. // Debug.LogWarning("水文站联网不成功,原因:返request不成功");
  947. // successInternet = false;
  948. // }
  949. // else
  950. // {
  951. // string postResult = requestData.downloadHandler.text;
  952. // if (useAes)
  953. // {
  954. // postResult = AESCrypto.Decrypt(postResult);
  955. // }
  956. // JObject jsonObject = JObject.Parse(postResult);
  957. // // 提取data字段的值
  958. // JToken dataToken = jsonObject["data"];
  959. // JToken codeToken = jsonObject["code"];
  960. // if (codeToken.ToString() == "200")
  961. // {
  962. // GlobalData.qXZDatas = JsonConvert.DeserializeObject<List<QXZData>>(dataToken.ToString());
  963. // }
  964. // else
  965. // {
  966. // Debug.LogWarning("水文站联网不成功,原因:返序列化失败");
  967. // successInternet = false;
  968. // }
  969. // }
  970. //}
  971. //catch (Exception e)
  972. //{
  973. // successInternet = false;
  974. // Debug.LogWarning("水文站联网不成功,原因:" + e.ToString());
  975. //}
  976. //requestData.Dispose();
  977. successInternet = true;
  978. UnityWebRequest requestData1 = UnityWebRequest.Get(ServerAddress.APIGetGeSWZData);
  979. await requestData1.SendWebRequest();
  980. try
  981. {
  982. if (requestData1.result != UnityWebRequest.Result.Success)
  983. {
  984. Debug.LogWarning("水文站联网不成功,原因:返request不成功");
  985. successInternet = false;
  986. }
  987. else
  988. {
  989. JObject jsonObject = JObject.Parse(requestData1.downloadHandler.text);
  990. // 提取data字段的值
  991. JToken dataToken = jsonObject["data"];
  992. JToken codeToken = jsonObject["code"];
  993. if (codeToken.ToString() == "200")
  994. {
  995. GlobalData.sWZDatas = JsonConvert.DeserializeObject<List<SWZData>>(dataToken.ToString());
  996. }
  997. else
  998. {
  999. Debug.LogWarning("水文站联网不成功,原因:返序列化失败");
  1000. successInternet = false;
  1001. }
  1002. }
  1003. }
  1004. catch (Exception e)
  1005. {
  1006. successInternet = false;
  1007. Debug.LogWarning("水文站联网不成功,原因:" + e.ToString());
  1008. }
  1009. requestData1.Dispose();
  1010. successInternet = true;
  1011. UnityWebRequest requestData2 = UnityWebRequest.Get(ServerAddress.APIGetGeSWZData6H);
  1012. await requestData2.SendWebRequest();
  1013. try
  1014. {
  1015. if (requestData2.result != UnityWebRequest.Result.Success)
  1016. {
  1017. Debug.LogWarning("水文站联网不成功,原因:返request不成功");
  1018. successInternet = false;
  1019. }
  1020. else
  1021. {
  1022. JObject jsonObject = JObject.Parse(requestData2.downloadHandler.text);
  1023. // 提取data字段的值
  1024. JToken dataToken = jsonObject["data"];
  1025. JToken codeToken = jsonObject["code"];
  1026. if (codeToken.ToString() == "200")
  1027. {
  1028. GlobalData.sWZDatas6H = JsonConvert.DeserializeObject<List<SWZData>>(dataToken.ToString());
  1029. }
  1030. else
  1031. {
  1032. Debug.LogWarning("水文站联网不成功,原因:返序列化失败");
  1033. successInternet = false;
  1034. }
  1035. }
  1036. }
  1037. catch (Exception e)
  1038. {
  1039. successInternet = false;
  1040. Debug.LogWarning("水文站联网不成功,原因:" + e.ToString());
  1041. }
  1042. requestData2.Dispose();
  1043. }
  1044. public async Task InitGCJKData1h()
  1045. {
  1046. bool successInternet = true;
  1047. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeQXZOneHourData);
  1048. requestData.timeout = timeOut;
  1049. await requestData.SendWebRequest();
  1050. try
  1051. {
  1052. if (requestData.result != UnityWebRequest.Result.Success)
  1053. {
  1054. Debug.LogWarning("水文站联网不成功,原因:返request不成功");
  1055. successInternet = false;
  1056. }
  1057. else
  1058. {
  1059. string postResult = requestData.downloadHandler.text;
  1060. if (useAes)
  1061. {
  1062. postResult = AESCrypto.Decrypt(postResult);
  1063. }
  1064. JObject jsonObject = JObject.Parse(postResult);
  1065. // 提取data字段的值
  1066. JToken dataToken = jsonObject["data"];
  1067. JToken codeToken = jsonObject["code"];
  1068. if (codeToken.ToString() == "200")
  1069. {
  1070. GlobalData.qXZDatas1h = JsonConvert.DeserializeObject<List<QXZData>>(dataToken.ToString());
  1071. }
  1072. else
  1073. {
  1074. Debug.LogWarning("水文站联网不成功,原因:返序列化失败");
  1075. successInternet = false;
  1076. }
  1077. }
  1078. }
  1079. catch (Exception e)
  1080. {
  1081. successInternet = false;
  1082. Debug.LogWarning("水文站联网不成功,原因:" + e.ToString());
  1083. }
  1084. requestData.Dispose();
  1085. }
  1086. public async Task InitGCJKData2()
  1087. {
  1088. GlobalData.sensorAlertDone = false;
  1089. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetSensorAlerts);
  1090. requestData.timeout = 2;
  1091. await requestData.SendWebRequest();
  1092. try
  1093. {
  1094. if (requestData.result != UnityWebRequest.Result.Success)
  1095. {
  1096. Debug.LogWarning("工程告警联网不成功,原因:返request不成功");
  1097. }
  1098. else
  1099. {
  1100. string postResult = requestData.downloadHandler.text;
  1101. if (useAes)
  1102. {
  1103. postResult = AESCrypto.Decrypt(postResult);
  1104. }
  1105. JObject jsonObject = JObject.Parse(postResult);
  1106. Debug.LogError(postResult.ToString());
  1107. // 提取data字段的值
  1108. JToken dataToken = jsonObject["data"];
  1109. JToken codeToken = jsonObject["code"];
  1110. if (codeToken.ToString() == "200")
  1111. {
  1112. GlobalData.sensorAlert = JsonConvert.DeserializeObject<SensorAlert>(dataToken.ToString());
  1113. GlobalData.sensorAlertDone = true;
  1114. }
  1115. else
  1116. {
  1117. Debug.LogWarning("工程告警联网不成功,原因:返序列化失败");
  1118. }
  1119. }
  1120. }
  1121. catch (Exception e)
  1122. {
  1123. Debug.LogWarning("工程告警联网不成功,原因:" + e.ToString());
  1124. }
  1125. }
  1126. public async Task InitXHDDData0()
  1127. {
  1128. WWW www = new WWW(Application.streamingAssetsPath + "/scheduling.json");
  1129. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  1130. GlobalData.schedulingData = JsonConvert.DeserializeObject<SchedulingData>(www.text);
  1131. www.Dispose();
  1132. }
  1133. public async Task InitXHDDData1()
  1134. {
  1135. WWW www = new WWW(Application.streamingAssetsPath + "/allAlert.json");
  1136. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  1137. GlobalData.xHDDAlertData = JsonConvert.DeserializeObject<XHDDAlertData>(www.text);
  1138. www.Dispose();
  1139. }
  1140. public async Task InitXHDDData2()
  1141. {
  1142. WWW www = new WWW(Application.streamingAssetsPath + "/rkzyld.json");
  1143. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  1144. GlobalData.emergencyResponseData = JsonConvert.DeserializeObject<EmergencyResponseData>(www.text);
  1145. www.Dispose();
  1146. }
  1147. public async Task InitXHDDData3()
  1148. {
  1149. WWW www = new WWW(Application.streamingAssetsPath + "/rkzygb.json");
  1150. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  1151. GlobalData.allRegionData = JsonConvert.DeserializeObject<AllRegionData>(www.text);
  1152. www.Dispose();
  1153. }
  1154. public async Task InitRKZYData()
  1155. {
  1156. bool successInternet = true;
  1157. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGetMovePlans);
  1158. requestData.timeout = timeOut;
  1159. await requestData.SendWebRequest();
  1160. try
  1161. {
  1162. if (true)
  1163. {
  1164. Debug.LogWarning("RKZYLayer联网不成功,读本地缓存数据,原因:返request不成功");
  1165. successInternet = false;
  1166. }
  1167. else
  1168. {
  1169. string postResult = requestData.downloadHandler.text;
  1170. if (useAes)
  1171. {
  1172. postResult = AESCrypto.Decrypt(postResult);
  1173. }
  1174. JObject jsonObject = JObject.Parse(postResult);
  1175. // 提取data字段的值
  1176. JToken dataToken = jsonObject["data"];
  1177. JToken codeToken = jsonObject["code"];
  1178. if (codeToken.ToString() == "200")
  1179. {
  1180. GlobalData.allServerMovePlans =
  1181. JsonConvert.DeserializeObject<List<ServerMovePlan>>(dataToken.ToString());
  1182. }
  1183. else
  1184. {
  1185. successInternet = false;
  1186. Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返序列化失败");
  1187. }
  1188. }
  1189. }
  1190. catch (Exception e)
  1191. {
  1192. successInternet = false;
  1193. Debug.LogWarning("RKZYLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
  1194. }
  1195. if (!successInternet)
  1196. {
  1197. WWW www = new WWW(Application.streamingAssetsPath + "/moveplan.json");
  1198. await new UnityAsync.WaitUntil(() => { return www.isDone; });
  1199. GlobalData.allServerMovePlans = JsonConvert.DeserializeObject<List<ServerMovePlan>>(www.text);
  1200. www.Dispose();
  1201. }
  1202. }
  1203. public async Task InitSWYJData()
  1204. {
  1205. InitSWYJData0();
  1206. await InitSWYJData1();
  1207. await InitSWYJData2();
  1208. await InitSWYJData3();
  1209. await InitSWYJData4();
  1210. OnSWYJRefresh?.Invoke();
  1211. }
  1212. /// <summary>
  1213. /// 获取补元的水位
  1214. /// </summary>
  1215. /// <returns></returns>
  1216. public async Task InitSWYJData1()
  1217. {
  1218. var devicesInfo = GlobalData._devicesIdDatas["上游水位计"];
  1219. string sw1Result = await GetSingleDevicesInfo(2, devicesInfo.dataGid.ToString(), devicesInfo.dataSid.ToString(),
  1220. "d", 10000);
  1221. //Debug.Log("sw1Resultsw1Resultsw1Result上游水位计:" + sw1Result);
  1222. try
  1223. {
  1224. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(sw1Result);
  1225. if (tempData != null)
  1226. {
  1227. bool findData = false;
  1228. foreach (var VARIABLE in GlobalData.BuYuanShuiWeiDataList)
  1229. {
  1230. if (VARIABLE.name.Equals("补元上游水位"))
  1231. {
  1232. VARIABLE.value = float.Parse(tempData.data[0].avgS1);
  1233. VARIABLE.datas = tempData.data.ToArray();
  1234. findData = true;
  1235. }
  1236. }
  1237. if (!findData)
  1238. {
  1239. GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
  1240. {
  1241. name = "补元上游水位",
  1242. targetName = "BY_ShuiWei_Up",
  1243. value = float.Parse(tempData.data[0].avgS1),
  1244. type = shuiWeiType.BuYuanShuiWei,
  1245. datas = tempData.data.ToArray(),
  1246. sid = devicesInfo.dataSid.ToString(),
  1247. gid = devicesInfo.dataGid.ToString()
  1248. });
  1249. }
  1250. }
  1251. }
  1252. catch (Exception e)
  1253. {
  1254. Debug.LogWarning("补元上游水位不成功,原因:" + e.ToString());
  1255. }
  1256. var devicesInfo1 = GlobalData._devicesIdDatas["下游水位计"];
  1257. string sw2Result = await GetSingleDevicesInfo(2, devicesInfo1.dataGid.ToString(), devicesInfo1.dataSid.ToString(),
  1258. "d", 100000);
  1259. Debug.Log("sw1Resultsw1Resultsw1Result下游水位计:" + sw2Result);
  1260. try
  1261. {
  1262. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(sw2Result);
  1263. if (tempData != null)
  1264. {
  1265. bool findData = false;
  1266. foreach (var VARIABLE in GlobalData.BuYuanShuiWeiDataList)
  1267. {
  1268. if (VARIABLE.name.Equals("补元下游水位"))
  1269. {
  1270. VARIABLE.value = float.Parse(tempData.data[0].avgS1);
  1271. VARIABLE.datas = tempData.data.ToArray();
  1272. findData = true;
  1273. }
  1274. }
  1275. if (!findData)
  1276. {
  1277. GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
  1278. {
  1279. name = "补元下游水位",
  1280. targetName = "BY_ShuiWei_Down",
  1281. value = float.Parse(tempData.data[0].avgS1),
  1282. type = shuiWeiType.BuYuanShuiWei,
  1283. datas = tempData.data.ToArray(),
  1284. sid = devicesInfo.dataSid.ToString(),
  1285. gid = devicesInfo.dataGid.ToString()
  1286. });
  1287. }
  1288. }
  1289. }
  1290. catch (Exception e)
  1291. {
  1292. Debug.LogWarning("补元下游水位不成功,原因:" + e.ToString());
  1293. }
  1294. string dayResult = await GetSingleDevicesInfo(2, devicesInfo.dataGid.ToString(), devicesInfo.dataSid.ToString(),
  1295. "d", 6);
  1296. try
  1297. {
  1298. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(dayResult);
  1299. GlobalData.buYuanShuiWei_day = new ShuiWeiBianHuaData();
  1300. GlobalData.buYuanShuiWei_day.name = new string[tempData.data.Count];
  1301. GlobalData.buYuanShuiWei_day.value = new double[tempData.data.Count];
  1302. for (int i = 0; i < tempData.data.Count; i++)
  1303. {
  1304. GlobalData.buYuanShuiWei_day.name[i] = tempData.data[i].timeGroup;
  1305. GlobalData.buYuanShuiWei_day.value[i] = double.Parse(tempData.data[i].avgS1);
  1306. }
  1307. }
  1308. catch (Exception e)
  1309. {
  1310. Debug.LogWarning("获取6天平均数据不成功,原因:" + e.ToString());
  1311. }
  1312. string monthResult = await GetSingleDevicesInfo(2, devicesInfo.dataGid.ToString(), devicesInfo.dataSid.ToString(),
  1313. "d", 90);
  1314. try
  1315. {
  1316. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(monthResult);
  1317. GlobalData.buYuanShuiWei_month = new ShuiWeiBianHuaData();
  1318. GlobalData.buYuanShuiWei_month.name = new string[tempData.data.Count];
  1319. GlobalData.buYuanShuiWei_month.value = new double[tempData.data.Count];
  1320. for (int i = 0; i < tempData.data.Count; i++)
  1321. {
  1322. GlobalData.buYuanShuiWei_month.name[i] = tempData.data[i].timeGroup;
  1323. GlobalData.buYuanShuiWei_month.value[i] = double.Parse(tempData.data[i].avgS1);
  1324. }
  1325. }
  1326. catch (Exception e)
  1327. {
  1328. Debug.LogWarning("获取6月平均数据不成功,原因:" + e.ToString());
  1329. }
  1330. string hourResult = await GetSingleDevicesInfo(2, devicesInfo.dataGid.ToString(), devicesInfo.dataSid.ToString(),
  1331. "h", 6);
  1332. try
  1333. {
  1334. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(hourResult);
  1335. GlobalData.buYuanShuiWei_hour = new ShuiWeiBianHuaData();
  1336. GlobalData.buYuanShuiWei_hour.name = new string[tempData.data.Count];
  1337. GlobalData.buYuanShuiWei_hour.value = new double[tempData.data.Count];
  1338. for (int i = 0; i < tempData.data.Count; i++)
  1339. {
  1340. GlobalData.buYuanShuiWei_hour.name[i] = tempData.data[i].timeGroup;
  1341. GlobalData.buYuanShuiWei_hour.value[i] = double.Parse(tempData.data[i].avgS1);
  1342. }
  1343. }
  1344. catch (Exception e)
  1345. {
  1346. Debug.LogWarning("获取6小时平均数据不成功,原因:" + e.ToString());
  1347. }
  1348. }
  1349. public async Task InitSWYJData2()
  1350. {
  1351. var devicesInfo = GlobalData._devicesIdDatas["SWJ01YQ"];
  1352. Debug.Log(devicesInfo.dataGid);
  1353. Debug.Log(devicesInfo.dataSid);
  1354. string sw1Result = await GetSingleDevicesInfo(1, devicesInfo.dataGid.ToString(), devicesInfo.dataSid.ToString(), "d", 10000);
  1355. try
  1356. {
  1357. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(sw1Result);
  1358. if (tempData != null)
  1359. {
  1360. bool findData = false;
  1361. foreach (var VARIABLE in GlobalData.TaoKouShuiWeiDataList)
  1362. {
  1363. if (VARIABLE.name.Equals("套口上游水位"))
  1364. {
  1365. VARIABLE.value = float.Parse(tempData.data[0].avgS1);
  1366. VARIABLE.datas = tempData.data.ToArray();
  1367. findData = true;
  1368. }
  1369. }
  1370. if (!findData)
  1371. {
  1372. GlobalData.TaoKouShuiWeiDataList.Add(new ShuiWeiData()
  1373. {
  1374. name = "套口上游水位",
  1375. targetName = "TK_ShuiWei_Up",
  1376. value = float.Parse(tempData.data[0].avgS1),
  1377. type = shuiWeiType.TaoKouShuiWei,
  1378. datas = tempData.data.ToArray(),
  1379. sid = devicesInfo.dataSid.ToString(),
  1380. gid = devicesInfo.dataGid.ToString()
  1381. });
  1382. }
  1383. }
  1384. }
  1385. catch (Exception e)
  1386. {
  1387. Debug.LogWarning("套口上游水位不成功,原因:" + e.ToString());
  1388. }
  1389. var devicesInfo1 = GlobalData._devicesIdDatas["SWJ02YQ"];
  1390. string sw2Result = await GetSingleDevicesInfo(1, devicesInfo1.dataGid.ToString(), devicesInfo1.dataSid.ToString(),
  1391. "d", 100000);
  1392. //Debug.Log("sw1Resultsw1Resultsw1Result下游水位计:" + sw2Result);
  1393. try
  1394. {
  1395. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(sw2Result);
  1396. if (tempData != null)
  1397. {
  1398. bool findData = false;
  1399. foreach (var VARIABLE in GlobalData.TaoKouShuiWeiDataList)
  1400. {
  1401. if (VARIABLE.name.Equals("套口下游水位"))
  1402. {
  1403. VARIABLE.value = float.Parse(tempData.data[0].avgS1);
  1404. VARIABLE.datas = tempData.data.ToArray();
  1405. findData = true;
  1406. }
  1407. }
  1408. if (!findData)
  1409. {
  1410. GlobalData.TaoKouShuiWeiDataList.Add(new ShuiWeiData()
  1411. {
  1412. name = "套口下游水位",
  1413. targetName = "TK_ShuiWei_Down",
  1414. value = float.Parse(tempData.data[0].avgS1),
  1415. type = shuiWeiType.TaoKouShuiWei,
  1416. datas = tempData.data.ToArray(),
  1417. sid = devicesInfo.dataSid.ToString(),
  1418. gid = devicesInfo.dataGid.ToString()
  1419. });
  1420. }
  1421. }
  1422. }
  1423. catch (Exception e)
  1424. {
  1425. Debug.LogWarning("套口下游水位不成功,原因:" + e.ToString());
  1426. }
  1427. string dayResult = await GetSingleDevicesInfo(1, devicesInfo.dataGid.ToString(), devicesInfo.dataSid.ToString(),
  1428. "d", 6);
  1429. try
  1430. {
  1431. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(dayResult);
  1432. GlobalData.taoKouShuiWei_day = new ShuiWeiBianHuaData();
  1433. GlobalData.taoKouShuiWei_day.name = new string[tempData.data.Count];
  1434. GlobalData.taoKouShuiWei_day.value = new double[tempData.data.Count];
  1435. for (int i = 0; i < tempData.data.Count; i++)
  1436. {
  1437. GlobalData.taoKouShuiWei_day.name[i] = tempData.data[i].timeGroup;
  1438. GlobalData.taoKouShuiWei_day.value[i] = double.Parse(tempData.data[i].avgS1);
  1439. }
  1440. }
  1441. catch (Exception e)
  1442. {
  1443. Debug.LogWarning("获取6天平均数据不成功,原因:" + e.ToString());
  1444. }
  1445. string monthResult = await GetSingleDevicesInfo(1, devicesInfo.dataGid.ToString(), devicesInfo.dataSid.ToString(),
  1446. "d", 90);
  1447. try
  1448. {
  1449. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(monthResult);
  1450. GlobalData.taoKouShuiWei_month = new ShuiWeiBianHuaData();
  1451. GlobalData.taoKouShuiWei_month.name = new string[tempData.data.Count];
  1452. GlobalData.taoKouShuiWei_month.value = new double[tempData.data.Count];
  1453. for (int i = 0; i < tempData.data.Count; i++)
  1454. {
  1455. GlobalData.taoKouShuiWei_month.name[i] = tempData.data[i].timeGroup;
  1456. GlobalData.taoKouShuiWei_month.value[i] = double.Parse(tempData.data[i].avgS1);
  1457. }
  1458. }
  1459. catch (Exception e)
  1460. {
  1461. Debug.LogWarning("获取6月平均数据不成功,原因:" + e.ToString());
  1462. }
  1463. string hourResult = await GetSingleDevicesInfo(1, devicesInfo.dataGid.ToString(), devicesInfo.dataSid.ToString(),
  1464. "h", 6);
  1465. try
  1466. {
  1467. GetSingleDevicesRequest tempData = JsonConvert.DeserializeObject<GetSingleDevicesRequest>(hourResult);
  1468. GlobalData.taoKouShuiWei_hour = new ShuiWeiBianHuaData();
  1469. GlobalData.taoKouShuiWei_hour.name = new string[tempData.data.Count];
  1470. GlobalData.taoKouShuiWei_hour.value = new double[tempData.data.Count];
  1471. for (int i = 0; i < tempData.data.Count; i++)
  1472. {
  1473. GlobalData.taoKouShuiWei_hour.name[i] = tempData.data[i].timeGroup;
  1474. GlobalData.taoKouShuiWei_hour.value[i] = double.Parse(tempData.data[i].avgS1);
  1475. }
  1476. }
  1477. catch (Exception e)
  1478. {
  1479. Debug.LogWarning("获取6小时平均数据不成功,原因:" + e.ToString());
  1480. }
  1481. }
  1482. public async Task InitSWYJData3()
  1483. {
  1484. bool successInternet = true;
  1485. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeSWData);
  1486. requestData.timeout = 6;
  1487. await requestData.SendWebRequest();
  1488. try
  1489. {
  1490. if (requestData.result != UnityWebRequest.Result.Success)
  1491. {
  1492. Debug.LogWarning("水位高度联网不成功,原因:返request不成功");
  1493. successInternet = false;
  1494. }
  1495. else
  1496. {
  1497. string postResult = requestData.downloadHandler.text;
  1498. if (useAes)
  1499. {
  1500. postResult = AESCrypto.Decrypt(postResult);
  1501. }
  1502. JObject jsonObject = JObject.Parse(postResult);
  1503. // 提取data字段的值
  1504. JToken dataToken = jsonObject["data"];
  1505. JToken codeToken = jsonObject["code"];
  1506. //Debug.LogError(dataToken);
  1507. if (codeToken.ToString() == "200")
  1508. {
  1509. //Debug.LogError(200);
  1510. GlobalData.swDatas = JsonConvert.DeserializeObject<List<StationData>>(dataToken.ToString());
  1511. //Debug.LogError(GlobalData.swDatas.Count);
  1512. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  1513. {
  1514. GlobalData.swDatas[i].stnm = GlobalData.swDatas[i].stnm.Replace("(", "(").Replace(")", ")");
  1515. }
  1516. }
  1517. else
  1518. {
  1519. Debug.LogWarning("水位高度联网不成功,原因:返序列化失败");
  1520. successInternet = false;
  1521. }
  1522. //for (int i = 0; i < GlobalData.BuYuanShuiWeiDataList.Count; i++)
  1523. //{
  1524. // StationData stationData = new StationData();
  1525. // stationData.LGTD = 113.910187f;
  1526. // stationData.LTTD = 30.1765823f;
  1527. // stationData.STNM = GlobalData.BuYuanShuiWeiDataList[i].name;
  1528. // stationData.upz = GlobalData.BuYuanShuiWeiDataList[i].name.Contains("上")
  1529. // ? GlobalData.BuYuanShuiWeiDataList[i].value
  1530. // : -1;
  1531. // stationData.dwz = GlobalData.BuYuanShuiWeiDataList[i].name.Contains("下")
  1532. // ? GlobalData.BuYuanShuiWeiDataList[i].value
  1533. // : -1;
  1534. // GlobalData.swDatas.Add(stationData);
  1535. //}
  1536. }
  1537. }
  1538. catch (Exception e)
  1539. {
  1540. successInternet = false;
  1541. Debug.LogWarning("水位高度联网不成功,原因:" + e.ToString());
  1542. }
  1543. }
  1544. public async Task InitSWYJData4()
  1545. {
  1546. GlobalData.sWAlertDone = false;
  1547. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetAlerts);
  1548. requestData.timeout = 2;
  1549. await requestData.SendWebRequest();
  1550. try
  1551. {
  1552. if (requestData.result != UnityWebRequest.Result.Success)
  1553. {
  1554. Debug.LogWarning("水位告警联网不成功,原因:返request不成功");
  1555. }
  1556. else
  1557. {
  1558. string postResult = requestData.downloadHandler.text;
  1559. if (useAes)
  1560. {
  1561. postResult = AESCrypto.Decrypt(postResult);
  1562. }
  1563. JObject jsonObject = JObject.Parse(postResult);
  1564. // 提取data字段的值
  1565. JToken dataToken = jsonObject["rows"];
  1566. GlobalData.sWAlerts = JsonConvert.DeserializeObject<List<SWAlert>>(dataToken.ToString());
  1567. GlobalData.sWAlertDone = true;
  1568. }
  1569. }
  1570. catch (Exception e)
  1571. {
  1572. Debug.LogWarning("水位告警联网不成功,原因:" + e.ToString());
  1573. }
  1574. }
  1575. public async Task InitSWYJData0()
  1576. {
  1577. bool successInternet = true;
  1578. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetThreeLevel);
  1579. requestData.timeout = timeOut;
  1580. await requestData.SendWebRequest();
  1581. try
  1582. {
  1583. if (requestData.result != UnityWebRequest.Result.Success)
  1584. {
  1585. Debug.LogWarning("三线水位联网不成功,原因:返request不成功");
  1586. successInternet = false;
  1587. }
  1588. else
  1589. {
  1590. string postResult = requestData.downloadHandler.text;
  1591. if (useAes)
  1592. {
  1593. postResult = AESCrypto.Decrypt(postResult);
  1594. }
  1595. JObject jsonObject = JObject.Parse(postResult);
  1596. // 提取data字段的值
  1597. JToken dataToken = jsonObject["data"];
  1598. JToken codeToken = jsonObject["code"];
  1599. if (codeToken.ToString() == "200")
  1600. {
  1601. GlobalData.threeLevelShuiWeiDatas =
  1602. JsonConvert.DeserializeObject<List<ThreeLevelShuiWeiData>>(dataToken.ToString());
  1603. }
  1604. else
  1605. {
  1606. Debug.LogWarning("三线水位联网不成功,原因:返序列化失败");
  1607. successInternet = false;
  1608. }
  1609. }
  1610. }
  1611. catch (Exception e)
  1612. {
  1613. successInternet = false;
  1614. Debug.LogWarning("三线水位联网不成功,原因:" + e.ToString());
  1615. }
  1616. }
  1617. public async Task SendBuYuan_GetSensorData()
  1618. {
  1619. UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_BuYuan_GetSensorData);
  1620. await www.SendWebRequest();
  1621. try
  1622. {
  1623. if (www.result != UnityWebRequest.Result.Success)
  1624. {
  1625. Debug.LogWarning("获取补元闸门设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1626. }
  1627. else
  1628. {
  1629. // Debug.Log("11111111111111111111:" + www.downloadHandler.text);
  1630. GlobalData.buYuanSensorData = JsonUtility.FromJson<SensorDataResult>(www.downloadHandler.text);
  1631. }
  1632. }
  1633. catch (Exception e)
  1634. {
  1635. Debug.LogWarning("获取补元闸门设备数据不成功,原因:" + e.ToString());
  1636. }
  1637. www.Dispose();
  1638. }
  1639. public async void GetBuYuanDevicesGroupInfo()
  1640. {
  1641. Debug.Log("获取补元所有渗压记");
  1642. //获取所有渗压记
  1643. //GetDevicesData tempData = new GetDevicesData();
  1644. //tempData.idsList = new List<DevicesMessage>();
  1645. foreach (var device in GlobalData._devicesIdDatas.Values)
  1646. {
  1647. if (device.stationName.Contains("补元") && device.sensorType.Equals("渗压计"))
  1648. {
  1649. GlobalData.BuYuanShuiYaDataList.Add(new ShuiYaData()
  1650. {
  1651. name = device.sensorName,
  1652. value = device.realtimeValue1,
  1653. type = shuiYaType.BuYuanShuiYa,
  1654. targetName = $"BY_{device.sensorName}",
  1655. gid = device.dataGid.ToString(),
  1656. sid = device.dataSid.ToString()
  1657. });
  1658. }
  1659. }
  1660. Debug.Log("添加补元渗压记:" + GlobalData.BuYuanShuiYaDataList.Count);
  1661. Debug.Log("获取补元所有位移记");
  1662. //获取所有位移记
  1663. foreach (var device in GlobalData._devicesIdDatas.Values)
  1664. {
  1665. if (device.stationName.Contains("补元") && device.sensorType.Equals("静力水准仪"))
  1666. {
  1667. GlobalData.BuYuanWeiYiDataList.Add(new WeiYiData()
  1668. {
  1669. name = device.sensorName,
  1670. value = device.realtimeValue1,
  1671. type = weiYiType.BuYuanWeiYi,
  1672. targetName = $"BY_{device.sensorName}",
  1673. gid = device.dataGid.ToString(),
  1674. sid = device.dataSid.ToString()
  1675. });
  1676. }
  1677. }
  1678. Debug.Log("添加补元位移记:" + GlobalData.BuYuanWeiYiDataList.Count);
  1679. }
  1680. public async void GetTaoKouDevicesGroupInfo()
  1681. {
  1682. Debug.Log("获取套口所有渗压记");
  1683. //获取所有渗压记
  1684. foreach (var device in GlobalData._devicesIdDatas.Values)
  1685. {
  1686. if (device.stationName.Contains("套口") && device.sensorType.Equals("渗压计"))
  1687. {
  1688. GlobalData.TaoKouShuiYaDataList.Add(new ShuiYaData()
  1689. {
  1690. name = device.sensorName,
  1691. value = device.realtimeValue1,
  1692. type = shuiYaType.TaoKouShuiYa,
  1693. targetName = $"TK_{device.sensorName}",
  1694. gid = device.dataGid.ToString(),
  1695. sid = device.dataSid.ToString()
  1696. });
  1697. }
  1698. }
  1699. Debug.Log("添加套口渗压记:" + GlobalData.TaoKouShuiYaDataList.Count);
  1700. Debug.Log("获取套口所有位移记");
  1701. //获取所有位移记
  1702. foreach (var device in GlobalData._devicesIdDatas.Values)
  1703. {
  1704. if (device.stationName.Contains("补元") && device.sensorType.Equals("静力水准仪"))
  1705. {
  1706. GlobalData.TaoKouWeiYiDataList.Add(new WeiYiData()
  1707. {
  1708. name = device.sensorName,
  1709. value = device.realtimeValue1,
  1710. type = weiYiType.TaoKouWeiYi,
  1711. targetName = $"TK_{device.sensorName}",
  1712. gid = device.dataGid.ToString(),
  1713. sid = device.dataSid.ToString()
  1714. });
  1715. }
  1716. }
  1717. Debug.Log("添加套口位移记:" + GlobalData.TaoKouWeiYiDataList.Count);
  1718. }
  1719. public async Task SendTaoKou_GetSensorData()
  1720. {
  1721. UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_TaoKou_GetSensorData);
  1722. await www.SendWebRequest();
  1723. try
  1724. {
  1725. if (www.result != UnityWebRequest.Result.Success)
  1726. {
  1727. Debug.LogWarning("获取套口闸门设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1728. }
  1729. else
  1730. {
  1731. GlobalData.taoKouSensorData = JsonUtility.FromJson<SensorDataResult>(www.downloadHandler.text);
  1732. Debug.Log($"获取套口闸门设备数据:{GlobalData.taoKouSensorData.data.Count}");
  1733. }
  1734. }
  1735. catch (Exception e)
  1736. {
  1737. Debug.LogWarning("获取套口闸门设备数据不成功,原因:" + e.ToString());
  1738. }
  1739. www.Dispose();
  1740. }
  1741. /// <summary>
  1742. /// 获取设备趋势数据
  1743. /// </summary>
  1744. /// <param name="type">0:补元 1:套口</param>
  1745. /// <param name="gid">=devicesID 套口都传一样=sid</param>
  1746. /// <param name="sid">=ChannelID 套口都传一样=sid</param>
  1747. /// <param name="beginTime">yyyy-MM-dd 最大183天</param>
  1748. /// <param name="endTime"></param>
  1749. /// <returns></returns>
  1750. public async Task<string> GetDeviceTrend(int type, string gid, string sid, string beginTime, string endTime)
  1751. {
  1752. string cmdUrl = ServerAddress.APIGetDeviceTrend;
  1753. cmdUrl += $"/{(type == 0 ? "buyuan" : "taokou")}/{gid}/{sid}?beginTime={beginTime}&endTime={endTime}";
  1754. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  1755. www.downloadHandler = new DownloadHandlerBuffer();
  1756. www.SetRequestHeader("Content-Type", "application/json");
  1757. Debug.Log("send:" + cmdUrl);
  1758. await www.SendWebRequest();
  1759. if (www.result != UnityWebRequest.Result.Success)
  1760. {
  1761. Debug.LogWarning("获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1762. }
  1763. string result = www.downloadHandler.text;
  1764. www.Dispose();
  1765. return result;
  1766. }
  1767. // /// <summary>
  1768. // /// 获取补元硬件组数据
  1769. // /// </summary>
  1770. // /// <param name="sendData"></param>
  1771. // /// <returns></returns>
  1772. // public async Task<string> Devices(GetDevicesData sendData)
  1773. // {
  1774. // string cmdUrl = ServerAddress.API_BuYuan_GetDevicesGroupInfo;
  1775. // string tempStr = JsonConvert.SerializeObject(sendData);
  1776. // var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1777. // UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1778. // www.uploadHandler = new UploadHandlerRaw(sendByte);
  1779. // www.downloadHandler = new DownloadHandlerBuffer();
  1780. // www.SetRequestHeader("Content-Type", "application/json");
  1781. // await www.SendWebRequest();
  1782. // if (www.result != UnityWebRequest.Result.Success)
  1783. // {
  1784. // Debug.LogWarning($"获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1785. // }
  1786. // string result = www.downloadHandler.text;
  1787. // www.Dispose();
  1788. // return result;
  1789. // }
  1790. /// <summary>
  1791. /// 获取设备的最近N条记录
  1792. /// </summary>
  1793. /// <param name="channelId=gid"></param>
  1794. /// <param name="deviceId=sid"></param>
  1795. /// <param name="count"></param>
  1796. /// <returns></returns>
  1797. public async Task<string> GetSingleDevicesInfo(int type, string gid, string sid, string timeUnit, int count)
  1798. {
  1799. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo;
  1800. cmdUrl += $"?dataFrom={type}&dataSid={sid}&dataGid={gid}&timeUnit={timeUnit}&number={count}";
  1801. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  1802. www.downloadHandler = new DownloadHandlerBuffer();
  1803. www.SetRequestHeader("Content-Type", "application/json");
  1804. await www.SendWebRequest();
  1805. if (www.result != UnityWebRequest.Result.Success)
  1806. {
  1807. Debug.LogWarning("获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1808. }
  1809. string result = www.downloadHandler.text;
  1810. www.Dispose();
  1811. return result;
  1812. }
  1813. /// <summary>
  1814. /// 获取设备最近几天的平均数据
  1815. /// </summary>
  1816. /// <param name="channelId"></param>
  1817. /// <param name="deviceId"></param>
  1818. /// <param name="count"></param>
  1819. /// <returns></returns>
  1820. public async Task<string> GetSingleDevicesInfo_day(int channelId, int deviceId, int count)
  1821. {
  1822. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  1823. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  1824. sendData.ChannelID = channelId;
  1825. sendData.DeviceID = deviceId;
  1826. sendData.AvgType = "day";
  1827. sendData.N = count;
  1828. string tempStr = JsonConvert.SerializeObject(sendData);
  1829. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1830. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1831. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1832. www.downloadHandler = new DownloadHandlerBuffer();
  1833. www.SetRequestHeader("Content-Type", "application/json");
  1834. await www.SendWebRequest();
  1835. if (www.result != UnityWebRequest.Result.Success)
  1836. {
  1837. Debug.LogWarning("获取设备天平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1838. }
  1839. string result = www.downloadHandler.text;
  1840. www.Dispose();
  1841. return result;
  1842. }
  1843. /// <summary>
  1844. /// 获取设备最近几小时的平均数据
  1845. /// </summary>
  1846. /// <param name="channelId"></param>
  1847. /// <param name="deviceId"></param>
  1848. /// <param name="count"></param>
  1849. /// <returns></returns>
  1850. public async Task<string> GetSingleDevicesInfo_hour(int channelId, int deviceId, int count)
  1851. {
  1852. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  1853. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  1854. sendData.ChannelID = channelId;
  1855. sendData.DeviceID = deviceId;
  1856. sendData.AvgType = "hour";
  1857. sendData.N = count;
  1858. string tempStr = JsonConvert.SerializeObject(sendData);
  1859. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1860. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1861. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1862. www.downloadHandler = new DownloadHandlerBuffer();
  1863. www.SetRequestHeader("Content-Type", "application/json");
  1864. await www.SendWebRequest();
  1865. if (www.result != UnityWebRequest.Result.Success)
  1866. {
  1867. Debug.LogWarning("获取设备小时平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1868. }
  1869. string result = www.downloadHandler.text;
  1870. www.Dispose();
  1871. return result;
  1872. }
  1873. /// <summary>
  1874. /// 获取设备最近几个月的平均数据
  1875. /// </summary>
  1876. /// <param name="channelId"></param>
  1877. /// <param name="deviceId"></param>
  1878. /// <param name="count"></param>
  1879. /// <returns></returns>
  1880. public async Task<string> GetSingleDevicesInfo_month(int channelId, int deviceId, int count)
  1881. {
  1882. string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
  1883. GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
  1884. sendData.ChannelID = channelId;
  1885. sendData.DeviceID = deviceId;
  1886. sendData.AvgType = "month";
  1887. sendData.N = count;
  1888. string tempStr = JsonConvert.SerializeObject(sendData);
  1889. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1890. UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
  1891. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1892. www.downloadHandler = new DownloadHandlerBuffer();
  1893. www.SetRequestHeader("Content-Type", "application/json");
  1894. await www.SendWebRequest();
  1895. if (www.result != UnityWebRequest.Result.Success)
  1896. {
  1897. Debug.LogWarning("获取设备月平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1898. }
  1899. string result = www.downloadHandler.text;
  1900. www.Dispose();
  1901. return result;
  1902. }
  1903. public async UniTaskVoid GetGCYW_Station()
  1904. {
  1905. Debug.Log("获取B08GCYW 站点列表");
  1906. using UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_B08_getStationList);
  1907. www.downloadHandler = new DownloadHandlerBuffer();
  1908. www.SetRequestHeader("Content-Type", "application/json");
  1909. await www.SendWebRequest();
  1910. if (www.result != UnityWebRequest.Result.Success)
  1911. {
  1912. Debug.LogWarning($"获取{ServerAddress.API_B08_getStationList}数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  1913. }
  1914. var jsonStr = www.downloadHandler.text;
  1915. www.Dispose();
  1916. Debug.Log(jsonStr);
  1917. var datas = JsonConvert.DeserializeObject<B08_StationListData>(jsonStr);
  1918. foreach (var data in datas.data)
  1919. {
  1920. GlobalData.B08StationList.TryAdd(data.name, data.id);
  1921. foreach (var chiles in data.children)
  1922. {
  1923. GlobalData.B08StationList.TryAdd(chiles.name, chiles.id);
  1924. foreach (var chilesChile in chiles.children)
  1925. {
  1926. GlobalData.B08StationList.TryAdd(chilesChile.name, chilesChile.id);
  1927. foreach (var chilesChilesChild in chiles.children)
  1928. {
  1929. GlobalData.B08StationList.TryAdd(chilesChilesChild.name, chilesChilesChild.id);
  1930. //三层应该没有儿子了吧 拉屎谁不会呢
  1931. }
  1932. }
  1933. }
  1934. }
  1935. //懒得搞直接获取所有属性
  1936. foreach (var key in GlobalData.B08StationList.Keys)
  1937. {
  1938. var StatisticsStr = await GetStatistics(GlobalData.B08StationList[key]);
  1939. B08_StatisticsInfo saveInfo = new B08_StatisticsInfo();
  1940. saveInfo.dates = new List<string>();
  1941. saveInfo.valueOfDates = new List<int>();
  1942. JObject jsonObject = JObject.Parse(StatisticsStr);
  1943. // 提取data字段的值
  1944. JToken dataToken = jsonObject["data"];
  1945. JToken statusCount = dataToken["statusCount"];
  1946. saveInfo.waitDispatch = statusCount?["0"] != null ? statusCount["0"].ToString() : "0";
  1947. saveInfo.waitPatrol = statusCount?["1"] != null ? statusCount["1"].ToString() : "0";
  1948. saveInfo.onPatrol = statusCount?["2"] != null ? statusCount["2"].ToString() : "0";
  1949. saveInfo.patrolCompleted = statusCount?["3"] != null ? statusCount["3"].ToString() : "0";
  1950. JObject dailyCountObj=(JObject)dataToken["dailyCount"];
  1951. foreach (var property in dailyCountObj.Properties())
  1952. {
  1953. saveInfo.dates.Add(property.Name);
  1954. saveInfo.valueOfDates.Add((int)property.Value);
  1955. }
  1956. GlobalData.B08StatisticsInfo.TryAdd(key, saveInfo);
  1957. }
  1958. Debug.Log("获取站点信息完毕");
  1959. }
  1960. public async Cysharp.Threading.Tasks.UniTask<string> GetStatistics(string stationId)
  1961. {
  1962. var result="";
  1963. string startTime = DateTime.Now.AddDays(-7).ToString("yyyy-M-d");
  1964. string endTime =DateTime.Now.ToString("yyyy-M-d");
  1965. var sendData = new PostStatisticsData
  1966. {
  1967. timeRange = new string[]
  1968. {
  1969. $"{startTime}", $"{endTime}"
  1970. },
  1971. startTime = $"{startTime} 00:00:00",
  1972. endTime = $"{endTime} 23:59:59",
  1973. ids = stationId
  1974. };
  1975. string tempStr = JsonConvert.SerializeObject(sendData);
  1976. var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
  1977. using UnityWebRequest www = new UnityWebRequest("http://58.19.230.46:9180/prod-api/project/workOrder/statistics","POST");
  1978. www.uploadHandler = new UploadHandlerRaw(sendByte);
  1979. www.downloadHandler = new DownloadHandlerBuffer();
  1980. www.SetRequestHeader("Content-Type", "application/json");
  1981. await www.SendWebRequest();
  1982. result = www.downloadHandler.text;
  1983. www.Dispose();
  1984. return result;
  1985. }
  1986. public async UniTask InitGCYWData1(string ids)
  1987. {
  1988. GlobalData.B08_Type = ids;
  1989. string TFSJ_cmd =
  1990. $"http://58.19.230.46:9180/prod-api/project/workOrder/list?pageNum=1&pageSize=999&type=2&stationId={ids}&isAsc=desc";
  1991. UnityWebRequest TFSJ_www = new UnityWebRequest(TFSJ_cmd, "Get");
  1992. TFSJ_www.downloadHandler = new DownloadHandlerBuffer();
  1993. TFSJ_www.SetRequestHeader("Content-Type", "application/json");
  1994. TFSJ_www.SetRequestHeader("Authorization", "Bearer "+token);
  1995. await TFSJ_www.SendWebRequest();
  1996. if (TFSJ_www.result != UnityWebRequest.Result.Success)
  1997. {
  1998. Debug.LogWarning($"获取{TFSJ_cmd}数据不成功,原因:返request不成功:" + TFSJ_www.downloadHandler.text);
  1999. }
  2000. string TFSJ_result = TFSJ_www.downloadHandler.text;
  2001. GlobalData.B08Event = JsonConvert.DeserializeObject<B08_event>(TFSJ_result);
  2002. foreach (var eventItems in GlobalData.B08Event.rows)
  2003. {
  2004. if (eventItems.status == null)
  2005. {
  2006. GlobalData.B08Event.waitHandle++;
  2007. continue;
  2008. }
  2009. switch (eventItems.status)
  2010. {
  2011. case 0:
  2012. case 1:
  2013. GlobalData.B08Event.waitHandle++;
  2014. break;
  2015. case 2:
  2016. GlobalData.B08Event.waitAccept++;
  2017. break;
  2018. case 3:
  2019. GlobalData.B08Event.hasHandle++;
  2020. break;
  2021. }
  2022. }
  2023. Debug.Log(TFSJ_result);
  2024. Debug.Log("!!!!!!!!!!!!!!!!!!!!");
  2025. string XJRW_cmd = $"http://58.19.230.46:9180/prod-api/project/workOrder/list?pageNum=1&pageSize=999&type=3&stationId={ids}&isAsc=desc";
  2026. UnityWebRequest XJRW_www = new UnityWebRequest(XJRW_cmd, "Get");
  2027. XJRW_www.downloadHandler = new DownloadHandlerBuffer();
  2028. XJRW_www.SetRequestHeader("Content-Type", "application/json");
  2029. XJRW_www.SetRequestHeader("Authorization", "Bearer "+token);
  2030. await XJRW_www.SendWebRequest();
  2031. if (XJRW_www.result != UnityWebRequest.Result.Success)
  2032. {
  2033. Debug.LogWarning($"获取{XJRW_cmd}数据不成功,原因:返request不成功:" + XJRW_www.downloadHandler.text);
  2034. }
  2035. string XJRW_result = XJRW_www.downloadHandler.text;
  2036. Debug.Log(XJRW_result);
  2037. Debug.Log("!!!!!!!!!!!!!!!!!!!!");
  2038. // try
  2039. // {
  2040. // jsonStr = await B08_API_data(ServerAddress.API_B08_dataStatis, type);
  2041. // Debug.Log("API_B08_dataStatis" + jsonStr);
  2042. // GlobalData.B08DataStatis = JsonConvert.DeserializeObject<B08_dataStatis>(jsonStr);
  2043. // }
  2044. // catch (Exception e)
  2045. // {
  2046. // Debug.LogWarning("获取API_B08_dataStatis数据不成功,原因:" + e.ToString());
  2047. // }
  2048. //
  2049. // try
  2050. // {
  2051. // jsonStr = await B08_API_data(ServerAddress.API_B08_inspectResult, type);
  2052. // Debug.Log("API_B08_inspectResult" + jsonStr);
  2053. // GlobalData.B08InspectResult = JsonConvert.DeserializeObject<B08_inspectResult>(jsonStr);
  2054. // }
  2055. // catch (Exception e)
  2056. // {
  2057. // Debug.LogWarning("获取API_B08_inspectResult数据不成功,原因:" + e.ToString());
  2058. // }
  2059. //
  2060. // try
  2061. // {
  2062. // jsonStr = await B08_API_data(ServerAddress.API_B08_projectExamine, type);
  2063. // Debug.Log("API_B08_projectExamine" + jsonStr);
  2064. // GlobalData.B08ProjectExamine = JsonConvert.DeserializeObject<B08_projectExamine>(jsonStr);
  2065. // }
  2066. // catch (Exception e)
  2067. // {
  2068. // Debug.LogWarning("获取API_B08_projectExamine数据不成功,原因:" + e.ToString());
  2069. // }
  2070. //
  2071. // try
  2072. // {
  2073. // jsonStr = await B08_API_data(ServerAddress.API_B08_event, type);
  2074. // Debug.Log("API_B08_event" + jsonStr);
  2075. // GlobalData.B08Event = JsonConvert.DeserializeObject<B08_event>(jsonStr);
  2076. // }
  2077. // catch (Exception e)
  2078. // {
  2079. // Debug.LogWarning("获取API_B08_event数据不成功,原因:" + e.ToString());
  2080. // }
  2081. // try
  2082. // {
  2083. // jsonStr = await B08_API_data(ServerAddress.API_B08_questionStatis, type);
  2084. // Debug.Log("API_B08_questionStatis" + jsonStr);
  2085. // GlobalData.B08QuestionStatis = JsonConvert.DeserializeObject<B08_questionStatis>(jsonStr);
  2086. // }
  2087. // catch (Exception e)
  2088. // {
  2089. // Debug.LogWarning("获取API_B08_questionStatis数据不成功,原因:" + e.ToString());
  2090. // }
  2091. }
  2092. public async Task B08_GetTaskList()
  2093. {
  2094. string jsonStr;
  2095. try
  2096. {
  2097. jsonStr = await B08_API_TaskInfoList(1,999);
  2098. //Debug.Log("B08_API_TaskInfoList" + jsonStr);
  2099. GlobalData.B08TaskListData = JsonConvert.DeserializeObject<B08_TaskListInfoData>(jsonStr);
  2100. //Debug.Log("GlobalData.B08TaskListData: "+GlobalData.B08TaskListData.rows.Length);
  2101. // GlobalData.B08TaskListInfos = new B08_TaskListInfoData[GlobalData.B08InspectType.data.Length];
  2102. for (int i = 0; i < GlobalData.B08TaskListData.rows.Length; i++)
  2103. {
  2104. string tempResult = await B08_API_TaskInfo(GlobalData.B08TaskListData.rows[i].id);
  2105. //Debug.Log($"B08_API_TaskInfo id={GlobalData.B08TaskListData.rows[i].id}:" + tempResult);
  2106. var tempInfo= JsonConvert.DeserializeObject<B08_TaskInfo>(tempResult);
  2107. if (tempInfo != null)
  2108. {
  2109. GlobalData.B08TaskListData.rows[i].infoData = tempInfo.Data;
  2110. }
  2111. else
  2112. {
  2113. Debug.Log("tempInfo null! :"+tempResult);
  2114. }
  2115. string taskLocationResult = await B08_API_TaskLocation(GlobalData.B08TaskListData.rows[i].id);
  2116. Debug.Log($"taskLocationResult id={GlobalData.B08TaskListData.rows[i].id}:" + taskLocationResult);
  2117. GlobalData.B08TaskListData.rows[i].infoData.Locations = JsonConvert.DeserializeObject<B08_TaskLocationData>(taskLocationResult).data.locations;
  2118. }
  2119. }
  2120. catch (Exception e)
  2121. {
  2122. Debug.LogWarning("获取B08_API_TaskInfo数据不成功,原因:" + e.ToString());
  2123. }
  2124. }
  2125. public string token;
  2126. public async Task<string> B08_API_data(string cmdUrl, int type)
  2127. {
  2128. if (type == 0)
  2129. {
  2130. cmdUrl += "1794245918999351298";
  2131. }
  2132. else if (type == 1)
  2133. {
  2134. cmdUrl += "1798366756789653505";
  2135. }
  2136. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  2137. www.downloadHandler = new DownloadHandlerBuffer();
  2138. www.SetRequestHeader("Content-Type", "application/json");
  2139. await www.SendWebRequest();
  2140. if (www.result != UnityWebRequest.Result.Success)
  2141. {
  2142. Debug.LogWarning($"获取{cmdUrl}数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2143. }
  2144. string result = www.downloadHandler.text;
  2145. www.Dispose();
  2146. return result;
  2147. }
  2148. // public async Task<string> B08_API_TaskInfo(int type, int xunjian_type)
  2149. // {
  2150. // string cmdUrl = ServerAddress.API_B08_taskInfo;
  2151. // if (type == 0)
  2152. // {
  2153. // cmdUrl += "1794245918999351298";
  2154. // }
  2155. // else if (type == 1)
  2156. // {
  2157. // cmdUrl += "1798366756789653505";
  2158. // }
  2159. //
  2160. // cmdUrl += "&xunjian_type=" + xunjian_type;
  2161. // Debug.Log("!!!:" + cmdUrl);
  2162. // UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  2163. // www.downloadHandler = new DownloadHandlerBuffer();
  2164. // www.SetRequestHeader("Content-Type", "application/json");
  2165. // await www.SendWebRequest();
  2166. // if (www.result != UnityWebRequest.Result.Success)
  2167. // {
  2168. // Debug.LogWarning($"获取B08_API_TaskInfo type={type} 数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2169. // }
  2170. // string result = www.downloadHandler.text;
  2171. // www.Dispose();
  2172. // return result;
  2173. // }
  2174. public async Task<string> B08_API_GetToken()
  2175. {
  2176. string cmdUrl = ServerAddress.API_GetToken;
  2177. //Debug.Log("!!!:" + cmdUrl);
  2178. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Post");
  2179. www.downloadHandler = new DownloadHandlerBuffer();
  2180. www.SetRequestHeader("Content-Type", "application/json");
  2181. await www.SendWebRequest();
  2182. if (www.result != UnityWebRequest.Result.Success)
  2183. {
  2184. Debug.LogWarning($"获取API_GetToken 数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2185. }
  2186. string result = www.downloadHandler.text;
  2187. www.Dispose();
  2188. return result;
  2189. }
  2190. public async Task<string> B08_API_TaskInfoList(int page,int pageSize)
  2191. {
  2192. string cmdUrl = ServerAddress.API_B08_taskInfoList;
  2193. cmdUrl += $"?pageNum={page}&pageSize={pageSize}";
  2194. Debug.Log("!!!:" + cmdUrl +" token:"+token);
  2195. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  2196. www.downloadHandler = new DownloadHandlerBuffer();
  2197. www.SetRequestHeader("Content-Type", "application/json");
  2198. www.SetRequestHeader("Authorization", "Bearer "+token);
  2199. await www.SendWebRequest();
  2200. if (www.result != UnityWebRequest.Result.Success)
  2201. {
  2202. Debug.LogWarning($"获取B08_API_TaskInfoList page={page} pageSize={pageSize} 数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2203. }
  2204. string result = www.downloadHandler.text;
  2205. www.Dispose();
  2206. return result;
  2207. }
  2208. public async Task<string> B08_API_TaskInfo(string id)
  2209. {
  2210. string cmdUrl = ServerAddress.API_B08_taskInfo;
  2211. cmdUrl += $"/{id}";
  2212. Debug.Log("!!!:" + cmdUrl +" token:"+token);
  2213. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  2214. www.downloadHandler = new DownloadHandlerBuffer();
  2215. www.SetRequestHeader("Content-Type", "application/json");
  2216. www.SetRequestHeader("Authorization", "Bearer "+token);
  2217. await www.SendWebRequest();
  2218. if (www.result != UnityWebRequest.Result.Success)
  2219. {
  2220. Debug.LogWarning($"获取API_B08_taskInfo id={id} 数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2221. }
  2222. string result = www.downloadHandler.text;
  2223. www.Dispose();
  2224. return result;
  2225. }
  2226. public async Task<string> B08_API_TaskInfoItems(string id)
  2227. {
  2228. string cmdUrl = ServerAddress.API_B08_taskItems;
  2229. cmdUrl += $"/{id}/taskItems";
  2230. //Debug.Log("!!!:" + cmdUrl +" token:"+token);
  2231. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  2232. www.downloadHandler = new DownloadHandlerBuffer();
  2233. www.SetRequestHeader("Content-Type", "application/json");
  2234. www.SetRequestHeader("Authorization", "Bearer "+token);
  2235. await www.SendWebRequest();
  2236. if (www.result != UnityWebRequest.Result.Success)
  2237. {
  2238. Debug.LogWarning($"获取B08_API_TaskInfoItems id={id} 数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2239. }
  2240. string result = www.downloadHandler.text;
  2241. www.Dispose();
  2242. return result;
  2243. }
  2244. public async Task<string> B08_API_TaskLocation(string id)
  2245. {
  2246. string cmdUrl = ServerAddress.API_B08_taskLocation;
  2247. cmdUrl += $"/{id}?useOptimized=true&includeWorkOrderInfo=true&limit=100";
  2248. Debug.Log("!!!:" + cmdUrl +" token:"+token);
  2249. UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
  2250. www.downloadHandler = new DownloadHandlerBuffer();
  2251. www.SetRequestHeader("Content-Type", "application/json");
  2252. www.SetRequestHeader("Authorization", "Bearer "+token);
  2253. await www.SendWebRequest();
  2254. if (www.result != UnityWebRequest.Result.Success)
  2255. {
  2256. Debug.LogWarning($"获取API_B08_taskLocation id={id} 数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2257. }
  2258. string result = www.downloadHandler.text;
  2259. www.Dispose();
  2260. return result;
  2261. }
  2262. /// <summary>
  2263. /// 获取站点水位图表
  2264. /// </summary>
  2265. /// <param name="stcd"></param>
  2266. /// <returns></returns>
  2267. public async Task<string> GetWaterTrend_Chart(string stcd,string startDate,string endDate)
  2268. {
  2269. UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetWaterTrend_chart + stcd + "&startDate=" + startDate + "&endDate=" + endDate, "Get");
  2270. Debug.Log(ServerAddress.API_GetWaterTrend_chart + stcd + "&startDate=" + startDate + "&endDate=" + endDate);
  2271. www.downloadHandler = new DownloadHandlerBuffer();
  2272. www.SetRequestHeader("Content-Type", "application/json");
  2273. await www.SendWebRequest();
  2274. if (www.result != UnityWebRequest.Result.Success)
  2275. {
  2276. Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2277. }
  2278. string result = www.downloadHandler.text;
  2279. www.Dispose();
  2280. return result;
  2281. }
  2282. public async Task<string> GetDropTrend_Chart(string stcd, string startDate, string endDate)
  2283. {
  2284. UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetDropTrend_chart + stcd + "&startDate=" + startDate + "&endDate=" + endDate, "Get");
  2285. www.downloadHandler = new DownloadHandlerBuffer();
  2286. www.SetRequestHeader("Content-Type", "application/json");
  2287. await www.SendWebRequest();
  2288. if (www.result != UnityWebRequest.Result.Success)
  2289. {
  2290. Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2291. }
  2292. string result = www.downloadHandler.text;
  2293. www.Dispose();
  2294. return result;
  2295. }
  2296. public async Task<string> GetWaterTrend_Info(string stcd)
  2297. {
  2298. UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetWaterTrend_info + stcd, "Get");
  2299. www.downloadHandler = new DownloadHandlerBuffer();
  2300. www.SetRequestHeader("Content-Type", "application/json");
  2301. await www.SendWebRequest();
  2302. if (www.result != UnityWebRequest.Result.Success)
  2303. {
  2304. Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2305. }
  2306. string result = www.downloadHandler.text;
  2307. www.Dispose();
  2308. return result;
  2309. }
  2310. public void SaveFirstFrame(byte[] uploadData, string fileName, string _targetName)
  2311. {
  2312. StartCoroutine(SendSaveFirstFrame(uploadData, fileName, _targetName));
  2313. }
  2314. IEnumerator SendSaveFirstFrame(byte[] uploadData, string fileName, string _targetName)
  2315. {
  2316. //fileName = "1.jpg";
  2317. WWWForm form = new WWWForm();
  2318. form.AddBinaryData("file", uploadData, fileName);
  2319. UnityWebRequest www = UnityWebRequest.Post(ServerAddress.API_TextureUploadPath, form);
  2320. yield return www.SendWebRequest();
  2321. if (www.result == UnityWebRequest.Result.Success)
  2322. {
  2323. ActionInstance._Instance.obsFmUpdata?.Invoke(_targetName);
  2324. }
  2325. Debug.Log(www.downloadHandler.text);
  2326. www.Dispose();
  2327. }
  2328. #region 摄像头远程控制
  2329. public void GetDeviceChannelId(string deviceId, Action<string> callBack)
  2330. {
  2331. StartCoroutine(SendGetDevicesChannel(deviceId, 1, 1, callBack));
  2332. }
  2333. IEnumerator SendGetDevicesChannel(string deviceId, int page, int count, Action<string> call)
  2334. {
  2335. string sendUrl = ServerAddress.API_GetDevicesInfo;
  2336. sendUrl += $"/{deviceId}/channels?page={page}&count={count}&query&online&channelType&catalogUnderDevice";
  2337. UnityWebRequest www = UnityWebRequest.Get(sendUrl);
  2338. yield return www.SendWebRequest();
  2339. ObsHttpRequestData tempData = JsonConvert.DeserializeObject<ObsHttpRequestData>(www.downloadHandler.text);
  2340. GetObsChannelRequestData channelData = tempData.data.ToObject<GetObsChannelRequestData>();
  2341. call?.Invoke(channelData.list[0].channelId);
  2342. www.Dispose();
  2343. }
  2344. IEnumerator SendStartRTSP(string deviceId, string channelId)
  2345. {
  2346. string sendUrl = ServerAddress.API_PlayStart;
  2347. sendUrl += $"/{deviceId}/{channelId}";
  2348. UnityWebRequest www = UnityWebRequest.Get(sendUrl);
  2349. yield return www.SendWebRequest();
  2350. Debug.Log(www.downloadHandler.text);
  2351. www.Dispose();
  2352. }
  2353. public void SendObsCameraCtrlCmd(string deviceId, string channelId, ObsCtrlType type)
  2354. {
  2355. StartCoroutine(SendCameraCtrl(deviceId, channelId, type.ToString()));
  2356. }
  2357. IEnumerator SendCameraCtrl(string deviceId, string channelId, string command)
  2358. {
  2359. string sendUrl = ServerAddress.API_CameraCtrl;
  2360. sendUrl += $"/{deviceId}/{channelId}?command={command}&horizonSpeed=10&verticalSpeed=10&zoomSpeed=10";
  2361. UnityWebRequest www = UnityWebRequest.Post(sendUrl, "");
  2362. Debug.Log("send:" + sendUrl);
  2363. yield return www.SendWebRequest();
  2364. Debug.Log(www.downloadHandler.text);
  2365. www.Dispose();
  2366. }
  2367. #endregion
  2368. // /// <summary>
  2369. // /// 所有硬件设备的获取信息
  2370. // /// </summary>
  2371. public async Task GetSensorList()
  2372. {
  2373. bool successInternet = true;
  2374. UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_GetAllSensorList);
  2375. www.timeout = timeOut;
  2376. await www.SendWebRequest();
  2377. try
  2378. {
  2379. if (www.result != UnityWebRequest.Result.Success)
  2380. {
  2381. successInternet = false;
  2382. Debug.LogWarning("获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
  2383. }
  2384. else
  2385. {
  2386. Debug.Log($"设备列表json :{www.downloadHandler.text}");
  2387. SensorListResult tempData = JsonUtility.FromJson<SensorListResult>(www.downloadHandler.text);
  2388. GlobalData._devicesIdDatas = new Dictionary<string, DevicesId_Data>();
  2389. for (int i = 0; i < tempData.rows.Count; i++)
  2390. {
  2391. GlobalData._devicesIdDatas.Add(tempData.rows[i].sensorName, tempData.rows[i]);
  2392. }
  2393. Debug.Log($"初始化设备列表成功!!! count:{tempData.total}");
  2394. }
  2395. }
  2396. catch (Exception e)
  2397. {
  2398. successInternet = false;
  2399. Debug.LogWarning("获取设备数据不成功,原因:" + e.ToString());
  2400. }
  2401. www.Dispose();
  2402. if (!successInternet)
  2403. {
  2404. WWW localWWW = new WWW(Application.streamingAssetsPath + "/SensorList.json");
  2405. await new UnityAsync.WaitUntil(() => { return localWWW.isDone; });
  2406. SensorListResult tempData = JsonUtility.FromJson<SensorListResult>(localWWW.text);
  2407. GlobalData._devicesIdDatas = new Dictionary<string, DevicesId_Data>();
  2408. for (int i = 0; i < tempData.rows.Count; i++)
  2409. {
  2410. GlobalData._devicesIdDatas.Add(tempData.rows[i].sensorName, tempData.rows[i]);
  2411. }
  2412. Debug.Log($"读取本地初始化设备列表成功!!! count:{tempData.total}");
  2413. www.Dispose();
  2414. }
  2415. }
  2416. }