Explorar o código

获取设备趋势数据接口

Void_F hai 2 semanas
pai
achega
a6efa8fd14

+ 1 - 1
Assets/Bitsplash/Modular Date Picker/Base/Script/DropDown/DatePickerDropDownBase.cs

@@ -104,7 +104,7 @@ namespace Bitsplash.DatePicker
             try
             {
                 if (d.HasValue)
-                    t = d.Value.ToString(labelDateFormat); // find the correct string to show for the selected date
+                    t = d.Value.ToString("labelDateFormat"); // find the correct string to show for the selected date
             }
             catch(Exception)
             {

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
Assets/Fonts/Resources/msyh SDF.asset


+ 12 - 0
Assets/Scripts/HttpGetData.cs

@@ -147,6 +147,18 @@ public class DevicesMessage
     public int DeviceID;
 }
 
+[Serializable]
+public class DeviceTrendRequest
+{
+    public DeviceTrendData[] data;
+}
+[Serializable]
+public class DeviceTrendData
+{
+    public string timeGroup;
+    public string r1;
+}
+
 [Serializable]
 public class ObsHttpRequestData
 {

+ 26 - 0
Assets/Scripts/HttpHelper.cs

@@ -1315,6 +1315,32 @@ public class HttpHelper : MonoBehaviour
 
         www.Dispose();
     }
+    
+    /// <summary>
+    /// 获取设备趋势数据
+    /// </summary>
+    /// <param name="type">0:补元 1:套口</param>
+    /// <param name="gid">=devicesID 套口都传一样=sid</param>
+    /// <param name="sid">=ChannelID 套口都传一样=sid</param>
+    /// <param name="beginTime">yyyy-MM-dd 最大183天</param>
+    /// <param name="endTime"></param>
+    /// <returns></returns>
+    public async Task<string> GetDeviceTrend(int type, string gid, string sid, string beginTime, string endTime)
+    {
+        string cmdUrl = ServerAddress.APIGetDeviceTrend;
+        cmdUrl += $"/{(type==0?"buyuan":"taokou")}/{gid}/{sid}?beginTime={beginTime}&endTime{endTime}";
+        UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
+        www.downloadHandler = new DownloadHandlerBuffer();
+        www.SetRequestHeader("Content-Type", "application/json");
+        await www.SendWebRequest();
+        if (www.result != UnityWebRequest.Result.Success)
+        {
+            Debug.LogWarning("获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
+        }
+        string result = www.downloadHandler.text;
+        www.Dispose();
+        return result;
+    }
 
     // /// <summary>
     // /// 获取补元硬件组数据

+ 5 - 0
Assets/Scripts/UI/Tools/ServerAddress.cs

@@ -152,5 +152,10 @@ public class ServerAddress
     /// 获取大屏的运维数据
     /// </summary>
     public static string APIGetInspectionStatistics = YZTServerAddress + "/open/data/inspectionStatistics";
+    
+    /// <summary>
+    /// 获取设备趋势数据
+    /// </summary>
+    public static string APIGetDeviceTrend = YZTServerAddress + "/open/sensor/trend2";
 
 }

+ 54 - 11
Assets/Scripts/UI/UIView/YZT/WaterTrendPanel.cs

@@ -3,6 +3,7 @@ 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;
@@ -23,6 +24,18 @@ public class WaterTrendPanel : MonoBehaviour
     public string startDateStr="";
     public string endDateStr="";
 
+
+
+    public void Init()
+    {
+        _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>();
+        closeButton.onClick.AddListener(() => { Hide(); });
+    }
+
+    
     private void Start()
     {
         DatePicker_Start = this.transform.Find("DatePicker_Start").GetComponent<DatePickerDropDownTextMeshPro>();
@@ -38,16 +51,6 @@ public class WaterTrendPanel : MonoBehaviour
             CheckDate();
         };
     }
-
-    public void Init()
-    {
-        _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>();
-        closeButton.onClick.AddListener(() => { Hide(); });
-    }
-
     public void CheckDate()
     {
         if (!startDateStr.Equals("") && !endDateStr.Equals(""))
@@ -56,12 +59,52 @@ public class WaterTrendPanel : MonoBehaviour
            var endD= DateTime.ParseExact(endDateStr,"yyyy-MM-dd",null);
            var disD = endD - startD;
            Debug.Log(disD.TotalDays);
-           if (disD.TotalDays > 180)
+           if (disD.TotalDays > 183)
            {
                Debug.Log("时间间隔大于6个月");
            }
         }
     }
+    /// <summary>
+    /// 获取时间范围内的趋势图
+    /// </summary>
+    /// <param name="type"></param>
+    /// <param name="gid"></param>
+    /// <param name="sid"></param>
+    /// <param name="startTime"></param>
+    /// <param name="endTime"></param>
+    public async Task GetTrend(int type,string gid,string sid,string startTime,string endTime)
+    {
+        string getJsonStr= await HttpHelper._Instance.GetDeviceTrend(type,gid,sid,startTime,endTime);
+        try
+        {
+            Debug.Log("GetTrend requestData:"+getJsonStr);
+            DeviceTrendRequest requestData = JsonConvert.DeserializeObject<DeviceTrendRequest>(getJsonStr);
+            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);
+            
+        }
+        catch (Exception e)
+        {
+            Debug.Log(e.ToString());
+            throw;
+        }
+    }
     
     public async Task Show(string stcd, string name)
     {

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio