104 lines
3.9 KiB
C#
104 lines
3.9 KiB
C#
using DataServer.api;
|
|
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 DongYingAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
///用能监测1-用气量
|
|
/// </summary>
|
|
public class GetGasConsumptionController : ApiController
|
|
{
|
|
public HttpResponseMessage Get(string date = "")
|
|
{
|
|
var res = new get_gas_consumption();
|
|
try
|
|
{
|
|
var data = new List<gas_consumptionData>();
|
|
if (date == "日")
|
|
{
|
|
var time_count = Convert.ToInt32(DateTime.Now.Hour);
|
|
for (int i = 0; i < time_count; i++)
|
|
{
|
|
// 只处理今年的数据
|
|
if (DateTime.Now.AddHours(-i).Day != DateTime.Now.Day)
|
|
{
|
|
continue;
|
|
}
|
|
var now = DateTime.Now;
|
|
var time = now.AddHours(-i).ToString("HH:00");
|
|
var model = new gas_consumptionData();
|
|
model.time = time;
|
|
model.GasValue =Math.Round( Convert.ToDecimal(4400.00/12/31/24),3);
|
|
if (model.GasValue == null)
|
|
{
|
|
model.GasValue = 0;
|
|
}
|
|
data.Add(model);
|
|
}
|
|
}
|
|
if (date == "月")
|
|
{
|
|
var time_count = Convert.ToInt32(DateTime.Now.Day);
|
|
for (int i = 0; i < time_count; i++)
|
|
{
|
|
// 只处理今年的数据
|
|
if (DateTime.Now.AddDays(-i).Month != DateTime.Now.Month)
|
|
{
|
|
continue;
|
|
}
|
|
var now = DateTime.Now;
|
|
var time = now.AddDays(-i).ToString("MM-dd");
|
|
var model = new gas_consumptionData();
|
|
model.time = time;
|
|
model.GasValue = 4400 / 12/31;
|
|
if (model.GasValue == null)
|
|
{
|
|
model.GasValue = 0;
|
|
}
|
|
data.Add(model);
|
|
}
|
|
}
|
|
if (date == "年")
|
|
{
|
|
var time_count = Convert.ToInt32(DateTime.Now.Month);
|
|
for (int i = 0; i < time_count; i++)
|
|
{
|
|
// 只处理今年的数据
|
|
if (DateTime.Now.AddMonths(-i).Year != DateTime.Now.Year)
|
|
{
|
|
continue;
|
|
}
|
|
var now = DateTime.Now;
|
|
var time = now.AddMonths(-i).ToString("MM月");
|
|
var model = new gas_consumptionData();
|
|
model.time = time;
|
|
model.GasValue = 4400 / 12 ;
|
|
if (model.GasValue == null)
|
|
{
|
|
model.GasValue = 0;
|
|
}
|
|
data.Add(model);
|
|
}
|
|
}
|
|
var adata=data.OrderBy(x=>x.time).ToList();
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = adata;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |