71 lines
2.7 KiB
C#
71 lines
2.7 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.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 今日用煤量
|
|
/// </summary>
|
|
public class GetPresentCoalController : ApiController
|
|
{
|
|
DataServer.BLL.coal_equipment bll = new DataServer.BLL.coal_equipment();
|
|
DataServer.BLL.gw_data bll_gw = new DataServer.BLL.gw_data();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_plant_consumption();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var now=DateTime.Now;
|
|
var date = now.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 alist = new List<plant_consumptionData>();
|
|
var model = new plant_consumptionData();
|
|
model.DeviceName = "平阴水泥厂";
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
var slist = string.Join(",", list.Select(x => x.Reserve1));
|
|
var list1 = bll_gw.GetModelListsDate(slist, time).GroupBy(x=>x.XTagName).Select(g=>g.OrderByDescending(x=>x.XTimeStamp).FirstOrDefault()).ToList();
|
|
var list2 = bll_gw.GetModelListsDate(slist, time).Where(x => x.XTimeStamp == Convert.ToDateTime(date)).DistinctBy(x=>x.XTagName).GroupBy(x => x.XTimeStamp).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
foreach (var item in list1)
|
|
{
|
|
num1 += Convert.ToDecimal(item.XValue);
|
|
}
|
|
foreach (var item in list2)
|
|
{
|
|
num2 += Convert.ToDecimal(item.XValue);
|
|
}
|
|
model.EH = num1-num2;
|
|
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;
|
|
}
|
|
}
|
|
} |