修复产量报表:下拉框字段映射、汇总卡片数值、表格运行时间/切削时间

main
haoliang 4 days ago
parent cf9f0575a8
commit de5e636fdc

@ -7,17 +7,17 @@
</el-form-item> </el-form-item>
<el-form-item label="车间"> <el-form-item label="车间">
<el-select v-model="filters.workshopId" placeholder="请选择车间" clearable style="min-width:220px"> <el-select v-model="filters.workshopId" placeholder="请选择车间" clearable style="min-width:220px">
<el-option v-for="w in options.workshops" :key="w.id" :label="w.name" :value="w.id" /> <el-option v-for="w in options.workshops" :key="w.value ?? w.id" :label="w.label ?? w.name" :value="w.value ?? w.id" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="机床"> <el-form-item label="机床">
<el-select v-model="filters.machineId" placeholder="请选择机床" clearable filterable style="min-width:220px"> <el-select v-model="filters.machineId" placeholder="请选择机床" clearable filterable style="min-width:220px">
<el-option v-for="m in options.machines" :key="m.id" :label="m.name" :value="m.id" /> <el-option v-for="m in options.machines" :key="m.value ?? m.id" :label="m.label ?? m.name" :value="m.value ?? m.id" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="工人"> <el-form-item label="工人">
<el-select v-model="filters.workerId" placeholder="请选择工人" clearable filterable style="min-width:220px"> <el-select v-model="filters.workerId" placeholder="请选择工人" clearable filterable style="min-width:220px">
<el-option v-for="wk in options.workers" :key="wk.id" :label="wk.name" :value="wk.id" /> <el-option v-for="wk in options.workers" :key="wk.value ?? wk.id" :label="wk.label ?? wk.name" :value="wk.value ?? wk.id" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="程序名"> <el-form-item label="程序名">
@ -119,7 +119,7 @@ const filters = reactive({
programName: '' 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) const historyVisible = ref(false)

@ -9,5 +9,10 @@ namespace CncModels.Dto.Production
public int MachineCount { get; set; } public int MachineCount { get; set; }
public int NormalCount { get; set; } public int NormalCount { get; set; }
public int OfflineCount { 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;
} }
} }

@ -43,9 +43,23 @@ namespace CncRepository.Impl
seg.program_name AS ProgramName, seg.program_name AS ProgramName,
SUM(CASE WHEN seg.is_settled=1 THEN seg.quantity 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, 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 FROM cnc_production_segment seg
LEFT JOIN cnc_machine m ON seg.machine_id = m.id 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 ( WHERE NOT EXISTS (
SELECT 1 FROM cnc_daily_production dp SELECT 1 FROM cnc_daily_production dp
WHERE dp.machine_id = seg.machine_id AND dp.production_date = seg.production_date WHERE dp.machine_id = seg.machine_id AND dp.production_date = seg.production_date

@ -91,5 +91,43 @@ namespace CncRepository.Impl
return conn.ExecuteScalar<decimal>(sql, new { Start = startDate, End = endDate }); return conn.ExecuteScalar<decimal>(sql, new { Start = startDate, End = endDate });
} }
} }
/// <summary>
/// 获取有产量记录的机床数量
/// </summary>
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<int>(sql, new { Date = date, WorkshopId = workshopId.Value });
}
return conn.ExecuteScalar<int>(sql, new { Date = date });
}
}
/// <summary>
/// 获取今日切削总时间(小时),取每台机床最新-最早的cutting_time差值之和
/// </summary>
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<decimal>(sql, new { Date = date });
}
}
} }
} }

@ -16,5 +16,7 @@ namespace CncRepository.Interface
bool CloseSegment(long id, decimal? endPartCount, decimal? quantity, string closeReason, DateTime endTime); bool CloseSegment(long id, decimal? endPartCount, decimal? quantity, string closeReason, DateTime endTime);
bool SettleByDate(DateTime date); bool SettleByDate(DateTime date);
decimal GetTotalByDateRange(DateTime startDate, DateTime endDate, int? workshopId = null); decimal GetTotalByDateRange(DateTime startDate, DateTime endDate, int? workshopId = null);
int GetActiveMachineCount(DateTime date, int? workshopId = null);
decimal GetTotalCuttingTimeByDate(DateTime date);
} }
} }

@ -45,12 +45,15 @@ namespace CncService.Impl
{ {
total = _productionSegmentRepository.GetTotalByDateRange(targetDate, targetDate, workshopId); total = _productionSegmentRepository.GetTotalByDateRange(targetDate, targetDate, workshopId);
} }
int machineCount = _productionSegmentRepository.GetActiveMachineCount(targetDate, workshopId);
decimal cuttingTime = _productionSegmentRepository.GetTotalCuttingTimeByDate(targetDate);
return new DailySummaryResponse return new DailySummaryResponse
{ {
TotalQuantity = (int)total, TotalQuantity = (int)total,
MachineCount = 0, MachineCount = machineCount,
NormalCount = 0, NormalCount = 0,
OfflineCount = 0 OfflineCount = 0,
totalCuttingTime = cuttingTime
}; };
} }

Loading…
Cancel
Save