# `Sp_bd_machine_TmAnalysis` (procedure)

> 单个机台时间分析


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 单个机台时间分析 — single-machine time-breakdown donut on the 看板管理 / 数字工厂 dashboard. For one PLC machine (parameter `sPlcNo`), splits all PLC-recorded hours across status buckets (生产/待料/纸张异常/文件异常/设备保养/设备异常/下班) and emits a JSON pie with a 总时间 subtitle.

**What it does:** Resolves the target machine from `elemachine` by `iPlcNo=sPlcNo` (tenant-scoped), aggregates `plc_machinedata.dProduceHour/3600` per `sStatus` into `p_bd_EqStatus`, decodes status codes (`endWorked→生产`, `waitingWork→待机`, `waitError→待料异常`, `PaperError→纸张异常`, `fileError→文件异常`, `maintain→设备保养`, `abnormal→设备异常`, `offwork→下班`), and emits `{"data":[{"x":"<sName>","y":<value>}], "hasLegend":true, "subTitle":"总时间", "valueFormat":false, "lineWidth":0}`. Body sets `sSuId='2220000222'` unconditionally — a tenant-baked override.

**Invocation:** No install script under `xly-src/script/标版/30100101/`, no form-master sSqlStr, no `gdsmodule` hook, no other-routine caller, no Java caller. Status: appears orphaned. No caller found in any channel — candidate for maintainer audit. Reachable only by a tenant-baked external dashboard endpoint that invokes the proc by name.

`SET sSuId = '2220000222'` after the IFNULL means the proc ignores its `sSuId` IN parameter and always queries the same subsidiary — flag for re-mapping if cloned to another tenant.
