|
|
@@ -1,17 +1,23 @@
|
|
|
package com.ruoyi.app.mendian;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.app.utils.DateUtil;
|
|
|
+import com.ruoyi.app.user.dto.StoreOutput;
|
|
|
import com.ruoyi.system.domain.OperatingHours;
|
|
|
+import com.ruoyi.system.domain.PosFood;
|
|
|
import com.ruoyi.system.domain.PosOrder;
|
|
|
import com.ruoyi.system.domain.PosReview;
|
|
|
import com.ruoyi.system.domain.PosStore;
|
|
|
+import com.ruoyi.system.mapper.PosFoodMapper;
|
|
|
import com.ruoyi.system.service.IOperatingHoursService;
|
|
|
import com.ruoyi.system.service.IPosOrderService;
|
|
|
import com.ruoyi.system.service.IPosReviewService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -26,6 +32,8 @@ public class PosStoreEnrichService {
|
|
|
private IPosOrderService posOrderService;
|
|
|
@Autowired
|
|
|
private IOperatingHoursService operatingHoursService;
|
|
|
+ @Autowired
|
|
|
+ private PosFoodMapper posFoodMapper;
|
|
|
|
|
|
/**
|
|
|
* 为门店列表设置评分、月售、营业状态。
|
|
|
@@ -99,4 +107,48 @@ public class PosStoreEnrichService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将门店列表转换为带商品列表的分页结构(StoreOutput)。
|
|
|
+ */
|
|
|
+ public Page<StoreOutput> buildStoreOutputPage(List<PosStore> storeList, String language, int page, long total) {
|
|
|
+ String lang = toLangCode(language);
|
|
|
+ List<Integer> storeIds = storeList.stream()
|
|
|
+ .map(PosStore::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Integer, List<PosFood>> foodMap = new java.util.HashMap<>();
|
|
|
+ if (!storeIds.isEmpty()) {
|
|
|
+ List<Long> storeIdsLong = storeIds.stream()
|
|
|
+ .map(Integer::longValue)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<PosFood> allFoods = posFoodMapper.selectFoodsByStoreIdsWithLimit(storeIdsLong, lang, 6);
|
|
|
+ foodMap = allFoods.stream()
|
|
|
+ .collect(Collectors.groupingBy(food -> food.getMdid().intValue()));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<StoreOutput> storeOutputList = new ArrayList<>();
|
|
|
+ for (PosStore store : storeList) {
|
|
|
+ StoreOutput storeOutput = new StoreOutput();
|
|
|
+ BeanUtils.copyProperties(store, storeOutput);
|
|
|
+ List<PosFood> foodList = foodMap.getOrDefault(store.getId(), new ArrayList<>());
|
|
|
+ storeOutput.setFoodList(foodList);
|
|
|
+ storeOutputList.add(storeOutput);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<StoreOutput> result = new Page<>(page, 10);
|
|
|
+ result.setTotal(total);
|
|
|
+ result.setRecords(storeOutputList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String toLangCode(String language) {
|
|
|
+ if ("zh-CN".equals(language)) {
|
|
|
+ return "2";
|
|
|
+ }
|
|
|
+ if ("en-US".equals(language)) {
|
|
|
+ return "1";
|
|
|
+ }
|
|
|
+ return "3";
|
|
|
+ }
|
|
|
}
|