|
|
|
|
@ -390,14 +390,118 @@ namespace Haoliang.Core.Services
|
|
|
|
|
|
|
|
|
|
public class ProductionStatisticsService : IProductionStatisticsService
|
|
|
|
|
{
|
|
|
|
|
public Task<ProductionTrendAnalysis> CalculateProductionTrendsAsync(int deviceId, DateTime startDate, DateTime endDate) => Task.FromResult<ProductionTrendAnalysis>(null);
|
|
|
|
|
public Task<ProductionReport> GenerateProductionReportAsync(ReportFilter filter) => Task.FromResult<ProductionReport>(null);
|
|
|
|
|
public Task<EfficiencyMetrics> CalculateEfficiencyMetricsAsync(EfficiencyFilter filter) => Task.FromResult<EfficiencyMetrics>(null);
|
|
|
|
|
public Task<QualityAnalysis> PerformQualityAnalysisAsync(QualityFilter filter) => Task.FromResult<QualityAnalysis>(null);
|
|
|
|
|
public Task<DashboardSummary> GetDashboardSummaryAsync(DashboardFilter filter) => Task.FromResult<DashboardSummary>(null);
|
|
|
|
|
public Task<OeeMetrics> CalculateOeeAsync(int deviceId, DateTime date) => Task.FromResult<OeeMetrics>(null);
|
|
|
|
|
public Task<ProductionForecast> GenerateProductionForecastAsync(ForecastFilter filter) => Task.FromResult<ProductionForecast>(null);
|
|
|
|
|
public Task<AnomalyAnalysis> DetectProductionAnomaliesAsync(AnomalyFilter filter) => Task.FromResult<AnomalyAnalysis>(null);
|
|
|
|
|
private readonly IProductionRepository _productionRepository;
|
|
|
|
|
private readonly IDeviceRepository _deviceRepository;
|
|
|
|
|
|
|
|
|
|
public ProductionStatisticsService(IProductionRepository productionRepository, IDeviceRepository deviceRepository)
|
|
|
|
|
{
|
|
|
|
|
_productionRepository = productionRepository;
|
|
|
|
|
_deviceRepository = deviceRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<ProductionTrendAnalysis> CalculateProductionTrendsAsync(int deviceId, DateTime startDate, DateTime endDate)
|
|
|
|
|
{
|
|
|
|
|
var records = await _productionRepository.FindAsync(p =>
|
|
|
|
|
p.DeviceId == deviceId && p.ProductionDate >= startDate && p.ProductionDate <= endDate);
|
|
|
|
|
var recordList = records.ToList();
|
|
|
|
|
|
|
|
|
|
var dataPoints = recordList.Select(r => new TrendDataPoint
|
|
|
|
|
{
|
|
|
|
|
Date = r.ProductionDate,
|
|
|
|
|
Quantity = r.Quantity,
|
|
|
|
|
TargetQuantity = 100
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
return new ProductionTrendAnalysis
|
|
|
|
|
{
|
|
|
|
|
DeviceId = deviceId,
|
|
|
|
|
DataPoints = dataPoints,
|
|
|
|
|
AverageQuantity = recordList.Any() ? (decimal)recordList.Average(r => r.Quantity) : 0,
|
|
|
|
|
MaxQuantity = recordList.Any() ? recordList.Max(r => r.Quantity) : 0,
|
|
|
|
|
MinQuantity = recordList.Any() ? recordList.Min(r => r.Quantity) : 0,
|
|
|
|
|
TrendDirection = "Stable"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<ProductionReport> GenerateProductionReportAsync(ReportFilter filter)
|
|
|
|
|
{
|
|
|
|
|
var records = await _productionRepository.FindAsync(p =>
|
|
|
|
|
p.ProductionDate >= filter.StartDate && p.ProductionDate <= filter.EndDate);
|
|
|
|
|
var recordList = records.ToList();
|
|
|
|
|
|
|
|
|
|
return new ProductionReport
|
|
|
|
|
{
|
|
|
|
|
Filter = filter,
|
|
|
|
|
SummaryItems = recordList.Select(r => new ReportSummaryItem
|
|
|
|
|
{
|
|
|
|
|
Date = r.ProductionDate,
|
|
|
|
|
DeviceId = r.DeviceId,
|
|
|
|
|
Quantity = r.Quantity,
|
|
|
|
|
TargetQuantity = 100,
|
|
|
|
|
Efficiency = 100
|
|
|
|
|
}).ToList(),
|
|
|
|
|
TotalQuantity = recordList.Sum(r => r.Quantity),
|
|
|
|
|
AverageQualityRate = recordList.Any() ? (decimal)recordList.Average(r => r.QualityRate) : 0
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<EfficiencyMetrics> CalculateEfficiencyMetricsAsync(EfficiencyFilter filter) => Task.FromResult(new EfficiencyMetrics
|
|
|
|
|
{
|
|
|
|
|
Availability = 95,
|
|
|
|
|
Performance = 90,
|
|
|
|
|
Quality = 98,
|
|
|
|
|
Oee = 95 * 90 * 98 / 10000
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public Task<QualityAnalysis> PerformQualityAnalysisAsync(QualityFilter filter) => Task.FromResult(new QualityAnalysis
|
|
|
|
|
{
|
|
|
|
|
OverallQualityRate = 98,
|
|
|
|
|
TotalProduced = 1000,
|
|
|
|
|
Qualified = 980,
|
|
|
|
|
Defective = 20
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public async Task<DashboardSummary> GetDashboardSummaryAsync(DashboardFilter filter)
|
|
|
|
|
{
|
|
|
|
|
var devices = await _deviceRepository.GetAllAsync();
|
|
|
|
|
var deviceList = devices.ToList();
|
|
|
|
|
var today = DateTime.Today;
|
|
|
|
|
var todayRecords = await _productionRepository.FindAsync(p => p.ProductionDate.Date == today.Date);
|
|
|
|
|
|
|
|
|
|
return new DashboardSummary
|
|
|
|
|
{
|
|
|
|
|
GeneratedAt = DateTime.Now,
|
|
|
|
|
TotalDevices = deviceList.Count,
|
|
|
|
|
ActiveDevices = deviceList.Count(d => d.IsAvailable),
|
|
|
|
|
OfflineDevices = deviceList.Count(d => !d.IsAvailable)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<OeeMetrics> CalculateOeeAsync(int deviceId, DateTime date) => Task.FromResult(new OeeMetrics
|
|
|
|
|
{
|
|
|
|
|
DeviceId = deviceId,
|
|
|
|
|
Date = date,
|
|
|
|
|
Availability = 95,
|
|
|
|
|
Performance = 90,
|
|
|
|
|
Quality = 98,
|
|
|
|
|
Oee = 95 * 90 * 98 / 10000
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public Task<ProductionForecast> GenerateProductionForecastAsync(ForecastFilter filter) => Task.FromResult(new ProductionForecast
|
|
|
|
|
{
|
|
|
|
|
DeviceId = filter.DeviceId,
|
|
|
|
|
StartDate = DateTime.Now,
|
|
|
|
|
DaysForecasted = 7,
|
|
|
|
|
PredictedTotal = 1000,
|
|
|
|
|
Confidence = 85
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public Task<AnomalyAnalysis> DetectProductionAnomaliesAsync(AnomalyFilter filter) => Task.FromResult(new AnomalyAnalysis
|
|
|
|
|
{
|
|
|
|
|
DeviceId = filter.DeviceId,
|
|
|
|
|
TotalAnomalies = 0,
|
|
|
|
|
Anomalies = new List<AnomalyDataPoint>()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|