修复我的页统计空作品报错

This commit is contained in:
2026-07-24 22:17:30 +08:00
parent 3857065262
commit f4937b2dc2
2 changed files with 13 additions and 1 deletions
@@ -328,6 +328,7 @@ public class DashboardController {
List<Map<String, Object>> productOrderCounts = orderItemMapper.selectMaps(
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<OrderItemDO>()
.select("product_id, COUNT(*) as order_count")
.isNotNull("product_id")
.groupBy("product_id")
.orderByDesc("order_count")
.last("LIMIT 5")
@@ -337,7 +338,11 @@ public class DashboardController {
// 遍历查询结果,获取商品详情
for (Map<String, Object> map : productOrderCounts) {
Long productId = Long.valueOf(map.get("product_id").toString());
Object productIdValue = map.get("product_id");
if (productIdValue == null) {
continue;
}
Long productId = Long.valueOf(productIdValue.toString());
ProductDO product = productMapper.selectById(productId);
if (product != null && (shopId == null || shopId.equals(product.getShopId()))) {
+7
View File
@@ -516,3 +516,10 @@
- 影响范围:仅影响 `JY-Salon-WeChat/api/dashboard.js`、`pages/profile/`、`pages/profile-settings/` 和相关设计文档;不修改店铺设置页面已有改动。
- 验证方式:相关 JS 语法检查通过;修改文件 UTF-8 BOM 检查通过;`git diff --check` 无实质错误;微信开发者工具自动化已确认连接项目为 `JY-Salon-WeChat`,但当前 AppService 未重新编译,运行态页面仍读取旧 data,需在开发者工具中手动编译或重启后复测。
- 追加修正:根据用户反馈,“我的管理”和“设置与帮助”入口改为 WXML 静态完整渲染,恢复设计图中的 4 个管理入口和 5 个设置帮助入口,避免运行态 JS data 未刷新时入口缺失;微信开发者工具 CLI `preview` 已重新编译通过。
## 2026-07-24 店务小程序我的页统计接口空作品 ID 报错修复
- 变更原因:店务小程序进入“我的”页时新增经营统计会调用 `/admin/dashboard/stats`,历史手工预约或订单项可能没有关联 `product_id`,后端热销作品统计直接执行 `map.get("product_id").toString()` 导致接口返回 Java 空值异常,并在小程序端弹出技术错误。
- 处理方式:`DashboardController.getHotProducts` 的订单项聚合查询增加 `product_id IS NOT NULL` 条件,并在解析 `product_id` 前保留空值短路,确保没有关联作品的订单项不参与“热销作品”统计,也不会影响今日订单、今日收入等其它统计字段。
- 数据库说明:本次不新增 SQL,不修改初始化 SQL,不需要执行数据库迁移。
- 影响范围:仅影响 `JY-Core` 的 `/admin/dashboard/stats` 热销作品统计分支;不改变订单、预约、作品、店铺和小程序页面字段契约。
- 验证方式:GitNexus `getHotProducts` upstream impact 为 LOW,直接调用方为 `buildDashboardStats`,上游接口为 `getDashboardStats`;`rtk mvn -f JY-Core/pom.xml -DskipTests compile` 通过。