168 lines
7.3 KiB
C#
168 lines
7.3 KiB
C#
using DataServer.api;
|
|
using Microsoft.Ajax.Utilities;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 破碎系统实时负荷
|
|
/// </summary>
|
|
public class GetBrokenLoadController : ApiController
|
|
{
|
|
DataServer.BLL.electrical_installation bll = new DataServer.BLL.electrical_installation();
|
|
DataServer.BLL.gw_data bll_gw=new DataServer.BLL.gw_data();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Get(string date = "")
|
|
{
|
|
var res = new get_one_load();
|
|
try
|
|
{
|
|
var list = bll.GetModelList(" EquipmentName like '%破碎%'");
|
|
var alist = new List<one_loadData>();
|
|
var now=DateTime.Now;
|
|
if (date == "日")
|
|
{
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
var model = new one_loadData();
|
|
model.time = DateTime.Now.AddDays(-i).ToString("dd号");
|
|
var sdate = now.AddDays(-i).ToString("yyyy-MM-dd 00:00:00");
|
|
var edate = now.AddDays(-i + 1).ToString("yyyy-MM-dd 00:00:00");
|
|
decimal? num = 0;
|
|
string stime;
|
|
if (Convert.ToDateTime(sdate).Month < 10)
|
|
{
|
|
stime = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
stime = now.ToString("yyyy_MM");
|
|
}
|
|
foreach (var aitem in list)
|
|
{
|
|
var blist = bll_gw.GetModelListDate(" XTagName like '%" + aitem.P + "' and XTimeStamp>='" + sdate + "' and XTimeStamp<'" + edate + "'",stime).DistinctBy(x => new { x.XTagName, x.XTimeStamp }).ToList();
|
|
foreach (var item in blist)
|
|
{
|
|
num += Convert.ToDecimal(item.XValue);
|
|
}
|
|
}
|
|
model.RealTimeLoad = num;
|
|
if (model.RealTimeLoad == null)
|
|
{
|
|
model.RealTimeLoad = 0;
|
|
}
|
|
alist.Add(model);
|
|
}
|
|
}
|
|
if (date == "月")
|
|
{
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
var model = new one_loadData();
|
|
model.time = DateTime.Now.AddMonths(-i).ToString("MM月");
|
|
var sdate = now.AddMonths(-i).ToString("yyyy-MM-01 00:00:00");
|
|
var edate = now.AddMonths(-i + 1).ToString("yyyy-MM-01 00:00:00");
|
|
decimal? num = 0;
|
|
string stime;
|
|
if (Convert.ToDateTime(sdate).Month < 10)
|
|
{
|
|
stime = Convert.ToDateTime(sdate).ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
stime = Convert.ToDateTime(sdate).ToString("yyyy_MM");
|
|
}
|
|
foreach (var aitem in list)
|
|
{
|
|
var blist = bll_gw.GetModelListDate(" XTagName like '%" + aitem.P + "' and XTimeStamp>='" + sdate + "' and XTimeStamp<'" + edate + "'",stime).DistinctBy(x => new { x.XTagName, x.XTimeStamp }).ToList();
|
|
foreach (var item in blist)
|
|
{
|
|
num += Convert.ToDecimal(item.XValue);
|
|
}
|
|
}
|
|
model.RealTimeLoad = num;
|
|
if (model.RealTimeLoad == null)
|
|
{
|
|
model.RealTimeLoad = 0;
|
|
}
|
|
alist.Add(model);
|
|
}
|
|
}
|
|
if (date == "年")
|
|
{
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
var sdate = now.AddYears(-i).ToString("yyyy-01-01 00:00:00");
|
|
var edate = now.AddYears(-i + 1).ToString("yyyy-01-01 00:00:00");
|
|
if(Convert.ToDateTime(sdate)>=Convert.ToDateTime("2024-01-01 00:00:00"))
|
|
{
|
|
var model = new one_loadData();
|
|
model.time = DateTime.Now.AddYears(-i).ToString("yyyy");
|
|
decimal? num = 0;
|
|
string stime;
|
|
if (Convert.ToDateTime(sdate).Month < 10)
|
|
{
|
|
stime = Convert.ToDateTime(sdate).ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
stime = Convert.ToDateTime(sdate).ToString("yyyy_MM");
|
|
}
|
|
var slists = string.Join(",", list.Select(x => x.P));
|
|
var blist = bll_gw.GetModelLists(slists).Where(x=>x.XTimeStamp>=Convert.ToDateTime(sdate)&&x.XTimeStamp<Convert.ToDateTime(edate)).DistinctBy(x=>new { x.XTagName,x.XTimeStamp}).ToList();
|
|
foreach (var item in blist)
|
|
{
|
|
num += Convert.ToDecimal(item.XValue);
|
|
}
|
|
model.RealTimeLoad = num;
|
|
if (model.RealTimeLoad == null)
|
|
{
|
|
model.RealTimeLoad = 0;
|
|
}
|
|
alist.Add(model);
|
|
}
|
|
else
|
|
{
|
|
var model = new one_loadData();
|
|
model.time = DateTime.Now.AddYears(-i).ToString("yyyy");
|
|
decimal? num = 0;
|
|
model.RealTimeLoad = num;
|
|
if (model.RealTimeLoad == null)
|
|
{
|
|
model.RealTimeLoad = 0;
|
|
}
|
|
alist.Add(model);
|
|
}
|
|
|
|
}
|
|
}
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = alist;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
res.code = 500;
|
|
res.msg = ex.Message;
|
|
}
|
|
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(res), Encoding.GetEncoding("UTF-8"), "application/json") };
|
|
return result;
|
|
}
|
|
}
|
|
} |