Преглед изворни кода

工程监控的设备趋势图

Void_F пре 2 недеља
родитељ
комит
23c4870fec

+ 5 - 0
Assets/Bitsplash/Modular Date Picker/TextMeshPro/Script/DatePickerDropDownTextMeshPro.cs

@@ -21,5 +21,10 @@ namespace Bitsplash.DatePicker
             
             GetDateString?.Invoke(text);
         }
+        public void SetLabelText(string text)
+        {
+            if (Label != null)
+                Label.text = text;
+        }
     }
 }

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
Assets/Fonts/Resources/msyh SDF.asset


+ 45 - 0
Assets/Prefabs/UI/Item/GongChengLieBiaoItem.prefab

@@ -252,6 +252,7 @@ GameObject:
   - component: {fileID: 8458676335335314587}
   - component: {fileID: 8251202584017028272}
   - component: {fileID: 56195425700809643}
+  - component: {fileID: 6183096527794626195}
   m_Layer: 5
   m_Name: GongChengLieBiaoItem
   m_TagString: Untagged
@@ -337,3 +338,47 @@ MonoBehaviour:
     name: 
     state: 0
     type: 0
+--- !u!114 &6183096527794626195
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 6844746409962870716}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Navigation:
+    m_Mode: 0
+    m_WrapAround: 0
+    m_SelectOnUp: {fileID: 0}
+    m_SelectOnDown: {fileID: 0}
+    m_SelectOnLeft: {fileID: 0}
+    m_SelectOnRight: {fileID: 0}
+  m_Transition: 1
+  m_Colors:
+    m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
+    m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
+    m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
+    m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
+    m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
+    m_ColorMultiplier: 1
+    m_FadeDuration: 0.1
+  m_SpriteState:
+    m_HighlightedSprite: {fileID: 0}
+    m_PressedSprite: {fileID: 0}
+    m_SelectedSprite: {fileID: 0}
+    m_DisabledSprite: {fileID: 0}
+  m_AnimationTriggers:
+    m_NormalTrigger: Normal
+    m_HighlightedTrigger: Highlighted
+    m_PressedTrigger: Pressed
+    m_SelectedTrigger: Selected
+    m_DisabledTrigger: Disabled
+  m_Interactable: 1
+  m_TargetGraphic: {fileID: 8251202584017028272}
+  m_OnClick:
+    m_PersistentCalls:
+      m_Calls: []

Разлика између датотеке није приказан због своје велике величине
+ 512 - 156
Assets/Prefabs/UI/XHYZT/GCJK.prefab


+ 18 - 6
Assets/Scripts/HttpHelper.cs

@@ -984,7 +984,9 @@ public class HttpHelper : MonoBehaviour
                         targetName = "BY_ShuiWei_Up",
                         value = float.Parse(tempData.data[0].avgS1),
                         type = shuiWeiType.BuYuanShuiWei,
-                        datas = tempData.data.ToArray()
+                        datas = tempData.data.ToArray(),
+                        sid = devicesInfo.dataSid.ToString(),
+                        gid = devicesInfo.dataGid.ToString()
                     });
                 }
             }
@@ -1020,7 +1022,9 @@ public class HttpHelper : MonoBehaviour
                         targetName = "BY_ShuiWei_Down",
                         value = float.Parse(tempData.data[0].avgS1),
                         type = shuiWeiType.BuYuanShuiWei,
-                        datas = tempData.data.ToArray()
+                        datas = tempData.data.ToArray(),
+                        sid = devicesInfo.dataSid.ToString(),
+                        gid = devicesInfo.dataGid.ToString()
                     });
                 }
             }
@@ -1231,7 +1235,9 @@ public class HttpHelper : MonoBehaviour
                     name = device.sensorName,
                     value = device.realtimeValue1,
                     type = shuiYaType.BuYuanShuiYa,
-                    targetName = $"BY_{device.sensorName}"
+                    targetName = $"BY_{device.sensorName}",
+                    gid = device.dataGid.ToString(),
+                    sid = device.dataSid.ToString()
                 });
             }
         }
@@ -1248,7 +1254,9 @@ public class HttpHelper : MonoBehaviour
                     name = device.sensorName,
                     value = device.realtimeValue1,
                     type = weiYiType.BuYuanWeiYi,
-                    targetName = $"BY_{device.sensorName}"
+                    targetName = $"BY_{device.sensorName}",
+                    gid = device.dataGid.ToString(),
+                    sid = device.dataSid.ToString()
                 });
             }
         }
