|
|
@@ -279,12 +279,24 @@ public class S8MonitoringService : ITransient
|
|
|
/// 口径:module_code IN (S1,S7) AND exception_type_code IN (ORDER_CHANGE / DELIVERY_DELAY / PENDING_SHIPMENT);
|
|
|
/// 时间字段 created_at;不排除 CLOSED;按日聚合,缺失日期补 0;days 限 1-30。
|
|
|
/// </summary>
|
|
|
- public async Task<AdoS8DeliveryTrendDto> GetDeliveryTrendAsync(long tenantId = 1, long factoryId = 1, int days = 7)
|
|
|
+ public async Task<AdoS8DeliveryTrendDto> GetDeliveryTrendAsync(long tenantId = 1, long factoryId = 1, int days = 7, string? period = null)
|
|
|
{
|
|
|
- days = Math.Clamp(days, 1, 30);
|
|
|
- var today = DateTime.Today;
|
|
|
- var from = today.AddDays(-(days - 1));
|
|
|
- var toExclusive = today.AddDays(1);
|
|
|
+ DateTime from, toExclusive;
|
|
|
+ int effectiveDays;
|
|
|
+ var (periodFrom, periodTo) = S8PeriodHelper.Resolve(period);
|
|
|
+ if (periodFrom.HasValue && periodTo.HasValue)
|
|
|
+ {
|
|
|
+ from = periodFrom.Value;
|
|
|
+ toExclusive = periodTo.Value;
|
|
|
+ effectiveDays = Math.Max(1, Math.Min(90, (int)(toExclusive - from).TotalDays));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ effectiveDays = Math.Clamp(days, 1, 30);
|
|
|
+ var today = DateTime.Today;
|
|
|
+ from = today.AddDays(-(effectiveDays - 1));
|
|
|
+ toExclusive = today.AddDays(1);
|
|
|
+ }
|
|
|
|
|
|
var deliveryModules = new[] { "S1", "S7" };
|
|
|
var deliveryTypes = new[] { "ORDER_CHANGE", "DELIVERY_DELAY", "PENDING_SHIPMENT" };
|
|
|
@@ -301,8 +313,8 @@ public class S8MonitoringService : ITransient
|
|
|
.GroupBy(r => r.CreatedAt.Date)
|
|
|
.ToDictionary(g => g.Key, g => g.ToList());
|
|
|
|
|
|
- var dayList = new List<AdoS8DeliveryTrendDayDto>(days);
|
|
|
- for (var i = 0; i < days; i++)
|
|
|
+ var dayList = new List<AdoS8DeliveryTrendDayDto>(effectiveDays);
|
|
|
+ for (var i = 0; i < effectiveDays; i++)
|
|
|
{
|
|
|
var d = from.AddDays(i);
|
|
|
var bucket = byDate.TryGetValue(d, out var list) ? list : new();
|
|
|
@@ -332,7 +344,7 @@ public class S8MonitoringService : ITransient
|
|
|
{
|
|
|
PeakValue = peak?.Total ?? 0,
|
|
|
PeakDate = (peak is null || peak.Total == 0) ? null : peak.RawDate,
|
|
|
- AvgValue = Math.Round(totalSum / (double)days, 2),
|
|
|
+ AvgValue = Math.Round(totalSum / (double)effectiveDays, 2),
|
|
|
TodayValue = todayDay.Total,
|
|
|
TodayChangeRate = changeRate,
|
|
|
};
|
|
|
@@ -345,12 +357,24 @@ public class S8MonitoringService : ITransient
|
|
|
/// 口径:module_code IN (S2,S6) AND exception_type_code IN (EQUIP_FAULT / MFG_MATERIAL_ABNORMAL / MFG_QUALITY_ABNORMAL);
|
|
|
/// 时间字段 created_at;不排除 CLOSED;按日聚合,缺失日期补 0;days 限 1-30。
|
|
|
/// </summary>
|
|
|
- public async Task<AdoS8ProductionTrendDto> GetProductionTrendAsync(long tenantId = 1, long factoryId = 1, int days = 7)
|
|
|
+ public async Task<AdoS8ProductionTrendDto> GetProductionTrendAsync(long tenantId = 1, long factoryId = 1, int days = 7, string? period = null)
|
|
|
{
|
|
|
- days = Math.Clamp(days, 1, 30);
|
|
|
- var today = DateTime.Today;
|
|
|
- var from = today.AddDays(-(days - 1));
|
|
|
- var toExclusive = today.AddDays(1);
|
|
|
+ DateTime from, toExclusive;
|
|
|
+ int effectiveDays;
|
|
|
+ var (periodFrom, periodTo) = S8PeriodHelper.Resolve(period);
|
|
|
+ if (periodFrom.HasValue && periodTo.HasValue)
|
|
|
+ {
|
|
|
+ from = periodFrom.Value;
|
|
|
+ toExclusive = periodTo.Value;
|
|
|
+ effectiveDays = Math.Max(1, Math.Min(90, (int)(toExclusive - from).TotalDays));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ effectiveDays = Math.Clamp(days, 1, 30);
|
|
|
+ var today = DateTime.Today;
|
|
|
+ from = today.AddDays(-(effectiveDays - 1));
|
|
|
+ toExclusive = today.AddDays(1);
|
|
|
+ }
|
|
|
|
|
|
var prodModules = new[] { "S2", "S6" };
|
|
|
var prodTypes = new[] { "EQUIP_FAULT", "MFG_MATERIAL_ABNORMAL", "MFG_QUALITY_ABNORMAL" };
|
|
|
@@ -365,8 +389,8 @@ public class S8MonitoringService : ITransient
|
|
|
|
|
|
var byDate = rows.GroupBy(r => r.CreatedAt.Date).ToDictionary(g => g.Key, g => g.ToList());
|
|
|
|
|
|
- var dayList = new List<AdoS8ProductionTrendDayDto>(days);
|
|
|
- for (var i = 0; i < days; i++)
|
|
|
+ var dayList = new List<AdoS8ProductionTrendDayDto>(effectiveDays);
|
|
|
+ for (var i = 0; i < effectiveDays; i++)
|
|
|
{
|
|
|
var d = from.AddDays(i);
|
|
|
var bucket = byDate.TryGetValue(d, out var list) ? list : new();
|
|
|
@@ -396,7 +420,7 @@ public class S8MonitoringService : ITransient
|
|
|
{
|
|
|
PeakValue = peak?.Total ?? 0,
|
|
|
PeakDate = (peak is null || peak.Total == 0) ? null : peak.RawDate,
|
|
|
- AvgValue = Math.Round(totalSum / (double)days, 2),
|
|
|
+ AvgValue = Math.Round(totalSum / (double)effectiveDays, 2),
|
|
|
TodayValue = todayDay.Total,
|
|
|
TodayChangeRate = changeRate,
|
|
|
};
|
|
|
@@ -410,12 +434,24 @@ public class S8MonitoringService : ITransient
|
|
|
/// / WAREHOUSE_RECEIPT_ABNORMAL / IQC_ISSUE / WH_PUTAWAY_ISSUE / WORK_ORDER_KITTING_ABNORMAL / WORK_ORDER_ISSUE_ABNORMAL);
|
|
|
/// 时间字段 created_at;不排除 CLOSED;按日聚合,缺失日期补 0;days 限 1-30。
|
|
|
/// </summary>
|
|
|
- public async Task<AdoS8SupplyTrendDto> GetSupplyTrendAsync(long tenantId = 1, long factoryId = 1, int days = 7)
|
|
|
+ public async Task<AdoS8SupplyTrendDto> GetSupplyTrendAsync(long tenantId = 1, long factoryId = 1, int days = 7, string? period = null)
|
|
|
{
|
|
|
- days = Math.Clamp(days, 1, 30);
|
|
|
- var today = DateTime.Today;
|
|
|
- var from = today.AddDays(-(days - 1));
|
|
|
- var toExclusive = today.AddDays(1);
|
|
|
+ DateTime from, toExclusive;
|
|
|
+ int effectiveDays;
|
|
|
+ var (periodFrom, periodTo) = S8PeriodHelper.Resolve(period);
|
|
|
+ if (periodFrom.HasValue && periodTo.HasValue)
|
|
|
+ {
|
|
|
+ from = periodFrom.Value;
|
|
|
+ toExclusive = periodTo.Value;
|
|
|
+ effectiveDays = Math.Max(1, Math.Min(90, (int)(toExclusive - from).TotalDays));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ effectiveDays = Math.Clamp(days, 1, 30);
|
|
|
+ var today = DateTime.Today;
|
|
|
+ from = today.AddDays(-(effectiveDays - 1));
|
|
|
+ toExclusive = today.AddDays(1);
|
|
|
+ }
|
|
|
|
|
|
var supplyModules = new[] { "S3", "S4", "S5" };
|
|
|
var supplyTypes = new[]
|
|
|
@@ -434,8 +470,8 @@ public class S8MonitoringService : ITransient
|
|
|
|
|
|
var byDate = rows.GroupBy(r => r.CreatedAt.Date).ToDictionary(g => g.Key, g => g.ToList());
|
|
|
|
|
|
- var dayList = new List<AdoS8SupplyTrendDayDto>(days);
|
|
|
- for (var i = 0; i < days; i++)
|
|
|
+ var dayList = new List<AdoS8SupplyTrendDayDto>(effectiveDays);
|
|
|
+ for (var i = 0; i < effectiveDays; i++)
|
|
|
{
|
|
|
var d = from.AddDays(i);
|
|
|
var bucket = byDate.TryGetValue(d, out var list) ? list : new();
|
|
|
@@ -473,7 +509,7 @@ public class S8MonitoringService : ITransient
|
|
|
{
|
|
|
PeakValue = peak?.Total ?? 0,
|
|
|
PeakDate = (peak is null || peak.Total == 0) ? null : peak.RawDate,
|
|
|
- AvgValue = Math.Round(totalSum / (double)days, 2),
|
|
|
+ AvgValue = Math.Round(totalSum / (double)effectiveDays, 2),
|
|
|
TodayValue = todayDay.Total,
|
|
|
TodayChangeRate = changeRate,
|
|
|
};
|
|
|
@@ -486,7 +522,7 @@ public class S8MonitoringService : ITransient
|
|
|
/// 单一时间窗口下 total / open / closed / avgProcessHours / closeRate 共用同一分母。
|
|
|
/// 公共过滤:tenant/factory + is_deleted=0 + module_code IN S1-S7 + exception_type_code IN domain 类型集 + created_at IN window。
|
|
|
/// </summary>
|
|
|
- public async Task<AdoS8DomainTypeMetricsDto> GetDomainTypeMetricsAsync(string domain, string window, long tenantId = 1, long factoryId = 1)
|
|
|
+ public async Task<AdoS8DomainTypeMetricsDto> GetDomainTypeMetricsAsync(string domain, string window, long tenantId = 1, long factoryId = 1, string? period = null)
|
|
|
{
|
|
|
var d = (domain ?? string.Empty).Trim().ToUpperInvariant();
|
|
|
var w = (window ?? string.Empty).Trim().ToUpperInvariant();
|
|
|
@@ -526,7 +562,13 @@ public class S8MonitoringService : ITransient
|
|
|
}
|
|
|
|
|
|
DateTime from, to;
|
|
|
- if (w == "LAST_7D")
|
|
|
+ var (periodFrom, periodTo) = S8PeriodHelper.Resolve(period);
|
|
|
+ if (periodFrom.HasValue && periodTo.HasValue)
|
|
|
+ {
|
|
|
+ from = periodFrom.Value;
|
|
|
+ to = periodTo.Value;
|
|
|
+ }
|
|
|
+ else if (w == "LAST_7D")
|
|
|
{
|
|
|
// 与 trend 接口保持一致:[today-6, today+1)
|
|
|
var today = DateTime.Today;
|