# `Sp_workorderSave` (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_workorderSave`'`._

## Narrative

**Business context:** 制造 → 工单 — 工单保存校验 (per `COMMENT`): refuses to save a 工单 slave row when its upstream 销售订单 (`salsalesordermaster`) has been unapproved (`bCheck=0`) or deleted, protecting the work-order data from drifting against a stale order.

**What it does:** Single guard. Counts `salsalesordermaster.sId WHERE sId IN (SELECT sSrcId FROM mftworkorderslave WHERE sId=sGuid) AND IFNULL(bCheck,0)=0`. If any such row exists, sets `sReturn='订单已消审/或已删除 不能保存工单数据 请核查订单数据'`, `sCode=-1` and `LEAVE top` to abort. Otherwise falls through (default `sCode=1`). No table mutations.

**Invocation:** Status: appears orphaned. No `gdsmodule.sSaveProName*` references this exact (lower-case `Sp_workorderSave`) name — the live 工单 forms point at `Sp_Check_sWod` and `Sp_beforeSave_sWod` for save validation. No `gdsconfigformmaster`, no other DB routine, no xly-src file calls it. Likely an early sketch of the work-order save guard, superseded by `Sp_Check_sWod`; candidate for maintainer audit.
