111 lines
4.6 KiB
C#
111 lines
4.6 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 GetLoadClassificationController : ApiController
|
|
{
|
|
DataServer.BLL.adjustable_load bll = new DataServer.BLL.adjustable_load();
|
|
DataServer.BLL.gw_data bll_gw = new DataServer.BLL.gw_data();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_load_classification();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var blist = new List<load_classificationData>();
|
|
var alist=new List<load_classification>();
|
|
var list1=list.Where(x=>x.LoadLevel==1).ToList();
|
|
var model1 = new load_classification();
|
|
var now=DateTime.Now;
|
|
var sdate = now.ToString("yyyy-MM-dd 00:00:00");
|
|
var edate = now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
decimal? num1 = 0;
|
|
foreach (var item in list1)
|
|
{
|
|
model1.Name = "一级";
|
|
var alist1 = bll_gw.GetModelListDate(" XTagName like '%"+item.Reserve1+ "' and XTimeStamp >='"+sdate+ "' and XTimeStamp<'"+edate+"'", time).DistinctBy(x=>new { x.XTagName,x.XTimeStamp}).ToList();
|
|
foreach (var aitem in alist1)
|
|
{
|
|
num1 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
model1.Value =num1;
|
|
}
|
|
alist.Add(model1);
|
|
var list2 = list.Where(x => x.LoadLevel == 2).ToList();
|
|
var model2 = new load_classification();
|
|
decimal? num2 = 0;
|
|
foreach (var item in list2)
|
|
{
|
|
model2.Name = "二级";
|
|
var alist2 = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "' and XTimeStamp >='" + sdate + "' and XTimeStamp<'" + edate + "'", time).DistinctBy(x=>new { x.XTagName,x.XTimeStamp}).ToList();
|
|
foreach (var aitem in alist2)
|
|
{
|
|
num2 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
model2.Value =num2;
|
|
}
|
|
alist.Add(model2);
|
|
var list3 = list.Where(x => x.LoadLevel == 3).ToList();
|
|
var model3 = new load_classification();
|
|
decimal? num3 = 0;
|
|
foreach (var item in list3)
|
|
{
|
|
model3.Name = "三级";
|
|
var alist3 = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "' and XTimeStamp >='" + sdate + "' and XTimeStamp<'" + edate + "'", time).DistinctBy(x=>new { x.XTagName,x.XTimeStamp}).ToList();
|
|
foreach (var aitem in alist3)
|
|
{
|
|
num3 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
model3.Value=num3;
|
|
}
|
|
alist.Add(model3);
|
|
var model4 = new load_classificationData();
|
|
decimal? num4 = 0;
|
|
foreach (var item in list)
|
|
{
|
|
var alist4 = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "' and XTimeStamp >='" + sdate + "' and XTimeStamp<'" + edate + "'", time).DistinctBy(x=>new { x.XTagName,x.XTimeStamp}).ToList();
|
|
foreach (var aitem in alist4)
|
|
{
|
|
num4 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
model4.Amount =num4;
|
|
}
|
|
model4.data = alist;
|
|
blist.Add(model4);
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = blist;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |