155 lines
6.9 KiB
C#
155 lines
6.9 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 GetMaterialLoadController : 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");
|
|
string stime;
|
|
if(Convert.ToDateTime(sdate).Month < 10)
|
|
{
|
|
stime = Convert.ToDateTime(sdate).ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
stime = Convert.ToDateTime(sdate).ToString("yyyy_MM");
|
|
}
|
|
decimal? num = 0;
|
|
var slist=string.Join(",", list.Select(x=>x.P));
|
|
var blist = bll_gw.GetModelListsDate(slist, stime).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);
|
|
}
|
|
}
|
|
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");
|
|
}
|
|
var slist = string.Join(",", list.Select(x => x.P));
|
|
var blist = bll_gw.GetModelListsDate(slist, stime).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);
|
|
}
|
|
}
|
|
if (date == "年")
|
|
{
|
|
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 slist = string.Join(",", list.Select(x => x.P));
|
|
var blist = bll_gw.GetModelLists(slist).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;
|
|
}
|
|
}
|
|
} |