产量报表后端:支持机床多选、程序名多值、跨页面联动MachineIds/ProgramNames字段

main
haoliang 1 month ago
parent 61ef4d71db
commit be8d8c323e

@ -22,5 +22,8 @@ namespace CncModels.Dto.Production
/// <summary>产量占比(百分比)</summary>
public decimal Percentage { get; set; }
/// <summary>关联机床ID列表逗号分隔用于跨页面联动</summary>
public string MachineIds { get; set; }
}
}

@ -22,5 +22,11 @@ namespace CncModels.Dto.Production
/// <summary>产量占比(百分比)</summary>
public decimal Percentage { get; set; }
/// <summary>关联机床ID列表逗号分隔用于跨页面联动</summary>
public string MachineIds { get; set; }
/// <summary>关联程序名列表(逗号分隔,用于跨页面联动)</summary>
public string ProgramNames { get; set; }
}
}

@ -135,7 +135,7 @@ namespace CncRepository.Impl
}
}
public List<MachineProductionListItem> GetMachineList(DateTime startDate, DateTime endDate, int? workshopId, int? machineId)
public List<MachineProductionListItem> 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<MachineProductionListItem>(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<ProgramProductionListItem> GetProgramList(DateTime startDate, DateTime endDate, string programName)
public List<ProgramProductionListItem> 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<ProgramProductionListItem>(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); } }

@ -20,10 +20,10 @@ namespace CncRepository.Interface
List<DailyProduction> GetMachineRankByDateRange(DateTime startDate, DateTime endDate, int top);
List<DailyProduction> GetWorkerRankByDateRange(DateTime startDate, DateTime endDate, int top);
MachineProductionSummaryResponse GetMachineSummary(DateTime startDate, DateTime endDate, int? workshopId);
List<MachineProductionListItem> GetMachineList(DateTime startDate, DateTime endDate, int? workshopId, int? machineId);
List<MachineProductionListItem> GetMachineList(DateTime startDate, DateTime endDate, int? workshopId, string machineIds);
WorkerProductionSummaryResponse GetWorkerSummary(DateTime startDate, DateTime endDate);
List<WorkerProductionListItem> GetWorkerList(DateTime startDate, DateTime endDate, int? workerId);
ProgramProductionSummaryResponse GetProgramSummary(DateTime startDate, DateTime endDate, int? workshopId);
List<ProgramProductionListItem> GetProgramList(DateTime startDate, DateTime endDate, string programName);
List<ProgramProductionListItem> GetProgramList(DateTime startDate, DateTime endDate, string programNames);
}
}

@ -114,11 +114,11 @@ namespace CncService.Impl
}
/// <inheritdoc/>
public List<MachineProductionListItem> GetMachineList(DateTime? startDate, DateTime? endDate, int? workshopId, int? machineId)
public List<MachineProductionListItem> 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);
}
/// <inheritdoc/>
@ -146,11 +146,11 @@ namespace CncService.Impl
}
/// <inheritdoc/>
public List<ProgramProductionListItem> GetProgramList(DateTime? startDate, DateTime? endDate, string programName = null)
public List<ProgramProductionListItem> 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);
}
}
}

@ -31,7 +31,7 @@ namespace CncService.Interface
MachineProductionSummaryResponse GetMachineSummary(DateTime? startDate, DateTime? endDate, int? workshopId);
/// <summary>获取设备产量明细列表(按日期范围)</summary>
List<MachineProductionListItem> GetMachineList(DateTime? startDate, DateTime? endDate, int? workshopId, int? machineId);
List<MachineProductionListItem> GetMachineList(DateTime? startDate, DateTime? endDate, int? workshopId, string machineIds);
/// <summary>获取员工产量汇总(按日期范围)</summary>
WorkerProductionSummaryResponse GetWorkerSummary(DateTime? startDate, DateTime? endDate);
@ -43,6 +43,6 @@ namespace CncService.Interface
ProgramProductionSummaryResponse GetProgramSummary(DateTime? startDate, DateTime? endDate, int? workshopId);
/// <summary>获取程序产量明细列表(按日期范围)</summary>
List<ProgramProductionListItem> GetProgramList(DateTime? startDate, DateTime? endDate, string programName);
List<ProgramProductionListItem> GetProgramList(DateTime? startDate, DateTime? endDate, string programNames);
}
}

@ -103,9 +103,9 @@ namespace CncWebApi.Controllers
/// </summary>
[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<object>.Success(new { items = result }));
}
@ -151,9 +151,9 @@ namespace CncWebApi.Controllers
/// </summary>
[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<object>.Success(new { items = result }));
}
}

Loading…
Cancel
Save