61 lines
2.2 KiB
C#
61 lines
2.2 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 GetUseCoalController : 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_use_coal();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var alist = new List<use_coalData>();
|
|
var model = new use_coalData();
|
|
var now=DateTime.Now;
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
var blist=list.DistinctBy(x=>x.CoalName).ToList();
|
|
model.CoalAmount = blist.Count;
|
|
var sdate = now.ToString("yyyy-MM-dd 00:00:00");
|
|
var edate = now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
|
|
var strings=string.Join(",", list.Select(x=>x.Reserve1));
|
|
var list1 = bll_gw.GetModelListsDate(strings, time).Where(x=>x.XTimeStamp>=Convert.ToDateTime(sdate)&&x.XTimeStamp<Convert.ToDateTime(edate)).GroupBy(x=>x.XTagName).Select(g=>g.OrderByDescending(x=>x.XTimeStamp).FirstOrDefault()).ToList();
|
|
model.CoalNumber = list1.Count();
|
|
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;
|
|
}
|
|
}
|
|
} |