# `Sp_productionMainPlan_BackupCurrPlaniOrder` (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_BackupCurrPlaniOrder`'`._

## Narrative

**Business context:** 生产管理 / 主计划 — pre-save hook that snapshots the current `iOrder` (sequence) of every in-flight plan row into `mftproductionplaniorderbak` so the user can rewind to the previous ordering if they don't like the auto-sort result. Comment on the proc: "主计划保存之前调用：保存当前计划的次序数据，以备恢复上次计划次序".

**What it does:** Reads `MAX(iInsertBatch)+1` from `mftproductionplaniorderbak`, then `INSERT INTO mftproductionplaniorderbak(sBrandsId, sSubsidiaryId, iInsertBatch, sMakePerson, iOrder, sMainPlanSid) SELECT sBrId, sSuId, p_iInsertBatch, p_sMakePerson, P.iOrder, P.sId FROM mftproductionplan P WHERE P.sState IN (2,3,7) AND tenant scope`. The batch number lets the rewind helper restore one specific snapshot.

**Invocation:** Standard `Sp_<Module>_BtnEvent*` slot — dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` when the 主计划 page issues the save-prelude. Same backup logic is also inlined at the top of `Sp_productionMainPlan_BtnEventAutoOrder` (smart-sort writes its own snapshot before resequencing). xly-src ships `script/标版/30100101/schedule/Sp_productionMainPlan_BackupCurrPlaniOrder.sql`. No form-master or gdsmodule binding.
