147 lines
5.1 KiB
C#
147 lines
5.1 KiB
C#
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 Serenity.Services;
|
||
using iTextSharp.text;
|
||
using HT.Cloud.Domain.DevicesManage;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
namespace HT.Cloud.Service.ChartsManage
|
||
{
|
||
/// <summary>
|
||
/// 创 建:cdl
|
||
/// 日 期:2023-02-23 11:10
|
||
/// 描 述:历史趋势服务类
|
||
/// </summary>
|
||
public class HistoryChartsService : BaseService<HistoryChartsEntity>, IDenpendency
|
||
{
|
||
public HistoryChartsService(ISqlSugarClient context) : base(context)
|
||
{
|
||
}
|
||
|
||
public async Task<string> GetDriverGroupList()
|
||
{
|
||
List<GroupNameList> subsystems = new List<GroupNameList>();
|
||
var list_group = _context.Queryable<MetaGroupEntity>().ToList();
|
||
int i = 0;
|
||
foreach (var group in list_group)
|
||
{
|
||
subsystems.Add(new GroupNameList() { Lable = "a" + i, Value = group.GroupDescription });
|
||
i++;
|
||
}
|
||
return subsystems.ToJson();
|
||
}
|
||
|
||
public async Task<string> GetGroupSubsystemTag(string groupDescription)
|
||
{
|
||
List<SubsysytemNameList> subsystems = new List<SubsysytemNameList>();
|
||
var groupId = _context.Queryable<MetaGroupEntity>().Where(x => x.GroupDescription == groupDescription).First().GroupID;
|
||
var grouped = _context.Queryable<MetaTagEntity>().ToList().Where(x=>x.GroupID==groupId);
|
||
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> 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,string groupDescription)
|
||
{
|
||
|
||
var subsysname = subsysytemName;
|
||
var groupId = _context.Queryable<MetaGroupEntity>().Where(x => x.GroupDescription == groupDescription).First().GroupID;
|
||
var response = _context.Queryable<MetaTagEntity>().Where(x => x.Subsystem == subsysname&&x.GroupID == groupId).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> GetChartsTagValue(short tagid,string startdt, string enddt, int timeinterval)
|
||
{
|
||
SugarParameter[] sqlParameters =
|
||
{
|
||
new SugarParameter("@enddt",enddt),
|
||
new SugarParameter("@Htagid",tagid),
|
||
new SugarParameter("@startdt",startdt),
|
||
new SugarParameter("@timeinterval",timeinterval)
|
||
};
|
||
var dt = _context.Ado.UseStoredProcedure().GetDataTable("Query_Group_Tag", sqlParameters);
|
||
//*
|
||
//var ds = db.SqlQuery("Query_Report_Period", sqlParameters);///
|
||
|
||
var valuelist = DataTableConvertModel<HDATETIMEVALUE>.ConvertDataTableToList(dt);
|
||
var resultlist = new List<ChartData>();
|
||
foreach (var value in valuelist)
|
||
{
|
||
resultlist.Add(new ChartData()
|
||
{
|
||
name = value.HDATETIME,
|
||
value = value.VALUE
|
||
});
|
||
}
|
||
return resultlist.ToJson();
|
||
}
|
||
|
||
public class SubsysytemNameList
|
||
{
|
||
public string Lable { get; set; }
|
||
public string Value { get; set; }
|
||
}
|
||
private class GroupNameList
|
||
{
|
||
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; }
|
||
}
|
||
}
|
||
}
|