# `Sp_Check_SaveOeeReport` (procedure)

> oee上报保存后校验


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sFormGuid` | `varchar(100)` |
| 2 | IN | `sGuid` | `varchar(100)` |
| 3 | IN | `sLoginId` | `varchar(100)` |
| 4 | IN | `sBrId` | `varchar(100)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | IN | `iFlag` | `int` |
| 7 | OUT | `sReturn` | `varchar(4000)` |
| 8 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 生产管理 → OEE / 产量上报 — post-save validator and OEE-metric back-fill for `mftproductionreportmaster/slave`. Guards against over-reporting (cumulative report qty per work-order line exceeds the planned `dProcessQty`) and re-derives adjust-time / produce-time / idle-time / employee-hour columns from `plc_machinedata` so the report row carries the OEE inputs the dashboards downstream expect.

**What it does:** With `iFlag=0` (initial save) builds a temp `p_Root_MftProductionReportSlave` keyed by `sSrcSlaveId`, sums prior reports against `mftproductionplanslave.dProcessQty`, and aborts the save when any process is over-reported. Then cursors the just-saved slave rows joined to `viw_mftproductionreport`, pulls last-report timestamps and `plc_machinedata` samples per `sMachineId/sSrcSlaveId` to compute `dAdjustableQty`, `dAdjustableHour`, `dHour`, `dOtherHour`, `dAllHour`, `dEmpHour`, `tStartDate/tEndDate`, and finally writes them back to `mftproductionreportslave` so OEE = (生产时间 / 全时间) etc. can be computed by the OEE dashboards.

**Invocation:** Called from `Sp_Calc_sPpr` (the 产量上报 audit handler), not bound as a gdsmodule hook directly. xly-src ships `script/标版/30100101/Sp_Check_SaveOeeReport.sql` as the install body. Sibling `Sp_Check_SaveOeeReportCheck` is the audit-time variant gated on `sId=sGuid` rather than the all-tenant pass; `Sp_Check_SaveOeeReportAAA` is a developer scratch copy (see its own page).