@@ -1268,7 +1276,9 @@ public class HttpHelper : MonoBehaviour
                     name = device.sensorName,
                     value = device.realtimeValue1,
                     type = shuiYaType.TaoKouShuiYa,
-                    targetName = $"TK_{device.sensorName}"
+                    targetName = $"TK_{device.sensorName}",
+                    gid = device.dataGid.ToString(),
+                    sid = device.dataSid.ToString()
                 });
             }
         }
@@ -1285,7 +1295,9 @@ public class HttpHelper : MonoBehaviour
                     name = device.sensorName,
                     value = device.realtimeValue1,
                     type = weiYiType.TaoKouWeiYi,
-                    targetName = $"TK_{device.sensorName}"
+                    targetName = $"TK_{device.sensorName}",
+                    gid = device.dataGid.ToString(),
+                    sid = device.dataSid.ToString()
                 });
             }
         }

+ 3 - 0
Assets/Scripts/UI/Data/GongChengLieBiaoData.cs

@@ -7,6 +7,9 @@ public class GongChengLieBiaoData
    public string name;
    public GongChengState state;
    public GongChengType type;
+
+   public string gid;
+   public string sid;
 }
 /// <summary>
 /// 正常、运行 #15DCFC  养护#FFBC1D 告警#EF491C

+ 3 - 0
Assets/Scripts/UI/Data/ShuiWeiData.cs

@@ -29,4 +29,7 @@ public class ShuiWeiData
     public Transform targetTransform;
     public float value;
     public SingleDevicesRequestData[] datas;
+
+    public string sid;
+    public string gid;
 }

+ 3 - 0
Assets/Scripts/UI/Data/ShuiYaData.cs

@@ -17,4 +17,7 @@ public class ShuiYaData
     public shuiYaType type;
     public Transform targetTransform;
     public float value;
+    
+    public string sid;
+    public string gid;
 }

+ 3 - 0
Assets/Scripts/UI/Data/WeiYiData.cs

@@ -17,4 +17,7 @@ public class WeiYiData
     public weiYiType type;
     public Transform targetTransform;
     public float value;
+
+    public string sid;
+    public string gid;
 }

+ 18 - 0
Assets/Scripts/UI/Item/GongChengLieBiaoItem.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
@@ -11,11 +12,28 @@ public class GongChengLieBiaoItem : MonoBehaviour
     private Text _nameText;
     private Text _stateText;
 
+    private Button _button;
+
     public void Init()
     {
         _indexText = this.transform.Find("index").GetComponent<Text>();
         _nameText = this.transform.Find("type").GetComponent<Text>();
         _stateText = this.transform.Find("state").GetComponent<Text>();
+
+        _button = this.GetComponent<Button>();
+        _button.onClick.AddListener(ItemClick);
+    }
+
+    public void ItemClick()
+    {
+        switch (_currentData.type)
+        {
+            case GongChengType.shuiWei:
+            case GongChengType.shuiYa:
+            case GongChengType.weiYi:
+                GCJKLayer._Instance._DeviceTrendPanel.Show(_currentData.name,_currentData.type,_currentData.gid,_currentData.sid);
+                break;
+        }
     }
 
     public void SetData(GongChengLieBiaoData data)

+ 224 - 0
Assets/Scripts/UI/UIView/GCJK/DeviceTrendPanel.cs

