# `sp_getErpPlanData_before` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | OUT | `sSql` | `longtext` |
| 2 | OUT | `sReturn` | `longtext` |
| 3 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** Customer-specific (高旺 / Gao Wang) integration export — pushes ERP plan rows out to the customer's external SQL Server `lxfmac` table. This is the "before" hook of a paired before/after dispatcher; it composes the upstream INSERT-template SQL string and returns the pending plan rows from `lxfmac` where `iStatus = 0` (not yet pushed). The "after" companion `sp_getErpPlanData_after` (called by the same Java) marks them shipped.

**What it does:** Sets `sCode = 1`, `sReturn = "操作成功"`. Builds `sSql` as a parametrised SQL Server INSERT statement (using MyBatis `#{...}` placeholders) targeting `lxfmac (ORDER_NO, MAC_NO, CUST_NO, CUST_SHORT, CZ_NO, CZ_NO_P, PAPER_NO1..5, KB, PROD_WMM, PROD_HMM, PROD_YA1..3, OR_OQTY, PL_OQTY, INS_TYPE)`. Then returns the resultset to push: `SELECT sId, IFNULL(ORDER_NO,'') AS ORDER_NO, …, IFNULL(INS_TYPE,'') AS INS_TYPE FROM lxfmac WHERE IFNULL(iStatus, 0) = 0`. The Java driver iterates each row, calls `slaveBaseDao.insertByMap(m)` against the SQL Server datasource, and collects the dispatched `sId` set for the "after" call.

**Invocation:** Called by `GwServiceImpl.tbsjCron()` ("高旺个性化需求", per the matching `ErpJobRunStatus.tbsjCron` comment) through `procedureService.getDoProMap("sp_getErpPlanData_before", …)` + `procedureService.getCallPro(…)`. The cron itself is declared in `ScheduledTasks.java` as `@Scheduled(cron="${gw.tbsjCron}")` but **commented out** in the deployed version — the integration is dormant. Re-enable by un-commenting the scheduler stanza in `ScheduledTasks.tbsjCron`.
