From 109cbb50d48867083e1a2c746a7ebc3c95cf3569 Mon Sep 17 00:00:00 2001
From: zepengdev <lzpsmith@outlook.com>
Date: Thu, 26 Jun 2025 22:54:12 +0800
Subject: [PATCH] fix: 修正分页查询返回错误总数的问题
---
oying-system/src/main/java/com/oying/modules/pc/store/mapper/StoreMapper.java | 7 +++----
oying-system/src/main/resources/mapper/pc/store/StoreMapper.xml | 4 +++-
oying-system/src/main/java/com/oying/modules/pc/store/domain/dto/StoreQueryCriteria.java | 33 ++++++++++++++-------------------
oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreCustomerController.java | 6 ++----
4 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/oying-system/src/main/java/com/oying/modules/pc/store/domain/dto/StoreQueryCriteria.java b/oying-system/src/main/java/com/oying/modules/pc/store/domain/dto/StoreQueryCriteria.java
index ad86796..f2791d4 100644
--- a/oying-system/src/main/java/com/oying/modules/pc/store/domain/dto/StoreQueryCriteria.java
+++ b/oying-system/src/main/java/com/oying/modules/pc/store/domain/dto/StoreQueryCriteria.java
@@ -1,8 +1,7 @@
package com.oying.modules.pc.store.domain.dto;
-import com.oying.utils.StringUtils;
-import lombok.Data;
import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
import org.springframework.util.DigestUtils;
import java.io.Serializable;
@@ -18,13 +17,13 @@
@ApiModelProperty(value = "商户ID", example = "1")
private Long merchantId;
- private String storeName;
-
- private Integer status;
-
private Long storeId;
private Long platformCategoryId;
+
+ private String storeName;
+
+ private Integer status;
private String blurry;
@@ -44,19 +43,15 @@
public String buildConditionCacheKey() {
StringJoiner baseKeyJoiner = new StringJoiner("|");
- if (platformCategoryId != null) {
- baseKeyJoiner.add("platformCategoryId=" + platformCategoryId);
- }
- if (StringUtils.isNotEmpty(blurry)) {
- baseKeyJoiner.add("blurry=" + blurry);
- }
- if (longitude != null && latitude != null) {
- baseKeyJoiner.add("longitude=" + longitude);
- baseKeyJoiner.add("latitude=" + latitude);
- }
- if (StringUtils.isNotEmpty(blurry)) {
- baseKeyJoiner.add("radius=" + radius);
- }
+ baseKeyJoiner.add("merchantId=" + merchantId);
+ baseKeyJoiner.add("storeId=" + storeId);
+ baseKeyJoiner.add("platformCategoryId=" + platformCategoryId);
+ baseKeyJoiner.add("storeName=" + storeName);
+ baseKeyJoiner.add("status=" + status);
+ baseKeyJoiner.add("blurry=" + blurry);
+ baseKeyJoiner.add("longitude=" + longitude);
+ baseKeyJoiner.add("latitude=" + latitude);
+ baseKeyJoiner.add("radius=" + radius);
// 使用MD5或SHA缩短键长度
return "store:search:page:" + DigestUtils.md5DigestAsHex(baseKeyJoiner.toString().getBytes());
}
diff --git a/oying-system/src/main/java/com/oying/modules/pc/store/mapper/StoreMapper.java b/oying-system/src/main/java/com/oying/modules/pc/store/mapper/StoreMapper.java
index b535f17..ae21034 100644
--- a/oying-system/src/main/java/com/oying/modules/pc/store/mapper/StoreMapper.java
+++ b/oying-system/src/main/java/com/oying/modules/pc/store/mapper/StoreMapper.java
@@ -3,11 +3,10 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.oying.modules.pc.store.domain.Store;
import com.oying.modules.pc.search.domain.dto.NearbyStoreQueryCriteria;
-import com.oying.modules.pc.store.domain.dto.StoreCustomerQueryCriteria;
-import com.oying.modules.pc.store.domain.dto.StoreQueryCriteria;
import com.oying.modules.pc.search.domain.dto.StoreSearchDto;
+import com.oying.modules.pc.store.domain.Store;
+import com.oying.modules.pc.store.domain.dto.StoreQueryCriteria;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -22,7 +21,7 @@
@Mapper
public interface StoreMapper extends BaseMapper<Store> {
- List<Store> selectStoreList(@Param("criteria") StoreQueryCriteria criteria, Page<Store> page);
+ IPage<Store> selectStoreList(@Param("criteria") StoreQueryCriteria criteria, Page<Store> page);
List<Store> selectStoreList(@Param("criteria") StoreQueryCriteria criteria);
diff --git a/oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreCustomerController.java b/oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreCustomerController.java
index 3a12592..59900e0 100644
--- a/oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreCustomerController.java
+++ b/oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreCustomerController.java
@@ -46,11 +46,9 @@
@GetMapping(value = "/page")
@ApiOperation("查询店铺")
public ResponseEntity<?> getStoresByPage(StoreQueryCriteria criteria) {
+ criteria.setLimit(1000);
PageResult<Store> pagedStores = storeQueryService.findPagedStores(criteria);
- List<Store> stores = pagedStores.getContent();
- for (Store store : stores) {
- store.setProducts(this.getProductsByStoreId(store.getStoreId()));
- }
+ pagedStores.getContent().forEach(store -> store.setProducts(this.getProductsByStoreId(store.getStoreId())));
return ResponseEntity.ok(R.success(pagedStores));
}
diff --git a/oying-system/src/main/resources/mapper/pc/store/StoreMapper.xml b/oying-system/src/main/resources/mapper/pc/store/StoreMapper.xml
index 25f5a00..ac3cb3d 100644
--- a/oying-system/src/main/resources/mapper/pc/store/StoreMapper.xml
+++ b/oying-system/src/main/resources/mapper/pc/store/StoreMapper.xml
@@ -135,7 +135,9 @@
AND s.platform_category_id = #{criteria.platformCategoryId}
</if>
</where>
- LIMIT 1000
+ <if test="criteria.limit != null">
+ limit #{criteria.limit}
+ </if>
</select>
<select id="queryUserStores" parameterType="java.lang.Long" resultMap="StoreResult">
--
Gitblit v1.9.3