# `Sp_MachineSpeedanalysis_2_new` (procedure)

> 机台速度分析_折线


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_iPlcNo` | `varchar(100)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |

## Body

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

## Narrative

**Business context:** 生产管理 → 设备速度看板 — newer variant of `Sp_MachineSpeedanalysis_2`. Returns a per-机台 折线 of 速度/小时 keyed by PLC number rather than machine sId, scoped to the current shift window (`FUN_GET_DATE_BC_STARTDATE_NEW(NOW(), sOffWork, sShiftsWork)` → NOW), and zeroes out `dRate` for non-running states.

**What it does:** Resolves the machine from `elemachine` by `iPlcNo = p_iPlcNo` (loads `sId, sOffWork, sShiftsWork, sWorkType, dAvgRate`), computes `p_tStartDate` as the shift's start via `FUN_GET_DATE_BC_STARTDATE_NEW`, drops/creates the same `Sp_MachineSpeedanalysis_2` temp shape. `INSERT … SELECT` from `plc_oeeupdate` AVG'd per-minute, but `dRate` is forced to 0 when `sCurState NOT IN ('startWorking', 'adjustment', 'adjustment2')` — i.e. the line drops to zero during stops/idles, distinguishing operating speed from downtime. Result is shaped into `{"data":[{x:tCreateDate, y:dRate}, …]}` JSON via `Sp_MachineSpeedanalysis_data` / `Sp_MachineSpeedanalysis_return` temps.

**Invocation:** Status: appears orphaned. No `gdsconfigcharmaster.sProcedureName` binding, no caller in xly-src, no other routine references it (sibling `Sp_MachinePoweranalysis_2` only reuses the prefixed temp-table name). The parameter shift to `p_iPlcNo` suggests it's intended as the line-side / kiosk dashboard variant of `Sp_MachineSpeedanalysis_2`. Candidate for maintainer audit.
