# `Sp_productionMainPlan_BtnEventUnlock` (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_BtnEventUnlock`'`._

## Narrative

**Business context:** 生产管理 / 主计划 → 二次审核 — planner-grid "second-pass review" button. Triggered after a downstream change to a work-order or its 跟单 (order-follower) selection flagged the main plan as needing re-approval. Verifies the upstream `mftworkordermaster.bCheck=1` and the plan-row freeze flag before letting the planner thaw it back into scheduling.

**What it does:** Parses `$.params[*].value[*].sId`. For each plan id: joins to `mftworkordermaster` to read `bWorkOrderCheck` and reads `mftproductionplan.bFrozen`. Aborts with `sCode=-1` and a `GROUP_CONCAT(sBillNo)` of the offending work-orders when `bWorkOrderCheck=0` (work-order not approved). Otherwise reads the plan's current state, computes the max sibling `iOrder`, and updates `mftproductionplan` to unfreeze (`bFrozen=0`) and assign the next free order, leaving downstream slaves available for re-planning.

**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_BtnEventUnlock.sql`.
