XunJianDataManager.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. using LitJson;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. using XRTool.Util;
  9. using static easyar.ImageTargetController;
  10. public class XunJianDataManager : Singleton<XunJianDataManager>
  11. {
  12. public XunJianListData chooseXunJian;
  13. public List<XunJianListData> xjDataList = new List<XunJianListData>();
  14. public void GetXunJianList(Action<List<XunJianListData>> callback)
  15. {
  16. WindowsManager.Instance.StartCoroutine(testBack(callback));
  17. }
  18. public void GetAreaList(string area, Action<List<XunJianListData>> callback)
  19. {
  20. if (areaList.ContainsKey(area))
  21. {
  22. callback.Invoke(areaList[area]);
  23. }
  24. else
  25. {
  26. callback.Invoke(xjDataList);
  27. }
  28. }
  29. public void GetPeopleList(string people, Action<List<XunJianListData>> callback)
  30. {
  31. if(peopleList.ContainsKey(people))
  32. {
  33. callback.Invoke( peopleList[people]);
  34. }else
  35. {
  36. callback.Invoke(xjDataList);
  37. }
  38. }
  39. XunJianListData testData()
  40. {
  41. XunJianListData xj = new XunJianListData();
  42. xj.id = "saotu";
  43. xj.url = Application.streamingAssetsPath + "/DianYun/85471-ghzoffice (2).bytes";
  44. xj.projectname = "工厂巡检";
  45. xj.inarea = "杨浦区";
  46. xj.updateState = "新项目";
  47. xj.projectState = "测试巡检 ";
  48. xj.projectType = "未开始 ";
  49. xj.projectTime = "2023/11/23 10:53 ";
  50. xj.renwuModelType = RenWuModelType.SaoTu;
  51. xj.itemList = getRenwuData();
  52. xj.people = "员工A";
  53. return xj;
  54. }
  55. XunJianListData testData2()
  56. {
  57. XunJianListData xj = new XunJianListData();
  58. xj.id = "saotu";
  59. xj.url = Application.streamingAssetsPath + "/DianYun/85471-ghzoffice (2).bytes";
  60. xj.projectname = "办公室巡检";
  61. xj.inarea = "杨浦区";
  62. xj.updateState = "新项目";
  63. xj.projectState = "测试巡检 ";
  64. xj.projectType = "未开始 ";
  65. xj.projectTime = "2023/11/23 10:53 ";
  66. xj.renwuModelType = RenWuModelType.DianYun;
  67. xj.itemList = getRenwuData();
  68. xj.people = "员工B";
  69. return xj;
  70. }
  71. XunJianListData testData3()
  72. {
  73. XunJianListData xj = new XunJianListData();
  74. xj.id = "saotu";
  75. xj.url = Application.streamingAssetsPath + "/DianYun/85471-ghzoffice (2).bytes";
  76. xj.projectname = "机房巡检";
  77. xj.inarea = "杨浦区";
  78. xj.updateState = "新项目";
  79. xj.projectState = "巡检 ";
  80. xj.projectType = "未开始 ";
  81. xj.projectTime = "2023/11/23 10:53 ";
  82. xj.renwuModelType = RenWuModelType.None;
  83. xj.itemList = getRenwuData();
  84. xj.people = "员工C";
  85. xj.listWall = getWallData();
  86. return xj;
  87. }
  88. List<RenWuItem> getRenwuData()
  89. {
  90. List < RenWuItem > itemlist = new List<RenWuItem>();
  91. for (int j = 0; j < 7; j++)
  92. {
  93. RenWuItem rw = new RenWuItem();
  94. rw.imageUrl ="";
  95. //任务id
  96. rw.id = j.ToString();
  97. RenWuTypeModel rwtm = new RenWuTypeModel();
  98. RenWuTypeModel rwtm2 = new RenWuTypeModel();
  99. RenWuTypeModel rwtm3 = new RenWuTypeModel();
  100. RenWuTypeModel rwtm4 = new RenWuTypeModel();
  101. //任务索引
  102. rw.index = j;
  103. switch(j)
  104. {
  105. case 0:
  106. //任务路线 (空间定位时才有)
  107. rw.roadList = new List<Vector3>();
  108. rw.roadList.Add(new Vector3(-4.2f+0.5f, 0, 0.92f));
  109. rw.roadList.Add(new Vector3(-4.2f + 0.5f, 0, 2));
  110. rw.roadList.Add(new Vector3(-5 + 0.5f, 0, 2));
  111. rw.info = "请检查机房空调温度是否正常";
  112. //单个任务素材
  113. rw.typeList = new List<RenWuTypeModel>();
  114. rwtm.id = "1";
  115. rwtm.type = RenWuType.Image;
  116. rwtm.url = Application.streamingAssetsPath + "/Demo1/温湿度.jpeg";
  117. rw.typeList.Add(rwtm);
  118. rwtm4.id = "4";
  119. rwtm4.type = RenWuType.Text;
  120. rwtm4.info = "通常要求机房长期工作环境温度: 0'C'4S'C; 短期工作环境温度: -5C~SSC";
  121. rw.typeList.Add(rwtm4);
  122. break;
  123. case 1:
  124. //任务路线 (空间定位时才有)
  125. rw.roadList = new List<Vector3>();
  126. rw.roadList.Add(new Vector3(-4.2f + 0.5f, 0, 0.92f));
  127. rw.info = "请检查机房湿度是否正常";
  128. //单个任务素材
  129. rw.typeList = new List<RenWuTypeModel>();
  130. rwtm4.id = "4";
  131. rwtm4.type = RenWuType.Text;
  132. rwtm4.info = "通常机房的长期工作环境相对漫庭应在5%RH~85%RH之间,不结露;短期工作环境相对湿度应在0%RH~95%RH之间,不结露.";
  133. rw.typeList.Add(rwtm4);
  134. rwtm.id = "1";
  135. rwtm.type = RenWuType.Image;
  136. rwtm.url = Application.streamingAssetsPath + "/Demo1/温湿度.jpeg";
  137. rw.typeList.Add(rwtm);
  138. break;
  139. case 2:
  140. //任务路线 (空间定位时才有)
  141. rw.roadList = new List<Vector3>();
  142. rw.roadList.Add(new Vector3(-4.2f + 0.5f, 0, -1.6f));
  143. rw.info = "请检查服务器电源灯是否正常";
  144. //单个任务素材
  145. rw.typeList = new List<RenWuTypeModel>();
  146. rwtm.id = "1";
  147. rwtm.type = RenWuType.Image;
  148. rwtm.url = Application.streamingAssetsPath + "/Demo1/服务器指示灯.png";
  149. rw.typeList.Add(rwtm);
  150. rwtm3.id = "3";
  151. rwtm3.type = RenWuType.Model;
  152. rwtm3.url = Application.streamingAssetsPath + "/Demo1/dell poweredge.fbx";
  153. rw.typeList.Add(rwtm3);
  154. break;
  155. case 3:
  156. //任务路线 (空间定位时才有)
  157. rw.roadList = new List<Vector3>();
  158. rw.roadList.Add(new Vector3(-4.2f + 0.5f, 0, 0.52f));
  159. rw.roadList.Add(new Vector3(-1.78f, 0, 0.52f));
  160. rw.roadList.Add(new Vector3(-1.78f, 0, -1.6f));
  161. rw.info = "请检查服务器告警灯状态是否正常";
  162. //单个任务素材
  163. rw.typeList = new List<RenWuTypeModel>();
  164. rwtm3.id = "3";
  165. rwtm3.type = RenWuType.Model;
  166. rwtm3.url = Application.streamingAssetsPath + "/Demo1/dell poweredge.fbx";
  167. rw.typeList.Add(rwtm3);
  168. rwtm2.id = "2";
  169. rwtm2.type = RenWuType.Video;
  170. rwtm2.url = Application.streamingAssetsPath + "/Demo1/服务器告警灯2.mp4";
  171. rw.typeList.Add(rwtm2);
  172. break;
  173. case 4:
  174. //任务路线 (空间定位时才有)
  175. rw.roadList = new List<Vector3>();
  176. rw.roadList.Add(new Vector3(-1.78f, 0, 0.52f));
  177. rw.roadList.Add(new Vector3(-5.18f + 0.5f, 0, 0.52f));
  178. rw.info = "请检查服务器网线连接是否正常";
  179. //单个任务素材
  180. rw.typeList = new List<RenWuTypeModel>();
  181. rwtm2.id = "2";
  182. rwtm2.type = RenWuType.Video;
  183. rwtm2.url = Application.streamingAssetsPath + "/Demo1/网线.mp4";
  184. rw.typeList.Add(rwtm2);
  185. break;
  186. case 5:
  187. //任务路线 (空间定位时才有)
  188. rw.roadList = new List<Vector3>();
  189. rw.roadList.Add(new Vector3(-1.78f, 0, 0.52f));
  190. rw.info = "机房室内消防设施是否齐全";
  191. //单个任务素材
  192. rw.typeList = new List<RenWuTypeModel>();
  193. rwtm.id = "1";
  194. rwtm.type = RenWuType.Image;
  195. rwtm.url = Application.streamingAssetsPath + "/Demo1/机房消防设施巡检.jpeg";
  196. rw.typeList.Add(rwtm);
  197. break;
  198. case 6:
  199. //任务路线 (空间定位时才有)
  200. rw.roadList = new List<Vector3>();
  201. rw.roadList.Add(new Vector3(-4.2f + 0.5f, 0, 0.52f));
  202. rw.roadList.Add(new Vector3(-1.78f, 0, 0.52f));
  203. rw.roadList.Add(new Vector3(-1.78f, 0, -1f));
  204. rw.info = "机房室内消防设施摆放是否规范";
  205. //单个任务素材
  206. rw.typeList = new List<RenWuTypeModel>();
  207. rwtm.id = "1";
  208. rwtm.type = RenWuType.Image;
  209. rwtm.url = Application.streamingAssetsPath + "/Demo1/机房消防设施摆放.jpeg";
  210. rw.typeList.Add(rwtm);
  211. break;
  212. }
  213. //任务介绍
  214. //拍照按钮
  215. int randomInt = UnityEngine.Random.Range(0, 10);
  216. rw.isPaiZhao = randomInt > 5 ? true : false;
  217. //RTC按钮
  218. int randomInt2 = UnityEngine.Random.Range(0, 10);
  219. rw.isYuanCheng = randomInt2 > 5 ? true : false;
  220. itemlist.Add(rw);
  221. }
  222. return itemlist;
  223. }
  224. public Dictionary<string, List<XunJianListData>> areaList = new Dictionary<string, List<XunJianListData>>();
  225. public Dictionary<string, List<XunJianListData>> peopleList = new Dictionary<string, List<XunJianListData>>();
  226. List<Wall> getWallData()
  227. {
  228. List<Wall> listWall = new List<Wall>();
  229. for (int i = 0; i < 6; i++)
  230. {
  231. switch (i)
  232. {
  233. case 0:
  234. Wall wall = new Wall();
  235. wall.listPoint.Add(new Vector3(-5, 0, 0.25f));
  236. wall.listPoint.Add(new Vector3(5, 0, 0.25f));
  237. wall.listPoint.Add(new Vector3(5, 0, -0.25f));
  238. wall.listPoint.Add(new Vector3(-5, 0, -0.25f));
  239. listWall.Add(wall);
  240. break;
  241. case 1:
  242. Wall wall1 = new Wall();
  243. wall1.listPoint.Add(new Vector3(-5, 0, -4.75f));
  244. wall1.listPoint.Add(new Vector3(5, 0, -4.75f));
  245. wall1.listPoint.Add(new Vector3(5, 0, -5.25f));
  246. wall1.listPoint.Add(new Vector3(-5, 0, -5.25f));
  247. listWall.Add(wall1);
  248. break;
  249. case 2:
  250. Wall wall2 = new Wall();
  251. wall2.listPoint.Add(new Vector3(-5.25f, 0, 0));
  252. wall2.listPoint.Add(new Vector3(-4.75f, 0, 0));
  253. wall2.listPoint.Add(new Vector3(-4.75f, 0, -5));
  254. wall2.listPoint.Add(new Vector3(-5.25f, 0, -5));
  255. listWall.Add(wall2);
  256. break;
  257. case 3:
  258. Wall wall3 = new Wall();
  259. wall3.listPoint.Add(new Vector3(4.75f, 0, 0));
  260. wall3.listPoint.Add(new Vector3(5.25f, 0, 0));
  261. wall3.listPoint.Add(new Vector3(5.25f, 0, -5));
  262. wall3.listPoint.Add(new Vector3(4.75f, 0, -5));
  263. listWall.Add(wall3);
  264. break;
  265. case 4:
  266. Wall wall4 = new Wall();
  267. wall4.listPoint.Add(new Vector3(-2.75f, 0, -1f));
  268. wall4.listPoint.Add(new Vector3(-2.25f, 0, -1f));
  269. wall4.listPoint.Add(new Vector3(-2.25f, 0, -3f));
  270. wall4.listPoint.Add(new Vector3(-2.75f, 0, -3f));
  271. listWall.Add(wall4);
  272. break;
  273. case 5:
  274. Wall wall5 = new Wall();
  275. wall5.listPoint.Add(new Vector3(2.25f, 0, -2));
  276. wall5.listPoint.Add(new Vector3(2.75f, 0, -2));
  277. wall5.listPoint.Add(new Vector3(2.75f, 0, -4));
  278. wall5.listPoint.Add(new Vector3(2.25f, 0, -4));
  279. listWall.Add(wall5);
  280. break;
  281. default:
  282. break;
  283. }
  284. }
  285. return listWall;
  286. }
  287. IEnumerator testBack(Action<List<XunJianListData>> callback)
  288. {
  289. yield return WindowsManager.Instance.StartCoroutine(HttpTool.Instance.SendHttp(HttpEdustryAction.InspectionList, "", (string msg) =>
  290. {
  291. Debug.Log("DGJ ===>InspectionList " + msg);
  292. JObject jObject = JObject.Parse(msg);
  293. if (jObject["code"].ToString() == "200")
  294. {
  295. List<XunJianData> data = JsonConvert.DeserializeObject<List<XunJianData>>(jObject["data"]["list"].ToString());
  296. if(WindowsManager.Instance.isTest)
  297. {
  298. xjDataList.Add(testData3());
  299. xjDataList.Add(testData());
  300. xjDataList.Add(testData2());
  301. }
  302. xjDataList.AddRange(XunJianDataParetListData(data));
  303. peopleList = new Dictionary<string, List<XunJianListData>>();
  304. areaList = new Dictionary<string, List<XunJianListData>>();
  305. for (int i = 0; i < xjDataList.Count; i++)
  306. {
  307. if (areaList.ContainsKey(xjDataList[i].inarea))
  308. {
  309. areaList[xjDataList[i].inarea].Add(xjDataList[i]);
  310. }
  311. else
  312. {
  313. areaList.Add(xjDataList[i].inarea, new List<XunJianListData>());
  314. areaList[xjDataList[i].inarea].Add(xjDataList[i]);
  315. }
  316. if (peopleList.ContainsKey(xjDataList[i].people))
  317. {
  318. peopleList[xjDataList[i].people].Add(xjDataList[i]);
  319. }
  320. else
  321. {
  322. peopleList.Add(xjDataList[i].people, new List<XunJianListData>());
  323. peopleList[xjDataList[i].people].Add(xjDataList[i]);
  324. }
  325. }
  326. callback(xjDataList);
  327. }
  328. else
  329. {
  330. Debug.LogError("获取巡检列表失败 " + jObject["code"].ToString());
  331. xjDataList = new List<XunJianListData>();
  332. if (WindowsManager.Instance.isTest)
  333. {
  334. xjDataList.Add(testData3());
  335. xjDataList.Add(testData());
  336. xjDataList.Add(testData2());
  337. }
  338. callback(xjDataList);
  339. }
  340. }));
  341. }
  342. List<XunJianListData> XunJianDataParetListData(List<XunJianData> data)
  343. {
  344. List<XunJianListData> listData = new List<XunJianListData>();
  345. for (int i = 0; i < data.Count; i++)
  346. {
  347. XunJianListData xj = new XunJianListData();
  348. xj.id = data[i].id.ToString();
  349. xj.projectname = data[i].name;
  350. xj.inarea = data[i].regionName;
  351. xj.projectState = ((ProjectStatus)data[i].status).ToString();
  352. xj.projectType = ((ProjectType)data[i].type).ToString();
  353. xj.projectTime = data[i].inspectionTime.ToString();
  354. xj.updateState = data[i].status > 2 ? "已更新" : "新项目";
  355. xj.listWall = data[i].listWall;
  356. listData.Add(xj);
  357. }
  358. return listData;
  359. }
  360. public class XunJianListData
  361. {
  362. public int nowIndex = 0;
  363. public string id;
  364. public string projectname;
  365. public string inarea; // 所在区域
  366. public string updateState; // 这个参数目前本地自己判断
  367. public string projectState;
  368. public string projectType;
  369. public string projectTime;
  370. public List<RenWuItem> itemList;
  371. public RenWuModelType renwuModelType;
  372. public string url;
  373. public string people = "未知员工";
  374. public List<Wall> listWall;
  375. }
  376. public class XunJianData
  377. {
  378. public int id { get; set; }
  379. public string name { get; set; }
  380. public string regionId { get; set; }
  381. public string regionName { get; set; }
  382. public int type { get; set; }
  383. public int status { get; set; }
  384. public int inspectionTime { get; set; }
  385. public List<EmployeesData> listEmployees { get; set; }
  386. public List<Wall> listWall { get; set; }
  387. }
  388. public class EmployeesData
  389. {
  390. public int id { get; set; }
  391. public string name { get; set; }
  392. public string number { get; set; }
  393. }
  394. public void GotoXunJian(XunJianListData xjld)
  395. {
  396. chooseXunJian = xjld;
  397. WindowsManager.Instance.show(WindowConfig.windowType.XunJianStart);
  398. JinRuRenwu.Instance.initStart();
  399. }
  400. public void gotoNext()
  401. {
  402. if(chooseXunJian.itemList.Count-1 > chooseXunJian.nowIndex)
  403. {
  404. chooseXunJian.nowIndex++;
  405. if (JinRuRenwu.Instance != null)
  406. {
  407. JinRuRenwu.Instance.UpdateData();
  408. }
  409. if (RenWuListWindow.Instance != null)
  410. {
  411. RenWuListWindow.Instance.UpdateData();
  412. }
  413. if (CaoZuoLanManager.Instance)
  414. CaoZuoLanManager.Instance.nextInteractable(false);
  415. }
  416. else
  417. {
  418. List<string> backTip = new List<string>();
  419. JsonData data = new JsonData();
  420. data["type"] = "30001";
  421. backTip.Add("1");
  422. backTip.Add(data.ToJson());
  423. backTip.Add("3");
  424. WindowsManager.Instance.show(WindowConfig.windowType.Error, false, WindowsManager.Instance.getErrorData("提示", "已经是最后一步了!", Color.gray, "icon", backTip, false, "自动退出", 5,"","退出巡检","返回").ToJson());
  425. }
  426. }
  427. public void chooseItem(int i)
  428. {
  429. chooseXunJian.nowIndex = i;
  430. if (JinRuRenwu.Instance != null)
  431. {
  432. JinRuRenwu.Instance.UpdateData();
  433. }
  434. if (RenWuListWindow.Instance != null)
  435. {
  436. RenWuListWindow.Instance.UpdateData();
  437. }
  438. }
  439. public class RenWuItem
  440. {
  441. public string id;
  442. public int index;
  443. public bool isPaiZhao;
  444. public bool isYuanCheng;
  445. public string info;
  446. public List<RenWuTypeModel> typeList;
  447. public List<Vector3> roadList;
  448. public string imageUrl;
  449. public ImageFileSourceData imageData;
  450. public RenWuState state = RenWuState.None;
  451. }
  452. public class RenWuTypeModel
  453. {
  454. public RenWuType type;
  455. public string id;
  456. public string url;
  457. public string info;
  458. }
  459. public class Wall
  460. {
  461. public List<Vector3> listPoint { get; set; }
  462. public Wall()
  463. {
  464. listPoint = new List<Vector3>();
  465. }
  466. }
  467. public enum RenWuState
  468. {
  469. None = 100001, // 未处理
  470. Success = 100002, // 成功
  471. Fail = 100003, // 失败
  472. }
  473. public enum RenWuType
  474. {
  475. Text = 100001, // 文字
  476. Image = 100002, // 图片
  477. Video = 100003, // 视频
  478. Model = 100004, // 模型
  479. }
  480. public enum RenWuModelType
  481. {
  482. SaoTu = 100001, // 扫图
  483. DingWeiBan = 100002, // 定位板
  484. DianYun = 100003, // 点云
  485. None = 100004, // 无
  486. }
  487. public enum ProjectType
  488. {
  489. 常规 =1,
  490. 异常 = 2
  491. }
  492. public enum ProjectStatus
  493. {
  494. 未开始 = 1,
  495. 即将开始 =2,
  496. 已逾期 = 3,
  497. 进行中 = 4,
  498. 已完成=5
  499. }
  500. }