# `Sp_Apply_Flow_MaterialsReturn` (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_MaterialsReturn`'`._

## Narrative

**Business context:** 研发反馈审核 / 研发工单 (catalog header: "流程启动前调用-研发反馈审核") — per-row workflow-apply data builder triggered from a `mftworkorderslave` row of a 研发工单 (R&D work order). The "Return" in the proc name refers to the feedback-return loop (车间主管 → 技术工程 → 技术部长 → 供应链部长), not material return.

**What it does:** Resolves one approver tier (供应链部长, `iPosition=5`) into `p_OneFlow`. Unwraps the inbound `sGuid` if it is a JSON envelope of the shape `{"params":[{"key":"slave","value":[{"sSlaveId":"..."}]}]}` — used when the proc is invoked from a multi-select 自定义按钮; if JSON parse fails it sets `sCode=-8 / sReturn='请选择数据'` and `LEAVE top`. After unwrapping, `sGuid` is treated as a `mftworkorderslave.sId`. Emits `sTableParams` (研发工单号/研发材料/车间主管反馈/技术工程反馈/技术部长反馈/测试是否合格) and `sTableParamsValue` (JSON joining `mftworkorderslave`/`mftworkordermaster`/`elematerials` for the slave-row 反馈 columns + `OneFlow`).

**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.

Flags: `Declare p_iType Int Default 0` is declared but never used. The JSON-unwrap path is the only branch that sets `sGuid` correctly; if a caller passes a raw slave-row sId (not wrapped), the proc immediately returns `sCode=-8`.
