From de5e636fdc0d8a053e1928bd0353337c15fa4ae1 Mon Sep 17 00:00:00 2001
From: haoliang <821644@qq.com>
Date: Sun, 3 May 2026 00:00:00 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=A7=E9=87=8F=E6=8A=A5?=
=?UTF-8?q?=E8=A1=A8=EF=BC=9A=E4=B8=8B=E6=8B=89=E6=A1=86=E5=AD=97=E6=AE=B5?=
=?UTF-8?q?=E6=98=A0=E5=B0=84=E3=80=81=E6=B1=87=E6=80=BB=E5=8D=A1=E7=89=87?=
=?UTF-8?q?=E6=95=B0=E5=80=BC=E3=80=81=E8=A1=A8=E6=A0=BC=E8=BF=90=E8=A1=8C?=
=?UTF-8?q?=E6=97=B6=E9=97=B4/=E5=88=87=E5=89=8A=E6=97=B6=E9=97=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/views/production/ProductionPage.vue | 8 ++--
.../Dto/Production/DailySummaryResponse.cs | 5 +++
.../Impl/DailyProductionRepository.cs | 16 +++++++-
.../Impl/ProductionSegmentRepository.cs | 38 +++++++++++++++++++
.../Interface/IProductionSegmentRepository.cs | 2 +
src/CncService/Impl/ProductionService.cs | 7 +++-
6 files changed, 69 insertions(+), 7 deletions(-)
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
};
}