@@ -0,0 +1,224 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Bitsplash.DatePicker;
+using Newtonsoft.Json;
+using UnityEngine;
+using UnityEngine.UI;
+using XCharts.Runtime;
+
+public class DeviceTrendPanel : MonoBehaviour
+{
+    public LineChart _LineChart;
+    public Text nameText;
+    public GameObject listItemOri;
+    public List<GameObject> listObj = new List<GameObject>();
+    public Transform listRoot;
+
+    public Button closeButton;
+    public Button resetButton;
+    public Button checkButton;
+
+
+    public DatePickerDropDownTextMeshPro DatePicker_Start;
+    public DatePickerDropDownTextMeshPro DatePicker_End;
+
+    public string startDateStr = "";
+    public string endDateStr = "";
+
+    public int currentType = 0; //0补元 1套口
+    public string _sid;
+    public string _gid;
+
+    private void Awake()
+    {
+        _LineChart = this.transform.Find("LineChart").GetComponent<LineChart>();
+        listRoot = this.transform.Find("ScrollView/Viewport/Content").transform;
+        closeButton = this.transform.Find("CloseButton").GetComponent<Button>();
+        nameText = this.transform.Find("nameText").GetComponent<Text>();
+
+        checkButton = this.transform.Find("CheckButton").GetComponent<Button>();
+        checkButton.onClick.AddListener(() => { GetData(); });
+        closeButton.onClick.AddListener(() => { Hide(); });
+    }
+
+    private void Start()
+    {
+        DatePicker_Start = this.transform.Find("DatePicker_Start").GetComponent<DatePickerDropDownTextMeshPro>();
+        DatePicker_End = this.transform.Find("DatePicker_End").GetComponent<DatePickerDropDownTextMeshPro>();
+        DatePicker_Start.GetDateString += (string dateStr) =>
+        {
+            startDateStr = dateStr;
+            CheckDate();
+        };
+        DatePicker_End.GetDateString += (string dateStr) =>
+        {
+            endDateStr = dateStr;
+            CheckDate();
+        };
+        
+        Hide();
+    }
+
+    public void CheckDate()
+    {
+        if (!startDateStr.Equals("") && !endDateStr.Equals(""))
+        {
+            var startD = DateTime.ParseExact(startDateStr, "yyyy-MM-dd", null);
+            var endD = DateTime.ParseExact(endDateStr, "yyyy-MM-dd", null);
+            var disD = endD - startD;
+            Debug.Log(disD.TotalDays);
+            if (disD.TotalDays > 183)
+            {
+                Debug.Log("时间间隔大于6个月");
+                checkButton.gameObject.SetActive(false);
+            }
+            else
+            {
+                checkButton.gameObject.SetActive(true);
+            }
+        }
+    }
+
+    public async Task GetData()
+    {
+        string getJsonStr =
+            await HttpHelper._Instance.GetDeviceTrend(currentType, _gid, _sid, startDateStr, endDateStr);
+        GetTrend(getJsonStr);
+    }
+
+    public async Task Show(string name, GongChengType type, string gid, string sid)
+    {
+        _gid = gid;
+        _sid = sid;
+        name = name.Replace(" ", "");
+        string typeText = "";
+        switch (type)
+        {
+            case GongChengType.shuiWei:
+                typeText = "水位";
+                break;
+            case GongChengType.shuiYa:
+                typeText = "水压";
+                break;
+            case GongChengType.weiYi:
+                typeText = "位移";
+                break;
+        }
+
+        XAxis tempXaxis = _LineChart.GetChartComponent<XAxis>();
+        tempXaxis.axisName.name = typeText;
+        nameText.text = $"{name} {typeText}趋势";
+        this.gameObject.SetActive(true);
+        string endTime = DateTime.Now.ToString("yyyy-MM-dd");
+        string startTime = DateTime.Now.AddMonths(-3).ToString("yyyy-MM-dd");
+
+        startDateStr = startTime;
+        endDateStr = endTime;
+        DatePicker_Start.SetLabelText(startTime);
+        DatePicker_End.SetLabelText(endTime);
+
+        string getJsonStr = await HttpHelper._Instance.GetDeviceTrend(currentType, gid, sid, startTime, endTime);
+        GetTrend(getJsonStr);
+    }
+
+    public void Hide()
+    {
+        this.gameObject.SetActive(false);
+    }
+
+    /// <summary>
+    /// 获取时间范围内的趋势图
+    /// </summary>
+    public void GetTrend(string jsonStr)
+    {
+        try
+        {
+            Debug.Log("GetTrend requestData:" + jsonStr);
+            DeviceTrendRequest requestData = JsonConvert.DeserializeObject<DeviceTrendRequest>(jsonStr);
+            XAxis tempXaxis = _LineChart.GetChartComponent<XAxis>();
+            tempXaxis.data.Clear();
+            for (int i = 0; i < requestData.data.Length; i++)
+            {
+                tempXaxis.AddData(requestData.data[i].timeGroup);
+            }
+
+            var tempSeries = _LineChart.series;
+            SerieData[] tempDatas = new SerieData[requestData.data.Length];
+            for (int i = 0; i < tempDatas.Length; i++)
+            {
+                tempDatas[i] = new SerieData();
+                tempDatas[i].data = new List<double>();
+                tempDatas[i].data.Add(i);
+                tempDatas[i].data.Add(float.Parse(requestData.data[i].r1));
+            }
+
+            tempSeries[0].data.Clear();
+            tempSeries[0].data.AddRange(tempDatas);
+            StartCoroutine(CreatList(requestData));
+        }
+        catch (Exception e)
+        {
+            Debug.LogError(e.ToString());
+            throw;
+        }
+    }
+
+    IEnumerator CreatList(DeviceTrendRequest deviceData)
+    {
+        var wait = new WaitForEndOfFrame();
+        if (listObj.Count > 0)
+        {
+            GameObject[] deleteObjs = listObj.ToArray();
+            for (int i = 0; i < deleteObjs.Length; i++)
+            {
+                Destroy(deleteObjs[i]);
+            }
+        }
+
+        listObj.Clear();
+        int creatCount = 0;
+        float lastWaterValue = 0;
+        for (int i = 0; i < deviceData.data.Length; i++)
+        {
+            GameObject tempObj = Instantiate(listItemOri, listRoot);
+            tempObj.transform.Find("id").GetComponent<Text>().text = $"{i + 1}";
+            tempObj.transform.Find("time").GetComponent<Text>().text = $"{deviceData.data[i].timeGroup}";
+            tempObj.transform.Find("value").GetComponent<Text>().text = $"{deviceData.data[i].r1}";
+            string dirStr = "-";
+            if (i == 0)
+            {
+                dirStr = "→";
+                lastWaterValue = float.Parse(deviceData.data[i].r1);
+            }
+            else
+            {
+                float currentWaterValue = float.Parse(deviceData.data[i].r1);
+                if (currentWaterValue > lastWaterValue)
+                {
+                    dirStr = "↑";
+                }
+                else if (currentWaterValue < lastWaterValue)
+                {
+                    dirStr = "↓";
+                }
+                else
+                {
+                    dirStr = "→";
+                }
+
+                lastWaterValue = currentWaterValue;
+            }
+
+            tempObj.transform.Find("trend").GetComponent<Text>().text = $"{dirStr}";
+            listObj.Add(tempObj);
+            creatCount++;
+            if (creatCount >= 10)
+            {
+                creatCount = 0;
+                yield return wait;
+            }
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/UI/UIView/GCJK/DeviceTrendPanel.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6d504d833826ac94ebbb830f13b071df
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 12 - 0
Assets/Scripts/UI/UIView/GCJK/GCJKLayer.cs

@@ -253,6 +253,9 @@ public class GCJKLayer : YZTRootLayer
     public Button buyuanBtn;
     public Button taokouBtn;
 
+
+    public DeviceTrendPanel _DeviceTrendPanel;
+
     private void Awake()
     {
         _Instance = this;
@@ -589,6 +592,7 @@ public class GCJKLayer : YZTRootLayer
 
         currentDataType = type;
 
+        _DeviceTrendPanel.currentType = currentDataType;
 
         //水位图标
         CreatShuiWeiIcon();
@@ -703,6 +707,8 @@ public class GCJKLayer : YZTRootLayer
             tempLieBiaoData.name = tempData.name;
             tempLieBiaoData.type = GongChengType.shuiWei;
             tempLieBiaoData.state = GongChengState.normal;
+            tempLieBiaoData.sid = tempData.sid;
+            tempLieBiaoData.gid = tempData.gid;
             datas.Add(tempLieBiaoData);
         }
 
@@ -713,6 +719,8 @@ public class GCJKLayer : YZTRootLayer
             tempLieBiaoData.name = tempData.name;
             tempLieBiaoData.type = GongChengType.shuiYa;
             tempLieBiaoData.state = GongChengState.normal;
+            tempLieBiaoData.sid = tempData.sid;
+            tempLieBiaoData.gid = tempData.gid;
             datas.Add(tempLieBiaoData);
         }
 
@@ -723,6 +731,8 @@ public class GCJKLayer : YZTRootLayer
             tempLieBiaoData.name = tempData.name;
             tempLieBiaoData.type = GongChengType.weiYi;
             tempLieBiaoData.state = GongChengState.normal;
+            tempLieBiaoData.sid = tempData.sid;
+            tempLieBiaoData.gid = tempData.gid;
             datas.Add(tempLieBiaoData);
         }
 
@@ -733,6 +743,8 @@ public class GCJKLayer : YZTRootLayer
             tempLieBiaoData.name = tempData.name;
             tempLieBiaoData.type = GongChengType.shiPin;
             tempLieBiaoData.state = tempData.status ? GongChengState.normal : GongChengState.warning;
+            tempLieBiaoData.sid = "";
+            tempLieBiaoData.gid = "";//监控没有这玩意
             datas.Add(tempLieBiaoData);
         }
 

Неке датотеке нису приказане због велике количине промена