# `Sp_Apply_Flow_OpsProduct` (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_OpsProduct`'`._

## Narrative

**Business context:** 整单发外 → 发外加工流程 → KPI流程操作菜单 (catalog header: "流程启动前调用-成品外购"; module sId `192116810113315234963208090`, form sId `192116810113315234988665330`, tbName `opsoutsideprocessmaster`). Per-form workflow-apply data builder for the single-row (per-slave) whole-order subcontracting flow. Compared with the bulk variants `OpsProductMore` / `OpsProductMorebecome`, this proc evaluates pricing on a single `opsoutsideprocessslave` row.

**What it does:** Resolves four approver tiers: 营销部长 (`iPosition=3`) merged with 对应部门部长 (`iPosition=8` 生产部长 or `iPosition=5` 供应链部长 depending on whether the制单人's `sDepartId` parent equals `'20231120093814639059733069696942'`), 总经理 (`iPosition=1`), 二级部门经理 (制单人's department head). Pulls the linked `salsalesorderslave` row's pricing (`dQuoRate`/`dQuoPrice`/`dProductPrice`) and the slave's `dMaterialsPrice` into `p_dQuoRate`/`p_dQuoPrice`/`p_dOpsPrice`/`p_dProductPrice`. Computes four escalation flags: `iOut` (毛利率 ≤ 1.05), `iOut1` (发外单价 > 基准价×(毛利率−0.05)), `iOut2` (发外单价 > 基准价×毛利率), `iOut3` (发外单价 > 基准价). All flags short-circuit to 0 when `p_dProductPrice=0`. Emits `sTableParams` (发外单号/外协商/总金额/产品信息/发外备注) and `sTableParamsValue` (single-row JSON from `opsoutsideprocessslave`/`eleproduct`/`opsoutsideprocessmaster`/`elesupply` + the four `iOut*` flags + the four 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.

Flags: `p_OneFlow` is built as `CONCAT(p_OneFlow,',',p_TwoFlow)` — so 营销部长 names get the 对应部门部长 names appended. Downstream consumers must accept the comma-joined dual list. Department-classification GUID `'20231120093814639059733069696942'` (生产 root) is hardcoded — tenant-specific.
