# `Sp_Do_ProcedurePageTree` (procedure)

> 过程插入20条数据后，获取分组，分页条数


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_sTmpTableName` | `varchar(1000)` |
| 2 | IN | `p_sSumTableName` | `longtext` |
| 3 | IN | `p_sTmpTableWhere` | `longtext` |
| 4 | IN | `p_sLimit` | `varchar(500)` |
| 5 | IN | `p_sTbNameBm` | `varchar(10)` |
| 6 | IN | `countCloumn` | `varchar(5000)` |
| 7 | IN | `p_sumCloumn` | `longtext` |
| 8 | OUT | `totalCount` | `int` |
| 9 | OUT | `countMapJson` | `longtext` |
| 10 | OUT | `p_sSumSql` | `longtext` |

## Body

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

## Narrative

**Business context:** Reporting infrastructure helper — the standard "page + total + column-sums" finisher invoked at the end of report procs that build their result-set inside a temporary table. Reports such as 销售管理 → 未发货明细 (`Sp_Sales_NotDeliverGoodList`), 生产管理 → 生产排程 (`Sp_Manufacture_ProductionArrange2`, `Sp_Manufacture_MftPlanPhase_product`) and 销售业绩 (`Sp_Sales_SalesAnalysiseOfSalesperson_copy1`) call it to honour the BACK grid's pagination, total-row and per-column aggregate UI.

**What it does:** Given a base temp table (`p_sTmpTableName`), an optional `p_sSumTableName`, a `WHERE` clause, a `LIMIT` clause, a per-table-bm prefix, a comma-list of `countCloumn`s and a JSON map `p_sumCloumn` of override SQLs, it: (1) for each requested aggregate column either uses the override SQL (running it via prepared statement when it contains `@sum`) or falls back to `SUM(<col>)` over the table, building `p_sumJson` as a `JSON_OBJECT`; (2) counts `totalCount` from the temp table after applying the WHERE; (3) builds the final paged SELECT (with `p_sLimit`) into the OUT param `p_sSumSql`; (4) returns the aggregate JSON in `countMapJson`. Stays generic so any report proc can plug in its result-set.

**Invocation:** Other-routine callers found in the live DB: `Sp_BillOfNoPicking_copy1`, `Sp_Manufacture_ProductionArrange2`, `Sp_Sales_NotDeliverGoodList`, `Sp_Sales_NotDeliverGoodListNew`, `Sp_Sales_SalesAnalysiseOfSalesperson_copy1`. xly-src additionally ships customer-override variants under `script/客户/无锡中江/`, `script/客户/千彩/` and `script/客户/朝阳/` that call it. Install body: `script/标版/30100101/Sp_Do_ProcedurePageTree.sql`. No direct Java caller — reports invoke it from inside their bodies.
