# `Sp_bd_MachinePlanTemplate` (procedure)

> 车间效率综合看板-根


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sPlcNo` | `varchar(100)` |
| 2 | IN | `sFormGuid` | `varchar(100)` |
| 3 | IN | `sLoginId` | `varchar(100)` |
| 4 | OUT | `sReturn` | `varchar(4000)` |
| 5 | IN | `sBrId` | `varchar(100)` |
| 6 | IN | `sSuId` | `varchar(100)` |
| 7 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 看板管理 / 数字工厂状态看板 — root proc behind the "车间效率综合看板" single-machine dashboard tile. Returns the live key/value bundle for one PLC-mapped press: machine name, current work-order number, current shift label, qualified-count total, current PLC status (生产中 / 待料异常 / 纸张异常 / 文件异常 / 设备保养 / 设备异常 / 下班停机), today and this-month counter sums, plan-attainment rate, time-utilisation rate, speed-utilisation rate.

**What it does:** Looks up `elemachine` by `iPlcNo` to resolve `sMachineId` and shift boundaries (`sOffWork`/`sShiftsWork`), then derives `p_tTeamWorkStartDate` and `p_tMachineWorkStartDate` from the current clock. Aggregates `viw_plc_machine` (current status, current 工单号, 合格数) and the `p_bd_Tm` / `p_bd_McPlanCount` temp tables seeded from `mftproductionplanslave` and counter views to fill `p_bd_MachinePlanTemplate(sName,sValue)`, then `SELECT *` returns the rowset to the dashboard renderer.

**Invocation:** Installed by `xly-src/script/标版/30100101/Sp_bd_MachinePlanTemplate.sql`. No form-master `sSqlStr`, no `gdsmodule` hook, no Java caller in xly-src. Other DB references are sibling `_1`/`_2`/`_3`/`_4`/`_5` variants and `_new` plus the `Sp_mes_TimeActivation_*` family — none of them call it. Reachable only via an external dashboard HTTP endpoint that invokes the proc by name.
