115 lines
4.8 KiB
C#
115 lines
4.8 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 GetCarbonNeutralController : 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 now=DateTime.Now;
|
|
var alist = new List<emission_ratioData>();
|
|
var model = new emission_ratioData();
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
var date = now.ToString("yyyy-MM-dd 00:00:00");
|
|
string time;
|
|
if (Convert.ToDateTime(now).Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
foreach (var item in list)
|
|
{
|
|
var blist = new List<emission_ratio>();
|
|
var slist = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault();
|
|
var zlist = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "' and XTimeStamp='" + date + "'", time).FirstOrDefault();
|
|
if (slist == null)
|
|
{
|
|
num1 = num1;
|
|
}
|
|
else
|
|
{
|
|
num1 += Convert.ToDecimal(slist.XValue);
|
|
}
|
|
if (zlist == null)
|
|
{
|
|
num2 = num2;
|
|
}
|
|
else
|
|
{
|
|
num2 += Convert.ToDecimal(zlist.XValue);
|
|
}
|
|
|
|
var list1 = list.DistinctBy(x => x.CoalName).ToList();
|
|
//var list2 = list.DistinctBy(x=>x.CoalName).Where(x => x.CoalName==item.CoalName).ToList();
|
|
foreach (var aitem in list1)
|
|
{
|
|
decimal? num3 = 0;
|
|
decimal? num4 = 0;
|
|
var model1 = new emission_ratio();
|
|
model1.EmissionName = aitem.CoalName;
|
|
var list2 = list.Where(x => x.CoalName == aitem.CoalName).ToList();
|
|
foreach (var bitem in list2)
|
|
{
|
|
var slist1 = bll_gw.GetModelListDate(" XTagName like '%" + bitem.Reserve1 + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault();
|
|
var zlist1 = bll_gw.GetModelListDate(" XTagName like '%" + bitem.Reserve1 + "' and XTimeStamp='" + date + "'", time).FirstOrDefault();
|
|
if (slist1 == null)
|
|
{
|
|
num3 = num3;
|
|
}
|
|
else
|
|
{
|
|
num3 += Convert.ToDecimal(slist1.XValue);
|
|
}
|
|
if (zlist1 == null)
|
|
{
|
|
num4 = num4;
|
|
}
|
|
else
|
|
{
|
|
num4 += Convert.ToDecimal(zlist1.XValue);
|
|
}
|
|
}
|
|
model1.EmissionValue = Convert.ToDecimal(Math.Round(Convert.ToDouble((num3 - num4) * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12), 3));
|
|
blist.Add(model1);
|
|
}
|
|
model.list = blist;
|
|
}
|
|
model.Amount = Convert.ToDecimal(Math.Round(Convert.ToDouble((num1 - num2) * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12), 3));
|
|
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;
|
|
}
|
|
}
|
|
} |