97 lines
3.9 KiB
C#
97 lines
3.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.Reflection;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 各类排放占比
|
|
/// </summary>
|
|
public class GetEmissionRatioController : 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_emission_ratio();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var alist = new List<emission_ratioData>();
|
|
var blist = new List<emission_ratio>();
|
|
var model = new emission_ratioData();
|
|
var now=DateTime.Now;
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
var date = now.ToString("yyyy-MM-dd 00:00:00");
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
foreach (var item in list.DistinctBy(x=>x.CoalName))
|
|
{
|
|
decimal? num3 = 0;
|
|
decimal? num4 = 0;
|
|
var clist=list.Where(x=>x.CoalName==item.CoalName).ToList();
|
|
foreach (var aitem in clist)
|
|
{
|
|
var list1 = bll_gw.GetModelListDate(" XTagName like '%" + aitem.Reserve1 + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault();
|
|
if (list1 == null)
|
|
{
|
|
num1 = num1;
|
|
num3 = num3;
|
|
}
|
|
else
|
|
{
|
|
num1 += Convert.ToDecimal(list1.XValue);
|
|
num3 += Convert.ToDecimal(list1.XValue);
|
|
}
|
|
var list2 = bll_gw.GetModelListDate(" XTagName like '%" + aitem.Reserve1 + "' and XTimeStamp='" + date + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault();
|
|
if (list2 == null)
|
|
{
|
|
num2 = num2;
|
|
num4 = num4;
|
|
}
|
|
else
|
|
{
|
|
num2 += Convert.ToDecimal(list2.XValue);
|
|
num4 += Convert.ToDecimal(list2.XValue);
|
|
}
|
|
}
|
|
|
|
var bmodel = new emission_ratio();
|
|
bmodel.EmissionName = item.CoalName;
|
|
bmodel.EmissionValue= Convert.ToDecimal(Math.Round(Convert.ToDouble((num3 - num4) * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12), 3));
|
|
blist.Add(bmodel);
|
|
}
|
|
model.Amount =Convert.ToDecimal(Math.Round(Convert.ToDouble( (num1 - num2) * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12),3));
|
|
model.list = 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;
|
|
}
|
|
}
|
|
} |