# `SP_Return_Flow` (procedure)

> 报价单撤回流程


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `varchar(10000)` |
| 2 | IN | `sLoginId` | `varchar(100)` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |
| 5 | OUT | `sReturn` | `varchar(1000)` |
| 6 | OUT | `sCode` | `int` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `SP_Return_Flow`'`._

## Narrative

**Business context:** 工作流 / 报价单 — toolbar action that withdraws (撤回) a started approval flow on a bill before the next approver acts on it, returning the bill to pre-approval state. COMMENT `'报价单撤回流程'`. Implemented generically on `biz_flow.sMasterTableName` so it works for any bill type whose flow has been started but not finished.

**What it does:** Parses `sProInParam` JSON to get the bill id `p_sId` and a textarea reason. Looks up the latest `biz_flow` row for that bill (`sSrcId=p_sId` ORDER BY `start_time` DESC LIMIT 1), reading `instance_id`, `sMasterTableName`, `id`. Aborts with sCode=-1 if no flow found. Sets `biz_flow.type='已撤销'`, `end_time=NOW()`, `update_time=NOW()`, `update_by=Fun_GetLoginUserName(...)`. If `sMasterTableName` is known, executes dynamic `UPDATE <master> SET sStatus=0 WHERE sId='p_sId' …`. Finally `DELETE FROM biz_todo_item WHERE instance_id=p_instanceId AND is_handle=0` to clear pending todos. The Activiti runtime-task delete is commented out (left for the runtime to clean up).

**Invocation:** Dispatched dynamically by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` (POST `/procedureCall/doGenericProcedureCall`) — the 撤回流程 toolbar button on any flow-enabled bill names this proc as the action. Ships in xly-src as `xlyEntry/src/main/resources/flyway/V1.0.6__202354_SPReturnFlow.sql` (flyway migration) and `script/标版/upgrade/更新WAR脚本/20230210_消息、工作流、定时 模块/消息、工作流、定时 模块_20230210.sql`.
