# `Sp_productionMainPlan_BtnEventBlock` (procedure)

> 主计划：锁定 状态为8  印刷、印后工序被锁定，当机台计划算到该时间点的时候，优先该工序排
				 例如工序锁定时间2022-04-30 18:00 - 20:00
				 机台上一道工序开始时间18：00之前的可以再此之前排，例如 16：00 - 19：00
				 那么该工序就是19：00-21：00
				 之后的要再该工序后面排


- **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_BtnEventBlock`'`._

## Narrative

**Business context:** 生产管理 / 主计划 → 锁定 — planner-grid "lock resource" button. Pins selected plan rows at `sState='8'` (locked) so that when the machine-scheduler walks the timeline and reaches the locked window, it lays this process down first. Header comment: locked 印刷/印后 process owns its time window; prior process must finish before, later processes must start after.

**What it does:** Parses `$.params[*].value[*].sId` (plus optional `tCompleteDate`). For each id: refuses with `sCode=-8` and localised `sProductionMainPlanResourceLocked` ("资源已锁定,请勿重复锁定资源") if the row is already at `sState='8'`. Otherwise reads `sWorkOrderId`, then `UPDATE mftproductionplan SET sState='8', sPriorState=p_sState` (so unlock can rewind), `UPDATE mftproductionplanslave SET bEmploy=1, sEmployPerson=sMakePerson, tEmploytime=NOW()` for every slave row under that work-order at `sType>=1`. Finally `CALL Sp_unifiedPlanning_BtnCalculation_workorder(p_sWorkOrderGuid, ...)` to recompute the machine schedule with the new lock in place.

**Invocation:** Standard `Sp_<Module>_BtnEvent*` slot — dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` when the 主计划 grid's 锁定 button names this procedure. Per-slave-row variant: `Sp_productionMainPlan_BtnEventBlockOne`. xly-src ships `script/标版/30100101/schedule/Sp_productionMainPlan_BtnEventBlock.sql`.
