# `Sp_MachinePoweranalysis` (procedure)

> 设备用电分析


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `tStartDate` | `datetime` |
| 2 | IN | `tEndDate` | `datetime` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |
| 5 | IN | `sLoginId` | `varchar(100)` |
| 6 | IN | `bFilter` | `varchar(5000)` |
| 7 | IN | `pageNum` | `int` |
| 8 | IN | `pageSize` | `int` |
| 9 | OUT | `totalCount` | `int` |
| 10 | IN | `countCloumn` | `varchar(5000)` |
| 11 | OUT | `countMapJson` | `longtext` |
| 12 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 13 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 14 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 生产管理 → 设备用电分析 — paged-grid 设备能耗 report. Lists every PLC-tracked machine (`elemachine` with `iPlcNo > 0`) and rolls up 待机能耗 (`sStatus <> 'startWorking'`) vs 运行能耗 (`sStatus = 'startWorking'`) plus 度/分钟 averages over a date window, sourced from `plc_machinedata`.

**What it does:** Defaults `tStartDate` to `today 08:00:00` and `tEndDate` to NOW. Drops/creates `Tmp_elemachine_1` populated from `elemachine` (filtered by `iPlcNo > 0` and `bInvalid = 0`), then aggregates `plc_machinedata` into `p_bd_EqStatus_1` by 机台 (sum of `dElectricityQty` split by status; sum of `dProduceHour/3600`). `UPDATE` joins the temp by `sMachineId` to copy 度数 and 时间 columns, computes 度/分钟 ratios, then `CALL Sp_Do_UpdateByPageSizeBefore` to paginate via the standard report-paging helper.

**Invocation:** Status: appears orphaned by formal channels. No `gdsmodule.sProcName`/`sSaveProName*` hook, no `gdsconfigformmaster.sSqlStr/sConfigSqlStr/sSqlCondition` binding, no other-routine reference, no install script in xly-src. The paged-report signature implies it was intended as a form data-source — candidate for maintainer audit. Drill-in dashboards: `Sp_MachinePoweranalysis_1` (per-machine pie of 设备状态 能耗), `Sp_MachinePoweranalysis_2` (per-machine ~25-hour line).
