# `Sp_Change_WorkOrderStatus` (procedure)

> 判断工单是否完工并修改


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sWorkOrderGuids` | `longtext` |
| 2 | IN | `sSrcModifyType` | `varchar(255)` |
| 3 | IN | `sLoginId` | `varchar(255)` |
| 4 | IN | `sBrId` | `varchar(50)` |
| 5 | IN | `sSuId` | `varchar(50)` |

## Body

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

## Narrative

**Business context:** 制造管理 / 工单 — completion-status re-evaluator for a comma-separated list of work-order ids. Triggered after produce/outsource events to decide whether the work-order is now fully completed and stamp `bBillComplete`, `tBillCompleteDate`, and an audit trail in `sCompletePerson`.

**What it does:** Splits `sWorkOrderGuids` on commas; for each id loads slave rows from `viw_mftworkorder` into temp `workorderTmp`. When the master has `bBillOutside=1` it aggregates `opsoutsideprocessslave.dInStoreAuxiliaryQty`/`dMaterialsQty` (checked, non-invalid) into `dOutsideInStoreQty`, then counts slaves still short of `dProductQty`; if zero remain, sets the master complete. Otherwise (in-house path) compares `dProductQty` vs `dProductInStoreQty` per slave and applies the same complete-flag flip. The `sCompletePerson` column gets a `----<loginId><modifyType>:成品入库/整单发外入库<0|1>` trail concatenated for each invocation, building an in-place audit log.

**Invocation:** Called by `Sp_Calc_sPpr` (产量上报 form, sId `19211681019715476042694840`, the production-report audit/un-audit handler) and the equivalent mobile form 内部报工 (sId `101251240115015916850901130`). Whenever a production report or outsource-return is audited, the upstream proc forwards the affected work-order ids here to refresh completion state. xly-src ships `script/标版/30100101/Sp_Change_WorkOrderStatus.sql` as the install body.
