# `Sp_Calc_sPct1` (procedure)

> @author:zhucx
							@date:2021.11.21 封存
							@describe: 
							1.移动端-生产首检-保存自动调用本过程,当系统设定中本单据为自动审核时


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

## Parameters

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

## Body

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

## Narrative

**Business context:** Three-bind audit for the QC 首检 / 印刷大检 family on `QlyProcessTestMaster`. Header authorship: `zhucx 2021.11.21 封存`. Serves the mobile 品质首检 form, the desktop 品质首检 PC variant, and the mobile 印刷大检 form. The 首检 doc records the first-piece inspection at the start of a run; on approval it not only freezes the inspection record but also flips `mftproductionplanslave.bFirst1Inspection` so the production-plan slave knows the first-piece check was passed.

**What it does:** Standard validate-and-flip — guards `sGuid`/`bInvalid`/`bCheck`, sets `bCheck=1, sStatus=1, sCheckPerson, tCheckDate=NOW()` on `QlyProcessTestMaster`. Joins `mftproductionplanslave` ← `plc_machinedata` ← `QlyProcessTestMaster` to mark `bFirst1Inspection=1` on the matching production-plan slave row, then (when configured) `INSERT INTO kpidetail` and `CALL`s the workflow hook. `iFlag=0` reverses both the master flags and the production-plan flag.

**Invocation:** Bound to `gdsmodule.sProcName` on:
- `品质首检(mobile单据)` (sId `12012615914116373957014740`) — 移动端管理 → 现场 → 功能操作
- `品质首检pc` (sId `101801153119616487115552840`) — 质量管理 → 过程质量控制(PQC)
- `印刷大检(mobile单据)` (sId `101801153119616509371170730`) — 移动端管理 → 现场 → 功能操作

Dispatched by `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)`. Auto-invoked from the mobile-side save path when the module's auto-audit flag is on (per the header note). Install scripts at `script/标版/30100101/Sp_Calc_sPct1.sql` and `script/标版/optimize/Sp_Calc_sPct1.sql`.
