|
|
@@ -10,11 +10,10 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import shop.alien.entity.store.StoreCuisine;
|
|
|
import shop.alien.entity.store.StoreCuisineCombo;
|
|
|
-import shop.alien.entity.store.StoreInfo;
|
|
|
import shop.alien.entity.store.dto.CategoryGroupDto;
|
|
|
import shop.alien.entity.store.dto.CuisineComboDto;
|
|
|
-import shop.alien.entity.store.dto.CuisineDetailDto;
|
|
|
import shop.alien.entity.store.dto.CuisineItemDto;
|
|
|
+import shop.alien.entity.store.dto.CuisineTypeResponseDto;
|
|
|
import shop.alien.mapper.StoreCuisineMapper;
|
|
|
import shop.alien.mapper.StoreInfoMapper;
|
|
|
import shop.alien.store.service.StoreCuisineComboService;
|
|
|
@@ -116,46 +115,55 @@ public class StoreCuisineServiceImpl extends ServiceImpl<StoreCuisineMapper, Sto
|
|
|
return updateById(cuisine);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 根据 id 与类型获取详情:
|
|
|
+ * 根据 id 与类型获取详情(新格式):
|
|
|
* - type = 1:返回单品详情
|
|
|
* - type = 2:返回套餐详情(主信息 + 套餐包含的单品列表)
|
|
|
*/
|
|
|
@Override
|
|
|
- public CuisineDetailDto getByCuisineType(Integer id, Integer cuisineType) {
|
|
|
+ public CuisineTypeResponseDto getByCuisineTypeNew(Integer id, Integer cuisineType) {
|
|
|
// 1. 先查主表记录
|
|
|
StoreCuisine base = getById(id);
|
|
|
if (base == null) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- CuisineDetailDto dto = new CuisineDetailDto();
|
|
|
- dto.setBaseInfo(base);
|
|
|
-
|
|
|
- //查询当前门店套餐/单品列表 详情头部使用
|
|
|
- List<StoreCuisine> cuisineList = storeCuisineMapper.selectList(new LambdaQueryWrapper<StoreCuisine>().eq(StoreCuisine :: getStoreId, base.getStoreId()));
|
|
|
- dto.setStoreCuisineList(cuisineList);
|
|
|
-
|
|
|
- //查询门店手机号 门店名称
|
|
|
- StoreInfo storeInfo = storeInfoMapper.selectOne(new LambdaQueryWrapper<StoreInfo>().eq(StoreInfo :: getId, base.getStoreId()));
|
|
|
- if(storeInfo !=null){
|
|
|
- dto.setStorePhone(storeInfo.getStoreTel());
|
|
|
- dto.setStoreName(storeInfo.getStoreName());
|
|
|
- }
|
|
|
-
|
|
|
- // 单品:直接返回主信息,items 为空
|
|
|
+ CuisineTypeResponseDto response = new CuisineTypeResponseDto();
|
|
|
+ CuisineTypeResponseDto.CuisineTypeData data = new CuisineTypeResponseDto.CuisineTypeData();
|
|
|
+
|
|
|
+ // 填充基本信息
|
|
|
+ data.setCuisineType(base.getCuisineType());
|
|
|
+ data.setStoreId(base.getStoreId());
|
|
|
+ data.setName(base.getName());
|
|
|
+ data.setTotalPrice(base.getTotalPrice());
|
|
|
+ data.setImages(base.getImages());
|
|
|
+ data.setImageContent(base.getImageContent());
|
|
|
+ data.setDetailContent(base.getDetailContent());
|
|
|
+ data.setExtraNote(base.getExtraNote());
|
|
|
+ data.setNeedReserve(base.getNeedReserve());
|
|
|
+ data.setReserveRule(base.getReserveRule());
|
|
|
+ data.setPeopleLimit(base.getPeopleLimit());
|
|
|
+ data.setUsageRule(base.getUsageRule());
|
|
|
+ data.setRawJson(base.getRawJson());
|
|
|
+ // 单品:groupJson 为空,name 为单品名称
|
|
|
if (cuisineType != null && cuisineType == 1) {
|
|
|
- dto.setItems(Collections.emptyList());
|
|
|
- return dto;
|
|
|
+ response.setName(base.getName());
|
|
|
+ data.setGroupJson("");
|
|
|
+ response.setData(data);
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
- // 套餐:通过中间表查出包含哪些单品
|
|
|
+ // 套餐:通过中间表查出包含哪些单品,构建 groupJson
|
|
|
LambdaQueryWrapper<StoreCuisineCombo> comboWrapper = new LambdaQueryWrapper<>();
|
|
|
comboWrapper.eq(StoreCuisineCombo::getCid, id);
|
|
|
List<StoreCuisineCombo> combos = storeCuisineComboService.list(comboWrapper);
|
|
|
+
|
|
|
if (combos.isEmpty()) {
|
|
|
- dto.setItems(Collections.emptyList());
|
|
|
- return dto;
|
|
|
+ response.setName("套餐:" + base.getName());
|
|
|
+ data.setGroupJson("[]");
|
|
|
+ response.setData(data);
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
// 收集所有单品 sid
|
|
|
@@ -171,21 +179,54 @@ public class StoreCuisineServiceImpl extends ServiceImpl<StoreCuisineMapper, Sto
|
|
|
Map<Integer, StoreCuisine> singleMap = singles.stream()
|
|
|
.collect(Collectors.toMap(StoreCuisine::getId, s -> s));
|
|
|
|
|
|
- // 组装套餐明细
|
|
|
- List<CuisineDetailDto.CuisineItemDetail> itemDetails = new ArrayList<>();
|
|
|
- for (StoreCuisineCombo combo : combos) {
|
|
|
- StoreCuisine single = singleMap.get(combo.getSid());
|
|
|
- if (single == null) {
|
|
|
- continue;
|
|
|
+ // 按分类分组构建 CategoryGroupDto 列表
|
|
|
+ Map<String, List<StoreCuisineCombo>> categoryMap = combos.stream()
|
|
|
+ .collect(Collectors.groupingBy(StoreCuisineCombo::getCategory));
|
|
|
+
|
|
|
+ List<CategoryGroupDto> categoryGroups = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<StoreCuisineCombo>> entry : categoryMap.entrySet()) {
|
|
|
+ String categoryName = entry.getKey();
|
|
|
+ List<StoreCuisineCombo> categoryCombos = entry.getValue();
|
|
|
+
|
|
|
+ CategoryGroupDto group = new CategoryGroupDto();
|
|
|
+ group.setCategoryName(categoryName);
|
|
|
+
|
|
|
+ List<CuisineItemDto> items = new ArrayList<>();
|
|
|
+ for (StoreCuisineCombo combo : categoryCombos) {
|
|
|
+ StoreCuisine single = singleMap.get(combo.getSid());
|
|
|
+ if (single == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ CuisineItemDto item = new CuisineItemDto();
|
|
|
+ item.setCuisineId(single.getId());
|
|
|
+ item.setCuisineName(single.getName());
|
|
|
+ item.setQuantity(combo.getSnum());
|
|
|
+ item.setUnit("份");
|
|
|
+ items.add(item);
|
|
|
}
|
|
|
- CuisineDetailDto.CuisineItemDetail detail = new CuisineDetailDto.CuisineItemDetail();
|
|
|
- detail.setSingle(single);
|
|
|
- detail.setQuantity(combo.getSnum());
|
|
|
- detail.setCategory(combo.getCategory());
|
|
|
- itemDetails.add(detail);
|
|
|
+ group.setItems(items);
|
|
|
+ categoryGroups.add(group);
|
|
|
}
|
|
|
- dto.setItems(itemDetails);
|
|
|
- return dto;
|
|
|
+
|
|
|
+ // 将 CategoryGroupDto 列表转换为 JSON 字符串
|
|
|
+ String groupJson;
|
|
|
+ try {
|
|
|
+ groupJson = objectMapper.writeValueAsString(categoryGroups);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException("构建套餐组合 JSON 失败", e);
|
|
|
+ }
|
|
|
+ data.setGroupJson(groupJson);
|
|
|
+
|
|
|
+ // 构建 name 字段:套餐:{套餐名称}(引用上述{数量}个单品)
|
|
|
+ // 计算不同单品的数量(去重后的 sid 数量)
|
|
|
+ int singleCount = sidList.size();
|
|
|
+ String countText = singleCount == 2 ? "两个" : (singleCount == 3 ? "三个" : singleCount + "个");
|
|
|
+ response.setName("套餐:" + base.getName() + "(引用上述" + countText + "单品)");
|
|
|
+
|
|
|
+ response.setData(data);
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|