JinanCementFactory/JinanCementFactoryAPI/Controllers/api/GetLoadManagementController.cs

69 lines
2.5 KiB
C#

using DataServer.api;
using Microsoft.Ajax.Utilities;
using Microsoft.SqlServer.Server;
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 GetLoadManagementController : ApiController
{
DataServer.BLL.adjustable_load bll = new DataServer.BLL.adjustable_load();
DataServer.BLL.gw_data bll_gw = new DataServer.BLL.gw_data();
// GET api/<controller>
public HttpResponseMessage Get()
{
var res = new get_load_management();
try
{
var list = bll.GetModelList("");
var alist = new List<load_managementData>();
var now=DateTime.Now;
var sdate = now.ToString("yyyy-MM-dd 00:00:00");
var edate = now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
string time;
if (now.Month < 10)
{
time = now.ToString("yyyy_M");
}
else
{
time = now.ToString("yyyy_MM");
}
var model =new load_managementData();
decimal? num1 = 0;
foreach (var item in list)
{
model.MonitoredLoad +=Convert.ToInt32(item.NumericalValue);
var list1 = bll_gw.GetModelListDate(" XTagName like '%"+item.Reserve1+ "' and XTimeStamp>='"+sdate+ "' and XTimeStamp<'"+edate+"'", time).DistinctBy(x=>new { x.XTagName, x.XTimeStamp }).ToList();
foreach (var aitem in list1)
{
num1 += Convert.ToDecimal(aitem.XValue);
}
model.RealTimeLoad =num1;
}
model.Amount =Convert.ToDecimal(model.MonitoredLoad) + model.RealTimeLoad;
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;
}
}
}