|
|
@@ -1,6 +1,12 @@
|
|
|
package com.ruoyi.app.mendian;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.ruoyi.app.user.dto.StoreOutput;
|
|
|
+import com.ruoyi.system.mapper.PosFoodMapper;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
|
|
@@ -16,6 +22,7 @@ import com.ruoyi.system.domain.PosStore;
|
|
|
import com.ruoyi.system.service.IPosStoreService;
|
|
|
import com.ruoyi.system.utils.Auth;
|
|
|
import com.ruoyi.system.utils.JwtUtil;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@@ -42,6 +49,8 @@ public class PosCollectController extends BaseController
|
|
|
private IPosCollectService posCollectService;
|
|
|
@Autowired
|
|
|
private IPosStoreService posStoreService;
|
|
|
+ @Autowired
|
|
|
+ private PosFoodMapper posFoodMapper;
|
|
|
/**
|
|
|
* 我的收藏门店列表
|
|
|
*/
|
|
|
@@ -53,43 +62,51 @@ public class PosCollectController extends BaseController
|
|
|
@RequestParam Integer size){
|
|
|
JwtUtil jwtUtil = new JwtUtil();
|
|
|
String id = jwtUtil.getusid(token);
|
|
|
- IPage<PosCollect> food = new Page<>(page,size);
|
|
|
+ IPage<PosCollect> pageInput = new Page<>(page,size);
|
|
|
QueryWrapper<PosCollect> queryWrapper= new QueryWrapper<>();
|
|
|
queryWrapper.eq("user_id",id);
|
|
|
- IPage<PosCollect> list = posCollectService.page(food,queryWrapper);
|
|
|
+ IPage<PosCollect> list = posCollectService.page(pageInput,queryWrapper);
|
|
|
List<PosCollect> pos = list.getRecords();
|
|
|
- JSONArray all = new JSONArray();
|
|
|
- for(PosCollect col:pos){
|
|
|
- JSONObject org = new JSONObject();
|
|
|
- PosStore posStore = posStoreService.getById(col.getMdId());
|
|
|
- if(posStore!=null){
|
|
|
- org.put("id",posStore.getId());
|
|
|
- org.put("posName",posStore.getPosName());
|
|
|
- org.put("image",posStore.getImage());
|
|
|
- org.put("posPrice",posStore.getPosPrice());
|
|
|
- org.put("area",posStore.getArea());
|
|
|
- org.put("address",posStore.getAddress());
|
|
|
- org.put("longitude",posStore.getLongitude());
|
|
|
- org.put("latitude",posStore.getLatitude());
|
|
|
- org.put("briefIntroduction",posStore.getBriefIntroduction());
|
|
|
- org.put("type",posStore.getType());
|
|
|
- org.put("hygienePermit",posStore.getHygienePermit());
|
|
|
- org.put("openBusiness",posStore.getOpenBusiness());
|
|
|
- org.put("windingUp",posStore.getWindingUp());
|
|
|
- org.put("sort",posStore.getSort());
|
|
|
- org.put("userId",posStore.getUserId());
|
|
|
- org.put("juli",posStore.getJuli());
|
|
|
- org.put("cretim",posStore.getCretim());
|
|
|
- org.put("zhitsj",posStore.getJuli());
|
|
|
- org.put("tgpaixv",posStore.getCretim());
|
|
|
- org.put("state",posStore.getState());
|
|
|
- org.put("serverType",posStore.getServerType());
|
|
|
- org.put("telephone",posStore.getTelephone());
|
|
|
- org.put("offShelf",posStore.getOffShelf());
|
|
|
- all.add(org);
|
|
|
+
|
|
|
+ // 收集所有门店ID(Integer类型)
|
|
|
+ List<Long> storeIds = pos.stream()
|
|
|
+ .map(PosCollect::getMdId)
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ // 使用MyBatis Plus一次性查询所有门店的商品(避免N+1查询问题)
|
|
|
+ Map<Integer, List<PosFood>> foodMap = new java.util.HashMap<>();
|
|
|
+ if (!storeIds.isEmpty()) {
|
|
|
+ // 将Integer类型的门店ID转换为Long类型用于查询(因为mdid是Long类型)
|
|
|
+ List<Long> storeIdsLong = storeIds.stream()
|
|
|
+ .map(x->x)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 使用MyBatis Plus的Mapper方法,在数据库查询时就限制每个门店只返回6条商品
|
|
|
+ List<PosFood> allFoods = posFoodMapper.selectFoodsByStoreIdsWithLimit(storeIdsLong, "3", 6);
|
|
|
+
|
|
|
+ // 按门店ID分组(查询结果已经限制为每个门店最多6条)
|
|
|
+ foodMap = allFoods.stream()
|
|
|
+ .collect(Collectors.groupingBy(food -> food.getMdid().intValue()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为StoreOutput并设置每个门店的商品列表(每个门店最多6条)
|
|
|
+ List<StoreOutput> storeOutputList = new ArrayList<>();
|
|
|
+ for (PosCollect collect : pos) {
|
|
|
+ PosStore store=posStoreService.getById(collect.getMdId());
|
|
|
+ if(store!=null){
|
|
|
+ StoreOutput storeOutput = new StoreOutput();
|
|
|
+ // 复制PosStore的所有属性
|
|
|
+ BeanUtils.copyProperties(store, storeOutput);
|
|
|
+ // 从分组结果中获取该门店的商品列表(已限制为最多6条)
|
|
|
+ List<PosFood> foodList = foodMap.getOrDefault(store.getId(), new ArrayList<>());
|
|
|
+ storeOutput.setFoodList(foodList);
|
|
|
+ storeOutputList.add(storeOutput);
|
|
|
}
|
|
|
}
|
|
|
- return success(all);
|
|
|
+ Page<StoreOutput> result = new Page<>(page, 10);
|
|
|
+ result.setTotal(list.getTotal());
|
|
|
+ result.setRecords(storeOutputList);
|
|
|
+ return success(result);
|
|
|
}
|
|
|
|
|
|
/**
|