# `Sp_saveReturn_sPpr` (procedure)

> 产量上报反写


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `longtext` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | IN | `iTag` | `int` |
| 5 | OUT | `sCode` | `int` |
| 6 | OUT | `sReturn` | `longtext` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_saveReturn_sPpr`'`._

## Narrative

**Business context:** 生产管理 → 产量上报 — back-write helper for 产量上报 (`MftProductionReportMaster`). When a production-output report is saved or cancelled, it folds the reported `dProcessQty` back onto the originating 工单工序 (`MftWorkOrderProcess`) and the upstream `MftProductionPlanSlave`, so the planner board's "已产" and the workorder's process-stage progress reflect the latest report.

**What it does:** Builds `t_data_temp` with `sSrcSlaveId` aggregates from the report slaves, then updates `MftProductionPlanSlave` and `MftWorkOrderProcess` (with an additional rollup `JOIN (SELECT … Sum(dProcessQty) …)` over `MftWorkOrderProcess` for cross-stage totals). `iTag=1` (before/delete) excludes the current report; `iTag=2` (after) includes it.

**Invocation:** Wrapped by `Sp_afterSave_sPpr` (iTag=2) and `Sp_beforeSave_sPpr` (iTag=1). 产量上报 (`sId 19211681019715476042694840`) binds `Sp_Check_sPpr`/`Sp_beforeSave_sPpr` on `gdsmodule`; `Sp_afterSave_sPpr` is reached via `Sp_Invalid_backwriting` on cancel. The OEE-side reporter `Sp_Check_SaveOeeReport` also calls this directly to apply the back-write when OEE data is committed. Install script: `xly-src/script/标版/30100101/Sp_afterSave_sPpr.sql`.
