feat(district): 新增 district.paper.position.detail.query 客户用纸详情工具 (REQ-20261012-0001)
- 纯 MySQL monthly_statistics,位置(厕位/厕墙)×日期分组 - 修复老接口整数除法截断 bug,厕墙人均改 null - 位置命名直查 positions/toilet,补行级权限 - 扁平 rows[] 输出,seed/文档登记
This commit is contained in:
@@ -819,6 +819,33 @@
|
||||
|
||||
---
|
||||
|
||||
## 33. district.paper.position.detail.query
|
||||
|
||||
客户用纸详情,复刻老系统 `POST /MonthlyStatistics/getMonthlyStatisticsPerPositionMap`
|
||||
(MonthlyStatisticsController :404-512),按 位置(厕位/厕墙)× 日期 输出用纸明细。
|
||||
|
||||
- 分类:district | 类型:读
|
||||
- 数据来源:m0 `monthly_statistics`(XXL-Job 预聚合日汇总),**纯 MySQL 不查 ES**;
|
||||
`statistics_time` 左闭右开 [startDate 00:00:00, endDate+1 00:00:00),可选 `buildingId/floor/toiletId/deviceType` 精确过滤,
|
||||
`positionMode`(position=仅厕位 `position_id>0` / wall=仅厕墙)对齐 statistics 工具语义,不沿用老 detail 接口 positionId 0/1 的混乱口径。
|
||||
- 入参:`districtId`(必填正整数)、`startDate`/`endDate`(必填 yyyy-MM-dd,startDate≤endDate≤今天);
|
||||
日期区间硬限 31 天(一个月,2026-09-24 拍板),且受 Redis `Dictionary.StatisticsDays` 限制,字典缺失 fail fast。
|
||||
- 返回扁平 `rows[]`:`date/locationType(position|wall)/positionId/toiletId/locationName/gender/genderText/`
|
||||
`snCodes/paperLengthMeters/useCount/perUseLengthMeters`;排序 date 升序、locationType、positionId/toiletId 升序。
|
||||
- 指标口径:`paperLengthMeters`=Σpaper_length/100(米,2 位小数,**全程 Double**——修老 :452 合并分支整数除法
|
||||
逐次截断 bug);`useCount`=Σuse_count **仅厕位行累计**(厕墙恒 0);`perUseLengthMeters`=paperLengthMeters/useCount
|
||||
(useCount=0 为 null,厕墙不适用而非老系统的硬编码 0.0);`snCodes`=组内 distinct sn_code 去重排序。
|
||||
- 维度字段恒在、不适用为 null:厕墙行 `positionId=null`;`gender` 透传库内原值,
|
||||
genderText 映射 0男卫/1女卫/2母婴/3残卫/4第三/5其他,99 及未知编码为 null。
|
||||
- 位置命名:直查 m0 `positions.memo`(回退 name)/ `toilet.no`(回退 name)批量富化(新增极简实体+Mapper,
|
||||
不读 Redis 实体缓存),查不到给"未知";无数据的 日期×位置 不出行、不补 0。
|
||||
- 行级权限:站点可见性沿用 `district.paper.statistics.query` 模式(id + soft_delete=0 + applyDistrictRowFilter),
|
||||
查不到统一抛 `站点不存在或无权访问`(老 detail 接口无行级权限,MCP 版补齐)。
|
||||
|
||||
详细设计见 `paper-position-detail-mcp-design.md`。
|
||||
|
||||
---
|
||||
|
||||
## 33. district.paper.percapita.query
|
||||
|
||||
查询站点人均用纸统计,覆盖老 `StatisticsReportController` 的五个接口。
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
# district.paper.position.detail.query 设计文档(客户用纸详情 MCP 工具)
|
||||
|
||||
> 状态:设计中(待评审)
|
||||
> 老接口:`POST /MonthlyStatistics/getMonthlyStatisticsPerPositionMap`(xiaoqu-franchisee
|
||||
> `MonthlyStatisticsController.java:404-512`,辅助方法 `putMonthStatistToDay` :863-883)
|
||||
> 姊妹工具:`district.paper.statistics.query`(客户用纸统计,已实现,复刻同 Controller 的
|
||||
> getMonthlyStatisticsMap;设计见 district-paper-statistics-design.md)
|
||||
|
||||
## 1. 定位
|
||||
|
||||
按站点查询**位置级(厕位/厕墙)× 日期**的用纸明细:每个位置每天用掉多少纸、多少人次、
|
||||
人均多少、涉及哪些设备 SN。面向 LLM 消费,返回扁平行数组,不搬老系统的嵌套 Map 结构。
|
||||
|
||||
## 2. 老系统口径复刻
|
||||
|
||||
- 表:m0 库 `monthly_statistics`(每站点每厕位/厕每天一行,XXL-Job 预聚合;实体
|
||||
`entity/m0/MonthlyStatistics.java` 已存在)。**纯 MySQL,不查 ES**——老接口的 ES 分支
|
||||
(`monthlyStatisticsESFlag` 开关走 monthly_statistics 索引)只是同一份预聚合数据的另一存储,
|
||||
MCP 统一走 DB(与 district.paper.percapita.query 一致)。
|
||||
- 过滤:`soft_delete=0`、`district_id` 精确必填、`statistics_time ∈ [startDate, endDate]`
|
||||
(实现为左闭右开 `[start, end+1)`);可选 `building_id/floor/toilet_id/device_type` 精确匹配。
|
||||
- 天数上限:Redis db5 `Dictionary` hash 的 `StatisticsDays`,超限抛 `查询时间段最大{N}天`
|
||||
(老 :412-423)。本工具不查 paperuselog,**无 LocalEsDate 冷热集群/跨界判断**。
|
||||
- 分组键:位置 = `position_id > 0` ? 厕位 `p-{positionId}` : 厕墙 `t-{toiletId}`(老 :437-442)。
|
||||
- 指标(每 位置×日期):
|
||||
- `paperLengthMeters` = Σpaper_length / 100(表内厘米→米,2 位小数)。
|
||||
⚠️ 修老 bug::452 合并分支 `paperLength / 100` 是**整数除法**,同位置同日多行时每次合并
|
||||
都截断到整米;MCP 版全程 Double 计算(:879 单行情景是 /100.0,无此问题)。
|
||||
- `useCount` = Σuse_count,**仅厕位行累计**(厕墙行表内恒 0,老 :454-456)。
|
||||
- `perUseLengthMeters` = paperLengthMeters / useCount(2 位小数);useCount=0 时为 **null**
|
||||
(老系统厕墙硬编码 0.0,:876——0 和"不适用"语义不同,按 LLM 输出铁律改 null)。
|
||||
- `snCodes` = distinct sn_code(老 :457-473 snmap)。
|
||||
- 位置命名:老系统读 Redis 实体缓存 `entity:Positions:{id}`.memo / `entity:Toilet:{id}`.no,
|
||||
缓存冷时显示"未知"(:486-497);MCP 改**直查 m0 positions/toilet 表**(新增极简实体+Mapper),
|
||||
查不到同样给"未知"。DB 比缓存更稳,且本服务无该缓存的写入端。
|
||||
|
||||
## 3. 工具契约
|
||||
|
||||
```
|
||||
district.paper.position.detail.query @XqTool(category="district", kind="read")
|
||||
```
|
||||
|
||||
| 参数 | 必填 | 说明 |
|
||||
|---|---|---|
|
||||
| districtId | 是 | 站点 id,正整数 |
|
||||
| startDate / endDate | 是 | yyyy-MM-dd,含当天;endDate 不得晚于今天;跨度 ≤ StatisticsDays |
|
||||
| positionMode | 否 | `position`=仅厕位、`wall`=仅厕墙,缺省不过滤(对齐 statistics 工具,**不沿用**老 input.positionId 0/1 的混乱语义——老 detail 接口 positionId=1 经 beanToWrapper 变 `eq position_id=1`,与统计接口的 `gt 0` 不一致) |
|
||||
| deviceType | 否 | 0=出纸机、1=擦手纸机 |
|
||||
| buildingId / floor / toiletId | 否 | 精确匹配 |
|
||||
|
||||
返回 `Map<String, Object>`(统一风格,无 DTO 类),**一种结构走天下**:
|
||||
|
||||
```json
|
||||
{
|
||||
"districtId": 12610,
|
||||
"districtName": "望京SOHO",
|
||||
"dateRange": {"start": "2026-09-01", "end": "2026-09-07"},
|
||||
"unit": "米/人次",
|
||||
"rows": [
|
||||
{
|
||||
"date": "2026-09-01",
|
||||
"locationType": "position",
|
||||
"positionId": 3456,
|
||||
"toiletId": 123,
|
||||
"locationName": "3层男卫1号位",
|
||||
"gender": 0,
|
||||
"genderText": "男卫",
|
||||
"snCodes": ["SN001", "SN002"],
|
||||
"paperLengthMeters": 45.6,
|
||||
"useCount": 38,
|
||||
"perUseLengthMeters": 1.2
|
||||
},
|
||||
{
|
||||
"date": "2026-09-01",
|
||||
"locationType": "wall",
|
||||
"positionId": null,
|
||||
"toiletId": 124,
|
||||
"locationName": "3层女卫",
|
||||
"gender": 1,
|
||||
"genderText": "女卫",
|
||||
"snCodes": ["SN003"],
|
||||
"paperLengthMeters": 12.3,
|
||||
"useCount": 0,
|
||||
"perUseLengthMeters": null
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
遵守 MCP 输出铁律(王恒 2026-09-22 确认):
|
||||
|
||||
- 扁平 `rows[]`,每行维度值+指标同对象自描述;不搬老系统
|
||||
`Map<位置拼接串, Map<日期, 指标>>` 嵌套结构,也不把 `memo(p-123)_sn1,sn2` 塞进 key。
|
||||
- 无数据的 日期×位置 **不出行**,不补 0.0(老系统只给前端已发生数据的 key,本就无补 0,
|
||||
此处语义保持一致)。
|
||||
- 透出原始度量(paperLengthMeters、useCount、snCodes),perUseLengthMeters 只是派生。
|
||||
- 维度字段恒在、不适用为 null:厕墙行 `positionId=null`;`gender` 为库内原值
|
||||
(0男/1女/2母婴/3残卫/4第三/5其他,99=无厕所,其他编码 genderText 为 null)。
|
||||
- 排序确定:date 升序,再 locationType、positionId/toiletId 升序(老系统按拼接 key 字典序
|
||||
倒序是给前端展示用,LLM 消费改为稳定正序)。
|
||||
|
||||
## 4. 权限
|
||||
|
||||
- 沿用 district.paper.statistics.query 模式:`district_district_strategy` eq id + soft_delete=0
|
||||
套 `PermissionService.applyDistrictRowFilter`,查不到抛 `站点不存在或无权访问`
|
||||
(老 detail 接口**无行级权限**,MCP 版补上,与 percapita 设计 §2 一致)。
|
||||
- scope 绑定:用户委托 + ops-query(生产惯例绑 scope 1/2/3/5),sync 不绑。
|
||||
|
||||
## 5. 与老系统的差异点(有意为之)
|
||||
|
||||
| 点 | 老系统 | 本工具 | 理由 |
|
||||
|---|---|---|---|
|
||||
| 返回结构 | 嵌套 Map,key 拼 `memo(p-123)_sn1,sn2` | 扁平 rows[] 结构化字段 | LLM 消费,免 key 解析 |
|
||||
| 多行合并用纸量 | 整数除法逐次截断(:452) | 全程 Double,末次 /100 | 修精度 bug |
|
||||
| 厕墙人均 | 硬编码 0.0 | null | 区分"0"与"不适用" |
|
||||
| 位置命名 | Redis 实体缓存,冷缓存=未知 | DB 直查 positions/toilet | 本服务无缓存写入端,DB 更稳 |
|
||||
| 位置过滤 | input.positionId 0/1,detail 接口语义有 bug | positionMode 枚举 | 与 statistics 工具统一 |
|
||||
| ES 分支 | monthlyStatisticsESFlag 走 ES 索引 | 纯 MySQL | 同一预聚合数据,DB 即可 |
|
||||
|
||||
## 6. 改动文件清单
|
||||
|
||||
1. 新建 `entity/m0/Positions.java`、`entity/m0/Toilet.java`(极简字段子集:Positions 取
|
||||
id/districtId/memo/name/softDelete;Toilet 取 id/districtId/no/name/gender/softDelete)
|
||||
+ `mapper/m0/PositionsMapper.java`、`ToiletMapper.java`(空接口继承 BaseMapper)。
|
||||
2. 新建 `mcp/tool/DistrictPaperPositionDetailTools.java`
|
||||
(@Component implements ToolObject,骨架照抄 DistrictPaperStatisticsTools.java:43-87;
|
||||
构造器注入 MonthlyStatisticsMapper/PositionsMapper/ToiletMapper/DistrictDistrictStrategyMapper/
|
||||
PermissionService/StringRedisTemplate)。
|
||||
3. 单测 `src/test/java/me/iiv/agent/mcp/tool/DistrictPaperPositionDetailToolsTest.java`
|
||||
(Mockito + AuthContextHolder.set(),参照 DistrictPaperStatisticsToolsTest)。
|
||||
4. `sql/seed-dev.sql` 加幂等 scope_tool 绑定(白名单制,须手工把工具名加进对应 scope 的
|
||||
IN 列表再跑 seed);生产上线后绑 scope 1/2/3/5。
|
||||
5. 登记 `doc/agent-mcp-tools-reference.md`。
|
||||
6. 装配层零改动(McpToolConfig 自动收集 ToolObject bean,ToolSyncService 自动同步 tool 表)。
|
||||
|
||||
## 7. 单测要点
|
||||
|
||||
- 参数校验:districtId 必填/正整数、日期格式、start≤end、endDate≤今天、positionMode 枚举、
|
||||
deviceType 0/1。
|
||||
- StatisticsDays 超限拒绝;字典缺失 fail fast。
|
||||
- 站点不可见 → `站点不存在或无权访问`。
|
||||
- 分组键:position_id>0 → position 行、=0 → wall 行;同位置同日多行合并(Double 精度,
|
||||
覆盖老整数除法 bug 的回归用例)。
|
||||
- useCount 仅厕位行累计;厕墙行 perUseLengthMeters=null。
|
||||
- snCodes 去重;locationName 从 positions.memo/toilet.no 富化,查不到给"未知"。
|
||||
- gender 透传与 genderText 映射(含 99/未知编码 → null)。
|
||||
- 无数据不出行(空结果 rows=[])。
|
||||
Reference in New Issue
Block a user