# `Sp_Check_sOdt` (procedure)

> 发外检验单据保存之前数据校验


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 质量管理 → 质量管理单据 → 发外检验单据, and 移动端管理 → 现场 → 功能操作 → 发外检验(mobile单据) — post-save validator on `qlyoutsideproducttestmaster`. Computes 合格/不合格 per slave row from `dNoQualifyQty` vs `iAcQty`/`iAcQty2`, rolls overall test result up to the master, and applies AQL-standard accept-reject totals across the sample group.

**What it does:** Reads `sSrcSlaveId` from `qlyoutsideproducttestmaster`. Sets `QlyOutSideProductTestSlave.sActValue` to `不合格` when `dNoQualifyQty > iAcQty` OR `dNoQualifyQty2 > iAcQty2`. Updates `qlyoutsideproducttestmaster.iTestResult` (1 if any 不合格 slave row exists) and `dOutSampleQty` (max sample qty across slaves). Then opens a cursor per `sAqlstandardId`, sums `dNoQualifyQty`/`dNoQualifyQty2`, increments `p_iResult` if the group totals exceed `p_iAcQty`/`p_iAcQty2`, and writes the final flag back to `qlyoutsideproducttestmaster.iTestResult`.

**Invocation:** Bound to `gdsmodule.sSaveProName` (post-save) on `发外检验单据` (`15827076660008241075501010830000`, under 质量管理 → 质量管理单据) and `发外检验(mobile单据)` (`12012615914116374731690490`, under 移动端管理 → 现场 → 功能操作). Dispatched by `BusinessBaseServiceImpl.checkUpdate(..., "sSaveProName")` after the save batch commits. xly-src ships `script/标版/30100101/Sp_Check_sOdt.sql` as the install body.
