# `Sp_Apply_Flow_OpsProductMore` (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_OpsProductMore`'`._

## Narrative

**Business context:** 整单发外 → 发外加工流程 → KPI流程操作菜单 (catalog header: "流程启动前调用-成品外购"; backing table `opsoutsideprocessmaster`). Extended (multi-slave) variant of [`Sp_Apply_Flow_OpsProduct`](./Sp_Apply_Flow_OpsProduct.md) — evaluates pricing thresholds across *all* `opsoutsideprocessslave` rows for the master, with a richer 10-tier approver list and extra `iOut4` (烟包) flag.

**What it does:** Resolves ten approver tiers: 营销部长 (`iPosition=3`), 对应部门部长 (生产部长 `iPosition=8` / 供应链 `iPosition=40` / 采购 `iPosition=5` — branched by制单人's `sisdepart.sParentId` against three tenant-specific dept root sIds), 总经理 (`iPosition=1`), 二级部门经理 (制单人's department head), 营销经理 (`iPosition=37`), 营销负责人 (`iPosition=34`), 副董执行董事 (`iPosition=38`), 财务经理 (`iPosition=11`), 董事长 (`iPosition=39`), 核价审核1 (`iPosition=35`). Counts five price-comparison conditions (`p_iCount1..5`) across all slave rows where `bChild=0`: any-row price=0, 毛利率 ≤ 1.05, 发外单价 > 基准价, 发外单价 > 基准价×(毛利率−0.05), 发外单价 > 订单单价. Computes 是否烟包 (`p_iOut4`) by joining 产品 → `sisproductclassify` parent → classify root sId `'16624527080007919539418229414000'`. Builds `p_sProductName` (per-slave aggregate `'产品名称:{n}➜数量:{q}➜价格:{m}'`) and `p_dTotalMoney` = `SUM(dMaterialsMoney)`. Emits `sTableParams` (发外单号/外协商/总金额/产品信息/发外备注) and `sTableParamsValue` (master + the 5 `iOut*` flags + the 10 approver name lists).

**Invocation:** Dispatched dynamically by Java `CheckExamineFlowDataServiceImpl.doSendCheckFolwData()` via `doProByNameFlow(..., sApplyProName, ...)` where `sApplyProName` is read from `gdsmoduleflow.sApplyProName` on the 整单发外 multi-row workflow config row. `gdsmoduleflow` is empty in this database — workflow configs are tenant-provisioned per deployment.

Flags: three department-classification GUIDs hardcoded: `'20231120093814639059733069696942'` (生产 root), `'17344173190001090119214960551400'` (供应链 root), and the 烟包 root `'16624527080007919539418229414000'` — tenant-specific. `p_iCount2` (基准价×毛利率) is calculated but `iOut2` is set from `p_iCount4` (订单单价) — variable naming drift between query and assignment.
