# `Sp_WorkOrder_CalcDataBsLastStd` (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 | IN | `p_sFormId` | `varchar(100)` |
| 7 | IN | `p_sCorrugateWidth` | `varchar(100)` |
| 8 | IN | `p_sCorrugateLength` | `varchar(100)` |
| 9 | IN | `p_dMinusLength` | `varchar(100)` |
| 10 | IN | `p_dMinusWidth` | `varchar(100)` |
| 11 | IN | `p_sModelsType` | `varchar(100)` |
| 12 | IN | `p_sSlaveGuid` | `varchar(100)` |
| 13 | IN | `p_sCustomerId` | `varchar(100)` |
| 14 | IN | `p_sProductId` | `varchar(100)` |
| 15 | IN | `p_tDeliverDate` | `datetime` |
| 16 | OUT | `sCode` | `int` |
| 17 | OUT | `sReturn` | `varchar(5000)` |

## Body

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

## Narrative

**Business context:** 商务工单 → 计算 → 收尾阶段 (商务工单计算材料部分) — final/aggregation phase of the 商务 (business / non-packaging) work-order cost calc. Sibling of `Sp_WorkOrder_CalcDataPackLastStd`; both are the "Last" stage in the Java orchestrator's `Product → PartsStd → LastStd` pipeline. Runs after every parts/process row is computed, collapsing the per-part figures into the master totals.

**What it does:** Operates on `mftworkordermaster_Tmp`/`mftworkorderslave_Tmp`/`mftworkordercontrol_tmp`/`mftworkordermaterials_tmp`/`mftworkorderprocess_tmp` keyed by `sGuid`+`sMakePerson`. Receives all calc context as IN parameters (corrugate dimensions, models type, slave/customer/product/delivery-date) — no re-reading of `SysSystemSettings`. Updates the staging master/slave/control/materials/process tables with summed costs, totalled paper area, finalised process money, capacity hours. Returns the calc result via `sCode`/`sReturn`.

**Invocation:** Called by `WorkOrderCalcDataPackServiceImpl.doCalcDataPackStd()` as the `Sp_WorkOrder_CalcLastStd` slot when the orchestrator runs in 商务 mode (it points `Sp_WorkOrder_CalcLastStd = Sp_WorkOrder_CalcDataBsLastStd`). Called by the Java service after `Sp_WorkOrder_CalcDataBsProductStd` (before) and per-control `Sp_WorkOrder_CalcDataBsPartsStd` loops. Install script: `script/标版/30100101/Sp_WorkOrder_CalcDataBsLastStd.sql`.
