100 lines
3.7 KiB
C#
100 lines
3.7 KiB
C#
using DataServer.api;
|
|
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;
|
|
using System.Web.Http.Tracing;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 用煤设备监测
|
|
/// </summary>
|
|
public class GetCoalMonitoringController : 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_coal_monitoring();
|
|
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");
|
|
}
|
|
string stime;
|
|
if (Convert.ToDateTime(date).Month < 10)
|
|
{
|
|
stime = Convert.ToDateTime(date).ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
stime = Convert.ToDateTime(date).ToString("yyyy_MM");
|
|
}
|
|
var alist = new List<coal_monitoringData>();
|
|
var model = new coal_monitoringData();
|
|
model.Amount = list.Count;
|
|
var num = 0;
|
|
var blist = new List<coal_monitoring>();
|
|
foreach (var item in list)
|
|
{
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
var amodel=new coal_monitoring();
|
|
num++;
|
|
amodel.SerialNumber = num;
|
|
amodel.Name = item.CoalName;
|
|
var list1 = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "'", time).OrderByDescending(x => x.XTagName).FirstOrDefault();
|
|
if (list1 == null)
|
|
{
|
|
num1 = num1;
|
|
}
|
|
else
|
|
{
|
|
num1 += Convert.ToDecimal(list1.XValue);
|
|
}
|
|
var list2= bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "' and XTagName='"+date+"'", stime).OrderByDescending(x => x.XTagName).FirstOrDefault();
|
|
if(list2 == null)
|
|
{
|
|
num2 = num2;
|
|
}
|
|
else
|
|
{
|
|
num2 += Convert.ToDecimal(list2.XValue);
|
|
}
|
|
amodel.CoalConsumption = num1-num2;
|
|
amodel.CarbonEmission=Convert.ToDecimal(Math.Round(Convert.ToDouble( (num1-num2) *Convert.ToDecimal(25.909) *Convert.ToDecimal(0.02610) * 44 / 12),3));
|
|
amodel.UnitCalorific =Convert.ToDecimal(0.02610);
|
|
blist.Add(amodel);
|
|
model.data = blist;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |