Jelajahi Sumber

1、修改我的收藏、我的足迹方法

qmj 4 hari lalu
induk
melakukan
fa8a4523df

+ 1 - 1
foodie_sj_vue/.env.production

@@ -1,3 +1,3 @@
 ENV  = 'production'
-#VUE_APP_BASE_API='https://api.fooder.tw'
+VUE_APP_BASE_API='https://api.fooder.tw'
 VUE_APP_BACKEND_URL='https://backend.fooder.tw/prod-api/'

+ 3 - 3
foodie_sj_vue/src/components/googmap.vue

@@ -68,8 +68,8 @@ export default {
       type: Object,
       default: () => {
         return {
-          lat: 21.031859020043132,
-          lng:105.82760815495604
+          lat: 25.037798,
+          lng: 121.565170
         }
       },
     },
@@ -91,7 +91,7 @@ export default {
   data() {
     return {
       //地图选点回显值
-      longlat: 21.031859020043132 + ',' + 105.82760815495604,
+      longlat: 25.037798 + ',' + 121.565170,
       //标记点
       marker: [],
       //图形实例

+ 1 - 1
foodie_sj_vue/src/views/AcidrollingCapacity.vue

@@ -239,7 +239,7 @@ import {
 		},
 		data(){
 			return {
-				seruer: process.env.VUE_APP_BASE_URL,
+				seruer: process.env.VUE_APP_BASE_API,
 				loding:false,
 				tableData:[],
 				total:0,

+ 49 - 32
ruoyi-admin/src/main/java/com/ruoyi/app/mendian/PosCollectController.java

@@ -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);
     }
 
     /**

+ 3 - 0
ruoyi-admin/src/main/java/com/ruoyi/app/mendian/PosFoodController.java

@@ -30,6 +30,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import jakarta.servlet.http.HttpServletResponse;
+
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -57,6 +59,7 @@ public class PosFoodController extends BaseController {
     @Autowired //用户
     private IInfoUserService infoUserService;
 
+
     //删除商品
     @Anonymous
     @Auth

+ 44 - 11
ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderController.java

@@ -17,6 +17,7 @@ import com.ruoyi.app.order.dto.PositionDto;
 import com.ruoyi.app.order.dto.QsDto;
 import com.ruoyi.app.pay.PayController;
 import com.ruoyi.app.service.WalletService;
+import com.ruoyi.app.user.dto.StoreOutput;
 import com.ruoyi.app.utils.DateUtil;
 import com.ruoyi.app.utils.PayPush;
 import com.ruoyi.app.utils.event.PushEventService;
@@ -35,6 +36,7 @@ import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.system.domain.*;
 import com.ruoyi.system.domain.vo.OrderDTO;
+import com.ruoyi.system.mapper.PosFoodMapper;
 import com.ruoyi.system.mapper.PosOrderMapper;
 import com.ruoyi.system.mapper.RiderPositionMapper;
 import com.ruoyi.system.mapper.UserBillingMapper;
@@ -44,6 +46,7 @@ import com.ruoyi.system.utils.GetArea;
 import com.ruoyi.system.utils.JwtUtil;
 import lombok.SneakyThrows;
 import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Isolation;
@@ -116,6 +119,8 @@ public class PosOrderController extends BaseController {
     private IOrderParentService orderParentService;
     @Autowired
     private WalletService walletService;
+    @Autowired
+    private PosFoodMapper posFoodMapper;
 
 
     //查询用户足迹
@@ -130,18 +135,46 @@ public class PosOrderController extends BaseController {
         queryWrapper.select().orderByDesc("cretim");
         queryWrapper.eq("user_id", id);
         IPage<UserFootprint> list = userFootprintService.page(palist, queryWrapper);
-        List<UserFootprint> orlist = list.getRecords();
-        JSONArray arr = new JSONArray();
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        for (int i = 0; i < orlist.size(); i++) {
-            JSONObject org = new JSONObject();
-            org.put("id", orlist.get(i).getId());
-            org.put("user", infoUserService.selectInfoUserByUserId(orlist.get(i).getUserId()));
-            org.put("store", posStoreService.getById(orlist.get(i).getMdId()));
-            org.put("cretim", sdf.format(orlist.get(i).getId()));
-            arr.add(org);
+        List<UserFootprint> footprints = list.getRecords();
+        // 收集所有门店ID(Integer类型)
+        List<Long> storeIds = footprints.stream()
+                .map(UserFootprint::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 (UserFootprint collect : footprints) {
+            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(arr);
+        Page<StoreOutput> result = new Page<>(page, 10);
+        result.setTotal(list.getTotal());
+        result.setRecords(storeOutputList);
+        return success(result);
     }
 
 

+ 29 - 8
ruoyi-admin/src/main/java/com/ruoyi/app/user/UserAppIndexController.java

@@ -12,6 +12,7 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.domain.*;
 import com.ruoyi.system.mapper.PosStoreMapper;
+import com.ruoyi.system.mapper.PosFoodMapper;
 import com.ruoyi.system.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -23,6 +24,7 @@ import java.math.BigDecimal;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import com.ruoyi.system.mapper.PosOrderMapper;
 import com.ruoyi.app.user.dto.StoreOutput;
@@ -51,6 +53,8 @@ public class UserAppIndexController extends BaseController {
     @Autowired
     private PosStoreMapper posStoreMapper;
     @Autowired
+    private PosFoodMapper posFoodMapper;
+    @Autowired
     private IInfoUserService infoUserService;
 
     /**
@@ -96,19 +100,36 @@ public class UserAppIndexController extends BaseController {
         if ("en-US".equals(language)) {
             lang = "1";
         }
-        // 转换为StoreOutput并查询每个门店的商品列表
+        
+        // 收集所有门店ID(Integer类型)
+        List<Integer> storeIds = storeList.stream()
+                .map(PosStore::getId)
+                .collect(Collectors.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(Integer::longValue)
+                    .collect(Collectors.toList());
+            
+            // 使用MyBatis Plus的Mapper方法,在数据库查询时就限制每个门店只返回6条商品
+            List<PosFood> allFoods = posFoodMapper.selectFoodsByStoreIdsWithLimit(storeIdsLong, lang, 6);
+            
+            // 按门店ID分组(查询结果已经限制为每个门店最多6条)
+            foodMap = allFoods.stream()
+                    .collect(Collectors.groupingBy(food -> food.getMdid().intValue()));
+        }
+        
+        // 转换为StoreOutput并设置每个门店的商品列表(每个门店最多6条)
         List<StoreOutput> storeOutputList = new ArrayList<>();
         for (PosStore store : storeList) {
             StoreOutput storeOutput = new StoreOutput();
             // 复制PosStore的所有属性
             BeanUtils.copyProperties(store, storeOutput);
-            // 查询门店的商品列表
-            LambdaQueryWrapper<PosFood> foodWrapper = new LambdaQueryWrapper<>();
-            foodWrapper.eq(PosFood::getMdid, store.getId());
-            foodWrapper.eq(PosFood::getToExamine, "1");
-            foodWrapper.eq(PosFood::getLanguage, lang);
-            foodWrapper.last("limit 6");
-            List<PosFood> foodList = posFoodService.list(foodWrapper);
+            // 从分组结果中获取该门店的商品列表(已限制为最多6条)
+            List<PosFood> foodList = foodMap.getOrDefault(store.getId(), new ArrayList<>());
             storeOutput.setFoodList(foodList);
             storeOutputList.add(storeOutput);
         }

+ 28 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PosFoodMapper.java

@@ -4,6 +4,7 @@ import java.util.Date;
 import java.util.List;
 
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.system.domain.PosFood;
@@ -70,4 +71,31 @@ public interface PosFoodMapper  extends BaseMapper<PosFood>
      * @return 结果
      */
     public int countPosFoodByCreatedAt(@Param("createdAt") Date createdAt);
+
+    /**
+     * 查询多个门店的商品,每个门店最多返回指定数量的商品(使用窗口函数)
+     * @param storeIds 门店ID列表
+     * @param language 语言
+     * @param limitPerStore 每个门店的商品数量限制
+     * @return 商品列表
+     */
+    @Select("<script>" +
+            "SELECT id, fl_id, mdid, name, image, price, introduce, recommend, sort, language, stacking_up, to_examine " +
+            "FROM (" +
+            "  SELECT id, fl_id, mdid, name, image, price, introduce, recommend, sort, language, stacking_up, to_examine, " +
+            "         ROW_NUMBER() OVER (PARTITION BY mdid ORDER BY id DESC) as rn " +
+            "  FROM pos_food " +
+            "  WHERE mdid IN " +
+            "  <foreach collection='storeIds' item='storeId' open='(' separator=',' close=')'>" +
+            "    #{storeId}" +
+            "  </foreach>" +
+            "  AND to_examine = '1' " +
+            "  AND language = #{language}" +
+            ") AS ranked_foods " +
+            "WHERE rn &lt;= #{limitPerStore} " +
+            "ORDER BY mdid, id DESC" +
+            "</script>")
+    List<PosFood> selectFoodsByStoreIdsWithLimit(@Param("storeIds") List<Long> storeIds,
+                                                 @Param("language") String language,
+                                                 @Param("limitPerStore") int limitPerStore);
 }