# `Sp_System_UpdateWorkCl` (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 | `sTableName` | `varchar(100)` |
| 4 | IN | `sLoginId` | `varchar(100)` |
| 5 | OUT | `sReturn` | `varchar(4000)` |
| 6 | IN | `sBrId` | `varchar(100)` |
| 7 | IN | `sSuId` | `varchar(100)` |
| 8 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 制造 → 工单 (生产工单) — POST-save validation+materialisation hook (header comment: "业务单据保存校验") used when saving a 工单主表 (`mftworkordermaster`) row. Refuses saves with missing component/product picks or stopped materials, then snapshots inserted/changed materials into the inventory-detail backing table `EleMaterialsStock`.

**What it does:** Only fires for `sTableName='mftworkordermaster'`. Stamps `mftworkordermaster.sSaveName=sLoginId, tSaveDate=NOW()`; backfills `sAddPerson/tAddDate` on new `mftworkordermaterials` rows (where `sAddPerson=''` and `bSource=1`). Then runs four guards: (1) any non-type-2 row with empty `sControlId` → "未选择部件信息" (sNoComponentSelect); (2) any type-2 row with empty `sCombinePartsName` → "未选择成品信息" (sNoProductSelect); (3) any material whose `elematerials.bInvalid=1` → "物料为停用物料，请用其他料替换" (sMaterialInactive) with `sCode=-8`; (4) any duplicate (materialsId, style) pair where both `bSource=1` and `bSource=0` exist → "物料已存在工单中，禁止核算新增" (sMaterialHaveWorkOrder). Last guard runs the same dedup against type-2 (combined) rows joined through `mftworkorderslave`/`eleproduct`. On success inserts the work-order's materials into `EleMaterialsStock` (qty/unit/warehouse/location seed) for downstream inventory ops.

**Invocation:** Status: appears orphaned. No `gdsmodule.sSaveProName`/`sSaveProNameBefore` binding, no form-master, no other-proc, no xly-src match. Given the signature shape (`sFormGuid,sGuid,sTableName,sLoginId,sReturn,sBrId,sSuId,sCode` — the standard `sSaveProName` slot) and the work-order-master-only branch, this is clearly the save-validator for the 工单 form. Dispatch must be via a route table not visible to grep. Candidate for maintainer audit.
