# `Sp_PC_PatrolInspection` (procedure)

> @author:zhucx
							
							@date:20211108 封存
							
							@describe: PC 质量管理-过程检验PQC-巡检任务列表 / 移动端-过程巡检


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iState` | `int` |
| 2 | IN | `sLoginId` | `varchar(100)` |
| 3 | IN | `sMachineId_s` | `varchar(100)` |
| 4 | IN | `sProceeAllMachine` | `varchar(10)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | IN | `sBrId` | `varchar(100)` |
| 7 | IN | `bFilter` | `longtext` |
| 8 | IN | `sUnTaskFormId` | `varchar(100)` |
| 9 | IN | `pageNum` | `int` |
| 10 | IN | `pageSize` | `int` |
| 11 | OUT | `totalCount` | `int` |
| 12 | IN | `countCloumn` | `varchar(5000)` |
| 13 | OUT | `countMapJson` | `longtext` |
| 14 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 15 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 16 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 质量管理 → 过程质量控制(PQC) → 巡检任务列表 (and 移动端管理 → 现场 → 过程巡检) — paged worklist of machines/orders currently awaiting an in-process patrol inspection (巡检). The PC desktop and mobile clients both feed off this result. Body comment is dated `20211108 封存` (sealed/legacy) but the form binding is still live.

**What it does:** Builds a temp table `p_Tmp_ProductionReport` from `mftProductionPlanSlave` rows that have started (`sState in (1,2)`), still have qty remaining (`dProcessQty > dProductionReportQty`), and intersect `plc_machinedata`. Joins `EleTestStandard` + `eleteststandardobject` (form `12012615914116374914703890`) to attach the test-standard name and the patrol interval `dQualifyRate`; computes `tThisPatrolInspection` (= last-first-inspection-or-patrol + interval minutes) and a 状态 label `已首检 / 未首检 / 超期未巡检 / N分内巡检 / 未到巡检时间`. Honours `SysSystemSettings.CkxProcessFilter` + `Fun_GetLookProcess` for process-level row-level security.

**Invocation:** Bound as the data-source on two `gdsconfigformmaster` forms via `sSqlStr`:
- `过程巡检` (sId `12012615914116371305494760`) under 移动端管理 → 现场
- `巡检任务列表` (sId `12012615914116372379422240`) under 质量管理 → 过程质量控制(PQC)

Loaded when either form opens. Install script: `script/标版/30100101/Sp_PC_PatrolInspection.sql`; an older variant lives in `script/标版/20210323/optimizeprocedure.sql`.
