# `PRO_ERPMERGEPRODUCTIONREPORT` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sSlaveId` | `varchar(100)` |
| 2 | OUT | `sErrorMsg` | `varchar(100)` |

## Body

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

## Narrative

**Business context:** Manufacturing — 生产报工 (Production Report) reporting-row builder. Rebuilds the denormalized `ERPMERGEPRODUCTIONREPORT` row for one `MFTPRODUCTIONREPORTSLAVE` whenever the report is saved/checked, joining in all the dimensional labels (customer, product, team, work-center, machine, employee, process, work-order, classification names) so analytics can scan one wide table.

**What it does:** loads the slave row from `MFTPRODUCTIONREPORTSLAVE` by `sSlaveId` and its master from `MFTPRODUCTIONREPORTMASTER` via `@sParentId`, then conditionally fetches name labels from the related base tables. Inside a transaction it `DELETE`s any existing `ERPMERGEPRODUCTIONREPORT` row keyed on `sSlaveId` and `INSERT`s the freshly composed denormalized row.

**Invocation:** Called by `ProDao.proErpMergeProductionReport(map)` via MyBatis CALLABLE mapper `ProMapper.xml`, driven from `MegerProductionReportServiceImpl` after a `MFTPRODUCTIONREPORTSLAVE` mutation event. Sibling of `PRO_ERPMERGEMFTWORKORDER` and `PRO_ERPMERGESALSALESORDER`. See [Cache invalidation on metadata change](../../reference/maintainer/cache-invalidation.md).

Caveat: the DELETE predicate is `WHERE sSlaveId = sSlaveId` — same shadowed-name bug as the sibling procs; MySQL binds both sides to the IN parameter so the WHERE is effectively a tautology. Single-row INSERT after a table-wide DELETE may be wider than intended; flag for maintainer audit.
