diff --git a/src/CncModels/Dto/Production/ProgramProductionListItem.cs b/src/CncModels/Dto/Production/ProgramProductionListItem.cs index b5c4fd4..59bc86b 100644 --- a/src/CncModels/Dto/Production/ProgramProductionListItem.cs +++ b/src/CncModels/Dto/Production/ProgramProductionListItem.cs @@ -22,5 +22,8 @@ namespace CncModels.Dto.Production /// 产量占比(百分比) public decimal Percentage { get; set; } + + /// 关联机床ID列表(逗号分隔,用于跨页面联动) + public string MachineIds { get; set; } } } diff --git a/src/CncModels/Dto/Production/WorkerProductionListItem.cs b/src/CncModels/Dto/Production/WorkerProductionListItem.cs index a0dc5e9..81bfb27 100644 --- a/src/CncModels/Dto/Production/WorkerProductionListItem.cs +++ b/src/CncModels/Dto/Production/WorkerProductionListItem.cs @@ -22,5 +22,11 @@ namespace CncModels.Dto.Production /// 产量占比(百分比) public decimal Percentage { get; set; } + + /// 关联机床ID列表(逗号分隔,用于跨页面联动) + public string MachineIds { get; set; } + + /// 关联程序名列表(逗号分隔,用于跨页面联动) + public string ProgramNames { get; set; } } } diff --git a/src/CncRepository/Impl/DailyProductionRepository.cs b/src/CncRepository/Impl/DailyProductionRepository.cs index 132728c..929c316 100644 --- a/src/CncRepository/Impl/DailyProductionRepository.cs +++ b/src/CncRepository/Impl/DailyProductionRepository.cs @@ -135,7 +135,7 @@ namespace CncRepository.Impl } } - public List GetMachineList(DateTime startDate, DateTime endDate, int? workshopId, int? machineId) + public List GetMachineList(DateTime startDate, DateTime endDate, int? workshopId, string machineIds) { using (var conn = CreateConnection()) { @@ -143,7 +143,15 @@ namespace CncRepository.Impl var parameters = new DynamicParameters(); parameters.Add("Start", startDate); parameters.Add("End", endDate); if (workshopId.HasValue) { sql += " AND m.workshop_id = @WorkshopId"; parameters.Add("WorkshopId", workshopId.Value); } - if (machineId.HasValue) { sql += " AND dp.machine_id = @MachineId"; parameters.Add("MachineId", machineId.Value); } + if (!string.IsNullOrWhiteSpace(machineIds)) + { + var ids = machineIds.Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList(); + if (ids.Count > 0) + { + sql += " AND dp.machine_id IN @MachineIds"; + parameters.Add("MachineIds", ids); + } + } sql += " AND (dp.end_total_count > dp.base_total_count) GROUP BY dp.machine_id, dp.program_name, m.name HAVING SUM(dp.end_total_count - dp.base_total_count) > 0 ORDER BY TotalQuantity DESC"; var items = conn.Query(sql, parameters).ToList(); for (int i = 0; i < items.Count; i++) { items[i].Rank = i + 1; items[i].DayStatus = items[i].DayStatus ?? ""; } @@ -169,7 +177,7 @@ namespace CncRepository.Impl { using (var conn = CreateConnection()) { - string sql = @"SELECT w.name AS WorkerName, COUNT(DISTINCT wm.machine_id) AS MachineCount, COUNT(DISTINCT dp.program_name) AS ProgramCount, COALESCE(SUM(dp.end_total_count - dp.base_total_count), 0) AS TotalQuantity FROM cnc_worker w JOIN cnc_worker_machine wm ON wm.worker_id = w.id LEFT JOIN cnc_daily_production dp ON dp.machine_id = wm.machine_id AND dp.production_date BETWEEN @Start AND @End AND dp.end_total_count > dp.base_total_count"; + string sql = @"SELECT w.name AS WorkerName, COUNT(DISTINCT wm.machine_id) AS MachineCount, COUNT(DISTINCT dp.program_name) AS ProgramCount, COALESCE(SUM(dp.end_total_count - dp.base_total_count), 0) AS TotalQuantity, GROUP_CONCAT(DISTINCT wm.machine_id) AS MachineIds, GROUP_CONCAT(DISTINCT dp.program_name) AS ProgramNames FROM cnc_worker w JOIN cnc_worker_machine wm ON wm.worker_id = w.id LEFT JOIN cnc_daily_production dp ON dp.machine_id = wm.machine_id AND dp.production_date BETWEEN @Start AND @End AND dp.end_total_count > dp.base_total_count"; var parameters = new DynamicParameters(); parameters.Add("Start", startDate); parameters.Add("End", endDate); if (workerId.HasValue) { sql += " AND w.id = @WorkerId"; parameters.Add("WorkerId", workerId.Value); } @@ -199,14 +207,22 @@ namespace CncRepository.Impl } } - public List GetProgramList(DateTime startDate, DateTime endDate, string programName) + public List GetProgramList(DateTime startDate, DateTime endDate, string programNames) { using (var conn = CreateConnection()) { - string sql = @"SELECT dp.program_name AS ProgramName, COUNT(DISTINCT dp.machine_id) AS MachineCount, SUM(dp.end_total_count - dp.base_total_count) AS TotalQuantity FROM cnc_daily_production dp LEFT JOIN cnc_machine m ON dp.machine_id = m.id WHERE dp.production_date BETWEEN @Start AND @End"; + string sql = @"SELECT dp.program_name AS ProgramName, GROUP_CONCAT(DISTINCT dp.machine_id) AS MachineIds, COUNT(DISTINCT dp.machine_id) AS MachineCount, SUM(dp.end_total_count - dp.base_total_count) AS TotalQuantity FROM cnc_daily_production dp LEFT JOIN cnc_machine m ON dp.machine_id = m.id WHERE dp.production_date BETWEEN @Start AND @End"; var parameters = new DynamicParameters(); parameters.Add("Start", startDate); parameters.Add("End", endDate); - if (!string.IsNullOrWhiteSpace(programName)) { sql += " AND dp.program_name = @ProgramName"; parameters.Add("ProgramName", programName); } + if (!string.IsNullOrWhiteSpace(programNames)) + { + var names = programNames.Replace(',', ',').Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList(); + if (names.Count > 0) + { + sql += " AND dp.program_name IN @ProgramNames"; + parameters.Add("ProgramNames", names); + } + } sql += " AND (dp.end_total_count > dp.base_total_count) GROUP BY dp.program_name HAVING SUM(dp.end_total_count - dp.base_total_count) > 0 ORDER BY TotalQuantity DESC"; var items = conn.Query(sql, parameters).ToList(); if (items.Count > 0) { int grandTotal = items.Sum(x => x.TotalQuantity); for (int i = 0; i < items.Count; i++) { items[i].Rank = i + 1; if (items[i].MachineCount > 0) items[i].AvgPerMachine = Math.Round((decimal)items[i].TotalQuantity / items[i].MachineCount, 1); if (grandTotal > 0) items[i].Percentage = Math.Round((decimal)items[i].TotalQuantity / grandTotal * 100, 1); } } diff --git a/src/CncRepository/Interface/IDailyProductionRepository.cs b/src/CncRepository/Interface/IDailyProductionRepository.cs index 1480d5c..97fbea2 100644 --- a/src/CncRepository/Interface/IDailyProductionRepository.cs +++ b/src/CncRepository/Interface/IDailyProductionRepository.cs @@ -20,10 +20,10 @@ namespace CncRepository.Interface List GetMachineRankByDateRange(DateTime startDate, DateTime endDate, int top); List GetWorkerRankByDateRange(DateTime startDate, DateTime endDate, int top); MachineProductionSummaryResponse GetMachineSummary(DateTime startDate, DateTime endDate, int? workshopId); - List GetMachineList(DateTime startDate, DateTime endDate, int? workshopId, int? machineId); + List GetMachineList(DateTime startDate, DateTime endDate, int? workshopId, string machineIds); WorkerProductionSummaryResponse GetWorkerSummary(DateTime startDate, DateTime endDate); List GetWorkerList(DateTime startDate, DateTime endDate, int? workerId); ProgramProductionSummaryResponse GetProgramSummary(DateTime startDate, DateTime endDate, int? workshopId); - List GetProgramList(DateTime startDate, DateTime endDate, string programName); + List GetProgramList(DateTime startDate, DateTime endDate, string programNames); } } diff --git a/src/CncService/Impl/ProductionService.cs b/src/CncService/Impl/ProductionService.cs index b1261e1..fa32f47 100644 --- a/src/CncService/Impl/ProductionService.cs +++ b/src/CncService/Impl/ProductionService.cs @@ -114,11 +114,11 @@ namespace CncService.Impl } /// - public List GetMachineList(DateTime? startDate, DateTime? endDate, int? workshopId, int? machineId) + public List GetMachineList(DateTime? startDate, DateTime? endDate, int? workshopId, string machineIds) { var s = startDate ?? DateTime.Today; var e = endDate ?? DateTime.Today; - return _dailyProductionRepository.GetMachineList(s, e, workshopId, machineId); + return _dailyProductionRepository.GetMachineList(s, e, workshopId, machineIds); } /// @@ -146,11 +146,11 @@ namespace CncService.Impl } /// - public List GetProgramList(DateTime? startDate, DateTime? endDate, string programName = null) + public List GetProgramList(DateTime? startDate, DateTime? endDate, string programNames = null) { var s = startDate ?? DateTime.Today; var e = endDate ?? DateTime.Today; - return _dailyProductionRepository.GetProgramList(s, e, programName); + return _dailyProductionRepository.GetProgramList(s, e, programNames); } } } diff --git a/src/CncService/Interface/IProductionService.cs b/src/CncService/Interface/IProductionService.cs index b61d85e..37c9249 100644 --- a/src/CncService/Interface/IProductionService.cs +++ b/src/CncService/Interface/IProductionService.cs @@ -31,7 +31,7 @@ namespace CncService.Interface MachineProductionSummaryResponse GetMachineSummary(DateTime? startDate, DateTime? endDate, int? workshopId); /// 获取设备产量明细列表(按日期范围) - List GetMachineList(DateTime? startDate, DateTime? endDate, int? workshopId, int? machineId); + List GetMachineList(DateTime? startDate, DateTime? endDate, int? workshopId, string machineIds); /// 获取员工产量汇总(按日期范围) WorkerProductionSummaryResponse GetWorkerSummary(DateTime? startDate, DateTime? endDate); @@ -43,6 +43,6 @@ namespace CncService.Interface ProgramProductionSummaryResponse GetProgramSummary(DateTime? startDate, DateTime? endDate, int? workshopId); /// 获取程序产量明细列表(按日期范围) - List GetProgramList(DateTime? startDate, DateTime? endDate, string programName); + List GetProgramList(DateTime? startDate, DateTime? endDate, string programNames); } } diff --git a/src/CncWebApi/Controllers/ProductionController.cs b/src/CncWebApi/Controllers/ProductionController.cs index 7577954..f67c49c 100644 --- a/src/CncWebApi/Controllers/ProductionController.cs +++ b/src/CncWebApi/Controllers/ProductionController.cs @@ -103,9 +103,9 @@ namespace CncWebApi.Controllers /// [HttpGet] [Route("machine/list")] - public IHttpActionResult GetMachineList(DateTime? startDate = null, DateTime? endDate = null, int? workshopId = null, int? machineId = null) + public IHttpActionResult GetMachineList(DateTime? startDate = null, DateTime? endDate = null, int? workshopId = null, string machineIds = null) { - var result = _productionService.GetMachineList(startDate, endDate, workshopId, machineId); + var result = _productionService.GetMachineList(startDate, endDate, workshopId, machineIds); return Ok(ApiResponse.Success(new { items = result })); } @@ -151,9 +151,9 @@ namespace CncWebApi.Controllers /// [HttpGet] [Route("program/list")] - public IHttpActionResult GetProgramList(DateTime? startDate = null, DateTime? endDate = null, string programName = null) + public IHttpActionResult GetProgramList(DateTime? startDate = null, DateTime? endDate = null, string programNames = null) { - var result = _productionService.GetProgramList(startDate, endDate, programName); + var result = _productionService.GetProgramList(startDate, endDate, programNames); return Ok(ApiResponse.Success(new { items = result })); } }