# `Sp_WorkOrder_CopyToWorkOrderData` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(100)` |
| 2 | IN | `sConfigId` | `varchar(100)` |
| 3 | IN | `sControlName` | `varchar(100)` |
| 4 | IN | `sLoginId` | `varchar(100)` |
| 5 | IN | `sBrId` | `varchar(100)` |
| 6 | IN | `sSuId` | `varchar(100)` |

## Body

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

## Narrative

**Business context:** 制造 → 工单 — "Copy product-card data into the in-progress 工单" helper. Behind the 工单 editor's "拷贝工艺" / "套用工艺卡" action: after the user picks customer + product rows on the 工单 slave, this proc fills the slave's `sProductTechnologyId` and explodes the chosen `mftproduct` cards into the 工单 control / materials / process / color slots.

**What it does:** Operates entirely on the `mftworkorder*_tmp` family (session-scoped by `sParentId=sGuid AND sMakePerson=sLoginId AND sBrandsId/sSubsidiaryId`). First ranks the latest `viw_mftproduct.bCheck=1` rows per (sCustomerId, sProductId) and `UPDATE`s `mftworkorderslave_tmp.sProductTechnologyId` to the most recent product-card sId. Then groups `mftproductmaterials` rows by parts (`sType='0'`) and uses cursors to fan out `mftproductmaterials` / `mftproductprocess` / `mftproductcontrolcombine` etc. into `mftworkordermaterials_tmp` / `mftworkorderprocess_tmp` / `mftworkordercontrol_tmp` keyed by the new control ids it generates via `NewId()`.

**Invocation:** Called from Java by `BusinessBaseServiceImpl.getCopyToWorkOrderData(Map)`, which builds and runs `call Sp_WorkOrder_CopyToWorkOrderData(?, sConfigId, sControlName, sMakePerson, sBrId, sSuId)` via `businessBaseDao.getByStringSql()`. The HTTP entry is `BusinessBaseController` POST `/getCopyToWorkOrderData`. Not bound on `gdsmodule` or `gdsconfigformmaster` — the dispatch is Java-side, fired by the 工单 拷贝/套用 button.
