添加项目文件。
This commit is contained in:
180
HT.Cloud.Service/ChartsManage/RtchartsService.cs
Normal file
180
HT.Cloud.Service/ChartsManage/RtchartsService.cs
Normal file
@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using HT.Cloud.Code;
|
||||
using SqlSugar;
|
||||
using HT.Cloud.DataBase;
|
||||
using HT.Cloud.Domain.ChartsManage;
|
||||
using HT.Cloud.Domain.DevicesManage;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace HT.Cloud.Service.ChartsManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 创 建:cdl
|
||||
/// 日 期:2023-03-01 15:05
|
||||
/// 描 述:实时趋势服务类
|
||||
/// </summary>
|
||||
public class RtchartsService : BaseService<RtchartsEntity>, IDenpendency
|
||||
{
|
||||
public RtchartsService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<string> GetAllSubsystemTag()
|
||||
{
|
||||
List<SubsysytemNameList> subsystems = new List<SubsysytemNameList>();
|
||||
var grouped = _context.Queryable<MetaTagEntity>().ToList();
|
||||
List<string> list_name_two = grouped.Select(t => t.Subsystem).GroupBy(c => c).Select(c => c.First()).ToList();
|
||||
int i = 0;
|
||||
foreach (var Meta_Tag in list_name_two)
|
||||
{
|
||||
subsystems.Add(new SubsysytemNameList() { Lable = "a" + i, Value = Meta_Tag });
|
||||
i++;
|
||||
}
|
||||
return subsystems.ToJson();
|
||||
}
|
||||
|
||||
public async Task<string> GetSubsystemAllTag(string subsysytemName)
|
||||
{
|
||||
|
||||
var subsysname = subsysytemName;
|
||||
var response = _context.Queryable<MetaTagEntity>().Where(x => x.Subsystem == subsysname).Select(x => new { x.TagID, x.Description, x.Units }).ToList();
|
||||
var reList = new List<SubAllTagReturn>();
|
||||
foreach (var subsystem in response)
|
||||
{
|
||||
reList.Add(
|
||||
new SubAllTagReturn()
|
||||
{
|
||||
TagID = (short)subsystem.TagID,
|
||||
Description = subsystem.Description + $"({subsystem.Units})",
|
||||
Units = subsystem.Units
|
||||
}
|
||||
);
|
||||
}
|
||||
return reList.ToJson();
|
||||
}
|
||||
|
||||
public async Task<string> GetChartsTagValueInit(string[] charts_TagIDs)
|
||||
{
|
||||
var tagName_list = new List<string>();
|
||||
|
||||
var result_list = new List<List<ChartData>>();
|
||||
|
||||
|
||||
foreach (string tagIDTxt in charts_TagIDs)
|
||||
{
|
||||
var tagID = ushort.Parse(tagIDTxt);
|
||||
var TagName = _context.Queryable<MetaTagEntity>().Where(x => x.TagID == tagID).First().TagName;
|
||||
tagName_list.Add(TagName);
|
||||
result_list.Add(new List<ChartData>());
|
||||
}
|
||||
var remoteRtDataServer = repository.IQueryable().First().remotertdataserver;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var responseStr = RemoteHttpRequest.HttpGet(remoteRtDataServer);
|
||||
|
||||
JObject valueJson = JObject.Parse(responseStr);
|
||||
int forid = 0;
|
||||
foreach (string tagName in tagName_list)
|
||||
{
|
||||
var timestring = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
var srcvalue = valueJson[tagName].ToString();
|
||||
decimal value = 0.0M;
|
||||
if (srcvalue.Equals("False") || srcvalue.Equals("True"))
|
||||
{
|
||||
value = srcvalue.Equals("True") ? value = 1.0M : value = 0.0M;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = decimal.Parse(srcvalue);
|
||||
}
|
||||
result_list[forid].Add(new ChartData()
|
||||
{
|
||||
name = timestring,
|
||||
value = value
|
||||
});
|
||||
|
||||
forid++;
|
||||
}
|
||||
Thread.Sleep(980);
|
||||
}
|
||||
return result_list.ToJson();
|
||||
}
|
||||
|
||||
public async Task<string> GetChartsTagValue(string[] charts_TagIDs)
|
||||
{
|
||||
var tagName_list = new List<string>();
|
||||
|
||||
var result_list = new List<List<ChartData>>();
|
||||
|
||||
|
||||
foreach (string tagIDTxt in charts_TagIDs)
|
||||
{
|
||||
var tagID = ushort.Parse(tagIDTxt);
|
||||
var TagName = _context.Queryable<MetaTagEntity>().Where(x => x.TagID == tagID).First().TagName;
|
||||
tagName_list.Add(TagName);
|
||||
result_list.Add(new List<ChartData>());
|
||||
}
|
||||
|
||||
var remoteRtDataServer = repository.IQueryable().First().remotertdataserver;
|
||||
var responseStr = RemoteHttpRequest.HttpGet(remoteRtDataServer);
|
||||
|
||||
JObject valueJson = JObject.Parse(responseStr);
|
||||
int forid = 0;
|
||||
foreach (string tagName in tagName_list)
|
||||
{
|
||||
var timestring = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
var srcvalue = valueJson[tagName].ToString();
|
||||
decimal value = 0.0M;
|
||||
if (srcvalue.Equals("False") || srcvalue.Equals("True"))
|
||||
{
|
||||
value = srcvalue.Equals("True") ? value = 1.0M : value = 0.0M;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = decimal.Parse(srcvalue);
|
||||
}
|
||||
result_list[forid].Add(new ChartData()
|
||||
{
|
||||
name = timestring,
|
||||
value = value
|
||||
});
|
||||
|
||||
forid++;
|
||||
}
|
||||
|
||||
return result_list.ToJson();
|
||||
|
||||
}
|
||||
|
||||
public class SubsysytemNameList
|
||||
{
|
||||
public string Lable { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class SubAllTagReturn
|
||||
{
|
||||
//x.TagID, x.Description, x.Units
|
||||
public short TagID { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Units { get; set; }
|
||||
}
|
||||
|
||||
public class ChartData
|
||||
{
|
||||
public decimal value { get; set; }
|
||||
public String name { get; set; }
|
||||
}
|
||||
|
||||
public class HDATETIMEVALUE
|
||||
{
|
||||
public String HDATETIME { get; set; }
|
||||
public decimal VALUE { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user