# `Sp_productionMainPlan_BtnEventResumefirstOrder` (procedure)

> 主计划：自动排序工具, 恢复首次排序


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `varchar(10000)` |
| 2 | IN | `sMakePerson` | `varchar(100)` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |
| 5 | OUT | `sReturn` | `varchar(1000)` |
| 6 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 生产管理 / 主计划 → 自动排序工具 / 恢复首次排序 — auto-sort tool's "restore the very first sort order" button. Reverts `iOrder` on every active plan row to what it was when this user took their first snapshot, by reading from the order-backup table.

**What it does:** Picks the latest `(iInsertBatch, iOrder)` snapshot row from `mftproductionplaniorderbak`. If none exists, returns `sCode=-1` with localised `sProductionMainNoRecoverData`. Otherwise: `UPDATE mftproductionplan T LEFT JOIN mftproductionplaniorderbak P ON E.sMainPlanSid=T.sId SET T.iOrder = IFNULL(E.iOrder, T.iOrder + p_iOrder)` filtered to the current `sMakePerson`, the latest `iInsertBatch`, and `sState IN (2,3,7)`. Unlike `BtnEventResumeOrder`, the backup batch is **not** deleted afterwards, so the snapshot stays available for repeated rollbacks.

**Invocation:** Standard `Sp_<Module>_BtnEvent*` slot — dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` when the 主计划 自动排序工具's 恢复首次排序 button names this procedure. xly-src ships `script/标版/30100101/schedule/Sp_productionMainPlan_BtnEventResumefirstOrder.sql`. Sibling: `Sp_productionMainPlan_BtnEventResumeOrder` (consumes the snapshot).
