上海虹口龙之梦项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

139 lines
4.9 KiB

using AillieoUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 人员定位面板
/// </summary>
public class PersonnelLocationPanel : UIView
{
public List<long> numbsrs;
public ScrollView alarmScrollView;
public EmployeeScrollView employeeScrollView;
public List<GameObject> locationCards = new List<GameObject>();
public List<EmployeeItem> items = new List<EmployeeItem>();
public Toggle showAll;
public Color chaiXieColor = Color.white;
public Color diDianColor = Color.white;
public Color sosColor = Color.white;
public Color xinlvColor = Color.white;
public Color jinruColor = Color.white;
public Color likaiColor = Color.white;
public Color biaoqianColor = Color.white;
public Color quyuchaoyuanColor = Color.white;
private string alarmUrl = "";
public Dictionary<int, Color> AlarmColor = new Dictionary<int, Color>();
public override void Awake()
{
base.Awake();
showAll.onValueChanged.AddListener(v => Main.Event.EmployeeItemActive(v));
LoadTags(Config.Tags);
AlarmColor.Add(1, chaiXieColor);
AlarmColor.Add(2, diDianColor);
AlarmColor.Add(3, sosColor);
AlarmColor.Add(4, xinlvColor);
AlarmColor.Add(5, jinruColor);
AlarmColor.Add(6, likaiColor);
AlarmColor.Add(10, biaoqianColor);
AlarmColor.Add(13, quyuchaoyuanColor);
alarmUrl = $"{Config.AlarmServer}/prod-api/dingweiRest/apiGetAlarmDatas";
}
private void Start()
{
InvokeRepeating("GetAlarmData", 0, Config.AlarmInterval);
InvokeRepeating("GetPersonnelData", 0f, 600f);
}
private void GetAlarmData()
{
HttpManager.Instance.Post<AlarmData>(alarmUrl, tempData =>
{
if (tempData.ErrorCode == 1)
{
if (tempData.List.Count > 0)
{
alarmScrollView.SetUpdateFunc((index, item) =>
{
var data = tempData.List[index];
item.gameObject.SetActive(true);
item.GetComponent<AlarmItem>().Set(data, AlarmColor);
item.GetComponent<AlarmItem>().alarml = data;
});
alarmScrollView.SetItemCountFunc(() => tempData.List.Count);
alarmScrollView.UpdateData(false);
}
}
else
alarmScrollView.ResetAllDelegates();
});
}
private void LoadTags(List<string> tags)
{
employeeScrollView.SetUpdateFunc<string>(tags, (index, item) =>
{
string info = tags[index];
item.name = info;
item.GetComponent<EmployeeItem>().targetNo = long.Parse(info);
item.transform.Find("CardNumber").GetComponent<Text>().text = info;
locationCards.Add(item.gameObject);
items.Add(item.GetComponent<EmployeeItem>());
item.transform.Find("Show").GetComponent<Toggle>().onValueChanged.AddListener(v => Main.Event.EmployeeActive(long.Parse(info), v));
item.transform.Find("Track").GetComponent<Toggle>().onValueChanged.AddListener(v => Main.LocationSimulator.GetTrackPlaybackData(v, long.Parse(info)));
});
}
private void GetPersonnelData()
{
numbsrs.Clear();
var url = $"{Config.LocationServer}/le/uwbofferdata/getPositionDataByMapId/{Config.MapId}";
HttpManager.Instance.Get<PositionData>(url, tempData =>
{
if (tempData.list.Count > 0)
{
foreach (var data in tempData.list)
{
DateTime timestampDate = DateTimeOffset.FromUnixTimeMilliseconds(data.createdTime).LocalDateTime;
DateTime currentDate = DateTime.Now;
TimeSpan timeDifference = currentDate - timestampDate;
if (timeDifference.TotalMinutes <= 10)
{
// 使用Any方法检查是否已经存在匹配的data.targetNo
if (!numbsrs.Any(d => d == data.targetNo))
{
numbsrs.Add(data.targetNo);
}
}
}
}
foreach (var card in locationCards)
{
var c = numbsrs.Find(a => a.ToString() == card.name);
if (c == 0)
{
card.transform.Find("State").GetComponent<Text>().text = "离线";
card.transform.Find("State").GetComponent<Text>().color = Color.red;
}
else
{
card.transform.Find("State").GetComponent<Text>().text = "在线";
card.transform.Find("State").GetComponent<Text>().color = Color.green;
}
}
});
}
}