# `Sp_BtnCalculation_Machine_time_byMachineTypeEnd` (procedure)

> 根据机台类型循环计算时间


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_sMachineType` | `varchar(100)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | OUT | `sReturn` | `varchar(1000)` |
| 5 | OUT | `sCode` | `int` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_BtnCalculation_Machine_time_byMachineTypeEnd`'`._

## Narrative

**Business context:** 排程 / 统筹排程 — terminal-pass variant of `Sp_BtnCalculation_Machine_time_byMachineType` for the unified-planning 计算时间 button. Walks `elemachine` rows whose `iCalcOrder>0` and `sMachineType<>1` (non-printing presses ordered by their explicit calc sequence) and re-anchors `mftproductionplanslave` times for the unconsumed (`bProductionReportComplete=0`, `dProcessQty-dProductionReportQty>0`) plan-slaves on each machine, finally re-sequencing locked (`bEmploy=1` / `sState='2'`) rows so released (`bEmploy=0`) rows pick up after them.

**What it does:** Per-machine cursor → for each chained next-process planslave, sets `tHeoryCompletDate=p_tDate` to propagate the new completion date down the routing graph. Then, when `p_tEmployStartDate` is set, rebuilds a `MftProductionPlanSlave_Tmp_Employ` temp table whose `iOrder` starts from `MAX(iOrder)` of locked rows and increments per `(tStartDate, iOrderNew ASC)`, and UPDATEs `mftproductionplanslave.iOrder` from it — effectively pushing the unlocked queue after the locked queue. Uses temp tables `MftProductionPlanSlave_next` (next-process lookup) and the large commented-out `MftProductionPlanSlave_MachineTypeEnd` skeleton (dead).

**Invocation:** Called only by `Sp_unifiedPlanning_BtnCalculation_Machine` as the second-stage pass after `Sp_BtnCalculation_Machine_time_byMachineType` finishes printing-machine seeding. Reached from the 统筹排程 → 计算时间 button via `GenericProcedureCallServiceImpl.doSetTimeCalcMachineHour()`.

Flag: large blocks of the body are commented-out variants of `MftProductionPlanSlave_MachineTypeEnd`/cursor logic — confirm whether the live path matches the intent before relying on the procedure name.
