# `Sp_Apply_Flow_materialspd` (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_materialspd`'`._

## Narrative

**Business context:** 材料盘点单据 → 材料库单据 → 材料库存 (catalog header: "流程启动前调用-材料盘点"; module sId `192116810113315228128521360`, form sId `192116810113315228129419200`, tbName `mitmaterialscheckmaster`). Per-form workflow-apply data builder for the warehouse stock-count submission.

**What it does:** Resolves two approver tiers from `eleemployee`: 仓库组长 (`iPosition=32 AND (sEmployeeNo='00034' OR iPosition=7)`) and 成本会计 (`sEmployeeNo='06376' OR iPosition=33`). Both clauses hardcode tenant-specific employee numbers as fallbacks alongside the position-id route. Emits `sTableParams` (盘点单号/盘点仓库/盘点人/盘点时间/盘点备注) and `sTableParamsValue` (master values joined to `eleemployee` for the 盘点人 name and `siswarehouse` for the warehouse name + `OneFlow`/`TwoFlow`).

**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: 仓库组长 predicate `WHERE iPosition=32 AND (sEmployeeNo='00034' OR iPosition=7)` is malformed — the parenthesised OR is ANDed with `iPosition=32` so the `iPosition=7` branch is unreachable (always false when `iPosition=32`). The 成本会计 fallback uses `sEmployeeNo='06376'` and `iPosition=33` — tenant-specific GUIDs hardcoded into approver-resolution logic.
