# `Sp_productionMainPlan_BtnEventResumeOrder` (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_BtnEventResumeOrder`'`._

## Narrative

**Business context:** 生产管理 / 主计划 → 自动排序工具 / 恢复排序 — auto-sort tool's "undo last sort" button. Pops the most-recent `iOrder` snapshot, applies it to the active plan rows, then removes that snapshot so successive clicks walk back through the stack.

**What it does:** Reads the latest `(iInsertBatch, iOrder)` from `mftproductionplaniorderbak`. If none, returns `sCode=-1` with "No recoverable data". Otherwise restores: `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` and latest `iInsertBatch`, scoped to `sState IN (2,3,7)`. Then `DELETE from mftproductionplaniorderbak WHERE sMakePerson=p_sMakePerson AND iInsertBatch=p_iInsertBatch` so the next click rolls back the previous batch.

**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_BtnEventResumeOrder.sql`. Sibling: `Sp_productionMainPlan_BtnEventResumefirstOrder` (restores oldest snapshot, leaves it in place).
