# `Sp_Apply_Flow_sCustomerAccord` (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_sCustomerAccord`'`._

## Narrative

**Business context:** 框架协议 (流程启动前调用-框架协议) — workflow-apply data builder for the customer-framework-agreement approval flow on `elecustomeraccord`. Builds a six-tier roster with dynamic营销一/二部 position-tier swap, 招标 and 新/老客户 routing flags.

**What it does:** Climbs applicant dept via `sisdepart.sParentId` to set `p_saledeptl` (=37 营销一部 `1734417170...` → uses销售经理 iPosition=37 for tier-2 lookup; =1 营销二部 `2023112009...` → uses总经理 iPosition=1; default=1). Resolves tiers from `eleemployee.iPosition`: 4=客服经理, 10=法务, 2=销售副总, 1=总经理. `p_TwoFlow` (营销部长/财务会签) = `iPosition IN (p_saledeptl, 11)`. `p_FourFlow` (总经办/财务/营销部长 会签) = `iPosition IN (p_saledeptl, 11, 12)`. Emits master `sBillNo`, `sAccordName` (CONCAT(`sAccordNo`,'➜',`sAccordName`)), `dYearMoney`, customer name, `iTender=1` when `bBidding=1` (招标), `iNewOld=1` when `sCustomerProperty='新'`.

**Invocation:** Dispatched dynamically by Java `CheckExamineFlowDataServiceImpl.doSendCheckFolwData()` via `doProByNameFlow(..., sApplyProName, ...)` from `gdsmoduleflow.sApplyProName` (empty in this DB — workflow configs tenant-provisioned per deployment).

Flag: variable name `p_saledeptl` (with trailing `l`) is unusual but consistent throughout the proc; hardcodes tenant dept-root GUIDs (营销一/二部).
