diff --git a/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs b/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs
index 72dda92..237ad00 100644
--- a/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs
+++ b/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceDowntimeRecordController.cs
@@ -6,6 +6,7 @@ using DOAN.Admin.WebApi.Filters;
using DOAN.Model.MES.dev;
using Infrastructure.Converter;
+using DOAN.Model.mes.echarts;
namespace DOAN.Admin.WebApi.Controllers
{
@@ -114,6 +115,32 @@ namespace DOAN.Admin.WebApi.Controllers
}
+ #region 设备停机时间BI
+
+
+ //TODO 每月停机时间柱状图
+
+ ///
+ /// 每月停机时间柱状图
+ ///
+ ///
+ public IActionResult GetDeviceDowntimeRecordMonthBarChart()
+ {
+
+ EchartsOptions response = _DeviceDowntimeRecordService.GetDeviceDowntimeRecordMonthBarChart();
+ //TODO 每月停机时间柱状图
+ return ToResponse(new ApiResult((int)ResultCode.SUCCESS, "每月停机时间柱状图"));
+ }
+
+
+ //TODO 停机原因TOP3
+
+
+
+
+ #endregion
+
+
}
diff --git a/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs b/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs
index 1bef797..e2c8c95 100644
--- a/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs
+++ b/DOAN.Service/MES/dev/DeviceDowntimeRecordService.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DOAN.Model;
+using DOAN.Model.mes.echarts;
using DOAN.Model.MES.dev;
using DOAN.Model.MES.dev.Dto;
using DOAN.Model.System;
@@ -126,5 +127,58 @@ namespace DOAN.Service.MES.dev
//return response;
return Update(model, true);
}
+
+
+
+ public EchartsOptions GetDeviceDowntimeRecordMonthBarChart()
+ {
+ var result = Context.Queryable()
+ .Where(x => x.Downdate != null && x.ConsumeTime != null)
+ .GroupBy(x => new
+ {
+ Year = x.Downdate.Value.Year,
+ Month = x.Downdate.Value.Month
+ })
+ .Select(x => new
+ {
+ Year = x.Downdate.Value.Year,
+ Month = x.Downdate.Value.Month,
+ TotalDowntime = SqlFunc.AggregateSum(x.ConsumeTime.Value)
+ })
+ .OrderByDescending(x => x.Year)
+ .OrderByDescending(x => x.Month)
+ .Take(24)
+ .MergeTable()
+ .OrderBy(x => x.Year)
+ .OrderBy(x => x.Month)
+ .Select(x => new EchartsSeriesData
+ {
+ Name = $"{x.Year}-{x.Month.ToString().PadLeft(2, '0')}",
+ Value= x.TotalDowntime
+ })
+ .ToList();
+
+
+ var echartsOptions = new EchartsOptions
+ {
+ Title = new EchartsTitle("设备停机时间统计", "按月统计停机时间"),
+ XAxis = new EchartsXAxis
+ {
+ Type = "category",
+ Data = result.Select(x=>x.Name).ToList(),
+ },
+ YAxis = new EchartsYAxis { Type = "value" },
+ Series = new List
+ {
+ new EchartsSeries
+ {
+ Name = "停机时间",
+ Type = "bar",
+ Data = result
+ }
+ }
+ };
+ return echartsOptions;
+ }
}
}
diff --git a/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs b/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs
index 2edb03e..c1975fb 100644
--- a/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs
+++ b/DOAN.Service/MES/dev/IService/IDeviceDowntimeRecordService.cs
@@ -3,6 +3,7 @@ using DOAN.Model.MES.dev;
using DOAN.Model.MES.dev.Dto;
using System.Collections.Generic;
using DOAN.Model;
+using DOAN.Model.mes.echarts;
namespace DOAN.Service.MES.dev.IService
{
@@ -21,5 +22,7 @@ namespace DOAN.Service.MES.dev.IService
int UpdateDeviceDowntimeRecord(DeviceDowntimeRecord parm);
+ EchartsOptions GetDeviceDowntimeRecordMonthBarChart();
+
}
}