# `Sp_Apply_Flow_OpsProcess` (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_OpsProcess`'`._

## Narrative

**Business context:** 工序发外 → 发外加工流程 → KPI流程操作菜单 (catalog header: "流程启动前调用-工序发外"; module sId `192116810113315232400087230`, form sId `192116810113315232402114180`, tbName `opsoutsideprocessmaster`). Per-form workflow-apply data builder for the process-level subcontracting flow, gated by multiple price-vs-guidance comparisons and 是否烟包 (tobacco-pack route).

**What it does:** Resolves ten approver tiers: 发外 (`iPosition=14`), 报价员 (`iPosition=35`), 生产+报价+营销 会签 (`iPosition in (3,8,16)`), 生产部长 (制单人's grandparent department head — climbs `sisdepart.sParentId` twice), 总经理 (`iPosition=1`), 副董执行董事 (`iPosition=38`), 国内事业副总 (`iPosition=34`), 财务总鉴 (`iPosition=11`), 董事长 (`iPosition=39`). Computes seven escalation flags: `iOut2` (exempt 7 工序 sIds — same hardcoded list as `Sp_Apply_Flow_OpsCheck`), `iOut` (any row exceeds 指导价), `iOut3` (exceeds 报价员报价 given that it already exceeds 指导价), `iOut4` (exceeds 报价 by >2000), `iOut1` (sum of dMaterialsMoney > 2000), `iOut5` (是否烟包 — joins customer/product to `siscustomerproperty.sName='烟包'` or 产品 classify root sId `'16624527080007919539418229414000'`). Aggregates `p_sProcessMemo` per slave row as `'工序名称:{n}➜发外单价:{p}➜指导价:{g}➜报价员报价:{q}➜总价:{m}'`. Emits `sTableParams` (发外单号/外协商/发外总价/发外信息/发外加工原因/发外备注) and `sTableParamsValue` (master values + all 5 `iOut*` flags + the ten 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: the 7-element exempt 工序-sId list and the 烟包 classification root sId `'16624527080007919539418229414000'` are tenant-specific. The 生产部长 resolution climbs `sisdepart.sParentId` *twice* — fragile if a department's hierarchy depth changes. `iOut3` is computed inside an `IF p_iCount1 > 0` block so it's only set when 指导价 was already exceeded; otherwise it remains 0 from the declared default. `iOut4` uses `(A.dMaterialsQty*A.dQuotationPrice)>2000` rather than the commented-out `(A.dOldMaterialsMoney-...)>2000` — comment suggests the metric was revised.
