11
This commit is contained in:
1 parent
ccc40fc6e1
commit
849e9c584e
3 files changed
+11
-8
No files matched your search
+4
-2
@@ -7,7 +7,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户预约按餐段和菜品快照聚合的统计数据。
|
||||
* 用户预约按餐段、商品 ID 和下单菜品名称快照聚合的统计数据。
|
||||
*
|
||||
* <p>商品 ID 相同但名称快照不同的历史订单会拆分展示,避免商品 ID 被菜谱复用后串入错误名称。</p>
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "食堂用户预约菜品统计")
|
||||
@@ -21,7 +23,7 @@ public class HardCanteenUserApptDishStatisticsVo {
|
||||
@Schema(description = "菜品名称")
|
||||
private String productName;
|
||||
|
||||
/** 当前菜品统计项实际涉及的商品 ID;正常数据仅有一个,历史商品 ID 为空时不写入集合。 */
|
||||
/** 当前名称快照统计项实际涉及的商品 ID;正常数据仅有一个,历史商品 ID 为空时不写入集合。 */
|
||||
@Schema(description = "商品ID集合")
|
||||
private List<Long> productIds = new ArrayList<>();
|
||||
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public class HardCanteenUserApptStatisticsSummaryVo {
|
||||
@Schema(description = "餐段统计")
|
||||
private List<HardCanteenUserApptMealStatisticsVo> meals = new ArrayList<>();
|
||||
|
||||
/** 按餐段和商品 ID 聚合的菜品份数;历史商品 ID 缺失时按菜品名称兜底。 */
|
||||
/** 按餐段、商品 ID 和下单名称快照聚合的菜品份数;历史商品 ID 缺失时按菜品名称兜底。 */
|
||||
@Schema(description = "菜品统计")
|
||||
private List<HardCanteenUserApptDishStatisticsVo> dishes = new ArrayList<>();
|
||||
}
|
||||
+6
-5
@@ -1076,7 +1076,7 @@ public class HardCanteenApptTotalServiceImpl implements HardCanteenApptTotalServ
|
||||
/** 餐段编码到餐段聚合结果的有序映射。 */
|
||||
private final Map<String, MealStatisticsAccumulator> meals = new LinkedHashMap<>();
|
||||
|
||||
/** 餐段和商品身份到菜品聚合结果的有序映射;商品 ID 缺失时使用名称兼容历史数据。 */
|
||||
/** 餐段、商品 ID 和名称快照到菜品聚合结果的有序映射;商品 ID 缺失时仅使用名称兼容历史数据。 */
|
||||
private final Map<String, DishStatisticsAccumulator> dishes = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
@@ -1120,15 +1120,16 @@ public class HardCanteenApptTotalServiceImpl implements HardCanteenApptTotalServ
|
||||
dishCount += count;
|
||||
meal.dishCount += count;
|
||||
String productName = normalize(car.getProductName(), "未命名菜品");
|
||||
// 同一商品的历史名称快照可能带有空格或不可见字符,优先按商品 ID 聚合可避免页面出现同 ID 重复行。
|
||||
String productKey = car.getProductId() == null ? "name:" + productName : "id:" + car.getProductId();
|
||||
String dishKey = hourType + "\u0000" + productKey;
|
||||
// 商品 ID 可能被后续菜谱复用,名称快照必须同时参与分组,避免历史菜品被错误并入当前名称。
|
||||
String productIdentityKey = car.getProductId() == null ? "name" : "id:" + car.getProductId();
|
||||
String productNameKey = StrUtil.cleanBlank(productName);
|
||||
String dishKey = hourType + "\u0000" + productIdentityKey + "\u0000" + productNameKey;
|
||||
DishStatisticsAccumulator dish = dishes.computeIfAbsent(dishKey,
|
||||
key -> new DishStatisticsAccumulator(hourType, productName, car.getProductPic()));
|
||||
if (car.getProductId() != null) {
|
||||
dish.productIds.add(car.getProductId());
|
||||
}
|
||||
// 同餐段同名菜品合并时优先保留首个非空快照图片,兼容早期订单未保存图片的情况。
|
||||
// 同餐段、同商品和同名称快照合并时优先保留首个非空图片,兼容早期订单未保存图片的情况。
|
||||
if (StrUtil.isBlank(dish.productPic) && StrUtil.isNotBlank(car.getProductPic())) {
|
||||
dish.productPic = car.getProductPic();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user