# `Sp_productionMainPlan_BtnEventOrder` (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_BtnEventOrder`'`._

## Narrative

**Business context:** 生产管理 / 主计划 → 撤单 — planner-grid "withdraw plan" button. Reverses a row that was previously pushed into 规划中 (`sState='2'`) back to either 新工单 (`sState='1'`) or 规划中 itself, depending on the `CkxIntoPlanNewWod` system setting that controls whether the planner uses two-stage or one-stage flow.

**What it does:** Reads `SysSystemSettings.sValue` for `sName='CkxIntoPlanNewWod'` into `p_bXd`. Parses `$.params[*].value[*].sId`. For each plan id, reads current `sState`. The proc bails with `,无需撤单` when the current state is already at or below the target (`p_sStateOld <= p_sState`). Target state: `p_bXd=1 → '1'` (新工单), else `'2'` (规划中). Picks `MAX(iOrder)` over rows already at that state, then `UPDATE mftproductionplan SET sState=p_sState, bFrozen=IF(p_bXd=1,0,1), iOrder=MAX+1` and `UPDATE mftproductionplanslave SET bFrozen=1` for every slave row under the work-order.

**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_BtnEventOrder.sql` and the proc also appears in `script/标版/30100101/planTmp.sql`. No form-master or gdsmodule binding.
