# `Sp_QlyProductJudge` (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_QlyProductJudge`'`._

## Narrative

**Business context:** 质量管理 / 成品检验 — auto-evaluates a 成品检验 record (`qlyproducttestmaster` / `QlyProductTestSlave`) against the AQL sampling standard, marks each line 合格/不合格, and rolls a master-level `iTestResult` pass/fail. Single-row variant; the toolbar-button equivalent is `Sp_QlyProduct_BtnCalculate`.

**What it does:** Three sequential updates: (1) `UPDATE QlyProductTestSlave A INNER JOIN EleTestStandardItem B INNER JOIN qlyproducttestmaster C SET A.dSampleQty=B.iSample, A.iAcQty=B.iAccept, A.iReQty=B.iReject WHERE A.sParentId=sGuid AND C.dProductQty BETWEEN B.iQuantityFrom AND B.iQuantityTo` — fills the AQL sample/accept/reject from the standard band keyed by the master's `dProductQty`. (2) `UPDATE QlyProductTestSlave SET sActValue = CASE WHEN dNoQualifyQty >= iReQty THEN '不合格' ELSE '合格' END WHERE sParentId=sGuid`. (3) Master roll-up: `iTestResult = (COUNT slave 不合格 > 0 ? 1 : 0)` and `dSampleQty = MAX(slave.dSampleQty)`.

**Invocation:** Status: appears orphaned. No caller found in any channel (form-master, gdsmodule sSaveProName/sCalcProName, other routines, xly-src grep across all extensions). Signature matches the standard 自动判断 button hook (`sFormGuid, sGuid, sTableName, sLoginId, sReturn, sBrId, sSuId, sCode`) for the 成品检验 form — likely invoked dynamically by name from a Java handler not present in xly-src; candidate for maintainer audit.
