# `Sp_plc_implementation2_new` (procedure)

> 信号采集点位监控-2024-12-07


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sMachineId` | `varchar(100)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | IN | `tStartDate` | `varchar(100)` |
| 5 | IN | `tEndDate` | `varchar(100)` |
| 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)` |
| 14 | OUT | `sCode` | `int` |
| 15 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 设备 / PLC 信号采集 — 2024-12-07 rewrite of `Sp_plc_implementation2` (proc COMMENT: "信号采集点位监控-2024-12-07"). Same role — latest-snapshot PLC decoder per machine — extended with a "前 50 条一致" stability heuristic that flags devices stuck on the same processed-quantity or electricity-meter reading.

**What it does:** Builds the per-machine temp tables and pulls `LIMIT 1` from `sysdoplclog` like the v2 proc, plus new `p_status` temp table holding the last 50 readings of `Fn_split_string(...,4)` (status code) and `Fn_split_string(...,16)` (警报灯 flag) per machine. Then aggregates `plc_machinedata.dProcessQty` and `dElectricityStartQty` over last 50 rows per `sMachineId` and sets `p_iCo`/`p_iCo2` to the count of groups that repeat — feeding `sStatusName2` and additional flags in the output. Adds an `sStatusName2` second-status column and 256/16 indicators to the output schema.

**Invocation:** Status: appears orphaned. No `gdsmodule.sProcName` binding, no form-master sSqlStr reference, no `gdsconfigcharmaster.sProcedureName` chart binding, no other-routine caller, no xly-src reference. The `_new` suffix and the date stamp imply it is staged for a release that hadn't been wired at catalog time — candidate for maintainer audit.
