-- 1. 先修改字段精度（支持小数）
ALTER TABLE pro_workorder_entry 
MODIFY COLUMN report_quantity DECIMAL(10, 3) NULL DEFAULT NULL COMMENT '报工数量';

-- 2. 从 pro_report 表汇总报工数量，更新回 pro_workorder_entry
UPDATE pro_workorder_entry pwe
INNER JOIN (
    SELECT 
        work_order_entry_id,
        SUM(report_quantity) AS total_report_qty
    FROM pro_report
    WHERE work_order_entry_id IS NOT NULL
    GROUP BY work_order_entry_id
) pr ON pwe.id = pr.work_order_entry_id
SET pwe.report_quantity = pr.total_report_qty
WHERE pwe.type = 'report';