75 lines
2.7 KiB
C#
75 lines
2.7 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.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 设备异常统计
|
|
/// </summary>
|
|
public class GetUnitExceptionController : ApiController
|
|
{
|
|
DataServer.BLL.electric_equipment bll = new DataServer.BLL.electric_equipment();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_unit_exception();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var alist=new List<unit_exceptionData>();
|
|
for(var i = 0; i < 6;i++)
|
|
{
|
|
var date=DateTime.Now.AddMonths(-i).ToString("yyyy-MM-dd");
|
|
var amodel=new unit_exceptionData();
|
|
amodel.UnitTime= date;
|
|
var alist1 = new List<unit_exception>();
|
|
var bmodel = new unit_exception();
|
|
foreach (var item in list.DistinctBy(x=>x.EquipmentName))
|
|
{
|
|
|
|
|
|
var blist = list.Where(x => x.EquipmentName == item.EquipmentName).ToList();
|
|
var clist1 = list.Where(x => x.EH > 0 && x.P > 0).ToList();
|
|
var clist2=list.Where(x=>(x.EH==0&&x.P>0)||(x.EH>0&&x.P== 0)).ToList();
|
|
var clist3=list.Where(x=>x.EH==0&&x.P== 0).ToList();
|
|
if (clist1.Count != 0)
|
|
{
|
|
bmodel.Normal=clist1.Count;
|
|
}
|
|
if(clist2.Count != 0)
|
|
{
|
|
bmodel.Early=clist2.Count;
|
|
}
|
|
if(clist3.Count!=0)
|
|
{
|
|
bmodel.Malfunction =clist3.Count;
|
|
}
|
|
|
|
}
|
|
alist1.Add(bmodel);
|
|
amodel.data = alist1;
|
|
alist.Add(amodel);
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |