# `Sp_productionMainPlan_BtnEventUnOrder` (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_BtnEventUnOrder`'`._

## Narrative

**Business context:** 生产管理 / 主计划 → 恢复撤单 — planner-grid "undo cancel-order" button. Inverse of 撤单/order-cancel: thaws plan and slave rows that had been frozen out of the schedule, conditionally re-keying their `iOrder` per the `CkxIntoPlanNewWod` system setting (whether canceled orders rejoin the queue as new work-orders).

**What it does:** Reads `CkxIntoPlanNewWod` from `syssystemsettings` into `p_bXd`. Parses `$.params[*].value[*].sId`. For each plan id: reads `sState`, aborts with `sCode=-1` ",无需恢复撤单" if already at `sState='1'`. Otherwise: `UPDATE mftproductionplan SET bFrozen=0` and `UPDATE mftproductionplanslave SET bFrozen=0` for every slave keyed by the plan's `sWorkOrderId`. When `p_bXd=1`, also reassigns the plan-row `iOrder` to `MAX(iOrder)+1` so the canceled batch lands at the end of the queue.

**Invocation:** Standard `Sp_<Module>_BtnEvent*` slot — dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` when the 主计划 grid's 恢复撤单 button names this procedure. xly-src ships `script/标版/30100101/schedule/Sp_productionMainPlan_BtnEventUnOrder.sql`. Inverse: `Sp_productionMainPlan_BtnEventOrder` (撤单).
