# `Sp_mes_TimeActivation_Machine` (procedure)

> @author:zhucx
							@date:20210621 封存
							@describe: 机器稼动率


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 生产管理 → 生产执行 → 数据采集与设备控制 → 设备稼动率 — paged 机器稼动率 (machine OEE/availability) report. For the supplied date range, returns one row per machine carrying调试/生产中/生产异常/设备保养 minute breakdowns and the derived `dErroHourRate`/`dValidTimeRate`/`dAdjustHourRate`/`dmaintainHourRate`/`dOee` percentages used by the MES dashboard.

**What it does:** Builds temp tables `p_bd_Tm`/`p_bd_Tm_oee`/`p_machinedata`/`p_bd_MachinePlanTemplate2` from `plc_machinedata`, `mftproductionreport*`, and `elemachine`, then aggregates by `sMachineId` with `SUM(dAdjustHour)`/`SUM(dValidTime)`/`SUM(dErroHour)`/`SUM(dmaintainHour)`/`SUM(dTotalTime)`. Wraps the breakdown into a JSON_ARRAY (`sTimeStatus`) with `sName`/`sValue`/`dRate`/`sColor` per status — green for 生产中, yellow for 调试, red for 异常, magenta for 设备保养 — for the front-end chart. Pagination is handled inline (no `Sp_Outstanding_Query` call) and temp tables are dropped at end.

**Invocation:** Bound as the data-source of the 设备稼动率 form (`sParentId 19211681019715708722537970`) via `gdsconfigformmaster.sSqlStr` — under 数据采集与设备控制 inside 生产执行. xly-src ships `script/标版/30100101/Sp_mes_TimeActivation_Machine.sql` (install) and a `客户/亚明威` custom variant. Comment marks the body 封存 (frozen) — newer variants may exist for later customer revisions.
