# `Sp_Mes_EventReport` (procedure)

> mes-异常事件提报


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sMachineGuid` | `varchar(100)` |
| 2 | IN | `sTeamGuid` | `varchar(100)` |
| 3 | IN | `sShift` | `varchar(5)` |
| 4 | IN | `sBrId` | `varchar(100)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | IN | `sMakePerson` | `varchar(100)` |
| 7 | OUT | `sReturn` | `longtext` |
| 8 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 生产执行 → 数据采集与设备控制 — mes-异常事件提报: for a given machine + team + shift, returns the production-report slave (`mftproductionreportslave`) rows belonging to the current shift window so the MES operator can pick which PLC events still need a manual 异常 (abnormal) explanation.

**What it does:** Reads `sOffWork`, `sShiftsWork`, `sWorkType` from `elemachine` to find the machine's shift definition; locates the latest non-manual report end-date for the machine, falling back to the earliest `plc_machinedata.tStartDate` (TIMESTAMPDIFF>6 min) when no prior report exists; computes the current shift's `p_tStartDate`/`p_tEndDate` based on `sShift` (1=白班, 2=夜班) versus `NOW()`; finally calls `FUN_GET_DATE_BC_STARTDATE_NEWTYPE` to lock the shift start and `SELECT` the matching `mftproductionreportslave` rows. Read-only — no writes.

**Invocation:** Status: appears orphaned. No `gdsmodule`/`gdsconfigformmaster` row references it, no other routine calls it, and no xly-src file mentions the name. The newer 异常事件提报 path likely goes through a different proc; this is a candidate for maintainer audit (and `Sp_Mes_EventReportOld` is the prior body kept as backup).
