# `Sp_Apply_Flow_MaterialsTest` (procedure)

> 流程启动前调用-材料检验


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sFormGuid` | `varchar(100)` |
| 2 | IN | `sGuid` | `varchar(100)` |
| 3 | IN | `sSrcNo` | `varchar(100)` |
| 4 | IN | `sLoginId` | `varchar(100)` |
| 5 | OUT | `sTableParams` | `longtext` |
| 6 | OUT | `sSrcReportData` | `longtext` |
| 7 | OUT | `sTableParamsValue` | `longtext` |
| 8 | OUT | `sReturn` | `varchar(4000)` |
| 9 | IN | `sBrId` | `varchar(100)` |
| 10 | IN | `sSuId` | `varchar(100)` |
| 11 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 材料检验 / 来料检验 → 质量管理单据 → 质量管理 (catalog header: "流程启动前调用-材料检验"; module sId `15828617570008732160077596657000`, form sId — incoming-materials IQC inspection). Per-form workflow-apply data builder for the inbound-material inspection (`qlycomematerialstestmaster`) approval flow, gated by `iTestResult` (合格/不合格 outcome) and `iTypeResult`/`iTypeResult1` (disposition routes).

**What it does:** Resolves five approver tiers: SQE (`iPosition=17`), 物控人员 (the制单人 of the linked `purpurchaseordermaster` via `qlycomematerialstestmaster.sPurChaseOrderId`), 物控经理 (`iPosition=6`), 品质经理 (`iPosition=18`), 生产部长 (`iPosition=8`). Reads `iTestResult` into `p_iOut` (gates 不合格 escalation nodes). Emits `sTableParams` (检验单号/采购订单号/材料名称/不合格数/检验备注) and `sTableParamsValue` (JSON joining `qlycomematerialstestmaster`/`elematerials` for `sBillNo`/`sPurChaseOrderNo`/`sMaterialsName`/`dNoQualifyQty`/`sMemo` + `iOut`/`iTypeResult`/`iTypeResult1` + the five approver name lists).

**Invocation:** Dispatched dynamically by Java `CheckExamineFlowDataServiceImpl.doSendCheckFolwData()` via `doProByNameFlow(..., sApplyProName, ...)` where `sApplyProName` is read from `gdsmoduleflow.sApplyProName` on the 材料检验 workflow config row. `gdsmoduleflow` is empty in this database — workflow configs are tenant-provisioned per deployment. The companion in-flow update-procs are [`Sp_Apply_Flow_MaterialsTest_Proc1`](./Sp_Apply_Flow_MaterialsTest_Proc1.md) (`iTypeResult1` setter) and [`Sp_Apply_Flow_MaterialsTest_Proc2`](./Sp_Apply_Flow_MaterialsTest_Proc2.md) (`iTypeResult` setter).

Flags: `p_TwoFlow` is loaded as a single `sMakePerson` *name string* rather than a `Group_CONCAT`-style list (other tiers are lists) — downstream consumers must accept both shapes. `Declare p_iOut1 Int Default 0` is unused.
