# `Sp_Reachingrate_Machine` (procedure)

> @author:zhucx
							
		@date:20210621 封存
							
		@describe: 班组-机器计划达标率分析


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sAttribute` | `varchar(100)` |
| 2 | IN | `tBetweenDate` | `varchar(100)` |
| 3 | IN | `sPMachineID` | `varchar(100)` |
| 4 | IN | `sProcessId` | `varchar(100)` |
| 5 | IN | `sWorkCenterId` | `varchar(100)` |
| 6 | IN | `sType` | `char(1)` |
| 7 | IN | `sBrId` | `varchar(100)` |
| 8 | IN | `sSuId` | `varchar(100)` |
| 9 | IN | `sLoginId` | `varchar(100)` |
| 10 | IN | `bFilter` | `varchar(5000)` |
| 11 | IN | `pageNum` | `int` |
| 12 | IN | `pageSize` | `int` |
| 13 | OUT | `totalCount` | `int` |
| 14 | IN | `countCloumn` | `varchar(5000)` |
| 15 | OUT | `countMapJson` | `longtext` |
| 16 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 17 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 18 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 生产管理 → 生产运营报表 → 计划执行力度分析 — paged "plan-execution rate" pivot by machine/process/work-center. Body header self-marks `@date:20210621 封存` (sealed/deprecated). Three pivots discriminated by `sType`: `1`=机台, `2`=工序, `3`=工作中心. The current week's plan vs actual is compared per machine to compute a 达标率 (achievement rate).

**What it does:** Computes the week window (Mon–Sun) shifted by `-7 days` (last week by default) or parsed from `tBetweenDate`. Builds temp table `p_tmp_T` (`sId, sSlaveId, iPlcNo, sMachineName, dAgvRate, iSumCount`) and aggregates per-machine PLC counts vs plan from the production tables, with off-work handling via `p_sOffWork`. Outputs a per-machine `dAgvRate` and hands the final SQL to `Sp_Outstanding_Query` for paging/`bFilter`/`countMapJson` splicing.

**Invocation:** Bound as data-source of form 计划执行力度分析 (`gfm.sId=19211681019715708754570950`, module `19211681019715708754570630` under 生产运营报表 → 生产管理). Install: `script/标版/30100101/schedule/Sp_Reachingrate_Machine.sql`. The 封存 marker in the body header signals the report is retained for compatibility but newer replacements likely exist.
