# `Sp_ProductCardAddMaterials_calc` (procedure)

> 自定义计算过程，前台传入数据源，经过运算处理后返回前台渲染


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sDropTableSql` | `longtext` |
| 2 | IN | `sCreateTableSql` | `longtext` |
| 3 | IN | `sData` | `longtext` |
| 4 | IN | `selectSql` | `longtext` |
| 5 | IN | `sErroId` | `varchar(100)` |
| 6 | IN | `iErroFlag` | `int` |
| 7 | IN | `sFormGuid` | `varchar(100)` |
| 8 | IN | `sLoginId` | `varchar(100)` |
| 9 | IN | `sBrId` | `varchar(100)` |
| 10 | IN | `sSuId` | `varchar(100)` |
| 11 | OUT | `sCode` | `int` |
| 12 | OUT | `sReturn` | `longtext` |

## Body

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

## Narrative

**Business context:** 产品资料 / 生产工艺卡 — custom-calc handler invoked when the user adds materials to a product process card; the front-end posts the grid data, the proc materialises it into a temp table, applies cross-row roll-ups (pack/mounted-style material consolidation, machine vs. process linkage), and returns the recalculated rows for the UI to repaint.

**What it does:** Drops/recreates `mftproductmaterials_calc_tmp` from `sCreateTableSql`/`sDropTableSql`, inserts the posted `sData` rows, then joins to `elemachine`, `elematerials`, `eleprocess`, `mftproductcontrol_calc_tmp`, `mftproductprocess_calc_tmp`, `mftproductslave_calc_tmp`, `p_sMaterialsStyle_table`, `p_sPackMaterialsTb_table`. Routes through `CALL Sp_calc_addData_toTable` for the row-insert helper and `CALL Sp_Sis_GetConst` for localised error messages. Final `EXECUTE selectSql` ships the recalculated dataset back via the cursor (no OUT-table return).

**Invocation:** Dispatched by Java `CalcProcedureServiceImpl.calc()` (in `xlyBusinessService`) when the request body's `sProName=Sp_ProductCardAddMaterials_calc` — the standard custom-calc bridge that funnels frontend grid edits through user-defined SQL procs. The companion proc `Sp_ProductCardMaterials_calc` (without `Add`) handles the same form's full reload. No gdsmodule hook or form-master binding — the proc name lives on the form's calc-button definition and is shipped from the frontend.
