HttpHelper.cs 64 KB

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