# `Sp_WorkOrder_CalcDataPackStd` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(100)` |
| 2 | IN | `bChangeRate` | `int` |
| 3 | IN | `sLoginId` | `varchar(100)` |
| 4 | IN | `sBrId` | `varchar(100)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | OUT | `sCode` | `int` |
| 7 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 生产管理 / 生产工单 → 计算 (包装工单) — full-bill cost/quantity calculation for 包装 (packaging) work-orders. One of the four model-specific siblings of `Sp_WorkOrder_CalcDataStd`: `Pack` (包装), `Book` (书刊), `Set` (套装), `Flex` (柔印). Largest of the family (208KB body) — packaging has the richest control-row hierarchy (合版/拼版/sub-parts) and is where most customer-specific cost rules accumulate.

**What it does:** Operates on the `mftworkordermaster_Tmp` / `mftworkorderslave_Tmp` / `mftworkordercontrol_tmp` / `mftworkordermaterials_tmp` / `mftworkorderprocess_tmp` staging set keyed by `sGuid`+`sMakePerson`. Reads system constants (`CbxCorrugateWidth` etc. from `SysSystemSettings`), then runs the Product → Parts → Last pipeline inline (this is the all-in-one variant; the Java service prefers the split-proc variant via `WorkOrderCalcDataPackServiceImpl` for parallelism). Computes paper area, run-counts, loss qty, capacity hours, process money. Calls `Sp_Sis_GetConst` and `Sp_System_ReplaceField` (twice — one for normal, one for change-rate path).

**Invocation:** Dispatched by `Sp_Calc_sBgd` (生产工单 audit/calc entry) when the work-order's `sFormId='101251240115016002469445380'` (包装工单). Also enumerated in `CaclProNameEnum` (constant `pack`) for direct Java invocation when the split-proc orchestrator isn't used. Install script: `script/标版/30100101/Sp_WorkOrder_CalcDataPackStd.sql` plus optimisation patch in `script/标版/optimize/Sp_Calc_sBgd.sql`.
