diff --git a/frontend/src/views/production/ProductionPage.vue b/frontend/src/views/production/ProductionPage.vue index 6f9ac17..d05d52f 100644 --- a/frontend/src/views/production/ProductionPage.vue +++ b/frontend/src/views/production/ProductionPage.vue @@ -7,17 +7,17 @@ - + - + - + @@ -119,7 +119,7 @@ const filters = reactive({ programName: '' }) // 下拉项数据 -const options = reactive({ workshops: [] as Array<{ id: string | number; name: string }>, machines: [] as Array<{ id: string | number; name: string }>, workers: [] as Array<{ id: string | number; name: string }> }) + const options = reactive({ workshops: [] as Array<{ id: string | number; name: string; value?: string | number; label?: string }>, machines: [] as Array<{ id: string | number; name: string; value?: string | number; label?: string }>, workers: [] as Array<{ id: string | number; name: string; value?: string | number; label?: string }> }) // 导出/修正历史相关 const historyVisible = ref(false) diff --git a/src/CncModels/Dto/Production/DailySummaryResponse.cs b/src/CncModels/Dto/Production/DailySummaryResponse.cs index b12325a..fb14b87 100644 --- a/src/CncModels/Dto/Production/DailySummaryResponse.cs +++ b/src/CncModels/Dto/Production/DailySummaryResponse.cs @@ -9,5 +9,10 @@ namespace CncModels.Dto.Production public int MachineCount { get; set; } public int NormalCount { get; set; } public int OfflineCount { get; set; } + + // 前端兼容字段 + public int activeMachineCount => MachineCount; + public decimal totalCuttingTime { get; set; } + public decimal avgQuantityPerMachine => MachineCount > 0 ? (decimal)TotalQuantity / MachineCount : 0; } } diff --git a/src/CncRepository/Impl/DailyProductionRepository.cs b/src/CncRepository/Impl/DailyProductionRepository.cs index dc05a4d..37ba494 100644 --- a/src/CncRepository/Impl/DailyProductionRepository.cs +++ b/src/CncRepository/Impl/DailyProductionRepository.cs @@ -43,9 +43,23 @@ namespace CncRepository.Impl seg.program_name AS ProgramName, SUM(CASE WHEN seg.is_settled=1 THEN seg.quantity ELSE COALESCE(seg.end_part_count, seg.start_part_count) - seg.start_part_count END) AS TotalQuantity, - COUNT(*) AS SegmentCount, NULL AS TotalRunTime, NULL AS TotalCuttingTime, NULL AS TotalCycleTime + COUNT(*) AS SegmentCount, + cr_runtime.run_hours AS TotalRunTime, + cr_runtime.cut_hours AS TotalCuttingTime, + NULL AS TotalCycleTime FROM cnc_production_segment seg LEFT JOIN cnc_machine m ON seg.machine_id = m.id + LEFT JOIN ( + SELECT cr.machine_id, DATE(cr.collect_time) AS d, + COALESCE(ROUND(SUM(max_min.delta)/3600,1), 0) AS run_hours, + COALESCE(ROUND(SUM(max_min.delta)/3600,1), 0) AS cut_hours + FROM cnc_collect_record cr + JOIN ( + SELECT machine_id, DATE(collect_time) AS dd, MAX(cutting_time)-MIN(cutting_time) AS delta + FROM cnc_collect_record GROUP BY machine_id, DATE(collect_time) + ) max_min ON cr.machine_id = max_min.machine_id AND DATE(cr.collect_time) = max_min.dd + GROUP BY cr.machine_id, DATE(cr.collect_time) + ) cr_runtime ON cr_runtime.machine_id = seg.machine_id AND cr_runtime.d = seg.production_date WHERE NOT EXISTS ( SELECT 1 FROM cnc_daily_production dp WHERE dp.machine_id = seg.machine_id AND dp.production_date = seg.production_date diff --git a/src/CncRepository/Impl/ProductionSegmentRepository.cs b/src/CncRepository/Impl/ProductionSegmentRepository.cs index 2478feb..6206005 100644 --- a/src/CncRepository/Impl/ProductionSegmentRepository.cs +++ b/src/CncRepository/Impl/ProductionSegmentRepository.cs @@ -91,5 +91,43 @@ namespace CncRepository.Impl return conn.ExecuteScalar(sql, new { Start = startDate, End = endDate }); } } + + /// + /// 获取有产量记录的机床数量 + /// + public int GetActiveMachineCount(DateTime date, int? workshopId = null) + { + using (var conn = CreateConnection()) + { + string sql = @"SELECT COUNT(DISTINCT seg.machine_id) + FROM cnc_production_segment seg + LEFT JOIN cnc_machine m ON seg.machine_id = m.id + WHERE seg.production_date = @Date"; + if (workshopId.HasValue) + { + sql += " AND m.workshop_id = @WorkshopId"; + return conn.ExecuteScalar(sql, new { Date = date, WorkshopId = workshopId.Value }); + } + return conn.ExecuteScalar(sql, new { Date = date }); + } + } + + /// + /// 获取今日切削总时间(小时),取每台机床最新-最早的cutting_time差值之和 + /// + public decimal GetTotalCuttingTimeByDate(DateTime date) + { + using (var conn = CreateConnection()) + { + string sql = @"SELECT COALESCE(ROUND(SUM(today_delta)/3600, 1), 0) + FROM ( + SELECT MAX(cr.cutting_time) - MIN(cr.cutting_time) AS today_delta + FROM cnc_collect_record cr + WHERE DATE(cr.collect_time) = @Date + GROUP BY cr.machine_id + ) t"; + return conn.ExecuteScalar(sql, new { Date = date }); + } + } } } diff --git a/src/CncRepository/Interface/IProductionSegmentRepository.cs b/src/CncRepository/Interface/IProductionSegmentRepository.cs index bad1949..040c3a4 100644 --- a/src/CncRepository/Interface/IProductionSegmentRepository.cs +++ b/src/CncRepository/Interface/IProductionSegmentRepository.cs @@ -16,5 +16,7 @@ namespace CncRepository.Interface bool CloseSegment(long id, decimal? endPartCount, decimal? quantity, string closeReason, DateTime endTime); bool SettleByDate(DateTime date); decimal GetTotalByDateRange(DateTime startDate, DateTime endDate, int? workshopId = null); + int GetActiveMachineCount(DateTime date, int? workshopId = null); + decimal GetTotalCuttingTimeByDate(DateTime date); } } diff --git a/src/CncService/Impl/ProductionService.cs b/src/CncService/Impl/ProductionService.cs index 7d36040..e6a8918 100644 --- a/src/CncService/Impl/ProductionService.cs +++ b/src/CncService/Impl/ProductionService.cs @@ -45,12 +45,15 @@ namespace CncService.Impl { total = _productionSegmentRepository.GetTotalByDateRange(targetDate, targetDate, workshopId); } + int machineCount = _productionSegmentRepository.GetActiveMachineCount(targetDate, workshopId); + decimal cuttingTime = _productionSegmentRepository.GetTotalCuttingTimeByDate(targetDate); return new DailySummaryResponse { TotalQuantity = (int)total, - MachineCount = 0, + MachineCount = machineCount, NormalCount = 0, - OfflineCount = 0 + OfflineCount = 0, + totalCuttingTime = cuttingTime }; }