# `Sp_Product_BeforeUpdate` (procedure)

> 产品保存前过程


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(100)` |
| 2 | IN | `sFormGuid` | `varchar(100)` |
| 3 | IN | `sLoginId` | `varchar(100)` |
| 4 | IN | `sBrId` | `varchar(100)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | IN | `iFlag` | `int` |
| 7 | OUT | `sCode` | `int` |
| 8 | OUT | `sReturn` | `varchar(4000)` |

## Body

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

## Narrative

**Business context:** 产品管理 → 产品档案及SOP → 产品信息 (`eleproduct`) — save hook on the 产品信息 record (proc COMMENT: "产品保存前过程", but bound on `sSaveProName` which fires post-save). When a product is created from a quotation (`quoquotationslave.sId` lives in `eleproduct.sSrcSlaveId`), this proc back-stitches the new product into the source quotation rows and patches a few defaults so the product is internally consistent.

**What it does:** Reads `sSrcSlaveId` and `sProductNo` for the saved product. Updates `quoquotationslave` (joined to `eleproduct` on `sSrcSlaveId`) — rewrites `sProductId`, `sProductName`, `sProductClassifyId=sParentId`, clears `sProductInfo` for every slave that points at this product. Then updates `quoquotationcontrol` (joined transitively): `REPLACE(sCombinedMemo, oldProductNo, newProductNo)` so the combined-memo text still refers to the right product code. Sets `eleproduct.sParentProductId=1` when an `eleproductchild` row exists for this id (marks composite parents), and back-fills `sProductVer='V01'` when blank.

**Invocation:** Bound on `gdsmodule.sSaveProName = 'Sp_Product_BeforeUpdate'` for `产品信息` (`sId 11811781131121915159873080990`) under 产品档案及SOP → 产品管理 — runs after every save of an `eleproduct` row. Java path: `BusinessBaseServiceImpl` consults `gdsmodule.sSaveProName` post-save. Install script `xly-src/script/标版/30100101/Sp_Product_BeforeUpdate.sql` is the source of truth. Note the name says "BeforeUpdate" but the binding is post-save — the proc is named for intent, not for the hook column.
